Created
April 5, 2025 18:25
-
-
Save olgierd/9dd0dc7b9aada5083ba3c26ef03067c1 to your computer and use it in GitHub Desktop.
Pixel Bydgoszcz flip-dot display
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 | |
| import serial | |
| import time | |
| import struct | |
| import sys | |
| s = serial.Serial('/dev/serial0', 4800, parity='E') # parity is important here | |
| device_id = '2' # usually can be chosen using selector on PCB | |
| # preamble configured as per https://github.com/domints/PythonPixelBydgoszcz/blob/master/pixel2.py | |
| preamble = '00 00 01 01 00 01 1A 00 00 00 30 22' | |
| payload = sys.argv[1] # bitmap 1bit/pixel, starting in bottom-left and scanning up (MSB = bottom), hex-encoded string | |
| message = preamble.replace(' ', '') + payload | |
| def get_crc16(data: bytes): | |
| crc = 0x0000 | |
| for i in range(0, len(data)): | |
| crc ^= data[i] << 8 | |
| for j in range(0,8): | |
| if (crc & 0x8000) > 0: | |
| crc =(crc << 1) ^ 0x1021 | |
| else: | |
| crc = crc << 1 | |
| return struct.pack('<H', crc & 0xFFFF).hex().upper() | |
| def initialize(): | |
| send_raw('01SAT " 11"') | |
| send_raw(f"2{device_id}DPM 01FF57") | |
| def send_packet(data): | |
| # first byte in the command specifies packet length | |
| data_len = struct.pack("B", len(data)//2+3).hex().upper() # +1 for length, +2 for CRC = +3 | |
| data = data_len + data | |
| crc = get_crc16(bytes.fromhex(data)) | |
| send_raw(f"2{device_id}DDB {data}{crc}") | |
| def send_raw(data): | |
| print(data) | |
| # 0x01 - packet start; \r\n + 0x04 - packet ending | |
| s.write(bytes(f"\x01{data}\x0d\x0a\x04", 'ascii')) | |
| time.sleep(0.5) | |
| initialize() | |
| send_packet(message) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment