Arduino + microStudio? YES!
Hello everyone I want to share with you my experiment, which was crowned with success. Now your projects can get additional features thanks to my library, which adds Web Serial support.
The library itself: https://microstudio.dev/i/Romero/serialport/
Video with a demonstration: https://youtu.be/yJVV-omELXs?si=CUTLzsYGUxFMgO_6
Library Functions:
- Connecting to the device:
connect()
- Disconnecting from the device:
disconnect()
- Changing the port speed (you can also change it while the program is running):
setBaudRate()
- Data transfer:
write()
- Receiving data:
read()
- Using the received data:
getRawReceivedData()
Update
- remove the
getRawReceivedData()
function - added the
getBinaryData()
function - added the
getString Data()
function - added a parser -
parseReadLine()
Not relevant!(At the moment there is only getRawReceivedData(), it returns the raw data, then I will rename it to getReceivedData() or leave it and add it — I have problems implementing buffering with processing “\n” “\r”, I do not know, I cannot do it so that, what comes in is adequately displayed in DrawText, and I want to make it as universal as possible.)
If you have any tips and/or suggestions on how to do this, I will be glad to hear them!
Limitations:
Doesn't work with microScript: Unfortunately, I couldn't get the library to work with microScript. - Not relevant! I made a separate version for microScript: https://microstudio.dev/i/Romero/serialportapiformicroscript/
Not all browsers support Web Serial: This is a limitation that cannot be circumvented. For more information, see the compatibility table: https://developer.mozilla.org/en-US/docs/Web/API/Web_Serial_API#browser_compatibility or https://caniuse.com/web-serial
No support on mobile devices and tablets: It is not possible to connect to the browser application via USB on mobile devices and tablets. This limitation is due to the lack of Web Serial support on mobile browsers. (I haven't tried Bluetooth yet, but judging by the fact that you can connect to the espruino web ide via Bluetooth from Android, there is a high probability that it will work here too.)
Work only in a separate tab: This only works in a separate browser tab (because the window that you see while writing the code works in “protected mode” or something like that)
Working in an exported project: If you exported your project to HTML5, it will work, but again, see which browser you are using. If you exported your project to something else, then it won't work at all, at least for now it does.
If @gilles is interested in this and he can implement it technically, then the situation may change. After all, there are applications on PC and Android that support this (I can't say about macOS and iOS — I don't have them). I think that if desired, something could be implemented here.