pcomp help session: serial communication

Arduino

  • Serial.write(65): sends one byte (encodes in binary)
    • sends 65
  • Serial.print(65): sends two bytes (sends as a string)
    • sends 54 53
  • serial monitor interprets everything as ASCII

p5

  • callback functions need to be defined in draw()
  • Serial.read() with Serial.write()
  • Println() + readLine()
    • readLine() looks for println() to execute

Steps:

  1. Serial print values from Arduino
  2. Run p5.serialcontrol app
  3. Include serial.js library in index.html of sketch
  4. create serial object in p5 and define callback functions

 


Arduino code

 


p5 code

Leave a Reply

Your email address will not be published. Required fields are marked *