Working with the Sparkfun Photon IMU Shield

Anyone have experience working with the Sparkfun Photon IMU Shield?

I’m having issues with the library for the IMU and there’s very little/nothing on this on the Internet. I’m doing a Master’s project and this hardware part of the project is the most frustrating since I can’t even get a simple reading from the IMU using the sample code (it just ends up sending my Photon into an endless breathing green state). Maybe I’m just missing something basic, but there doesn’t seem to be anywhere to bounce ideas on this. I would love to create an informal discussion that could serve as a guide for first-timers using the Photon and IMU Shield.

Did you look at their product page for resources? https://learn.sparkfun.com/tutorials/photon-imu-shield-hookup-guide?_ga=1.207958993.213298261.1438358873#introduction

Are you seeing anything via the Serial port?

Yeah, I checked out al of those resources and followed that hookup guide. I just started seeing stuff come back on the Serial Port (I have a Mac with OS X El Captain - so I decided to switch over to a Windows 7 Desktop).

When I run the sample code, it fails in the setup function. The imu.begin() comes back false and I see the message come back on Serial (“Failed to communicate with LSM9DS1. Double Check Wiring. Default settings will work for out of the box LSM9DS1.”). I bought the photon with shield and IMU with shield so all I did was plug them in together like legos. They are being powered by a USB. Is there something I’m missing? I’m using the I2C example and haven’t modified by IMU since taking it out of the box.

Could my IMU by faulty?

Did you attach the Photon in the correct direction?

1 Like

Yep - just matched up the pin names with the Photon and the IMU.

I explored my issue a little further and found out that the firmware is failing inside the begin() function in the library.

I added a couple of Serial.println() statements to help debug and here’s what I found.

  • The code is using I2C mode - which is what I expected and just wanted
    to verify. From the tutorial I’m using, it sounds like the Photon
    IMU is by default set in I2C mode, so I’m good here.
  • uint8_t mTest = mReadByte(WHO_AM_I_M); is returning 255 - I’m not sure what I should
    expect here.
  • uint8_t xgTest = xgReadByte(WHO_AM_I_XG); is returning 255 - I’m also not sure what I should expect here.

Most importantly,
the function is returning 0 when it hits the if (whoAmICombined…)
statement.

Any ideas on where I should go from here? Here’s the code for the begin() function from the IMU Library.

uint16_t LSM9DS1::begin()
    {
	//! Todo: don't use _xgAddress or _mAddress, duplicating memory
	_xgAddress = settings.device.agAddress;
	_mAddress = settings.device.mAddress;
	
	constrainScales();
	// Once we have the scale values, we can calculate the resolution
	// of each sensor. That's what these functions are for. One for each sensor
	calcgRes(); // Calculate DPS / ADC tick, stored in gRes variable
	calcmRes(); // Calculate Gs / ADC tick, stored in mRes variable
	calcaRes(); // Calculate g / ADC tick, stored in aRes variable
	
	// Now, initialize our hardware interface.
	if (settings.device.commInterface == IMU_MODE_I2C)	// If we're using I2C
		initI2C();	// Initialize I2C
	else if (settings.device.commInterface == IMU_MODE_SPI) 	// else, if we're using SPI
		initSPI();	// Initialize SPI
		
	// To verify communication, we can read from the WHO_AM_I register of
	// each device. Store those in a variable so we can return them.
	uint8_t mTest = mReadByte(WHO_AM_I_M);		// Read the gyro WHO_AM_I
	uint8_t xgTest = xgReadByte(WHO_AM_I_XG);	// Read the accel/mag WHO_AM_I
	uint16_t whoAmICombined = (xgTest << 8) | mTest;
	
	if (whoAmICombined != ((WHO_AM_I_AG_RSP << 8) | WHO_AM_I_M_RSP))
		return 0;
	
	// Gyro initialization stuff:
	initGyro();	// This will "turn on" the gyro. Setting up interrupts, etc.
	
	// Accelerometer initialization stuff:
	initAccel(); // "Turn on" all axes of the accel. Set up interrupts, etc.
	
	// Magnetometer initialization stuff:
	initMag(); // "Turn on" all axes of the mag. Set up interrupts, etc.
	
	// Once everything is initialized, return the WHO_AM_I registers we read:
	return whoAmICombined;
}

@u2pride, I just grabbed the Sparkfun files for the IMU board from their github, fixed the IDE-specific #include path, compiled the I2C basic example and flashed over to a Photon configured for the latest develop system firmware (0.4.7). I then plugged it in to the IMU shield and it worked flawlessly with data streaming over the USB serial. So, perhaps we need to look at your shield. Any chance you can take pictures of the shield without the photon, both sides?

@peekay123 thanks for checking on this. I did the same thing with my IMU and it didn’t work. Here are some pictures. See anything strange? How do I go about getting a replacement?

@u2pride, if you powering via the Photon USB port, make sure you use a good power supply. What are you using?

1 Like

I think one problem is that @u2pride tries the SPI demo while @peekay123 tried the I2C one.

I can also confirm, that the I2C one works, but the SPI one does not.

The main reason for this is mentioned in the docs @kennethlimcp linked above

One other reasons even after setting SPI might well be this part of the demo

///////////////////////
// Example SPI Setup //
///////////////////////
// Define the pins used for our SPI chip selects. We're
// using hardware SPI, so other signal pins are set in stone.
#define LSM9DS1_M_CS	10 // Can be any digital pin
#define LSM9DS1_AG_CS	9  // Can be any other digital pin

There is no pin 9 on any Particle devices so far.
I’ve already opened an issue about this on the SparkFun GitHub repo.
https://github.com/sparkfun/SparkFun_LSM9DS1_Particle_Library/issues/1

The I2C Sparkfun example worked out of the box for me, with no changes whatsoever.

@peekay123 I’m using a desktop PC to power it via USB.

@ScruffR I’ve made sure to use the I2C one. I’m lost as to what could be the issue.

:blush: I just focused on this part of the code snippet you provided and didn’t read the rest :blush:

@u2pride, how are you flashing your Photon? Via Web IDE or otherwise?

If your Photon is still running an “old” system firmware there was some I2C issue, but if you flash via Web IDE and make sure to select 0.4.7 as target firmware (as Paul mentioned) than this can be ruled out too.

(grabbing straws here)

But if you really should have a hardware issue and you ordered the shield of :particle: Particle, then you can shoot them a mail at hello [AT] particle.io and refer to this thread.

@ScruffR flashing via the Web IDE mainly. It’s running the latest firmware from my understanding. Thanks for trying to sort this out. I ordered from Sparkfun.

Hmm - I don’t know how SparkFun is about replacements :confused:

But if you have no spare shield and/or Photon to try, have you got a way to check the I2C signals with a logic analyzer or oszillograph?
And see if the signal levels at the shield jumpers are as they are described in their docs.

@ScruffR Gotcha. Although I have a background in EE, I really need to focus on moving forward on my project - this has been really frustrating because of how much time it’s wasted. Thanks for the help though!

1 Like

Too bad!

But if you need these things working for your project you will have to figure it somehow.
The good thing is that you now got three people reporting that it should be a piece of cake when you got working devices. Maybe you safe time by spending extra money on a new shield and maybe a Photon.

Yeah, I’m thinking about my options now. Thanks for the help.