Multiple displays Oled with u8g2 Library

allacmc
Posts: 6
Joined: Fri Nov 24, 2023 4:32 pm

Multiple displays Oled with u8g2 Library

Postby allacmc » Mon Apr 08, 2024 1:21 am

I am using a library called u8g2 to display the data on the i2c oled display.

This library "Originally made for Arduino" I can make it work with a port made by a colleague.

And it works perfectly.

I have a 16 channel multiplexer and everything is mounted on the breadboard. Working perfectly.

https://github.com/mkfrey/u8g2-hal-esp-idf

I use this library below to port and it works perfectly.
  1. #include <u8g2.h>
  2. #include "sdkconfig.h"
  3. #include "u8g2_esp32_hal.h"
  4.  
  5. #define PIN_SDA 21
  6. #define PIN_SCL 22
  7.  
  8. u8g2_t u8g2;
  9. u8g2_t u8g2_1;
  10.  
  11. void f_setupI2c(){
  12.  
  13.     selectChannel(1);//Select Display 2
  14.         u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT;
  15.         u8g2_esp32_hal.bus.i2c.sda = PIN_SDA;
  16.         u8g2_esp32_hal.bus.i2c.scl = PIN_SCL;
  17.         u8g2_esp32_hal_init(u8g2_esp32_hal);
  18.  
  19.         u8g2_Setup_sh1106_i2c_128x64_noname_f(&u8g2, U8G2_R0,u8g2_esp32_i2c_byte_cb,u8g2_esp32_gpio_and_delay_cb);
  20.         u8x8_SetI2CAddress(&u8g2.u8x8, 0x78);
  21.         u8g2_InitDisplay(&u8g2);
  22.         u8g2_SetPowerSave(&u8g2, 0);
  23.         u8g2_ClearBuffer(&u8g2);
  24.         u8g2_SetFont(&u8g2, u8g2_font_ncenB10_tr);
  25.         u8g2_DrawStr(&u8g2, 0, 17, "ENERVISION");
  26.         u8g2_SendBuffer(&u8g2);
  27.    
  28.     selectChannel(3); //Select Display 3
  29.         /*
  30.         u8g2_Setup_sh1106_i2c_128x64_noname_f(&u8g2_1, U8G2_R0,u8g2_esp32_i2c_byte_cb,u8g2_esp32_gpio_and_delay_cb);
  31.         u8x8_SetI2CAddress(&u8g2_1.u8x8, 0x78);
  32.         u8g2_InitDisplay(&u8g2_1);
  33.         u8g2_SetPowerSave(&u8g2_1, 0);
  34.         u8g2_ClearBuffer(&u8g2_1);
  35.         u8g2_SetFont(&u8g2_1, u8g2_font_ncenB10_tr);
  36.         u8g2_DrawStr(&u8g2_1, 0, 17, "ENERVISION");
  37.         u8g2_SendBuffer(&u8g2_1);
  38.         */
  39.  
  40. }
However, when I repeat the code to create a new u8g2 object, it gives an error during execution.

I'm lost on how to solve this problem, which way to go. He knows

Where am I going wrong?
  1. I (872) wifi_init: tcp tx win: 5760
  2. I (872) wifi_init: tcp rx win: 5760
  3. I (872) wifi_init: tcp mss: 1440
  4. I (882) wifi_init: WiFi IRAM OP enabled
  5. I (882) wifi_init: WiFi RX IRAM OP enabled
  6. I (892) phy_init: phy_version 4791,2c4672b,Dec 20 2023,16:06:06
  7. I (982) wifi:mode : sta (08:d1:f9:e1:06:60)
  8. I (982) wifi:enable tsf
  9. I (992) INFO: Wifi-Conectando...
  10. I (1002) wifi:new:<11,0>, old:<1,0>, ap:<255,255>, sta:<11,0>, prof:1
  11. I (1002) wifi:state: init -> auth (b0)
  12. I (1012) wifi:state: auth -> assoc (0)
  13. W (1012) Multiplexer: Canal 1 - (1 0 0 0)
  14. I (1012) u8g2_hal: sda_io_num 21
  15. I (1012) wifi:state: assoc -> run (10)
  16. I (1012) u8g2_hal: scl_io_num 22
  17. I (1022) u8g2_hal: clk_speed 50000
  18. I (1022) u8g2_hal: i2c_param_config 1
  19. I (1032) u8g2_hal: i2c_driver_install 1
  20. I (1252) wifi:<ba-add>idx:0 (ifx:0, 38:6b:1c:01:ea:a8), tid:0, ssn:462, winSize:64
  21. I (1262) wifi:connected with WifiStudio, aid = 7, channel 11, BW20, bssid = 38:6b:1c:01:ea:a8
  22. I (1262) wifi:security: WPA2-PSK, phy: bgn, rssi: -54
  23. I (1272) wifi:pm start, type: 1
  24.  
  25. I (1272) wifi:dp: 1, bi: 102400, li: 3, scale listen interval from 307200 us to 307200 us
  26. I (1282) INFO: Wifi-Conectado
  27. I (1342) wifi:AP's beacon interval = 102400 us, DTIM period = 1
  28. W (1342) wifi:[ADDBA]rx delba, code:39, delete tid:0
  29. I (1342) wifi:<ba-del>idx:0, tid:0
  30. W (1602) Multiplexer: Canal 3 - (1 1 0 0)
  31. I (1602) u8g2_hal: sda_io_num 21
  32. I (1602) u8g2_hal: scl_io_num 22
  33. I (1602) u8g2_hal: clk_speed 50000
  34. I (1602) u8g2_hal: i2c_param_config 1
  35. I (1612) u8g2_hal: i2c_driver_install 1
  36. E (1612) i2c: i2c driver install error
  37. E (1612) err: esp_err_t = -1
  38.  
  39. assert failed: u8g2_esp32_i2c_byte_cb u8g2_esp32_hal.c:148 (0 && "i2c_driver_install(I2C_MASTER_NUM, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0)")
  40.  
  41.  
  42. Backtrace: 0x40081bae:0x3ffba780 0x4008a471:0x3ffba7a0 0x40092795:0x3ffba7c0 0x400db513:0x3ffba8e0 0x400db129:0x3ffba920 0x400db177:0x3ffba940 0x400db321:0x3ffba960 0x401661ed:0x3ffba980 0x400d92e9:0x3ffba9a0 0x400d8850:0x3ffba9e0 0x4016d47b:0x3ffbaa80 0x4008afe9:0x3ffbaab0
  43. 0x40081bae: panic_abort at /home/allan/esp32/esp-idf/components/esp_system/panic.c:469
  44. 0x4008a471: esp_system_abort at /home/allan/esp32/esp-idf/components/esp_system/port/esp_system_chip.c:92
  45. 0x40092795: __assert_func at /home/allan/esp32/esp-idf/components/newlib/assert.c:81
  46. 0x400db513: u8g2_esp32_i2c_byte_cb at /home/allan/Codigos/EnervisionMegaDash/components/u8g2-hal-esp-idf/src/u8g2_esp32_hal.c:148 (discriminator 17)
  47. 0x400db129: u8x8_cad_ssd13xx_fast_i2c at /home/allan/Codigos/EnervisionMegaDash/components/u8g2/csrc/u8x8_cad.c:592
  48. 0x400db177: u8x8_d_helper_display_init at /home/allan/Codigos/EnervisionMegaDash/components/u8g2/csrc/u8x8_display.c:68
  49. 0x400db321: u8x8_d_sh1106_128x64_noname at /home/allan/Codigos/EnervisionMegaDash/components/u8g2/csrc/u8x8_d_ssd1306_128x64_noname.c:487
  50. 0x401661ed: u8x8_InitDisplay at /home/allan/Codigos/EnervisionMegaDash/components/u8g2/csrc/u8x8_display.c:137
  51. 0x400d92e9: f_setupI2c at /home/allan/Codigos/EnervisionMegaDash/main/f_display.c:44
  52. 0x400d8850: app_main at /home/allan/Codigos/EnervisionMegaDash/main/main.c:40
  53. 0x4016d47b: main_task at /home/allan/esp32/esp-idf/components/freertos/app_startup.c:208
  54. 0x4008afe9: vPortTaskWrapper at /home/allan/esp32/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:134
  55.  
  56.  
  57.  
  58.  
  59.  
  60. ELF file SHA256: 757a52547
  61.  
  62. Rebooting...
  63. ets Jul 29 2019 12:21:46
  64.  
  65. rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
  66. configsip: 0, SPIWP:0xee
  67. clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
  68. mode:DIO, clock div:2
  69. load:0x3fff0030,len:7172
  70. load:0x40078000,len:15556
  71. load:0x40080400,len:4
  72. 0x40080400: _init at ??:?
  73.  
  74. ho 8 tail 4 room 4
  75. load:0x40080404,len:3904
  76. entry 0x40080640
  77. I (31) boot: ESP-IDF v5.3-dev-1922-g5454d37d49 2nd stage bootloader
  78. I (31) boot: compile time Apr  6 2024 17:06:50
  79. I (33) boot: Multicore bootloader
  80. I (37) boot: chip revision: v3.1
  81. I (41) boot.esp32: SPI Speed      : 40MHz
  82. I (45) boot.esp32: SPI Mode       : DIO
  83. I (50) boot.esp32: SPI Flash Size : 4MB
  84. I (54) boot: Enabling RNG early entropy source...
  85. I (60) boot: Partition Table:
  86. I (63) boot: ## Label            Usage          Type ST Offset   Length
  87. I (71) boot:  0 nvs              WiFi data        01 02 00009000 00010000
  88. I (78) boot:  1 phy_init         RF data          01 01 00019000 00010000
  89. I (86) boot:  2 factory          factory app      00 00 00030000 00100000
  90. I (93) boot:  3 storage          Unknown data     01 82 00130000 00100000
  91. I (101) boot: End of partition table
Allan Caldas - Enervision Telemetria

liaifat85
Posts: 200
Joined: Wed Dec 06, 2023 2:46 pm

Re: Multiple displays Oled with u8g2 Library

Postby liaifat85 » Mon Apr 08, 2024 7:57 am

Here is a thread on this error message. You can check this out: https://esp32.com/viewtopic.php?t=10995

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Multiple displays Oled with u8g2 Library

Postby MicroController » Mon Apr 08, 2024 8:34 am

Where am I going wrong?
Nowhere, apparently. That "esp32-hal" doesn't seem to support multiple displays; notably, it will attempt to install the I2C driver for each display again which fails on the second instance.
A hacky work-around could be to provide your own version of u8g2_esp32_i2c_byte_cb() for all but the first display which just returns 0 if msg==U8X8_MSG_BYTE_INIT, else calls the original u8g2_esp32_i2c_byte_cb().

allacmc
Posts: 6
Joined: Fri Nov 24, 2023 4:32 pm

Re: Multiple displays Oled with u8g2 Library

Postby allacmc » Wed Apr 10, 2024 3:07 am

I solved, thanks:
  1.  
  2. #include <u8g2.h>
  3. #include "sdkconfig.h"
  4. #include "u8g2_esp32_hal.h"
  5.  
  6. #define PIN_SDA 21
  7. #define PIN_SCL 22
  8.  
  9. u8g2_t u8g2;
  10. u8g2_t u8g2_1;
  11. u8g2_t u8g2_2;
  12. u8g2_t u8g2_3;
  13. u8g2_t u8g2_4;
  14.  
  15. void f_setupDisplay() {
  16.         selectChannel(0);
  17.         u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT;
  18.         u8g2_esp32_hal.bus.i2c.sda = PIN_SDA;
  19.         u8g2_esp32_hal.bus.i2c.scl = PIN_SCL;
  20.         u8g2_esp32_hal_init(u8g2_esp32_hal);
  21.         for(int i=0;i<5;i++){
  22.             selectChannel(i);
  23.             u8g2_Setup_sh1106_i2c_128x64_noname_f(&u8g2, U8G2_R0,u8g2_esp32_i2c_byte_cb,u8g2_esp32_gpio_and_delay_cb);
  24.             u8x8_SetI2CAddress(&u8g2.u8x8, 0x78);
  25.             if(i==0){
  26.                 u8g2_InitDisplay(&u8g2);
  27.             }else{
  28.                 u8g2_SetDisplayRotation(&u8g2, U8G2_R2);
  29.             }
  30.             u8g2_SetPowerSave(&u8g2, 0);
  31.             u8g2_ClearBuffer(&u8g2);
  32.             u8g2_SetFont(&u8g2, u8g2_font_ncenB12_tr);
  33.             u8g2_DrawStr(&u8g2, 6, 40, "ENERVISION");
  34.             u8g2_SendBuffer(&u8g2);
  35.         }
  36.         vTaskDelay(pdMS_TO_TICKS(2000));
  37. }
Allan Caldas - Enervision Telemetria

Who is online

Users browsing this forum: YaCy [Bot] and 118 guests