C++ ?
dann probier mal die hier:
Displays
OLED 128x64 SSD1306, SH1106
I2C Bus speed: STANDARD + FAST-I2C (100-400kHz, getestet)
aktuelle Treiber-Version:
http://hallard.me/adafruit-oled-display-driver-for-pi/
https://github.com/hallard/ArduiPi_OLED
https://github.com/jonesman/ArduiPi_OLED // neue I2C Treiber ohne sudo
Anwendungsbeispiel:
https://raspilab.blog/2015/03/31/mei...lay-ansteuern/
Zur Verwendung mit Geany: zusätzlicher build-Parameter
-lArduiPi_OLED // lowercase "-L"
7 verschiedene OLED Typen werden unterstützt:
0 Adafruit SPI 128x32 SSD1306
1 Adafruit SPI 128x64 SSD1306
2 Adafruit I2C 128x32 SSD1306
3 Adafruit I2C 128x64 SSD1306
4 Seeed I2C 128x64 SSD1308
5 Seeed I2C 96x96 SSD1327
6 NoName I2C 128x64 SH1106
Den richtigen OLED Type muss man ausprobieren, bei mir funktioniert Type 6, d.h. also für den Konsole-Aufruf des Bespielprogramms in examples:
sudo ./oled_demo --verbose --oled 6
vereinfachter Start der demo mit festem I2C oled Type 6, ohne Command Line Parameter :
Code:
//----------------------------------------------------------------------
int main(int argc, char **argv)
{
int i;
// 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
//.... Code!
display.close();
}
//----------------------------------------------------------------------
einfacher Testcode, testweise zusammen mit wiringPi :
Code:
//----------------------------------------------------------------------/*
*
*
* OLED Display
* plus wringPi millis + delay
*
* http://hallard.me/adafruit-oled-display-driver-for-pi/
* https://github.com/hallard/ArduiPi_OLED
*
* 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>
#define byte uint8_t
// Instantiate the OLED display
ArduiPi_OLED oledtft;
void oled_cls() {
oledtft.clearDisplay();
oledtft.display();
}
void oled_printxy(int x, int y, char * str) {
oledtft.setCursor(x,y);
oledtft.print(str);
oledtft.display();
}
// 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;
}
//=========================================================================
int main() {
int check;
char sbuf[100];
uint32_t msec, millisav;
// wiringPi
setenv("WIRINGPI_GPIOMEM", "1", 1); // no sudo for gpios required
check = wiringPiSetup(); // init by wiringPi pin numbering
if( check == -1 ) return 1;
// Oled supported display in ArduiPi_SSD1306.h
// change parameters to fit to your LCD
if ( !oledtft.init(OLED_I2C_RESET, 6) )
exit(EXIT_FAILURE);
oledtft.begin();
// init done
oled_cls();
// test
oledtft.setTextSize(1);
oledtft.setTextColor(WHITE);
oledtft.setTextSize(1);
oledtft.setCursor(0, 0); oledtft.print(" 0 Hello, world!\n");
oledtft.setCursor(0, 8); oledtft.print(" 8 I2C OLED");
oledtft.setCursor(0,16); oledtft.print("16 128x64 addr 0x3c"); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< !!!!!
oledtft.setCursor(0,24); oledtft.print("24 8x21 char size=1");
oledtft.setCursor(0,32); oledtft.print("32 ");
oledtft.setCursor(0,40); oledtft.print("40 ");
oledtft.setCursor(0,48); oledtft.print("48 456789112345678921");
oledtft.setCursor(0,56); oledtft.print("56 ");
oledtft.display();
sleep(1);
oled_cls();
millisav=millis();
while(1) {
msec = millis() - millisav;
sprintf(sbuf, " millisec = %ld \n", msec);
printf(sbuf);
oledtft.setTextColor(WHITE, BLACK);
oled_printxy( 0,16, sbuf);
if (kbhit())
{
int c = getchar();
if(c==27) break;
}
delay(500);
}
oled_cls();
oledtft.close();
return (0);
}
//----------------------------------------------------------------------
du kannst ja C++, wschl kriegst du das auch dann mit 2 versch. Instanzen hin...
Lesezeichen