In [1]:
%%javascript
IPython.load_extensions('calico-document-tools');



In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from __future__ import division
from __future__ import print_function
import serial
import time

In [2]:
!ls /dev/tty.usbmodem*


/dev/tty.usbmodem1452

In [3]:
!ls /dev/cu.usbmodem*


/dev/cu.usbmodem1452

In [5]:
avariable = 1001
bvariable = 3.145
print("{},{}".format(avariable,bvariable))


1001,3.145

In [8]:
pyboard = serial.Serial('/dev/tty.usbmodem1452', 115200)
temp = []
for i in range(20):
    if i == 0:
        pyboard.flushInput()
    temp.append( pyboard.readline().strip().split(',') )
pyboard.close()

print(temp)


[['12900093 ', ' 3000'], ['13000093 ', ' 4000'], ['13100093 ', ' 5000'], ['13200093 ', ' 6000'], ['13300093 ', ' 7000'], ['13400093 ', ' 8000'], ['13500093 ', ' 9000'], ['13600093 ', ' 0'], ['13700093 ', ' 1000'], ['13800093 ', ' 2000'], ['13900093 ', ' 3000'], ['14000093 ', ' 4000'], ['14100093 ', ' 5000'], ['14200093 ', ' 6000'], ['14300093 ', ' 7000'], ['14400093 ', ' 8000'], ['14500093 ', ' 9000'], ['14600093 ', ' 0'], ['14700093 ', ' 1000'], ['14800093 ', ' 2000']]

In [7]:
pyboard = serial.Serial('/dev/tty.usbmodem1452', 115200)
temp = []
for i in range(25):
    if i == 0:
        pyboard.flushInput()
    temp.append( pyboard.readline().strip().split(',') )
pyboard.close()

print(temp)


[['93 ', ' 8'], ['33400093 ', ' 9'], ['33500093 ', ' 0'], ['33600093 ', ' 1'], ['33700093 ', ' 2'], ['33800093 ', ' 3'], ['33900093 ', ' 4'], ['34000093 ', ' 5'], ['34100093 ', ' 6'], ['34200093 ', ' 7'], ['34300093 ', ' 8'], ['34400093 ', ' 9'], ['34500093 ', ' 0'], ['34600093 ', ' 1'], ['34700093 ', ' 2'], ['34800093 ', ' 3'], ['34900093 ', ' 4'], ['35000093 ', ' 5'], ['35100093 ', ' 6'], ['35200093 ', ' 7'], ['35300093 ', ' 8'], ['35400093 ', ' 9'], ['35500093 ', ' 0'], ['35600093 ', ' 1'], ['35700093 ', ' 2']]

In [6]:
pyboard = serial.Serial('/dev/tty.usbmodem1452', 115200)

In [7]:
pyboard.baudrate


Out[7]:
115200

In [8]:
pyboard.bytesize


Out[8]:
8

In [9]:
pyboard.getBaudrate


Out[9]:
<bound method Serial.getBaudrate of Serial<id=0x105baab50, open=True>(port='/dev/tty.usbmodem1452', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)>

In [10]:
pyboard.getBaudrate()


Out[10]:
115200

In [11]:
pyboard.getPort()


Out[11]:
'/dev/tty.usbmodem1452'

In [12]:
pyboard.getSupportedBaudrates()


Out[12]:
[('50', 50),
 ('75', 75),
 ('110', 110),
 ('134', 134),
 ('150', 150),
 ('200', 200),
 ('300', 300),
 ('600', 600),
 ('1200', 1200),
 ('1800', 1800),
 ('2400', 2400),
 ('4800', 4800),
 ('9600', 9600),
 ('19200', 19200),
 ('38400', 38400),
 ('57600', 57600),
 ('115200', 115200),
 ('230400', 230400),
 ('460800', 460800),
 ('500000', 500000),
 ('576000', 576000),
 ('921600', 921600),
 ('1000000', 1000000),
 ('1152000', 1152000),
 ('1500000', 1500000),
 ('2000000', 2000000),
 ('2500000', 2500000),
 ('3000000', 3000000),
 ('3500000', 3500000),
 ('4000000', 4000000)]

In [13]:
pyboard.isOpen()


Out[13]:
True

In [14]:
pyboard.isatty()


Out[14]:
False

In [ ]:
temp = []
for i in range(20):
    if i == 0:
        pyboard.flushInput()
    temp.append( pyboard.readline().strip().split(',') )

print(temp)

In [ ]:


In [12]:
class serial_speed_test(object):

    def __init__(self, freq_Hz):
        self.tick = 0
        self.tick_ready = False
        self.freq_Hz = freq_Hz
        #tim1 = pyb.Timer(1)
        #tim1.init(freq=freq_Hz)
        #tim1.callback(self.serial_speed_test_cb)

    def serial_speed_test_cb(self):
        self.tick_ready = True
        #print(micros_timer.counter(), ',', 40*self.tick)
        self.tick = (self.tick + 1) % 100

sst = serial_speed_test(2)
print(sst.tick_ready)


False

In [14]:
s = "%d,%d\n" % (sst.tick, sst.freq_Hz)
print(s)


0,2


In [16]:
s_temp = 'start\n'
s_temp.startswith('start')


Out[16]:
True

In [ ]: