LCD Smartie на ардуино

SAn4Es_TV
Offline
Зарегистрирован: 18.04.2019

Привет!

Недавно я управлял подключенным к ардуино дисплеем при помощи программы LCD Smartie.

И у меня появились вопросы:

1. Как управлять яркостью дисплея с программы?

2. Можно ли нормально отображать полосу  "загрузки"(у меня она не правильно отображается)

3. Как можно создать свой символ этой программой?

 

Вот код

// Pour UNO -> A4 SDA - A5 SCL
// Pour Mega -> 20 SDA - 21 SCL
#include <avr/interrupt.h>
#include <avr/io.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//#include <LCD.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adresse du LCD :0x27 pour 16c et 2 lignesLiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

#define VERSION 1
const int numRows = 2;

const int numCols = 16;
#define I2C_ADDR 0x27 // <<- Add your address here.
#define Rs_pin 0
#define Rw_pin 1
#define En_pin 2
#define BACKLIGHT_PIN 3
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

#define GPO1 8 // Not yet implemented. (pg. 18 of the manual)
//LiquidCrystal_I2C lcd(0x27,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup() {
  Serial.begin(9600); // Default baudrate.
  {
    lcd.init(); // Initialise le lcd
    // lcd.begin(numRows, numCols);
    // écrit mon nom
    lcd.backlight();
    lcd.print("HI");
    delay(2000);
    lcd.clear();
    // lcd.setCursor(0,0); // cuseur et ligne en haut a gauche
    // lcd.print("Olivier Lefebvre"); // écrit sur le LCD

  }

}

byte serial_getch() {

  int incoming;
  while (Serial.available() == 0) {}
  // read the incoming byte:
  incoming = Serial.read();

  return (byte) (incoming & 0xff);
}

void loop() {

  byte rxbyte;
  byte temp;

  rxbyte = serial_getch();

  if (rxbyte == 254) //Matrix Orbital uses 254 prefix for commands
  {
    switch (serial_getch())
    {
      case 66: //backlight on (at previously set brightness)
        lcd.backlight();

        break;
      case 70: //backlight off
        lcd.noBacklight();
        break;
      case 71: //set cursor position
        temp = (serial_getch() - 1); //get column byte
        switch (serial_getch()) //get row byte
        {
          //line 1 is already set up
          case 2:
            temp += 0x40;
            break;
          case 3:
            temp += 0x14;
            break;
          case 4:
            temp += 0x54;
            break;
          default:
            break;
        }
        lcd.command(0b10000000 + temp);
        break;
      case 72: //cursor home (reset display position)
        lcd.command(2);
        break;
      case 74: //show underline cursor
        lcd.command(0b00001110);
        break;
      case 75: //underline cursor off
      case 84: //block cursor off
        lcd.command(0b00001100);
        break;
      case 76: //move cursor left
        lcd.command(16);
        break;
      case 77: //move cursor right
        lcd.command(20);
        break;
      case 78: //define custom char
        lcd.command(64 + (serial_getch() * 8)); //get+set char address
        for (temp = 7; temp != 0; temp--)
        {
          lcd.print(serial_getch()); //get each pattern byte
        }
        break;
      case 83: //show blinking block cursor
        lcd.command(0b00001111);
        break;
      case 86: //GPO OFF
        //implement later
        break;
      case 87: //GPO ON
        /*temp = serial_getch();
          if (temp == 1)
          {
          GPO1 = GPO_ON;
          }*/
        break;
      case 88: //clear display, cursor home
        lcd.command(1);
        break;
      case 152: //set and remember (doesn't save value, though)
      case 153: //set backlight brightness
        //not implemented
        break;

      //these commands ignored (no parameters)
      case 35: //read serial number
      case 36: //read version number
      case 55: //read module type
      case 59: //exit flow-control mode
      case 65: //auto transmit keypresses
      case 96: //auto-repeat mode off (keypad)
      case 67: //auto line-wrap on
      case 68: //auto line-wrap off
      case 81: //auto scroll on
      case 82: //auto scroll off
      case 104: //init horiz bar graph
      case 109: //init med size digits
      case 115: //init narrow vert bar graph
      case 118: //init wide vert bar graph
        break;
      default:
        //all other commands ignored and parameter byte discarded
        temp = serial_getch(); //dump the command code
        break;
    }
    return;
  } //END OF COMMAND HANDLER

  //change accented char to plain, detect and change descenders
  //NB descenders only work on 5x10 displays. This lookup table works
  // with my DEM-20845 (Display Elektronik GmbH) LCD using KS0066 chip.
  switch (rxbyte)
  {
    //chars that have direct equivalent in LCD charmap
    /* case 0x67: //g
      rxbyte = 0xE7;
      break;
      case 0x6A: //j
      rxbyte = 0xEA;
      break;
      case 0x70: //p
      rxbyte = 0xF0;
      break;
      case 0x71: //q
      rxbyte = 0xF1;
      break;
      case 0x79: //y
      rxbyte = 0xF9;
      break;
*/ case 0xE4: //ASCII "a" umlaut
      rxbyte = 0xE1;
      break;
    case 0xF1: //ASCII "n" tilde
      rxbyte = 0xEE;
      break;
    case 0xF6: //ASCII "o" umlaut
      rxbyte = 0xEF; //was wrong in v0.86
      break;
    case 0xFC: //ASCII "u" umlaut
      rxbyte = 0xF5;
      break;

    //accented -> plain equivalent
    //and misc symbol translation
    case 0xA3: //sterling (pounds)
      rxbyte = 0xED;
      break;
    /* case 0xB0: //degrees symbol
      rxbyte = 0xDF;
      break;
*/ case 0xB5: //mu
      rxbyte = 0xE4;
      break;
    case 0xC0: //"A" variants
    case 0xC1:
    case 0xC2:
    case 0xC3:
    case 0xC4:
    case 0xC5:
      rxbyte = 0x41;
      break;
    case 0xC8: //"E" variants
    case 0xC9:
    case 0xCA:
    case 0xCB:
      rxbyte = 0x45;
      break;
    case 0xCC: //"I" variants
    case 0xCD:
    case 0xCE:
    case 0xCF:
      rxbyte = 0x49;
      break;
    case 0xD1: //"N" tilde -> plain "N"
      rxbyte = 0x43;
      break;
    case 0xD2: //"O" variants
    case 0xD3:
    case 0xD4:
    case 0xD5:
    case 0xD6:
    case 0xD8:
      rxbyte = 0x4F;
      break;
    case 0xD9: //"U" variants
    case 0xDA:
    case 0xDB:
    case 0xDC:
      rxbyte = 0x55;
      break;
    case 0xDD: //"Y" acute -> "Y"
      rxbyte = 0x59;
      break;
    /* case 0xDF: //beta //mucks up LCDSmartie's degree symbol??
      rxbyte = 0xE2;
      break;
*/ case 0xE0: //"a" variants except umlaut
    case 0xE1:
    case 0xE2:
    case 0xE3:
    case 0xE5:
      rxbyte = 0x61;
      break;
    case 0xE7: //"c" cedilla -> "c"
      rxbyte = 0x63;
      break;
    case 0xE8: //"e" variants
    case 0xE9:
    case 0xEA:
    case 0xEB:
      rxbyte = 0x65;
      break;
    case 0xEC: //"i" variants
    case 0xED:
    case 0xEE:
    case 0xEF:
      rxbyte = 0x69;
      break;
    case 0xF2: //"o" variants except umlaut
    case 0xF3:
    case 0xF4:
    case 0xF5:
    case 0xF8:
      rxbyte = 0x6F;
      break;
    case 0xF7: //division symbol
      rxbyte = 0xFD;
      break;
    case 0xF9: //"u" variants except umlaut
    case 0xFA:
    case 0xFB:
      rxbyte = 0x75;
      break;
    default:
      break;
  }

  lcd.write(rxbyte); //otherwise a plain char so we print it to lcd
  return;
}

 

b707
Offline
Зарегистрирован: 26.05.2017

вы этот код явно откуда-то списали, в нем в строчке 24 упоминается какой-то "мануал" - может стоит его найти и почитать?

SAn4Es_TV
Offline
Зарегистрирован: 18.04.2019

Мануала я не нашел.

Вот откуда я взял этот код.

Все ссылки ведут либо на несуществующие страницы, либо на скетч, либо на википедию

sadman41
Онлайн
Зарегистрирован: 19.10.2016

http://lcdsmartie.sourceforge.net/ - все там ок. Даже форум имеется.

SAn4Es_TV
Offline
Зарегистрирован: 18.04.2019

Я нашел чуть другой скетч для ардуины, только он без I2C


// include the library code:
#include <LiquidCrystal.h>
//constants
const unsigned int numRows = 2; 
const unsigned int numColms = 16;
const unsigned int GPO1 = 13;
const unsigned int Contrast_pin = 11; //LCD Contrast pin 3
const unsigned int Brightness_pin = 3; //2N2222 transistor, Base - pin 3, Collector - +5v, Emitter - lcd Brightness pin 15
unsigned int cValue = 0; //contrast max. ~0v .. min 1.5v
unsigned int bValue = 255; //brightness max. ~4.5-5v .. min ~0v
byte rx_byte, ch_byte;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(10, 9, 8, 7, 6, 5, 4); //LCD RS - 4 pin, RW - 5 pin, Enable - 6 pin, Data4 - 11 pin, Data5 - 12 pin, Data6- 13 pin, Data7- 14 pin


void setup() {

  pinMode(GPO1, OUTPUT); //set GPO1 pin as Output
  digitalWrite(GPO1, LOW); //set GPO1 OFF
  pinMode(Contrast_pin, OUTPUT); //set Contrast pin as Output
  analogWrite(Contrast_pin, cValue); //set Contrast to max.
  pinMode(Brightness_pin, OUTPUT); //set Brightness pin as Output
  analogWrite(Brightness_pin, bValue); //set Brightness to max.
  Serial.begin(19200); //19200 is default Matrix Orbital speed (max.= 115200)
  lcd.begin(numColms, numRows); // set up the LCD's number of rows and columns: 
  LCD_CGRAM_Reset(); //for some reason after power up, there is a garbage in CGRAM. Do the trick, fill all CGRAM with blocks
  lcd.clear(); // clear LCD memory and move cursor to 0,0
  lcd.print("**LCD  SMARTIE**");
  lcd.setCursor(0,1);
  lcd.print("Arduino  Orbital");
}


byte serial_getCh() { //read and returne one byte
  while (Serial.available() == 0); // loop continuously, until the expression == 0, becomes false
  return Serial.read();
}

void LCDcustomChar5x8() {
 byte customCh[8];
 byte addr = serial_getCh(); //get custom simbol addr (up to. 8 simbols)
 for (unsigned int i = 0; i < 8; i ++) {
   customCh[i] = serial_getCh(); //get 5 pixels of custom pattern x 8 times
 }
 lcd.createChar(addr, customCh); //load custom simbol to the CGRAM
}

void LCD_CGRAM_Reset() { //for some reason after power up, there is a garbage in CGRAM. Do the trick, fill all CGRAM with blocks
  byte solidBlock[8]={31,31,31,31,31,31,31,31};
  for (unsigned int i = 0; i < 8; i ++) { 
    lcd.createChar(i, solidBlock); //create custom simbol (custom simbol addr, custom simbol), max. 8 simbols
  }
}

void loop() {
  
  ch_byte = serial_getCh();
   
  if (ch_byte == 0xFE) { //0xFE(254) - Matrix Orbital Prefix followed before any command
    switch (rx_byte = serial_getCh()) { //take next command byte an "swich" it
        case 53: //read serial number, 2 bytes
        Serial.print(0x0D,0x03); //1303
        break;
        case 54: //read firmware version number, 1 byte
            Serial.print(0x22); //0x22 - LK162-12, 0x57 - LK204-25
            break;
        case 55: //read module type
            Serial.print(0x34); // 0x34 - LK162-12, 0x9 - LK204-25
            break;
        case 66: //backlight on (min) if min = 0 ramain indefinitely
        if (serial_getCh() >= 0) {
            analogWrite(Brightness_pin, bValue);
          }
            break;
        case 70: //backlight off
            analogWrite(Brightness_pin, 0);
            break;
        case 71: //set cursor position (column, row)
            lcd.setCursor(serial_getCh()-1, serial_getCh()-1); //(take next bit after 71 and -1, take another bit and -1)
            break;
        case 72: //cursor home but don't clear the screen
            lcd.setCursor(0,0);
            break;
        case 74: //underline cursor on
            lcd.cursor();
            break;
        case 75:  //underline cursor off
            lcd.noCursor();			
            break;
        case 76: //move cursor left
            lcd.scrollDisplayLeft();
            break;
        case 77: //move cursor right
            lcd.scrollDisplayRight();
            break;
        case 78: //define custom char (id, data)
            LCDcustomChar5x8();
            break;
        case 80: //set contrast, 0-255 (0x00-0xff)
            cValue = map(serial_getCh(),0,255,75,0); // map slider's min .. max to 1.5v .. 0v
            analogWrite(Contrast_pin, cValue);
            break;
        case 81: //auto scroll on
            lcd.autoscroll();
            break;
        case 82: //auto scroll off
            lcd.noAutoscroll();
            break;
        case 83: //blinkin block cursor on
            lcd.blink();
            break;
        case 84:  //blinking block cursor off
            lcd.noBlink();
            break;
        case 86: //GPO off (originaly Matrix orbital has 7 GPO, 1..7)
            if (serial_getCh() >= 0) {
              digitalWrite(GPO1, LOW);
            }
            break;
        case 87: //GPO on (originaly Matrix orbital has 7 GPO, 1..7)
            if (serial_getCh() >= 0) {
       	      digitalWrite(GPO1, HIGH);
            }
            break;
        case 88: //clear display, cursor home
            lcd.clear();
            break;
        case 104: //initialize horizontal bar
            LCDcustomChar5x8();
            break;
        case 115: //initialize narrow vertical bar
            LCDcustomChar5x8();
            break;        
        case 118: //initialize wide vertical bar
            LCDcustomChar5x8();
            break;
         case 152: //set brightness, 0-255 (0x00-0xff)
            bValue = map(serial_getCh(),0,255,25,255); //map slider's min .. max to 0.44v .. 4.5-5v
            analogWrite(Brightness_pin, bValue);
            break;
          case 35: //place large number (col, digit)
          case 37: //GPO or keypad mode (mode)
          case 38: //poll key presses
          case 51: //change I2C slave address (address)
          case 52: //set serial number (byte_1, byte_2)
          case 57: //set baud rate (baud rate)
          case 58: //enter flow control mode (full, empty)
          case 59: //exit flow-control mode
          case 61: //draw vertical bar (2 parameters, column, length)
          case 64: //load the startup screen
          case 65: //auto transmit keypresses on
          case 67: //auto line wrap on (R)
          case 68: //auto line wrap off (R)
          case 69: //clear key buffer
          case 79: //auto transmit keypress off
          case 85: //set debounce time (time)
          case 96: //auto repeat mode off
          case 109: //initialize medium number
          case 110: //initialize lange numbers
          case 111: //place medium numbers
          case 124: //place horizontal bar graph (column, row, direction, length)
          case 126: //set auto repeat mode (mode)
          case 145: //set and save contrast (contrast)
          case 153: //set and save brightness (brightness)
          case 160: //transmission protocol select (protocol)
          case 192: //load custom characters (bank)
          case 164: //setting a non-standart baudrate (speed)
          case 193: //save custom character (bank, id, data)
          case 194: //save startup screen custom characters (id, data)
          case 195: //set startup GPO state (number, state)
          case 200: //dallas 1-Wire
          case 213: //assign keypad codes
             lcd.clear();
             lcd.print(" Command No. ");
             lcd.print(rx_byte);
             lcd.setCursor(0,1);
             lcd.print("is not supported");
             delay(300);
             break;
        default: // if nothing else matches, do default switch
               Serial.flush(); //unrecognized commands , flush the buffer.
    } // end of "switch", also "break" point
  } //end of "if"
  else {
     lcd.write(ch_byte); //else it's a plain char, write to LCD
  } //end of "else"
} //end of scketch :(

Как можно переделать его на I2C?

b707
Offline
Зарегистрирован: 26.05.2017

SAn4Es_TV пишет:

Как можно переделать его на I2C?

в качестве идеи - заменить библиотеку LiquidCrystal.h на LiquidCrystal_I2C.h ?

SAn4Es_TV
Offline
Зарегистрирован: 18.04.2019
040 void LCDcustomChar5x8() {
041  byte customCh[8];
042  byte addr = serial_getCh(); //get custom simbol addr (up to. 8 simbols)
043  for (unsigned int i = 0; i < 8; i ++) {
044    customCh[i] = serial_getCh(); //get 5 pixels of custom pattern x 8 times
045  }
046  lcd.createChar(addr, customCh); //load custom simbol to the CGRAM
047 }
040 void LCDcustomChar5x8() {
041  byte customCh[8];
042  byte addr = serial_getCh(); //get custom simbol addr (up to. 8 simbols)
043  for (unsigned int i = 0; i < 8; i ++) {
044    customCh[i] = serial_getCh(); //get 5 pixels of custom pattern x 8 times
045  }
046  lcd.createChar(addr, customCh); //load custom simbol to the CGRAM
047 }

SAn4Es_TV
Offline
Зарегистрирован: 18.04.2019

А как можно почту добавить?

Что нужно вводить?

b707
Offline
Зарегистрирован: 26.05.2017

SAn4Es_TV , форум не чат, не надо тут все подряд спрашивать

SAn4Es_TV
Offline
Зарегистрирован: 18.04.2019

Как можно подключить кнопки что бы они работали с программой?

3-тий день пытаюсь найти решение

BOOM
BOOM аватар
Offline
Зарегистрирован: 14.11.2018

707й, тебя игнорят...

SAn4Es_TV
Offline
Зарегистрирован: 18.04.2019

Тема была создана для ОБЩЕГО подключения к ардуине всей нужной электроники(Дисплей, кнопки) так, чтобы она работала с LCDsmartie