Parsing using DFROBOT Gravity: I²C to Dual UART Module

Hello everyone,
I’m creating a small project for my boat and I need to implement 3 uarts in addition to UART_0 for the logger, so I purchased a DFROBOT Gravity: I²C to Dual UART Module, a module compatible with esphome. My YAML file includes a second I2C bus with a frequency of 800mhz to which the module is connected and then the configuration of the module which at this moment only includes the UART_0 channel.

#        -----------------------------------------------------------------------------------------I2C Configurazione

i2c:
  - id: bus_a
    sda: GPIO32
    scl: GPIO33
    scan: true
  - id: bus_b
    sda: GPIO23
    scl: GPIO25
    scan: true
    frequency: 800khz
    

# #------------------------------------------------------------------------------------------------------------------------------------------------------------UART EXTENDER Configurazione I2C 


wk2132_i2c:
  - address: 0x70
    i2c_id: bus_b
    id: wk2132_uart_i2c
    uart:
      - id: i2c_uart_0
        channel: 0
        baud_rate: 4800
        parity: NONE
        stop_bits: 1

In reality I only need the rx channel of this port as I need to read the nmea data transmitted by a Raytheon system via a ttl-RS485 interface, but it doesnt matter.

Because i understood that its not possible tu use the “debug” function as per the three ESP32 UARTS, I created a testbed with a nmea string generator (made using an esp32 which send one string per second) connected to the DFROBOT module and a kind of “sniffer” to read the receiving strings with this code:


  - interval: 10ms
    then:
      - lambda: |-
          const size_t MAX_NMEA_SIZE = 82;
          uint8_t temp_buffer[MAX_NMEA_SIZE] = {0};
          uint8_t start_register = 0x00; 

          // Leggi i dati dal modulo WK2132
          if (id(wk2132_uart_i2c).read_bytes(start_register, temp_buffer, sizeof(temp_buffer))) {
              char nmea_data[MAX_NMEA_SIZE + 1] = {0};
              size_t nmea_length = 0;

              // Converti i byte ricevuti in una stringa
              for (size_t i = 0; i < sizeof(temp_buffer); i++) {
                  uint8_t byte = temp_buffer[i];
                  if (isprint(byte) || byte == '\r' || byte == '\n') {
                      nmea_data[nmea_length++] = byte;
                  }
                  if (nmea_length >= MAX_NMEA_SIZE) break;
              }
              nmea_data[nmea_length] = '\0';

              // Verifica stringa NMEA valida
              if (nmea_data[0] == '$' && strstr(nmea_data, "*") != NULL) {
                  ESP_LOGD("UART_WK2132", "Stringa NMEA valida: %s", nmea_data);
              } else {
                  ESP_LOGW("UART_WK2132", "Stringa NMEA non valida o incompleta: %s", nmea_data);
              }
          } else {
              ESP_LOGW("UART_WK2132", "Nessun dato ricevuto o overflow del buffer");
          }

but no way to make it working.

Is there anyone who setted up a parsing using this module to show me the right way??

Thanks for any help
Costa

I don’t know your I2C board, but I expect you could do the whole crap with 2 hardware uarts and 1 software uart. Without that I2C board.

Hi, that would be great! Too bad that as far as I know the software uart are not implemented on the esp32…

[Please add Software UART to ESP32 · Issue #1712 · esphome/feature-requests · GitHub]

If you know something that I don’t know, show me the way, thanks

Sorry for misleading, for some reason, according to documentation, Esp32 doesn’t support sw uart like esp8266 does. I don’t see any reason for that, probably developers thought 2 hw uarts are enough. My apologies…

no problem, i thought you knew a trick to get around the problem. thanks anyway

Since Arduino framework supports software uart for Esp32, some trick there should be in Esphome… But beyond of my knowledge. :disappointed:

Do you need the hardware logger component? If you set the baud rate to zero in the logger section it won’t send to the serial console allowing you to use for other things. It still sends to the online logger console to help debugging.

In my opinion very rare you need the logger to send to serial once you have OTA up and running, but obviously you may have a specific need.

Hi, its true i can use UART 0 but because its a very heavy parsing with lot of automations ( we are talking around 4k code Lines) my First approch Is to keep the logger and see if someone knows how to do it with this uart extension. If not… Thats Will be my way

Thanks