serial led display using software serial

LED Display(4 digit):

I am using a Pro Mini 168 with the above display and software serial library to control the display.

When I send the information, only 3 of the numbers display (1 blank digit) and in a random order. The manual for the display says I have to send display data in 4-byte packets. The code I used is shown below.

Also, can I used software serial to control two displays simultaneously? I tried and neither display responded.

#include <SoftwareSerial.h>

#define rx1Pin 8
#define tx1Pin 9
#define rx2Pin 11
#define tx2Pin 10

SoftwareSerial serialPort1 = SoftwareSerial(rx1Pin, tx1Pin);
SoftwareSerial serialPort2 = SoftwareSerial(rx2Pin, tx2Pin);

void setup(){
pinMode(rx1Pin, INPUT);
pinMode(tx1Pin, OUTPUT);
pinMode(rx2Pin, INPUT);
pinMode(tx2Pin, OUTPUT);
// serialPort1.print(0x03);

void loop(){


I just added BYTE to my print commands and now all 4 digits display, but they still display in a random order (different each time I upload sketch).

serialPort2.print(0x01, BYTE);
serialPort2.print(0x02, BYTE);
serialPort2.print(0x03, BYTE);
serialPort2.print(0x04, BYTE);

I get the feeling that sending the data that way is not a “4-byte packet” and is instead 4 1-byte packets, is that true? And if so how do I send as one 4-byte packet?

I just tried putting a delay between software serial initialization and each of the print commands, that didn't work either; but it made me realize that the numbers don't appear randomly. What is happening is that the first number (1) is appearing to the right of where is appeared the previous upload with each subsequent number appearing in the correct order after it. For example: there are 4 digits on the display, so if the # 1 was the second digit the previous upload, when I re-upload the # 1 will show up as the third digit, # 2 will be 4th digit, #3 will be 1st digit and #4 will be 2nd digit. This is still a problem but at least I am headed in the right direction.

Any ideas? The pdf manual says that I need to send the number information in 4 byte packets, I don't think what I am doing qualifies as doing that but I am not sure how I would do that.

I think the problem is that the "cursor" position is not initialized and the display is starting at a random point and then wrapping around. The serial displays I am familiar with have commands to control the cursor position but I do not see that on the pdf you referenced.

i never did figure that out travis.

but someone told me to try SPI and even made some code, it worked perfectly. i will post the code below for anyone who happens to run into this thread due to having the same problem i had. btw, if anyone knows what my problem was with using serial please let me know.

int dataPin = 2; // connect to MOSI on both displays int clockPin =3; // connect to SCK on both displays int CS1 = 4; // connect to CS on first display int CS2 = 5; // connect to CS on second display

void setup (void) { pinMode (dataPin, OUTPUT); pinMode (clockPin, OUTPUT); pinMode (CS1, OUTPUT); pinMode (CS2, OUTPUT); digitalWrite (CS1, LOW); // select first display digitalWrite (CS2, HIGH); // deselect second display shiftOut(dataPin, clockPin, MSBFIRST, 1); shiftOut(dataPin, clockPin, MSBFIRST, 2); shiftOut(dataPin, clockPin, MSBFIRST, 3); shiftOut(dataPin, clockPin, MSBFIRST, 4); digitalWrite (CS1, HIGH); // select second display digitalWrite (CS2, LOW); // deslect first display shiftOut(dataPin, clockPin, MSBFIRST, 5);// name white spaces in treble clef shiftOut(dataPin, clockPin, MSBFIRST, 6); shiftOut(dataPin, clockPin, MSBFIRST, 7); shiftOut(dataPin, clockPin, MSBFIRST, 8); //shiftOut(dataPin, clockPin, MSBFIRST, 0x7A); special character for setting brightness //shiftOut(dataPin, clockPin, MSBFIRST, 0x00); full brightness (0x00) and dimmest (0xFF) }

void loop (void) {}

Random off-topic question: How do you get the code to be colored like that?

All you do is highlight the code you want to copy, go to EDIT menu and select "Copy for Forum".

Something odd happened, I was able to fix it but its something hidden within the led display architecture/code.

I decided to try sending 1234 to display 1 all in one shiftout instance instead of the four instances (shiftout sends info bit by bit and display takes info in 4-byte packets so i thought that'd work). It only displayed 3 of the numbers and they kept shifting to the right each time I uploaded the code. When I put the code back to normal, it displayed 1234 starting where it last was; so somehow sending one shiftout instance moves the starting digit on the display. I will have to play around with it more.

What I don't like is that once I put all the hardware into the final enclosure I may have to pull it out if the starting digit gets switched due to battery death mid-send or something to that effect. Gunna have to set a switch up for changing the starting digit if it is indeed reliable to switch starting digit. And turning power off and on doesn't reset the starting digit so must be something in the display software?

This makes me think that the software serial route I was trying was having a similar problem and the fix potentially wouldn't be too hard; but I don't know what that would be and SPI is nice and easy to work with.

I think I solved the random digit problem. What's been working for me so far is to do a special character command at the beginning of my program, and that "resets" the cursor position. I'd have to check the code on the ATMega128 to verify it, but it's been working consistently for me.

I've been setting the colon on:

if (initialized ==0){

Serial.print(0x77, BYTE); Serial.print(0x30, BYTE); initialized=1;


Then send your 4 byte packets normally.

I did have some trouble when I put these lines in the setup() function, so I put them in the loop with my own initialization variable.