BerryIMU and mbed

Forums Technical Support for BerryIMU BerryIMU and mbed

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #6170
    Osairiis
    Participant

    Hello,

    I am trying to use the BerryIMU with a NUCLEO L053R8 board. For some reason I am not receiving any data back from the IMU. Can anyone suggest anything? Thanks a lot! The code I used is below:

    ---------------------

    #include "LSM9DS0.h"
    #include "mbed.h"
    #include "I2C.h"
    #include "DigitalOut.h"

    /*
    #define MAG_ADDRESS 0x1E
    #define ACC_ADDRESS 0x1E
    #define GYR_ADDRESS 0x6A
    */

    I2C berry_i2c(PB_9, PB_8); // PB_9 -> SDA
    // PB_8 -> SCL

    Serial pc(SERIAL_TX, SERIAL_RX);

    void berryWrite(uint8_t addr, uint8_t reg, uint8_t data) {

    char dat_tx[2];

    dat_tx[0] = (char) reg;
    dat_tx[1] = (char) data;

    berry_i2c.write(addr, dat_tx, 2);
    }

    /*
    char berryReadACC(int addr, char cmd, ) {

    char dat_rx[2];
    berry_i2c.read(addr, dat_rx, 1);
    }

    */

    void berry_init() {
    // Enable accelerometer
    berryWrite(ACC_ADDRESS, CTRL_REG1_XM, '0b01100111'); // z,y,x axis enabled, continuous update, 100Hz data rate
    berryWrite(ACC_ADDRESS, CTRL_REG2_XM, '0b00100000'); // +/- 16G full scale

    //Enable magnetometer
    berryWrite(MAG_ADDRESS, CTRL_REG5_XM, '0b11110000'); // Temp enable, M data rate = 50Hz
    berryWrite(MAG_ADDRESS, CTRL_REG6_XM, '0b01100000'); // +/-12gauss
    berryWrite(MAG_ADDRESS, CTRL_REG7_XM, '0b00000000'); // Continuous-conversion mode

    // Enable gyro
    berryWrite(GYR_ADDRESS, CTRL_REG1_G, '0b00001111'); // Normal power mode, all axes enabled
    berryWrite(GYR_ADDRESS, CTRL_REG4_G, '0b00110000'); // Continious update, 2000 dps full scale
    }

    // Main function
    int main()
    {
    // uint8_t buf_rx[6];
    char cmd;
    char buf_rx[6];
    int accRaw[3];
    int magRaw[3];

    // init berryIMU
    berry_init();

    // infinite loop
    while(1) {

    // read from i2c

    // acc values
    cmd = (0x80 | OUT_X_L_A);

    berry_i2c.write(ACC_ADDRESS, &cmd, 1);
    berry_i2c.read(ACC_ADDRESS, buf_rx, 6);

    accRaw[0] = (int)(buf_rx[0] | (buf_rx[1] << 8));
    accRaw[1] = (int)(buf_rx[2] | (buf_rx[3] << 8));
    accRaw[2] = (int)(buf_rx[4] | (buf_rx[5] << 8));

    // Send to PC
    pc.printf("X- acc is '%d'. ", accRaw[0]);
    pc.printf("Y- acc is '%d'. ", accRaw[1]);
    pc.printf("Z- acc is '%d'. \r\n", accRaw[2]);

    // mag values
    cmd = (0x80 | OUT_X_L_M);

    berry_i2c.write(MAG_ADDRESS, &cmd, 1);
    berry_i2c.read(MAG_ADDRESS, buf_rx, 6);

    magRaw[0] = (int)(buf_rx[0] | (buf_rx[1] << 8));
    magRaw[1] = (int)(buf_rx[2] | (buf_rx[3] << 8));
    magRaw[2] = (int)(buf_rx[4] | (buf_rx[5] << 8));

    // Send to PC
    pc.printf("X- mag is '%d'. ", magRaw[0]);
    pc.printf("Y- mag is '%d'. ", magRaw[1]);
    pc.printf("Z- mag is '%d'. \r\n", magRaw[2]);

    wait(0.5);
    }

    }

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Blip, blop, bloop...