7 segment serial display with TTL serial need help

Hi, I am new to Arduino and just bought a 7 segment serial display this week. http://www.sparkfun.com/commerce/product_info.php?products_id=9230

Instead of using SPI, I would like to use TTL level communication to control my display and my arduino is ATMega328. The wiring is easy, VCC to pin11, GND to GND and RX to TX(arduino).

I was told to use Serial.write() to display numbers but not succeed yet.

After hours of struggling, I'd like to ask your kindly help to help me with the coding. At this first stage, I just want to display four digits mannually.

Below is my code now: (try to display"2345")

Void Setup(){ Serial.begin(9600);

pinMode(11, OUTPUT); }

Void loop(){

Serial.write(0x02); Serial.write(0x03); Serial.write(0x04); Serial.write(0x05);

}

I really have no idea with my coding and I hope someone can help me... Thank you in advance!

i think you have to use serial1 and not serial

tobi

You haven't got the USB hooked up when you're trying to do this, have you?

I corrected your code:

void setup() { //c/c++ is case sensitive Void is not the same as void
  Serial.begin(9600); 
  pinMode(11, OUTPUT); 
} 

void loop() { 
  Serial.print(0x02); //use print instead of write
  Serial.print(0x03); 
  Serial.print(0x04); 
  Serial.print(0x05); 
}

Thank you AlphaBeta for your kindly help. (I can upload to I/O now) There is still nothing appeared on my display board and I guess that my code missed some important part...

Try this

void setup() { Serial.begin(9600); pinMode(11, OUTPUT); }

void loop() { Serial.print(0x32,BYTE); Serial.print(0x33,BYTE); Serial.print(0x34,BYTE); Serial.print(0x35,BYTE); } :)

Pin 11 as output will not do what you want here. I think you need to use the software serial library and leave the hardware serial alone since it's connected to the FTDI chip.

You only need the send function since serial on it only has RX. You may have to set the TX pin to please the library.

If you leave the hardware serial free you can write your program to receive commands over it and then have those sent to the display.

Software serial only works at 9600 baud.

Hack the example so that it has the RX and TX pins you want which don't conflict with other pins. then replace all in the void section with

mySerial.print(0x31); mySerial.print(0x32); mySerial.print(0x41); mySerial.print(0x42);

try adding BYTE if this fails.

http://www.arduino.cc/en/Reference/SoftwareSerial

http://arduino.cc/en/Reference/SoftwareSerialExample

Maybe something like this will do the trick. You will have to download
the SoftwareSerial library :slight_smile:

#include <SoftwareSerial.h>

#define txPin 11
#define rxPin 12 //not used

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

void setup() {
pinMode(txPin, OUTPUT);
mySerial.begin(9600);

mySerial.print(0x32,BYTE);
mySerial.print(0x33,BYTE);
mySerial.print(0x34,BYTE);
mySerial.print(0x35,BYTE);
}

// Dim the display
// Displays the digits 2345

#include <SoftwareSerial.h>

#define txPin 11
#define rxPin 12 //not used

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

void setup() {
pinMode(txPin, OUTPUT);
mySerial.begin(9600);
mySerial.print(0x7A,BYTE); // Command byte
mySerial.print(0xF0,BYTE); // Dim display

mySerial.print(0x02,BYTE); // left digit
mySerial.print(0x03,BYTE);
mySerial.print(0x04,BYTE);
mySerial.print(0x05,BYTE);
}

void loop() {
}
:smiley:

//Better example

#include <SoftwareSerial.h>

#define txPin 11
#define rxPin 12 //not used

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

void setup() {
pinMode(txPin, OUTPUT);
mySerial.begin(9600);
mySerial.print(0x7A,BYTE); // Command byte
mySerial.print(0xF0,BYTE); // Dim display

// This following 77 commands can be add together
mySerial.print(0x77,BYTE); // Command byte
mySerial.print(0x30,BYTE); // Display colon

//mySerial.print(0x77,BYTE); // Command byte
//mySerial.print(0x40,BYTE); // Display apostrophes

//mySerial.print(0x77,BYTE); // Command byte
//mySerial.print(0x01,BYTE); // Display digit 1 decimal point

//mySerial.print(0x77,BYTE); // Command byte
//mySerial.print(0x02,BYTE); // Display digit 2 decimal point

//mySerial.print(0x77,BYTE); // Command byte
//mySerial.print(0x04,BYTE); // Display digit 3 decimal point

//mySerial.print(0x77,BYTE); // Command byte
//mySerial.print(0x8,BYTE); // Display digit 4 decimal point

mySerial.print(0x02,BYTE); // left digit
mySerial.print(0x03,BYTE);
mySerial.print(0x04,BYTE);
mySerial.print(0x05,BYTE);
}

void loop() {
}

That is a great walkthrough code, thanks! I am having a strange issue now, that whenever I change the code and re-upload it to the arudino, the serial display losing its starting point and will think that the next number is the starting point.

For example, if I only want it to read 2345, the first time I run the code it will read 2345, next time I upload it it will be 5234, next time 4523 etc. For some reason I think the display gets confused when it is running an old code and a new one comes in.

I am using an Arduino Mega. Thanks!!!

~Ryan J.

In general those displays read 4 bytes and display them, if for any reason you send an odd byte (including any pulse on the line due to the Adruino restarting which will be seen as a start bit by the display) then things get out of sync and you will see the sort of thing you're mentioning.

I've found that the only thing to do is cycle the display's power to reset it.

FWIW I think it's bad not to have a way to resync a connection like this but they don't have anything. Maybe a low signal for > a byte time or something could be implemented by Sparkfun to allow resyncing.

It sounds like a reasonable answer. Thanks for the explanation.

I'm new to electronics, so now I need to figure out a way to cycle the power... maybe a 5V DC relay that gets switched off/on before the 4 bytes are sent?

If indeed that is your problem we're really only talking about cycling the power each time you download a program. ie. only while developing, there shouldn't be a problem with the final gadget.

To test this how about you unplug the entire circuit you are playing with and plug back in. Does it work correctly or still have the problem?

If it works 10 times in a row I'd say that's it, if it still doesn't work then some more deep thought is required.

As this display contains a processor then the easiest way to reset it is to wire a link from pin 29 of the 16B processor on the display to an arduino output. During the setup() put the pin low then put it high again. This will then start you off at the beginning of your four byte data packet.

I have the same problem with the cursor being in a random spot so that when I write my characters, they do write correctly but the starting point is not at the beginning. For example I write 1234 and I get 3412 or 4123.

Some questions...

(1) I am using pin 3 to transmit, using software serial. When I upload my code (via USB) to my Duemilanove, the display (tx on pin 3) randomly changes to garbage. Obviously something is leaking out of pin 3 while I upload the code. Why is this? Shouldn't this software serial pin be quiet?

(2) The LED supposedly has a special reset command (0x76) which will clear the display and set the cursor to the first digit. I have tried sending this in my code first. I send it multiple times separated by a delay before sending my desired characters. This reset command doesn't appear to be working... first the screen doesn't clear but instead fills with new garbage, and then when I send my characters, they are still out of order.

Code snippet...

delay(5000); display.print(0x76); delay(1000); display.print(0x76); delay(1000); display.print(0x01); display.print(0x02); display.print(0x03); display.print(0x04);

(3) I am powering the Duemilanove via USB only (i.e. 5V). Is this wise? I read somewhere that the optimal supply is 9V, and that with only 5V signals can sag. Could this be contributing to comm problems? (I need to find a 9V supply and power the Duemilanove to test this theory).

Update 1:

I have a 9V supply powering my Duemilanove now with no change in behavior.

Update 2:

I have tried using the hardware serial port... same behavior.

When I upload my code (via USB) to my Duemilanove, the display (tx on pin 3) randomly changes to garbage.

The chip gets reset to upload a new sketch, when this happens pins are set to be inputs and are therefore floating. This means that the display Rx is liable to pick up any old crap, pulling it high with a 10k resistor should fix that.

The LED supposedly has a special reset command (0x76) which will clear the display and set the cursor to the first digit.

This display never used to have a reset command but they were upgrading the software some time back. If it now has one that should work I would think as long as you give it time to recover from any crap which you are.

I am powering the Duemilanove via USB only (i.e. 5V). Is this wise?

Shouldn't be any problems with this.

What happens if you cycle the power on the display? Does it come good? Same if you rest the display with a wire from the reset pad (on the back) to GND.


Rob

Thanks for the advice on the 10k pullup resistor. I will try it.

I had a bit of a breakthrough but I am not sure why. If I send the reset command as (0x76,BYTE) then the screen clears properly and the cursor is properly set to the beginning.

However, the BYTE formatting doesn't seem to be required when sending the four desired characters. I've tried it with and without BYTE and it works every time now. But when sending the formatting command it seems to be required.

I thought that sending it as 0x** would be fine as a way to send the command. In fact this is suggested in the user manual for the display. Any ideas why BYTE would be required for this particular command, yet apparently not for sending the 4 characters to be displayed?

I am an ME not a SW expert, so perhaps this is something plainly evident to others.

Thanks!