Created
February 9, 2021 21:47
-
-
Save enkiusz/83b97245640d3725e97ea75d6dc95228 to your computer and use it in GitHub Desktop.
A simple LED board driver example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# This code is in the public domain. | |
# Maciej Grela <[email protected]> | |
# | |
import serial | |
ser = serial.Serial("/dev/ttyUSB0", 115200) | |
# Some random board with LEDs from a "network appliance". | |
# It uses a USB connection to send data to a PIC uC | |
# via an FT245BM converter. | |
# | |
# Board layout: | |
# USB port on the left, looking at leds: | |
# <USB PORT> | |
# LED1 LED2 LED3 LED4 LED5 LED6 LED7 LED8 LED9 | |
# A command sent via the serial port with 115200 8N1 | |
# contains 3 bytes: | |
# | |
# Cmd := byte1 byte2 byte3 | |
# | |
# The bits for control bytes are as follows: | |
# | |
# byte1 | |
# 00xxxxxx | |
# |||||||`-- 1: LED1 (green) | |
# ||||||`--- 1: LED1 (yellow) | |
# |||||`---- 1: LED2 (green) | |
# ||||`----- 1: LED2 (yellow) | |
# |||`------ 1: LED3 (green) | |
# ||`------- 1: LED3 (yellow) | |
# |`-------- 0 | |
# `--------- 0 | |
# | |
# byte2 | |
# 01xxxxxx | |
# |||||||`-- 1: LED4 (green) | |
# ||||||`--- 1: LED4 (yellow) | |
# |||||`---- 1: LED5 (green) | |
# ||||`----- 1: LED5 (yellow) | |
# |||`------ 1: LED6 (green) | |
# ||`------- 1: LED6 (yellow) | |
# |`-------- 1 | |
# `--------- 0 | |
# | |
# byte3 | |
# 10xxxxxx | |
# |||||||`-- 1: LED7 (green) | |
# ||||||`--- 1: LED7 (yellow) | |
# |||||`---- 1: LED8 (green) | |
# ||||`----- 1: LED8 (yellow) | |
# |||`------ 1: LED9 (green) | |
# ||`------- 1: LED9 (yellow) | |
# |`-------- 0 | |
# `--------- 1 | |
# Example command | |
ser.write([int('00001000', 2), int('01001000', 2), int('10000100', 2)]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment