Go Down

Topic: 7 Segment Display with NewSoftSerial (Read 3 times) previous topic - next topic

sys_spud

This is a follow-up to a post in the 7 Segment Display with SPI (different thread): http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1247533060/2#2. I'm starting a new thread in case people wanted to see how to use the TTL Serial input side of the SparkFun LED Serial Breakout Board (http://www.sparkfun.com/commerce/product_info.php?products_id=9230).

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.

Hint: for controlling the output, the ASCII Table is your friend - http://www.asciitable.com/

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.

Code: [Select]
// 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;
}


}


3d29

Hi

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?

sys_spud

I used digital pin 3, not analog pin 3. The analog pins can also be used as digital input pins: analog 0 through 5 are digital 14 through 19.

See http://www.arduino.cc/en/Tutorial/AnalogInputPins for more information.

You can use analog pin 3 if you want, but you have to refer to it as digital pin 17.

Hope this helps....

3d29


wpongp

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);

//delay(1000);

}

void loop()
{
Serial.write(0x01);
Serial.write(0x04);
Serial.write(0x02);
Serial.write(0x00);
Serial.println(" ");
}

Your help will be much appreciated.  :)

Go Up