Skip to content

Instantly share code, notes, and snippets.

@eni23
Created December 24, 2018 14:33
Show Gist options
  • Save eni23/0571a56b74c34e184431df58e34940f8 to your computer and use it in GitHub Desktop.
Save eni23/0571a56b74c34e184431df58e34940f8 to your computer and use it in GitHub Desktop.
#include "Arduino.h"
#include "config.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1331.h>
#include <SPI.h>
#define sclk 13
#define mosi 11
#define cs 10
#define rst 9
#define dc 8
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, rst);
void setup() {
Serial.begin(SERIAL_BAUD);
display.begin();
display.fillScreen(BLACK);
// display.setCursor(0,0);
// display.setTextColor(RED);
// display.setTextSize(1);
}
int incoming;
uint8_t idata[] = { 0, 0 };
uint16_t idata16;
int x=0;
int y=0;
void loop() {
//if (Serial.available() > 0) {
// incoming = Serial.read();
// if (incoming==244){
//display.fillScreen(BLACK);
display.setAddrWindow(0, 0, 96, 64);
display.startWrite();
for (int i=0; i<6144; i++){
if (Serial.available() > 0){
idata[0] = Serial.read();
}
if (Serial.available() > 0){
idata[1] = Serial.read();
}
idata16 = ( (uint16_t) idata[1] << 8) | idata[0];
display.writePixel(x, y, idata16);
x++;
if (x>93){
display.endWrite();
display.startWrite();
x=0;
y++;
}
//display.println(i);
}
display.endWrite();
//}
//}
}
#!/usr/bin/env python
import sys
import struct
import serial
import time
SERIAL_PORT = "/dev/ttyUSB3"
SERIAL_BAUD = 115200
try:
f = open(sys.argv[1], "rb")
except:
print("error loading file")
sys.exit(1)
try:
ser = serial.Serial(port=SERIAL_PORT, baudrate=SERIAL_BAUD)
except:
print("error opening serial port")
sys.exit(1)
def read16(f):
return struct.unpack("=H", f.read(2))[0]
def read32(f):
return struct.unpack("=I", f.read(4))[0]
header = read16(f)
if header != 19778:
print("not a bmp file")
sys.exit(1)
bmp_size = read32(f)
bmp_creator = read32(f)
bmp_offset = read32(f)
bmp_head_sz = read32(f)
bmp_width = read32(f)
bmp_height = read32(f)
bmp_planes = read16(f)
bmp_depth = read16(f)
bmp_compress = read32(f)
bmp_num_px = bmp_width*bmp_height
print("size={0} offset={1} head_sz={2} width={3} height={4} planes={5} depth={6} compress={7} px={8}".format(
bmp_size,
bmp_offset,
bmp_head_sz,
bmp_width,
bmp_height,
bmp_planes,
bmp_depth,
bmp_compress,
bmp_num_px
))
f.seek(bmp_offset, 0)
data = f.read(bmp_num_px*2)
data16 = struct.unpack("={0}H".format(bmp_num_px), data)
time.sleep(1)
ser.reset_input_buffer()
ser.write( struct.pack("=B", 244) )
# for i in range(0,94):
# px = data16[i]
# sdata = struct.pack("=H", px)
# ser.write(sdata)
print(len(data16))
for px in data16:
sdata = struct.pack("=H", px)
ser.write(sdata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment