Skip to content

Instantly share code, notes, and snippets.

@owenthewizard
Created November 22, 2017 17:09
Show Gist options
  • Save owenthewizard/f3a8201e0540683c812189bb83d9ef5a to your computer and use it in GitHub Desktop.
Save owenthewizard/f3a8201e0540683c812189bb83d9ef5a to your computer and use it in GitHub Desktop.
A simple library for interacting with the Samsung 20S207DA1 VFD
# Library for using Samsung 20S207DA1
# Based on https://www.pollin.de/productdownloads/D120394D.PDF
import serial
class Samsung20S207DA1:
DIM_0 = b'\x04\x00'
DIM_20 = b'\x04\x20'
DIM_40 = b'\x04\x40'
DIM_60 = b'\x04\x60'
DIM_80 = b'\x04\x80'
DIM_100 = b'\x04\xFF'
BACKSPACE = b'\x08'
TAB = b'\x09'
CARRIAGE_RETURN = b'\x0D'
ALL_DISPLAY = b'\x0F'
DISPLAY_POSITION = b'\x10'
CURSOR_OFF = b'\x14'
CURSOR_ON = b'\x15'
CURSOR_BLINK = b'\x16'
DOT_CURSOR_LIGHTING = b'\xFF'
DOT_CURSOR_BLINKING = b'\x88'
DOT_CURSOR_NO_LIGHTING = b'\x00'
RESET = b'\x1F'
def __init__(self, port, baud=9600, parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS):
self.vfd = serial.Serial(
port=port,
baudrate=baud,
parity=parity,
stopbits=stopbits,
bytesize=bytesize
)
def write(self, string):
self.vfd.write(string.encode('ascii'))
def set_dim(self, dim):
self.vfd.write(dim)
def backspace(self):
self.vfd.write(self.BACKSPACE)
def tab(self):
self.vfd.write(self.TAB)
def enter(self):
self.vfd.write(self.CARRIAGE_RETURN)
def all_display(self):
self.vfd.write(self.ALL_DISPLAY)
def set_pos(self, pos):
self.vfd.write(self.DISPLAY_POSITION + bytes.fromhex(format(pos, '02x')))
set_cursor_mode = set_dim
set_dot_cursor_mode = set_dim
def reset(self):
self.vfd.write(self.RESET)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment