Candy Count

5. Set up the Code


Next, we’ll login to the Pi and do some set up. The code is up on Github and available here. You’ll want to update Raspbian for Robots

. This will guarantee you have the Python code in the GrovePi Github repository for this project.

First, let’s make sure the volume is up and running on the Raspberry Pi. In the command line run:

1
aplay /usr/share/sounds/alsa/*

If you are able to hear the sounds, move to the next step! If not, this tutorial may help you set up the audio: Increase the volume to 100%.

Next, install espeak. Run the following in terminal:

1
sudo apt-get install espeak -y

After it is successfully installed, run the following command. (Disregard error messages on the terminal if you can hear sound):

1
espeak “hello”

If you are able to hear “hello” from the headphones or the speakers then move to the next step!

Our final step is to set up the Python program to auto-run at boot. We’ll be using rc.local, and there is some background on this here. In the command line, open up the file rc.local

1
sudo nano /etc/rc.local

In the file, add in the line:

1
python /home/pi/Desktop/GrovePi/Projects/Candy-Counting-Robot-Costume/robot.py &

This should go into the file ABOVE the final exit command, and below any other commands.

Optional: Customize the WiFi Access Point

As we mentioned above, the robot costume is going to have its own WiFi Access Point. We do this through CINCH, a version of Raspbian For Robots, which automatically opens up a WiFi Access Point. This can be handy for debugging or restarting the costume on the fly with a phone or laptop (not that you want to haul one around while trick-or-treating, but hey . . . maybe you’re that person!). It can also be a cute party trick: “She’s also a WiFi Access Point!”

You can customize the pages served up by the Raspberry Pi access point by rewriting the HTML files in the directory:

1
/var/www/html

Add in any extra pictures or code you want to run. When someone logs into the WiFi Access Point “dex” they’ll see this web page at the address “10.10.10.10”.