olikraus / u8g2

U8glib library for monochrome displays, version 2
Other
5.08k stars 1.05k forks source link

U8X8_SH1106_128X64 DRAW LARGE BITMAP? #2100

Open Beppi4U opened 1 year ago

Beppi4U commented 1 year ago

Hi! Is it possible to draw large Bitmap image with U8x8? Have already included U8x8 for Text but want to show a big Bitmap at start as a welcome screen! Use an Arduino Nano as Board There should be 4.5 Kbit left for the Bitmap after Sketch compiling. Isnt enough space for another Lib. Thanx for Helping! Andreas

olikraus commented 1 year ago

U8g2 is there for bitmap graphics. Of course you could also use u8x8 for graphics, but then you need to use the draw tile function and break down you picture into 8x8 tiles.

Beppi4U commented 1 year ago

Hi! Na... not an option! I tried to use both lib's and now i am afraid all i made is a bunch of Spaghetti code! Do i have to init the U8g2 to show it? Because it compiles and waits 3sec. but does'nt show the Bitmap! Would you min d to throw an eye on it? Rest works fine. Greetings Andi Sorry for ugly coding....my bad!

`

include

include

include

include "U8glib.h"

include "AVL.h"

ifdef U8x8_HAVE_HW_I2C

endif

U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/ reset=/ U8X8_PIN_NONE); // DEFINITION DES DISPLAYS UND DER SCHNITTSTELLE

define button1 3 // Button B1 is connected to Arduino pin 9 CHANGE BUTTON

define button2 2 // Button B2 is connected to Arduino pin 8 SET BUTTON

// DER DRITTE BUTTON (RESET BUTTON) IST DIREKT AUSGEFÜHRT RST TO GND

void setup(void) { pinMode(button1, INPUT_PULLUP); pinMode(button2, INPUT_PULLUP); delay(500);

draw(); // SHOW AVL LOGO ON SCREEN delay(2999);

u8x8.begin(); u8x8.clear();

// VORSCHAU u8x8.clearDisplay(); u8x8.setFont(u8x8_font_inr21_2x4_r); fadeinout(0, 2, "FTIR i60", 255); u8x8.setFont(u8x8_font_pcsenior_r); u8x8.drawString(0, 6,"_"); delay(250); u8x8.setFont(u8x8_font_inr21_2x4_r); fadeinout(0, 2, "FTIR i60", 255); delay(10); u8x8.setFont(u8x8_font_pcsenior_r); u8x8.drawString(0, 6,"____"); delay(250); u8x8.drawString(0, 6,"_"); delay(250); u8x8.setFont(u8x8_font_inr21_2x4_r); fadeinout(0, 2, "FTIR i60", 255); u8x8.setFont(u8x8_font_pcsenior_r); u8x8.drawString(0, 6,"____"); delay(2500);

u8x8.clear(); u8x8.setContrast(255); u8x8.setFont(u8x8_font_pcsenior_r); // (u8x8_font_5x7_f) u8x8.drawString(0,1," ZUR ERINNERUNG"); u8x8.drawString(0,2," AN DEINE "); u8x8.drawString(0,3," KOLLEGEN BEI"); u8x8.drawString(0,4," DER *** "); u8x8.drawString(0,5," MESSTECHNIK! "); u8x8.drawString(0,6," 23.FEBRUAR 2023"); delay(5000); u8x8.clear(); u8x8.setFont(u8x8_font_pcsenior_r); // (u8x8_font_5x7_f) u8x8.drawString(0,1," +++++++++"); u8x8.drawString(0,2,"+++++++++++"); u8x8.drawString(0,3," ++++++++"); u8x8.drawString(0,4,"++++++++++ "); u8x8.drawString(0,5," UND ANDI "); delay(5000); u8x8.clear(); u8x8.drawString(0,0," WIR VERMISSEN"); u8x8.drawString(0,1," DICH !"); u8x8.drawString(0,3," BEGINNE DEN TAG"); u8x8.drawString(0,4,"MIT EINEM LACHEN"); u8x8.drawString(0,5," UND DER TAG"); u8x8.drawString(0,6," LACHT MIT DIR!"); delay(8000); u8x8.clear(); }

char Time[] = " : : "; char Calendar[] = " / /20 "; char temperature[] = " 00.00"; char temperature_msb; byte i, second, minute, hour, day, date, month, year, temperature_lsb;

// DRAW THE BITMAP AVL LOGO void draw(void) { // graphic commands to redraw the complete screen should be placed here
u8g.drawBitmapP( 0, 9, 16, 64 , AVL); }

void display_day(){ switch(day){ u8x8.setFont(u8x8_font_pcsenior_r); case 1: u8x8.drawString(0, 0, " SO "); break; case 2: u8x8.drawString(0, 0, " MO "); break; case 3: u8x8.drawString(0, 0, " DI "); break; case 4: u8x8.drawString(0, 0, " MI "); break; case 5: u8x8.drawString(0, 0, " DO "); break; case 6: u8x8.drawString(0, 0, " FR "); break; default: u8x8.drawString(0, 0, " SA "); } }

void DS3231_display(){ // Convert BCD to decimal second = (second >> 4) 10 + (second & 0x0F); minute = (minute >> 4) 10 + (minute & 0x0F); hour = (hour >> 4) 10 + (hour & 0x0F); date = (date >> 4) 10 + (date & 0x0F); month = (month >> 4) 10 + (month & 0x0F); year = (year >> 4) 10 + (year & 0x0F); // End conversion

Time[7] = second % 10 + 48; Time[6] = second / 10 + 48; Time[4] = minute % 10 + 48; Time[3] = minute / 10 + 48; Time[1] = hour % 10 + 48; Time[0] = hour / 10 + 48; Calendar[9] = year % 10 + 48; Calendar[8] = year / 10 + 48; Calendar[4] = month % 10 + 48; Calendar[3] = month / 10 + 48; Calendar[1] = date % 10 + 48; Calendar[0] = date / 10 + 48; if(temperature_msb < 0){ temperature_msb = abs(temperature_msb); temperature[0] = '-'; } else temperature[0] = ' '; temperature_lsb >>= 6; temperature[2] = temperature_msb % 10 + 48; temperature[1] = temperature_msb / 10 + 48; if(temperature_lsb == 0 || temperature_lsb == 2){ temperature[5] = '0'; if(temperature_lsb == 0) temperature[4] = '0'; else temperature[4] = '5'; } if(temperature_lsb == 1 || temperature_lsb == 3){ temperature[5] = '5'; if(temperature_lsb == 1) temperature[4] = '2'; else temperature[4] = '7'; } u8x8.setFont(u8x8_font_pcsenior_r); u8x8.drawString(5,0, Calendar); // Display the date (format: dd/mm/yyyy) u8x8.setFont(u8x8_font_profont29_2x3_r); u8x8.drawString(0, 2, Time); // Display the time u8x8.setFont(u8x8_font_pcsenior_r); u8x8.drawString(1, 6," TEMP"); u8x8.drawString(6, 6, temperature); // Display the temperature u8x8.drawString(13, 6,"C"); }

void blink_parameter(){ byte j = 0; while(j < 10 && digitalRead(button1) && digitalRead(button2)){ j++; delay(25); } }

byte edit(byte x_pos, byte y_pos, byte parameter){ char text[3]; sprintf(text,"%02u", parameter); while(!digitalRead(button1)); // Wait until button B1 released while(true){ while(!digitalRead(button2)){ // If button B2 is pressed parameter++; if(i == 0 && parameter > 31) // If date > 31 ==> date = 1 parameter = 1; if(i == 1 && parameter > 12) // If month > 12 ==> month = 1 parameter = 1; if(i == 2 && parameter > 99) // If year > 99 ==> year = 0 parameter = 0; if(i == 3 && parameter > 23) // If hours > 23 ==> hours = 0 parameter = 0; if(i == 4 && parameter > 59) // If minutes > 59 ==> minutes = 0 parameter = 0; sprintf(text,"%02u", parameter); draw_text(x_pos, y_pos, text, 1); delay(200); // Wait 200ms } draw_text(x_pos, y_pos, " ", 1); blink_parameter(); draw_text(x_pos, y_pos, text, 1); blink_parameter(); if(!digitalRead(button1)){ // If button B1 is pressed i++; // Increament 'i' for the next parameter return parameter; // Return parameter value and exit } } }

void draw_text(byte x_pos, byte y_pos, char *text, byte text_size) { u8x8.setCursor(x_pos, y_pos); u8x8.setFont(u8x8_font_5x7_f); // u8x8.setTextSize(text_size); u8x8.print(text); u8x8.display(); }

void loop() {

if(!digitalRead(button1)){ // If button B1 is pressed i = 0; while(!digitalRead(button1)); // Wait for button B1 release while(true){ while(!digitalRead(button2)){ // While button B2 pressed day++; // Increment day if(day > 7) day = 1; display_day(); // Call display_day function delay(200); // Wait 200 ms } u8x8.setFont(u8x8_font_5x7_f); u8x8.drawString(0, 0, " "); blink_parameter(); // Call blink_parameter function display_day(); // Call display_day function blink_parameter(); // Call blink_parameter function if(!digitalRead(button1)) // If button B1 is pressed break; } //set position of text when editing on button press date = edit(6, 0, date); // Edit date month = edit(9, 0, month); // Edit month year = edit(13,0, year); // Edit year hour = edit(0, 2, hour); // Edit hours minute = edit(4, 2, minute); // Edit minutes

// Convert decimal to BCD
minute = ((minute / 10) << 4) + (minute % 10);
hour = ((hour / 10)  << 4) + (hour % 10);
date = ((date / 10) <<  4) + (date % 10);
month = ((month / 10)  << 4) + (month % 10);
year = ((year / 10)  << 4) + (year % 10);
// End conversion

// Write data to DS3231 RTC
Wire.beginTransmission(0x68);               // Start I2C protocol with DS3231 address
Wire.write(0);                              // Send register address
Wire.write(0);                              // Reset sesonds and start oscillator
Wire.write(minute);                         // Write minute
Wire.write(hour);                           // Write hour
Wire.write(day);                            // Write day
Wire.write(date);                           // Write date
Wire.write(month);                          // Write month
Wire.write(year);                           // Write year
Wire.endTransmission();                     // Stop transmission and release the I2C bus
delay(200);                                 // Wait 200ms

}

Wire.beginTransmission(0x68); // Start I2C protocol with DS3231 address Wire.write(0); // Send register address Wire.endTransmission(false); // I2C restart Wire.requestFrom(0x68, 7); // Request 7 bytes from DS3231 and release I2C bus at end of reading second = Wire.read(); // Read seconds from register 0 minute = Wire.read(); // Read minuts from register 1 hour = Wire.read(); // Read hour from register 2 day = Wire.read(); // Read day from register 3 date = Wire.read(); // Read date from register 4 month = Wire.read(); // Read month from register 5 year = Wire.read(); // Read year from register 6 Wire.beginTransmission(0x68); // Start I2C protocol with DS3231 address Wire.write(0x11); // Send register address Wire.endTransmission(false); // I2C restart Wire.requestFrom(0x68, 2); // Request 2 bytes from DS3231 and release I2C bus at end of reading temperature_msb = Wire.read(); // Read temperature MSB temperature_lsb = Wire.read(); // Read temperature LSB

display_day(); DS3231_display(); // Diaplay time & calendar

delay(50); // Wait 50ms }

// EIN UND AUSBLENDEN VON TEXT!

void fadeinout(int xpos, int ypos,String text, int stufe) { stufe = 0; //u8x8.clearDisplay();

for (int stufe=0; stufe<255; stufe=stufe+4) { u8x8.setFont(u8x8_font_inr21_2x4_r); u8x8.setCursor(xpos, ypos); u8x8.print(text); u8x8.setContrast(stufe); Serial.print(text); Serial.println(stufe); stufe=stufe+3;

}

for (int stufe=255; stufe>0; stufe=stufe-4) { u8x8.setFont(u8x8_font_inr21_2x4_r); u8x8.setCursor(xpos, ypos); u8x8.print(text); u8x8.setContrast(stufe); Serial.print(text); Serial.println(stufe); stufe=stufe-3; }

}

//AVL.h const unsigned char AVL [] PROGMEM = { // 'AVL, 128x55px 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc1, 0x80, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0xc0, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0xe1, 0xc0, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0xc0, 0xff, 0xc0, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0xc0, 0x7f, 0x80, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xc0, 0x9c, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xd0, 0xc0, 0x00, 0x00, 0x01, 0x80, 0x00, 0x01, 0xe0, 0x7c, 0x01, 0xe1, 0xe0, 0x00, 0x00, 0x63, 0xd0, 0xfe, 0x00, 0x00, 0x01, 0x80, 0x00, 0x01, 0xe0, 0x3c, 0x03, 0xe1, 0xe0, 0x00, 0x00, 0x7f, 0x91, 0x78, 0x00, 0x00, 0x01, 0x80, 0x00, 0x03, 0xf0, 0x3c, 0x03, 0xc1, 0xe0, 0x00, 0x00, 0x3f, 0x3c, 0xa0, 0x06, 0x00, 0x01, 0x80, 0x00, 0x03, 0xf0, 0x3e, 0x03, 0xc1, 0xe0, 0x00, 0x00, 0x1c, 0x7c, 0xf8, 0xdf, 0x00, 0x01, 0x80, 0x00, 0x07, 0xf8, 0x1e, 0x07, 0xc1, 0xe0, 0x00, 0x00, 0x01, 0xf4, 0x65, 0x9d, 0x00, 0x01, 0x80, 0x00, 0x07, 0xf8, 0x1f, 0x07, 0x81, 0xe0, 0x00, 0x00, 0x03, 0xcc, 0x09, 0xb9, 0x80, 0x01, 0x80, 0x00, 0x07, 0xf8, 0x0f, 0x0f, 0x81, 0xe0, 0x00, 0x00, 0x00, 0x3c, 0x1b, 0x38, 0x80, 0x01, 0x80, 0x00, 0x0f, 0xfc, 0x0f, 0x8f, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x13, 0x30, 0x80, 0x01, 0x80, 0x00, 0x0f, 0x3c, 0x07, 0x9f, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x1b, 0xb8, 0x80, 0x01, 0x80, 0x00, 0x1f, 0x3e, 0x07, 0x9e, 0x01, 0xe0, 0x00, 0x00, 0x03, 0xfe, 0x09, 0xb9, 0x80, 0x01, 0x80, 0x00, 0x1e, 0x1e, 0x07, 0xde, 0x01, 0xe0, 0x00, 0x00, 0x09, 0xf6, 0x64, 0xdd, 0x00, 0x01, 0x80, 0x00, 0x3f, 0xff, 0x03, 0xfe, 0x01, 0xe0, 0x00, 0x00, 0x3f, 0x7e, 0xf8, 0x1f, 0x00, 0x01, 0x80, 0x00, 0x3f, 0xff, 0x03, 0xfc, 0x01, 0xe0, 0x00, 0x00, 0x7f, 0xbe, 0xa8, 0x0e, 0x00, 0x01, 0x80, 0x00, 0x3f, 0xff, 0x81, 0xfc, 0x01, 0xe0, 0x00, 0x00, 0x67, 0xd5, 0xf8, 0x00, 0x00, 0x01, 0x80, 0x00, 0x7f, 0xff, 0x81, 0xf8, 0x01, 0xe0, 0x00, 0x00, 0x61, 0xd0, 0xfe, 0x00, 0x00, 0x01, 0x80, 0x00, 0x78, 0x07, 0x80, 0xf8, 0x01, 0xe0, 0x00, 0x00, 0x21, 0xd0, 0xc0, 0x00, 0x00, 0x01, 0x80, 0x00, 0xf8, 0x03, 0xc0, 0xf8, 0x01, 0xff, 0xfc, 0x00, 0x31, 0xc0, 0xbf, 0x00, 0x00, 0x01, 0x80, 0x00, 0xf0, 0x03, 0xc0, 0xf0, 0x01, 0xff, 0xfc, 0x00, 0x19, 0xc1, 0x7f, 0x80, 0x00, 0x01, 0x80, 0x01, 0xf0, 0x03, 0xe0, 0x70, 0x01, 0xff, 0xfc, 0x00, 0x0f, 0x80, 0xf3, 0xc0, 0x00, 0x01, 0x80, 0x01, 0xf0, 0x01, 0xe0, 0x60, 0x01, 0xff, 0xfc, 0x00, 0x07, 0x01, 0xe0, 0xc0, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc1, 0x80, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; `

olikraus commented 1 year ago

Ok, I stopped reading after the first view lines: do no use old u8g lib and u8x8 together. Use u8g2 only. U8g2 includes u8x8 (Use u8g2.getU8x8)

Beppi4U commented 1 year ago

Mixing up libs is never a good idea. Thanx for help! Gonna try u8g2 out.