Society of Robots - Robot Forum

Software => Software => Topic started by: mr_kobayashi on April 19, 2007, 01:36:46 AM

Title: $50 Robot Problem... programmed but inactive?
Post by: mr_kobayashi on April 19, 2007, 01:36:46 AM
Alright, so I managed to connect the microcontroller to the PC using AVR ISP kit and AVR Studio 4, I've attached a screenshot. I click on 'Program' under Flash and it writes and verifies.... then I plug in my servos, turn on the battery pack (I'm using 4xAAs for the servos and 9V battery for the circuit and sensors).... but then nothing happens.... the robot doesn't "go". I used a multimeter to verify voltages, and the servos/sensors are definitely getting power.

I notice that when I click on the "Connect to AVR programmer" button in AVR Studio 4, connect always fails despite the COM port selection being correct... which makes me suspect that perhaps the program isn't properly written?

(http://www.societyofrobots.com/images/sbs_connect_AVR.png)

Additionally, I tried to use PonyProg2000 and that doesn't detect the microcontroller either, although I suspect that might have something to do with the fact that PonyProg2000 isn't compatible with AVR ISP kit.

Can anyone help me out? (maybe Admin?)  ;D ;D
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: JonHylands on April 19, 2007, 04:59:38 AM
The very first thing you need to do is verify that the AVR is working. The easiest way to do that is to hook an LED to one of the I/O pins of the AVR, and make it flash. That's basically the "Hello World" of the embedded world.

I suspect it would be a good idea (hint Admin) to add a flasher program to the tutorial, so people can verify that their build/program/power cycle is working with the least amount of extra complications thrown in there.

Once you get the flasher program working, then you can try and program and run with the full blown robot code, at least knowing that one variable is out of the way.

I've been doing embedded microcontrollers for almost 10 years, and I still invariably screw up something every time I build a new board, and end up using an LED flasher as the first application to help debug.

- Jon
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: Admin on April 19, 2007, 10:11:42 AM
Hmmm this is a tought one . . .

So when you click on 'Connect to AVR programmer' (Display the 'Connect' Dialog), make sure you select:
Platform: STK500 or AVRISP
Port: Auto

When you click Connect it should then figure it out . . .

But Im assuming you tried that and it didnt work.

Are you using the com port with another program simultaneously? For example, if hypterminal or ponyprog is already using that port, then AVR studio will not be able to use it. I make this dumb mistake all the time . . .

So when you program it, it programs and verifies correctly? The attached image is what it should look like if it was successful.

To test with a blinky LED, put this in your while loop and delete the other stuff:
Code: [Select]
while(1)
{
//blink LED every second
LED_on();
delay_cycles(23200);
LED_off();
delay_cycles(23200);
}
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: JonHylands on April 19, 2007, 11:36:56 AM
I think I see what the problem might be - he's using the wrong thing to program it.

When you bring up AVR Studio, you need to go to the Tools menu, and select "Program AVR" -> "Connect..." or "Auto Connect" (not sure what Admin uses, I use the first one).

You need to have the window up that Admin shows in his post. Then you can program the chip...

- Jon
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: mr_kobayashi on April 19, 2007, 03:53:58 PM
OK I understand that you need to program it using the other screen by clicking on "Connect to Selected AVR Programmer" the thing is that it always says "Connect Failed", I attached a screenshot. I checked the microcontroller is getting 5V at Pin 7 and Pin 20/21 and that's not the problem.

The weird thing is I *think* the connection to the PC is working because that other dialog box comes up (the first screenshot I posted), but it can't connect to the AVR Programmer using that other option....

Any other ideas? Thanks in advance.
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: mr_kobayashi on April 19, 2007, 04:24:01 PM
Haha damn this is weird... I used that LED code and that works! My LED is blinking on and off  ;D

I attached a screenshot and notice that I programmed it using the *other* dialog box, the one I posted originally, NOT the one where you click on "Connect to Selected AVR Programmer" (the one in the screenshot that Admin posted) as that one still fails as per my previous post.

But at least this shows that the program is "in" the microcontroller and working.... so it must be something wrong with the servos or the photoresistors? I'm not using the same servos and photoresistors as in the tutorial BTW (maybe that is making a difference?), here's a link to the ones I am using:

LDR: http://www.jaycar.com/productView.asp?ID=RD3485&CATID=&keywords=ldr+resistor&SPECIAL=&form=KEYWORD&ProdCodeOnly=&Keyword1=&Keyword2=&pageNumber=&priceMin=&priceMax=&SUBCATID=

Servos:
http://www.jaycar.com/productView.asp?ID=YM2760&CATID=&keywords=servo&SPECIAL=&form=KEYWORD&ProdCodeOnly=&Keyword1=&Keyword2=&pageNumber=&priceMin=&priceMax=&SUBCATID=

In the tutorial there is a 1.5kohm resistor in series with the LDR, but since my is more sensitive and using the resistance data on the website, I used a 4.7kohm resistor.
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: ed1380 on April 19, 2007, 06:08:53 PM
I am so confused. after I did rebuild where do I get the .hex file to use in ponyprog?

Doing the same exact stuff everytime, but everytime I get diferent errors when rebuilding.
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: dunk on April 19, 2007, 06:15:54 PM
looks like you have one too many "}"s in that snippet.
remove this one:
Quote
      }
   /*********ADD YOUR CODE ABOVE THIS LINE **********/

you should always have the same number of "{" as "}"

dunk.
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: mr_kobayashi on April 19, 2007, 08:42:22 PM
Right, I'm CONVINCED the problem is with the servos. I tried inputting the servo test code

 
Code: [Select]
// Servo Test Code
i=250;
while(i>0)
{
servo_left(40);
i--;
}

i=250;
while(i>0)
{
servo_left(24);
i--;
}

Nothing happens, so what else can I try? Do I have to buy new servos (maybe they are busted)? They are definitely connected to Pin 2 and Pin 3 (Port 0 and 1 respectively).
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: JonHylands on April 19, 2007, 09:11:37 PM
Do you have the ground for the servo power supply coupled to the logic power supply? They have to share a common ground in order to work...

- Jon
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: mr_kobayashi on April 20, 2007, 01:12:53 AM
Do you have the ground for the servo power supply coupled to the logic power supply? They have to share a common ground in order to work...

- Jon


Yes all my grounds are connected.
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: Hal9000 on April 20, 2007, 10:05:41 AM
Maybe a bit unrelated to the original post, but maybe there should be separate parts of the forum for the $50 tutorial and/or a troubleshooting FAQ, although i'm sure you've thought of that already.
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: Admin on April 22, 2007, 09:31:02 AM
try this code to test your photoresistors:
Code: [Select]
while(1)
{
//store sensor data
sensor_left=a2dConvert8bit(5);

if(sensor_left>125)
LED_on();

else
LED_off();

delay_cycles(1000);
}
the led should change depending on if the photoresistor is covered up or not


try this code to test your servos:
Code: [Select]
while(1)
{
int i=20;

for(i=20;i<55;i++)
{
servo_left(i);
servo_right(i);
delay_cycles(5000);
}

}
this code will try all possible speeds of your servo

*note, i didnt test this code but i think there are no typos in it . . .

if either doesnt work, that means there is something wrong with your wiring


Quote
Maybe a bit unrelated to the original post, but maybe there should be separate parts of the forum for the $50 tutorial and/or a troubleshooting FAQ, although i'm sure you've thought of that already.
hmmmm good idea. Ill think about this for a bit. If the forum gets a bunch more $50 robot posts, I can always create a new category and move all the posts in to it.
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: ed1380 on April 22, 2007, 09:58:46 AM
How did the OP get this(attached pic) to pop up? all I get is teh connect failed dialog box
(http://www.societyofrobots.com/robotforum/index.php?action=dlattach;topic=909.0;attach=249;image)
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: Admin on April 22, 2007, 11:29:03 AM
Quote
I am so confused. after I did rebuild where do I get the .hex file to use in ponyprog?

Doing the same exact stuff everytime, but everytime I get diferent errors when rebuilding.
The .hex file will only be made when there are no errors. What errors are you getting?

Quote
How did the OP get this(attached pic) to pop up? all I get is teh connect failed dialog box
hmmmm are you using the AVR STK Serial Port Dongle Programmer or the more expensive AVR ISP2 Programmer? Is the microcontroller power on and the cables properly connected?

You got to give us details of your errors if we are to help ya :P
Title: Re: $50 Robot Problem... programmed but inactive?
Post by: ed1380 on April 22, 2007, 11:33:10 AM
I'm using the $12 cable, and the mcu is getting power. I rebuilt the curcuit last night, so I'm about to test it with teh new mcu.  :-\


It doesn't work. :'(
so admin what's your adress? ;)