I2C and an MMA8452 accelerometer

Hi! I have a pair of shiny new spark cores and really like the system but am having a little trouble with them. I am trying to interface with an MMA8452 accelerometer using I2C and the relevant library available in the online IDE (MMA8452-Accelerometer-Library-Spark-Core). No matter what I do, I seem to get stuck with a ‘breathing’ cyan LED and the spark going offline. From there I have to factory reset it and set the thing up with the wifi network again. It seems to happen after instantiating an MMA8452Q object (calling it “accel”), around the point of making an accel.init(SCALE_2G, ODR_800) call.

I have searched the forums and haven’t managed to find a solution, is it possible that something isn’t finishing in the I2C code and blocking the loop() from maintaining the connection to the IDE/cloud?

I would be happy to provide more information but am not sure exactly what would be relevant. Any help would be appreciated, cheers!

Are you using a Sparkfun MMA8452 board or your own MMA8452 soldered ? Do you have the pull-up resistors to the SCL and SDA lines ? Just checking …


Oh pull-ups, of course! Last time I used the accelerometer it was on a different platform that included them internally so I forgot about them this time. I’m using the Sparkfun breakout. That seems to have been the problem, thank you very much! Like the proverbial “have you tried turning it off and on again?”, it’s always worth starting from the basics when helping someone troubleshoot :).

But if you are using this breakout board it would already bring its own 4k7 pullups on-board.
So I guess there must still be something else :wink:

Can you maybe provide a photo of your setup?

Are you using your own code or one of the samples provided along with the library?

I sometimes have problems with my power supply when using a similar I2C device. Not because of the power consumption but due to voltage quality. When I use a different power source (e.g. a selfpowered USB hub, if I need the serial output on my PC) the problem goes away.

Hmm, you are very right. After bhamadicharef’s response I put a couple of pull-ups in there and it started working so I didn’t think any more about it. Now it continues working even if I take them back out again and I can only reproduce the problem by disconnecting the accelerometer completely. It might have been something as simple as a dodgy connection in the breadboard but I think that is unlikely because I unplugged and plugged in all of the wires a few times over the course of trying to debug.

The power supply is from a single USB port on the computer, the accelerometer supplied by the 3V3 pin of the Spark Core. Before my original post I had already tried powering it from the 3V3* pin and from a completely separate USB port. I used a different device that has worked with it before to supply 3.3 V in case the Spark was unstable or unable to supply enough current or something.

It seems to be working reliably now so it’s not really a problem but it would be interesting to know if there was a reason further than a dodgy connection. Thank you for the help so far! I dunno if you want to follow it up any further but since you asked, here are a couple of photographs:



Hi, I’ve copied this setup, I’m having the same problem ! After uploading the code, nothing is presented in the serial port, the loop isn’t run at all. The spark needs to be factory reset as well as you mentioned in your first post. I don’t know what to do. I’m using

I just copied the break out board example and uploaded it to the spark core.
I’ve tried with a few different pull up resistors. They didn’t seem to help ? could it be a possbility that the accelerometer is damage ?

@Kevinruder, I suggest you run the I2C scanner to “find” the I2C address of the MMA8452, if it is there:


If the MMA8452 is not found, try using 4.7K ohm pull-ups (to 3.3v) and check you I2C lines to make sure they are correctly connected. If the MMA8452 is found, let me know which address it was found at. :smile:

1 Like

@peekay123 I’ve run the I2C scanner and it hasn’t found any I2C devices. I’m at home right now so I don’t have 4.7k resistors atm - could I use a larger/smaller value by any chance ? If not then I’ll wait till I get to the university tomorrow before trying again

@Kevinruder, any value between 2.2K and 10K should do.

1 Like

I’ve added 10k resistors to the SDA and SCL but the scanner still won’t find anything… could the accelerometer be damaged ? @peekay123

@Kevinruder, from your picture, you seem to have two red wires - one for 3.3V and the other for SCL. Make sure they are not reversed! Also make sure your solder joints on the breakout are good. How long are your wires?

I would say my wires are probably around 30cm / 12 inches… I double checked the wires they’re in the right position and the soldering seems to be pretty solid! @peekay123

@Kevinruder, can you measure the voltage at the 3.3v terminal of the breakout? Also, with the I2C wires disconnected from the Core, you should read 3.3V on both SDA and SCL of the breakout (from the onboard pull-up resistors). The wires should be ok but you may want to test with shorter wires. Do you have another I2C device you can test with the I2C scanner just to be sure?

So I’ve hooked up another accelerometer to the spark, this time however, the wires aren’t soldered. The result is the same tho, nothing was found. I’ll measure the voltage when I get to the university and I’ll get back to you :smiley: thanks for the help so far tho @peekay123

@Kevinruder, when you say “not soldered”, do you mean there is a header on the breakout which you then inserted into the breadboard?

I just kind of twisted the wires around the openings - it’s the same kind of breakout board i posted above

@Kevinruder, ouch! That is not a very reliable. Any chance you can solder a header and plug the breakout into your protoboard?

@peekay123 :sunny: Yea, I’ll need to go to the lab though - Once i get there, I’ll solder the second breakout board and I’ll measure the voltages aswell and I’ll get back to you !

1 Like

meanwhile, if you have (or have access to) an arduino, you can double check to verify the breakout board’s I2C address.

to @peekay123 's point, a good electrical connection is key.

@BulldogLowell, good point on the Arduino. The I2C scanner code is easily adaptable to the Arduino platform by uncommenting the #include <Wire.h> line :smile: