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

Ultrasonic sensor code not working when building for thingy91_nrf9160ns

Hello,

I am experiencing a weird issue with a code which I wrote for my ultrasonic distance measurement sensor for Thingy91. The code works fine and gives measurement values when I build for thingy91_nrf9160 but it doesn't work when I build for thingy91_nrf9160ns and distance measurement always comes out to be 0.

I am linking the datasheet of the sensor as it explains the operating principle of the sensor: https://www.makerguides.com/wp-content/uploads/2019/02/JSN-SR04T-Datasheet.pdf . I am using it in Mode 1.

I can see the sensor LED blinking which means that sensor is being triggered correctly so I think the problem arises when we try to calculate the time for which the sensor response remains high. This is done using GPIOTE events, Timer and Interrupt.

I am attaching the code so can anyone, please, take a look and see what aspects of it might not be working when I build for thingy91_nrf9160ns.

Thank you.

2438.ultrasonic_sensor.rar

  • Hi Simon,

    Thank you for your suggestions. I actually found the solution to the problem by making following changes in the code. I replaced:

    IRQ_CONNECT(DT_IRQN(DT_NODELABEL(gpiote)),
    				DT_IRQ(DT_NODELABEL(gpiote), priority),
    				nrfx_isr, nrfx_gpiote_irq_handler, 0);

    with:

    IRQ_DIRECT_CONNECT(GPIOTE1_IRQn, 0, nrfx_gpiote_irq_handler, 0);

    and everything worked. GPIOTE1 is working in thingy91_nrf9160ns now.

    Regards,

    Haris Ahmed

Related