Arduino Meets Lego: The Ultimate DIY Robotics Project

Cyrus Tabrizi, 8/29/13
Receiver_INO_Capture RC_INO_Capture

Step 10: Coding! (and some extra XBEE info!)

      That’s basically all the hardware. Now, it’s just a matter of testing your components via code on the Arduino and programming the right serial communication protocol for the XBEEs(you also may have to change the pins I've assigned in my code if you wired you remote or car differently).
      If you're coding this yourself, the serial communication can take a bit of back and forth if you’re new to it, but it’s just a matter of making sure everything's speaking the same language and speaking it on the same wavelength. As for as language goes, I've worked it out in my code so feel free to modify the code to your specific remote control or car design (or not modify it if you're doing the same thing as me).
      As far as getting the XBEEs on the same wavelength, though, they should already be set and ready to go if you purchased them new (unless you want a higher data-transmission rate or if you have other XBEE projects near you, you shouldn't need to do anything to them for them to work). If you didn't purchase them new, its possible somebody changed the factory settings and that you will have to reconfigure them. There are tutorials online, but if there’s enough interest, I can go into detail about how to sync the radios and how to do the right testing, but it’s hard to generalize about that stuff.


IMG_4093
Step 11: Wrapping Up..

      I think that’s it for now. I hope I didn’t lose too many of you on the way, but if I did, feel free to ask me any questions or comment anything you would like to see in more detail! Also, if you have any feedback or suggestions for how I should write future Instructables, I’m all ears! Lastly, if you actually manage to make something from this, I’D LOVE TO SEE IT. Send me pictures, send me links—I want to see what YOU have made! Happy Building!       I would like to acknowledge and thank Floyd Baker for partnering with me to develop the Handuino, and I would like to give a special thanks to me robotics teacher, Mr. Dela Cuesta, for providing Floyd and I not only with parts and materials and access to a laser-cutter, a 3D-printer, and the robotics lab during off hours, but also his guidance and experience. I would also like to thank Mr. Kosek for lending me the FTDI chips needed to reconfigure the XBEE radios and for his help with serial communication and processing.



>>UPDATE: After I replied to a question by carlos66ba, I have decided to include and elaborate on my response within the Instructable, since there is information that is potentially relevant for anyone working with XBEE communication!! carlos66ba: Very nice setup. Can you also consider adding the arduino sketches and lego nxt programs? Also: have you thought if it would be possible to interact directly via usb or to connect the xbee radio directly to the nxt? Crtlego: YES, it is most certainly possible! You'll need two things (besides an XBEE): a board to connect the XBEE to the USB, and the right software to communicate with the port.       For the board, I used this little guy from Sparkfun (https://www.sparkfun.com/products/8687). You'll need a mini-to-A USB cable if you want to use it with your computer, but you'll definitely need a board of some sort if you want to configure your XBEE!!
IMG_3765
Software-wise, I've communicated directly with the XBEE with two different programs and they both have their plus-sides.
One is called X-CTU (search "x-ctu digi" in google and you can find it for installation). Its made by the same people who made the XBEE (Digi) and it gives you all the options and tools you'll need to configure all the settings of your radio if you don't like it out of the box. It also serves our purposes, though, by having a Terminal that lets you type out Serial data straight to the radio. Provided you have all the data transmission rates and channels set properly (which the program lets you view and configure rather easily), you could technically have your own private little chatroom with local XBEEs (or one on your own computer if you opened two windows up at the same time and connected two XBEEs to it).
      The second one is called Termite, and its by CompuPhase (http://www.compuphase.com/software_termite.htm). This one's much simpler and is essentially the "Terminal" part of X-CTU. It still has the options needed to properly communicate through your USB port to the X-CTU, but, if I understand correctly, you cannot change the actual settings on the radio.
      As far as controlling the RC car I built or doing other XBEE communication, though, both Termite and X-CTU are good places to start. Did I mention they are both free?
----------
      As far as XBEE and NXT communication goes, I'm not sure what the possibilities are (I never really experimented with the NXT in depth, even with my love for Lego). I imagine somebody has worked out a way to do communicate serially via USB with the NXT, so if that's possible, I suppose you could hook an NXT up to the XBEE? I know a couple of Lego fans that might like that..
----------
      With regards to programs and sketches, I have uploaded the latest stable release of my Arduino code/sketch for both the remote control and the Arduino on the car. They are in a zip file on my website along with the CAD files.