Problems with I2C configuration with an IMU

Hi, I'm currently doing a project where I use a Berry IMU v3 to an Arduino Pro mini 328 5V. I connected the two using the I2c interface and copied and pasted the code the manufacturer made here with no changes: BerryIMU/arduino-BerryIMU at master · ozzmaker/BerryIMU · GitHub. The problem is, when I upload the code to the Arduino, I don't get any Serial Monitor output. I am on the current baud rate but nothing inside the "loop" method of the "arduino-BerryIMU.ino" is running. I only get serial monitor output when I comment out the enableIMU() method call. There is something wrong with this function that is causing this issue but I don't what is wrong. I commented out the readFrom() method inside "IMU.cpp" because it is throwing me errors. My wiring is correct and according to the side. I checked the i2c addresses that it defined and they were correct.

The errors in "IMU.cpp" say:

warning: invalid conversion from 'byte {aka unsigned char}' to 'byte* {aka unsigned char}' [-fpermissive]

readFrom(LSM6DSL_ADDRESS,LIS3MDL_CTRL_REG3,1, temp);

initializing argument 4 of 'void readFrom(int, byte, int, byte)'

void readFrom(int device, byte address, int num, byte buff[ ]) {

With new I2C devices, the first step is to run the I2C address scanner program, to verify communications.

Pullup resistors are required on the SDA and SCL lines, but there is no standard requiring manufacturers to have these on their devices, so check that if the scanner does not detect the device.

You can probably ignore that warning.

For further questions, post ALL the code, using code tags.

Warnings != errors. Commenting out functions in a library is very rarely the method to fixing things.

Even after I uploaded the code with the warning, I still didn't get any output though

Have you run the I2C scanner to verify the IMU is hookup up properly?

    byte temp = 11;
    readFrom(LSM6DSL_ADDRESS, LIS3MDL_CTRL_REG3, 1, temp);
    Serial.print(temp);
void readFrom(int device, byte address, int num, byte buff[]) {

Whoever wrote the code is trying to pass a byte when the function is expecting a byte pointer. They are only requesting a single byte from the readFrom function, so it will fit in temp, but the function wants the address of temp, not its value.

Try this:

    byte temp = 11;
    readFrom(LSM6DSL_ADDRESS, LIS3MDL_CTRL_REG3, 1, &temp);
    Serial.print(temp);

or if I have the syntax incorrect on that, then the convoluted method of making temp a single-element array:

    byte temp[1] = {11};
    readFrom(LSM6DSL_ADDRESS, LIS3MDL_CTRL_REG3, 1, temp);
    Serial.print(temp[0]);

Looking at the function, I'm not sure they know how to use I2C on an Arduino, with the extraneous Wire.beginTransmission and Wire.endTransmission around Wire.requestFrom.

void readFrom(int device, byte address, int num, byte buff[]) {
  Wire.beginTransmission(device); //start transmission to device
  Wire.write(address);        //sends address to read from
  Wire.endTransmission(); //end transmission

  Wire.beginTransmission(device); //start transmission to device (initiate again)
  Wire.requestFrom(device, num);    // request 6 bytes from device

  int i = 0;
  while (Wire.available())   //device may send less than requested (abnormal)
  {
    buff[i] = Wire.read(); // receive a byte
    i++;
  }
  Wire.endTransmission(); //end transmission
}

It's definitely an error in this case. It just gets downgraded to a warning by the horrible -fpermissive flag Arduino uses.

Either way, it's a bug and should be fixed.

1 Like

I see the error has been reported on the repository:

Type Conversion error in base code for ArduinoBerryIMUv3 #25

Also a very old (almost 3 years) report of the improper use of the Wire library:

Usage of Wire library. #15

HI, the error went away, but still no output. When I ran the I2C scanner, it is just stuck on "Scanning...". I don't think I need pull-up resistors for my setup. My wiring is correct according to the manufacturer, I am using header pins for my Arduino and my IMU.

if you are using the scanner from the arduino site

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
 
#include <Wire.h>
 
 
void setup()
{
  Wire.begin();
 
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}
 
 
void loop()
{
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
 
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           // wait 5 seconds for next scan
}

You should get the "done" response. If that is not happening, then something is not wired properly since either SCL or SCK is most likely being held LOW, preventing the communication.

  1. I just ran the i2c scanner for my Arduino pro mini 328(5V) connected to a berry imu v3(requires 3.3V), but it's stuck at "Scanning...". I don't know what the issue is. My connections all use header pins and are correct. I don't think I need pull-up resistors for it, what could be causing this issue? The code I am using is attached.
#include <Wire.h>



void setup() {
  Serial.begin(9600);
  while (!Serial);            
  Serial.println("\nI2C Scanner");
}

void loop() {
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ ) 
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4) 
    {
      Serial.print("Unknown error at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

I have a buck converter to step-down the 5v to 3.3v btw

Hi
Ideally, you should post a schematic, (not fritzing), and photos of your montage.
See if the arduino's GND and your module's GND are connected.

I do.

Pull-up resistors required to 3V3 and the internal pull-up on the 5V system disabled.

image

The wiring looks like this

Oh so not having pull-up resistors be causing the problem?

Hi
What voltage and what I2C are you using?

I'm using the 3.3V I2C

Hi
But the photo you posted is different.

Oh my bad, I didn't notice, it's supposed to be 3.3 V sorry

Hi
Web photo does not help to find the problem.
Post a photo of your montage, not a photo copied from the web..


The voltage from VCC goes from 5V to 3.3V