I built another handy circuit to ‘house’ a 4 character 7 segment display. It looks like this:
Basically it just ‘breaks out’ the 16 pins of the display with two 8 pin female headers. Pins 1-8 are connected to the header at the bottom and pins 9-16 are connected to the header at the top. Note that 6 220 Ohm resistors are needed to protect the LEDs.
The Fritzing diagram to the right (Download Link) shows which pins select which character (colon or apostrophe) is selected to turn on and thus needs a resistor. The LEDs actually light a bar shape. Each ‘character’ is composed of 7 LEDs (or segments). The image below shows what each of the pins controls.
The LED pattern is as follows:
Four of these characters go together to be able to display things like time, temperature, voltage, etc.
The technical manual is HERE. The pin functions (1-8 bottom and 9-16 top) are as follows:
1 2 3 4 5 6 7 8 |
1: Digit 1 16: B 2: Digit 2 15: G 3: D 14: A 4: Colon Anode 13: C 5: E 12: Colon Cathode 6: Digit 3 11: F 7: Decimal Point 10:Apostrophe Anode 8: Digit 4 9: Apostrophe Cathode |
Connecting this 4 character 7 segment display to an Arduino is usually done in conjunction with 1 or more shift registers due to having so many wires. Connecting without the shift register, an arduino looks like it needs a ‘hair cut’ with so many ‘wires’ all over the place.
I connected my 4 character 7 segment display circuit with two 74HC595 (shift register IC) breakout modules. Each 74HC595 module controls 8 pins (1 shift register for the bottom 8 pins and one for the top 8). With these modules, only 3 wires (besides power and ground) connect to the Arduino.
Using an Arduino library designed for the 74HC595 shift register makes it easier to control the display. I like this shifter library hosted on GitHub. With it, each pin is easily referenced by number.
Here is a an Arduino sketch I created to display current voltage on the 4 character 7 segment display :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
#include <Shifter.h> #define SER_Pin 4 #define RCLK_Pin 3 #define SRCLK_Pin 2 #define NUM_REGISTERS 2 Shifter shifter(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS); /* A F B G E C D 1 Digit 1 2 Digit 2 3 D 4 Colon Anode 5 E 6 Digit 3 7 Decimal Point 8 Digit 4 9 Apostrophe Cathode 10 Apostrophe Anode 11 F 12 Colon Cathode 13 C 14 A 15 G 16 B */ void setup(){ shifter.clear(); shifter.write(); } void displayDigit(int num) { switch(num) { case 0: shifter.setPin(13, LOW); // A shifter.setPin(15, LOW); // B shifter.setPin(12, LOW); // C shifter.setPin(2, LOW); // D shifter.setPin(4, LOW); // E shifter.setPin(10, LOW); // F shifter.setPin(14, HIGH); // G shifter.setPin(6, HIGH); // DP break; case 1: shifter.setPin(13, HIGH); // A shifter.setPin(15, LOW); // B shifter.setPin(12, LOW); // C shifter.setPin(2, HIGH); // D shifter.setPin(4, HIGH); // E shifter.setPin(10, HIGH); // F shifter.setPin(14, HIGH); // G shifter.setPin(6, HIGH); // DP break; case 2: shifter.setPin(13, LOW); // A shifter.setPin(15, LOW); // B shifter.setPin(12, HIGH); // C shifter.setPin(2, LOW); // D shifter.setPin(4, LOW); // E shifter.setPin(10, HIGH); // F shifter.setPin(14, LOW); // G shifter.setPin(6, HIGH); // DP break; case 3: shifter.setPin(13, LOW); // A shifter.setPin(15, LOW); // B shifter.setPin(12, LOW); // C shifter.setPin(2, LOW); // D shifter.setPin(4, HIGH); // E shifter.setPin(10, HIGH); // F shifter.setPin(14, LOW); // G shifter.setPin(6, HIGH); // DP break; case 4: shifter.setPin(13, HIGH); // A shifter.setPin(15, LOW); // B shifter.setPin(12, LOW); // C shifter.setPin(2, HIGH); // D shifter.setPin(4, HIGH); // E shifter.setPin(10, LOW); // F shifter.setPin(14, LOW); // G shifter.setPin(6, HIGH); // DP break; case 5: shifter.setPin(13, LOW); // A shifter.setPin(15, HIGH); // B shifter.setPin(12, LOW); // C shifter.setPin(2, LOW); // D shifter.setPin(4, HIGH); // E shifter.setPin(10, LOW); // F shifter.setPin(14, LOW); // G shifter.setPin(6, HIGH); // DP break; case 6: shifter.setPin(13, LOW); // A shifter.setPin(15, HIGH); // B shifter.setPin(12, LOW); // C shifter.setPin(2, LOW); // D shifter.setPin(4, LOW); // E shifter.setPin(10, LOW); // F shifter.setPin(14, LOW); // G shifter.setPin(6, HIGH); // DP break; case 7: shifter.setPin(13, LOW); // A shifter.setPin(15, LOW); // B shifter.setPin(12, LOW); // C shifter.setPin(2, HIGH); // D shifter.setPin(4, HIGH); // E shifter.setPin(10, HIGH); // F shifter.setPin(14, HIGH); // G shifter.setPin(6, HIGH); // DP break; case 8: shifter.setPin(13, LOW); // A shifter.setPin(15, LOW); // B shifter.setPin(12, LOW); // C shifter.setPin(2, LOW); // D shifter.setPin(4, LOW); // E shifter.setPin(10, LOW); // F shifter.setPin(14, LOW); // G shifter.setPin(6, HIGH); // DP break; case 9: shifter.setPin(13, LOW); // A shifter.setPin(15, LOW); // B shifter.setPin(12, LOW); // C shifter.setPin(2, LOW); // D shifter.setPin(4, HIGH); // E shifter.setPin(10, LOW); // F shifter.setPin(14, LOW); // G shifter.setPin(6, HIGH); // DP break; } } void turnOnChar(int num) { switch(num) { case 1: shifter.setPin(0, HIGH); shifter.setPin(1, LOW); shifter.setPin(5, LOW); shifter.setPin(7, LOW); break; case 2: shifter.setPin(0, LOW); shifter.setPin(1, HIGH); shifter.setPin(5, LOW); shifter.setPin(7, LOW); break; case 3: shifter.setPin(0, LOW); shifter.setPin(1, LOW); shifter.setPin(5, HIGH); shifter.setPin(7, LOW); break; case 4: shifter.setPin(0, LOW); shifter.setPin(1, LOW); shifter.setPin(5, LOW); shifter.setPin(7, HIGH); break; default: break; } } void loop() { long vcc; int num4,num3,num2,num1; vcc = readVcc(); num4 = (vcc / 10) % 10; num3 = (vcc / 100) % 10; num2 = (vcc / 1000) % 10; num1 = (vcc / 10000) % 10; if (num1 != 0) { turnOnChar(1); displayDigit(num1); shifter.write(); delay(2); } turnOnChar(2); displayDigit(num2); shifter.setPin(6,LOW); shifter.write(); delay(2); turnOnChar(3); displayDigit(num3); shifter.write(); delay(2); turnOnChar(4); displayDigit(num4); shifter.write(); delay(2); } long readVcc() { // Read 1.1V reference against AVcc // set the reference to Vcc and the measurement to the internal 1.1V reference #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = _BV(MUX5) | _BV(MUX0); #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) ADMUX = _BV(MUX3) | _BV(MUX2); #else ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #endif #if defined(__AVR_ATmega2560__) ADCSRB &= ~_BV(MUX5); // Without this the function always returns -1 on the ATmega2560 #endif delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA,ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high<<8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts } |
Notice that I created functions to select the specific character to turn on and a function to turn on the LED segments needed to display each number digit. With the shifter library and these functions, you are all set to make something interesting! How about a multimeter?
Recent Comments