Intro to Asynchronous Serial Communications

IMG_6202.GIF

IMG_6203.GIF

IMG_6204.GIF

IMG_6205.GIF

Serial Input to P5.js

Sensor Value: Undefined

I was confused about some problems that happened during my running program. I understand that I should have P5 closed every time I make changes in Arduino. However, the error message would still come out sometimes. Although I did succeed for few times, I still have no idea what the error message means and why it happens.

IMG_6208.GIF

In the failed version, the serial console can work as I turned the potentiometer; however, the screen still showed undefined.

Screen Shot 2021-10-20 at 1.47.36 PM.png

I don't understand the message.

IMG_6211.GIF

IMG_6212.GIF

The succeeded version happened when I turned off my P5, re-loaded Arduino, re-opened P5, re-scanned the port. After a whole set of restarts, it worked.

Class note - solved questions:

  1. Why the number always shows between 48 - 57:

    A: The number here is not the number value, instead, it is the character value; "1" → 48

A: 

```jsx
//serial.write; serial.read; serial.print
function serialEvent() {
	var input = serial.readLine();
	consle.log(input);
if (input) {
	receivedData = input;
	}
}
```
  1. Answers to my question

    A: The same problem as P5 can not read from Arduino; The solution should be when use serial.read in Arduino, use serial.write in P5.

    B: Can't find the client (P5 serial control can't connect with p5.js); the solution is might to just restart and re-connect the whole set.

A:

//DO NOT DO ANYTHING UNTIL I ENTER A CHARACTER
if (serial.available() > 0 )
int inChar = serial.read()
serial.write (inChar);
if (inChar = 32) {
	digitalWrite(LED.BUILTIN , HIGH)
}
else

Project 2 Ideas