Week7 – Serial Communication

Interpreting Serial Data

1. Parsing Text in Arduino

When getting a string of numbers separated by commas, using Serial.parseInt()

int x = Serial.parseInt(); int y = Serial.parseInt(); Serial.print(“x = “); Serial.print(x); Serial.print(“, y = “); Serial.println(y);

  Checking for the right number of bytes:

34, 56, 78 carriage return newline (Comma Separated Values (CSV)) 10 bytes in total

   (Serial.available() > 10)

Lab 1:

1. ASCII vs. Binary  Send the data in many formats

w7-9

2. Send the values for 3 sensors: formatting multiple data

w7p10

3. Handshaking

w7p11

4. Advantages of Raw Binary and ASCII

Raw Binary is more efficient, and readable in Arduino; ASCII is more readable for debugging and easy to use when writing in JavaScript.

5. Advantages of Punctuation and Call-and-Response

The punctuation method for sending multiple serial values may seem more straightforward, but in some cases, the receiver would interpret data as punctuation, not as a sensor value. The call-and-response method could prevent the sketch from slowing down in p5js.

Lab 2:

1. Input

 

2. Draw a graph with the sensor value:

 

3. Reading data as a string. 

 

Change code in Arduino from Serial.write() to Serial.println();  

*note: readLine() is the same as readStringUntil(‘\r\n’);

Lab 3:

1 Output: keyPressed & mousePressed

 

2 send a specific numeric value

w7p12

Leave a Reply

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