Author Topic: $50 robot debugging  (Read 5045 times)

0 Members and 2 Guests are viewing this topic.

Offline dmcliftonTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 1
$50 robot debugging
« on: February 13, 2011, 04:13:58 PM »
So I was able to finish putting the controller together for the $50 robot - I have connected the servos, 9V battery and 4xAA pack, but I have not connected the sensors yet - I wanted to test out getting the servos going.

I used my multimeter to check and the power line for the servos (center, connected to red servo connector) is 6.4V, the ground seems to be wired fine, and I've checked continuiting from the microcontroller to the inner row of connectors. The power line on the other side is a solid 5V and 5V is going to the ATmega8 and the pin in the connector.

I adjusted the program to just have this:

Code: [Select]
int main(void)
{
//declare variables here
//int i=250;//a 'whatever' variable
int sensor_left=0;//left photoresistor
int sensor_right=0;//right photoresistor
int threshold=8;//the larger this number, the more likely your robot will drive straight
configure_ports(); // configure which ports are analog, digital, etc.
a2dInit(); // initialize analog to digital converter (ADC)
a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage
LED_off();//turn LED on


while(1)
{
// Servo Test Code
int i=250;
while(i>0)
{
servo_left(40);
i--;
}

i=250;
while(i>0)
{
servo_left(24);
i--;
}
// end Servo Test Code

//rprintf("Initialization Complete\r\n");

//output message to serial (use hyperterminal)
//print("Hello, World! Read My Analog: %u\r\n", sensor_0);

delay_cycles(500);//a small delay to prevent crazy oscillations
}

return 0;
}

  I have the 6-pin AVR mkII programmer, so I plugged that into USB and used the auto connect feature of AVR Studio.

I went to the 'auto' tab and selected to erase device, program flash, verify flash

I clicked ok and it did some 'stuff' which resulted in indications of 'OK' for everything and it seemed to accurately program the device. I expected at this point the servos woud start 'going' but nothing happened.

I took out my multimeter again, and on the pins leading to the control for the servos I am reading ~4.6v on the first one and ~3.4v on the second servo constantly. I'm not sure if this means it is presumably 'sending go' or if this is the default state.

Would appreciate if anybody would help me out a bit - in particular, understanding if the voltage I am reading does indicate that the microcontroller is 'trying to tell the servos to go' or if it means nothing, or if there may be some issues with my code that I should correct. Any pointers towards things to try definitely appreciated.

Thanks in advance.
« Last Edit: February 13, 2011, 04:15:23 PM by dmclifton »

paulstreats

  • Guest
Re: $50 robot debugging
« Reply #1 on: February 13, 2011, 04:52:20 PM »
Code: [Select]
//declare variables here
//int i=250;//a 'whatever' variable
int sensor_left=0;//left photoresistor

should read

Code: [Select]
//declare variables here
int i=250;//a 'whatever' variable
int sensor_left=0;//left photoresistor


at first glance
the // shouldnt be in front of the variable declaration, im surprised it compiled (unless your compiler realizes dynamic declarations?)

Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Re: $50 robot debugging
« Reply #2 on: February 13, 2011, 06:14:59 PM »
A great idea for a first attempt with any new microcontroller system is the microcontroller equivalent of 'Hello World' - the flashing LED. Simple to set up and code, and gives great feedback as to whether the device is being programmed ok. Do something like:
Code: [Select]
int main(void)
{
configure_ports(); // configure which ports are analog, digital, etc.

        while(1)
{
                PORTD = 0xFF; // set all portD pins high (pins 2:6, 11:13)
delay_cycles(2000);

               PORTD = 0x00; //set all portD pins low
delay_cycles(2000);
}
return 0;
}

Even if you don't have an LED to hand this should be easy to check with a meter. You may need higher or lower values of delay_cycles() to get a sensible time for testing.

If everything on the computer side indicates ok during programming it is likely the device has been programmed.

Your code looks ok, but you only change the value for servo_left() , so only one servo should react. According to the photovore code that should be attached to PORTD,0 = pin 2 of the microcontroller. The voltage you see on this pin when running servos is likely to be fairly meaningless, but values should be clearly defined 5V or 0V when running the code posted above. Suggest you try this first and see if it checks out ok.

Offline dmcliftonTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 1
Re: $50 robot debugging
« Reply #3 on: February 13, 2011, 08:42:22 PM »
Code: [Select]
//declare variables here
//int i=250;//a 'whatever' variable
int sensor_left=0;//left photoresistor

should read

Code: [Select]
//declare variables here
int i=250;//a 'whatever' variable
int sensor_left=0;//left photoresistor


at first glance
the // shouldnt be in front of the variable declaration, im surprised it compiled (unless your compiler realizes dynamic declarations?)

I changed the code further down to declare the variable.

Offline dmcliftonTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 1
Re: $50 robot debugging
« Reply #4 on: February 13, 2011, 08:44:20 PM »
A great idea for a first attempt with any new microcontroller system is the microcontroller equivalent of 'Hello World' - the flashing LED. Simple to set up and code, and gives great feedback as to whether the device is being programmed ok. Do something like:
Code: [Select]
int main(void)
{
configure_ports(); // configure which ports are analog, digital, etc.

        while(1)
{
                PORTD = 0xFF; // set all portD pins high (pins 2:6, 11:13)
delay_cycles(2000);

               PORTD = 0x00; //set all portD pins low
delay_cycles(2000);
}
return 0;
}

Even if you don't have an LED to hand this should be easy to check with a meter. You may need higher or lower values of delay_cycles() to get a sensible time for testing.

If everything on the computer side indicates ok during programming it is likely the device has been programmed.

Your code looks ok, but you only change the value for servo_left() , so only one servo should react. According to the photovore code that should be attached to PORTD,0 = pin 2 of the microcontroller. The voltage you see on this pin when running servos is likely to be fairly meaningless, but values should be clearly defined 5V or 0V when running the code posted above. Suggest you try this first and see if it checks out ok.


So if I understand the code right - everything should come on for a bit, delay, then go off, delay, come on and so forth - and I can check the LED and whatnot to see.

Definitely going to give it a shot, thanks.

Offline dmcliftonTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 1
Re: $50 robot debugging
« Reply #5 on: February 14, 2011, 10:58:02 AM »
I tried this code update and got nothing - no blinking light, no activation otherwise.

The voltage I am reading off the Atmega8 has not changed with the code update, all looks the same. At this point I'm at a total loss - program uploads ok and it validates ok. There is power in the power bus. The ground seems good. And the voltage I am reading off the pin of the Atmega8 is the same voltage I see when I check the pin the servo is connected to - so as far as I can tell, it should be getting any messages over there.

When I was playing around with my voltage meter, I happened to bridge the gap between the ground and the hot for a second and the servo spun briefly - does that make any sense? Seemed kind of strange to me.

I found that when I flip the connector for the servo around (so black is toward the ATMega8 and white is on the ground line), the servo runs continuously.

So if the software uploads fine (according to AVR Studio) and the voltages for power line seems fine, what else should I be checking? Is there some other test I can do on the circuit? I am honestly learning electronics from scratch, so I've been using the 'continuity' setting to check all the connections are going where they should and not where they shouldn't, and the auto voltage meter for the rest - is there something else I can check?

Really appreciate any thoughts or help.
« Last Edit: February 14, 2011, 11:18:34 AM by dmclifton »

 


data_list