My objective is ., when i send the data through uart , it should be able to process some function.
For example , when am send the char '1' or a string "ON" through uart , the led should blink like that .
Am a newbie to this platform , can anyone please say..?
Hi , is there any sample code for uart in esp32..??
Re: Hi , is there any sample code for uart in esp32..??
And one more thing , how to read the received char and string from uart ..?
- ESP_krzychb
- Posts: 400
- Joined: Sat Oct 01, 2016 9:05 am
- Contact:
Re: Hi , is there any sample code for uart in esp32..??
I have tried all those codes , i cannot able to read the string in esp32 , am just able to read only the length of the string, what modification will am need to do in order to read a string..?
- martinayotte
- Posts: 141
- Joined: Fri Nov 13, 2015 4:27 pm
Re: Hi , is there any sample code for uart in esp32..??
You need to read character by character, fill a separate buffer with them, increment an index, and continue until you find a delimiter, usually CR, then compare buffer content with your available commands and execute the command found.
Re: Hi , is there any sample code for uart in esp32..??
string is only a container with bytes, nothing moreReeshma wrote:I have tried all those codes , i cannot able to read the string in esp32 , am just able to read only the length of the string, what modification will am need to do in order to read a string..?
if you talk about "string" you mean a char variable with idx len of the string, right?
Code: Select all
char myString[] = "hello world";
myString[0]
would be 'h'
myString[1]
would be 'e'
myString[2]
would be 'l'
and so on.
have you test the Uart echo example?
part of code is:
https://github.com/espressif/esp-idf/bl ... main.c#L60
Code: Select all
uint8_t* data = (uint8_t*) malloc(BUF_SIZE);
while(1) {
//Read data from UART
int len = uart_read_bytes(uart_num, data, BUF_SIZE, 20 / portTICK_RATE_MS);
//Write data back to UART
uart_write_bytes(uart_num, (const char*) data, len);
}
}
you send to the uart
and the uart will echo (const char*) data
if you send "hello world" and push enter
then the uart gives echo "hello world"
best wishes
rudi
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪
Who is online
Users browsing this forum: Bing [Bot] and 44 guests