Spirit Arduino Quick Reference
The Arduino based processor on Spirit is identical to the processor and code uploading process used on our Ringo2 and Wink2 robots. Please follow the setup instructions for Wink2/Ringo2 and you will be all set to upload code onto Spirit.
Visit the Wink2 Getting Started page and follow the instructions as if you were using the Wink2 robot.
You will install the Arduino software environment, a the USB driver to communicate with the robot, and a few software libraries. This setup process only needs to be done one time for a given computer. If you're already using a Wink2 or Ringo2 robot, no further setup is needed for Spirit.
Please read this entire Setup section carefully before starting.
- Arduino calls its code files "sketches". These are basically text files with code which is compiled into machine readable instructions which are then uploaded into the processor on the Spirit Rover.
- You can begin uploading code at any time (you don't have to cycle the power or do anything special to begin the process.
- Each time a sketch is uploaded, the previous sketch already loaded on the processor is erased and replaced by the new sketch you are uploading. There is no limit to how many times you can upload new sketches to the robot.
Spirit is intended as an advanced robot for more advanced users, though it can certainly be used by novice programmers as well. The supporting documents for Spirit won't attempt to teach you how to program. Code examples and tutorials will be provided as we move forward with the project. If you are new to programming or Arduino, here are a few tips to help you in the correct direction.
If you are very new to code and feeling a bit overwhelmed, we suggest reading our Learn to Code lessons for Wink2. The code used on Spirit is nearly identical. These lessons describe basic programming concepts in a super simple way, and you don't need to have a Wink2 robot to understand and learn from them. http://www.plumgeek.com/learn-to-code.html
The Arduino based processor on Spirit is basically an Arduino UNO board (the most popular kind of Arduino board).
You can use any code on Spirit you would use on any other Arduino board. There are millions of tutorials on the use of Arduino on the internet, and the Arduino website provides an excellent code reference as well.
You will use the functions described in this guide to perform the significant functionality of Spirit, but you will also use other bits of code common to Arduino such as delay() functions, and the normal if, for, while, and other control statements.
When writing your own code, you should always begin from the Rover_BaseSketch. This is a template Arduino program that already contains all the back-end code and functions you will use to control the robot. Write your code inside the loop() and setup() functions as with any other Arduino board.
Restoring Shipping Code:
If you want to restore your Spirit Rover to the program it was shipped with, download the Rover_DemoSketch. Open this sketch inside Arduino and upload it to the robot. You can also study this sketch to see how the example behaviors work. It is somewhat complicated but you can still pick out individual sections to see how they work.
Charging the Rover:
Spirit is charged via the USB cable when connected to your computer or a USB wall power adapter cube. When you plug in the USB cable, the battery will automatically begin charging. It will charge whether the robot is turn on or off, but it will charge faster if it is turned off. A charge indicator LED is located near the battery connector. It is lit while charging is in progress, and turns off when charging is complete. Charging will stop automatically when complete. A full charge takes about four hours to complete.
The Spirit Rover will power off automatically if the battery level gets too low.
To power on the robot, press the PWR button briefly. The PWR LED should light up when powered on. To turn off the robot, press and hold the PWR button for a few seconds until the PWR LED begins to strobe. Once the PWR LED begins to strobe you can release the PWR button. The strobing PWR LED indicates the robot has entered its power down cycle. During this time the robot signals the attached Raspberry Pi computer that it is about to turn off. The several seconds of strobing allows the Raspberry Pi to perform an orderly shutdown before power is removed. This is necessary to prevent problems with the file system on the SD card on the Raspberry Pi.