Read Data over Serial From PC

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Posts: 2
Joined: Thu Jun 11, 2015 3:20 pm

Read Data over Serial From PC

Postby adrianovrm » Wed Mar 08, 2017 9:17 pm

Well ,

After hours and hours trying to make my Macbook Send Simple String data to my pyboard v1.1 . l ask aid here ... let me explaind in details so :

L wrote the following python program onto
# -- put your code here!
from pyb import UART
import os

uart = UART(1, 9600)
#uart.init(9600, bits=8, parity=None, stop=1)

#if (os.isfile('data.txt')):
#if (isfile('data.txt')):
# print('data.txt')
# f = open('data.txt', 'r')
# f2 = open('dcopy.txt', 'w')
# f2.write(
# f2.close()
f = open('data.txt', 'r')
f2 = open('dcopy.txt', 'w')
f = open('data.txt', 'w')
f.write('tentou ler e nao existia')

led = pyb.LED(2)
while (1 == 1):
# uart.write('a')
if (uart.any() != 0):
led4 = pyb.LED(4)

led3 = pyb.LED(3)

just learning how use it . l was expect that after receive some bytes . the blue led of the board comes on.. then l use de coolterm program to connect to the device and send some string to pyboard .. well, l ve checked all the paramters of serial, 9600 8 n1 , equal at both sides.. but when l push control ctrl-c onto keyboard of macbook , the coolterm shows an keyboard interrupted and keep the REPL onto screnn working. before the ctrl-d the collterm show tx led as it was sending comands but the pyboard doenst shows the blue led . if l remove the uart.any line, the blue led lights, so my conclusion is that l m not receiving any bytes over usb/serial and l dont lnow how to sokve it , at arduino this is works like a charm, l getting crazy to make this work at pyboard world, simples is a much more powerful enviroment and l wanna leran and use.

Another details to help , this is my

# -- run on boot-up
# can run arbitrary Python, but best to keep it minimal

import pyb
#pyb.main('') # main script to run after this one
pyb.usb_mode('CDC+MSC') # act as a serial and a storage device
#pyb.usb_mode('CDC+HID') # act as a serial device and a mouse

so guys , any magical tips ?

L tried at windows too , after install the *.inf driver, but had the same issues ...

User avatar
Posts: 2253
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada

Re: Read Data over Serial From PC

Postby dhylands » Thu Mar 09, 2017 5:44 am

If I'm reading this correctly, you're trying to send data over the same link as the REPL.

On the pyboard, the USB-serial isn't a UART. You can use pyb.USB_VCP() to get access to the virtual port associated with the USB-serial link (from the pyboard side of things): ... B_VCP.html

To use a UART, you need to connect a logic-level serial adapter to one of the UARTs. See

Connect Tx from the serial adapter to Rx on the pyboard, Rx from the serial adapter to Tx on the pyboard and also connect GND from the serial adapter to the pyboard. An example of a logic level serial adapter is something like this:

I wrote some code which talks between the host and the pyboard over the USB-serial link here:

Posts: 2
Joined: Thu Jun 11, 2015 3:20 pm

Re: Read Data over Serial From PC

Postby adrianovrm » Thu Mar 09, 2017 1:05 pm

Yes, l trying do exactly that ..
Communicate with pyboard in same way l used to with arduino and its ide, cause l m a newbie at pyboard.
l will try yours tips so, and will return here to report you my results.. thanks for your attention in advance ..

Return to “General Discussion and Questions”

Who is online

Users browsing this forum: mahmud, microPyforMy and 4 guests