I am working on getting the serial communication to work between a Microbit and p5.js. I’m pretty sure the Microbit side of the project is working since I am able to see the serial write in my terminal.
On the p5.js side, I’ve been following the available documentation and believe the library, variables, and functions are set up correctly however it’s not working.
Yes, I see the server is connected and serial port is open messages. The serial message I’m sending from the Microbit do not show up in the inData variable (I get “undefined”). Printing the inData in the console log also gets me undefined. Using the if(serial.available()>0) - executes none of the text. I also tried to run it using the web editor and in multiple browsers.
I do not see any of the serial data sent from the Microbit on p5.serialcontrol app. I can, however, see the data that is sent when using screen from the Terminal. Any ideas why it would work in Terminal and not elsewhere?
Also about serial.readStringUntil('\r\n'). \r\n is line break symbol. But I think that write number function will not add it. Probably you should convert it to string first and then send as a string. (If you want to receive data with line breaks only).
Thanks @dector for the tips and help. I tried the above with still no serial data coming through (nothing in text or console log). Also tried to re download and run the basic examples provided from local files without luck. I’m starting to think it might be related to WebUSB and permissions (https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web)? Although it’s not working in Safari or Firefox either. I’ll go down this rabbit hole a little and perhaps try and find a PC and Arduino to see if that makes a difference.
It works! I think the main culprit may have been the firmware version I was running. The older firmware doesn’t have WebUSB. Updating to 250 helped. The Microbit also runs at a115200 baudrate so specifying that rate may have helped also: