LED blink¶
This example creates an IO Sequence composed out of two IO Sync Frames for turning ON and OFF the LEDs of the Red Pitaya 125-14, respectively. The first frame is triggered automatically at the beginning of the sequence and the second one is triggered at a falling edge of the external trigger line (digital_io_0[0], DIO0_P). See README for IO Names and Pin Mapping.
Imports¶
import time
from matplotlib import pyplot as plt
from openlabctrl.device import Rp_125_14_Z7010
from openlabctrl.sequence import IoSequence
from openlabctrl.frame import IoSyncFrame, TriggerSource
Device instances¶
rp_0 = Rp_125_14_Z7010(ip="192.168.1.143", label="rp_0", force=True)
IO Sequences & IO Frames instances¶
seq = IoSequence(device_list=[rp_0])
fr_0 = IoSyncFrame(device_type=Rp_125_14_Z7010, trig=None)
fr_1 = IoSyncFrame(device_type=Rp_125_14_Z7010, trig=TriggerSource.EXT_LOW)
Frame definitions¶
#FRAME O (turn on LEDs sequentially)
fr_0.reset()
fr_0.set_time_increment(125_000_000) # 1 Sa/s
for i in range(8):
fr_0.led.output(val=(1 << i), mask=(1 << i))
#FRAME 1 (turn off LEDs sequentially)
fr_1.reset()
fr_1.set_time_increment(125_000_000) # 1 Sa/s
for i in range(8):
fr_1.led.output(val=0, mask=(1 << i))
Sequence definition¶
seq.reset()
seq.add_frame(frame=fr_0, device=rp_0, label="LED on")
seq.add_frame(frame=fr_1, device=rp_0, label="LED off")
print(seq.sequence_description())
+--------------------+
| rp_0@192.168.1.143 |
+--------------------+
| LED on |
| LED off |
+--------------------+
NOTE: Frames with (*) are triggered by external trigger source.
Upload & Run sequence¶
seq.upload()
seq.start()
while not seq.is_done():
if seq.is_error():
print("Sequence error. Please check status.")
break
time.sleep(0.01)
seq.get_status()
{'rp_0@192.168.1.143': {'enabled': True,
'done': True,
'error': False,
'current_frame': 'LED off',
'io': {'rf_out_0': {'error': False, 'done': True},
'rf_out_1': {'error': False, 'done': True},
'digital_io_0': {'error': False, 'done': True},
'digital_io_1': {'error': False, 'done': True},
'digital_io_2': {'error': False, 'done': True},
'digital_io_3': {'error': False, 'done': True},
'analog_out_0': {'error': False, 'done': True},
'analog_out_1': {'error': False, 'done': True},
'analog_out_2': {'error': False, 'done': True},
'analog_out_3': {'error': False, 'done': True},
'scope_0': {'error': False, 'done': True},
'scope_1': {'error': False, 'done': True},
'led': {'error': False, 'done': True}}}}
seq.stop()