top of page

Week 06

This week I learned a lot about serial communications and learn how to connect the P5.js with Arduino.

Notes

图片1.png

In order to communicate, the two devices need to agree on a few things:

  • the rate at which data is sent and read

  • the voltage levels representing a 1 or a 0 bit

  • the meaning of those voltage levels; is a high voltage 1 and a low voltage 0, or is the signal inverted so that a low voltage is a 1 and high voltage is 0

So there should have three lines:

1. A common ground wire to ensure the same voltage 
2. A line from sender to receiver (transmit line for the sender)
3. a line from the receiver to the sender to transmit data (receive line for the sender)

  • Sending a series of digital pulses back and forth between devices at a mutually agreed-upon rate.The sender sends pulses representing the data to be sent at the agreed-upon data rate, and the receiver listens for pulses at that same rate.

  • 9600 means the date rate is 9600 bit per second=9600 baud. Receiver read the voltage on its receive line every 1/9600th of the second. That means 1200 bytes each second.

  • All processors that have a UART (this includes personal computers and microcontrollers, and most embedded boards like the Beaglebone Black and Raspberry Pi as well)  have an area in memory where they store incoming data from the serial ports called a serial buffer.

Test

Everything seems to be going well, but just remind myself that I need to restart the P5 serial control after changing the arduino code.

When I tried the menu of serial port, I met a problem. My computer( dell laptop) seems like just can detect one serial port. So I can't change the port, and the function will not be trigger. "(portSelector.changed(mySelectEvent);"

Thanks for Shirley, she quickly add a code line for me “portSelector.option('--');” So that my menu has two option and work!

To be honest, even I success try the example, but I'm not sure that I can understand every code line in P5.js. Especially the call back part. I don't know why to do that, but seems like if I want to connect the P5 and Arduino, I just use that code.

bottom of page