In [1]:
import serial
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
from IPython.display import display
import time
In [4]:
buspirate = serial.Serial('/dev/ttyUSB0', baudrate=115200, timeout=1)
In [ ]:
def serial_init(self):
buspirate.write(("%c" % 13).encode())
print(buspirate.readline())
buspirate.write(("%c" % 13).encode())
print(buspirate.readline())
buspirate.write(("%c" % 13).encode())
print(buspirate.readline())
time.sleep(1)
buspirate.write(("m\n").encode())
time.sleep(1)
buspirate.write(("5\n").encode())
print(buspirate.readline())
time.sleep(1)
buspirate.write(("4\n").encode())
print(buspirate.readline())
time.sleep(1)
buspirate.write(("1\n").encode())
print(buspirate.readline())
time.sleep(1)
buspirate.write(("2\n").encode())
print(buspirate.readline())
time.sleep(1)
buspirate.write(("1\n").encode())
print(buspirate.readline())
time.sleep(1)
buspirate.write(("2\n").encode())
print(buspirate.readline())
time.sleep(1)
buspirate.write(("2\n").encode())
print(buspirate.readline())
time.sleep(1)
buspirate.write(("W\n").encode())
print(buspirate.readline())
time.sleep(1)
In [ ]:
button = widgets.Button(description="Init Serial!")
display(button)
button.on_click(serial_init)
In [26]:
def write_resistor_0(resistor_value):
buspirate.reset_input_buffer()
buspirate.write(("[0b00000000, " + str(resistor_value) + "]\n").encode())
print(buspirate.readline())
print(buspirate.readline())
print(buspirate.readline())
print(buspirate.readline())
print(buspirate.readline())
In [27]:
def write_resistor_1(resistor_value):
buspirate.reset_input_buffer()
buspirate.write(("[0b00010000, " + str(resistor_value) + "]\n").encode())
print(buspirate.readline())
print(buspirate.readline())
print(buspirate.readline())
print(buspirate.readline())
print(buspirate.readline())
In [28]:
widgets.interact(write_resistor_0, resistor_value=(1, 255, 1))
widgets.interact(write_resistor_1, resistor_value=(1, 255, 1))
Out[28]:
In [ ]: