Altitude & Temp

Home Forums Forums Technical Support for BerryIMU Altitude & Temp

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #7922
    jgreen
    Participant

    Where can I find sample code on the altitude and temp for an arduino nano?

    I have guessed at some code for the temp but it is not working.  This is always returning a temp of 77 degrees

    float readTemp(){
    uint8_t block[2];
    //readFrom(LSM9DS1_MAG_ADDRESS, 0x80 | LSM9DS0_OUT_TEMP_L_XM, 2, block);
    readFrom(LSM9DS1_MAG_ADDRESS, 0x80 | LSM9DS0_OUT_TEMP_H_XM, 2, block);
    int16_t temp = (int16_t)(block[0] | block[1] << 8);
    float temperature_c = (float)temp / 8.0 + 25;
    float temperature_f = temperature_c * 1.8 + 32;
    return temperature_f;
    }

    #7924
    Mark Williams
    Keymaster

    What version of BerryIMU do you have?  1 or 2?

    Mark --OzzMaker.com --

    #7925
    jgreen
    Participant

    2.3  When I run the gyro demo it states LSM9DS1 found

    #7926
    Mark Williams
    Keymaster

    okay… try using this LSM9DS1_OUT_TEMP_H  here

    readFrom(LSM9DS1_MAG_ADDRESS, 0x80 | LSM9DS1_OUT_TEMP_H_XM, 2, block);

     

    Mark --OzzMaker.com --

    #7927
    jgreen
    Participant

    ‘LSM9DS1_OUT_TEMP_H_XM’ was not declared in this scope

    I dont see the entry in LSM9DS1.h.  File from https://github.com/ozzmaker/BerryIMU/blob/master/arduino-BerryIMU/LSM9DS1.h

    #7928
    Mark Williams
    Keymaster

    sorry…  a copy and paste error.  this is the correct one
    LSM9DS1_OUT_TEMP_H

    Mark --OzzMaker.com --

    #7929
    jgreen
    Participant

    the function returns -3310

    float readTemp(){
    uint8_t block[2];
    readFrom(LSM9DS1_MAG_ADDRESS, 0x80 | LSM9DS1_OUT_TEMP_H, 2, block);
    int16_t temp = (int16_t)(block[0] | block[1] << 8);
    float temperature_c = (float)temp / 8.0 + 25;
    float temperature_f = temperature_c * 1.8 + 32;
    return temperature_f;
    }

    #7930
    Mark Williams
    Keymaster

    have you enabled the accelerometer at the start of your code?

    you could try and get the temperature from the BMP280  google “read temp bmp280” and you will find plenty of information.

     

    We have python code

    https://github.com/ozzmaker/BerryIMU/tree/master/python-BMP280-temperature-pressure

    Mark --OzzMaker.com --

    #7931
    jgreen
    Participant

    yes,

     

    void setup() {
    // join i2c bus (address optional for master)
    Serial.begin(115200); // start serial for output

    detectIMU();
    enableIMU();

    delay(1000);
    }

    void enableIMU(){

    if (LSM9DS0){//For BerryIMUv1
    //Enable accelerometer
    writeTo(LSM9DS0_ACC_ADDRESS,LSM9DS0_CTRL_REG1_XM, 0b01100111); // z,y,x axis enabled, continuos update, 100Hz data rate
    writeTo(LSM9DS0_ACC_ADDRESS,LSM9DS0_CTRL_REG2_XM, 0b00100000); // +/- 16G full scale

    //Enable the magnetometer
    writeTo(LSM9DS0_MAG_ADDRESS,LSM9DS0_CTRL_REG5_XM, 0b11110000); // Temp enable, M data rate = 50Hz
    writeTo(LSM9DS0_MAG_ADDRESS,LSM9DS0_CTRL_REG6_XM, 0b01100000); // +/-12gauss
    writeTo(LSM9DS0_MAG_ADDRESS,LSM9DS0_CTRL_REG7_XM, 0b00000000); // Continuous-conversion mode

    // Enable Gyro
    writeTo(LSM9DS0_GYR_ADDRESS, LSM9DS0_CTRL_REG1_G, 0b00001111); // Normal power mode, all axes enabled
    writeTo(LSM9DS0_GYR_ADDRESS, LSM9DS0_CTRL_REG4_G, 0b00110000); // Continuos update, 2000 dps full scale
    }
    else if(LSM9DS1){//For BerryIMUv2
    // Enable the gyroscope
    writeTo(LSM9DS1_GYR_ADDRESS,LSM9DS1_CTRL_REG4,0b00111000); // z, y, x axis enabled for gyro
    writeTo(LSM9DS1_GYR_ADDRESS,LSM9DS1_CTRL_REG1_G,0b10111000); // Gyro ODR = 476Hz, 2000 dps
    writeTo(LSM9DS1_GYR_ADDRESS,LSM9DS1_ORIENT_CFG_G,0b10111000); // Swap orientation

    // Enable the accelerometer
    writeTo(LSM9DS1_ACC_ADDRESS,LSM9DS1_CTRL_REG5_XL,0b00111000); // z, y, x axis enabled for accelerometer
    writeTo(LSM9DS1_ACC_ADDRESS,LSM9DS1_CTRL_REG6_XL,0b00101000); // +/- 16g

    //Enable the magnetometer
    writeTo(LSM9DS1_MAG_ADDRESS,LSM9DS1_CTRL_REG1_M, 0b10011100); // Temp compensation enabled,Low power mode mode,80Hz ODR
    writeTo(LSM9DS1_MAG_ADDRESS,LSM9DS1_CTRL_REG2_M, 0b01000000); // +/-12gauss
    writeTo(LSM9DS1_MAG_ADDRESS,LSM9DS1_CTRL_REG3_M, 0b00000000); // continuos update
    writeTo(LSM9DS1_MAG_ADDRESS,LSM9DS1_CTRL_REG4_M, 0b00000000); // lower power mode for Z axis

    }
    }

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

Blip, blop, bloop…