Combining arduino code and esp-idf C-code for UART communication

mahadh
Posts: 2
Joined: Fri Apr 24, 2020 7:23 am

Combining arduino code and esp-idf C-code for UART communication

Postby mahadh » Fri Apr 24, 2020 7:46 am

Hello. I've been working on a project with an ESP32 board (OLIMEX ESP32-PoE) and I decided that I want the board to communicate with an arduino UNO through UART. So far, the ESP32 is programmed with ESP-IDF, and I want that to continue. I have written code in arduino for the ESP32 board to transmit data, and I've written code for the UNO to receive data, but the two won't communicate. My understanding is that the arduino Serial default is 8 data bits, no parity, one stop bit. The following are my code structures for both boards:

Code: Select all

#include <driver/gpio.h>
#include <driver/uart.h>
// Include FreeRTOS for delay
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
int app_main() {
    uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity    = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };
    uart_driver_install(UART_NUM_1, 2048, 0, 0, NULL, 0);
    uart_param_config(UART_NUM_1, &uart_config);
    uart_set_pin(UART_NUM_1, 4, 5, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);

    while(true) {
        uart_write_bytes(UART_NUM_1, "assa", 5);
        vTaskDelay(100 / portTICK_RATE_MS);
    }
}

Code: Select all

int incomingByte = 0; // for incoming serial data

void setup() {
  Serial.begin(115200); // opens serial port, sets data rate to 9600 bps
}

void loop() {
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
  }
  else{
    Serial.println("nothing");
    }
}
Any suggestions would be greatly appreciated.

Mohammed Yasar
Posts: 1
Joined: Tue Sep 19, 2023 5:11 am

Re: Combining arduino code and esp-idf C-code for UART communication

Postby Mohammed Yasar » Tue Sep 19, 2023 5:14 am

The main in IDF is loop in Arduino, and I am also confused about setup...

florinbaciu
Posts: 3
Joined: Wed Feb 08, 2023 2:19 pm

Re: Combining arduino code and esp-idf C-code for UART communication

Postby florinbaciu » Mon Oct 30, 2023 2:06 pm

No. Main app is not loop. Loop is while(1) or for(;;) or while(true) etc. Setup is in main, the code before while(1) will run only once and the while(1) will run in loop.

lbernstone
Posts: 829
Joined: Mon Jul 22, 2019 3:20 pm

Re: Combining arduino code and esp-idf C-code for UART communication

Postby lbernstone » Tue Oct 31, 2023 1:08 am

Your uart config looks ok. Make sure the TX from esp32 is going to RX on Arduino? You can put a LED inline on the TX and make sure you see it flashing when sending data (it should be nearly continuous with your loop). If the Uno is running at 5V on it's gpio lines, you may need a signal shifter to make everybody happy with the voltages.

Who is online

Users browsing this forum: No registered users and 88 guests