Notes About Working with Various Arduino & Netduino Microcontroller Boards

Wednesday, November 7, 2012

Displaying Data Using a Sparkfun 7-Segment Serial LED Display

There are multiple ways to connect to a Sparkfun 7-segment serial LED display (4-digit). There is good official documentation online. The easiest option is the TTL serial option, which requires only one wire for data. This approach uses the Arduino SoftwareSerial library.

Here is a quick example that uses a DHT22 to measure temperature and relative humidity that displays the results on the LED display in an alternating fashion. 

Connections (along the long sid of the LED):
7-Segment  -->  Arduino Uno
        GND  -->  GND
        VCC  -->  5V
        RX     -->  Digital 7    

The data line for the DHT22 is connected to the Arduino's digital pin 2.

#include <dht22.h>
#include <Versalino.h>
#include <SoftwareSerial.h>

const static int rst = 0x76; 
const static int pos = 0x79;
const static int pause = 4000;  // 4 second pause

// Only pin 7 is actually connected, but both rx & tx specified
SoftwareSerial Serial7Segment(6, 7); //RX pin, TX pin
dht22 DHT22;

void setup() {
  // DHT22 sensor connected to digital pin 2
  Serial7Segment.begin(9600);   // Talk to the Serial7Segment at 9600 bps
  Serial7Segment.write(rst);    // Reset the display 

void loop() {
  int chk =;
  // No ned for decimal, cast as int
  int temp = (int) DHT22.fahrenheit();
  int rh = (int) DHT22.humidity;
  // Display temp shifted 1 char to the right
  // Label temp as Fahrenheit

No comments:

Post a Comment