Tuesday, 25 February 2014

From Python to Teensy!

Now I have Teensy reading from serial it's probably worth trying to put something there to receive.

I took the code in blog post on the forum's for Teensy and hacked it a bit to only send a simple string via the USB.

Here's my Code:
 #!/usr/bin/python2.7  
 import numpy as np  
 import sys  
 import serial, time  
 from serial.tools import list_ports  
 if __name__ == "__main__":  
   ports = [port[0] for port in list_ports.comports()]  
   print "Using serial port %s" % (ports[-1])  
   serial = serial.Serial(ports[-1],baudrate=9600, timeout=0, writeTimeout=1)  
   serial.flushInput()  
   serial.flushOutput()  
   data = sys.argv[1]  
   print data  
   try:  
     start = time.time()  
     iter = 0  
     serial.write(data)  
   except KeyboardInterrupt:  
     serial.close()  

 Here's an animated picture of the message going past:

Of course I need to tidy the python up, handle params properly and check some state but for a few minutes work it's not bad.

No comments:

Post a Comment