Motorized Egg-A-Sketch
I've always wanted to make an Egg-bot for creating art on an egg. I've seen multiple "instructables" and "DIY kits" for creating an "EggBot" or "SphereBot," but I've never been able to get one to work. Most of the instructions use a wonderful tool for CNC called "GRBL." GRBL uses G-code to drive bipolar stepper motors. I've looked for a GRBL derivative to use on a unipolar stepper set, but the software is archaic and is difficult to get working.
I recently built a "Motorized Etch-A-Sketch," from the author steve_a. Steve's research and beautiful python coding make it easy to create an image on an Etch-A-Sketch. I looked at Steve's code and found it to be exactly what I was looking for.
I'm kinda cheap. The unipolar steppers, 28BYJ-48, and their control boards, ULN2003, are perfect for the hobbyist such as myself. I looked into buying another Raspberry Pi Zero (RPi Zero) and found that they are hard to come by. The RPi Zero is at a pretty stiff price for someone as cheap as myself. I had an old OrangePi Zero (OPi Zero) laying around which is cheap but powerful enough to drive the project. I loaded Debian on the Opi Zero and Hacked -- with some great difficulty -- Steve's code to create the Motorized Egg-A-Sketch.
Our local "maker space," the Inventor Center was hosting a "Ukrainian Egg Dying Class." I HAD to make the Zelensky Egg shown in the Title. What's more Ukrainian?
Supplies
This tutorial is not so much about the apparatus used to hold the egg. There are several Eggbot, Sherebot, Egg Painter,... plans out there. Sadly, most use the bipolar steppers. I DID find a few 3D printable versions using the 28BYJ-48 as the main stepper set -- mostly on Thingiverse using the software I couldn't get to work:
https://www.thingiverse.com/thing:2245428
https://www.thingiverse.com/thing:2681413
https://www.thingiverse.com/thing:3453327
https://www.thingiverse.com/thing:1461709
I built a wooden frame and modified the arm parts of one of these models to fit my device. My first attempt was a failure due to the lack of clearance of the drawing arm. I had to totally re-build the frame. I use sticky-tac to hold the egg in place on the wheels. It allows much less pressure on the egg-- especially if it's raw... EEEWWW!
Electrical Components you will need
1 Orange Pi Zero -- Add a heatsink or it will crash!!!
2 28BYJ-48 Steppers that should come with the ULN2003 controllers
1 SG90 Servo
1 USB cord that you will destroy! BWAHAHAHAHA!!!!
Get a USB cord that you can plug into the OrangePi Zero.
1 Micro SD card of at least 8GB.
1 PC for programming and communicating with the OPi Zero.
Install Armbian on Your OrangePi Zero
Install Armbian on your OrangePi Zero
There are a number of instructions on how to get Armbian on your Orange Pi. Rather than re-inventing the wheel, please look up and follow instructions for your OS.
The Egg-A-Sketch runs on a very lightweight OS of Debian Linux for ARM processors called, Armbian. If you are familiar with Ubuntu, Debian, or other deb-package management versions of Linux, you will have no problem.
I will try to make this instructable as easy as possible for the average layman on Microsoft Windows as well-- but the Egg-A-Sketch will run on Armbian, and their will be many commands in Linux. Have patience, take your time, and follow the instructions. It should have good results.
- Download the latest stable version of Armbian from here.
- Etcher (Balena) is the easiest tool I can find to burn an image. Use Etcher to create the SD card. If you are a linux guru, and "dd" is your thing, use it instead.
- Boot
Linux Users
If you are a linux user, put the SD card in your OPi Zero, and connect the USB cable to a USB port in your computer. You can find out which port your OPi Zero is connect as root with--
# dmesg
-- is a message log of recent hardware changes.
Towards the end of the log, you should see something like 'ttyACM0' or 'ttyUSB0', which is your serial port.
With '/dev/ttyACM0' as an example, type in--
$ screen /dev/ttyACM0 115200
-- will bring up the OPi Zero connection.
Microsoft Windows User
b. Once again, I'm not trying to rewrite the book, nor re-invent the wheel. I have to give credit to this web page, by LUC SMALL, because it is well done. .. but once you see the big "OrangePi" ascii text login screen, ...
First Time Login
Be sure to immediately change your "root" password. For all practical purposes, this does not need to be a serious password unless you plan on using the OrangePi Zero for more than an Egg-A-Sketch. I wouldn't think anyone would want to hack into your Egg-A-Sketch to wreak havoc on an egg. If you plan on using it for more than an Egg-A-Sketch, use the safety standard "...at least 8 characters including at least one capital letter and some special characters and never any dictionary words ...." .. But for the Egg-A-Sketch, use something you can remember and is fast, like "orange," or "egg."
Once the root password is set, your Armbian version may want you to create a user as well. When I used steve_a's software, he went with the standard user,"pi". I would suggest you do the same, unless you want to hack a bunch of code. I have some specific privileges for the user, "pi," built into the download. Create a password again, and you should be ready to move on.
The script will move to setting up the shell. I use "bash." It's an old standard. There are a few differences are between "bash" and "zsh."
You can now set the Network connection-- "easy peasy." If you want to change it later, I'll show how that is done later in the instructable.
It will ask you for a Timezone. It will then go to "locales." for the language. I'm in Eastern US so en_US.UTF-8 is perfect.
Congratulations! You are running Linux on an Orange Pi Zero!!!
From this point on, you will be working on the Orange Pi Zero in the "bash shell." If you like to copy and paste, there is a trick in the bash shell. A shortcut to copy is <Shift><CTRL><C>. A shortcut to paste is <Shift><CTRL><V>. In a regular window screen the command is still just <Ctrl><C>, and <Ctrl><V> respectively.
NOTE: The commands from this point onward are either as a 'user' or as 'root'.
'#' = root is a hash mark prompt. ie.
root@orangepizero:~#
'$' = user is a dollar sign prompt. ie.
pi@orangepizero:~$
Get the Software for Your OrangePi Zero
Update
Let's make sure you have the latest tools.
'# apt update' -- this will go out and look for updated packages
'# apt upgrade '-- This will upgrade any packages with latest versions
Set up the WiFi
If you want to change the Wifi, you have been using ethernet, or you didn't set it earlier... You must first login as root. You should see the '#' prompt. To see a list of access points type:
'# nmcli device wifi list' ---should give you a list of Wifi access points.
Then set up your Wifi with,
' # nmcli device wifi connect <SSID> password <password> '
To see if you're connected, you can type:
'# ping -c 3 www.google.com '
Switch to your "user" rather than root
'# logout'
' login:<username>' ie. --"pi"
' password:<userpassword>'
You should now see the ASCII art prompt for Orange Pi Zero. Now, we will use "sudo" (meaning 'switch user') commands to install other packages. The "sudo" command allows you to run as root if yo don't specify a different user.
'$ sudo apt install python3-dev libjpeg-dev zlib1g-dev python3-pip libffi-dev libatlas-base-dev libtiff5 libopenjp2-7 python3-pip'
Get access to the GPIOs
' $ sudo addgroup gpio'
' $ sudo python3 -m pip install --upgrade OPi.GPIO '
$ sudo usermod -aG gpio <current_user>
This gives your user general permissions on the GPIOs.
Prepair to Install Some Python Tools These Python tools are what steve_a's software need to run. It's a little more difficult to get them to run on an OrangePi, but we'll walk you through it. I have an older version of the OrangePi Zero with an "H2" printed on the top. It can not handle compiling the python packages from scratch. If you can succeed in installing the python tools without this next little trick while using the later versions of OrangePi Zero, more power to ya. Otherwise, we need to edit a couple of files for binary downloads.
$ sudo nano /etc/pip.conf
Paste the next two lines into the file.
[global]
extra-index-url=https://www.piwheels.org/simple
Then <Ctrl><X> to close the file and <Y> to save.
Open nano again with:
$ sudo nano /etc/udev/rules.d/99-gpio.rules
Paste these two huge one-liners into the editor.
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
Then, again. <Ctrl><X> to close the file and <Y> to save.
Finally Reboot the OrangePi to update the configuration.
$ sudo reboot
You will be logged out of the Orange Pi automatically. You'll have to either "SSH" or "screen" back into the OPi Zero.
Now install the Python Tools These are a bunch of "one at a time" commands. Some take longer to run than others-- like numpy (painfully slow). Get up, stretch, get a cup of coffee or something,
$ sudo python3 -m pip install --upgrades pip setuptools wheel.
$ sudo python3 -m pip install --upgrade Pillow
-- installs the Pillow software for image manipulation.
$ TMPDIR=/home/pi/tmp sudo pip install --cache-dir=$TMPDIR --verbose numpy -i https://www.piwheels.org/simple
-- adds a repository of binary python tools.
$ sudo pip install Flask
--- Flask is a super small, super kewl, web server on Python.
Install WiringOP
$ cd ~/
-- go back to the home base of <user>.
$ git clone https://github.com/orangepi-xunlong/wiringOP.git
-- get the WiringPi library for OrangePi Zero (needed for the servos).
$ cd wiringOP
-- change into the downloaded WiringOP directory.
$ ./build clean
-- clean the build
$ ./build
-- build the library.
Finally, Download the Egg-A-Sketch software, and set up
$ git clone https://github.com/jgarbe/Egg-A-Sketch.git
-- get the software.
$ mv Egg-A-Sketch/EAS ..
-- move the EAS folder into the "home" folder for 'pi'.
$ chmod -R a+x EAS
-- change permissions for navigating and using the software.
$ ln -s /home/pi/EAS/shade_image/Images /home/pi/EAS/flask/static/Images
-- bring in the shared Images file.
Hardware Assembly
It's time to put all those wires together into something usable. Using the diagram above, connect all of your hardware to the OrangePi Zero. Take your time. Relax, you're almost finished.
Test Your Creation
For this part you will need to log into two separate terminals on the OrangePi Zero.
In terminal one, log back into your OrangePi Zero as 'pi', or <user>.
$ sudo python3 EAS/EAS_controller.py
You will be asked for the password...
Don't worry if the bash shell gives you a bunch of lines like--
/home/pi/EAS/steppers/stepper_control.py:39: UserWarning: Channel 2 is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(self.A, GPIO.OUT)
It's because the WiringPi library and Python, both, are controlling the GPIO pins.
Your program should run and the steppers should move, checking for backlash-- then, your servo should activate, testing for clearance. If it DID, you are successful!!! Hooray!!! So far.
Now Test Flask
In terminal two, log in as <user> again. Type--
$ sudo sh EAS/flask/flask_script.sh
--this starts the flask web server.
Note the highlighted, second to last, line. You should be able to use a web browser of your choice, and type in that address with a beautiful web page designed by "steve_a".
Finally, we're finished-- almost!
Ok, the last thing you want out of any device is to have to log back into it and turn on the two programs to see the web interface and to control the steppers. Let's make them come on while booting the Orange Pi.
$ sudo nano /etc/rc.local
-- This is the "startup" file for servers and such.
Place these two lines in the file before the exit clause.
sh /home/pi/EAS/flask/flask_script.sh &
python3 /home/pi/EAS/EAS_controller.py &
It should look something like this
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sh /home/pi/EAS/flask/flask_script.sh &
python3 /home/pi/EAS/EAS_controller.py &
exit 0
Tada!!!! Finished at Last!!!! ...but what about that picture of Grandma on the egg?
Uploading Pictures
Now that you know the IP address of the OrangePi Zero, use Filezilla or SFTP (port 22) to upload your "black and white" images into the folder, "/home/pi/EAS/shade_image/Images" folder. Next time you scroll in and out of the "Images" page of the Egg-A-Sketch, your Grandmother's picture can be there.
Accolades
This project would not have happened if it weren't for steve_a. The software is for the Egg-A-Sketch is based mainly on the development of the Motorized Etch-A-Sketch of Steve's. I visited the Maker Faire in Asheville this past week to meet Steve. I'm in the green flanel shirt, Steve is in the White T-shirt showing off some of his latest inventions. 3D-Blender Guru, Byron is in the orange shirt, and all around creative genius, Andy, is in blue.