SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the Movement & IMU category should be posted in this forum.

I have a project I am playing around with where I would like to use an IMU with a Sparkfun Pro Micro. I have some experience with Arduino's though I haven't touched them in many years and am super rusty, and find myself stuck at the first hurdle!

I have a Sparkfun 9DoF Sensor Stick and a Sparkfun Pro Micro 3.3v which I am trying to get talking to each other. I am using the example code as shown below. I changed #define LSM9DS1_SCK from A5 to A3, and #define LSM9DS1_MOSI from A4 to A2, but apart from that have kept the code unchanged. When I run it I get the error - LSM9DS1 data read demo
Oops ... unable to initialize the LSM9DS1. Check your wiring!

Not sure where I am going wrong and some help would be appreciated! When I run the original code on my RedBoard it works fine. Also when I run a simple LED Blink program on the Pro Micro it also works fine.


Moderator edit to add code tags
Code: Select all
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS1.h>
#include <Adafruit_Sensor.h>  // not used in this demo but required!

// i2c
Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1();

#define LSM9DS1_SCK A3
#define LSM9DS1_MISO 12
#define LSM9DS1_MOSI A2
#define LSM9DS1_XGCS 6
#define LSM9DS1_MCS 5
// You can also use software SPI
//Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1(LSM9DS1_SCK, LSM9DS1_MISO, LSM9DS1_MOSI, LSM9DS1_XGCS, LSM9DS1_MCS);
// Or hardware SPI! In this case, only CS pins are passed in
//Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1(LSM9DS1_XGCS, LSM9DS1_MCS);

void setupSensor()
  // 1.) Set the accelerometer range
  // 2.) Set the magnetometer sensitivity

  // 3.) Setup the gyroscope

void setup() 

  while (!Serial) {
    delay(1); // will pause Zero, Leonardo, etc until serial console opens
  Serial.println("LSM9DS1 data read demo");
  // Try to initialise and warn if we couldn't detect the chip
  if (!lsm.begin())
    Serial.println("Oops ... unable to initialize the LSM9DS1. Check your wiring!");
    while (1);
  Serial.println("Found LSM9DS1 9DOF");

  // helper to just set the default scaling we want, see above!

void loop() 
{;  /* ask it to read in the data */ 

  /* Get a new sensor event */ 
  sensors_event_t a, m, g, temp;

  lsm.getEvent(&a, &m, &g, &temp); 

  Serial.print("Accel X: "); Serial.print(a.acceleration.x); Serial.print(" m/s^2");
  Serial.print("\tY: "); Serial.print(a.acceleration.y);     Serial.print(" m/s^2 ");
  Serial.print("\tZ: "); Serial.print(a.acceleration.z);     Serial.println(" m/s^2 ");

  Serial.print("Mag X: "); Serial.print(m.magnetic.x);   Serial.print(" gauss");
  Serial.print("\tY: "); Serial.print(m.magnetic.y);     Serial.print(" gauss");
  Serial.print("\tZ: "); Serial.print(m.magnetic.z);     Serial.println(" gauss");

  Serial.print("Gyro X: "); Serial.print(g.gyro.x);   Serial.print(" dps");
  Serial.print("\tY: "); Serial.print(g.gyro.y);      Serial.print(" dps");
  Serial.print("\tZ: "); Serial.print(g.gyro.z);      Serial.println(" dps");

Hi MaxKabliafkas,

I do not understand why you are manually setting the SPI pins in your code. It should work without needing to define anything but CS since the SPI pins are hardware defined on the Pro Micro. I would recommend referring to the Graphical Datasheet for the Pro Micro to make your connections.

Also, I'm afraid we cannot help debug custom code or code that was not written and verified by SparkFun. We would be happy to help if you are using the SparkFun LSM9DS1 Library but again, you should not need to adjust the SPI definitions in the code. Simply adjust CS to whichever I/O pin you connect that to and it should work just fine on a Pro Micro.