{ "cells": [ { "cell_type": "markdown", "id": "5e9f76d6", "metadata": {}, "source": [ "# LED blink\n", "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](https://github.com/dspsandbox/OpenLabCtrl/blob/main/README.md#ios--pin-mapping) for IO Names and Pin Mapping. \n" ] }, { "cell_type": "markdown", "id": "3a07359c", "metadata": {}, "source": [ "\n", "### Imports" ] }, { "cell_type": "code", "execution_count": 1, "id": "607b9c7a", "metadata": {}, "outputs": [], "source": [ "import time \n", "from matplotlib import pyplot as plt\n", "from openlabctrl.device import Rp_125_14_Z7010\n", "from openlabctrl.sequence import IoSequence\n", "from openlabctrl.frame import IoSyncFrame, TriggerSource\n" ] }, { "cell_type": "markdown", "id": "43fb4f95", "metadata": {}, "source": [ "### Device instances" ] }, { "cell_type": "code", "execution_count": 2, "id": "563af75c", "metadata": {}, "outputs": [], "source": [ "rp_0 = Rp_125_14_Z7010(ip=\"192.168.1.143\", label=\"rp_0\", force=True)" ] }, { "cell_type": "markdown", "id": "0436c2e7", "metadata": {}, "source": [ "### IO Sequences & IO Frames instances" ] }, { "cell_type": "code", "execution_count": null, "id": "6e410a24", "metadata": {}, "outputs": [], "source": [ "seq = IoSequence(device_list=[rp_0])\n", "fr_0 = IoSyncFrame(device_type=Rp_125_14_Z7010, trig=None)\n", "fr_1 = IoSyncFrame(device_type=Rp_125_14_Z7010, trig=TriggerSource.EXT_LOW)" ] }, { "cell_type": "markdown", "id": "e5930f84", "metadata": {}, "source": [ "### Frame definitions \n" ] }, { "cell_type": "code", "execution_count": 4, "id": "0406fc31", "metadata": {}, "outputs": [], "source": [ "#FRAME O (turn on LEDs sequentially)\n", "fr_0.reset()\n", "fr_0.set_time_increment(125_000_000) # 1 Sa/s\n", "for i in range(8):\n", " fr_0.led.output(val=(1 << i), mask=(1 << i))\n", " " ] }, { "cell_type": "code", "execution_count": 5, "id": "641f4621", "metadata": {}, "outputs": [], "source": [ "#FRAME 1 (turn off LEDs sequentially)\n", "fr_1.reset()\n", "fr_1.set_time_increment(125_000_000) # 1 Sa/s\n", "for i in range(8):\n", " fr_1.led.output(val=0, mask=(1 << i))\n", " " ] }, { "cell_type": "markdown", "id": "7d3c09a3", "metadata": {}, "source": [ "### Sequence definition" ] }, { "cell_type": "code", "execution_count": 6, "id": "1430a2e3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+\n", "| rp_0@192.168.1.143 |\n", "+--------------------+\n", "| LED on |\n", "| LED off |\n", "+--------------------+\n", "NOTE: Frames with (*) are triggered by external trigger source.\n", "\n" ] } ], "source": [ "seq.reset()\n", "seq.add_frame(frame=fr_0, device=rp_0, label=\"LED on\")\n", "seq.add_frame(frame=fr_1, device=rp_0, label=\"LED off\")\n", "\n", "print(seq.sequence_description())" ] }, { "cell_type": "markdown", "id": "14044a39", "metadata": {}, "source": [ "### Upload & Run sequence" ] }, { "cell_type": "code", "execution_count": null, "id": "b47594a9", "metadata": {}, "outputs": [], "source": [ "seq.upload()\n", "seq.start()\n", "while not seq.is_done():\n", " if seq.is_error():\n", " print(\"Sequence error. Please check status.\")\n", " break\n", " time.sleep(0.01)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "0e66586e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'rp_0@192.168.1.143': {'enabled': True,\n", " 'done': True,\n", " 'error': False,\n", " 'current_frame': 'LED off',\n", " 'io': {'rf_out_0': {'error': False, 'done': True},\n", " 'rf_out_1': {'error': False, 'done': True},\n", " 'digital_io_0': {'error': False, 'done': True},\n", " 'digital_io_1': {'error': False, 'done': True},\n", " 'digital_io_2': {'error': False, 'done': True},\n", " 'digital_io_3': {'error': False, 'done': True},\n", " 'analog_out_0': {'error': False, 'done': True},\n", " 'analog_out_1': {'error': False, 'done': True},\n", " 'analog_out_2': {'error': False, 'done': True},\n", " 'analog_out_3': {'error': False, 'done': True},\n", " 'scope_0': {'error': False, 'done': True},\n", " 'scope_1': {'error': False, 'done': True},\n", " 'led': {'error': False, 'done': True}}}}" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "seq.get_status()" ] }, { "cell_type": "code", "execution_count": null, "id": "fbe9a630", "metadata": {}, "outputs": [], "source": [ "seq.stop()" ] }, { "cell_type": "code", "execution_count": null, "id": "95977692", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.15" } }, "nbformat": 4, "nbformat_minor": 5 }