# HG changeset patch # User Paul Boddie # Date 1452463097 -3600 # Node ID 3743948571b38fd569aeee9ba0801e9d46695c59 # Parent a9ad2b31a8ffb29b384ea47b55c809a0463e8984 Added shape definitions and data sampling support, producing hexadecimal representations of input signal lines. diff -r a9ad2b31a8ff -r 3743948571b3 Alphanumeric.cpp --- a/Alphanumeric.cpp Sun Jan 10 00:30:41 2016 +0100 +++ b/Alphanumeric.cpp Sun Jan 10 22:58:17 2016 +0100 @@ -18,13 +18,47 @@ */ #include +#include "shapes.h" + +/* Multiplexer circuit definitions. */ + +const uint8_t MUX_S = 3, + D0 = 4, D1 = 5, D2 = 6, D3 = 7, + D4 = 8, D5 = 9, D6 = 10, D7 = 11; + +const uint8_t datapins[8] = {D7, D6, D5, D4, D3, D2, D1, D0}; + +const uint16_t digits[] = { + OUTER_FRAME, + RIGHT_EDGE, + HORIZONTALS | UPPER_RIGHT_VERTICAL | LOWER_LEFT_VERTICAL, + HORIZONTALS | RIGHT_EDGE, + UPPER_LEFT_VERTICAL | MIDDLE_ELEMENTS | RIGHT_EDGE, + HORIZONTALS | UPPER_LEFT_VERTICAL | LOWER_RIGHT_VERTICAL, + HORIZONTALS | LEFT_EDGE | LOWER_RIGHT_VERTICAL, + TOP_EDGE | UPPER_RIGHT_DIAGONAL | LOWER_LEFT_DIAGONAL, + OUTER_FRAME | MIDDLE_ELEMENTS, + HORIZONTALS | RIGHT_EDGE | UPPER_LEFT_VERTICAL, + HORIZONTALS | RIGHT_EDGE | LOWER_LEFT_VERTICAL, + LEFT_EDGE | MIDDLE_ELEMENTS | BOTTOM_EDGE | LOWER_RIGHT_VERTICAL, + MIDDLE_ELEMENTS | BOTTOM_EDGE | LOWER_LEFT_VERTICAL, + RIGHT_EDGE | MIDDLE_ELEMENTS | BOTTOM_EDGE | LOWER_LEFT_VERTICAL, + HORIZONTALS | LEFT_EDGE | UPPER_RIGHT_VERTICAL, + LEFT_EDGE | TOP_EDGE | MIDDLE_ELEMENTS + }; + +/* Serial communications definitions. */ const int BUFSIZE = 17; char inbuffer[BUFSIZE]; uint8_t nread = 0; +/* Display memory buffer. */ + uint8_t data[8] = {0, 0, 0, 0, 0, 0, 0, 0}; +/* Display operations. */ + void enable_clock() { Wire.beginTransmission(0x70); @@ -117,7 +151,50 @@ } } -void setup() +/* Data sampling functions. */ + +uint8_t sample_value(uint8_t start, uint8_t end) +{ + uint8_t bit, value; + + value = 0; + + for (bit = start; bit < end; bit++) + { + value = (value << 1) | digitalRead(datapins[bit]); + } + + return value; +} + +void sample_data(uint8_t data[], uint8_t start, uint8_t end) +{ + uint8_t low, high, value; + uint16_t digit_value; + + value = sample_value(start, end); + digit_value = digits[value]; + + /* Switch to little-endian. */ + + data[0] = (uint8_t) (digit_value & 0xff); + data[1] = (uint8_t) (digit_value >> 8); +} + +void scan_inputs(uint8_t data[]) +{ + digitalWrite(MUX_S, 0); + sample_data(&data[2], 4, 8); /* bits 3..0 */ + sample_data(&data[0], 0, 4); /* bits 7..4 */ + + digitalWrite(MUX_S, 1); + sample_data(&data[6], 4, 8); + sample_data(&data[4], 0, 4); +} + +/* Main functions. */ + +void client_setup() { Wire.begin(); Serial.begin(115200); @@ -131,7 +208,39 @@ Serial.println("?"); } -void loop() +void sample_setup() +{ + Wire.begin(); + + pinMode(MUX_S, OUTPUT); + pinMode(D0, INPUT); + pinMode(D1, INPUT); + pinMode(D2, INPUT); + pinMode(D3, INPUT); + pinMode(D4, INPUT); + pinMode(D5, INPUT); + pinMode(D6, INPUT); + pinMode(D7, INPUT); + + init_alphanumeric(); + write_digits(data, 8); + enable_display(); +} + +void setup() +{ + /* client_setup(); */ + sample_setup(); +} + +void sample_loop() +{ + scan_inputs(data); + write_digits(data, 8); + delay(250); +} + +void client_loop() { /* Read bytes, obtaining the number read excluding any newline terminator. */ @@ -156,6 +265,12 @@ } } +void loop() +{ + /* client_loop(); */ + sample_loop(); +} + extern "C" void __cxa_pure_virtual(void) { while(1); } diff -r a9ad2b31a8ff -r 3743948571b3 README.txt --- a/README.txt Sun Jan 10 00:30:41 2016 +0100 +++ b/README.txt Sun Jan 10 22:58:17 2016 +0100 @@ -1,7 +1,7 @@ From the HT16K33 datasheet [1] and EF4058 schematic [2]. Addressing ----------- +========== RAM addresses ROW0..7 ROW8..15 @@ -16,7 +16,7 @@ ROW3..14 | Tube and Digit Layout ---------------------- +===================== By observing the behaviour, the tubes and digits have the following layout: @@ -26,7 +26,7 @@ 1 2 1 2 Communications --------------- +============== I2C commands: @@ -59,7 +59,7 @@ -> 00 80 00 40 00 20 00 10 (bytes in LSB, MSB order) LED Digit Layout ----------------- +================ The digits each have the following layout: @@ -129,8 +129,54 @@ +See the shapes.h file for convenient definitions of the different elements. + +Interfacing +=========== + +It could be useful to interface the display with circuits and to have an +Arduino sample inputs and update the display to reflect the state of those +inputs. In order to represent 16 different signals with 4 hexadecimal digits, +the following circuit could be employed. + +Inputs 74HC157 74HC157 Arduino Display +------ ------- ------- ------- ------- + A4/SDA SDA + A5/SCL SCL + 5V VCC + E# E# GND GND + S S 3 +D0 1I0 +D1 2I0 +D2 3I0 +D3 4I0 +D4 1I0 +D5 2I0 +D6 3I0 +D7 4I0 +D8 1I1 +D9 2I1 +D10 3I1 +D11 4I1 +D12 1I1 +D13 2I1 +D14 3I1 +D15 4I1 + 1Y 4 + 2Y 5 + 3Y 6 + 4Y 7 + 1Y 8 + 2Y 9 + 3Y 10 + 4Y 11 + +By switching between the two multiplexers, the data signals could be sampled +by the Arduino and appropriate representation values written to the display +module memory. + References ----------- +========== [1] EF4058-OCTOPUS_Alphanumeric_V1.0_SCH.pdf [2] EF4058-ht16K33v110.pdf diff -r a9ad2b31a8ff -r 3743948571b3 client.py --- a/client.py Sun Jan 10 00:30:41 2016 +0100 +++ b/client.py Sun Jan 10 22:58:17 2016 +0100 @@ -47,13 +47,14 @@ resp = s.readline().rstrip("\r\n") return resp -def console(): +def console(prompt=True): try: while 1: - cmd = raw_input("> ") - if cmd: - s.write(cmd + "\n") - s.flush() + if prompt: + cmd = raw_input("> ") + if cmd: + s.write(cmd + "\n") + s.flush() print s.readline().rstrip("\r\n") except EOFError: print "Session closed." @@ -62,7 +63,7 @@ openPort() try: - console() + console(not "--read-only" in sys.argv) finally: closePort() diff -r a9ad2b31a8ff -r 3743948571b3 shapes.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/shapes.h Sun Jan 10 22:58:17 2016 +0100 @@ -0,0 +1,64 @@ +#ifndef __SHAPES_H__ +#define __SHAPES_H__ + +#define ROW0 0x0001 +#define ROW1 0x0002 +#define ROW2 0x0004 +#define ROW3 0x0008 +#define ROW4 0x0010 +#define ROW5 0x0020 +#define ROW6 0x0040 +#define ROW7 0x0080 +#define ROW8 0x0100 +#define ROW9 0x0200 +#define ROW10 0x0400 +#define ROW11 0x0800 +#define ROW12 0x1000 +#define ROW13 0x2000 +#define ROW14 0x4000 +#define ROW15 0x8000 + +#define TOP_HORIZONTAL ROW0 +#define UPPER_RIGHT_VERTICAL ROW1 +#define LOWER_RIGHT_VERTICAL ROW2 +#define BOTTOM_HORIZONTAL ROW3 +#define LOWER_LEFT_VERTICAL ROW4 +#define UPPER_LEFT_VERTICAL ROW5 +#define LEFT_MIDDLE_HORIZONTAL ROW6 +#define RIGHT_MIDDLE_HORIZONTAL ROW7 +#define UPPER_LEFT_DIAGONAL ROW8 +#define UPPER_CENTRE_VERTICAL ROW9 +#define UPPER_RIGHT_DIAGONAL ROW10 +#define LOWER_RIGHT_DIAGONAL ROW11 +#define LOWER_CENTRE_VERTICAL ROW12 +#define LOWER_LEFT_DIAGONAL ROW13 +#define DECIMAL_POINT ROW14 + +#define TOP_EDGE TOP_HORIZONTAL +#define UPPER_ELEMENTS (UPPER_LEFT_VERTICAL | UPPER_RIGHT_VERTICAL | UPPER_LEFT_DIAGONAL | UPPER_RIGHT_DIAGONAL | UPPER_CENTRE_VERTICAL) +#define MIDDLE_ELEMENTS (LEFT_MIDDLE_HORIZONTAL | RIGHT_MIDDLE_HORIZONTAL) +#define LOWER_ELEMENTS (LOWER_LEFT_VERTICAL | LOWER_RIGHT_VERTICAL | LOWER_LEFT_DIAGONAL | LOWER_RIGHT_DIAGONAL | LOWER_CENTRE_VERTICAL) +#define BOTTOM_EDGE BOTTOM_HORIZONTAL + +#define LEFT_EDGE (LOWER_LEFT_VERTICAL | UPPER_LEFT_VERTICAL) +#define LEFT_ELEMENTS (LEFT_MIDDLE_HORIZONTAL | UPPER_LEFT_DIAGONAL | LOWER_LEFT_DIAGONAL) +#define CENTRE_ELEMENTS (UPPER_CENTRE_VERTICAL | LOWER_CENTRE_VERTICAL) +#define RIGHT_ELEMENTS (RIGHT_MIDDLE_HORIZONTAL | UPPER_RIGHT_DIAGONAL | LOWER_RIGHT_DIAGONAL) +#define RIGHT_EDGE (LOWER_RIGHT_VERTICAL | UPPER_RIGHT_VERTICAL) + +#define OUTER_FRAME (TOP_HORIZONTAL | RIGHT_EDGE | BOTTOM_HORIZONTAL | LEFT_EDGE) +#define PLUS (LEFT_MIDDLE_HORIZONTAL | RIGHT_MIDDLE_HORIZONTAL | UPPER_CENTRE_VERTICAL | LOWER_CENTRE_VERTICAL) +#define DIAGONALS (UPPER_LEFT_DIAGONAL | UPPER_RIGHT_DIAGONAL | LOWER_RIGHT_DIAGONAL | LOWER_LEFT_DIAGONAL) +#define INNER_ELEMENTS (PLUS | DIAGONALS) +#define HORIZONTALS (TOP_HORIZONTAL | BOTTOM_HORIZONTAL | LEFT_MIDDLE_HORIZONTAL | RIGHT_MIDDLE_HORIZONTAL) + +#define UPPER_TRIANGLE (TOP_HORIZONTAL | UPPER_LEFT_DIAGONAL | UPPER_RIGHT_DIAGONAL) +#define LOWER_TRIANGLE (BOTTOM_HORIZONTAL | LOWER_LEFT_DIAGONAL | LOWER_RIGHT_DIAGONAL) +#define LEFT_TRIANGLE (UPPER_LEFT_VERTICAL | LOWER_LEFT_VERTICAL | UPPER_LEFT_DIAGONAL | LOWER_LEFT_DIAGONAL) +#define UPPER_LEFT_TRIANGLE (UPPER_LEFT_VERTICAL | UPPER_LEFT_DIAGONAL | LEFT_MIDDLE_HORIZONTAL) +#define LOWER_LEFT_TRIANGLE (LOWER_LEFT_VERTICAL | LOWER_LEFT_DIAGONAL | LEFT_MIDDLE_HORIZONTAL) +#define RIGHT_TRIANGLE (UPPER_RIGHT_VERTICAL | LOWER_RIGHT_VERTICAL | UPPER_RIGHT_DIAGONAL | LOWER_RIGHT_DIAGONAL) +#define UPPER_RIGHT_TRIANGLE (UPPER_RIGHT_VERTICAL | UPPER_RIGHT_DIAGONAL | RIGHT_MIDDLE_HORIZONTAL) +#define LOWER_RIGHT_TRIANGLE (LOWER_RIGHT_VERTICAL | LOWER_RIGHT_DIAGONAL | RIGHT_MIDDLE_HORIZONTAL) + +#endif /* __SHAPES_H__ */