USB Arduino Setup

This was an extra session held by spencer to introduce processing through an Arduino to those who were interested.


USB Port

Screen Shot 2017-04-01 at 17.24.09

Line 3: The serial library is what allows processing to receive data from the USB port.
Line 4: Serial myport is the path of communication to the Arduino

Line 117: The serial myport is setup here. Serial.list()[3] defines which USB port to use and 9600 is the speed of communication.


Println reveals that the serial.list array only has 2 drawers. Because I don’t have an arduino plugged in and serial list()[3] is out of bounds.

To catch this error we wrote a for loop…


with a new variable called havearduino (we had to define this at the top)


…and apply it with an if statement at the beginning of void draw so our check reader() function only runs if the arduino is plugged in

The next line down in void draw calls the function to replace the old ID with a new one.


Now the sketch runs, bypassing the need for an arduino because there is already some functionality built in that works based of keypresses.


Check reader function


Check reader needs to figure out the new ID

336: Listen for information from the arduino and store it in dat
338: We use asterisks to separate the id numbers so the if statement checks to see if the current character is an asterisk. It will use this break to store non-asterisk characters in thisreading.
342: If the character IS and asterisk, that means we have come to the end of the id, and it can now be compared with the lastreading. If they are not the same, then thisreading replaces lastreading.

348: Int stpos6 is about applying the numbers to a string UID: 01 23 45 67


Get data function

This function searches within the data and makes arrays from chunks of it. We end up with 3 arrays based on the FMP, Special Study and Dissertation data. The way you write this function will vary depending on the data that you are reading.


Applying Interactivity

Now, to apply the connection with the Arduino to an existing sketch. For this, we used the generative letter project we had been working on in Tuesday sessions.


For this we work by pasting the necessary parts of the code across part by part.


First import the library.


Then copy over the havearduino variable and all the other strings utilised in the checking and receiving parts of the code


create the link to card reader

check the card reader each frame at the beginning of void draw, note that you’ll also need to paste in the checkreader() function.

Now the id and new id values are being picked up.

Screen Shot 2017-01-26 at 12.10.14

paste across the if statement that compares the new and old id. Remember to paste in the getdata function AND copy across the data text file too.

Screen Shot 2017-01-26 at 12.13.11

some of the variables in get data are undeclared, we could declare them but a lot of them are not necessary, since the only part of the data we are using in this sketch is the name.

Screen Shot 2017-01-26 at 12.14.53

Strip down the get data function accordingly.

Now paste your original variables into get data and redeclare them to link them up with getdata

This works, except we need to add asterisks onto the end of currentname


Author: Pip Williamson

Pip // Animator & Motion Designer

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s