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

Read Temperature sensor on button press

Hi I'm using nRF5 SDK for mesh. with DK PCA10040.

I want to read the temperature sensor reading on button press. Please give me guidelines on implementing this.

Thank you.

Parents
  • In the nRF5 SDK (non-mesh), the BSP provides events on button press - is that not available in the mesh version?

    If it isn't, then look at how the non-mesh SDK does it ...

  • I tried the following

    static void button_event_handler(uint32_t button_number)
    {
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Button %u pressed\n", button_number);
    switch (button_number)
    {
    /* Pressing SW1 on the Development Kit will result in LED state to toggle and trigger
    the STATUS message to inform client about the state change. This is a demonstration of
    state change publication due to local event. */


    // Read Temperature Sensor
    case 2:
    {
    _ __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Temperature \n" );

    uint32_t temperature;
    sd_temp_get(&temperature);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Temperature is = %d \n" , temperature/4);
    break;
    }

    default:
    break;
    }
    }

    this gives the temperature of the board and prints on the RTT Viewer

  • static void button_event_handler(uint32_t button_number)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Button %u pressed\n", button_number);
        switch (button_number)
        {
            /* Pressing SW1 on the Development Kit will result in LED state to toggle and trigger
            the STATUS message to inform client about the state change. This is a demonstration of
            state change publication due to local event. */
    
    
            // Read Temperature Sensor
            case 2:
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Temperature \n" );
    
                uint32_t temperature;
                sd_temp_get(&temperature);
                 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Temperature is = %d \n" , temperature/4);
                 break;
            }   
    
            default:
            break;
        }
    }

Reply
  • static void button_event_handler(uint32_t button_number)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Button %u pressed\n", button_number);
        switch (button_number)
        {
            /* Pressing SW1 on the Development Kit will result in LED state to toggle and trigger
            the STATUS message to inform client about the state change. This is a demonstration of
            state change publication due to local event. */
    
    
            // Read Temperature Sensor
            case 2:
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Temperature \n" );
    
                uint32_t temperature;
                sd_temp_get(&temperature);
                 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Temperature is = %d \n" , temperature/4);
                 break;
            }   
    
            default:
            break;
        }
    }

Children
Related