P5.js as a web-based language that can be used with Arduino to allow a fast exchange of information between Arduino and a website.
...
If everything works you are (almost) set! 🔥
BE CAREFUL! If you have Serial port monitor open the connection is going to break up.
P5.js to Arduino
Download this file, unzip it and open the folder in VS Code:
View file | ||
---|---|---|
|
File → Open... → p5Arduino
Your screen should look like this:
...
...
To connect with the serial we can either use serial.autoConnectAndOpenPreviouslyApprovedPort(serialOptions);
, to connect with already connected port or serial.connectAndOpen(portInfo, serialOptions);
, to open the port menu
serial.on
subscribes to the events of the Serial class and handles the proper communication between WebSerial API and Arduino.
serialWriteTextData()
and serialWriteNumberData()
uses serial.writeLine()
to write values to Arduino. Notice the extra “<“ and “>” signs, which mark the beginning and end of a message.