Etch A Sketch in Processing

This offshoot of my experiments with a Raspberry Pi and electronics was an attempt to make a digital Etch A Sketch drawing toy with Processing, on a Raspberry Pi, controlled with 2 potentiometers to act as the nobs for drawing the horizontal and vertical lines. On a breadboard, both potentiometers are connected to an analog to digital converter which feeds the 2 voltage values back to the Pi, and that’s all there is to the electronics.

To get the ADC working I used a pre-built library, ADCDevice, provided with the Freenove kit I’ve been working through. In setup an instance of this ADCDevice class was created. To get a basic version of the sketch working, I had the draw loop read the values from both potentiometers, returning a value somewhere between 0 and 255 for each one to the Pi. By using the map() function to translate these values to the full width and height of the drawn canvas (for now 800 by 600 pixels) it was a pretty simple matter to use these as x and y coordinates to plot a series of points on the screen using point(x,y). This kind of worked, but there were a couple of problems. The first is that while the knobs were moved slowly, the trail of dots formed an unbroken line, but at quicker speeds they separated into a broken trail of dots. The second problem was that there was a small amount of jitter coming from the potentiometers, which caused the line to shift off its path by one or two pixels giving it a messy quality.

I could see how to address the first problem by drawing lines instead of dots with each update, and connecting the start of the current one to the end of the previous one. The second problem might be trickier, probably involving getting the code to somehow ignore smaller movements of say less than a couple of pixels. It was relatively simple to make the sketch draw a continuous line as described above and this worked quite well. Getting a smoother read from the potentiometers was problematic, and I ended up making a for loop for each one, filling an array with a set number of values and only sending the average to the line coordinates. I needed to sample quite a few to get a decent result though, and as the number increased it caused lag in the responsiveness of the sketch. I settled on 40 samples to be a good compromise between quality and performance, but the result is far from perfect so I think a better solution could be found. However both changes did make a difference.

Finally I made a few additions to mock up the look of the classic red Etch A sketch. I wanted to add knobs which rotated in sync with the physical knobs on the circuit, so I decided to to write a class to do this, which was actually my first attempt to do so. This was a good exercise though I  gave myself a lot of trouble by naming one of the methods in the class “rotate”, which is already a command in processing, a problem which took me ages to spot. Led to all sorts of errors and crashing of the sketch. Won’t be doing that again.




Artist, exhibition maker and educator based in Cork, Ireland