I am attempting to connect a 3.3V LSM6DS3 accelerometer/gyrometer to a 5V arduino nano using I2C for a school project. As a reference I have been using the following site and set-up:
https://learn.sparkfun.com/tutorials/lsm6ds3-breakout-hookup-guide/all#assembly
The equivalent from the redboard to the nano is the following:
A4 → SDA/SDI
A5 → SCL
GND → GND
3V3 → 3.3V
The following is the code I am using to read the data just to test the functionality of the sensor. The code is straight from the site I specified earlier:
/******************************************************************************
MinimalistExample.ino
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/LSM6DS3_Breakout
https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library
Description:
Most basic example of use.
Example using the LSM6DS3 with basic settings. This sketch collects Gyro and
Accelerometer data every second, then presents it on the serial monitor.
Resources:
Uses Wire.h for i2c operation
Development environment specifics:
Arduino IDE 1.6.4
Teensy loader 1.23
Hardware connections:
Connect I2C SDA line to A4
Connect I2C SCL line to A5
Connect GND and 3.3v power to the IMU
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
Please review the LICENSE.md file included with this example. If you have any questions
or concerns with licensing, please contact techsupport@sparkfun.com.
Distributed as-is; no warranty is given.
******************************************************************************/
#include "SparkFunLSM6DS3.h"
#include "Wire.h"
LSM6DS3 myIMU; //Default constructor is I2C, addr 0x6B
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
//Call .begin() to configure the IMU
myIMU.begin();
}
void loop()
{
//Get all parameters
Serial.print("\nAccelerometer:\n");
Serial.print(" X = ");
Serial.println(myIMU.readFloatAccelX(), 4);
Serial.print(" Y = ");
Serial.println(myIMU.readFloatAccelY(), 4);
Serial.print(" Z = ");
Serial.println(myIMU.readFloatAccelZ(), 4);
Serial.print("\nGyroscope:\n");
Serial.print(" X = ");
Serial.println(myIMU.readFloatGyroX(), 4);
Serial.print(" Y = ");
Serial.println(myIMU.readFloatGyroY(), 4);
Serial.print(" Z = ");
Serial.println(myIMU.readFloatGyroZ(), 4);
Serial.print("\nThermometer:\n");
Serial.print(" Degrees C = ");
Serial.println(myIMU.readTempC(), 4);
Serial.print(" Degrees F = ");
Serial.println(myIMU.readTempF(), 4);
delay(1000);
}
The serial monitor displays the following output:
Accelerometer:
X = 12.2449
Y = 12.2449
Z = 12.2449
Gyroscope:
X = 1756.4399
Y = 1756.4399
Z = 1756.4399
Thermometer:
Degrees C = 1593.2500
Degrees F = 2899.8500
So the board is reading something but I’m not sure what. The numbers don’t change when I manipulate the board. But if I change the delay, the numbers change.
No delay:
Accelerometer:
X = 5.4988
Y = 5.4988
Z = 5.4988
Gyroscope:
X = 788.7600
Y = 788.7600
Z = 788.7600
Thermometer:
Degrees C = 729.2500
Degrees F = 1344.6500
delay(5000):
Accelerometer:
X = 11.7452
Y = 11.7452
Z = 11.7452
Gyroscope:
X = 1684.7600
Y = 1684.7600
Z = 1684.7600
Thermometer:
Degrees C = 1529.2500
Degrees F = 2784.6499
I have tried troubleshooting a few ways.
- Using a code I found online for detecting devices connected in I2C
Code
// --------------------------------------
// 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
}
Results
I2C Scanner
Scanning...
No I2C devices found
- Using a previous code provided for a lab. This code had to be modified since the accelerometer was originally connected as a SPI. To change the code, the sensor was defined as an SPI and the argument was changed from a ‘0’ to a ‘1’.
#include <SparkFunLSM6DS3.h>
#include <Wire.h>
LSM6DS3 IMU;
void setup(){
Serial.begin(115200);
delay(500);
Wire.begin();
Serial.println("Testing Sensor Connections");
if(IMU.begin() != 1){
Serial.println("Error connecting to the IMU via SPI at CS=10, check connections");
}
else{
Serial.println("IMU Available!");
}
}
void loop(){}
Results
Testing Sensor Connections
IMU Available!
I honestly don’t know what this means and have no idea where to go to get this circuit to work. Any tips or advice would be extremely helpful. Thanks in advance.