Wiring is easy, GND, Vcc and Rx from pin 3 of arduino. Code is also easy, just send Serial.print statements, or mySerial.print statements in this example. Remember to send four print statements to fill out all four digits in the display, see the SFE docs for details.
The code example is for an XBee temperature monitor receiving module. I wanted to be able to print the temps out with Serial.print statements and also send the temps to the LED display via mySerial.print statements.
Not the best code in the world, and if you have helpful hints, they're appreciated. Be gentle, I'm a noob.
// NOTES:
// Using SparkFun Serial LED with XBee receiver
// 2009-08-03
#include <NewSoftSerial.h>
NewSoftSerial mySerial(2, 3); // Tx from arduino is pin 3, connect to Rx on SFE LED Serial
// following variables for receiving XBee Serial info and displaying them
byte incomingByte;
int j =0;
int prtout = 0; // flag to know when to send to LED display
int digitcnt = 0; // count the number of digits in incoming temperature
char temps[5]; // temperature array
void setup() {
// start serial port at 9600 bps
Serial.begin(9600);
Serial.println("Ready!");
mySerial.begin(9600);
delay(1000);
}
void loop()
{
j =0;
prtout =0; // don't print out until set to 1, then turn off flag immediately
digitcnt = 0; // count the number of digits of temperature for later use with index j
// Note: Sending XBee transmits temperature in degrees F, terminated by CR and LF (Serial.println(mytemp) on sending XBee)
// Need to remove the CR/LF or not send it to LED digits
while(Serial.available()) // are there any bytes available on the serial port ???
{
prtout =1; // if bytes available set flag to print them later
incomingByte = Serial.read(); // NOTE: value for temp PLUS CR and LF included in read, see above
temps[j]=(byte(incomingByte)); // store the temperature digits in an array
Serial.print(temps[j]);
j++;
delay(200); // achieved experimentally - need some kind of delay between iterations to receive properly
}
if (prtout)
{
digitcnt = j-2; // digitcnt holds the highest used index value for temp digits + 1 for use as conditional stop statement, ignore CR and LF
if (digitcnt == 3)
{ mySerial.print("x");}
if (digitcnt == 2)
{ mySerial.print("x");
mySerial.print("x");}
for(j=0;j < digitcnt;j++)
{Serial.print(temps[j]); // now print temperature values left-to-right, but right-justified
mySerial.print(temps[j]);
}
Serial.println(" ");
prtout = 0;
}
}
I'm trying to do something like you did but my display only shows 0000.
Any advices? I got a arduino mega, using analog pin 3 conected to rx in the 7-segment serial display, using 5v from arduino to vcc and gnd from arduino to gnd on display.
Thanks
ps: I didn't solder the wires I'm just using jumper cables. Think maybe that's my problem?
Thanks for the example. I am trying to use TTL serial to control my sfe 7 segment display too. In this first stage, I would like to display simple numbers mannually(As it is said, it should be easy).
Below is my code that tried to display "1420" on the board, I could not figure out what's wrong as I am very new to arduino and coding.
#include <NewSoftSerial.h>
NewSoftSerial mySerial(2, 3); // Tx from arduino is pin 3, connect to Rx on SFE LED Serial
void setup() {
// start serial port at 9600 bps
Serial.begin(9600); //Serial.println("Ready!");
mySerial.begin(9600);
I just did this and it works fine. I did however have to enter the delay(1000) for the numbers to show correctly, it was off by one digit for some reason, but it works as expected.
#include <NewSoftSerial.h>
NewSoftSerial RpSerial(2, 3); // Tx from arduino is pin 3, connect to Rx on SFE LED Serial
void setup() {
//Serial.println("Ready!");
RpSerial.begin(9600);
}
void loop()
{
delay(1000);
RpSerial.print(0x01);
RpSerial.print(0x04);
RpSerial.print(0x02);
RpSerial.print(0x00);
}
About as simple as it can get, RX on the SFE unit is tied to Digital Pin 3.
I'm having the toughest time communicating with the 7-seg serial display. My MCU is an ATmega8, with Arduino targeting atmega8_noxtal, which I got from todbot (website).
I'm wondering if there's a clocking issue, since I think the atmega8 is 8MHz and all the others are 16MHz.
If I begin the NewSoftSerial port at 9600 baud and then try to send data, I get a display full of zeroes.
If I begin the NewSoftSerial port at 19200 baud, I get gibberish.
OK, I'm now even more confident that this is a timing problem. I think the lesson learned is not to try asynchronous TTL serial w/o an external crystal.
Thi doesn't work for me it still stays at a low brightness level.
Even if I put
mySerialPort.print(0xFA);
to set it at the lowest brighntess nothing is going to happen.
Does someone know why?
Shouldn't this owkr also:
mySerialPort.print("z");
mySerialPort.print("0");