Adafruit 14 Segment LED Backpack for esp-idf

Hello guys, I know my post is a bit out of place because I have now switched to platformIO via ArduinoIDE in my Odysee and now want to code pure ESP-IDF in vscode. My project was also very advanced with PlatformIO, but the Arduino meant that at a certain point it was just chaos, so I got rid of the convenience. I have had good experiences with the Adafruit Led Backpack but now I am faced with the problem that esp-idf is difficult due to the documentation. I have registered my displays in the I2C bus and they are listening but now I am faced with the problem to send these corresponding commands and the examples are not very helpful. Basically I’m just begging for a good idea or a library that will bring me back to the level of comfort I had with this… or maybe good tips (help) on how I can implement the project and control the displays accordingly. THE MAIN PROBLEM is also because esp-idf has 2 outdated i2c libraries… one that is still up to date but poorly documented with examples and one that is somehow 5.2 dev, which I have little plan for and don’t even need as long as it is i2c.h would currently do. I’m also happy to post code. But basically it’s enough to say that I have initialized an I2C master port and initialized the devices… now I would just have to address them and send the bytes accordingly… but I’m a bit stuck. What I’ll try next is to adapt the Adafruit library for my purposes… or recapitulate the code. Best regards

ESP-IDF i2c Adafruit 0.54" Alphanumeric Backpack

Postby Checky » Thu Nov 23, 2023 11:16 am

Hello, I would like to get this display to work, but somehow there are only poor documentation examples and a confusing array of libraries. This wasn’t a problem at all under Arduni with the Adafruit LED Backpack Library, but somehow you don’t get such pretty things that make your life easy for esp-idf orre, at least not that I know of.
So I went here and tried, on the one hand, to get the interface for the IC2 to work and to make the Adafruit library C suitable, at least the part that I need.

My main problem is that I can’t seem to get the oscillator to work and the displays just stay off.

SO I WOULD BE VERY HAPPY IF SOMEONE COULD HELP ME FURTHER.

CODE: [SELECT ALL] [EXPAND/COLLAPSE]

  1. main.c VZ_Seg_setDisplay(&VZ_DISP_1, “ABCD”);

  2. VZ_Seg_setDisplay(&VZ_DISP_2, “1234”);

  3. VZ_Seg_setDisplay(&VZ_DISP_3, “BLUB”);

GeSHi © Codebox Plus Extension

CODE: [SELECT ALL] [EXPAND/COLLAPSE]

  1. I2Ccon.c //###############################################################################################################################

  2. // Unsere I2Ccon.c für die Initialisierung I2C Geräte und dem Master auf dem I2C-Bus unser Wrover-Kit

  3. //###############################################################################################################################

  • #include “…/include/I2Ccon.h”

  • //###############################################################################################################################

  • #define CHECK_ARG(ARG) do { if (!ARG) return ESP_ERR_INVALID_ARG; } while (0)

  • //###############################################################################################################################

  • // Master-Config

  1. // #define CONFIG_SCL_GPIO 0 // Definieren wiir über ide menuconfig

  2. // #define CONFIG_SDA_GPIO 2

  3. #define I2C_MASTER_PORT I2C_NUM_0 // Standartport

  4. #define I2C_MASTER_TX_BUF_ENABLE 0

  5. #define I2C_MASTER_RX_BUF_ENABLE 0

  6. #define I2C_MASTER_FREQ_HZ 100000 // Taktfrequenz

  • // Geräte im Bus und ihre Adressen
  1. #define BTTF_RTC_ADDR 0x68 //*!< RTC device address */

  2. #define VZ_DISP_1_ADDR 0x70 //*!< HT16K33 device address 1 */

  3. #define VZ_DISP_2_ADDR 0x71 //*!< HT16K33 device address 2 */

  4. #define VZ_DISP_3_ADDR 0x72 //*!< HT16K33 device address 3 */

  • // Flag, um den I2C-Master-Status zu überprüfen
  1. static bool i2c_master_initialized = false;
  • i2c_dev_t BTTF_RTC, VZ_DISP_1, VZ_DISP_2, VZ_DISP_3;

  • // I2C //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  1. //###############################################################################################################################
  • // Zuerst initialisiern wir den Master für den I2C-Bus (in unserem Fall das Wrover-Kit)
  1. esp_err_t BTTF_i2c_master_init(i2c_port_t port, int sda, int scl)

  2. {

  3. // Nur initialisieren, wenn noch nicht geschehen

  4. if (!i2c_master_initialized) {

  5. uint8_t i2c_master_port = I2C_MASTER_PORT;

  • i2c_config_t conf = {
  1. .mode = I2C_MODE_MASTER,

  2. .sda_io_num = CONFIG_SDA_GPIO,

  3. .scl_io_num = CONFIG_SCL_GPIO,

  4. .sda_pullup_en = GPIO_PULLUP_ENABLE,

  5. .scl_pullup_en = GPIO_PULLUP_ENABLE,

  6. .master.clk_speed = I2C_MASTER_FREQ_HZ,

  7. };

  • esp_err_t i2c_init_result = i2c_param_config(i2c_master_port, &conf);
  1. ESP_ERROR_CHECK(i2c_init_result);
  • i2c_init_result = i2c_driver_install(
  1. i2c_master_port,

  2. conf.mode,

  3. I2C_MASTER_RX_BUF_ENABLE,

  4. I2C_MASTER_TX_BUF_ENABLE,

  5. 0

  6. );

  7. if (i2c_init_result != ESP_OK) {

  8. ESP_LOGE(TAG, “Fehler bei der Installation des I2C-Treibers: %d”, i2c_init_result);

  9. const char *driver_err_msg = esp_err_to_name(i2c_init_result);

  10. ESP_LOGE(TAG, “I2C-Treiberfehlermeldung: %s”, driver_err_msg);

  11. } else {

  12. ESP_LOGI(TAG, “I2C-Master initialisiert”);

  13. i2c_master_initialized = true; // Setze das Flag, dass der I2C-Master initialisiert wurde

  14. I2C_Scan(); // DEBUG-Funktion Scannt den I2C Bus auf vorhandene Geräte

  15. }

  • return i2c_init_result; // Hier wird der Rückgabewert übergeben
  1. }

  2. // Falls bereits initialisiert, gebe ESP_OK zurück

  3. return ESP_OK;

  4. }

  • // DEBUG: Hilfsfunktion um den IC2 Bus auf Geräte zu scannen
  1. static esp_err_t check_adress_for_device(uint8_t device_address)

  2. {

  3. uint8_t write_buf[2] = {0, 0};

  • return i2c_master_write_to_device(I2C_NUM_0, device_address, write_buf, sizeof(write_buf), 10 / portTICK_PERIOD_MS);
  1. }
  • // DEBUG: I2C Bus auf Geräte scannen // Gibt und Anzahl und Adressen von angeschlossenen I2C-Geräten
  1. void I2C_Scan() {

  2. size_t devicesDiscovered = 0;

  3. for (size_t address = 1; address < 127; address++) {

  4. if (ESP_OK == check_adress_for_device(address)) {

  5. ESP_LOGI(TAG, “Found device at address 0x%X”, address);

  6. devicesDiscovered++;

  7. }

  8. }

  9. if (devicesDiscovered == 1){

  10. ESP_LOGI(TAG, “Found %d device\n”, (int)devicesDiscovered);

  11. } else if (devicesDiscovered > 1) {

  12. ESP_LOGI(TAG, “Found %d devices\n”, (int)devicesDiscovered);

  13. } else {

  14. ESP_LOGI(TAG, “No devices found\n”);

  15. }

  16. vTaskDelay(pdMS_TO_TICKS(50));

  17. }

  • void Init_I2C_Devices() {

  • // Initialisiere die RTC

  1. if (ds3231_init_desc(&BTTF_RTC, I2C_NUM_0, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO) != ESP_OK) {

  2. ESP_LOGE(TAG, “RTC: Konnte Gerätebeschreibung nicht initialisieren.”);

  3. while (1) { vTaskDelay(100); }

  4. } else {

  5. ESP_LOGI(TAG, “RTC erfolgreich initialisiert”);

  6. }

  • // Initialisiere das VZ1-Display
  1. if (VZ1_init_desc(&VZ_DISP_1, I2C_NUM_0, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO) != ESP_OK) {

  2. ESP_LOGE(TAG, “VZ_DISP_1: Konnte Gerätebeschreibung nicht initialisieren.”);

  3. ESP_LOGE(TAG, “I2C-Treiberfehlermeldung: %s”, esp_err_to_name(i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0)));

  4. while (1) { vTaskDelay(100); }

  5. } else {

  6. ESP_LOGI(TAG, “VZ_DISP_1 initialisiert”);

  7. }

  • // Initialisiere das VZ2-Display
  1. if (VZ2_init_desc(&VZ_DISP_2, I2C_NUM_0, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO) != ESP_OK) {

  2. ESP_LOGE(TAG, “VZ_DISP_2: Konnte Gerätebeschreibung nicht initialisieren.”);

  3. ESP_LOGE(TAG, “I2C-Treiberfehlermeldung: %s”, esp_err_to_name(i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0)));

  4. while (1) { vTaskDelay(100); }

  5. } else {

  6. ESP_LOGI(TAG, “VZ_DISP_2 initialisiert”);

  7. }

  • // Initialisiere das VZ3-Display
  1. if (VZ3_init_desc(&VZ_DISP_3, I2C_NUM_0, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO) != ESP_OK) {

  2. ESP_LOGE(TAG, “VZ_DISP_3: Konnte Gerätebeschreibung nicht initialisieren.”);

  3. ESP_LOGE(TAG, “I2C-Treiberfehlermeldung: %s”, esp_err_to_name(i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0)));

  4. while (1) { vTaskDelay(100); }

  5. } else {

  6. ESP_LOGI(TAG, “VZ_DISP_3 initialisiert”);

  7. }

  8. if (VZ_Seg_begin(&VZ_DISP_1) &&

  9. VZ_Seg_begin(&VZ_DISP_2) &&

  10. VZ_Seg_begin(&VZ_DISP_3)) {

  11. ESP_LOGI(TAG, “Alle Displays erfolgreich initialisiert”);

  12. } else {

  13. ESP_LOGE(TAG, “Fehler bei der Initialisierung der Displays”);

  14. }

  15. }

  • // Funktion zur Initialisierung der RTC
  1. esp_err_t ds3231_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

  2. {

  3. CHECK_ARG(dev);

  • dev->port = port;
  1. dev->addr = BTTF_RTC_ADDR; // Verwende die Adresse für die RTC

  2. dev->sda_io_num = sda_gpio;

  3. dev->scl_io_num = scl_gpio;

  4. dev->clk_speed = I2C_MASTER_FREQ_HZ;

  5. return BTTF_i2c_master_init(port, sda_gpio, scl_gpio);

  6. }

  • // Funktion zur Initialisierung des VZ1-Displays
  1. esp_err_t VZ1_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

  2. {

  3. CHECK_ARG(dev);

  • dev->port = port;
  1. dev->addr = VZ_DISP_1_ADDR;

  2. dev->sda_io_num = sda_gpio;

  3. dev->scl_io_num = scl_gpio;

  4. dev->clk_speed = I2C_MASTER_FREQ_HZ;

  5. return BTTF_i2c_master_init(port, sda_gpio, scl_gpio);

  6. }

  • // Funktion zur Initialisierung des VZ2-Displays

  • esp_err_t VZ2_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

  1. {

  2. CHECK_ARG(dev);

  • dev->port = port;
  1. dev->addr = VZ_DISP_2_ADDR;

  2. dev->sda_io_num = sda_gpio;

  3. dev->scl_io_num = scl_gpio;

  4. dev->clk_speed = I2C_MASTER_FREQ_HZ;

  5. return BTTF_i2c_master_init(port, sda_gpio, scl_gpio);

  6. }

  • // Funktion zur Initialisierung des VZ1-Displays

  • esp_err_t VZ3_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

  1. {

  2. CHECK_ARG(dev);

  • dev->port = port;
  1. dev->addr = VZ_DISP_3_ADDR;

  2. dev->sda_io_num = sda_gpio;

  3. dev->scl_io_num = scl_gpio;

  4. dev->clk_speed = I2C_MASTER_FREQ_HZ;

  5. return BTTF_i2c_master_init(port, sda_gpio, scl_gpio);

  6. }

  • //###############################################################################################################################

GeSHi © Codebox Plus Extension

CODE: [SELECT ALL] [EXPAND/COLLAPSE]

  1. I2Ccon.h //###############################################################################################################################

  2. // Unsere Headerdatei für die Init.c

  3. //###############################################################################################################################

  • #ifndef I2CCON_H
  1. #define I2CCON_H
  • //###############################################################################################################################

  • #include “Include.h” // Header-Datei für alle Includes

  • extern i2c_dev_t BTTF_RTC, VZ_DISP_1, VZ_DISP_2, VZ_DISP_3; // Geräte-Handels (Objekte) RTC und die 3x ht16k33 14-Seg

  • //FUNKTIONSDEKLARATIONEN/////////////////////////////////////////////////////////////////////////////////////////////////////////

  • esp_err_t ds3231_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio);

  1. esp_err_t VZ1_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio);

  2. esp_err_t VZ2_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio);

  3. esp_err_t VZ3_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio);

  • esp_err_t BTTF_i2c_master_init(i2c_port_t port, int sda, int scl);

  • void I2C_Scan();

  1. extern void Init_I2C_Devices();
  • //###############################################################################################################################
  1. #endif

GeSHi © Codebox Plus Extension

CODE: [SELECT ALL] [EXPAND/COLLAPSE]

  1. VZ_seg.c //###############################################################################################################################

  2. // Unsere VZ_seg.c für die Vierzehn-Segmentanzeigen die durch HT16K33 gesteuert werden

  3. //###############################################################################################################################

  • #include “…/include/VZ_seg.h”

  • //###############################################################################################################################

  • // DEKLARATIONEN

  • const uint16_t alphafonttable[] = {

  • 0b0000000000000001, 0b0000000000000010, 0b0000000000000100,

  1. 0b0000000000001000, 0b0000000000010000, 0b0000000000100000,

  2. 0b0000000001000000, 0b0000000010000000, 0b0000000100000000,

  3. 0b0000001000000000, 0b0000010000000000, 0b0000100000000000,

  4. 0b0001000000000000, 0b0010000000000000, 0b0100000000000000,

  5. 0b1000000000000000, 0b0000000000000000, 0b0000000000000000,

  6. 0b0000000000000000, 0b0000000000000000, 0b0000000000000000,

  7. 0b0000000000000000, 0b0000000000000000, 0b0000000000000000,

  8. 0b0001001011001001, 0b0001010111000000, 0b0001001011111001,

  9. 0b0000000011100011, 0b0000010100110000, 0b0001001011001000,

  10. 0b0011101000000000, 0b0001011100000000,

  11. 0b0000000000000000, //

  12. 0b0000000000000110, // !

  13. 0b0000001000100000, // "

  14. 0b0001001011001110, // #

  15. 0b0001001011101101, // $

  16. 0b0000110000100100, // %

  17. 0b0010001101011101, // &

  18. 0b0000010000000000, // ’

  19. 0b0010010000000000, // (

  20. 0b0000100100000000, // )

  21. 0b0011111111000000, // *

  22. 0b0001001011000000, // +

  23. 0b0000100000000000, // ,

  24. 0b0000000011000000, // -

  25. 0b0100000000000000, // .

  26. 0b0000110000000000, // /

  27. 0b0000110000111111, // 0

  28. 0b0000000000000110, // 1

  29. 0b0000000011011011, // 2

  30. 0b0000000010001111, // 3

  31. 0b0000000011100110, // 4

  32. 0b0010000001101001, // 5

  33. 0b0000000011111101, // 6

  34. 0b0000000000000111, // 7

  35. 0b0000000011111111, // 8

  36. 0b0000000011101111, // 9

  37. 0b0001001000000000, // :

  38. 0b0000101000000000, // ;

  39. 0b0010010000000000, // <

  40. 0b0000000011001000, // =

  41. 0b0000100100000000, // >

  42. 0b0001000010000011, // ?

  43. 0b0000001010111011, // @

  44. 0b0000000011110111, // A

  45. 0b0001001010001111, // B

  46. 0b0000000000111001, // C

  47. 0b0001001000001111, // D

  48. 0b0000000011111001, // E

  49. 0b0000000001110001, // F

  50. 0b0000000010111101, // G

  51. 0b0000000011110110, // H

  52. 0b0001001000001001, // I

  53. 0b0000000000011110, // J

  54. 0b0010010001110000, // K

  55. 0b0000000000111000, // L

  56. 0b0000010100110110, // M

  57. 0b0010000100110110, // N

  58. 0b0000000000111111, // O

  59. 0b0000000011110011, // P

  60. 0b0010000000111111, // Q

  61. 0b0010000011110011, // R

  62. 0b0000000011101101, // S

  63. 0b0001001000000001, // T

  64. 0b0000000000111110, // U

  65. 0b0000110000110000, // V

  66. 0b0010100000110110, // W

  67. 0b0010110100000000, // X

  68. 0b0001010100000000, // Y

  69. 0b0000110000001001, // Z

  70. 0b0000000000111001, // [

  71. 0b0010000100000000, //

  72. 0b0000000000001111, // ]

  73. 0b0000110000000011, // ^

  74. 0b0000000000001000, // _

  75. 0b0000000100000000, // `

  76. 0b0001000001011000, // a

  77. 0b0010000001111000, // b

  78. 0b0000000011011000, // c

  79. 0b0000100010001110, // d

  80. 0b0000100001011000, // e

  81. 0b0000000001110001, // f

  82. 0b0000010010001110, // g

  83. 0b0001000001110000, // h

  84. 0b0001000000000000, // i

  85. 0b0000000000001110, // j

  86. 0b0011011000000000, // k

  87. 0b0000000000110000, // l

  88. 0b0001000011010100, // m

  89. 0b0001000001010000, // n

  90. 0b0000000011011100, // o

  91. 0b0000000101110000, // p

  92. 0b0000010010000110, // q

  93. 0b0000000001010000, // r

  94. 0b0010000010001000, // s

  95. 0b0000000001111000, // t

  96. 0b0000000000011100, // u

  97. 0b0010000000000100, // v

  98. 0b0010100000010100, // w

  99. 0b0010100011000000, // x

  100. 0b0010000000001100, // y

  101. 0b0000100001001000, // z

  102. 0b0000100101001001, // {

  103. 0b0001001000000000, // |

  104. 0b0010010010001001, // }

  105. 0b0000010100100000, // ~

  106. 0b0011111111111111,

  • };

  • uint16_t displaybuffer[8];

  1. uint8_t buffer[17]= {0}; // Initialisiert alle Elemente mit 0;
  • // VZ-SEG ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1. //###############################################################################################################################
  • void VZ_Seg_writeDigitRaw( uint8_t n, uint16_t bitmask) {
  1. displaybuffer[n] = bitmask;

  2. }

  • void VZ_Seg_writeDigitAscii(i2c_dev_t *display, uint8_t n, uint8_t ascii, bool d) {
  1. uint16_t font = alphafonttable[ascii];
  • displaybuffer[n] = font;

  • if (d)

  1. displaybuffer[n] |= (1 << 14);

  2. }

  • void VZ_Seg_setBrightness(i2c_dev_t *display, uint8_t b) {
  1. if (b > 15)

  2. b = 15; // limit to max brightness

  • uint8_t buffer = HT16K33_CMD_BRIGHTNESS | b;
  1. i2c_dev_write(display, NULL, 0, &buffer, sizeof(uint8_t));

  2. }

  • void VZ_Seg_blinkRate(i2c_dev_t *display, uint8_t b) {
  1. if (b > 3)

  2. b = 0; // turn off if not sure

  • uint8_t buffer = HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (b << 1);

  • // Verwende das i2c_dev_t-Objekt des Displays, um Daten zu schreiben

  1. i2c_dev_write(display, NULL, 0, &buffer, sizeof(uint8_t));

  2. }

  • bool VZ_Seg_begin(i2c_dev_t *display) {
  1. ESP_LOGI(TAG, “beginn”);

  2. VZ_Seg_clear(display);

  3. // turn on oscillator

  4. uint8_t buffer[1] = {0x21};

  5. i2c_dev_write(display, NULL, 0, &buffer, sizeof(uint8_t));

  • VZ_Seg_setBrightness(display, 15);
  1. VZ_Seg_writeDisplay(display);

  2. return true; // oder false je nach Erfolg oder Misserfolg der Initialisierung

  3. }

  • void VZ_Seg_writeDisplay(i2c_dev_t *display) {

  • buffer[0] = 0x00; // start at address $00

  • for (uint8_t i = 0; i < 8; i++) {

  1. buffer[1 + 2 * i] = displaybuffer[i] & 0xFF;

  2. buffer[2 + 2 * i] = displaybuffer[i] >> 8;

  3. }

  • ESP_LOGI(TAG, “writeDisplay”);
  1. ESP_LOGI(TAG, “Buffer values: %02x %02x %02x %02x %02x %02x %02x %02x”,

  2. buffer[1], buffer[2], buffer[3], buffer[4],

  3. buffer[5], buffer[6], buffer[7], buffer[8]);

  • i2c_dev_write(display, NULL, 0, &buffer, sizeof(uint8_t));
  1. }
  • void VZ_Seg_clear(i2c_dev_t *display) {
  1. for (uint8_t i = 0; i < 8; i++) {

  2. displaybuffer[i] = 0;

  3. }

  4. }

  • void VZ_Seg_setDisplay(i2c_dev_t *display, const char *text) {
  1. VZ_Seg_clear(display);
  • for (uint8_t i = 0; i < strlen(text); i++) {
  1. VZ_Seg_writeDigitAscii(display, i, text[i], false);

  2. }

  • VZ_Seg_writeDisplay(display);
  1. }

GeSHi © Codebox Plus Extension

CODE: [SELECT ALL] [EXPAND/COLLAPSE]

  1. VZ_seg.h

  2. -------A-------

  3. |\ | /|

  4. | \ J / |

  5. | H | K |

  6. F \ | / B

  7. | |/ |

  8. |–G1–|–G2–|

  9. | /|\ |

  10. E / | \ C

  11. | L | N |

  12. | / M \ |

  13. |/ | |

  14. -------D------- DP

  15. */

  • // DEFINITIONEN /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  • extern uint16_t displaybuffer[8];

  • #define LED_ON 1 ///< GFX color of lit LED segments (single-color displays)

  1. #define LED_OFF 0 ///< GFX color of unlit LED segments (single-color displays)
  • #define HT16K33_BLINK_CMD 0x80 ///< I2C register for BLINK setting
  1. #define HT16K33_BLINK_DISPLAYON 0x01 ///< I2C value for steady on

  2. #define HT16K33_BLINK_OFF 0 ///< I2C value for steady off

  3. #define HT16K33_BLINK_2HZ 1 ///< I2C value for 2 Hz blink

  4. #define HT16K33_BLINK_1HZ 2 ///< I2C value for 1 Hz blink

  5. #define HT16K33_BLINK_HALFHZ 3 ///< I2C value for 0.5 Hz blink

  • #define HT16K33_CMD_BRIGHTNESS 0xE0 ///< I2C register for BRIGHTNESS setting

  • #define ALPHANUM_SEG_A 0b0000000000000001 ///< Alphanumeric segment A

  1. #define ALPHANUM_SEG_B 0b0000000000000010 ///< Alphanumeric segment B

  2. #define ALPHANUM_SEG_C 0b0000000000000100 ///< Alphanumeric segment C

  3. #define ALPHANUM_SEG_D 0b0000000000001000 ///< Alphanumeric segment D

  4. #define ALPHANUM_SEG_E 0b0000000000010000 ///< Alphanumeric segment E

  5. #define ALPHANUM_SEG_F 0b0000000000100000 ///< Alphanumeric segment F

  6. #define ALPHANUM_SEG_G1 0b0000000001000000 ///< Alphanumeric segment G1

  7. #define ALPHANUM_SEG_G2 0b0000000010000000 ///< Alphanumeric segment G2

  8. #define ALPHANUM_SEG_H 0b0000000100000000 ///< Alphanumeric segment H

  9. #define ALPHANUM_SEG_J 0b0000001000000000 ///< Alphanumeric segment J

  10. #define ALPHANUM_SEG_K 0b0000010000000000 ///< Alphanumeric segment K

  11. #define ALPHANUM_SEG_L 0b0000100000000000 ///< Alphanumeric segment L

  12. #define ALPHANUM_SEG_M 0b0001000000000000 ///< Alphanumeric segment M

  13. #define ALPHANUM_SEG_N 0b0010000000000000 ///< Alphanumeric segment N

  14. #define ALPHANUM_SEG_DP 0b0100000000000000 ///< Alphanumeric segment DP

  • //###############################################################################################################################

  • #ifdef __cplusplus

  1. extern “C” {

  2. #endif

  • // Funktionen für die C+±Implementierung in der .cpp-Datei

  • extern bool VZ_Seg_begin(i2c_dev_t *display);

  1. extern void VZ_Seg_setBrightness(i2c_dev_t *display, uint8_t b);

  2. void VZ_Seg_blinkRate(i2c_dev_t *display, uint8_t b);

  3. void VZ_Seg_writeDisplay(i2c_dev_t *display);

  4. void VZ_Seg_clear(i2c_dev_t *display);

  5. void VZ_Seg_writeDigitRaw(uint8_t n, uint16_t bitmask);

  6. void VZ_Seg_writeDigitAscii(i2c_dev_t *display, uint8_t n, uint8_t ascii, bool d);

  • extern void VZ_Seg_setDisplay(i2c_dev_t *display, const char *text);

  • #ifdef __cplusplus

  1. }

  2. #endif

  • //###############################################################################################################################
  1. #endif

GeSHi © Codebox Plus Extension

CODE: [SELECT ALL] [EXPAND/COLLAPSE]

  1. i2cdev.h #ifndef MAIN_I2CDEV_H_

  2. #define MAIN_I2CDEV_H_

  • #include “driver/i2c.h”

  • #define I2C_FREQ_HZ 400000

  1. #define I2CDEV_TIMEOUT 1000
  • typedef struct {
  1. i2c_port_t port; // I2C port number

  2. uint8_t addr; // I2C address

  3. gpio_num_t sda_io_num; // GPIO number for I2C sda signal

  4. gpio_num_t scl_io_num; // GPIO number for I2C scl signal

  5. uint32_t clk_speed; // I2C clock frequency for master mode

  6. } i2c_dev_t;

  • esp_err_t i2c_master_init(i2c_port_t port, int sda, int scl);
  1. esp_err_t i2c_dev_read(const i2c_dev_t *dev, const void *out_data, size_t out_size, void *in_data, size_t in_size);

  2. esp_err_t i2c_dev_write(const i2c_dev_t *dev, const void *out_reg, size_t out_reg_size, const void *out_data, size_t out_size);

  3. inline esp_err_t i2c_dev_read_reg(const i2c_dev_t *dev, uint8_t reg,

  4. void *in_data, size_t in_size)

  5. {

  6. return i2c_dev_read(dev, &reg, 1, in_data, in_size);

  7. }

  • inline esp_err_t i2c_dev_write_reg(const i2c_dev_t *dev, uint8_t reg,
  1. const void *out_data, size_t out_size)

  2. {

  3. return i2c_dev_write(dev, &reg, 1, out_data, out_size);

  4. }

  5. #endif /* MAIN_I2CDEV_H_ */

GeSHi © Codebox Plus Extension

CODE: [SELECT ALL] [EXPAND/COLLAPSE]

  1. i2cdev.c #include <string.h>

  2. #include <time.h>

  • #include “freertos/FreeRTOS.h”
  1. #include “freertos/task.h”
  • #include “driver/i2c.h”
  1. #include “esp_log.h”
  • #include “i2cdev.h”

  • #define TAG “I2CDEV”

  • esp_err_t i2c_master_init(i2c_port_t port, int sda, int scl)

  1. {

  2. i2c_config_t i2c_config = {

  3. .mode = I2C_MODE_MASTER,

  4. .sda_io_num = sda,

  5. .scl_io_num = scl,

  6. .sda_pullup_en = GPIO_PULLUP_ENABLE,

  7. .scl_pullup_en = GPIO_PULLUP_ENABLE,

  8. .master.clk_speed = 1000000

  9. };

  10. //i2c_param_config(I2C_NUM_0, &i2c_config);

  11. //i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);

  12. i2c_param_config(port, &i2c_config);

  13. return i2c_driver_install(port, I2C_MODE_MASTER, 0, 0, 0);

  14. }

  • esp_err_t i2c_dev_read(const i2c_dev_t *dev, const void *out_data, size_t out_size, void *in_data, size_t in_size)
  1. {

  2. if (!dev || !in_data || !in_size) return ESP_ERR_INVALID_ARG;

  • i2c_cmd_handle_t cmd = i2c_cmd_link_create();
  1. if (out_data && out_size)

  2. {

  3. i2c_master_start(cmd);

  4. i2c_master_write_byte(cmd, (dev->addr << 1) | I2C_MASTER_WRITE, true);

  5. i2c_master_write(cmd, (void *)out_data, out_size, true);

  6. }

  7. i2c_master_start(cmd);

  8. i2c_master_write_byte(cmd, (dev->addr << 1) | 1, true);

  9. i2c_master_read(cmd, in_data, in_size, I2C_MASTER_LAST_NACK);

  10. i2c_master_stop(cmd);

  • esp_err_t res = i2c_master_cmd_begin(dev->port, cmd, I2CDEV_TIMEOUT / portTICK_PERIOD_MS);
  1. if (res != ESP_OK)

  2. ESP_LOGE(TAG, “Could not read from device [0x%02x at %d]: %d”, dev->addr, dev->port, res);

  3. i2c_cmd_link_delete(cmd);

  • return res;
  1. }
  • esp_err_t i2c_dev_write(const i2c_dev_t *dev, const void *out_reg, size_t out_reg_size, const void *out_data, size_t out_size)
  1. {

  2. if (!dev || !out_data || !out_size) return ESP_ERR_INVALID_ARG;

  • i2c_cmd_handle_t cmd = i2c_cmd_link_create();
  1. i2c_master_start(cmd);

  2. i2c_master_write_byte(cmd, (dev->addr << 1) | I2C_MASTER_WRITE, true);

  3. if (out_reg && out_reg_size)

  4. i2c_master_write(cmd, (void *)out_reg, out_reg_size, true);

  5. i2c_master_write(cmd, (void *)out_data, out_size, true);

  6. i2c_master_stop(cmd);

  7. esp_err_t res = i2c_master_cmd_begin(dev->port, cmd, I2CDEV_TIMEOUT / portTICK_PERIOD_MS);

  8. if (res != ESP_OK)

  9. ESP_LOGE(TAG, “Could not write to device [0x%02x at %d]: %d”, dev->addr, dev->port, res);

  10. i2c_cmd_link_delete(cmd);

  • return res;
  1. }

GeSHi © Codebox Plus Extension

CODE: [SELECT ALL] [EXPAND/COLLAPSE]

  1. OUTPUT : rst:0x1 (POWERON_RESET),boot:0x1e (SPI_FAST_FLASH_BOOT)

  2. configsip: 0, SPIWP:0xee

  3. clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

  4. mode:DIO, clock div:2

  5. load:0x3fff0030,len:7084

  6. ho 0 tail 12 room 4

  7. load:0x40078000,len:15584

  8. load:0x40080400,len:4

  9. 0x40080400: _init at ??:?

  • load:0x40080404,len:3876
  1. entry 0x4008064c

  2. I (31) boot: ESP-IDF v5.1.1-dirty 2nd stage bootloader

  3. I (31) boot: compile time Nov 17 2023 11:57:48

  4. I (31) boot: Multicore bootloader

  5. I (36) boot: chip revision: v3.0

  6. I (40) boot.esp32: SPI Speed : 40MHz

  7. I (44) boot.esp32: SPI Mode : DIO

  8. I (49) boot.esp32: SPI Flash Size : 2MB

  9. I (53) boot: Enabling RNG early entropy source…

  10. I (59) boot: Partition Table:

  11. I (62) boot: ## Label Usage Type ST Offset Length

  12. I (70) boot: 0 nvs WiFi data 01 02 00009000 00006000

  13. I (77) boot: 1 phy_init RF data 01 01 0000f000 00001000

  14. I (85) boot: 2 factory factory app 00 00 00010000 00100000

  15. I (92) boot: End of partition table

  16. I (96) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0c940h ( 51520) map

  17. I (123) esp_image: segment 1: paddr=0001c968 vaddr=3ffb0000 size=02230h ( 8752) load

  18. I (127) esp_image: segment 2: paddr=0001eba0 vaddr=40080000 size=01478h ( 5240) load

  19. I (131) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=1b22ch (111148) map

  20. I (178) esp_image: segment 4: paddr=0003b254 vaddr=40081478 size=0c91ch ( 51484) load

  21. I (199) esp_image: segment 5: paddr=00047b78 vaddr=50000000 size=00004h ( 4) load

  22. I (207) boot: Loaded app from partition at offset 0x10000

  23. I (207) boot: Disabling RNG early entropy source…

  24. I (219) cpu_start: Multicore app

  25. I (220) cpu_start: Pro cpu up.

  26. I (220) cpu_start: Starting app cpu, entry point is 0x40081294

  27. 0x40081294: call_start_cpu1 at C:/Users/CheckMakRack/esp/esp-idf/components/esp_system/port/cpu_start.c:154

  • I (0) cpu_start: App cpu up.
  1. I (238) cpu_start: Pro cpu start user code

  2. I (238) cpu_start: cpu freq: 160000000 Hz

  3. I (238) cpu_start: Application information:

  4. I (243) cpu_start: Project name: BTTF-TCD

  5. I (248) cpu_start: App version: 1

  6. I (252) cpu_start: Compile time: Nov 18 2023 10:57:00

  7. I (258) cpu_start: ELF file SHA256: 6c274682c571f52c…

  8. I (264) cpu_start: ESP-IDF: v5.1.1-dirty

  9. I (270) cpu_start: Min chip rev: v0.0

  10. I (274) cpu_start: Max chip rev: v3.99

  11. I (279) cpu_start: Chip rev: v3.0

  12. I (284) heap_init: Initializing. RAM available for dynamic allocation:

  13. I (291) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM

  14. I (297) heap_init: At 3FFB33F8 len 0002CC08 (179 KiB): DRAM

  15. I (303) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM

  16. I (310) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM

  17. I (316) heap_init: At 4008DD94 len 0001226C (72 KiB): IRAM

  18. I (324) spi_flash: detected chip: generic

  19. I (327) spi_flash: flash io: dio

  20. W (331) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.

  21. W (344) rmt(legacy): legacy driver is deprecated, please migrate to driver/rmt_tx.h and/or driver/rmt_rx.h

  22. I (355) app_start: Starting scheduler on CPU0

  23. I (360) app_start: Starting scheduler on CPU1

  24. I (360) main_task: Started on CPU0

  25. I (370) main_task: Calling app_main()

  26. I (370) gpio: GPIO[4]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0

  27. I (380) gpio: GPIO[5]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0

  28. I (390) gpio: GPIO[12]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0

  29. I (400) gpio: GPIO[14]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0

  30. I (410) uart_rx_task: Start

  31. I (410) uart_tx_task: Start

  • sending:7e ff 6 c 0 0 0 fe ef ef
  1. received:7e ff 6 3f 0 0 2 fe ba ef

  2. I (1560) MAIN: DF_begin=1

  3. I (1560) MAIN: DFPlayer Mini initialisiert.

  4. I (1560) MAIN: Setzen Lautstärke auf 15

  • sending:7e ff 6 6 0 0 f fe e6 ef
  1. I (1560) MAIN: I2C-Master initialisiert

  2. I (1580) MAIN: Found device at address 0x57

  3. I (1580) MAIN: Found device at address 0x5F

  4. I (1580) MAIN: Found device at address 0x68

  5. I (1580) MAIN: Found device at address 0x70

  6. I (1590) MAIN: Found device at address 0x71

  7. I (1590) MAIN: Found device at address 0x72

  8. I (1600) MAIN: Found 6 devices

  • I (1650) MAIN: RTC erfolgreich initialisiert
  1. I (1650) MAIN: VZ_DISP_1 initialisiert

  2. I (1650) MAIN: VZ_DISP_2 initialisiert

  3. I (1650) MAIN: VZ_DISP_3 initialisiert

  4. I (1650) MAIN: beginn

  5. I (1660) MAIN: writeDisplay

  6. I (1660) MAIN: Buffer values: 00 00 00 00 00 00 00 00

  7. I (1660) MAIN: beginn

  8. I (1670) MAIN: writeDisplay

  9. I (1670) MAIN: Buffer values: 00 00 00 00 00 00 00 00

  10. I (1680) MAIN: beginn

  11. I (1680) MAIN: writeDisplay

  12. I (1680) MAIN: Buffer values: 00 00 00 00 00 00 00 00

  13. I (1690) MAIN: Alle Displays erfolgreich initialisiert

  14. I (1690) MAIN: I2C_SCL_GPIO = 0

  15. I (1700) getClock: 2023-11-23 10:32:00, 19.75 deg Cel

  16. I (1700) MAIN: I2C_SDA_GPIO = 2

  17. I (1710) MAIN: CONFIG_TIMEZONE= 1

  18. I (1710) MAIN: writeDisplay

  19. I (1720) MAIN: Buffer values: f7 00 8f 12 39 00 0f 12

  20. I (1720) MAIN: writeDisplay

  21. I (1720) MAIN: Buffer values: 06 00 db 00 8f 00 e6 00

  22. I (1730) MAIN: writeDisplay

  23. I (1730) MAIN: Buffer values: 8f 12 38 00 3e 00 8f 12

  24. I (1740) main_task: Returned from app_main()

  25. I (1740) MAIN: IR-RX vor RINGBUFFER -DEBUGPRINT

  26. I (11690) getClock: 2023-11-23 10:32:10, 19.75 deg Cel

After ALL i took ht16k33.h of esp-idf and the example… throw out may deprecated mutex commands now it works