Page 1 of 1

UART reading float numbers

Posted: Tue Apr 11, 2023 8:15 am
by emanos
Hey everyone,

I would like to ask for your help. I am writing code in Arduino, yet i utilize the <driver/uart.h> library and i have set up the uart as following:

Code: Select all

  
  uart_config_t uart_config_0 = {
  .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_param_config(UART_NUM_0, &uart_config_0);
uart_set_pin(UART_NUM_0, TX_UART0, RX_UART0, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART_NUM_0, BUF_SIZE*2, 0, 0, NULL, 0);
Then, i try to read data and echo them as following:

Code: Select all

int len = uart_read_bytes(UART_NUM_0, dataR, 1024, 1000);
  if (len > 0)
  {
  	uart_write_bytes(UART_NUM_0, dataR, strlen(dataR));
  }
My plan was to take all 4 bytes that a float is consisted of and using memcpy try and structure the float that i would finally print.
To be honest i am having trouble even with reading plain data (not floats) in general, so if you can help me with even some echo, i would appreciate it.

Thanks in advance

Re: UART reading float numbers

Posted: Tue Apr 11, 2023 9:06 am
by corz.org
If it's not huge, it's best to post all your code, as well as how your project is setup (e.g. where is this data coming from?). You can't read floats from the UART, per se. Only data bits.

There may be a better way to do what you are trying to do.
Is this for RS-232? Or would Serial functions perhaps be more suitable? Or maybe SPI?

I would start somewhere like here: https://en.wikipedia.org/wiki/Universal ... ransmitter