- 3D-Druck Einstieg und Tipps         
Ergebnis 1 bis 4 von 4

Thema: LCD 2004 20x4 Zeichen per C/C++ für Raspi?

  1. #1
    HaWe
    Gast

    LCD 2004 20x4 Zeichen per C/C++ für Raspi?

    Anzeige

    Powerstation Test
    hallo,

    hat wer eine Idee,wie man so ein LCD Display mit HD44780 und I2C Controller
    https://www.amazon.de/mn/search/?_en...4780%20Display
    per Raspi im C-Programm ansteuern kann? Man findet immer nur jede Menge Python...:
    http://tutorials-raspberrypi.de/hd44...-pi-ansteuern/

    es soll ähnlich gehen wie bei Arduino:

    Cursor setzen auf Zeile,Spalte, z.B.
    LCD.setCursor(2,0);
    dann String schreiben, z.B.
    LCD.print(strbuf);

    oder, alternativ, auch
    lcdprintxy(x, y, strbuf);

    kennt wer eine solche oder eine ähnliche lib?
    Geändert von HaWe (04.08.2016 um 08:14 Uhr)

  2. #2
    Erfahrener Benutzer Begeisterter Techniker
    Registriert seit
    14.12.2010
    Ort
    NRW
    Beiträge
    223
    bei Sunfounder gibt es ein RaspiKit, da gibt ein C Beispiel für ein 16x2 aber direkt angeschlossen und lcd.h + wiringpi .... vielleicht kannst du da was von abwandeln und für dich benutzen.

  3. #3
    HaWe
    Gast
    hallo,
    vielen Dank, aber die dPin-Verkabelung verbraucht zu viele GPIOs, deshalb bin ich auf das I2C Gerät gekommen. WiringPi ist dazu schon ein guter Ansatz, das verwende ich sonst auch, nur müsste dann auch dafür eine I2C Lib oder aber der genaue i2c-Code-Ansteuerungscode samt high-level API-Befehlen existieren, eben vergleichbar mit Arduino/Wiring.

    - - - Aktualisiert - - -

    ps,
    alternativ käme sogar auch ein kleines i2c-OLED Display in Frage wie das hier,
    http://www.ebay.de/itm/1-3-SPI-I2C-I...sAAOSwHJhXM-pJ
    aber auch dazu wäre eine i2c-Lib (z.B. für wiringPi) notwendig -
    und auch Adafruit z.B. bietet nur Python, keine C/C++ libs soweit ich es durchforstet habe:
    https://learn.adafruit.com/adafruit-...g-your-display
    (Das Adafruit OLED ist allerdings SPI wie es aussieht, kein I2C)

  4. #4
    HaWe
    Gast
    update:
    habe mich jetzt für das 128x64 OLED entschieden - ist klein, flach, hat bis zu 8 Zeilen zu je 21 Zeichen, 3 verschiedene Schriftgrößen, und läuft im Gegensatz zu den PCF8574-i2c- getriebenen LCD2004 auch gemeinsam mit anderen I2C Geräten bei 400kHz!

    Hier ein Testbeispiel, das ich grade für i2c-Testzwecke (RTCDS3231 plus OLED bei 400kHz) geschrieben habe - funktioniert perfekt. Später kommen sowohl der Display-Teil als auch andere langsame Geräte-Zugriffe (RTC, ...) in je einen eigenen low-priority pthread task, damit sie die schnellen Geräte (MCP23017, IMU etc.) nicht durch delays behindern - share and enjoy!

    Code:
    /*
     * 
     * RTC DS3231
     * plus OLED Display
     *  
     * ver 0001
     * 
     */
     
     
    #include <string.h>
    #include <unistd.h>
    #include <errno.h>
    #include <stdio.h>
    #include <stdint.h>
    #include <stdlib.h>
    #include <linux/i2c-dev.h>
    #include <sys/ioctl.h>
    #include <fcntl.h>
    #include <unistd.h>
    
    #include <stdbool.h>
    #include <string.h>
    #include <termio.h>
    
    #include <wiringPi.h>
    #include <wiringPiI2C.h>
    
    #include <ArduiPi_OLED_lib.h>
    #include <Adafruit_GFX.h>
    #include <ArduiPi_OLED.h>
    #include <getopt.h>
    
    
    #define  byte  uint8_t
     
    // RTC DS3231
    #define ADDR_RTCDS3231 0x68
    int     fRTCds3231;
    
    // Instantiate the OLED display
    ArduiPi_OLED display;
    
    
    void oled_cls() {
         display.clearDisplay(); 
         display.display(); 
    }
    
    
    void oled_printxy(int x, int y, char * str) {
         display.setCursor(x,y);
         display.print(str);
         display.display(); 
    }
    
    
    void oled_clrlnxy(int x, int y) {
         display.setTextColor(BLACK, BLACK); 
         oled_printxy( 0, 8, "                     ");
         display.setTextColor(WHITE, BLACK);  
    }
    
    
    // mimic conio.h kbhit
    bool kbhit(void)
    {
        struct termios original;
        tcgetattr(STDIN_FILENO, &original);
        struct termios term;
        memcpy(&term, &original, sizeof(term));
        term.c_lflag &= ~ICANON;
        tcsetattr(STDIN_FILENO, TCSANOW, &term);
        int characters_buffered = 0;
        ioctl(STDIN_FILENO, FIONREAD, &characters_buffered);
        tcsetattr(STDIN_FILENO, TCSANOW, &original);
        bool pressed = (characters_buffered != 0);
        return pressed;
    }
    
    //=====================================================================================
    // Convert normal decimal numbers to binary coded decimal
    //=====================================================================================
    byte decToBcd(byte val) {  return( (val/10*16) + (val%10) );  }
    
    
    //=====================================================================================
    // Convert binary coded decimal to normal decimal numbers
    //=====================================================================================
    byte bcdToDec(byte val)  {  return( (val/16*10) + (val%16) ); }
    
    
    //=====================================================================================
    
    
    
    
    void setDS3231time( byte year, byte month, byte day, 
         byte hour, byte minute, byte second, byte dow)
    {
         // sets time and date data to DS3231  
       
         wiringPiI2CWriteReg8(fRTCds3231, 0, decToBcd(second));      // set seconds
         wiringPiI2CWriteReg8(fRTCds3231, 1, decToBcd(minute));      // set minutes
         wiringPiI2CWriteReg8(fRTCds3231, 2, decToBcd(hour));        // set hours
         wiringPiI2CWriteReg8(fRTCds3231, 3, decToBcd(dow));         // ( 1=Sunday, 7=Saturday)
         wiringPiI2CWriteReg8(fRTCds3231, 4, decToBcd(day));         // set dayOfMonth (1 to 31)
         wiringPiI2CWriteReg8(fRTCds3231, 5, decToBcd(month));       // set month
         wiringPiI2CWriteReg8(fRTCds3231, 6, decToBcd(year));        // set year (0 to 99)
       
    }
    
    
    void getDS3231time( int &year, int &month, int &day, 
         int &hour, int &minute, int &second, int &dow)
    {
         second =     bcdToDec(wiringPiI2CReadReg8 (fRTCds3231, 0) & 0x7f );
         minute =     bcdToDec(wiringPiI2CReadReg8 (fRTCds3231, 1) );
         hour =       bcdToDec(wiringPiI2CReadReg8 (fRTCds3231, 2) & 0x3f );
         dow =        bcdToDec(wiringPiI2CReadReg8 (fRTCds3231, 3) );
         day =        bcdToDec(wiringPiI2CReadReg8 (fRTCds3231, 4) );
         month =      bcdToDec(wiringPiI2CReadReg8 (fRTCds3231, 5) );
         year =       bcdToDec(wiringPiI2CReadReg8 (fRTCds3231, 6) );   
    }
    
    
      char * sdow (int dow) {	 
    	 switch(dow){     
         case 1:
           return("Sunday");
           break;
         case 2:
           return("Monday");
           break;
         case 3:
           return("Tuesday");
           break;
         case 4:
           return("Wednesday");
           break;
         case 5:
           return("Thursday");
           break;
         case 6:
           return("Friday");
           break;
         case 7:
           return("Saturday");
           break;
         } 
         return ("error");
    	  
      }
    
    //=====================================================================================
    
    
    
    int main() {
       static int  year, month, day, hour, minute, second, dow;   
       int i=0, check;
       char sbuf[100];   
       
       // Oled supported display in ArduiPi_SSD1306.h
    
       // I2C change parameters to fit to your LCD
       if ( !display.init(OLED_I2C_RESET, 6) )
         exit(EXIT_FAILURE);
    
       display.begin();
    	
       // init done
      
       oled_cls();
    
       // test
     
       display.setTextSize(1);
       display.setTextColor(WHITE);
       display.setTextSize(1); 
       display.setCursor(0, 0);  display.print(" 0 Hello, world!\n");
       display.setCursor(0, 8);  display.print(" 8 I2C OLED");  
       display.setCursor(0,16);  display.print("16 128x64 addr 0x3c");
       display.setCursor(0,24);  display.print("24 8x21 char size=1");
       display.setCursor(0,32);  display.print("32 ");
       display.setCursor(0,40);  display.print("40 ");
       display.setCursor(0,48);  display.print("48 456789112345678921");
       display.setCursor(0,56);  display.print("56 ");
       //display.setTextColor(BLACK, WHITE); // 'inverted' text
       display.display();
       sleep(1);
       oled_cls();
    
    
       // fRTCds3231 = wiringPiI2CSetupInterface( "/dev/i2c-0",  ADDR_RTCDS3231 );	
       fRTCds3231 = wiringPiI2CSetupInterface( "/dev/i2c-1",  ADDR_RTCDS3231 );   
       
       strcpy(sbuf, "RTC DS3231 \n\n");
       printf(sbuf); 
       oled_printxy( 0, 0, sbuf);
       getDS3231time( year, month, day, hour, minute, second, dow); 
       sprintf(sbuf, "20%02d/%02d/%02d  %02d:%02d:%02d", year, month, day, hour, minute, second); 
       printf(sbuf); 
       oled_printxy( 0, 8, sbuf);    
       sprintf(sbuf, " Day of week %1d: ", dow); 
       printf(sbuf);  
       printf(sdow(dow) );
       printf("\n\n");	
       
       printf("***  Set Date/Time: enter 1      *** \n");
       printf("***  else:          display time *** \n\n");
       oled_printxy( 0,24, "Set DateTime enter 1");
       oled_printxy( 0,32, "else:   display time");
    
       i = getchar();
       
       //debug
       //printf("%d \n", i);
       
       while (i=='1') {
          // get string yy mm dd hh mm ss dw : gets() ?
          printf("yy mm dd hh mm ss dw (DayOfWeek) \n");
          check=scanf("%d %d %d %d %d %d %d", &year, &month, &day,  &hour, &minute, &second, &dow);
          
          getchar();
          printf("check=%d\n", check);
          
          if(check==7) {     
    	     sprintf(sbuf, "20%02d/%02d/%02d  %02d:%02d:%02d", year, month, day, hour, minute, second);  
             printf(sbuf);     
             oled_printxy( 0, 8, sbuf); 
             printf(" Day of week %1d: ", dow);     
             printf(sdow(dow) );
             printf("\n");
             setDS3231time( year, month, day, hour, minute, second, dow );
          }             
           
          oled_cls();
           
          printf("RTC DS3231 \n");
          oled_printxy( 0, 0, sbuf); 
          printf("***  Set Date/Time: enter 1      *** \n");
          printf("***  else:          display time *** \n\n");
          oled_printxy( 0,24, "Set DateTime enter 1");
          oled_printxy( 0,32, "else:   display time");
          i=0;
          i = getchar();         
                
       }
       
       oled_cls();
       oled_printxy( 0, 0, "RTC DS3231 - quit:ESC"); 
       
       while(1) {
         getDS3231time( year, month, day, hour, minute, second, dow);
         sprintf(sbuf, "20%02d/%02d/%02d  %02d:%02d:%02d", year, month, day, hour, minute, second);        
         printf(sbuf);     
         oled_clrlnxy( 0,16); 
         oled_printxy( 0,16, sbuf);
         printf(" Day of week %1d: ", dow);     
         printf(sdow(dow) );
         printf("\n");		
         if (kbhit())
         {
             int c = getchar();
             if(c==27) break;
         }   
         sleep(1);
       }
       
       oled_cls();
       return (0);
    }

Ähnliche Themen

  1. Antworten: 63
    Letzter Beitrag: 18.02.2016, 07:43
  2. Folientastatur mit Aussparung für HD44780 20x4
    Von Cysign im Forum Suche bestimmtes Bauteil bzw. Empfehlung
    Antworten: 6
    Letzter Beitrag: 27.12.2015, 14:28
  3. Verkaufe 2004 Character LCD Module Display 20X4 Zeichen Blau TC2004A-03
    Von bufu im Forum Kaufen, Verkaufen, Tauschen, Suchen
    Antworten: 4
    Letzter Beitrag: 25.01.2014, 11:23
  4. Initialisierung des LCD - Display (20x4)
    Von hemisoft im Forum Allgemeines zum Thema Roboter / Modellbau
    Antworten: 16
    Letzter Beitrag: 28.05.2013, 20:43
  5. blinken einer Zeile (LCD 20x4)
    Von quantum im Forum Basic-Programmierung (Bascom-Compiler)
    Antworten: 2
    Letzter Beitrag: 16.09.2005, 10:57

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

Solar Speicher und Akkus Tests