Asynchronous Serial Communications
I didn't quite understand the logic of assigning a universal sensorValue (below right), so I rewrote the code as per the below left, which also worked. What confuses me is that when we have 2 sensors, we would write sensor1Value and sensor2Value as per the lab, but when there are 3 sensors, we are doing something different...
Serial input to P5.js
1. P5.js talking to microcontroller.
At the beginning I was very confused that the error kept saying "printList is not defined" or "serverConnected is not defined" (as per below left image). It took me a while to figure out that because I was too excited about using the P5.js with Arduino, I forgot to upload the code in IDE to the board.(as per below right image)...
So the issue was soon fixed once I have the code updated to the board and finally I've got P5.js talking to my microcontroller.
2. Adding A Serial Port Select Menu
Though I have done this part successfully, and followed the process step by step, but I'm still a bit hesitant to believe that if I were able to write the code from scratch...I'm not sure if the coding part will get better once I'm more familiar with the language...
3. Draw a Graph With the Sensor Values
I ran into another stupid issue with this one: so I didn't notice that every time I refresh the sketch, the select menu will automatically select my Airpods, instead of the board...Thus, while the error kept telling me map() is expecting number for the first parameter, which is the sensor change, there was nothing in the window simply because I didn't choose the right port....
4. Reading Serial Data as a String
Question: What is the difference between the below two? Is it one prints the binary value and the other prints the ASCII?
// print it out the serial port:
Serial.write(mappedPot);
Serial.println(mappedPot);
Didn't quite understand this part....
Guess remember the below table will be required for future projects.Though they all seem a bit mysterious to me as of now.
Serial output from P5.js
1. Program P5.js For Serial Communication
Comments