Serial I/O from mcsim to device connected over USB to host computer #933
-
Background
GoalMy goal is to use my M5Paper as an I/O device for my Playdate handheld console, using serial over USB. This kind of comms is already possible using a PC. I guess the first step is to create a small app to do serial I/O over USB from/to simulator to/from device? Any pointers or help appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
|
The Moddable SDK is moving to using ECMA-419 for I/O, which includes serial. The ECMA-419 APIs are well supported on ESP32 and ESP8266, so you are set there. On macOS, there are implementations of ECMA-419 Serial, TCP, UDP, and Listener I/O. Because ESP32 and macOS are very different operating systems,, there are differences in configuration. The APIs, however, are identical. I built a small exampleI starting from the serial echo example. The modified version is configured for macOS and also outputs received bytes to the xsbug console. Here's the import Serial from "embedded:io/serial";
import TextDecoder from "text/decoder";
const decoder = new TextDecoder;
new Serial({
device: "/dev/cu.usbserial-0001",
baud: 74880,
format: "buffer",
onReadable: function(count) {
const buffer = this.read();
this.write(buffer);
trace(decoder.decode(buffer, {stream: true}), "\n");
},
});Here's the {
"include": [
"$(MODDABLE)/modules/io/manifest.json",
"$(MODDABLE)/modules/data/text/decoder/manifest.json"
],
"modules": {
"*": "./main"
}
}To test, I connected an ESP8266 to a USB port on my Mac (via a Moddable Programmer Serial-to-USB bridge) and hit the reset button to generate some bytes (the boot-loader's baud rate on ESP8266 is an unusual 74880). Adjust the |
Beta Was this translation helpful? Give feedback.
The Moddable SDK is moving to using ECMA-419 for I/O, which includes serial. The ECMA-419 APIs are well supported on ESP32 and ESP8266, so you are set there.
On macOS, there are implementations of ECMA-419 Serial, TCP, UDP, and Listener I/O. Because ESP32 and macOS are very different operating systems,, there are differences in configuration. The APIs, however, are identical.
I built a small exampleI starting from the serial echo example. The modified version is configured for macOS and also outputs received bytes to the xsbug console. Here's the
main.jsscript: