Using LIS3dh with Thingy52

Hi

I am a student and this is my first project working on BLE. Please keep that in mind.

The end goal is to create a fingerprinting system with a Thingy (nRF6936) as a node. This Thingy currently broadcasts a UUID for gateways to pick up without a connection. The RSSI can then be derived inside the gateways. I am using the 17.1.0 nRF5 SDK

To increase the accuracy, I want to add accelerometer data inside the advertisement packet. Also, I want to make it more low power by sending very slow advertisements when the node isn't moving. 

I couldn't find any drivers for the LIS3dh that work on Thingies. That means I have to use SPI or I²C? 

The problem with this is that I need the pin layout of the Thingy to speak to the accelerometer directly. 

Where can I find these?

I have included the code of my beacon. 

 glass_beacon.zip

Parents Reply Children
  • The following code reads the whoAmI value from the lis2dh12 sensor inside the thingy52. I'm just leaving it here for people who are having the same trouble as me in the future. 

    Greetings

    Willem

    #include <stdio.h>
    #include "boards.h"
    #include "app_util_platform.h"
    #include "app_error.h"
    #include "nrf_drv_twi.h"
    #include "nrf_delay.h"
    
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    #include "lis2dh12.h"
    
    #include "nrf_twi_mngr.h"
    
    /* TWI instance ID. */
    #define TWI_INSTANCE_ID             0
    
    #define MAX_PENDING_TRANSACTIONS    33
    
    #define LIS2DH12_MIN_QUEUE_SIZE     32
    
    NRF_TWI_MNGR_DEF(m_nrf_twi_mngr, MAX_PENDING_TRANSACTIONS, TWI_INSTANCE_ID);
    
    NRF_TWI_SENSOR_DEF(m_nrf_twi_sensor, &m_nrf_twi_mngr, LIS2DH12_MIN_QUEUE_SIZE);
    
    LIS2DH12_INSTANCE_DEF(m_lis2dh12, &m_nrf_twi_sensor, LIS2DH12_BASE_ADDRESS_HIGH);
    
    static uint8_t m_sample = 0;
    
    void print_identity(ret_code_t r, void *p_register_data)
    {
        NRF_LOG_INFO("Identity: %d", *((uint8_t *)p_register_data));
    }
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
        uint32_t err;
    
        nrf_drv_twi_config_t const config = {
           .scl                = 15,
           .sda                = 14,
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_LOWEST,
           .clear_bus_init     = false
        };
    
    
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        NRF_LOG_INFO("TWI sensor example started.");
        NRF_LOG_FLUSH();
    
        err = nrf_twi_mngr_init(&m_nrf_twi_mngr, &config);
        APP_ERROR_CHECK(err);
    
        err = nrf_twi_sensor_init(&m_nrf_twi_sensor);
        APP_ERROR_CHECK(err);
    
        err = lis2dh12_init(&m_lis2dh12);
        APP_ERROR_CHECK(err);
    
        NRF_LOG_INFO("Here.");
        NRF_LOG_FLUSH();
        APP_ERROR_CHECK(err);
    
        while (true)
        {
            nrf_delay_ms(100);
            err = lis2dh12_who_am_i_read(&m_lis2dh12, print_identity, &m_sample);
            APP_ERROR_CHECK(err);
            NRF_LOG_INFO("Who am I: %x", m_sample);
            NRF_LOG_FLUSH();
        }
    }

Related