Using The Serial 7-Segment Display - Learn
Using The Serial 7-Segment Display - Learn
CONTRIBUTORS:
JIMB0
SHARE
Introduction
The Serial 7-Segment Display is an easy-to-use 4-digit display that is controlled using a
serial interface. Instead of using up a dozen-or-so of your microcontrollers pins to control
the LEDs, all you need is one. Using either a serial, I2C, or SPI interface, you can control
all digits, decimal points, the colon, and the apostrophe.
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
1/19
16/9/2014
In order to make use of the Serial 7-Segment Display, youll need to solder to at least a
few of its pins. That means youll need at least a basic soldering iron as well as solder.
Check out our how to solder tutorial for help, if this is you first time soldering.
Before You Begin
Before reading about how to hook up the Serial 7-Segment Display, itll help to be familiar
with some of these concepts. Consider reading through these tutorials before continuing
on:
Binary - The data sent to the display comes in packets of bytes. In order to control
the decimals or individual segments, knowledge of binary will be important.
How to Solder - To connect to the display, youll have to solder either wire, headers,
or another connector to it.
Serial Communication - This is the simplest of the three communication standards
used to talk to the display.
I2C Communication - I2C is a two-wire serial interface. An alternative to serial for
talking to the display.
SPI Communication - SPI is a three (or four) wire serial interface. The third serial
option for controlling the LED.
What is an Arduino? - In this example, well use an Arduino to control the LED. If
youre not sure what that is, definitely check out this tutorial.
Hardware Overview
This page covers the hardware end of the Serial 7-Segment Display (lets shorten that to
S7S from here on). Everything from the pin-out, to powering the display is covered here.
To begin, we should mention, the display comes in an assortment of color options: red,
green, blue, yellow, and white.
The Pin-Out
The S7S has a lot of pins broken out in just about every-which direction. Relax! Youll
actually only need to connect to about 3-5 of those pins. Most of the pins can be broken
down into categories based on the interface for which theyre used. This image should do
most of the explaining:
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
2/19
16/9/2014
Itll be your choice to decide which of the three serial interfaces youd like to use to connect
to the display. Using a basic serial input, youll only need to connect to the RX pin. I2C
requires two pins, and SPI requires three.
Regardless of which interface you choose to send data, there are two pins to which you
must connect: the power pins! VCC and GND.
Powering the Serial 7-Segment Display
To get a S7S up and running, youll first need to figure out how to power the thing. The
S7S can be powered from a variety of voltage supplies. It can operate at anywhere from
3.0V to 5.5V. Keep in mind that the supply voltage will affect how bright the display is
higher voltages increasing the maximum brightness.
The displays supply voltage is unregulated. So dont give it any crazy-high voltages,
anything over 6.0V will harm the display. Be nice to your S7S!
If youre using an Arduino, you could power the S7S off either the 5V or 3.3V headers.
Dont forget to connect ground (GND) as well.
Serial Interfaces
The Serial in the Serial 7-Segment Displays is something of a generalization. Aptbut
this display actually offers three different serial methods of interfacing: Serial UART, SPI
and I2C. Each of these interfaces offer their own benefits and disadvantages. A big
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
3/19
16/9/2014
difference between each of the communication protocols is the number of pins each
requires. They also each add their own level of complexity on the firmware end (though,
with Arduino, libraries really simplify the task).
UART Serial
UART serial, or TTL serial, this may be the most basic serial communication method on
the S7S. If youve played around with Arduino, youve probably used the hardware UART
to relay information back to your computer via the Serial Monitor. Or set up a software
serial port using the SoftwareSerial library. This form of serial communication is
asynchronous, meaning the data is transmitted without any help from a parallel clock
signal. This makes our job easier and harder. Easier in that we only need one wire (RX) to
communicate with the display. Harder in that extra attention needs to be paid to making
sure timing between bits is exact.
The S7S supports a range of very common baud rates, and defaults to everyones favorite
- 9600. The baud rate can be adjusted, if you please, but the display will only allow for 8
data-bits, no parity, and 1 stop bit (8N1).
Serial Peripheral Interface (SPI)
SPI is a synchronous serial communication method. Its kind of like taking the UART
method above and adding a clock signal. This way we dont have to worry about what
speed we send data (as long as its not too fast), but we do require the use of two more
pins.
SPI requires three wires for communication: data (SDI, thats Serial Data In), clock (SCK,
Serial Clock) and slave-select (SS, with a bar over it meaning its active low), which is
also known as chip select (CS). A couple caveats on this serial method: the maximum
clock speed for the S7S is 250kHz. And, data is clocked in on the rising edge of the
clock (when it goes from 0V to 5V). It is also worth noting that the SPI connections on the
master device, the Arduino in this case, are typically labeled MISO (Master In Slave Out)
and MOSI (Master Out, Slave In). The MOSI line connects to SDI on the S7S, whereas the
MISO line connects to the SDO line.
Thanks to the slave-select pin, we can connect multiple SPI devices on a single bus. You
could even connect multiple S7Ss on the same bus, provided each had its own dedicated
select pin.
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
4/19
16/9/2014
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
5/19
16/9/2014
Assembly
To interface other electronics to the display, youll need to solder to some of the S7Ss
pins. Before you do any soldering, though, think on how you want to use the display. Do
you plan on using one of the serial interfaces in particular? Maybe you only need to solder
to the power pins, and the few pins which correspond to your preferred interface. Are you
just prototyping with the display? Are you mounting it in an project enclosure? Your
assembly method really depends on what your final goals for the display are.
For many use cases, youll really only need the pins on the top header. When I prototype
with these displays, I like to solder some straight male headers in, so I can stick it into a
breadboard.
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
6/19
16/9/2014
Of course, you could solder stranded or solid-core wires into the pins you need. This is
useful if you plan on mounting the display in an enclosure.
If you intend to ever reprogram the display using an FTDI Basic, you might find it useful to
solder some right-angle male headers into the serial programming header. This can be a
bit tricky, as the display gets in the way. I solder my right-anglers on the curved side.
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
7/19
16/9/2014
Finally, if youll be mounting the display, any 4-40 screw should be able to find its way
through those stand-off holes.
7-Segment Shield
If youre looking for an even simpler form factor of the S7S, take a look at the 7-Segment
Shield display. The S7S Display Shield is an Arduino shield designed to run on top of an
Arduino Uno or an Arduino Uno compatible board. It runs the same firmware as the
OpenSegment and Serial 7-Segment displays and is controlled in the same manner. It is
arguably the easiest of the three to get up in running as all you have to do is populate the
standard Arduino headers, and then plug the shield into an Arduino Uno compatible board.
For more instructions on shield assembly, visit our shield tutorial.
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
8/19
16/9/2014
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
9/19
16/9/2014
So what about I2C? Well while I2C cant be disabled in the same manner, it shouldnt
conflict with another I2C device on the same bus unless they share the same address. In
this case, you can reprogram the shields firmware with a different I2C address. The
shields I2C address is 0x71 by default.
Super Quick Start Guide
1.
2.
3.
4.
5.
6.
If youre ready to take the plunge into creating your own sketches, feel free. If you want a
bit more explanation of one of the basic sketches, visit the following coding sections of this
tutorial. Simply plug in your shield to an Arduino, and follow along.
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
10/19
16/9/2014
Firmware Overview
All of the firmware found in this tutorial can be found on the S7S GitHub page.
Before really delving into the examples, we should discuss what types of data should be
sent to the display. As mentioned in the hardware section, the display provides for three
serial modes of communication. In each serial mode, data is sent to the display one byte
at-a-time. The byte (as bytes go) can be any value from 0 to 255. Data sent to the display
will fall into one of three categories: (1) displayable data, (2) command bytes, and (3)
command data bytes.
Displayable Data
Displayable data is just that: data sent to the S7S with the intent of actually being
displayed. Displayable data bytes include any value from 0-15, and a select few ASCII
values.
Bytes of value 0-15 will display their hex equivalent (0-9, A-F) on the display. ASCII values
(for only the characters that can actually be displayed) will generate an equivalent LED
pattern. Not all characters are displayable (the display does what it can with its limited
resolution). Heres a table of byte values and the characters displayed:
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
11/19
16/9/2014
For example, to display 12Ab you could send a variety of 4-byte patterns:
The actual byte values 1, 2, 10, and 11: [0x01] [0x02] [0x0A] [0x0B]
ASCII values for 1, 2, a, and b: [0x31] [0x32] [0x41] [0x42]
Or any combination of binary and ASCII values could be used:
[0x01] [0x32] [0x41] [0x0B] , etc.
Cursor
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
12/19
16/9/2014
Another controlling factor in displaying data is the cursor, which decides where the next
piece of received display data will be displayed. You cant see it, but its there. When the
S7S starts up, itll set the cursor to the left-most digit. Every displayable piece of data
moves the cursor right one digit, until it wraps around from the fourth digit to the first. The
above example assumes the cursor is set at the left-most digit. If not, the display might
show 2Ab1, Ab12, or b12A.
Special Commands
Special commands exist to perform non-displayable actions on the display. Actions like
clearing the display, setting the cursor, and turning the decimal points on/off are triggered
using special commands. In some cases special commands should be followed by a
command data byte.
For a complete reference of the available commands, check out the Special Commands
section of the datasheet. Lets cover some of the more useful commands: clear display
and cursor control.
Clear Display
The clear display command is a single byte of value 0x76. When this value is received by
the display two actions are performed: (1) everything on the display is turned off (segments
and decimal points), and (2) the cursor is reset to the left-most digit. This command is
useful in the example above, if you want to guarantee that the cursor is at the left-most of
the display when display data begins coming in.
Cursor Control
The cursor control command is a good example of a command byte that must be followed
by a data byte. The cursor command is 0x79, but immediately trailing that should be
another byte representing which position you want the cursor to take (e.g. 0 for left-most, 3
for right-most). For example, to set the cursor to the third digit from the left, send 0x79
followed by 0x02 .
Heres a quick table of the commands, their command-byte value, and any data-byte they
may require:
Special Command Command byte Data byte range
Clear display
Decimal control
0x76
0x77
None
0-63
Cursor control
0x79
0-3
0=left-most, 3=right-most
Brightness control
0x7A
0-255
0=dimmest, 255=brightest
Digit 1 control
0x7B
0-127
Digit 2 control
0x7C
0-127
Digit 3 control
0x7D
0-127
Digit 4 control
0x7E
0-127
0x7F
0-11
0x80
1-126
0x81
None
I2C
Address config
Factory reset
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
13/19
16/9/2014
Really, you can use any digital pin to serve as the Arduinos software TX pin. Just make
sure you change it in the code. Speaking of the code copy/past this, or you can download
it from here:
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
14/19
16/9/2014
// Set the displays brightness. Should receive byte with the value
// to set the brightness to
// dimmest------------->brightest
//
0--------127--------255
void setBrightness(byte value)
{
s7s.write(0x7A); // Set brightness command byte
s7s.write(value); // brightness data byte
}
// Turn on any, none, or all of the decimals.
// The six lowest bits in the decimals parameter sets a decimal
// (or colon, or apostrophe) on or off. A 1 indicates on, 0 off.
// [MSB] (X)(X)(Apos)(Colon)(Digit 4)(Digit 3)(Digit2)(Digit1)
void setDecimals(byte decimals)
{
s7s.write(0x77);
s7s.write(decimals);
}
In that code there are example functions for setting the displays brightness, decimals, and
clearing the display. Check out the functions and the comments, for more details.
The sketch begins by cycling through a select few brightnesses, so you can see what the
display looks at its dimmest and brightest. Following that, it turns into a stopwatch, making
use of the s7s.print() function to send data to the display via the software serial library.
Example 2: SPI
SPI is a useful communication method if you have more than one device to hook up on a
single bus. It requires more wires than basic serial, but its more dependable because its a
synchronous interface.
In this example, well only use a single display. Realize, though, that you could add more
displays (or other SPI devices) to the same SPI bus, each requiring only an additional SS
pin per device.
Heres the hardware setup:
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
15/19
16/9/2014
The SDI and SCK pins must remain where they are on the Arduino - those are the
hardware SPI pins. The SS pin could be moved to any digital pin, as long as its changed
in the code.
Speaking of code, copy/paste from below, or you can download it in a zip file by clicking
here.
/* Serial 7-Segment Display Example Code
SPI Mode Stopwatch
by: Jim Lindblom
SparkFun Electronics
date: November 27, 2012
license: This code is public domain.
COPY CODE
This example code shows how you could use the Arduino SPI
library to interface with a Serial 7-Segment Display.
There are example functions for setting the display's
brightness, decimals and clearing the display.
The SPI.transfer() function is used to send a byte of the
SPI wires. Notice that each SPI transfer(s) is prefaced by
writing the SS pin LOW and closed by writing it HIGH.
Each of the custom functions handle the ssPin writes as well
as the SPI.transfer()'s.
There's a custom function used to send a sequence of bytes
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
16/19
16/9/2014
This example works a lot like the serial version. The s7s.print() functions from the
previous example are replaced by SPI transfers. Take note that each time an
SPI.transfer() occurs, its blanketed by two digitalWrite() s to the SS pin. The SS pin
must go LOW, to let the display know that usable data is incoming. Once SS goes back to
HIGH, the display will know that data is no longer being sent to it.
Example 3: I2C
Finally, I2C. I2C is a really powerful communication method, but its also the most
complicated of the three discussed here. Happily, though, Arduinos got a great library
(Wire) to handle all of the nasty I2C stuff.
Only two data wires are required for I2C a data line (SDA) and a clock line (SCL). Dont
forget power! Heres how to hook it up:
Theres not any give in this pin configuration; youll have to use the hardware I2C pins.
Older Arduinos may not have the devoted SDA and SCL pins. They should still be there,
on pins A4 and A5 respectively.
You may have noticed I2C pins (as well as power pins) exist on both sides of the S7S.
These are useful if you want to link many S7Ss together on a single I2C bus. Thanks to
I2Cs addressing scheme, you could chain a large-ish number of Serial 7-Segment
displays using just these two I2C pins. Should be useful if youre making a national debt
clock!
2
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
17/19
16/9/2014
Heres some example code, using I2C (download here). The functionality is comparable to
the last couple of example sketches:
/* Serial 7-Segment Display Example Code
I2C Mode Stopwatch
by: Jim Lindblom
SparkFun Electronics
date: November 27, 2012
license: This code is public domain.
COPY CODE
This example code shows how you could use the Arduino Wire
library to interface with a Serial 7-Segment Display.
There are example functions for setting the display's
brightness, decimals, clearing the display, and sending a
series of bytes via I2C.
Each I2C transfer begins with a Wire.beginTransmission(address)
where address is the 7-bit address of the device set to
receive the data. Wire.write() sends a byte of data. I2C
communication is closed with Wire.endTransmission().
Circuit:
NowArduino
SPI.transfer() s from the last example are replaced with Wire.write() s. And
-------------- Serial 7-Segment
instead5Vof toggling
a SS pin, we use
-------------------VCC Wire.beginTransmission(address) and
Wire.endTransmission()
GND -------------------. Easy enough!
GND
SDA
SCL
---------------------------------------
Going
Further
*/
#include
<Wire.h>
// Include
the one
Arduino
SPISerial
library
Now
that youre
comfortable
using
of the
7-Segment Displays, why not check
out some of these related tutorials:
// Here we'll define the I2C address of our S7S. By default it
// should
be 0x71.
This can be
changed,
though. is the big brother to the Serial 7Using the
OpenSegment
- The
OpenSegment
constSegment
byte s7sAddress
=
0x71;
Display. They run on the same firmware, however the OpenSegment is
and firmware
files are open-source. Theyre posted on github. Check out this tutorial if need help
void downloading
setup()
from github.
{
Using GitHub to Share with SparkFun - Since this product is open-source, we
Wire.begin(); // Initialize hardware I2C pins
encourage our customers to use and modify our source files. Then you can share
and we
can
make
better!and decimals
// them
Clearwith
the us,
display,
and
then
turnthe
onproduct
all segments
clearDisplayI2C();
Resources
// Custom function to send four bytes via I2C
For //
even
more
information,
please
the Serial
github repository.
The
I2C.write
function
only check
allowsout
sending
of a 7-Segments
single
There
// youll
byte find:
at a time.
s7sSendStringI2C("-HI-");
Datasheet - A Wiki containing
all of
you should
setDecimalsI2C(0b111111);
// Turn
on the
all information
decimals, colon,
apos
display.
// Arduino
Flash brightness
valuesgalore
at the- We
beginning
Example Code
went a
setBrightnessI2C(0); // Lowest brightness
something useful here.
delay(1500);
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
18/19
16/9/2014
Firmware - If youre interested in modifying the behavior of the S7S, definitely check
out the firmware (written in Arduino).
In addition to the firmware, youll also need to add the SevSeg library to your
Arduino install.
Hardware - The Eagle files are hosted here. Do you want to make your own version
of the display? Go for it! This is an open-source project.
SHARE
Want more information about SparkFun's classes? Interested in getting involved with
teaching electronics? Just want to talk? Sign up for our newsletter, or contact our
education department.
SparkFun is a company built around one core idea sharing ingenuity. We think
everyone should have the hardware and resources to learn and play with cool
electronic gadgetry.
Share, give, learn, SparkFun.
Do you regularly instruct classes and workshops in a formal or informal learning
environment? SparkFun offers Educator Discounts to people teaching and sharing
electronics.
Find out more.
SparkFun Electronics
https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display#example-1-serial-uart
19/19