Ce site contient essentiellement des notes de travail. Le contenu est en constante évolution, et loin d'être achevé. (+ d'infos)
La plupart des documentations informatiques sont orientées Debian / Ubuntu.

Electronique/Hardware/Ecrans/SerLCD/Arduino

De Ordinoscope.net
Sauter à la navigation Sauter à la recherche

Introduction

Ce test a été effectué avec un écran LCD SparkFun LCD-09393 (en mode sériel).

Configuration

SerLCD connecté sur un Arduino Sériel hardware: pin 1 (TX)
Schéma fait avec Fritzing

Sériel hardware

Hello world + uptime

Ce exemple affiche

Hello world !
Uptime: 10s

L'uptime se met à jour 1x / seconde

void setup () {
  Serial.begin (9600);
  backlightOn ();
  delay (1000);
  selectLineOne ();
  delay (100);
  Serial.print ("Hello world !");
  delay (100);
}

void loop () {  
  selectLineTwo ();
  delay (100);
  Serial.print ("Uptime: ");
  Serial.print (millis ()/1000, DEC);
  Serial.print ("s");
  delay (1000);
}

void selectLineOne () {        //puts the cursor at line 0 char 0.
  Serial.print (0xFE, BYTE);   //command flag
  Serial.print (128, BYTE);    //position
}

void selectLineTwo () {        //puts the cursor at line 0 char 0.
  Serial.print (0xFE, BYTE);   //command flag
  Serial.print (192, BYTE);    //position
}

void goTo (int position) {                              //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
  if  (position<16) { Serial.print (0xFE, BYTE);        //command flag
    Serial.print ( (position+128), BYTE);               //position
  }else if  (position<32) {Serial.print (0xFE, BYTE);   //command flag
    Serial.print ( (position+48+128), BYTE);            //position 
  } else  {
    goTo (0);
  }
}

void clearLCD () {
   Serial.print (0xFE, BYTE);   //command flag
   Serial.print (0x01, BYTE);   //clear command.
}

void backlightOn () {            //turns on the backlight
    Serial.print (0x7C, BYTE);   //command flag for backlight stuff
    Serial.print (157, BYTE);    //light level.
}

void backlightOff () {           //turns off the backlight
    Serial.print (0x7C, BYTE);   //command flag for backlight stuff
    Serial.print (128, BYTE);    //light level for off.
}

void serCommand () {             //a general function to call the command flag for issuing all other commands   
  Serial.print (0xFE, BYTE);
}

Sériel software

Hello World

#include <SoftwareSerial.h>

#define txPin 2

SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin

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

void loop() {
  LCD.print ("Hello world!");
}

Hello World + uptime

#include <SoftwareSerial.h>

#define txPin 2
SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin

void setup () {
  pinMode(txPin, OUTPUT);
  LCD.begin (9600);
  backlightOn ();
  delay (1000);
  selectLineOne ();
  delay (100);
  LCD.print ("Hello world !");
  delay (100);
}

void loop () {  
  selectLineTwo ();
  delay (100);
  LCD.print ("Uptime: ");
  LCD.print (millis ()/1000, DEC);
  LCD.print ("s");
  delay (1000);
}

void selectLineOne () {     //puts the cursor at line 0 char 0.
  LCD.print (0xFE, BYTE);   //command flag
  LCD.print (128, BYTE);    //position
}

void selectLineTwo () {     //puts the cursor at line 0 char 0.
  LCD.print (0xFE, BYTE);   //command flag
  LCD.print (192, BYTE);    //position
}

void goTo (int position) {                              //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
  if  (position<16) { Serial.print (0xFE, BYTE);        //command flag
    LCD.print ( (position+128), BYTE);                  //position
  }else if  (position<32) {Serial.print (0xFE, BYTE);   //command flag
    LCD.print ( (position+48+128), BYTE);               //position 
  } else  {
    goTo (0);
  }
}

void clearLCD () {
   LCD.print (0xFE, BYTE);    //command flag
   LCD.print (0x01, BYTE);    //clear command.
}

void backlightOn () {         //turns on the backlight
    LCD.print (0x7C, BYTE);   //command flag for backlight stuff
    LCD.print (157, BYTE);    //light level.
}

void backlightOff () {        //turns off the backlight
    LCD.print (0x7C, BYTE);   //command flag for backlight stuff
    LCD.print (128, BYTE);    //light level for off.
}

void serCommand () {   //a general function to call the command flag for issuing all other commands   
  LCD.print (0xFE, BYTE);
}

Références