https://github.com/nopnop2002/esp-idf-serial
User-level UART I/O library for ESP-IDF
https://github.com/nopnop2002/esp-idf-serial
esp-idf esp32 uart
Last synced: 12 months ago
JSON representation
User-level UART I/O library for ESP-IDF
- Host: GitHub
- URL: https://github.com/nopnop2002/esp-idf-serial
- Owner: nopnop2002
- License: mit
- Created: 2023-01-22T13:44:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-13T18:57:25.000Z (about 2 years ago)
- Last Synced: 2025-04-03T04:41:34.839Z (about 1 year ago)
- Topics: esp-idf, esp32, uart
- Language: C
- Homepage:
- Size: 24.4 KB
- Stars: 4
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# esp-idf-serial
User-level UART I/O library for ESP-IDF.
# Background
The Arduino environment has several libraries and applications for handling UART devices such as MP3 players, GPS receivers, and gas sensors.
ESP-IDF provides a highly functional UART driver.
But we can't treat it like STDIN/STDOUT.
I created this to port applications and libraries that use UART from the Arduino environment to the ESP-IDF environment.
# Software requirements
ESP-IDF V4.4 or later.
# Installation
```Shell
git clone https://github.com/nopnop2002/esp-idf-serial
cd esp-idf-serial
idf.py flash
```
# Wirering
|ESP32||TTL-USB Converter|
|:-:|:-:|:-:|
|GPIO4|--|TX|
|GPIO5|--|RX|
|GND|--|GND|
Plug the TTL-USB Converter into your host and open a serial terminal on your host.
I use GtkTerm on linux.
# Limitation
When using this library, the task that initializes and the task that does the IO must be the same.
Unlike other drivers provided by ESP-IDF, initialization and IO cannot be separated into separate tasks.
# Arduno code
```
#include
SoftwareSerial _serial(4, 5); // RX, TX
unsigned long lastMillis;
void setup() {
Serial.begin(115200);
_serial.begin(115200);
lastMillis = 0;
}
void loop() {
int len = Serial.available();
if (len > 0) {
for (int i=0;i 1000) {
lastMillis = nowMillis;
char buffer[64];
sprintf(buffer, "Hello World %d",nowMillis);
Serial.println(buffer);
}
}
```
}
# ESP-IDF code using this
```
#include
#include
#include
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "serial.h"
#define TAG "MAIN"
#define TXD_PIN (GPIO_NUM_4)
#define RXD_PIN (GPIO_NUM_5)
void app_main(void)
{
serial_begin(112500, TXD_PIN, RXD_PIN);
TickType_t lastTick = xTaskGetTickCount();
while(1) {
int len = serial_available();
if (len > 0) {
ESP_LOGI(TAG, "serial_available=%d", len);
for (int i=0;i 100) {
lastTick = xTaskGetTickCount();
char buffer[64];
sprintf(buffer, "Hello World %"PRIu32, nowTick);
ESP_LOGI(TAG, "buffer=[%s]", buffer);
serial_println(buffer);
}
vTaskDelay(1);
}
}
```