Today I opened my new Sparkfun 7-Segment display and tried my hand at using it as a general purpose Arduino controller. My ultimate plan is to use it to drive a stepper motor and to respond to the input of a push button. However, this item interested me because it has 4 7-segment LED displays attached to it, which means my project could provide some minimum visual feedback.
First, I opened the package and soldered 6 header pins onto the end — put them inside where the package is silk screened with a little white line. I plugged in a FTDI connector and plugged that into my Mac. It displayed a zero on the first of the LED displays.
Next I installed the Arduino IDE and the FTDI driver for my Mac. The instructions for FTDI driver installer said to run a command `sudo kextunload –b com.apple.driver.AppleUSBFTDI` but that just gave me an error message (“Can’t create –b. Can’t create com.apple.driver.AppleUSBFTDI.”) so I don’t know if it did anything.
Next I tried running some sample SevSeg.cpp files but had trouble.
I realized I needed to program this device using a definition provided by Sparkfun. I followed the instructions in this repo’s readme file to install those definitions: https://github.com/sparkfun/Arduino_Boards and then selected “Sparkfun Serial 7-Segment Display” from the Arduino IDE Tools -> Board menu.
I found the SevSeg project and copied the files (SevSeg.cpp and SevSeg.h) next to my Arduino project file (SayHello.ino). Word of warning: This library just emits a blank character for letters that don’t have any mapping into LCD (e.g. K, V, W, M…) I guess it’s cool that it even tries to draw any letters at all…
Finally I had to figure out the pin order for this particular display. The SevSeg project requires about 18 integer parameters when it is initialized… and I had trouble mapping pinouts (for example from this spec for the display: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Components/LED/Serial-7-Segment-Display-v31.pdf) to the parameters. One of the things I’m immediately finding myself annoyed with in Arduino is the lack of transparency around what pins are called…. apparently each board renames the ATMega pins (which already have names like PB0 or PC4) to a new number. Finally I was able to solve this by looking at the firmware for the Sevseg display and copying the key values from there:
int digit1 = 16; // DIG1 = A2/16 (PC2)
int digit2 = 17; // DIG2 = A3/17 (PC3)
int digit3 = 3; // DIG3 = D3 (PD3)
int digit4 = 4; // DIG4 = D4 (PD4)
//Declare what pins are connected to the segments
int segA = 8; // A = D8 (PB0)
int segB = 14; // B = A0 (PC0)
int segC = 6; // C = D6 (PD6), shares a pin with colon cathode
int segD = A1; // D = A1 (PC1)
int segE = 23; // E = PB7 (not a standard Arduino pin: Must add PB7 as digital pin 23 to pins_arduino.h)
int segF = 7; // F = D7 (PD6), shares a pin with apostrophe cathode
int segG = 5; // G = D5 (PD5)
int segDP= 22; //DP = PB6 (not a standard Arduino pin: Must add PB6 as digital pin 22 to pins_arduino.h)
int digitColon = 2; // COL-A = D2 (PD2) (anode of colon)
int segmentColon = 6; // COL-C = D6 (PD6) (cathode of colon), shares a pin with C
int digitApostrophe = 9; // APOS-A = D9 (PB1) (anode of apostrophe)
int segmentApostrophe = 7; // APOS-C = D7 (PD7) (cathode of apostrophe), shares a pin with F
int numberOfDigits = 4; //Do you have a 2 or 4 digit display?
int displayType = COMMON_ANODE; //SparkFun 10mm height displays are common anode
//Initialize the SevSeg library with all the pins needed for this type of display
digit1, digit2, digit3, digit4,
segA, segB, segC, segD, segE, segF, segG,
My next objective is to see if I can repurpose the pins on the top of the display to control a stepper motor and read a button. Those are silk screened on the display as A7, A6, GND, VCC, SD0, SCK, RST, SD1, SS (with a bar), and RX. I haven’t yet figured out what those pins are called in arduino-speak, nor what their ATMega names are either. Stay tuned…