Eyepot - Programming
Let's program the robot I built in the previous article!
The Eyepot works by using in conjunction a Raspberry Pi Zero W and an Arduino Pro Mini connected by a serial link. Therefore, we'll write the Arduino code first, then a Python program for the Raspberry Pi. Then, we'll setup remote control from a web browser.
You can find the entire source code for the project licensed under GPLv3 on my repository on GitHub.
The Arduino Pro Mini is responsible for driving the eight servos of the legs. Commands to specify target angles are sent from the Raspberry Pi through a serial link.
The custom serial protocol is text-based and quite simple. It can easily be typed manually when debugging, but it is still compact enough to allow short transmission times even at low bitrates. Each line contains a one-character command, an optional space, and an optional parameter as a base-10 integer. Implemeted commands are as follows:
- 0 to 7: store target angle for corresponding servo (0 to 7)
- R: reset stored target angle to default for each servo
- C: commit stored target angles …