Firstly, I tried out communicating with the port (receiving analog input) through the terminal. The code was first uploaded through the Arduino. Then, once the code was uploaded, I was able to read it using the “cat” command in the terminal.
ls command in this folder shows the ports in my computer. The “usbmodem” is only visible when the Arduino is connected.
This the data that was being read from the port. I used Control + C to quit out of the port.
Next, I went back into the Arduino IDE and serial monitor to take a look at the code while modifying it to be easy to read. The output on the left is using “Serial.write” which outputs the information in binary code converted all in one line and is notably difficult to read. The information in the right uses “\t” tab and println() new line characters to make the data easier to read.
The output is shown in raw binary value, ASCII-encoded binary value, decimal value, hexadecimal value, and octal value respectively.
Next, I put together three sensors to manage serial communication between two inputs. I used several different Serial print methods to format the input reading in a readable way.
For this one, the serial data is formatted and differentiated using punctuation.
Next, I learned how to send all of the data received into a CSV file, which can later be read and imported into a spreadsheet. This is useful information for the future when I’d need to document different readings, import readings into other applications, etc. The image to the right of this text shows the CSV file opened.
Next I worked on reading analog input as serial input from a potentiometer, particularly into p5.webserial. Firstly, I set up my potentiometer.
Next, I imported p5.webserial into the index.html file and I changed the the p5 sketch code to utilize serial communication.
The indata variable is read in from the sensor and can be interpreted into any which way to be used in the p5 sketch. I can imagine this to be used in a lot of fun ways to create interactive digital artworks and games with a controller.
The console.log() and print() functions change inData into a String of bytes which can then be read… I think? Still in the process of understanding bytes.
The inData is a byte that can then be converted into a number and charted into a visual.
Next, I moved onto the third lab, which involves serial output. I set up a p5 sketch, and LED to communicate with each other.
mouseY is mapped to the brightness (0-255) of the LED.
PhysicalPixel code (found in the Examples > Communication section of Arduino IDE). In here, if you send a ‘H’, the LED will turn on and if you send a ‘L’, the LED will turn off.
The number entered (0-255) will result in the corresponding level of brightness in the LED.