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,

    I mean I used this program for nrf5340 and I added some changes in its code.

    I'm not sure if the program respects the communication protocol because I can't find how to add the "gasboard 7500H" or "OCS-3F" sensor in the device tree or the overlay file so I find a solution that to read the sensor data from the RX

    The outcome shows the output reading of the RX.


    The sensor protocol is UART So could you help me to read the correct values from this sensor.

  • If what you are currently trying to do is simply to read data from your sensor with some basic UART sample, then I would recommend you read through the communication protocol part of the specification. It tells you in detail how you are supposed to communicate with the sensor.

    It looks like you have to send a specific command to the sensor to get data in return, are you doing this?

    -Einar

  • Hi,
    No, I am not sending anything to the sensor, please help me how to send a specific command and what is this command?

  • Looks like you're using Zephyr's uart_irq API in your code, which uses uart_irq_tx_ready() and uart_fifo_fill() to send data.

    Read about it here:

    http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/hardware/peripherals/uart.html#uart-interrupt-api

    The communication protocol is explained in the data sheet you linked in your original question. Please read it.

  • Thank you I understand and I write an example code, but no result.

    #include <zephyr.h>
    #include <device.h>
    #include <devicetree.h>
    #include <drivers/uart.h>
    #include <sys/printk.h>
    uint8_t uart_buf[1024];
    uint8_t buf[] = {17, 1, 1, 237};//11 01 01 ED
    int count;
    void uart_cb(const struct device *x, void *user_data)
    {
    	uart_irq_update(x);
    	int data_length = 0;
    	if (uart_irq_tx_ready(x)) {
    	(void)uart_fifo_fill(x, buf, sizeof(buf));
    	uart_irq_tx_disable(x);
    	}
    	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
    		
    
    
    const struct device *uart = device_get_binding("UART_1");
    
        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 ;
     	uart_configure(uart, &cfg);
    
    	uart_irq_callback_set(uart, uart_cb);
    	uart_irq_rx_enable(uart);
    	printk("main function!\n"); //output on UART0, which is default for logging
    	while (1) {
            uart_fifo_fill(uart,buf ,sizeof(buf) );//11 01 01 ED
    
            count=uart_fifo_read(uart,uart_buf,sizeof(uart_buf));
            printf("read  %i\n",count);
    
            k_cpu_idle();
            k_sleep(K_SECONDS(1));
    	}
    }

    I have a question the Arduino code of this sensor works correctly without sending a specific command, why in the code zephyr is obliged to send a specific command to obtain the data in return?

Related