J’s tudio    File   Blog   Contact
       
Nov 4, 2025

Week7: Lab: Intro to Asynchronous Serial Communications

Serial  means that the two computers communicating are doing so one bit at a time, by sending pulses of data back and forth.  Asynchronous means that the two computers that are communicating are each keeping track of time independently. 



Week7: Lab: Serial Input to P5.js using WebSerialI learned what is the asynchronous 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
So if the value is “123”, then it will send like: '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 character
and then hands me the entire reading as a single string: "123" Once I realized this,  the whole data flow felt almost elegan