The arduino code contains a delay(1) to slow down and stabilize the ADC. Why should I stabilize the ADC?

Difficulties I am facing: Potentiometer reading is unstable and encrypted. Realized the difference between the Serial.write() & Serial.println(). Serial.write() is used for writing data (sending it digitally) to p5.js. Serial.println() is used for writing data to the serial monitor. 

Note to self: Only one port at a time can access a serial port. That means that when you want to reprogram your Arduino from the Arduino IDE, you should to stop your sketch in the browser window to do so. Then, restart the browser sketch when you’re done reprogramming the Arduino. You don’t need to quit the Arduino IDE each time, because it knows to release the serial port when it’s not programming. However, you do need to close the Serial Monitor in the Arduino IDE when you are using WebSerial in the browser. 

Note to self: The p5.webserial library uses events and callback functions as well. It can listen for the following serialport events:

noport – when there is no selected serial port
portavailable – when a serial port becomes available
data – new data arrives in a serial port
close – the serial port is closed
requesterror – something goes wrong when you request a serial port.

Note to self: 'p5.WebSerial Sketch Checklist'

1) In the HTML file, include the p5.webserial library
2) In the global variables of the sketch,
- make a new instance of the library
- include a port selector button or some way to invoke the serial port chooser dialogue box
3) In the setup:
- Make sure WebSerial is supported in this browser
- Include a call to serial.getPorts() to check for available ports.
- include serial.on() listeners for these events:
* noport
* portavailable
* data
* close
* requesterror
- include navigator listeners for connect and disconnect
4) Define handler functions for all of the events above. Most of these can be simple alerts or console.log messages
5) Customize the function that responds to the data listener (usually called serialEvent() in these examples)
6) Decide when and how you’ll send serial data out, as you’ll see in the other p5.webserial labs.

The last two items of this list are the ones on which you’ll spend most of your time. The rest of the items are things you’re likely to copy from one sketch to another.

Sensor input into p5.js seems to work, but has a huge lag when turning potentiometer. Tried to increase frameRate() but issue still persisted. Seems to work instantaneously on sketch version on GitHub. Is it because the operating system keeps the incoming serial data in a buffer, and P5.js isn’t reading and printing it as fast as Arduino is sending it? Why would it be any different with the GitHub sketch?

Note to self: You may be wondering why you’re mapping the sensor value or dividing it by 4 in the Arduino sketch above. That’s because in order to send the sensor value as a single byte, it must be between 0 and 255, or no more than 28 bits.

How can I re-structure the function openPort() in terms of the serial.open() function to change baudrate (9600) if required? In what context should I declare 'portName'?

Why are we still mapping the values read from the potentiometer from 0 to 255 when sending the data as an ASCII-encoded numeric string from the microcontroller?

You may also like

Back to Top