This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

how to disable the ADXL362 accelerometer on the thingy91

Hi,

I've used the ADXL362 sensor sample code in the zephyr folder to get the low power accelerometer sensor working on the the thingy91. It triggers on motion and I can print out the xyz values. but I cant figure out how to shut it down so I can turn it back on later. This would serve 2 purposes, to save power if needed, and eliminate motion triggers from the accelerameter when they shouldn't be acknowledged. For example the trigger fires off 2 motion events on all motions. I assume this is 1 high and 1 low. I would like to shut the accelerometer down after the first motion for a few minutes to eliminate the double read.

Here is some code example. disable_motion_sensor() doesn't seem to do anything

static void trigger_handler(struct device *dev, struct sensor_trigger *trig)
{
    switch (trig->type) {
    case SENSOR_TRIG_DATA_READY:
//                printf("trig data ready\n");
        if (sensor_sample_fetch(dev) < 0) {
            printf("Sample fetch error\n");
            return;
        }
        k_sem_give(&sem);
        break;
    case SENSOR_TRIG_THRESHOLD:
        printf("Motion event\n");
                blink_led();
//                disable_motion_sensor();
//                set_timer(checkinFrequency);
        break;
    default:
        printf("Unknown trigger\n");
    }
}

void set_motion_trig(){
    if (IS_ENABLED(CONFIG_ADXL362_TRIGGER)) {
        struct sensor_trigger trig = { .chan = SENSOR_CHAN_ACCEL_XYZ };

        trig.type = SENSOR_TRIG_THRESHOLD;
        if (sensor_trigger_set(devMotion, &trig, trigger_handler)) {
            printf("Trigger set error\n");
            return;
        }

        trig.type = SENSOR_TRIG_DATA_READY;
        if (sensor_trigger_set(devMotion, &trig, trigger_handler)) {
            printf("Trigger set error\n");
        }
    }
        else{
                printf("CONFIG_ADXL362_TRIGGER not enabled\n");
                motionTriggerOn = 0;
        }
}

void enable_motion_sensor(){
        devMotion = device_get_binding(DT_INST_0_ADI_ADXL362_LABEL);
        motionTriggerOn = 1;
    if (devMotion == NULL) {
                motionTriggerOn = 0;
        printf("Device get binding device is null\n");
        return;
    }
}

void disable_motion_sensor(){
        devMotion = NULL;
        if (devMotion == NULL) {
                if (IS_ENABLED(CONFIG_ADXL362_TRIGGER)) {
                      printf("Tried to shut down but motion sensor is still running\n");
                }
                else{
                      motionTriggerOn = 0;
                      printf("Motion sensor is shut down\n");
                      return;
                }
    }
}

Any thoughts would be appreciated

Parents
  • Hi,

    The sensor API in Zephyr does not seem to have this disable functionality implemented. Maybe you could try to implement a function in adxl362_trigger.c or adxl362.c that e.g. write to the INTMAP1 register in order to disable the interrupt ?

  • I'm not sure how I would do that. If I did do something like this, since I would be changing the driver code wouldn't it get overwritten when I do an NCS update?

    I did implement a flag and a test in the trigger handler itself. I flip the flag back and forth as if I am disabling it. Not power efficient but it works. At some point Ill test how much more power the Accel motion trigger draws. If you know how much that might be It would save me some time and Id appreciate it. If you don't know but you'd like to know I can provide the code I have for power testing.

Reply
  • I'm not sure how I would do that. If I did do something like this, since I would be changing the driver code wouldn't it get overwritten when I do an NCS update?

    I did implement a flag and a test in the trigger handler itself. I flip the flag back and forth as if I am disabling it. Not power efficient but it works. At some point Ill test how much more power the Accel motion trigger draws. If you know how much that might be It would save me some time and Id appreciate it. If you don't know but you'd like to know I can provide the code I have for power testing.

Children
  • AndrewR said:
    If I did do something like this, since I would be changing the driver code wouldn't it get overwritten when I do an NCS update?

     You would likely get a merge conflict that you then need to resolve. git has the functionality to help you handle that.

    If you have made changes you think other Zephyr users might find useful, please feel free to submit a patch to upstream Zephyr. See this link.

Related