Devices & Components
Through Hole Resistor, 510 ohm
LM7805 Voltage regulator
Shift register - TPIC6B595
10k resistor
Through Hole Resistor, 270 ohm
2.3" 7-segment dislplay
74AHCT125 Quad Level-Shifter
Hardware & Tools
Soldering iron (generic)
Software & Tools
Arduino IDE
KiCad
Project description
Code
Demo code
cpp
Demo and test code for the display
1// DM134B test program using hardware SPI (or ShiftOut) 2// This displays a seconds counter that counts from 0-999 seconds then resets. 3// If you added a button and relevant code you could use this as a stopwatch. 4// SoftPWM library used to avoid conflicts with timers and SPI when using hardware PWM 5// the SoftPWM library allows the display brightness to be adjusted in software. 6// This circuit will draw approx 600mA at full brightness displaying 8888 (21.5mA per segment) 7// If high brightness not required either back off using onboard brightness pot or set to max 4 8// brightness if using software control to adjust brightness through PWM. This will reduce power useage. 9// For example if using for a clock you could automatically dim the display at night. 10 11// 7-segment digits 0-9 12// {Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7} --> {g, f, e, d, c, b, a, DP} 13 14#include <SPI.h> 15#include <SoftPWM.h> 16 17int dm134_clock = 13; 18int dm134_latch = 10; // DM134B datasheet says active low but seems to be active high (like a '595)? 19int dm134_data = 11; 20int dm134_OE = 9; // output enable; Active LOW. Can be used to control brightness with PWM. 21 22int brightness = 5; // set display brightness. 1-5 23int brt = 0; // value for storing reversed PWM percentage 24 25long int cnt = 0; // counter initial value = 0 26unsigned long previousMillis = 0; 27const long interval = 10; 28 29unsigned char Data[] = {0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b}; // array without decimal point in hex 30 31byte ssddigits[10] = // array without decimal points on 32{ 33 B01111110, // 0 34 B00001100, // 1 35 B10110110, // 2 36 B10011110, // 3 37 B11001100, // 4 38 B11011010, // 5 39 B11111010, // 6 40 B01001110, // 7 41 B11111110, // 8 42 B11011110, // 9 43}; 44 45byte ssddigitsDP[10] = // array with decimal points on 46{ 47 B01111111, // 0 48 B00001101, // 1 49 B10110111, // 2 50 B10011111, // 3 51 B11001101, // 4 52 B11011011, // 5 53 B11111011, // 6 54 B01001111, // 7 55 B11111111, // 8 56 B11011111, // 9 57}; 58 59void setup() 60{ 61 62 pinMode (dm134_clock, OUTPUT); 63 pinMode (dm134_latch, OUTPUT); 64 pinMode (dm134_data, OUTPUT); 65 pinMode (dm134_OE,OUTPUT); 66 digitalWrite(dm134_OE,LOW); // enable output of DM134B. 67 setBrt(); 68 SoftPWMBegin(); 69 SoftPWMSet(9, 0); // init software PWM on pin 9. This pulses the DM134 OE pin on and off to control brightness. 70 SoftPWMSetPercent(9, brt); 71 72} 73 74void setBrt() // this changes the DM134 brightness logarithmic reversed scale to a more linear one 75 76{ 77 if (brightness == 1) 78 brt = 90; 79 80 else if (brightness == 2) 81 brt = 75; 82 83 else if (brightness == 3) 84 brt = 50; 85 86 else if (brightness == 4) 87 brt = 30; 88 89 else if (brightness == 5) 90 brt = 0; 91} 92 93void loop() 94{ 95 unsigned long currentMillis = millis(); 96 97 if (currentMillis - previousMillis >= interval) 98 { 99 previousMillis = currentMillis; 100 cnt++; 101 } 102 103 if (cnt == 999999) 104 { 105 cnt = 0; 106 } 107 108 109 110 displayNum(); 111} 112 113void displayNum() 114{ 115 116//long int num = analogRead(0); 117//long int num = 1234; 118long int num = cnt; 119 120// get digit 0 121int dig5 = num % 10; // ones 122// get digit 1 123int dig4 = (num / 10) % 10; // tens 124// get digit 2 125int dig3 = (num / 100) % 10; // hundreds 126// get digit 3 127int dig2 = (num / 1000) % 10; // thousands 128// get digit 4 129int dig1 = (num / 10000) % 10; // tenthousands 130// get digit 5 131int dig0 = (num / 100000) % 10; // hundredthousands 132 133SPI.beginTransaction(SPISettings(8000000, LSBFIRST, SPI_MODE0)); //reverse digits if left to right 134digitalWrite(dm134_latch,LOW); 135SPI.transfer(ssddigits[dig0]); 136SPI.transfer(ssddigitsDP[dig1]); 137SPI.transfer(ssddigits[dig2]); 138SPI.transfer(ssddigitsDP[dig3]); 139SPI.transfer(ssddigits[dig4]); 140SPI.transfer(ssddigits[dig5]); 141digitalWrite(dm134_latch,HIGH); 142SPI.endTransaction(); 143 144/* 145// shift out digits 146digitalWrite(dm134_latch,LOW); 147shiftOut(dm134_data, dm134_clock, LSBFIRST, ssddigits[dig3]); 148shiftOut(dm134_data, dm134_clock, LSBFIRST, ssddigits[dig2]); 149shiftOut(dm134_data, dm134_clock, LSBFIRST, ssddigitsDP[dig1]); 150shiftOut(dm134_data, dm134_clock, LSBFIRST, ssddigits[dig0]); 151//shiftOut(dm134_data, dm134_clock, LSBFIRST, B00000001); // DP test 152//shiftOut(dm134_data, dm134_clock, LSBFIRST, B00000001); // DP test 153digitalWrite(dm134_latch,HIGH); 154 155*/ 156 157}
Downloadable files
Schematic
Schematic for the SPI display
6 digit SPI Schematic.jpg

Bill of materials
Complete list of components
6 digit SPI display.csv
Comments
Only logged in users can leave comments