Contents
Do you find it troublesome to control the 7 segment display one at a time? Well, to solve this problem, let’s use the 7 segment serial display instead. In this tutorial, I’ll be using a 8 Digit 7-Segment Serial Display that utilises the SPI protocol, and after that, I’ll daisy-chain 2 of the display & run a scroll demo with 2 of it.
Overview
Single 8 Digit 7-Segment Serial Display
The above module actually uses the MAX7219 LED driver for controlling each 7 segment display. For more information on how SPI works, you can visit: https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi. The driver actually implement a SPI compatible slave interface that can be controlled from the Arduino.Therefore, for the first part of the tutorial, we will be interfacing this module with an Arduino Uno using only 3 of the digital output pins.
Parts
- Arduino Uno x 1
- 8 Digit 7-Segment Serial Display module (SPI) x 1
- Jumper wires
Schematics
Demo
This is just a short demonstration of it.
Code
We would be using the LedControl library to simplify things, which is comes with the Arduino IDE.
//We have to include the library #include "LedControl.h" /* Now we need a LedControl to work with. pin 11 is connected to the DataIn pin 13 is connected to the CLK pin 10 is connected to LOAD We have only a single MAX72XX. */ LedControl lc = LedControl(11,13,10,2); void printNumber(int v); void setup() { // Initialize the 7 Segment lc.shutdown(0,false); // Enable display lc.setIntensity(0,5); // Set brightness level (0 is min, 15 is max) lc.clearDisplay(0); // Clear display register } } void loop() { for(int i =0;i<10000;i++){ printNumber(i); delay(100); } //delay(100); } void printNumber(int v) { int ones; int tens; int hundreds; int thousands; if(v < 100000){ ones=v%10; v=v/10; tens=v%10; v=v/10; hundreds=v%10; v=v/10; thousands=v; //Now print the number digit by digit lc.setDigit(0,3,(byte)thousands,false); lc.setDigit(0,2,(byte)hundreds,false); lc.setDigit(0,1,(byte)tens,false); lc.setDigit(0,0,(byte)ones,false); } else{ lc.setChar(0,0,'E',false); } }
Connecting two 8 Digit 7-Segment Serial Display together
How do we transmit information using 2 of the modules? Well, we will be daisy chaining the 7-segment displays together, and since both uses SPI for communication.
Parts
- Arduino Uno x 1
- 8 Digit 7-Segment Serial Display module (SPI) x 2
- Jumper wires
Schematics
Demo
Code
//We always have to include the library #include "LedControl.h" /* Now we need a LedControl to work with. pin 11 is connected to the DataIn pin 13 is connected to the CLK pin 10 is connected to LOAD We have only a single MAX72XX. */ LedControl lc = LedControl(11,13,10,2); void setup() { // Initialize the 2 MAX7219 devices for(int k=0; k<2; k++){ lc.shutdown(k,false); // Enable display lc.setIntensity(k,5); // Set brightness level (0 is min, 15 is max) lc.clearDisplay(k); // Clear display register } } void loop() { for(int j =0; j<2;j++){ int count=0; for(int i =0;i<9;i++){ lc.setChar(j,i,'-',false); lc.setDigit(j,i-1,i,false); delay(300); lc.clearDisplay(j); } } } void printNumber(int v) { int ones; int tens; int hundreds; int thousands; int ten_thousand; if(v < 100000){ ones=v%10; v=v/10; tens=v%10; v=v/10; hundreds=v%10; v=v/10; thousands=v; //Now print the number digit by digit lc.setDigit(0,3,(byte)thousands,false); lc.setDigit(0,2,(byte)hundreds,false); lc.setDigit(0,1,(byte)tens,false); lc.setDigit(0,0,(byte)ones,false); } else{ lc.setChar(0,0,'E',false); } }