Week7: Lab: Intro to Asynchronous Serial Communications
but my question is: why serial monitor that I created in p5.js cannot update real-time value of my potentiameter? Is that I did something wrong?
-Nov 13,2025 update
I went to Tom, and ask him about this issue. It turns out on my SerialEvent, I use read instead of readLine to read the value from the potentiameter. But my Arduino sends data one line at a time, so p5 needs to read it one line at a time.
readLine() gives me a complete piece of data, while read() only returns a single character and breaks everything apart.What Arduino Really Sends
In my Arduino code, I print sensor values like this:
Serial.println(sensorValue);println()doesn’t just send the number. It sends
- Each digit of the number
- And then a newline character
'49' '50' '51'
It travels across the wire as a sequence of bytes.
But logically, Arduino is sending one complete reading per line.
What readLine() Does
In p5.js:
inData = serial.readLine();
readLine() patiently waits until it reaches the newline characterand then hands me the entire reading as a single string:
"123"
Once I realized this,
the whole data flow felt almost elegan