Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

working, tested & ready-for-release

  • Loading branch information...
commit a477f5c72ddaef4d3ec1a2d74e30cd7f1302d96f 0 parents
@ladyada ladyada authored
Showing with 872 additions and 0 deletions.
  1. +586 −0 Adafruit_USBSerialLCD.ino
  2. +286 −0 matrixtest.py
586 Adafruit_USBSerialLCD.ino
@@ -0,0 +1,586 @@
+// adafruit USB serial LCD code using Teensy core for '162
+
+#include <LiquidCrystal.h>
+#include <EEPROM.h>
+
+// uncomment below to have the display buffer echo'd to USB serial (handy!)
+//#define USBLCDDEBUG 1
+
+#define D4 1 // PD1
+#define D5 4 // PD4
+#define D6 5 // PD5
+#define D7 6 // PD6
+#define RS 12 // PB4
+#define RW 13 // PB5
+#define EN 14 // PB6
+
+LiquidCrystal lcd(RS, RW, EN, D4, D5, D6, D7);
+
+// This line defines a "Uart" object to access the serial port
+HardwareSerial Uart = HardwareSerial();
+
+// connect these to the analog output (PWM) pins!
+#define REDLITE 0 // D0
+#define GREENLITE 18 // C5
+#define BLUELITE 17 // C6
+#define CONTRASTPIN 15 // B7
+
+
+// see a list of matrix orbital commands here (we dont support -all-
+//http://www.matrixorbital.ca/manuals/LCDVFD_Series/LCD2041/LCD2041.pdf
+
+/******** Communication commands */
+//#define MATRIX_I2CADDR 0x33 // not supported
+#define MATRIX_BAUDRATE 0x39 // 1 arg
+//#define MATRIX_BAUDRATE2 0xA4 // not supported
+
+/******** text commands */
+#define MATRIX_AUTOSCROLL_ON 0x51
+#define MATRIX_AUTOSCROLL_OFF 0x52
+#define MATRIX_CLEAR 0x58
+#define MATRIX_CHANGESPLASH 0x40 // COL * ROW chars!
+#define MATRIX_AUTOWRAPLINE_ON 0x43
+#define MATRIX_AUTOWRAPLINE_OFF 0x44
+#define MATRIX_SETCURSOR_POSITION 0x47 // 2 args: col, row
+#define MATRIX_HOME 0x48
+#define MATRIX_MOVECURSOR_BACK 0x4C
+#define MATRIX_MOVECURSOR_FORWARD 0x4D
+#define MATRIX_UNDERLINECURSOR_ON 0x4A
+#define MATRIX_UNDERLINECURSOR_OFF 0x4B
+#define MATRIX_BLOCKCURSOR_ON 0x53
+#define MATRIX_BLOCKCURSOR_OFF 0x54
+
+/****** special chars */
+#define MATRIX_CUSTOM_CHARACTER 0x4E // 9 args: char #, 8 bytes data
+#define MATRIX_SAVECUSTOMCHARBANK 0xC1 // 9 args: char #, 8 bytes data
+#define MATRIX_LOADCUSTOMCHARBANK 0xC0 // 9 args: char #, 8 bytes data
+/***** Numbers & Bargraphs */
+//#define MATRIX_PLACEMEDIUMDIGIT 0x6F
+/***** display func */
+#define MATRIX_DISPLAY_ON 0x42 // backlight. 1 argument afterwards, in minutes
+#define MATRIX_DISPLAY_OFF 0x46
+#define MATRIX_SET_BRIGHTNESS 0x99 // 1 arg: scale
+#define MATRIX_SETSAVE_BRIGHTNESS 0x98 // 1 arg: scale
+#define MATRIX_SET_CONTRAST 0x50 // 1 arg
+#define MATRIX_SETSAVE_CONTRAST 0x91 // 1 arg
+
+
+/***** Extra commands */
+#define EXTENDED_RGBBACKLIGHT 0xD0 // 3 args - R G B
+
+#define MATRIX_STARTL_COMMAND 0xFE
+//#define MATRIX_END_COMMAND 0x9A
+
+// storage of the current backlight state
+#define SPLASH_ADDR 1
+#define BACKLIGHT_R_ADDR 100
+#define BACKLIGHT_G_ADDR 101
+#define BACKLIGHT_B_ADDR 102
+#define BACKLIGHT_STATE_ADDR 103
+#define BACKLIGHT_BRIGHTNESS_ADDR 104
+#define AUTOSCROLL_ADDR 105
+#define BAUDRATE_ADDR 106 // and 107, 108
+#define CONTRAST_ADDR 109
+#define CUSTOMCHARBANKS_ADDR 110
+// 110 thru 430 !
+#define LAST_ADDR 431
+#define EEPROM_END 511
+
+uint8_t COLS = 16;
+uint8_t ROWS = 2;
+uint8_t x, y;
+
+extern unsigned int __bss_end;
+extern unsigned int __heap_start;
+extern void *__brkval;
+int freeMemory() {
+ int free_memory;
+
+ if ((int)__brkval == 0)
+ free_memory = ((int)&free_memory) - ((int)&__bss_end);
+ else
+ free_memory = ((int)&free_memory) - ((int)__brkval);
+
+ return free_memory;
+}
+
+void setup() {
+ if (getBaud() > 115200) {
+ setBaud(9600);
+ } else {
+ setBaud(getBaud());
+ }
+
+ // set up the LCD's number of rows and columns:
+ lcd.begin(COLS, ROWS);
+
+ pinMode(CONTRASTPIN, OUTPUT);
+ pinMode(REDLITE, OUTPUT);
+ pinMode(GREENLITE, OUTPUT);
+ pinMode(BLUELITE, OUTPUT);
+
+/*** test ****/
+ setBacklight(255, 0, 0);
+ delay(250);
+ setBacklight(0, 255, 0);
+ delay(250);
+ setBacklight(0, 0, 255);
+ delay(250);
+ setBacklight(255, 255, 255);
+ setContrast(0x50);
+ EEPROM.write(SPLASH_ADDR, 0xFF);
+ setBaud(9600);
+
+ lcd.clear();
+ lcd.home();
+ lcd.print(getBaud());
+ lcd.print(" baud");
+ delay(1000);
+/*** test ****/
+
+
+#ifdef USBLCDDEBUG
+ // print to USB only
+ Serial.print(F("free mem = ")); Serial.println(freeMemory());
+#endif
+
+ setContrast(getContrast());
+
+ // do splash screen
+ displayOn();
+ if (EEPROM.read(SPLASH_ADDR) == 0xFF) {
+ lcd.setCursor(0,0);
+ lcd.print("USB/Serial LCD");
+ lcd.setCursor(0,1);
+ lcd.print("Adafruit.com");
+ } else {
+ for (uint8_t i=0; i < ROWS; i++) {
+ lcd.setCursor(0,i);
+ for (uint8_t j=0; j<COLS; j++) {
+ lcd.write(EEPROM.read(SPLASH_ADDR + j * 40 + i));
+ }
+ }
+ }
+ delay(1000);
+
+ lcd.clear();
+ lcd.home();
+ x = 0; y = 0;
+ clearbuffer();
+ lcd.home();
+}
+
+// max 20x4
+char displaybuff[20][4];
+
+void loop() {
+ byte a, b, c;
+ //parse command loop
+
+ if (serialAvailable()) {
+ c = serialBlockingRead();
+
+ if (c != MATRIX_STARTL_COMMAND) {
+ // not a command, just print the text!
+
+ if (c == 0x0D) {
+ // special exception for new lines
+ while (x <= COLS-1) {
+ lcd.print(' '); // fill with spaces
+ displaybuff[x][y] = ' ';
+ x++;
+ }
+ } else {
+ lcd.print((char)c);
+ displaybuff[x][y] = c;
+ }
+
+ // wrap the cursor
+ x++;
+ if (x >= COLS) {
+ // go to the next row
+ x = 0;
+ y++;
+ if (y >= ROWS) {
+ // ran out of display space!
+ if (! getAutoScroll()) {
+ // go to the top left
+ y = 0;
+ } else {
+ // shift all data up by one line!
+ for (int8_t i=ROWS-1; i >= 0; i--) {
+ for (uint8_t j=0; j<COLS; j++) {
+ if (i == 0) {
+ //Serial.print("spaces");
+ displaybuff[j][ROWS-1] = ' ';
+ } else
+ displaybuff[j][i-1] = displaybuff[j][i];
+ }
+ }
+ for (int8_t i=0; i < ROWS; i++) {
+ lcd.setCursor(0, i);
+ for (uint8_t j=0; j<COLS; j++) {
+ lcd.write(displaybuff[j][i]);
+ }
+ }
+ // set the x & y
+ x = 0;
+ y = ROWS-1;
+ printbuffer();
+ }
+ }
+ lcd.setCursor(x, y);
+ }
+ printbuffer();
+ return;
+ }
+ //Serial.print(F("\ncommand: "));
+ // it is a command! get the command byte
+ c = serialBlockingRead();
+ //Serial.println(c, HEX);
+ switch (c) {
+ case MATRIX_DISPLAY_ON:
+ displayOn();
+ c = serialBlockingRead(); // todo - add timeout!
+ break;
+ case MATRIX_DISPLAY_OFF:
+ displayOff();
+ break;
+ case MATRIX_SET_BRIGHTNESS:
+ case MATRIX_SETSAVE_BRIGHTNESS:
+ c = serialBlockingRead();
+ setBrightness(c);
+ break;
+ case MATRIX_SET_CONTRAST:
+ case MATRIX_SETSAVE_CONTRAST:
+ c = serialBlockingRead();
+ setContrast(c);
+ break;
+ case MATRIX_HOME:
+ lcd.home();
+ x = 0; y = 0;
+ break;
+ case MATRIX_CLEAR:
+ lcd.clear();
+ clearbuffer();
+ x = 0; y = 0;
+ break;
+ case MATRIX_AUTOSCROLL_OFF:
+ setAutoScroll(0);
+ break;
+ case MATRIX_AUTOSCROLL_ON:
+ setAutoScroll(1);
+ break;
+ case MATRIX_AUTOWRAPLINE_OFF:
+ case MATRIX_AUTOWRAPLINE_ON:
+ // not implemented
+ break;
+ case MATRIX_SETCURSOR_POSITION:
+ x = serialBlockingRead();
+ y = serialBlockingRead();
+ x--; y--;// matrix orbital starts at (1,1) not (0,0)
+ if (x >= COLS) { y += x / COLS; x %= COLS; }
+ y %= ROWS;
+ lcd.setCursor(x, y);
+ //Serial.print(F("\nMoving to (")); Serial.print(x, DEC);
+ //Serial.print(','); Serial.print(y, DEC); Serial.println(')');
+ break;
+ case MATRIX_MOVECURSOR_BACK:
+ if (x > 0) x--;
+ else {
+ x = COLS - 1;
+ if (y > 0) y--;
+ else y = ROWS - 1;
+ }
+ lcd.setCursor(x, y);
+ break;
+ case MATRIX_MOVECURSOR_FORWARD:
+ if (x < COLS - 1) x++;
+ else {
+ x = 0;
+ if (y < ROWS - 1) y++;
+ else y = 0;
+ }
+ lcd.setCursor(x, y);
+ break;
+ case MATRIX_UNDERLINECURSOR_ON:
+ lcd.cursor();
+ break;
+ case MATRIX_BLOCKCURSOR_OFF:
+ case MATRIX_UNDERLINECURSOR_OFF:
+ lcd.noCursor();
+ lcd.noBlink();
+ break;
+ case MATRIX_BLOCKCURSOR_ON:
+ lcd.blink();
+ break;
+ case MATRIX_CHANGESPLASH:
+ for (uint8_t i=0; i < ROWS; i++) {
+ for (uint8_t j=0; j<COLS; j++) {
+ c = serialBlockingRead();
+ EEPROM.write(SPLASH_ADDR + j * 40 + i, c);
+ }
+ }
+ break;
+ case MATRIX_BAUDRATE:
+ c = serialBlockingRead();
+ switch (c) {
+ case 0x53: setBaud(1200); break;
+ case 0x29: setBaud(2400); break;
+ case 0xCf: setBaud(4800); break;
+ case 0x67: setBaud(9600); break;
+ case 0x33: setBaud(19200); break;
+ case 0x22: setBaud(28800); break;
+ case 0x19: setBaud(38400); break;
+ case 0x10: setBaud(57600); break;
+ case 0x08: setBaud(115200); break;
+ }
+ break;
+ case MATRIX_CUSTOM_CHARACTER:
+ c = serialBlockingRead();
+ readCustom(c, 255);
+ break;
+ case MATRIX_LOADCUSTOMCHARBANK:
+ c = serialBlockingRead();
+ loadCustom(c);
+ break;
+ case MATRIX_SAVECUSTOMCHARBANK:
+ //Serial.println(F("Custom char"));
+ b = serialBlockingRead();
+ c = serialBlockingRead();
+ readCustom(c, b);
+ break;
+ /* hmm this didnt work out, try again later?
+ case MATRIX_PLACEMEDIUMDIGIT:
+ a = serialBlockingRead();
+ b = serialBlockingRead();
+ c = serialBlockingRead();
+ // MEME: load the medium chars into RAM
+ uint8_t tl, tr, bl, br;
+ if (c == 0) {
+ tl = 1; tr = 0; bl = 3; br = 2;
+ } else if (c == 1) {
+ tl = 0; tr = ' '; bl = 2; br = 4;
+ } else if (c == 2) {
+ tl = 5; tr = 6; bl = 3; br = 4;
+ } else if (c == 3) {
+ tl = 5; tr = 6; bl = 4; br = 2;
+ } else if (c == 4) {
+ tl = 3; tr = 2; bl = ' '; br = ' ';
+ } else if (c == 5) {
+ tl = 3; tr = 2; bl = ' '; br = ' ';
+ }
+ lcd.setCursor(a, b);
+ lcd.write(tl);
+ lcd.setCursor(a+1, b);
+ lcd.write(tr);
+ lcd.setCursor(a, b+1);
+ lcd.write(bl);
+ lcd.setCursor(a+1, b+1);
+ lcd.write(br);
+ break;
+ */
+ case EXTENDED_RGBBACKLIGHT:
+ a = serialBlockingRead();
+ b = serialBlockingRead();
+ c = serialBlockingRead();
+ setBacklight(a, b, c);
+ break;
+ }
+ }
+}
+
+void loadCustom(uint8_t bank) {
+ uint8_t newChar[8];
+
+ if (bank > 4) return;
+
+ int16_t addr = bank;
+ addr *= 64;
+ addr += CUSTOMCHARBANKS_ADDR;
+
+ for (uint8_t loc = 0; loc < 8; loc++) {
+ for (uint8_t i=0; i<8; i++) {
+ newChar[i] = EEPROM.read(addr);
+ //Serial.print(F("Loaded ")); Serial.print(newChar[i], HEX); Serial.print(F(" from $"));
+ //Serial.println(addr);
+ addr++;
+ }
+ lcd.createChar(loc, newChar);
+ //lcd.write(loc);
+ }
+ lcd.setCursor(x, y);
+}
+
+void readCustom(uint8_t loc, uint8_t bank) {
+ Serial.print(F("Saving char to bank #")); Serial.print(bank, DEC);
+ Serial.print(F(" : "));
+ Serial.println(loc, DEC);
+
+ uint8_t newChar[8];
+ for (uint8_t i=0; i<8; i++) {
+ newChar[i] = serialBlockingRead();
+ }
+ if (bank > 4) {
+ // instant display
+ lcd.createChar(loc, newChar);
+ lcd.setCursor(x, y);
+ } else {
+ // save it to EEPROM
+ int16_t addr = bank;
+ addr *= 64;
+ addr += loc * 8;
+ addr += CUSTOMCHARBANKS_ADDR;
+
+ for (uint8_t i=0; i<8; i++) {
+ EEPROM.write(addr + (int16_t)i, newChar[i]);
+ }
+ }
+}
+
+uint8_t getContrast() {
+ EEPROM.read(CONTRAST_ADDR);
+}
+
+void setContrast(uint8_t c) {
+ if (c != getContrast()) {
+ EEPROM.write(CONTRAST_ADDR, c);
+ }
+ analogWrite(CONTRASTPIN, c);
+}
+
+uint32_t getBaud() {
+ uint32_t b;
+
+ b = EEPROM.read(BAUDRATE_ADDR);
+ b <<= 8;
+ b |= EEPROM.read(BAUDRATE_ADDR+1);
+ b <<= 8;
+ b |= EEPROM.read(BAUDRATE_ADDR+2);
+
+ return b;
+}
+
+int serialAvailable() {
+ return max(Serial.available(), Uart.available());
+}
+
+char serialBlockingRead() {
+ while (!serialAvailable());
+ char c = 0;
+
+ if (Serial.available()) {
+ //Serial.print(F("Read USB char: "));
+ c = Serial.read();
+ } else if (Uart.available()) {
+ //Serial.print(F("Read UART char: "));
+ c = Uart.read();
+ }
+ Serial.write(c);
+ Serial.print(F(" (0x"));
+ Serial.print(c, HEX);
+ Serial.print(')');
+ return c;
+}
+
+void setBaud(uint32_t baudrate) {
+ if (getBaud() != baudrate) {
+ EEPROM.write(BAUDRATE_ADDR, baudrate >> 16);
+ EEPROM.write(BAUDRATE_ADDR+1, baudrate >> 8);
+ EEPROM.write(BAUDRATE_ADDR+2, baudrate & 0xFF);
+ }
+
+ Serial.begin(baudrate);
+ Uart.begin(baudrate);
+ // the Uart is a little noisy without a pullup, so we'll use the internal one on PD2
+ digitalWrite(PD2, HIGH);
+}
+
+void setAutoScroll(uint8_t x) {
+ EEPROM.write(AUTOSCROLL_ADDR, x);
+}
+uint8_t getAutoScroll() {
+ return EEPROM.read(AUTOSCROLL_ADDR);
+}
+
+void displayOn() {
+ setBrightness(EEPROM.read(BACKLIGHT_BRIGHTNESS_ADDR));
+}
+
+void displayOff() {
+ analogWrite(REDLITE, 0);
+ analogWrite(GREENLITE, 0);
+ analogWrite(BLUELITE, 0);
+}
+
+void setBrightness(uint8_t brightness) {
+ if (brightness != EEPROM.read(BACKLIGHT_BRIGHTNESS_ADDR))
+ EEPROM.write(BACKLIGHT_BRIGHTNESS_ADDR, brightness);
+ setBacklight(EEPROM.read(BACKLIGHT_R_ADDR), EEPROM.read(BACKLIGHT_G_ADDR), EEPROM.read(BACKLIGHT_B_ADDR));
+}
+
+void setBacklight(uint8_t r, uint8_t g, uint8_t b) {
+ if (r != EEPROM.read(BACKLIGHT_R_ADDR))
+ EEPROM.write(BACKLIGHT_R_ADDR, r);
+ if (g != EEPROM.read(BACKLIGHT_G_ADDR))
+ EEPROM.write(BACKLIGHT_G_ADDR, g);
+ if (b != EEPROM.read(BACKLIGHT_B_ADDR))
+ EEPROM.write(BACKLIGHT_B_ADDR, b);
+
+ uint8_t brightness = EEPROM.read(BACKLIGHT_BRIGHTNESS_ADDR);
+ // normalize the red LED
+ r = map(r, 0, 255, 0, 70);
+ b = map(b, 0, 255, 0, 190);
+
+ r = map(r, 0, 255, 0, brightness);
+ g = map(g, 0, 255, 0, brightness);
+ b = map(b, 0, 255, 0, brightness);
+
+
+ analogWrite(REDLITE, r);
+ analogWrite(GREENLITE, g);
+ analogWrite(BLUELITE, b);
+
+ TCNT0 = 127;
+ TCNT1 = 0;
+ TCCR0B = 0x01;
+ TCCR1B = 0x01;
+ /*
+ Serial.print(F("R = ")); Serial.print(r, DEC);
+ Serial.print(F(" G = ")); Serial.print(g, DEC);
+ Serial.print(F(" B = ")); Serial.println(b, DEC);
+
+ Serial.print(F("TCCR0A = ")); Serial.println(TCCR0A, HEX);
+ Serial.print(F("TCCR0B = ")); Serial.println(TCCR0B, HEX);
+ Serial.print(F("OCR0B = ")); Serial.println(OCR0B, HEX);
+
+ Serial.print(F("TCCR1A = ")); Serial.println(TCCR1A, HEX);
+ Serial.print(F("TCCR1B = ")); Serial.println(TCCR1B, HEX);
+ Serial.print(F("OCR1A = ")); Serial.println(OCR1A, HEX);
+ Serial.print(F("OCR1B = ")); Serial.println(OCR1B, HEX);
+ */
+}
+
+void clearbuffer() {
+ for (uint8_t i=0; i <ROWS; i++) {
+ for (uint8_t j=0; j<COLS; j++) {
+ displaybuff[j][i] = ' ';
+ }
+ }
+}
+
+
+void printbuffer() {
+//#ifdef USBLCDDEBUG
+ Serial.println(F("\n\r------------------"));
+ for (uint8_t i=0; i <ROWS; i++) {
+ Serial.print('|');
+ for (uint8_t j=0; j<COLS; j++) {
+ Serial.print(displaybuff[j][i], BYTE);
+ }
+ Serial.println('|');
+ }
+ Serial.println(F("------------------"));
+//#endif
+}
+
286 matrixtest.py
@@ -0,0 +1,286 @@
+import serial
+import sys
+import time
+
+# matrix orbital example test
+
+
+def matrixwritecommand(commandlist):
+ commandlist.insert(0, 0xFE)
+ #ser.write(bytearray([0xFE]))
+ #time.sleep(0.1);
+ for i in range(0, len(commandlist)):
+ #print chr(commandlist[i]),
+ ser.write(chr(commandlist[i]))
+ #ser.write(bytearray(commandlist))
+
+# 1. get serial port
+if len(sys.argv) != 2:
+ print "Usage: python test.py <serialport>"
+ exit(0)
+
+'''
+# baudrate fix
+ser = serial.Serial(sys.argv[1], 2400, timeout=1)
+matrixwritecommand([0x39, 0x67])
+time.sleep(2);
+ser = serial.Serial(sys.argv[1], 4800, timeout=1)
+matrixwritecommand([0x39, 0x67])
+time.sleep(2);
+ser = serial.Serial(sys.argv[1], 19200, timeout=1)
+matrixwritecommand([0x39, 0x67])
+time.sleep(2);
+ser = serial.Serial(sys.argv[1], 28800, timeout=1)
+matrixwritecommand([0x39, 0x67])
+time.sleep(2);
+ser = serial.Serial(sys.argv[1], 38400, timeout=1)
+matrixwritecommand([0x39, 0x67])
+time.sleep(2);
+ser = serial.Serial(sys.argv[1], 57600, timeout=1)
+matrixwritecommand([0x39, 0x67])
+time.sleep(2);
+'''
+
+ser = serial.Serial(sys.argv[1], 9600, timeout=1)
+matrixwritecommand([0x58])
+
+
+# turn on display
+ser.write("Display on");
+matrixwritecommand([0x42, 0])
+time.sleep(0.3);
+
+# contrast loop
+#for i in range(0, 256):
+ #matrixwritecommand([0x50, i])
+#time.sleep(0.1);
+
+matrixwritecommand([0x50, 80])
+
+# turn off display
+ser.write("off");
+matrixwritecommand([0x46])
+time.sleep(0.3);
+
+# turn on display
+ser.write("on");
+matrixwritecommand([0x42, 0])
+time.sleep(0.3);
+
+# create custom char
+matrixwritecommand([0x4E, 0, 0, 0xA, 0x15, 0x11, 0x11, 0xA, 0x4, 0])
+ser.write(chr(0))
+time.sleep(0.5)
+
+# color loop
+matrixwritecommand([0x99, 255])
+for r in range(0, 256):
+ matrixwritecommand([0xD0, r, 0, 0])
+ time.sleep(0.005);
+for g in range(0, 256):
+ matrixwritecommand([0xD0, 255-g, g, 0])
+ time.sleep(0.005);
+for b in range(0, 256):
+ matrixwritecommand([0xD0, 0, 255-b, b])
+ time.sleep(0.005);
+for r in range(0, 256):
+ matrixwritecommand([0xD0, r, 0, 255-r])
+ time.sleep(0.005);
+for r in range(255, 0):
+ matrixwritecommand([0xD0, r, 0, 0])
+ time.sleep(0.005);
+
+matrixwritecommand([0x99, 0])
+matrixwritecommand([0xD0, 255, 255, 255])
+# brightness loop
+for i in range(0, 256):
+ matrixwritecommand([0x99, i])
+ time.sleep(0.01);
+
+# home
+matrixwritecommand([0x48])
+ser.write("home");
+time.sleep(0.5);
+
+#clear
+matrixwritecommand([0x58])
+ser.write("clear");
+time.sleep(0.5);
+
+matrixwritecommand([0x58])
+# create horizontal bars in custom chars bank #1
+matrixwritecommand([0xC1, 1, 0, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10])
+matrixwritecommand([0xC1, 1, 1, 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18])
+matrixwritecommand([0xC1, 1, 2, 0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C])
+matrixwritecommand([0xC1, 1, 3, 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E])
+matrixwritecommand([0xC1, 1, 4, 0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF])
+matrixwritecommand([0xC1, 1, 5, 0x7,0x7,0x7,0x7,0x7,0x7,0x7,0x7])
+matrixwritecommand([0xC1, 1, 6, 0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3])
+matrixwritecommand([0xC1, 1, 7, 0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1])
+matrixwritecommand([0xC0, 1]) # load bank 1
+ser.write(chr(0))
+ser.write(chr(1))
+ser.write(chr(2))
+ser.write(chr(3))
+ser.write(chr(4))
+ser.write(chr(5))
+ser.write(chr(6))
+ser.write(chr(7))
+time.sleep(1)
+
+matrixwritecommand([0x58])
+# create vertical bars in custom chars bank #2
+matrixwritecommand([0xC1, 2, 0, 0,0,0,0,0,0,0,0x1F])
+matrixwritecommand([0xC1, 2, 1, 0,0,0,0,0,0,0x1F,0x1F])
+matrixwritecommand([0xC1, 2, 2, 0,0,0,0,0,0x1F,0x1F,0x1F])
+matrixwritecommand([0xC1, 2, 3, 0,0,0,0,0x1F,0x1F,0x1F,0x1F])
+matrixwritecommand([0xC1, 2, 4, 0,0,0,0x1F,0x1F,0x1F,0x1F,0x1F])
+matrixwritecommand([0xC1, 2, 5, 0,0,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F])
+matrixwritecommand([0xC1, 2, 6, 0,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F])
+matrixwritecommand([0xC1, 2, 7, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F])
+matrixwritecommand([0xC0, 2])
+ser.write(chr(0))
+ser.write(chr(1))
+ser.write(chr(2))
+ser.write(chr(3))
+ser.write(chr(4))
+ser.write(chr(5))
+ser.write(chr(6))
+ser.write(chr(7))
+time.sleep(1)
+
+'''
+matrixwritecommand([0x58])
+# create medium numbers in bank #3
+matrixwritecommand([0xC1, 3, 0, 0x1f,0x1f,0x03,0x03,0x03,0x03,0x03,0x03])
+matrixwritecommand([0xC1, 3, 1, 0x1f,0x1f,0x18,0x18,0x18,0x18,0x18,0x18])
+matrixwritecommand([0xC1, 3, 2, 0x03,0x03,0x03,0x03,0x03,0x03,0x1F,0x1F])
+matrixwritecommand([0xC1, 3, 3, 0x18,0x18,0x18,0x18,0x18,0x18,0x1F,0x1F])
+matrixwritecommand([0xC1, 3, 4, 0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F])
+matrixwritecommand([0xC1, 3, 5, 0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00])
+matrixwritecommand([0xC1, 3, 6, 0x1F,0x1F,0x03,0x03,0x03,0x03,0x1F,0x1F])
+
+matrixwritecommand([0xC1, 3, 7, 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F])
+matrixwritecommand([0xC0, 3])
+ser.write(chr(0))
+ser.write(chr(1))
+ser.write(chr(2))
+ser.write(chr(3))
+ser.write(chr(4))
+ser.write(chr(5))
+ser.write(chr(6))
+ser.write(chr(7))
+time.sleep(1)
+
+matrixwritecommand([0x58])
+# write medium num #0
+matrixwritecommand([0x6F, 0, 0, 0])
+matrixwritecommand([0x6F, 2, 0, 1])
+matrixwritecommand([0x6F, 4, 0, 2])
+matrixwritecommand([0x6F, 6, 0, 3])
+time.sleep(1)
+'''
+
+# autoscroll on
+matrixwritecommand([0x58])
+matrixwritecommand([0x51])
+ser.write("long long long text that scrolls the display ");
+time.sleep(1);
+
+# autoscroll off
+matrixwritecommand([0x58])
+matrixwritecommand([0x52])
+ser.write("long long long text that ends @ top left ");
+time.sleep(1);
+
+# cursor test
+matrixwritecommand([0x58])
+matrixwritecommand([0x47,1,1])
+ser.write('1');
+matrixwritecommand([0x47,16,1])
+ser.write('2');
+matrixwritecommand([0x47,1,2])
+ser.write('3');
+matrixwritecommand([0x47,16,2])
+ser.write('4');
+
+#underline cursor on
+matrixwritecommand([0x4A])
+# move cursor left
+matrixwritecommand([0x4C])
+time.sleep(2);
+# cursor off
+matrixwritecommand([0x4B])
+time.sleep(0.5);
+
+# block cursor
+matrixwritecommand([0x53])
+# move cursor right
+matrixwritecommand([0x4D])
+time.sleep(2);
+matrixwritecommand([0x54])
+time.sleep(0.5);
+
+# baudrate change
+matrixwritecommand([0x39, 0x29])
+time.sleep(1);
+ser.close();
+ser = serial.Serial(sys.argv[1], 2400, timeout=1)
+matrixwritecommand([0x58])
+ser.write("2400")
+
+matrixwritecommand([0x39, 0xCF])
+time.sleep(1);
+ser.close();
+ser = serial.Serial(sys.argv[1], 4800, timeout=1)
+matrixwritecommand([0x58])
+ser.write("4800")
+
+matrixwritecommand([0x39, 0x67])
+time.sleep(1);
+ser.close();
+ser.close();
+ser = serial.Serial(sys.argv[1], 9600, timeout=1)
+matrixwritecommand([0x58])
+ser.write("9600")
+
+matrixwritecommand([0x39, 0x33])
+time.sleep(1);
+ser.close();
+ser = serial.Serial(sys.argv[1], 19200, timeout=1)
+matrixwritecommand([0x58])
+ser.write("19200")
+
+matrixwritecommand([0x39, 0x22])
+time.sleep(1);
+ser.close();
+ser = serial.Serial(sys.argv[1], 28800, timeout=1)
+matrixwritecommand([0x58])
+ser.write("28800")
+
+matrixwritecommand([0x39, 0x19])
+time.sleep(1);
+ser.close();
+ser = serial.Serial(sys.argv[1], 38400, timeout=1)
+matrixwritecommand([0x58])
+ser.write("38400")
+
+matrixwritecommand([0x39, 0x10])
+time.sleep(1);
+ser.close();
+ser = serial.Serial(sys.argv[1], 57600, timeout=1)
+matrixwritecommand([0x58])
+ser.write("57600")
+
+# Revert back to 9600 baud
+matrixwritecommand([0x39, 0x67])
+time.sleep(1);
+ser.close();
+ser = serial.Serial(sys.argv[1], 9600, timeout=1)
+
+# Splashscreen change
+#matrixwritecommand([0x40, 'H','e','l','l','o',' ','W','o','r','l','d','!',' ',' ',' ',' ','T','e','s','t','i','n','g',' ','1','6','x','2',' ','L','C','D'])
+
+#matrixwritecommand([0x40, ' ',' ','A','d','a','f','r','u','i','t','.','c','o','m',' ',' ','1','6','x','2',' ','U','S','B','+','S','e','r',' ','L','C','D'])
+exit()
+
Please sign in to comment.
Something went wrong with that request. Please try again.