Generative art with Processing and working with Circuit Playground Express
Tags: processing, adafruit, python, raspberrypi
Published: 2020-07-15 22:58:01

##### *Note: This is an old post of a WIP project originally posted on [Coding Grace](https://www.codinggrace.com/news/generative-art-processing-and-working-circuit-playground-express-2020-5-27/) - for this post in dev.to, I'm splitting it up into a series.*

This might end up being a multi-part post. It's my learning journey of fails and little delights (or bigger if I'm successful) on learning about generating art via Processing from data obtained from the accelerometer from the Circuit Playground Express.

### Components mentioned in this project
* [Raspberry Pi](https://www.raspberrypi.org/products/)
* [Adafruit Circuit Playground Express (CPX)](https://www.adafruit.com/product/3333)
* [Adafruit Circuit Playground Tri-Color E-ink Gizmo](https://learn.adafruit.com/adafruit-circuit-playground-tri-color-e-ink-gizmo/)
* [Adafruit Circuit Playgroud TFT Gizmo](https://learn.adafruit.com/adafruit-tft-gizmo)
* [pi-top[4]](https://www.pi-top.com/products/pi-top-4)

### Software references
* [Processing](https://processing.org/)
* [PyProcessing](https://py.processing.org/)
* [PiProcessing](https://pi.processing.org/)
* [Circuit Python](https://circuitpython.org/)
* [Arduino](https://www.arduino.cc/)
* [VNC Viewer - Virtual Network computing](https://www.realvnc.com/en/connect/download/viewer/)

# Day 1: PyProcessing, Circuit Python, E-ink Gizmo - lots of experimenting
Ok, what I wanted to do (which made sense in my head) was to create an image with Processing when it detects sensor changes in CPX.

I was thinking of going whole hog with Python as there's a Python library for Processing via [py.processing.org](https://py.processing.org/) but first off I need to get Processing installed on my Raspberry Pi (model 4 on pi-top[4]). I quickly realised the normally version via Processing site doesn't work, but there's a [pi.processing.org](https://pi.processing.org/) that has a version of Processing specific for it.

Hit download and untarred it and voila, it worked.

Spent some time going through the tutorials with Python on Processing. That was fun... now I want to get cracking on how to get it working with CPX.

I can get Circuit Python to print to the E-ink Gizmo screen with the text `Testing`. That's a good start. 😊

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/uoj3ha5sm9csvcrue72z.jpg)

Was looking at using command line to call it programmatically... not so straight forward because it specifically needs a really old version of Java... and it doesn't support OpenJDK and just ugh...

Anyway, maybe it wouldn't be so bad to play with Processing, it's only Java light, right. I found that it does interact with GPIO on the Raspberry Pi, so that's a positive.

##### ℹ️ Reference
* https://learn.adafruit.com/processing-on-the-raspberry-pi-and-pitft/hardware-io
* https://processing.org/reference/libraries/io/GPIO.html

But I want it to work with CPX. I'll be connecting it with a microUSB cable to the Raspberry Pi (which I'm VNC'd into). So playing with GPIO is a moot point.

Ok, there's too many moving parts here that don't necessarily talk to each other, let's roll back a little. What comes out of the box with Python that can generate images? It's [Python Turtle](https://docs.python.org/3/library/turtle.html). I kind of ignored it as I was teaching kids about Python with it late last year, but I do notice a lot of people create generative art with Python Turtle.

The next question is how to save the output of Python Turtle.

Internetz helped here, between:-

* https://www.assertnotmagic.com/2019/02/02/art-math-python/
* https://stackoverflow.com/questions/36826570/how-to-close-the-python-turtle-window-after-it-does-its-code

I can see that you can generate something simple, save it to an image (note, I had to install pillow to use PIL), and also close the Python Turtle window after it generates the image.

##### ℹ️ Reference https://python-pillow.org/

So it's back to Circuit Python after all that. Interesting exercise though.

---

## Ok, back to basics
CPX with E-ink Gizmo -> pi-top[4] with Raspberry Pi Model 4

Remembering how to access the accelerometer data thanks to the following:

* https://learn.adafruit.com/sensor-plotting-with-mu-and-circuitpython/motion
* https://learn.adafruit.com/make-it-shake-rattle-and-roll/more-circuitpython

Adafruit Libaries:

* `adafruit_display_text`
* `adafruit_gizmo`
* `adafruit_il0373.mpy`

Found the following error:

```
Group Full RunTimeError for label.py: text was too long
```

##### ℹ️ Reference: https://github.com/adafruit/Adafruit_CircuitPython_Display_Text/issues/11

Also realising waiting 180s is very boring!