STEP-BY-STEP ROBOT TUTORIAL
Build a quality robot for under $50 - on your own!
1) Write the program. Cant program you say? No problem, I've written it already for you! But don't worry you wont get off the hook that easy. I've written the program so that a beginner can edit and change it to how you like. In the future, hopefully others will write source code and share for you to use.
2) Compile the program. Again, this is as easy as pushing the button labeled 'build'. Seriously. Compiling converts your program into a file that your microcontroller can understand.
3) Upload the program to your microcontroller. Again, just plug in the programmer, and push the button that says 'program'. Easy, no?
But before we can start programming your robot, you need some software.
Ideally, I would like to give you just one single program to download and everything will work right away. This is the idea of WinAVR (22.8mb), as when you download it (yes, please download and install it), you get everything you need in one go. It will install a bunch of useful programs all in one location, including GNU Compiler Collection (GCC), GNU Binutils, avr-libc, avrdude, avrice, and a few others. Its all seamlessly built in, so I wont even bother you about them. For more information, check out the WinAVR user manual.
Don't install Programmers Notepad, its useless if you use AVR Studio, and has been know to be buggy in previous versions.
The next program I will have you download is an IDE (Integrated Development Environment). Atmel (the producer of the microcontroller you are using) offers this software, AVR Studio, for free. This IDE has a built in editor, compiler, uploader, etc all in one package.
Atmel normally requires you to enter annoying registration info like your email address and phone number, but lucky you I bypassed it to offer you the direct link (suckers!).
Now that we have installed all the essential software, lets set up AVR Studio. Find the new AVR Studio 4 icon in your start menu, click, and you should immediately see this window come up:
Select 'New Project'
The next window that comes up will look like this:
Copy the options that I have chosen. Make sure there are NO spaces in the file name.
For example, do not do 'C:\Documents and Settings\User\Desktop . . .'
Also, the project file name must be the same name as the initial file. There is a 'feature' (bug) in AVR Studio that will cause you problems otherwise.
After clicking Next, another window should come up:
Select AVR Simulator, and choose ATmega8 on the right. Click Finish. AVR Studio should now load and look something like this:
Now you need to download the source code. Currently, I offer just one program for your robot, but plan to come out with others later:
Photovore v1.zip (March 10th, 2007) - Case-based photovore program
Empty the contents into the proper folder. For example, for Photovore v1, empty all files into C:\My_Robots\Photovore_1
Now we need to add in the source code that you downloaded for AVR Studio. Right click 'Source Files' and left click 'Add Existing Source File(s)...'.
Locate Photovore_v1.c in your Photovore folder, and add it. You could also just drag and drop. The source code file is the one you would want to edit if you wanted to reprogram what actions your robot takes.
Just like with the source files, now right click 'Header Files' and left click 'Add Existing Header File(s)...'.
Locate SoR_Utils.h in your Photovore folder, and add it. This header file is filled with a lot of useful functions I wrote up for you.
Now we must set up the options to compile your source code. Go to Project -> Configuration Options.
Check the box that says 'Use External Makefile' and then browse to locate the makefile (the file in the downloaded source code labeled 'makefile'). Then push OK.
The final programming step is to compile the code. This converts your code written in C to machine code in a .hex that only your specific microcontroller can read. You should do a Rebuild All the first time you compile the downloaded source code. But after that, if you only make changes to the .c source file, you only need to do the faster Build command.
If all went well, you should see this message after compiling:
If you get errors, and you are new to programming, it may be a little difficult to debug at first.
Now we need to upload the .hex file you just compiled to the microcontroller via the AVR STK Serial Port Dongle Programmer. To do this, you need to download the newest version of PonyProg2000: v2.06f BETA. For more info on the program, check the PonyProg Documentation.
After loading up PonyProg2000 again, you want to select 'Open Device File.' This is the beige folder looking button at the top left. Then go to your folder that has all your source code, and select/open the .hex file.
You might also need to configure which COM port you have the programmer plugged in to (serial port), as well as select ATmega8 as the microcontroller. My laptop has like 8 different USB ports so I had to try a few before it worked (I'm using a USB to serial adaptor).
If you aren't sure which COM port to use, click:
A new window will come up called 'System Properties'. Open the Hardware tab and click device manager. You should see this:
Plug in your AVR STK Serial Port Dongle Programmer to both your computer and your robot if it isn't already from Step 3C. AFTER plugging your robot in, turn on the microcontroller by flipping the ON/OFF switch, or plugging in the battery if it doesn't have one. If you were to unplug the programmer, make sure you turn off your robot first.
Now select 'Write All' from the drop down menu. A Yes/No window will come up, select Yes. Wait while the program uploads.
If you didn't select the correct port to use for your programmer (because you still aren't sure), or you forgot to turn your robot on, you will get this error:
Try plugging in your programmer to a different port of your computer and then push Retry. Try each COM port until it works.
What the error means is that it is not detecting the programmer for at least one of these reasons:
update: There is a known problem with PonyProg2000 that it won't work with a USB to serial adaptor. You might also be interested in this forum post,
After programming, hopefully, your robot now suddenly tries to commit suicide by driving off your table. Your are done! Congratulations!
Optional: Dont want to risk the problems some are having with PonyProg2000? Want to upload your program to your robot in under 30 seconds? You could buy the much more expensive (~$34) AVR ISP 2 programmer that is supported by Atmel (Digikey part # ATAVRISP2-ND). Its a much better programmer and supports many other Atmel microcontrollers. You also wouldn't need the PonyProg software and instead could directly connect with AVR Studio:
If you decide to use this programmer, please check out this post concerning pinouts of the programmer.
update 2009: You can also try the cheaper but less functional Pocket Programmer at sparkfun (see parts list on first page). It uses a 10 pin connection, but most microcontrollers today only come with 6 pin connections (including the Axon). Just keep that in mind. update 2010: Users have reported using the more affordable 6-pin ISP programmer by Pololu successfully. It works fine in AVR Studio, and includes a basic oscope, too.
Common Compiling Error
Photovore_v1.c:108: fatal error: opening dependency file .dep/Photovore_v1.o.d: No such file or directory compilation terminated. make: *** [Photovore_v1.o] Error 1 Build failed with 1 errors and 0 warnings...
Further Reading, More Source Code, and Upgrades
Many of my future robots will now use this microcontroller, so everyone can benefit from source code that I plan to post for future robots. If you would like to document and share your robot and source code, or see what others have done, feel free to check out the member written tutorials.
Have you finished making your $50 Robot and want to share your experiences? Or want to see what others have done for ideas? Check out this $50 robot forum post.
Was that too easy? Want to upgrade your $50 robot?
Has this site helped you with your robot? Give us credit -
link back, and help others in the forums!
Society of Robots copyright 2005-2014