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