Is it possible to use the Serial extension in MakeCode beta to communicate with a program running on the host computer over the USB cable connected to the CPX for power and downloads?
Or does Serial only work with a separate USB data cable connected to RX/TX pads (A6/A7)?
All of the tutorials I perused only show the connection being made with a USB serial converter cable or board.
Thanks.
Serial comm over USB with CPX
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- mikeysklar
- Posts: 13825
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Serial comm over USB with CPX
@adavid7,
I'm under the impression you can use the "console" function to write output over the USB connected CPX to your PC.
I'm under the impression you can use the "console" function to write output over the USB connected CPX to your PC.
https://makecode.adafruit.com/reference/consoleThe Adafruit Circuit Playground Express can read data from and write data to another computer or device with a serial connection using USB. To use serial communication between your board and MakeCode, you need the MakeCode for Adafruit app for Windows 10 and a USB cable.
You can also write data to an output log with the console functions without having to use a serial connection
- adavid7
- Posts: 120
- Joined: Fri Jul 04, 2014 7:32 pm
Re: Serial comm over USB with CPX
Right. Yes, with the Chrome web USB feature that allows you to pair the CPX with MakeCode to automatically download code to the board, you can also have MakeCode receive the console log messages from the board and display them in the browser.
OK, so let me reframe my question:
Has anyone used a program on a Mac other than MakeCode in the browser to receive the console messages?
For instance, this tutorial https://learn.adafruit.com/welcome-to-c ... -and-linux talks about using the "screen" utility to do that, but I have been unable to get that to work.
Ultimately, I would like to use https://editor.p5js.org to interact with the CPX using its serial library.
OK, so let me reframe my question:
Has anyone used a program on a Mac other than MakeCode in the browser to receive the console messages?
For instance, this tutorial https://learn.adafruit.com/welcome-to-c ... -and-linux talks about using the "screen" utility to do that, but I have been unable to get that to work.
Ultimately, I would like to use https://editor.p5js.org to interact with the CPX using its serial library.
- mikeysklar
- Posts: 13825
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Serial comm over USB with CPX
@adavid7,
I use the screen utility to connect to CircuitPython programs quite a bit from my mac.
Can you show me the output of the following when your CPX is plugged into your machine via USB:
Are you using the serial write command to output your data to the console?
https://maker.makecode.com/reference/serial
I use the screen utility to connect to CircuitPython programs quite a bit from my mac.
Can you show me the output of the following when your CPX is plugged into your machine via USB:
Code: Select all
ls -lrt /dev/tty.usb*
https://maker.makecode.com/reference/serial
- adavid7
- Posts: 120
- Joined: Fri Jul 04, 2014 7:32 pm
Re: Serial comm over USB with CPX
Even before trying any code, here is the serial port info:
With the CPX in download mode (all NeoPixels green after a click of the reset button):
But when an app is running (after another click of the reset button), no device is online:
This is with just the USB cable plugged in to the CPX (the standard one for power and downloading).
I have been able to use the screen utility, but only with the USB to Serial cable: https://www.adafruit.com/product/954, not over the regular USB cable. Here is code that does that and works with screen: https://makecode.com/_EEF3yDT5d9j7. If that cable is plugged in, here is its port:
and then screen displays all of the console log messages issued from MakeCode.
So, my question is whether it is actually possible to connect to a serial program on the Mac over the regular USB cable?
Thanks!
With the CPX in download mode (all NeoPixels green after a click of the reset button):
Code: Select all
andy:~$ ls -lrt /dev/tty.usb*
crw-rw-rw- 1 root wheel 20, 4 Feb 8 15:14 /dev/tty.usbmodem40131101
Code: Select all
andy:~$ ls -lrt /dev/tty.usb*
ls: /dev/tty.usb*: No such file or directory
I have been able to use the screen utility, but only with the USB to Serial cable: https://www.adafruit.com/product/954, not over the regular USB cable. Here is code that does that and works with screen: https://makecode.com/_EEF3yDT5d9j7. If that cable is plugged in, here is its port:
Code: Select all
andy:~$ ls -lrt /dev/tty.usb*
crw-rw-rw- 1 root wheel 20, 4 Feb 8 15:28 /dev/tty.usbserial-4013130
So, my question is whether it is actually possible to connect to a serial program on the Mac over the regular USB cable?
Thanks!
- adavid7
- Posts: 120
- Joined: Fri Jul 04, 2014 7:32 pm
Re: Serial comm over USB with CPX
PS: I'm not using serial write, but "serial attach to console"
- mikeysklar
- Posts: 13825
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Serial comm over USB with CPX
@adavid7,
Thanks for confirming that screen is working fine with the USB console cable breakout option. Also the /dev/tty.usb* is present unless in bootloader mode.
I do see people using the micro:bit to get a real serial console with OS/X and accessing it via screen. They are using "serial write". Do you think if you try serial write that the /dev/tty.usbmodem* device might reappear as the code is executing (rather than just in bootloader mode)? Seems worth a try since it works on a related piece of hardware.
https://support.microbit.org/support/so ... a-computer
Thanks for confirming that screen is working fine with the USB console cable breakout option. Also the /dev/tty.usb* is present unless in bootloader mode.
I do see people using the micro:bit to get a real serial console with OS/X and accessing it via screen. They are using "serial write". Do you think if you try serial write that the /dev/tty.usbmodem* device might reappear as the code is executing (rather than just in bootloader mode)? Seems worth a try since it works on a related piece of hardware.
https://support.microbit.org/support/so ... a-computer
- adavid7
- Posts: 120
- Joined: Fri Jul 04, 2014 7:32 pm
Re: Serial comm over USB with CPX
I'll give it a try, thanks.
- adavid7
- Posts: 120
- Joined: Fri Jul 04, 2014 7:32 pm
Re: Serial comm over USB with CPX
After an enormous amount of time trying and testing many options for serial comm using MakeCode, here is my conclusion. I am wondering if you might be able to confirm this diagnosis, @mikeysklar?
While I can successfully use the serial extension in MakeCode with the separate USB to TTL Serial Cable (https://www.adafruit.com/product/954) connected to the CPX RX/TX pins (A4/A5), I have completely failed at doing that same operation over the normal USB cable connected to the laptop for power and downloading.
I can do this exact operation in the Arduino IDE with the CPX over the host USB connection. In the Arduino IDE, however, you must close the serial monitor window in order to do this. Otherwise the host computer "owns" that serial port and the host app that tries to read/write serial data (say p5.js, or even a simple app like the Unix "Screen" utility in a macOS Terminal shell) is unable to connect because the IDE has that serial port attached to it. Once you close the Serial Monitor window, the port is released, and another app is free to use it.
My hypothesis is that in MakeCode, there is no way to have that browser app release the ownership (attachment) of the serial port. I believe this is because it needs to retain the connection so that when the CPX is paired with MakeCode using the WebUSB feature of Chrome, it can show the "Console Log DEVICE" in addition to the "Console Log SIMULATOR."
I don't know enough about browser code dev to know how to find out what serial ports are "owned" by a browser tab, but if there is a way to do that, I could likely verify my hypothesis.
If there is no way to disable the "Console Log DEVICE" feature of MakeCode, and thus have the browser release the serial port connected to the CPX, then I do not think that serial comm over the regular USB cable is possible.
Does that make sense? Can you confirm that?
Thanks,
.Andy
While I can successfully use the serial extension in MakeCode with the separate USB to TTL Serial Cable (https://www.adafruit.com/product/954) connected to the CPX RX/TX pins (A4/A5), I have completely failed at doing that same operation over the normal USB cable connected to the laptop for power and downloading.
I can do this exact operation in the Arduino IDE with the CPX over the host USB connection. In the Arduino IDE, however, you must close the serial monitor window in order to do this. Otherwise the host computer "owns" that serial port and the host app that tries to read/write serial data (say p5.js, or even a simple app like the Unix "Screen" utility in a macOS Terminal shell) is unable to connect because the IDE has that serial port attached to it. Once you close the Serial Monitor window, the port is released, and another app is free to use it.
My hypothesis is that in MakeCode, there is no way to have that browser app release the ownership (attachment) of the serial port. I believe this is because it needs to retain the connection so that when the CPX is paired with MakeCode using the WebUSB feature of Chrome, it can show the "Console Log DEVICE" in addition to the "Console Log SIMULATOR."
I don't know enough about browser code dev to know how to find out what serial ports are "owned" by a browser tab, but if there is a way to do that, I could likely verify my hypothesis.
If there is no way to disable the "Console Log DEVICE" feature of MakeCode, and thus have the browser release the serial port connected to the CPX, then I do not think that serial comm over the regular USB cable is possible.
Does that make sense? Can you confirm that?
Thanks,
.Andy
- mikeysklar
- Posts: 13825
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Serial comm over USB with CPX
Andy,
Your summary seems accurate to me.
Perhaps this is worth creating an issue for and let the experts chime in on options to release the console.
https://github.com/microsoft/pxt-adafruit/issues
Your summary seems accurate to me.
Perhaps this is worth creating an issue for and let the experts chime in on options to release the console.
https://github.com/microsoft/pxt-adafruit/issues
Please be positive and constructive with your questions and comments.