Communication between Pc and Metro express M0

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Lorlo
 
Posts: 4
Joined: Thu Dec 22, 2022 12:04 pm

Communication between Pc and Metro express M0

Post by Lorlo »

Hello,
as the title says i am looking for a way to establish a communication between the metro and my pc via usb.
I have tried it with thr serial lib on my pc and supervisor on the Metro i get bits through and can control the led that way

if supervisor.runtime.serial_bytes_available:
data = input().strip()

i tried it with the busio lib

uart = busio.UART(board.TX, board.RX, baudrate=115200)

but i can't get anything through i think because i can only control tx rx pin 1 and 0 with it.

is there like in arduino a library for serial communication or is there another way.
I could switch to the arduino ide and achieve this from there but would love to write it in python directly

thanks in advance

User avatar
adafruit_support_carter
 
Posts: 29159
Joined: Tue Nov 29, 2016 2:45 pm

Re: Communication between Pc and Metro express M0

Post by adafruit_support_carter »

Try enabling the secondary data serial device:
https://learn.adafruit.com/customizing- ... ta-3096590

That'll create a new COM port you can connect to and communicate over.

You'll need to write receive/transmit code on the CircuitPython side to handle your specific communication scenario.

User avatar
Lorlo
 
Posts: 4
Joined: Thu Dec 22, 2022 12:04 pm

Re: Communication between Pc and Metro express M0

Post by Lorlo »

Thanks for your answer

So you mean I need to open usb cdc.

And because data is not open it only displays None

Does that work when I run this code:

usb_cdc.enable(console=True, data=True) # Enable console and data

User avatar
adafruit_support_carter
 
Posts: 29159
Joined: Tue Nov 29, 2016 2:45 pm

Re: Communication between Pc and Metro express M0

Post by adafruit_support_carter »

You enable the feature per the guide. See guide for what code is needed, where it should be located, etc.

You then write code to use it once enabled. In the CircuitPython code, you'd access it using usb_cdc.data:
https://docs.circuitpython.org/en/lates ... b_cdc.data

This guide has an example usage that might help. This is the code on the CircuitPython side:
https://learn.adafruit.com/diy-trinkey- ... cuitpython
This is an example using PySerial on the host computer side:
https://learn.adafruit.com/diy-trinkey- ... iving-data

User avatar
Lorlo
 
Posts: 4
Joined: Thu Dec 22, 2022 12:04 pm

Re: Communication between Pc and Metro express M0

Post by Lorlo »

as i now understand i need to create a boot.py file
in circutpython with the code
import usb_cdc
usb_cdc.enable(data=True)

is there a library i have to load for usb_cdc or because when i upload the boot.py and do a hard reset i don't see a new comport

thanks for the effort

User avatar
Lorlo
 
Posts: 4
Joined: Thu Dec 22, 2022 12:04 pm

Re: Communication between Pc and Metro express M0

Post by Lorlo »

and do I have to activate this every time I boot or after I do it once I can delete boot.py
thanks

User avatar
adafruit_support_carter
 
Posts: 29159
Joined: Tue Nov 29, 2016 2:45 pm

Re: Communication between Pc and Metro express M0

Post by adafruit_support_carter »

Correct, to enable the feature, edit boot.py and reset. You do not need to do that every time. The boot.py contents persist and are checked at each boot.

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”