Introduction: Motorized Etch-A-Sketch

If you're like me, you've tried to make a drawing on an Etch-A-Sketch before with very limited success. It's just too hard to draw anything that isn't made out of only rectangles! So, my son's Etch-A-Sketch languished unused around the house for several years. Then, after building a harmonograph table (similar to this one), I noticed the Etch-A-Sketch lying around and thought "I could put motors on the Etch-A-Sketch and make it draw two pendulum harmonograph figures." After much trial and error, it actually worked fairly well. From there, I decided to make it replicate more complex rotary harmonograph figures and, finally, draw images.

Building your own is fairly straight forward. You will, however, need access to a 3D printer and/or laser cutter to create the gears (unless, of course, you can come up with some other creative solution). I have included design files that you can download for the parts as well as the code needed to run it on github here.

Overall, the build can be separated into the following tasks:

  1. attach the stepper motors to the Etch-A-Sketch so the motors can control the knobs of the Etch-A-Sketch;
  2. build a stand to hold the Etch-A-Sketch and allow it to erase itself (optional);
  3. set up the Raspberry Pi Zero W with all of the code it needs; and
  4. wire up the motors and Raspberry Pi.

Supplies

Raspberry Pi Zero W

3 12V stepper motors (28BYJ-48 with 1/64 reduction ratio)

3 uln2003 stepper motor driver boards (you can often find these sold together with the motors)

buck converter or 12v --> 5v regulator

solder supplies, screw terminals, header pins, and perfboard

jumper wires

about 6" of 5/16" threaded rod with 6 nuts and 2 stop nuts

2 608ZZ skateboard bearings (key here is 8mm inner diameter)

12v power supply (wall wart), at least 1 amp

1/4 inch plywood

wood for the stand and base (about 5/8 inch thick)

3D printer and filament

miscellaneous hardware

Step 1: Build the Base for the Etch-A-Sketch and Attach the Motors

In this step, you'll build a plywood backer board for the EAS to rest on with two stepper motors attached to control the EAS.

1. Cut a piece of plywood for the EAS to sit on. Mine is approximately 11.25" wide by 9" high. But, keep reading before you cut yours - you may need to make it a little taller depending on a choice you make below.

2. Both to hold the motors and to support the EAS, cut a piece of scrap wood to match the length of the EAS. This piece is 9" wide, 1.5" tall, and 5/8" thick (ignore the notch in the bottom you can see in the picture - this was already in the piece of scrap wood that I used). Attach this centered at the bottom of the plywood so that the EAS can rest against it while the top of the EAS is flush with the top of the plywood. But, you could put another piece of wood along the top of the EAS to keep the EAS secure at the top. I used 3D printed pieces for this, but using wood is another option. If you go with wood, you will need to increase the height of your plywood to allow room for this top piece.

3. With that piece in place, attach two tabs to either end to keep the EAS from moving side to side. You can 3D print these as I did (the small black pieces in the photo) or just use metal brackets or even spare pieces of wood. The design file and .stl file for these and all other 3D printed parts can be found in the github repository.

4. 3D print two gears to go on the EAS knobs. These should pressure fit very securely on the knobs so that they won't slip at all (you can see where I put a little masking tape on the EAS knob to make it fit more securely).

5. With the knobs in place, set the EAS onto the backer board resting snugly against the wood piece at the bottom. Secure the top of the EAS by 3D printing two corner brackets and sliding these in place. Alternatively, you could secure another piece of wood along the top of the EAS.

6. 3D print the gears that fit on the two motors to turn the knobs and attach them to the motors. Again, these should go on with just a pressure fit, but you can always add some glue if you need it. Before you put these gears on the motor shaft, however, put two wood screws (about 1.25" long) through each mounting hole on the motors. Do this now since once the gears are in place, they may block your access to these holes.

7. Attach the motors to the piece of wood running along the bottom of the EAS. Place them such that they mesh well with the gears on the knobs, but do not jam them together tightly, or they will not turn freely. Screw them into place to secure them using the screws you put in the motor mounting holes. If your support wood is pine, it will be easier to screw these in without a pilot hole. If this piece is hardwood, you may need to make pilot holes.

8. Finally, 3D print the yellow piece that prevents the EAS from falling off of the backerboard if it is rotated and secure it. If you are not planning to build a stand, you may be able to get away with skipping this step. Also, if you used a piece of wood to secure the EAS at the top of the backer board, print a second copy for the top.

Step 2: Build a Stand for the Etch-A-Sketch (optional)

This step is optional, but I really think it adds a lot to the project. The stand allows the EAS to be viewed in an upright position. But, more importantly, it allows the EAS to erase itself between drawings. If you don't build a stand, you will want to modify the code so that the Etch-A-Sketch pauses after moving to the starting position of a drawing so you can erase the Etch-A-Sketch manually.

To build the same stand that I made, you will need access to a CNC mill and a laser cutter. But, there are plenty of simpler options for a stand that don't require a CNC mill. The laser cutter is important since the gears that allow the EAS to erase itself are laser cut. But, you could certainly 3D print these gears, or come up with some other clever way to let the EAS erase itself.

  1. Mill the two bar supports that attach to the front of the backer board. If you don't have access to a CNC mill, that's no problem. There's no reason these couldn't be simple rectangular blocks of wood with holes drilled in them. The center holes should be drilled just large enough for the 5/16 threaded rod to fit through them. It is important that they are drilled straight through rather than at an angle, so a drill press is helpful here.
  2. Pick up the backer board with one finger underneath it on either side and determine the approximate height at which the board does not want to rotate either forward or backwards on your fingers. For my build, this was about 4" up front the bottom of the backer board. Mark this position on each side of the board.
  3. Secure the two bar supports on either side of the board. Here, it is important that the central holes in two bar supports are well-aligned. To ensure this, I ran a longer piece of threaded rod through both of them and kept it in place while I was securing them to the backer board.
  4. Mill the two stand sides. I milled them in two pieces and then glued them together, but it would probably be easier to glue the stock together first and then mill them as a single piece. If you don't have a CNC mill, it should be easy just to nail some scrap wood together to make effective stand sides. For the bearing insert, there are two key points. First, not how far up the center of the bar supports on the backer board are from the bottom of the backer board, and make sure your bearing insert holes are high enough up that the bottom of your backer board won't collide with a stabilizing cross bar at the bottom of the stand. Secondly, make sure the portion of the hole that goes completely through the side is large enough not just for your 5/16" rod to pass through, but large enough for your nuts to fit through without touching the sides.
  5. Use a laser cutter to cut out the large gear to fix to one side of the stand to use for erasing the EAS and the guide that helps keep the smaller gear aligned. Attach these to the left side of the stand.
  6. 3D print the motor gear mount and erasing motor mount. Use a laser cutter to cut the small erasing gear. Pressure fit the motor gear mount to the erasing motor and then pressure fit the small erasing gear to this mount. Attach the erasing motor mount to the bottom left corner of the EAS backer board and connect the erasing motor to this mount, with the mount on the back of the board. IMPORTANT: Before you mount the erasing motor to the backerboard, make sure it is positioned correctly so that the small erasing gear will mesh securely with the large erasing gear but will not bind.
  7. Finally, attach the backerboard to the stand. I used a lock nut on the inside of the threaded rod against the bar support with another nut tight against the other side of the bar support. Then, a nut firmly against the inside of the bearing and a final nut against the outside of the bearing. Once you have it all set up, measure the distance between the two sides and cut a piece of dowel rod to go between the sides at the base for additional support.

Step 3: Set Up the Raspberry Pi Zero W

Before getting started, let me say that I am not an expert in linux or using the Raspberry Pi (or Python, or really anything, for that matter). There may be minor changes for different set-ups, etc. If you encounter any errors or omissions in these instructions, I apologize in advance, and please let me know about them so I can correct them. And Google is your friend when trying to correct cryptic error messages. I often find that if I just copy the error message into a search engine, someone else has encountered that same error and posted a solution online.

Also, one warning - the Raspberry Pi does not have an on/off switch, and if you power it down by simply unplugging it, you may corrupt the SD card. To turn it off before unplugging it, you can use the Shut Down button on the web page or type 'sudo shutdown -h now' in a console window. It's also a good idea to save an image of the SD card once you get everything working.

With that said, let's get started.


Set up the Raspberry Pi to run “headless”

You can hook up a monitor and keyboard if you prefer, but this approach is easier, in my opinion. First, download and install the operating system on an SD card - I use Raspberry Pi OS Lite. You can find the OS and instructions on installing it here.

Next, get set up to be able to access your Pi remotely using SSH. For a tutorial on how to set up your RPi to be headless, you can go here.


Install PuTTY on Your Laptop and Log In

PuTTY is a free, easy to use terminal emulator that will allow you to log into your RPi remotely using your laptop. Again, you can use other terminal programs, but PuTTY is easy and free. The rest of this Instructable will be using PuTTY as an example. There is lots of information on installing PuTTY available online. Once you have installed PuTTY, open it to get a terminal window like the one above.

Set Host Name = 'raspberrypi' (this is the default host name), set Port = 22, set Connection type = SSH, and click on Open.

You should get a Warning message – read it and then click on Yes. This will open up a terminal screen asking for login information. For “login as:” enter “pi” and when it asks for a password, type “raspberry”

To change the password from the default password (a good idea), type in 'passwd' and follow the instructions.

You can also change the device name (its hostname) from 'raspberrypi' to something else (I changed mine to 'etchasketch').

To do this, type in 'sudo raspi-config' to bring up the Configuration Tool. Select System Options, and then on the next screen select Hostname and change the name. When the system asks if you would like to Reboot now, you can select No because we have some other tasks to complete first.

If you do change the hostname, remember when you log in with PuTTY going forward to use the new hostname instead of 'raspberrypi.' Also, note that you can save the connection parameters in PuTTY by naming the session parameters in the box under Saved Sessions and then clicking the Save button to the right.

Install Additional Python Packages

The Raspberry Pi OS comes with Python installed as well as many Python libraries. However, there are some we will need that are not pre-installed, so you will need to install these libraries now. I am using Python 3. If you want to use Python2.7, the instructions would be slightly different.

First, make sure your Pi OS has the latest updates and upgrades by typing 'sudo apt-get update' and, when that finishes, 'sudo apt-get upgrade.' Each of these commands may take a few minutes to finish.

Next, we want to install Pillow, which is an image processing library. This library has some other libraries on which it depends, so we need to install these first before installing Pillow.

We need to install something called 'pip' which will help us install the other packages we need. 'Pip' comes pre-installed in the OS versions that include the desktop, but is not pre-installed with the Lite OS that I installed.

This is also a good place to note that the OS comes with two versions of Python installed – the older Python v2 (Python) and the newer Python v3 (Python3). I would recommend using Python3; if you want to use Python v2 for some reason, some of these commands may not work. Python v2 is no longer being supported.

'sudo apt install python3-pip' – this installs pip for Python3

'sudo python3 -m pip install --upgrade pip'

'sudo python3 -m pip install --upgrade Pillow' – this installs Pillow, a library for image processing

'sudo pip3 install numpy' – this install numpy, a library for numerical processing

'sudo pip3 install RPi.GPIO' – this installs RPi.GPIO, a library for controlling the IO pins on the Pi using Python

'sudo pip3 install Flask' – this installs Flask, a library that allows Python to serve up simple web pages

'sudo apt-get install libopenjp2-7' – this installs a library that Pillow will need to use

'sudo apt install libtiff5' – another library that Pillow will need to use

'sudo apt-get install libatlas-base-dev' – this is a library that numpy may need on some installs, so I include it here for completeness.

Install the Etch-A-Sketch Code on the RPi

Next, you need to install the software that actually runs the MEAS.

The first step is to download the software from GitHub repository here. Next, extract the EAS directory from the zip file. To get the EAS directory loaded onto the Pi, I used something called FTP (file transfer protocol). If you installed PuTTY, you should also have a program called PSFTP installed. When you run this, it will open a terminal window with a prompt that looks like 'psftp>.' The following commands should be entered into this terminal.

'open raspberrypi' – if you changed the hostname, substitute that for raspberrypi.

Enter you login credentials when requested – username 'pi' and the password that you set previously.

'lcd <path where the EAS folder you unzipped resides on your laptop>' - Note that if any of the folders in the path contain spaces, these folder names must be included in quotes (“ ”). This command tells PSFTP the directory on your laptop that will be your working directory. The working directory on the RPi will be your home directory by default. For example, I type lcd C:\Users\steve\OneDrive\Documents\Projects\Harmonograph\"Etch A Sketch" since this is the folder where I put the EAS folder.

'put -r EAS' – this command tells PSFTP to transfer the folder EAS and all of its contents from your laptop working directory to the RPi working directory.

'exit' – this closes down PSFTP

Now, if you go to the terminal window for your RPi and type 'ls' to see the contents of your home directory, you should see a folder called EAS.

Let's See If It Works!

Well, that was a lot – hopefully it all went smoothly for you and you didn't have to spend hours searching the web for solutions. But, if you made it here, then we're almost done – let's see if everything is working so far.

First, in the terminal window for your RPi, use the 'cd ~/EAS/flask' command to go to the directory EAS/flask, and enter the command 'sh flask_script.sh' to launch the simple web-page that controls the MEAS. You should see something that looks like this.

pi@etchasketch:~/EAS/flask $ sh flask_script.sh

* Serving Flask app "/home/pi/EAS/flask/EAS_flask_v2.py"

* Environment: production

WARNING: This is a development server. Do not use it in a production deployment.

Use a production WSGI server instead.

* Debug mode: off

* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

192.168.1.66 - - [21/Jan/2021 19:57:04] "GET / HTTP/1.1" 200 -

192.168.1.66 - - [21/Jan/2021 19:57:04] "GET /favicon.ico HTTP/1.1" 404 -

You will notice that you do not get a new prompt at the end. This is because this program keeps running indefinitely to serve up the web page.

Now, go to your browser and type in 'etchasketch:5000' as the url (if your hostname for the RPi is not 'etchasketch,' use your hostname instead. This tells the browser to connect to port 5000 on the device with hostname 'etchasketch.' You should get a page that looks something like the web page above.

If so, congratulations! The web page control portion is working. Now, leave the flask script running in its terminal window, and use PuTTY to open another terminal window on your Pi, and log in.

In this new terminal window, enter 'cd ~/EAS' to go to the EAS directory, and then enter 'python3 EAS_controller.py' to launch the program that controls the MEAS. If all goes well, you will see the following text:

horiz going to: 400 from 0

horiz going to: 0 from 400

vert going to: 400 from 0

vert going to: 0 from 400

If this happens, you're in great shape!

Set Up to Run Automatically at Startup

This last step is optional, but well worth a few minutes, in my opinion. Instead of having to run the EAS_controller.py program and the flask_script.sh script every time you start up the Pi, you can set these up to run automatically every time the Pi boots up. To do this, edit the rc.local file in the /etc/ directory. First, open that file for editing with the command:

sudo nano /etc/rc.local

When this file opens, go to the end of the file, and above the line “exit 0” enter the following two lines:

sh /home/pi/EAS/flask/flask_script.sh &

python3 /home/pi/EAS/EAS_controller.py &

Then enter ctrl-X to exit, and when it asks if you want to save your changes, select Y. The “&” at the end of each of these lines is critical; that symbol lets the Pi know that it should not wait for these programs to complete before continuing. This is important since these programs don't finish, but rather stay open awaiting user inputs.

A Note on Security

It is generally a bad idea to download and run a program written by some random person (like me) without first looking through that code to make sure it does not do anything mischievous. I would definitely suggest you browse through the Python program and look at the flask_script.sh to make sure there's nothing dangerous in there (there isn't, but don't take my word for it).

Step 4: Wire Up the Motors and the Raspberry Pi

The overview of the electronics is that you will have a 12v power supply (wall wart) bringing power to the Etch-A-Sketch. The RPi needs 5v while the motors need 12v, so you will need to split the power into four different leads, with three going to the three uln2003 motor driver boards and the fourth going to a buck converter (or other regulator) to step it down to 5v. The 5v output from the buck converter/regulator will power the Pi. The Pi will also connect to the three uln2003 motor driver boards, which will drive the motors. (NOTE: The connections below are what I used. However, a couple of people have made this and told me their drawings came out reversed on the vertical and horizontal axes. Perhaps some of the motor controller boards are connected differently. If this happens to you, just reverse the connections on one of the two coils; for example, swap the IN2 and IN4 connections.)

The Pi connections to make are:

Pi Pin Connection
5v yo 5v out from buck converter/regulator
Ground to Ground out from buck converter/regulator


GPIO4 to IN4 on the uln2003 driver for the vertical motor
GPIO17 to IN3 on the uln2003 driver for the vertical motor
GPIO27 to IN2 on the uln2003 driver for the vertical motor
GPIO22 to IN1 on the uln2003 driver for the vertical motor


GPIO26 to IN4 on the uln2003 driver for the horizontal motor
GPIO19 to IN3 on the uln2003 driver for the horizontal motor
GPIO13 to IN2 on the uln2003 driver for the horizontal motor
GPIO6 to IN1 on the uln2003 driver for the horizontal motor


GPIO12 to IN4 on the uln2003 driver for the erasing motor
GPIO16 to IN3 on the uln2003 driver for the erasing motor
GPIO20 to IN2 on the uln2003 driver for the erasing motor
GPIO21 to IN1 on the uln2003 driver for the erasing motor

The motors themselves just plug directly into the driver boards, and they only fit in one orientation. You will also need to connect 12v power and ground to each of the three motor driver boards.

To secure everything to the back of the board, I put stand-offs on the boards and then used a little hot glue to attach the standoffs to the backer board.

Step 5: Conclusion and Usage

I hope everything is working for you as it should. If you encounter any errors in this Instructable, I apologize in advance, and please share them (along with any correction) so that I can update this and others can benefit from your troubleshooting.

Hopefully, using the Etch-A-Sketch from the web-page will be fairly straightforward. Note that for harmonographs, you typically get the most interesting images when the periods of the oscillators are very close to a simple ratio (e.g. 2.002 to 1). If they are exact ratios (e.g. 5 to 3) you get interesting figures that just decrease over time without rotating. If they are not very close to simple ratios, you generally get something that just looks chaotic.

When the program first starts, it assumes the Etch-A-Sketch stylus is in the middle of the Etch-A-Sketch. If that is not the case, just move it there manually. After start-up, it should keep track of its position. But, if for any reason it gets 'lost,' just manually move it back to the center and then click the Reset Origin button on the web-page to tell it it is back in the center.

For images, remember that simpler images generally come out better. To add new images, just use the PSFTP program to transfer an image into the ~/EAS/shade_image/Images directory. Once the image is in that directory, it should show up as an option to select on the web-page.

If you build one, I would love to hear about it. If you want to help improve the code, please let me know about that too. And, if you find inputs that make really nice harmonograph figures or images that come out really well, please share those as well!