Combining arduino code and esp-idf C-code for UART communication
Posted: 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:
Any suggestions would be greatly appreciated.
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");
}
}