0
Offline
Newbie
Karma: 0
Posts: 6
Arduino rocks
|
 |
« on: August 05, 2009, 09:32:30 pm » |
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. // 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; }
}

|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 21
Arduino rocks
|
 |
« Reply #1 on: September 06, 2009, 09:24:06 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 6
Arduino rocks
|
 |
« Reply #2 on: September 06, 2009, 02:55:40 pm » |
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....
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 21
Arduino rocks
|
 |
« Reply #3 on: September 06, 2009, 06:32:43 pm » |
Thanks. It worked.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 4
Arduino rocks
|
 |
« Reply #4 on: October 18, 2009, 11:06:17 am » |
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. 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 6
Arduino rocks
|
 |
« Reply #5 on: October 18, 2009, 03:10:17 pm » |
I think you have your Serial and mySerial switched. mySerial is what you are using to print to the SFE Serial LED, attached to pin 3 in your example. Your code was: void loop() { Serial.write(0x01); Serial.write(0x04); Serial.write(0x02); Serial.write(0x00); Serial.println(" "); }
Try this instead: void loop() { mySerial.print(0x01); mySerial.print(0x04); mySerial.print(0x02); mySerial.print(0x00); }
Note: ONLY send 4 numbers to the SFE LED. You had a Serial.println(" "); in your code after printing 4 numbers. Don't do that. Hope this helps.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 4
Arduino rocks
|
 |
« Reply #6 on: October 18, 2009, 10:28:05 pm » |
Thank you for your help  , I have changed my code again, but still no luck. Any suggestion? void setup() { Serial.begin(9600); pinMode(11, OUTPUT); }
void loop() { Serial.print(0x02); Serial.print(0x03); Serial.print(0x04); Serial.print(0x05); }
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 2
Arduino rocks
|
 |
« Reply #7 on: January 15, 2010, 07:08:08 pm » |
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. Hope this helps. ;D
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 10
Arduino rocks
|
 |
« Reply #8 on: June 28, 2010, 08:12:21 am » |
Hi, everyone.
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.
Any ideas?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 10
Arduino rocks
|
 |
« Reply #9 on: June 28, 2010, 12:23:23 pm » |
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.
Unless someone knows how to make that work...?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 13
Arduino rocks
|
 |
« Reply #10 on: August 16, 2010, 01:39:32 pm » |
Hi, I have this 7 segment Display and i use serial port to display data. I use the following code : #include <SoftwareSerial.h>
#define rxPin 2 #define txPin 3 SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
void setup() { // define pin modes for tx, rx, led pins: pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port mySerial.begin(9600); //set the data rate on 7 segment 0x02 = 9600bps delay(100); mySerial.print(0x79); delay(100); mySerial.print(0x02); // set brightness brighter delay(100); mySerial.print(0x7A); delay(100); mySerial.print(0x00); } void loop() {
delay(2000); mySerial.print(0x01); mySerial.print(0x06); mySerial.print(0x06); mySerial.print(0x04); delay(2000); mySerial.print(0x01); mySerial.print(0x04); mySerial.print(0x09); mySerial.print(0x06);
delay(2000); mySerial.print(0x01); mySerial.print(0x09); mySerial.print(0x08); mySerial.print(0x08); }
Sometimes, the 7 segment don't display this : 1664 1496 1988 BUT this : 6641 4961 9881 There is an offset.. How correct this ? I search a special Commands in datasheet, but i found nothing.. Any help would be appreciate :-)
|
|
|
|
« Last Edit: August 16, 2010, 01:46:31 pm by 2xyo »
|
Logged
|
|
|
|
|
Sussex UK / CT USA
Offline
Edison Member
Karma: 0
Posts: 1026
Forums forever
|
 |
« Reply #11 on: August 16, 2010, 01:49:34 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 13
Arduino rocks
|
 |
« Reply #12 on: August 16, 2010, 03:03:42 pm » |
Thanks a lot tkbyd ! My code is now : // library #include <SoftwareSerial.h>
// Pin for 7 segment display #define rxPin 2 #define txPin 3 SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
void setup() { // set up Serial library at 9600 bps for debug Serial.begin(9600); Serial.println("Ethylometre v0.01"); Serial.println("Set pin mode"); // define pin modes for tx, rx, led pins: pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT);
Serial.println("Set data rate for the SoftwareSerial port"); // set the data rate for the SoftwareSerial port mySerial.begin(9600); //v=0x76. To reset display module mySerial.print("vv"); }
void loop() { Serial.println("# START Loop"); delay(1000); displaySeg(1); delay(1000); displaySeg(12); delay(1000); displaySeg(123); delay(1000); displaySeg(1234); delay(1000);
Serial.println("# END Loop"); }
void displaySeg(int mg) {; if(mg < 10) { mySerial.print(" "); mySerial.print(mg); } else if(mg < 100) { mySerial.print(" "); mySerial.print(mg); } else if(mg < 1000) { mySerial.print(" "); mySerial.print(mg); } else if(mg < 1000) { mySerial.print(" "); mySerial.print(mg); } else { mySerial.print(mg); } }
|
|
|
|
|
Logged
|
|
|
|
|
Melbourne, Fla, USA
Offline
Newbie
Karma: 0
Posts: 22
MAKE + Arduino = ROCK!!!
|
 |
« Reply #13 on: August 16, 2010, 08:19:45 pm » |
[glow]@Wesley-[/glow][/b] I found out the hard way that software generated serial ports are restricted to 9600. Not sure if that applies to all, but a point to ponder. @tkbyd-WOW! Nice link. I will have to study that much more. My blue displays come in tomorrow. 
|
|
|
|
« Last Edit: August 16, 2010, 08:34:49 pm by Volkemon »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 313
Posts: 35507
Seattle, WA USA
|
 |
« Reply #14 on: August 17, 2010, 08:58:03 am » |
I found out the hard way that software generated serial ports are restricted to 9600. The NewSoftSerial library supports rates up to 57.6K.
|
|
|
|
|
Logged
|
|
|
|
|
|