2 min read

Week 7: Serial Communication

Week 7 Notes
Background Asynchronous Serial Communication TTL: transistor-transistor logic – used by UARTs (universal asynchronous receiver-transmitters), high voltage means logic 1, low means 0. USB: universal serial bus, allows multiple devices to communicate over the same wires includes CDC (communications...
Check here for notes from this week's lab.

I didn't think I would try to code in p5 since I'm not as familiar with it, but it gave me a good opportunity to try understanding the different kinds of input types between the Arduino and other devices.

I'm still trying to understand the exercise of processing ASCII-encoded strings at the end of the serial output lab: Serial.parseInt() reads a number, then Serial.write() outputs the number as binary, while also using the number to change the LED brightness? If I send an ASCII-encoded string, e.g., “40”, through the serial monitor, and Serial.parseInt() turns that into the integer 40, then why doesn’t Serial.write(40) also give “40” if the value is still between 0–255? Is it because the integer 40 is actually 4 bytes (representing 4, 0, feed, return)? So what do the numbers/symbols that get printed in the serial monitor as a result represent? Maybe my question is, what does `Serial.write()` accept as input, and what does it output?

From the lab: Imagine that analogValue = 32:

  • Serial.println(analogValue) results in "32" with a linefeed and carriage return
  • Serial.write(analogValue) results in " ", the space character, which has the ASCII value 32.

In this case, why doesn't using Serial.write(32) give me 100000, that is, 32 in binary? According to the lab, "when the Serial Monitor receives a byte, it and assumes it should show you the ASCII character corresponding to that byte’s value." So Serial.write(32) sends 32 as a binary, which is interpreted as the ASCII corresponding to that binary number. Can I get Serial Monitor to show me the binary output or the number 32 instead using write? Note that in p5.js, by using Number(serial.read()); we can turn the byte into a numerical value – otherwise, would it be interpreted as ASCII as well?

I also had some trouble reading serial from my Arduino through the terminal. I'm able to use Arduino's Serial Monitor and Serial Studio, but my PC doesn't seem to read anything.