I have a Micro Python board being used to operate multiple peripheral devices on a product test card via a set of methods in main.py. I would like to automate it by replacing the puTTY console with output from a remote PC running Python via the USB interface.
Remote PC code example:
import serial
import time
PyBoard_port = 'COM3'
class microPy(object):
'''A class to control the PyBoard micro controller used for programming
the DAC, relay drivers and reading data from the ADC on the LTM9057
automated test card.'''
def __init__(self, port=PyBoard_port, baudrate=115200, timeout=0.5):
# Establish the serial connection
self.ser = serial.Serial(port=port, baudrate=baudrate, timeout=timeout)
time.sleep(2)
# New universal function using dictionaries defined in the relay_connections file
def writeCommand(self,command):
self.ser.write(command)
return()
What do I need to make this work?
USB interface to Python program
Re: USB interface to Python program
You need to write some MicroPython code to read/parse the commands coming from the host.
You can either use a read UART, along with a USB-to-TTL-serial adapter, or you can read from the USB-serial.
The docs for the USB serial interface are here:
http://docs.micropython.org/en/latest/p ... B_VCP.html
and the UART here:
http://docs.micropython.org/en/latest/p ... .UART.html
If you're sending binary data over the USB serial link, then you'll want to make sure you call setinterrupt(-1) to disable the Control-C parsing.
You can either use a read UART, along with a USB-to-TTL-serial adapter, or you can read from the USB-serial.
The docs for the USB serial interface are here:
http://docs.micropython.org/en/latest/p ... B_VCP.html
and the UART here:
http://docs.micropython.org/en/latest/p ... .UART.html
If you're sending binary data over the USB serial link, then you'll want to make sure you call setinterrupt(-1) to disable the Control-C parsing.
Re: USB interface to Python program
Not having luck with that, however I was pointed to something on github that looks exactly like what I want:
https://github.com/micropython/micropyt ... pyboard.py
However when I try to run it I get:
Traceback (most recent call last):
File "C:\Users\markmi071556\eclipse-workspace\LTM9057_Auto_test\Run_PyBoard.py", line 6, in <module>
pyb = pyboard.Pyboard('192.168.1.1')
File "C:\Users\markmi071556\eclipse-workspace\LTM9057_Auto_test\pyboard.py", line 195, in __init__
self.serial = TelnetToSerial(device, user, password, read_timeout=10)
File "C:\Users\markmi071556\eclipse-workspace\LTM9057_Auto_test\pyboard.py", line 48, in __init__
self.tn = telnetlib.Telnet(ip, timeout=15)
File "C:\Python27\lib\telnetlib.py", line 211, in __init__
self.open(host, port, timeout)
File "C:\Python27\lib\telnetlib.py", line 227, in open
self.sock = socket.create_connection((host, port), timeout)
File "C:\Python27\lib\socket.py", line 575, in create_connection
raise err
socket.timeout: timed out
I've pinged ip 192.168.1.1 and it responds. Thanks for any help.
https://github.com/micropython/micropyt ... pyboard.py
However when I try to run it I get:
Traceback (most recent call last):
File "C:\Users\markmi071556\eclipse-workspace\LTM9057_Auto_test\Run_PyBoard.py", line 6, in <module>
pyb = pyboard.Pyboard('192.168.1.1')
File "C:\Users\markmi071556\eclipse-workspace\LTM9057_Auto_test\pyboard.py", line 195, in __init__
self.serial = TelnetToSerial(device, user, password, read_timeout=10)
File "C:\Users\markmi071556\eclipse-workspace\LTM9057_Auto_test\pyboard.py", line 48, in __init__
self.tn = telnetlib.Telnet(ip, timeout=15)
File "C:\Python27\lib\telnetlib.py", line 211, in __init__
self.open(host, port, timeout)
File "C:\Python27\lib\telnetlib.py", line 227, in open
self.sock = socket.create_connection((host, port), timeout)
File "C:\Python27\lib\socket.py", line 575, in create_connection
raise err
socket.timeout: timed out
I've pinged ip 192.168.1.1 and it responds. Thanks for any help.
Re: USB interface to Python program
What MicroPython board are you using?
My understanding is that the WiPy board runs a telnet server. I didn't think that any of the others did.
How are you invoking pyboard.py?
My understanding is that the WiPy board runs a telnet server. I didn't think that any of the others did.
How are you invoking pyboard.py?
Re: USB interface to Python program
The Micro Python board I'm using has PYBv1.1 printed on it's underside. Just trying to get the sample code running:
import pyboard
# pyb = pyboard.Pyboard('/dev/ttyACM0')
pyb = pyboard.Pyboard('192.168.1.1')
pyb.enter_raw_repl()
pyb.exec_('pyb.LED(1).on()')
pyb.exit_raw_repl()
Both pyboard.Pyboard('/dev/ttyACM0') and pyb = pyboard.Pyboard('192.168.1.1') fail similarly.
import pyboard
# pyb = pyboard.Pyboard('/dev/ttyACM0')
pyb = pyboard.Pyboard('192.168.1.1')
pyb.enter_raw_repl()
pyb.exec_('pyb.LED(1).on()')
pyb.exit_raw_repl()
Both pyboard.Pyboard('/dev/ttyACM0') and pyb = pyboard.Pyboard('192.168.1.1') fail similarly.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: USB interface to Python program
It works here with a USB connected Pyboard under Linux using
However it seems you're running Windows. Device names are different under Windows and I'm sure the key is to use the correct serial port name. The docs here http://docs.micropython.org/en/latest/p ... /repl.html indicate how to get the Pyboard running under Windows, and how to determine the name of the serial port on your PC.
It's not evident how
could be expected to work. How is your Pyboard connected to the network?
Code: Select all
pyb = pyboard.Pyboard('/dev/ttyACM0')
It's not evident how
Code: Select all
pyb = pyboard.Pyboard('192.168.1.1')
could be expected to work. How is your Pyboard connected to the network?
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: USB interface to Python program
It's working now. I didn't recognize that the code example was written for Linux, (I'm running on Windows 10). I changed '/dev/ttyACM0' to "COM3' and all is well.
Thanks again for your help.
Thanks again for your help.