Pop Gheorghe
Published © CC BY

DIY 7-Segment Display

Hi, In this post I will show you how you can build a diy seven segment display with the help of a 3D printer, an Arduino and some LED bar...

IntermediateFull instructions provided3 hours5,372
DIY 7-Segment Display

Things used in this project

Hardware components

Arduino Pro Mini 328 - 5V/16MHz
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
AMS1117
×1
LED BAR
×1
BSS138
×8
Resistor 10k ohm
Resistor 10k ohm
×8
Resistor 330 ohm
Resistor 330 ohm
×1

Software apps and online services

Fusion
Autodesk Fusion
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Thingiverse

https://www.thingiverse.com/thing:2822041

Schematics

7seg_brd_3jBWc1f2x0.PNG

7seg_sch_Pb6ifC5nr6.PNG

Code

7 segment display counter

Arduino
/*  7 segment display counter
    
    This sketch counts from 0 to 9 on a 7-segment display
    
    The circuit:
      
           A
          ____
         |    |
      F  |____|  B
         | G  |
      E  |____|  C 
                o DP
           D
           
      7-segment 10-pin package:
      
      10 9 8 7 6 
       ________
      |   __   |
      |  |__|  |
      |  |__|o |
      |________| 
      
      1 2 3 4 5  
      
      * If you have a common cathode device, uncomment line X
      * You only need to connect either pin 3 OR pin 8
      * 1 (E) connect to arduino pin 4
      * 2 (D) connect to arduino pin 3
      * 3 common-anode connect to +, common-cathode to -
      * 4 (C) connect to arduino pin 2
      * 5 (DP) connect to arduino pin 7
      * 6 (B) connect to arduino pin 1
      * 7 (A) connect to arduino pin 0
      * 8 common-anode connect to +, common-cathode to -
      * 9 (F) connect to arduino pin 5
      * 10 (G) connect to arduino pin 6
      
      This example is placed in the Public Domain and is free
      for your use/modification for any purpose
*/
  
#include "Seg7.h"
 
Seg7 s7;  // object
 
void setup()   {
  s7.set_cathode(true);  // set for common-cathode
  s7.attach(10, 13, 15, 17, 14, 12,11, 16);  // attach a single 7-segment display
//Serial.begin(9600);
}
 
void loop()                     
{
  for (int i = 0; i < 10; i++) {  // count from 0-9
    s7.write(i);
    //Serial.println(i);
    delay(1000);  // wait 1 second
  }
}

7 segment display slave

Arduino
#include "Seg7.h"
#include <Wire.h>
 
Seg7 s7;
int x, oldx;
void setup() {
  //Address handling pins
  pinMode(8, OUTPUT);  pinMode(6, INPUT);  pinMode(7, INPUT);
  digitalWrite(8, HIGH);
 
  int adress = 1;//here we establish the adress of the digit
  if (digitalRead(6) == HIGH) adress += 1;//here we establish the adress of the digit
  if (digitalRead(7) == HIGH) adress += 2;//here we establish the adress of the digit
 
  s7.set_cathode(true);
  s7.attach(10, 13, A1, A3, A0, 12, 11, A2); // attach a single 7-segment display
  /*below are the pin config
             A[10]
            _____
           |     |
    [12]F  |_____|  B[11]
           |G[13]|
    [A1]E  |_____|  C[A0]
                  o DP[A3]
             D[A2]
  */
 
  Serial.begin(9600);
  Serial.print(adress);
  Wire.begin(adress);                // join i2c bus with address #2
  Wire.onReceive(receiveEvent); // register event
  x = 0;
  oldx = x;
}
 
void loop() {
  // put your main code here, to run repeatedly:
  if (oldx != x) {//only update if we have a change
    s7.write(x);
    oldx = x;
  }
  //delay(100);
}
 
//what is received via I2C is shoun on the display
void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
  }
  x = Wire.read();    // receive byte as an integer
}

7 segment display master

Arduino
#include <Wire.h>
void setup() {
  // put your setup code here, to run once:
  Wire.begin();
  Serial.begin(9600);
}
int nDevices, u;
int adrese[10];
int contor = 999;
void loop() {
  // put your main code here, to run repeatedly:
  scanare();//make a scann to see if aditional digits were added
  for (int j = 0; j <= contor; j++) {
    if (j <= (contor % powint(10, nDevices))) {
      numar(j);
      delay(100);
    }
  }
 
  delay(5000);
}
 
 
// transmit to device
void numar(int nr) {
  for (int i = 0; i < nDevices; i++) {
    u = ((nr / powint(10, i)) % 10);
    Wire.beginTransmission(adrese[nDevices - i - 1]);
    Wire.write(u);
    Wire.endTransmission();
  }
}
 
void scanare() {
  byte error, address;
  nDevices = 0;
  for (address = 1; address < 10; address++ )
  { Wire.beginTransmission(address);
    error = Wire.endTransmission();
    if (error == 0)
    { adrese[nDevices] = address;
      nDevices++;
    }
  }
}
 
//function used for rais an int at a specific power
int powint(int x, int y)
{
  int val = x;
  for (int z = 0; z <= y; z++)
  {
    if (z == 0)
      val = 1;
    else
      val = val * x;
  }
  return val;
}

Github

https://github.com/depletionmode/seg7

Github

https://github.com/roroid/7-segment

Credits

Pop Gheorghe

Pop Gheorghe

4 projects • 4 followers

Comments