Go Down

Topic: SparksFun serial LCD Display and Due (Read 598 times) previous topic - next topic

EVP

I have tested this code successfully on the Ardunio Mega.
Code: [Select]

void setup()
{
  Serial1.begin(9600);
  backlightOn();
}

void loop()

  selectLineOne();
  Serial1.print(millis());
  selectLineTwo();
  Serial1.print(millis()/2);
  delay(100);
}

void selectLineOne(){  //puts the cursor at line 0 char 0.
   Serial1.write(0xFE);   //command flag
   Serial1.write(128);    //position
   delay(10);
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
   Serial1.write(0xFE);   //command flag
   Serial1.write(192);    //position
   delay(10);
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
if (position<16){ Serial1.write(0xFE);   //command flag
              Serial1.write((position+128));    //position
}else if (position<32){Serial1.write(0xFE);   //command flag
              Serial1.write((position+48+128));    //position
} else { goTo(0); }
   delay(10);
}

void clearLCD(){
   Serial1.write(0xFE);   //command flag
   Serial1.write(0x01);   //clear command.
   delay(10);
}
void backlightOn(){  //turns on the backlight
    Serial1.write(0x7C);   //command flag for backlight stuff
    Serial1.write(157);    //light level.
   delay(10);
}
void backlightOff(){  //turns off the backlight
    Serial1.write(0x7C);   //command flag for backlight stuff
    Serial1.write(128);     //light level for off.
   delay(10);
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  Serial1.write(0xFE);
}


However it doesn't seem to work on the Arduino Due. I get a serial signal but it's just junk text. I'm using a ttl level converter to go from 3.3 to 5. Is their a software reason?
Cheers.

EVP

I solved it, it needs a delay in the setup. That seemed to do it.

Go Up