Sunday, December 11

Programming anyone?

Hi there again!

Today I will teach you some of the basics in hardware-close C programming.

To start with you will need some sort of programming environment. Since I use an Arduino, I chose to use the environment you can get from HERE. It's the Arduino user- and programmer environment, making you able to both code end program your Arduino unit. It comes loaded with features making your life easier when it comes to the Arduino. For those of you that are more hardcore i recommend ATMELs own AVR studio 5.0. But in that case you will have to program your unit through the SPI-port and that's nothing i'll take up here. Not today anyways =)


The above picture is what you see when you first start the Arduino environment. A clean, small window with a textbox and a console (the black area). The console will give you every information you need and if something went wrong during for eg. the compilation.
I'll not go through the IDE thoroughly. You will have to find your own way by foe example hovering over the buttons (the ones above sketch_dec16a). When and if you do so, it'll appear a small text to the right indicating what that button does.

The IDE comes preloaded with a large pack of examples written in the, let's call it "Arduino-language" =) It's  a crossbreed between C and C++. You can use pure C to write your programs and that is what I'm gonna do. And of course, that's what I'll teach you too!

Feel free to look at the code examples the IDE gives you. You find them under File->Examples->...

The code I'm going to show today is code to get a bluetooth module (like BlueSmirf Gold) up and running.

So lets start!

At first you need a pretty hefty knowledge about the ATmega processor (since that's what's on the Arduino). I recommend you to read the manual here.

The code then. I'll just post the code here at the moment since I don't have time to thoroughly go though it.
The comments should be rather self explaining!

And by the way, the code does only(?) fit on an ATmega16 at the moment, though the only changes you'll have to do is change the names on the registers (i've made some changes but not tested them) and the constant F_CPU to "16000000L". By then you'll have a baud rate on 115200 BAUD (though with a effective loss of data on around 3%).

The code below is also interrupt driven. Meaning that if the Arduino receives anything, it'll immediately break that and serve the data that it receives.

The only thing this does is that the Arduino returns whatever you send to it! It's also supposed to light up the led on pin13 on the UNO.


/*
 * test.c
 *
 * Created: 2011-11-24 13:28:08
 *  Author: Alexander Widerberg
 */

#include<avr/io.h>
#include<stdio.h>
#include<avr/interrupt.h>
#include "util/delay.h"
#define F_CPU 16000000UL  // The CPU speed in Hz
#define USART_BAUDRATE 115200 // Baud Rate value
#define MYUBRR (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
uint8_t toggle = 0;
void USART_Init()
{
UCSR0B |= (1<<RXCIE0) | (1 << RXEN0) | (1 << TXEN0);   // Turn on the transmission and reception circuitry and
  // enables recieve interrupt flag
UCSR0C =
        /* no parity bit */
        (0 << UPM01) |
        (0 << UPM00) |
        /* asyncrounous USART */
        (0 << UMSEL01) |
        (0 << UMSEL00) |
        /* one stop bit */
        (0 << USBS0) |
        /* 8-bits of data */
        (1 << UCSZ01) |
        (1 << UCSZ00);


UBRR0L = MYUBRR; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register

UBRR0H = (MYUBRR >> 8); // Load upper 8-bits of the baud rate value..
// into the high byte of the UBRR register
}
void USART_Transmit( unsigned char data )
{
// Wait for empty transmit buffer
while ( !( UCSR0A & (1<<UDRE0)) )
;
// Put data into buffer, sends the data
UDR0 = data;
}
void USART_Flush( void )
{
unsigned char dummy;
while ( UCSR0A & (1<<RXC0) ) dummy = UDR0;
}
ISR (USART_RX_vect)
{
unsigned char value;
unsigned char temp;
temp = UDR0; // Fetch the received byte value into the variable "value"
value = temp;
        toggle = 1; // Toggle that we have received data!
        USART_Transmit(value);
        USART_Flush();
}

int
main(void)
{
    uint8_t state = 0;
    USART_Init();
    DDRD = 0x00; // Set all ports on port D to inputs except PD1 (0x01 == 000000010)
    DDRB = 0x20; // Set pins PB4 and PB5 to outputs (0x20 == 00110000)

    PORTB = 0; // Nulls all data (if there is any on port b)

    sei(); // Enables interrupts!

    for (;;) { // loop forever! A MUST HAVE!
        if (toggle) {
            state = state ? 0 : 1;
        }
        PORTB = state ? 0x20 : 0; // Light up the onboard LED if we have received data!
        toggle = 0;
    }
    cli(); // Disables interrupts
    return 0;
}

Saturday, December 10

Components, components, components....

Hi again!

As promised! Today I'll show you the electronics more close up and also show the housing for everything.
After second thoughts, I'll start off by showing you the housing and how i made it.

It's a standard electronics box which meassures 14 - 8.5 - 4 (l - w - h) centimeters. It's bought from a local hobbies shop here in Linköping, Sweden. ( ~ $2)

I drilled some holes in a pattern that matches the Arduino so that it fits and stays on the same place in the box. I also hot-glued some motherboard fittings so that I actually can screw the Arduino in place =)

The lid is used for the breadboard (fitted with dual-sided tape).

Arduino fitted. I also drilled some holes so that i can reprogram the Arduino whenever i want. Also, the cables for the servos and power supply needed to go through somewhere.


 I also made a cable making me able to connect the Arduino to the micro receiver in the car which in turn will make med able to steer and control the car from the Arduino. It's a standard jR servo female adapter soldered together with some standard breadboard cables.

All electronics together.

Friday, December 9

The Assemblyment

As i promised yesterday, here comes The Assemblyment.



The picture speaks for itself!


So i went out on eBay® to buy the lacking parts. But it ended with me almost buying a complete new truck in parts. Well at least i had spare parts. I also bought a sharp distance sensor.




The above picture shows a work in progress of the assembly! The only thing i ended up using from the old car was the engine mount.




Just a comparison =) UNO Vs. Tire


The above picture illustrates the assembled car together with a Sharp GP2Y0A21YK0F 10-80cm analog distance sensor and the Arduino UNO.


Tomorrow I'll show you the electronics more close up! I'll also list the components I'm using in this build. =)


Feel free to comment about your own builds below!


Circuits out!

Thursday, December 8

How to design and plan your project?

Well ain't that a tricky question? How to design and plan your project?

I'll start by saying there's no right or wrong here! You may as well start with your circuitry before the chassis.
I'll just tell you how I planned my project.

With that said, let's start!

I had thought of making a robot during a rather long period of time, before I actually put the wheel in motion. I had pondered the possibilities of how and what to create long before I started. Since that is the uttermost fundamental question to answer, I'll ask you the same! Do you know what to create? Let me and others know below!

The first thing I did was to write down the features i wanted my robot to have. I came up with the following list of things:

  • Remotely controllable via bluetooth (or equal)
  • Distance sensor(s) in front to keep track of obstacles
  • Ride height so that my robot could bash through the nature without problems
  • A long range camera so that i could see and steer the robot without actually have visual contact with it
  • It should be good looking! =) Yep that's important ;-)
  • Use of my Android® phone's sensors and GPS
  • Long range functionality (>1 mile to 2 miles)
As you can see this is a long list of, as I'm aware, hard things to achieve. But with alot of time and effort I made it work and so will YOU!


I chose to go with an Arduino since they are easy to use and even more easy to teach others in how to use. So I went out and bought myself an Arduino UNO which have the following (critical) specs:


Flash Memory32 KB (ATmega328) of which 0.5 KB used by bootloader
SRAM2 KB (ATmega328)
EEPROM1 KB (ATmega328)
Clock Speed16 MHz


This is enough memory and speed to make a really advanced robot (not a neuro-robot, but almost =) ).
Since my build will be a real-time implementation we really need to think about speed and drawbacks. One significant drawback to the UNO is that it's clocked at 16MHz. I would really love to go all the way to 20MHz but as it obviously turns out, the ATmega328p isn't rated for such speeds. Douh!


The next thing i needed was a chassis and since i had my list, things were pretty straight forward! I bought a second hand Traxxas® REVO 3.3. A remote controlled, BAD-ASS monster truck. It had an ride height of about 4.25" (~110mm)!! I thought that would be enough =)
But as it turns out i was going to learn a hard lesson... I bought the car for a pittance and when it arrived, it lacked almost everything interesting. Like an engine, RC-system and so on. It was just a rolling chassis!#&!% And in really bad condition!


So what do you think? Is it better to buy a brand new truck rather then buying a second hand one?
Feel free to comment below!


Next time I'll show the building and assembly of the chassis! And I'll also show how badly handled the chassis were!


Circuits out! 

Wednesday, December 7

Welcome to ElectronicSelect!

This blog is intended to teach you guys out there how to make your own robot(s)!


I'll start to say that it's a rather thorough process making a fully working robot. There's a lot to think of and a lot of things that can go wrong on the way to our success.


Who am i then?
My name is Alexander and i am currently studying my third year here in Sweden to become a master of science in computer engineering. I've built numerous robots and i have a large knowledge in how to write programs and    make circuitry.


I'll help you on your way and show how i made my robot shine like a Baws!


Stay tuned for the next post where i'll be starting off with some basics on how to plan and design your creation.


Circuits out!