Notes


Flow Control: Call and Response

Sometimes the sender sends faster than the receiver can read, then the receiver program slows down as the serial buffer fills up. So we need to do some flow control implements.

<aside> 📌 Call-and-response method is a simple way: the sending program only sends when it’s told to do so, and the receiving program has to request new data every time it finishes reading what it’s got.

</aside>

Advantages Of Raw Binary VS ASCII

If the receiving program is well-suited to convert strings to numbers, for debugging purposes >> ASCII is more readable

If it’s more challenging to read a multiple byte string/values are less than 255 >> Binary is more efficient

Limitations Of Raw Punctuation (VS Call-and-Response)

Labs


Lab: Two-Way (Duplex) Serial Communication Using An Arduino and P5.js

Lab Diagram

I used two potentiometers and a pushbutton to instead the ADXL335 accelerometer module in this lab as following

(Made with Tinkercad)

(Made with Tinkercad)

Arduino Code

const int buttonPin = 2;   
 
void setup() {
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
}
 
void loop() {
  // read the first potentiometer:
  int sensor1 = analogRead(A0);
  Serial.print(sensor1);
  Serial.print(",");
 
  // read the first potentiometer:
  int sensor2 = analogRead(A1);
  Serial.print(sensor2);
  Serial.print(",");
 
  int button = digitalRead(buttonPin);
  Serial.println(button);
}

Receive the data in P5.js