UART - sending from pyboard to PC
UART - sending from pyboard to PC
Good evening!
I'm a proud newbie of a pyboard and would like to use it to sample a signal from the ADC, do basic processing on it and then send some resulting data from the pyboard to a connected PC (via the USB cable) to be processed/displayed there using python. While I have quite some experience with Python, I've never used uart (or similar stuff) bevore...
Given the UART example on the webpage, I've managed to send strings from my PC from python to the pyboard. Unfortunately I fail to do it the other way round.
On the pyboard, I do:
import pyb
import select
u = pyb.UART(1, 9600)
u.write('teststring')
On my pc in ipython:
import serial
ser = serial.Serial('/dev/ttyACM0',9600, timeout=1)
ser.readall()
-> The last command (readall) returns an empty string (same for readline(), readlines()) adding '\n' to the string etc...
Could someone pl. help me and fix this simple example/ point me to a working example?
Thanks!
I'm a proud newbie of a pyboard and would like to use it to sample a signal from the ADC, do basic processing on it and then send some resulting data from the pyboard to a connected PC (via the USB cable) to be processed/displayed there using python. While I have quite some experience with Python, I've never used uart (or similar stuff) bevore...
Given the UART example on the webpage, I've managed to send strings from my PC from python to the pyboard. Unfortunately I fail to do it the other way round.
On the pyboard, I do:
import pyb
import select
u = pyb.UART(1, 9600)
u.write('teststring')
On my pc in ipython:
import serial
ser = serial.Serial('/dev/ttyACM0',9600, timeout=1)
ser.readall()
-> The last command (readall) returns an empty string (same for readline(), readlines()) adding '\n' to the string etc...
Could someone pl. help me and fix this simple example/ point me to a working example?
Thanks!
Re: UART - sending from pyboard to PC
I use the USB_VCP module to communicate with the PC over USB.
http://docs.micropython.org/en/latest/l ... B_VCP.html
You use it much like UART only it goes back to the PC over the COM port the uPython board is assigned.
http://docs.micropython.org/en/latest/l ... B_VCP.html
You use it much like UART only it goes back to the PC over the COM port the uPython board is assigned.
End of line...
Re: UART - sending from pyboard to PC
Hi,
Thanks a lot! I'll try it once I'm back home to play with my pyboard.
Do you maybe happen to have a short example illustrating the commands on the pyboard and PC?
Thanks a lot! I'll try it once I'm back home to play with my pyboard.
Do you maybe happen to have a short example illustrating the commands on the pyboard and PC?
Re: UART - sending from pyboard to PC
@ulrich, the port /dev/ttyACM0 is bind to the virtual serial line over usb; UART(1) is a real serial line, connected to X9/X10:
http://micropython.org/resources/pybv10-pinout.jpg
If you want to test this real serial line, you need to connect it to your PC, through a FTDI cable, for example (USB-TTL, not USB-RS232).
http://micropython.org/resources/pybv10-pinout.jpg
If you want to test this real serial line, you need to connect it to your PC, through a FTDI cable, for example (USB-TTL, not USB-RS232).
Frédéric
Re: UART - sending from pyboard to PC
Hi,
Thanks for your replies. I'm not back home and eager to tackle this issue again!
I'm slowly learning... SO UART is actually not what I'm looking for. I have no crutial real time requirements or lot of data... All I want is to send a few strings to a python running on my pc.
I'm now trying on my pyboard:
u = pyb.USB_VCP()
u.send('sending up\n', *, timeout=5000)
and on my pc:
import serial
ser = serial.Serial('/dev/ttyACM0',9600, timeout=1)
while True:
rcv = ser.readlines()
print(rcv)
but I still don't receive anything...
Do you have any other ideas?
Thanks,
Ulrich
Thanks for your replies. I'm not back home and eager to tackle this issue again!
I'm slowly learning... SO UART is actually not what I'm looking for. I have no crutial real time requirements or lot of data... All I want is to send a few strings to a python running on my pc.
I'm now trying on my pyboard:
u = pyb.USB_VCP()
u.send('sending up\n', *, timeout=5000)
and on my pc:
import serial
ser = serial.Serial('/dev/ttyACM0',9600, timeout=1)
while True:
rcv = ser.readlines()
print(rcv)
but I still don't receive anything...
Do you have any other ideas?
Thanks,
Ulrich
Re: UART - sending from pyboard to PC
Have a look at the pyboard.py script, which is uses to transmit and run scripts to pyboard...
Frédéric
Re: UART - sending from pyboard to PC
readline() reads a single line from the file.ulrich wrote: while True:
rcv = ser.readlines()
print(rcv)
readlines() reads ALL of the lines from the file before returning. The serial port doesn't really have an end-of-file, so readlines may never return.
Here's a serial terminal program that I wrote for llinux. It uses udev to detect when the serial port shows up and goes away, and then uses pyserial to read/write the data a single character at a time.
It also uses termios to put the serial port in raw mode.
https://github.com/dhylands/usb-ser-mon ... ser-mon.py
Re: UART - sending from pyboard to PC
Hi,
Thanks for all the hints -unfortunately my ignorance about USB, protcolls etc is still too big... I've used this occasion to try to learn about it now...
I've had a look at the pyboard.py - while it contains stuff close to what I need, it's not quite what it want...
Also the usb-erial code that was mentioned did not solve the problem (I've tried all combinations of read, readline, readlines, readall,...)
I've now noticed something, that seems odd: If I enter on my pyboard
usb = pyb.USB_VCP()
usb.send(b'testup')
it returns "testup6" although the command should only return the numebr of bytes (and not my string)
If I try to send an integer only, the return value is "1" - which seems to be correct only the bytes (but still nothing readable on my PC...
Cheers,
Ulrich
Thanks for all the hints -unfortunately my ignorance about USB, protcolls etc is still too big... I've used this occasion to try to learn about it now...
I've had a look at the pyboard.py - while it contains stuff close to what I need, it's not quite what it want...
Also the usb-erial code that was mentioned did not solve the problem (I've tried all combinations of read, readline, readlines, readall,...)
I've now noticed something, that seems odd: If I enter on my pyboard
usb = pyb.USB_VCP()
usb.send(b'testup')
it returns "testup6" although the command should only return the numebr of bytes (and not my string)
If I try to send an integer only, the return value is "1" - which seems to be correct only the bytes (but still nothing readable on my PC...
Cheers,
Ulrich
Re: UART - sending from pyboard to PC
When you do USB.send it's sending the data on the same stream as the reply. So you see 'testup'. Then because you didn't assign the result to a variable it prints the result 6 on the repl which is also on USB_VCP
Re: UART - sending from pyboard to PC
>>> from pyb import UART
>>> uart=UART(3,9600)
>>> pyb.repl_uart(uart)
>>> uart.send('AT+PIN3456')
>>>
>>> y4=pyb.Pin('Y4',pyb.Pin.OUT_PP)
>>> y4.low()
>>> uart.send('AT+PIN3456')
>>>
>>> y4.high()
>>> ERO:0
File "<stdin>", line 1, column 4
SyntaxError: invalid syntax
>>> ERO:0
File "<stdin>", line 1, column 4
SyntaxError: invalid syntax
>>> ERO:0)ERO:0
Is that ERO:0 stuff from Micropython or from the UART? I am trying to send to the JYMCA Bluetooth module. I set the pin high to set the device in AT mode.
>>> uart=UART(3,9600)
>>> pyb.repl_uart(uart)
>>> uart.send('AT+PIN3456')
>>>
>>> y4=pyb.Pin('Y4',pyb.Pin.OUT_PP)
>>> y4.low()
>>> uart.send('AT+PIN3456')
>>>
>>> y4.high()
>>> ERO:0
File "<stdin>", line 1, column 4
SyntaxError: invalid syntax
>>> ERO:0
File "<stdin>", line 1, column 4
SyntaxError: invalid syntax
>>> ERO:0)ERO:0
Is that ERO:0 stuff from Micropython or from the UART? I am trying to send to the JYMCA Bluetooth module. I set the pin high to set the device in AT mode.