Eric, Akshita, and I worked together to test out duplex serial communication between the Arduino Nano 33 IoT and p5.js. We used the built-in accelerometer on the Nano as our sensor and sent this data to our sketch in p5.js.
Basically, we started a “conversation” between the two and understood how data from the physical world can be collected and stored, as well as how this data can then be transported, read/ acknowledged, and modified within a browser-based app. This lab synthesized what we learned about asynchronous serial communication and serial input/ output to p5.js from last week’s class labs.
I look forward to trying this out with other serial terminal programs next time, and with more interesting sensors.
Components
-microcontroller (Arduino Nano 33 IoT with a built-in accelerometer)
-p5.js complete library
-p5.serial control
Connecting the Sensors
Reading the values of the accelerometer via the serial monitor in Arduino.
Sending Multiple Serial Data Via Punctuation + Receiving Data in p5.js
Apparently, the code I used was reading the pin A0 instead of the built-in accelerometer on the Nano! Eric checked with Arnab and realized this after we noticed that our x and y values were hovering in the same range (and once mapped in p5.js, location on the canvas). I mapped the values to half the width and height of the screen so we could “center” our circle.
Next Steps
Clearly, something was being sensed and somehow worked. Although, I will retry the lab using the correct code and ask Tom about it in class!