Page 1 of 1

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

Posted: Fri Apr 24, 2020 7:46 am
by mahadh
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.

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

Posted: Tue Sep 19, 2023 5:14 am
by Mohammed Yasar
The main in IDF is loop in Arduino, and I am also confused about setup...

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

Posted: Mon Oct 30, 2023 2:06 pm
by florinbaciu
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.

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

Posted: Tue Oct 31, 2023 1:08 am
by lbernstone
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.