4x7 segment led atmega128

having trouble using this product from Sparkfun

i am using the ttl level method and am having trouble displaying numbers starting from the first segment.

for example if i wanted to dispaly 0123 sometimes it would boot to 1230 and sometimes it would display 0123.

here is the code:

#include <Button.h>
#include <SoftwareSerial.h>

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

Button button = Button(12,PULLDOWN);
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

int dirPin = 3;
int stepperPin = 2;
int potPin = 0;
int potVal = 0;
int lastPotVal = 0;
int array = {0, 0, 0};

void updateDisp (int dispVal) {

mySerial.print(0x77,BYTE); // Command byte
mySerial.print(0x00,BYTE); // clear display
mySerial.print(0x78,BYTE); // blank
mySerial.print(dispVal);
// array[0] = dispVal[0];
// Serial.println();
}

void step(boolean dir, int steps) {
digitalWrite(dirPin, dir);
delay(50);
for(int i = 0; i < steps; i++) {
digitalWrite(stepperPin, HIGH);
delayMicroseconds(250);
digitalWrite(stepperPin, LOW);
delayMicroseconds(250);
}
}

void setup() {
pinMode(dirPin, OUTPUT);
pinMode(stepperPin, OUTPUT);
pinMode(txPin, OUTPUT);
Serial.begin(9600);
// 7 segment
mySerial.begin(9600);
mySerial.print(0x7A,BYTE); // Command byte dimmer
mySerial.print(0x00,BYTE); // Dim display 0-high 255-low 60=3Chex
mySerial.print(0x78,BYTE); // blank
mySerial.print(0x77,BYTE); // Command byte
mySerial.print(0x00,BYTE); // clear display
delay(200);
}

void loop() {

potVal = analogRead(potPin);
potVal = map(potVal, 0, 1023, 100, 200);
if (potVal != lastPotVal) {
updateDisp(potVal);
}
lastPotVal = potVal;

if(button.isPressed()){
// Serial.println(potVal);
step(true,potVal); //ccw
delay(200);
// step(false,0); //cw
// delay(200);
}
delay(50);
}

Thanks in advance for your time.

I was just running into this same problem. Seems to have something to do with the state of the display when it first starts. I was getting the offset numbers when I'd power up my arduino and the display at the same time. Reseting the arduino would get me back to normal, usually...

I managed to get around this by setting my txPin high for 200mS(arbitrary) before the mySerial.begin(9600). Not sure if this is the best method, but going with it since it's working.

pinMode(txPin, OUTPUT);
digitalWrite(rxPin, 1);
delay(200);
mySerial.begin(9600);

I'm having the same issue as both of you. The 200ms delay helps sometimes, but it seems to really come down to timing with the refresh rates. If there is a way to flash the memory of the display before a new code comes in I think that would help... Is something like that possible?

~Ryan J.