Week12. Interface and Application Programming

Connect Arduino to Processing via serial

I wanted to use P5JS first as this tutorial showed. However, seems the link was broken and npm installation failed, and there was no application

I follow this tutorial to use Proecssing.

I use the code below to send command to my Arduino board. The Arduino is running the LED code I wrote last week.

Starry Night in Processing

I like the sone Starry Night, and I wanted to visualize the song while it is playing by Arduino interactions. I got the starry night color from colourlovers.com.

I followed this tutorial to have Arduino play the tone.

The keyboards by buttons as below :

The result as below:

I found sometime the Arduino IDE and processing competed for the serial port, and lead to IO busy error. Unplug and plug the usb solved the problem.

Look deep into the code.
The Arduino code:

The processing code for starry night:
Detect serial input and create a new star

Draw the sky and the stars. Continuously draw a dark window with high-alpha can cause a fade out effect.

The code in Star class to draw star:

Another failed try:
I found an very beautiful project using perlin noise in openprocessing, and I want to modify it to work with arduino. However, the openprocessing.org does not have serial extension, so I have to modify the code from p5js to processing 3, and the result looks nice (see the code here).

The weird thing was the same code works fine in openprocessing with processingjs engine, but looks ugly in the processing 3 software.

I’ve no idea why there is such difference. I doubt it was because of the algorithm of random(), but I need to learn more about perlin noice first.

Android communicate with Arduino via USB

I wanted to use App Inventor to created a application, that communicate via USB. I didn’t have google player, so I use Chinese version App Inventor.The code was as below:

I read this wiki and this article to understand different USB standards and how it works.

Then I connect wires with a USB Type-A female header. Then I connect it with a standard TypeA-MicroB connector. Thus, I can connect my Android phone with Arduino or breadboards for prototyping.

It didn’t work. Open serial failed.

I created a female-2-female adapter and tried several different approaches, but all failed.

Then I realize that USB-OTG is not a simple wire adapter. It has more to make the serial talk.

So the next step is to dive deep and understand the serial communication. I’m still working on it now.

Updated:from this article, seems I need to connect the ID pin of micro-USB to the GND and then everything will be fine.