Read Uart based sensor data on nrf5340 using VsCode?

Hi,

I'am using the  Ultrasonic Oxygen Senor with the nrf5340, the output is like this "photo" I want to calculate the concentration and the purity and with this values I had wrong results, so can you help to solve this problem?

 I am using this code

4857.gasboard.zip

 and here is my result.


this technical specification for my sensor.

 https://en.gassensor.com.cn/Product_files/Specifications/Gasboard%207500H%20series%20technical%20specification.pdf?fbclid=IwAR0R1P0FlwkPzhew7jBYVzL-rvtESB1ob2HGF0OE4bngaI5jP8ktZfFMoMo 

Could you please help me to solve this problem

Parents Reply Children
  • Hi ,

    #include <zephyr.h>
    #include <device.h>
    #include <devicetree.h>
    #include <drivers/uart.h>
    #include <sys/printk.h>
    uint8_t uart_buf[12],i,j;
    uint16_t o2c,o2f,o2t;
    uint8_t temp;
    int count;
    	
     void uart_cb(const struct device *x, void *user_data)
     {
     	// uart_update(x);
         int data_length = 0;
    
     	if (uart_irq_rx_ready(x)) {
     		data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
     		// uart_buf[data_length] = 0;
     	}
         // uart_fifo_fill(x, uart_buf, data_length);
     }
    
    void main(void)
    {
        printk("sensor program start!\n"); //output on UART0, which is default for logging
    	  struct uart_config cfg ;
        cfg.baudrate = 9600 ;
        cfg.parity = UART_CFG_PARITY_NONE ;
        cfg.stop_bits = UART_CFG_STOP_BITS_1 ;
        cfg.data_bits = UART_CFG_DATA_BITS_8 ;
        cfg.flow_ctrl = UART_CFG_FLOW_CTRL_NONE ;
    
        const struct device *uart = device_get_binding("UART_1");	
      while(1){
          uart_configure(uart, &cfg);
        
          uart_rx_enable(uart,uart_buf,sizeof(uart_buf),500000);
           uart_callback_set(uart, uart_cb,NULL);
           printk("main function!\n");//output on UART0, which is default for logging
     	
         k_sleep(K_MSEC(1000));
    
    
            // for(int i=0;i<sizeof(uart_buf);i++){
            // printk("data%i= %x \n",i,uart_buf[i]);}
    
            printk("*******************************\n");
            k_sleep(K_MSEC(1000));
    
                o2c = uart_buf[3] * 256 + uart_buf[4];     //Oxygen concentration
                o2f = uart_buf[5] * 256 + uart_buf[6];     //Oxygen flow value
                o2t = uart_buf[7] * 256 + uart_buf[8];     //Oxygen temperature
                float o2c1;
                o2c1=(float)o2c/10;
                float o2f1;
                o2f1=(float)o2f/10;
                float o2t1;
                o2t1=(float)o2t/10;
                printf("O2 : %.2f %\n",o2c1);
                printf("flow : %.2f L/min\n",o2f1);
    
                printf("temp: %.2f °C\n",o2t1);
    
    }	}
    

    proj.conf

    CONFIG_UART_ASYNC_API=y
    CONFIG_UART_WIDE_DATA=y
    CONFIG_UART_USE_RUNTIME_CONFIGURE=y
    CONFIG_UART_LINE_CTRL=y
    CONFIG_UART_1_ASYNC=y
    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
    CONFIG_NRFX_UARTE1=y

Related