nRF Connect SDK machine learning application simulated sensor build problem

Hardware: nrf52840 DK.

Software: ncs version v1.7.0 and default SEGGER IDE for Nordic.

When I first build the machine learning application in nrf, there is no any problems. Because nrf52840 DK uses simulated sensor, so we want to add our own custom sensor, I modify the configuration file: app_ZDebug.conf for our own sensor. But when I want to use simulated sensor again, I change the configuration file back as follows:

# Using simulated sensor (the DK does not have built-in sensor)
CONFIG_SENSOR=y
CONFIG_SENSOR_SIM=y
CONFIG_SENSOR_SIM_ACCEL_WAVE=y

I clean the solution and rebuilt the whole solution, but it always output following warnings and error:

ncs/v1.7.0/zephyr/drivers/sensor/lis2dw12/lis2dw12.c:303:2: warning: #warning "LIS2DW12 driver enabled without any devices" -Wcpp]
ncs/v1.7.0/zephyr/drivers/sensor/lis2dw12/lis2dw12.c:239:12: warning: lis2dw12_init' defined but not used -Wunused-function]
ncs/v1.7.0/zephyr/drivers/sensor/lis2dw12/lis2dw12.c:208:39: warning: lis2dw12_driver_api' defined but not used -Wunused-const-variable=]

../configuration/nrf52840dk_nrf52840/sensor_sampler_def.h:36:15: error: 'CONFIG_SENSOR_SIM_DEV_NAME' undeclared here (not in a function); did you mean 'CONFIG_SENSOR_LOG_LEVEL'?
Build failed

This error makes me so confused. (In fact, we want to use LIS2DW12 sensor.) How can I solve this problem? Thank you guys!

BRs.

Parents
  • Hi, Marte:

    Thank your for your quick response. After I delete the build folder completely, everything is OK. I want to add LIS2DW12 sensor and I add following configuration in app_ZDebug.conf:

    # Using lis2dw12 ST sensor
    CONFIG_LIS2DW12=y
    CONFIG_I2C=y
    CONFIG_I2C_NRFX=y

    I also add following things in dts.overlay:

    &i2c0 {
    compatible = "nordic,nrf-twim";
    status = "okay";
    sda-pin = < 22 >;
    scl-pin = < 19 >;
    clock-frequency = <I2C_BITRATE_STANDARD>;

    lisdw12@31 {
    compatible = "st,lis2dw12";
    reg = <0x19>;
    label = "LIS2DW12";
    };
    };

    Then I want get the sensor acceleration data of  LIS2DW12 sensor in main function, but I get the following output:

    [00:00:07.981,994] <inf> main: LIS2DW12 Sensor data: X: 0.00, Y: 0.00, Z: 0.00
    [00:00:08.083,099] <inf> main: LIS2DW12 Sensor data: X: 0.00, Y: 0.00, Z: 0.00
    [00:00:08.184,173] <inf> main: LIS2DW12 Sensor data: X: 0.00, Y: 0.00, Z: 0.00
    [00:00:08.285,247] <inf> main: LIS2DW12 Sensor data: X: 0.00, Y: 0.00, Z: 0.00
    [00:00:08.386,322] <inf> main: LIS2DW12 Sensor data: X: 0.00, Y: 0.00, Z: 0.00
    [00:00:08.487,396] <inf> main: LIS2DW12 Sensor data: X: 0.00, Y: 0.00, Z: 0.00

    Is there any configuration missing for LIS2DW12 sensor? Any good suggestions? Thanks

    BRs.

  • Hi,

    What are you using to get the data in main? If you test following the steps in the documentation (Testing with the nRF52840 DK), just with your sensor instead of the simulated sensor, are the values still 0 in step 6?

    Best regards,

    Marte

Reply Children
  • Hi,

    I use following code to get the sensor data:

    const struct device *accel;
            struct sensor_value accel_x;
            struct sensor_value accel_y;
            struct sensor_value accel_z;
    
            static uint8_t buf[BUF_SIZE];
            
            // Initialize the sensor
            accel = device_get_binding("LIS2DW12");
            if (accel == NULL)
            {
                LOG_ERR("No device LIS2DW12 found, did initialization fail");
            }
            else
            {
                LOG_INF("Found device LIS2DW12");
            }
    
            // Read from the sensor
            if(accel)
            {
                while (1) {
                    sensor_sample_fetch(accel);
                    sensor_channel_get(accel, SENSOR_CHAN_ACCEL_X, &accel_x);
                    sensor_channel_get(accel, SENSOR_CHAN_ACCEL_Y, &accel_y);
                    sensor_channel_get(accel, SENSOR_CHAN_ACCEL_Z, &accel_z);
    
                    // Add more check
                    LOG_INF("LIS2DW12 Sensor data: X: %.2f, Y: %.2f, Z: %.2f",
                            sensor_value_to_double(&accel_x),
                            sensor_value_to_double(&accel_y),
                            sensor_value_to_double(&accel_z));
                    k_sleep(K_MSEC(100));
                    }
            }

    By the way, I don't modify the simulated sensor configuration and its related code in this machine learning application and I just add a new acceleration sensor(LIS2DW12) and use the above code to read sensor data. And I have already sent you new sensor configuration(LIS2DW12). Thanks.

    BRs.

  • Hi,

    In your overlay file you are using pins 19 and 22 for I2C0. These are by default used by QSPI on nRF52840 DK. Is QSPI disabled so that the pins are available? You must make sure to either use pins that are not used by anything else, by either using pins that are available or disabling whatever is already using them. You can see which pins are used and by what in the board file zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts and here nRF52840 DK > Connector interface. If you want to use these pins and do not use QSPI you can disable it in your overlay file by adding the following:

    &qspi{
        status = "disabled";
    };

    Have you tested whether you are able to get the sensor to work and get correct sensor readings using a simpler example that just read and print the sensor values?

    Best regards,

    Marte

Related