SparkFun 7-Segment Serial Display
Overview
The SparkFun 7-Segment Serial Display is an easy to interface, yet powerful display option for the mbed. This display, powered by the same ATMega328 found on many Arduino boards, supports SPI, Serial UART, and I2C communications. This board is available from Sparkfun in a variety of colors including red, blue, and green. The brightness of the board is dependent on the input voltage, as it will accept anywhere between 3.3V and 5V. The display is also mounted flush against the edge of the board with additional pinouts for easy series wiring on a single I2C bus.
Additional documentation can be found at the github page created by SparkFun.
UART
Serial UART is the simplest way to set up a single 7-Segment Serial Display out of the box. It requires only 3 wires, Vin, GND, and TX. By default, the display's serial interface is clocked at 9600bps which can easily be changed once wired up.
UART Wiring & Demo
mbed pin | Display pin |
---|---|
Vout or VU | VCC |
GND | GND |
p9 (or any TX pin) | RX |
Baud Rate is Persistent
The baud rate is stored in nonvolatile memory, thus it is necessary to keep track of what it was changed to most recently. If you do not know what the baud rate is set to, connect to the display using SPI and either change the baud rate or perform a factory reset.
Import programSeven_Segment_Serial_UART_Demo
Demo program for Serial 7 Segment Display by SparkFun using UART mode.
SPI
For the 7-Segment Serial Display, SPI is the most reliable method of communication with the mbed. Due to the persistence of the baud rate and I2C address, SPI provides a failsafe way to access the device. SPI wiring requires a MOSI and SCK wire, with an optional slave select.
SPI Wiring & Demo
mbed pin | Display pin |
---|---|
Vout or VU | VCC |
GND | GND |
p11 (or any MOSI pin) | SDI |
p13 (SCK) | SCK |
p14 (or any DigitalOut), or GND | SS |
Import programSeven_Segment_Serial_SPI_Demo
Demo program for Serial 7 Segment Display by SparkFun using SPI mode.
I2C
I2C is the best choice to use these displays with if you plan to use more than 1 at a time. The breakout board has convenient pads on the ends of the chip that allow the power and data lines to be passed through the chip allowing for multiple displays on a single 2 wire I2C bus. The default address is 0xE2, but there is a built in command to change it. Like the baud rate, this address is persistent so even if you power off the display, it will remember its address. If you lose track of its address, the easiest way is to connect via SPI or UART and reset the address.
I2C Wiring & Demo
mbed pin | Display pin |
---|---|
Vout or VU | VCC |
GND | GND |
p9(SDA) | SDA |
p10(SCL) | SCL |
I2C Pullup Resistor Required
As with most I2C devices, a pull up resistor is required on both the SDA and SCL lines. Typical resistor values range between 2.2kOhm and 4.7kOhm.
I2C Address is Persistent
The I2C address is stored in nonvolatile memory, thus it is necessary to keep track of what it was changed to most recently. If you do not know what the address is set to, connect to the display using SPI and either change the address or perform a factory reset.
Import programSeven_Segment_Serial_I2C_Demo
Demo program for Serial 7 Segment Display by SparkFun using I2C mode.
API
The API below enables interfacing to the device via any of the above methods (SPI, I2C, UART). In addition to having a basic send character function, it provides a variety of other methods for sending special commands, or parsing standard datatypes into a 7-Segment friendly output. This is the same library used in all of the above demo programs.
Import library
Public Member Functions |
|
SevenSegmentSerial (int m, PinName pin1, int baud=9600) | |
Create a seven segment serial object using the given mode on the specified pins - single pin constructor only supports m="UART_MODE".
|
|
SevenSegmentSerial (int m, PinName pin1, PinName pin2, char addr=0xE2) | |
Create a seven segment serial object using the given mode on the specified pins - 2 pin constructor supports m= SPI_MODE and I2C_MODE.
|
|
SevenSegmentSerial (int m, PinName pin1, PinName pin2, PinName pin3) | |
Create a seven segment serial object using the given mode on the specified pins - 3 pin constructor only supports m = SPI_MODE.
|
|
void | clear () |
Reset display to totally blank.
|
|
void | setBaud (int baud) |
Set UART baud rate.
|
|
void | setDigit (char digit, int loc) |
Set a specific digit on the display.
|
|
void | setDecimal (char d) |
Sets decimal points and other nonstandard 7seg segments.
|
|
void | setBrightness (int brightness) |
Set seven segment display brightness.
|
|
void | setSegmentsManual (char segs, int loc) |
Set specific segments at a given location.
|
|
void | factoryReset () |
Reset the display to its factory default baud rate and i2c address.
|
|
void | setI2CAddr (char addr) |
Set specific segments at a given location.
|
|
void | write (float f) |
Write the four least significant digits >0 to the display, includes decimal places if possible.
|
|
void | write (int i) |
Write the passed int to the display defaults to 4 LSB.
|
|
void | write (string s) |
Write the first 4 characters of a string to the display.
|
|
SevenSegmentSerial & | operator= (float f) |
Operator Overload - Write the four least significant digits >0 to the display, includes decimal places if possible.
|
|
SevenSegmentSerial & | operator= (int i) |
Operator Overload - Write the passed int to the display defaults to 4 LSB.
|
|
SevenSegmentSerial & | operator= (string s) |
Operator Overload - Write the first 4 characters of a string to the display.
|
|
void | sendChar (char c) |
Send a character over the correct interface.
|
|
void | locate (int l) |
Move the cursor to the specified position.
|
Please log in to post comments.