Use LIS3DH with Electron

Hi there,

Can I connect LIS3DH accelerometer directly to my Electron device?

I see there is a related library available in Particle Build. But I don’t know how to use it.

Any information will be appreciated.

What do you want to use the accelerometer for? If you only want to use it for waking on movement, there are three options. If you actually want to use the other features like orientation detection or the XYZ readings, there are fewer options (or you need to write some code).

The AssetTracker for the Electron has a LIS3DH on board. The current version of the AssetTracker library has an example that uses wake on move on the LIS3DH.

My library (LIS3DH, on github: only implements the wake on move, but has all of the stuff you would need to implement the other things. I’m in the process of adding the other features, but it will probably be a week or so, unless i get distracted by something else, in which case it could take longer to get the other features.

Finally, the Adafruit sensor library and LIS3DH driver work with minimal porting. That’s actually what’s inside the AssetTracker library.

1 Like

Thank you very much.

I see your library. Can you tell me how to use your library?

I have no AssetTracker, only a LIS3DH connected to my Electron device.

The following is my connections:

Acc. pin labeled 3Vo to the electron 3.3 pin.

Acc. pin labeled GND to any electron GND pin.

Acc. pin labeled SCL to electron pin labeled C5

Acc. pin labeled SDA to electron pin labeled C4

The LIS3DH can be configured for SPI mode or I2C mode. I’ve only ever used the SPI mode because that’s how it’s connected on the AssetTracker. I have a standalone LIS3DH breakout board on order, as I was going to add I2C support but have not done so yet.

You’ll have to either switch to SPI, wait for a week or so, or port the Adafruit LIS3DH driver yourself to use it right now.

I need to use I2C mode. I will wait for your adding I2C support.


I released a new version of my LIS3DH driver:

It’s in the community libraries as version 0.1.0. The API changed a little, but it’s a minor change and so few people used the old API it wasn’t worth keeping backward compatibility.

It supports I2C as well as SPI, and I tested it using the Wire1 interface on the Electron (pins C4 and C5) and it works well.

Also, I finally figured out the mysteries of the reference calibration feature so now wake-on-move works regardless of orientation. Every time you shake to wake it recalibrate when you set it down so it works even if you set it down on its side now.


Thanks for your library.

I can compile and flash your I2C example code to my Electron device (version 0.5.1) successfully. But I cannot get any serial output using “particle serial monitor”. It crashes shortly.

➜  Downloads particle serial monitor
Opening serial monitor for com port: "/dev/cu.usbmodem1411"
[1]    43818 segmentation fault  particle serial monitor

The code I am using is:

How can I debug this type of problem?

Thanks again.

You could try any other serial terminal program - e.g. putty

I am using Mac, no Putty. And I can get serial output correctly with other firmwares.

Then I guess Coolterm does exist

I am using iTerm2. I am going to try Coolterm now. I hope it will make differences.

What does iTerm2 do when you watch the serial output?
Before you only mentioned particle serial monitor crashing, which would have suggested an issue with CLI and not necessarily with the firmware.

Cannot get any serial output with Coolterm.

But you can see output of other firmware with CoolTerm or iTerm2?


What value pull-ups are you using on the I2C lines?
Could you try upgrading your Electron ot 0.5.2 (or even 0.6.0-rc.2 to get the most recent bug fixes)?

You could add this to your test code

void waitForSerial()
  pinMode(D7, OUTPUT);
  while( < 0); // waits for any byte to arrive via USB Serial
  digitalWrite(D7, HIGH);
  Serial.println("Ready to go");


That’s very odd. I wrote the code on a Mac and I just re-tested it with an Electron (G350) and an external I2C LIS3DH on Wire1 (C4/C5) and the particle serial monitor displayed the output with no difficulties. I tested it with 0.4.8, 0.5.1 and 0.5.2 on the Electron.

You could also try screen, which is built-in on the Mac. Open a new terminal window first, because it’s hard to get rid of screen, then just do:

screen /dev/cu.usbmodem1411

It’s very strange. But I can get output now with the screen command.

Ready to go
device not found
no sample
no sample
no sample
no sample

If the device is not found, there are two big things with I2C: The pull-up resistors as ScruffR mentioned, are required. Most breakout boards like the Adafruit one I used have them built-in, but if you’re using a chip directly you’ll probably need 10K pull-up resistors to 3V3 on C4 and C5.

The other is the SD0/SA0 pin. The Adafruit breakout a pull-down resistor on this pin. If you’re using a bare chip you’ll need to tie this pin (pin 7) to either 3V3 or GND. If you tie it to 3V3 you need to change the second parameter to the LIS3DHI2C constructor to 1 to use I2C addresses 0x32 and 0x33 instead of 0x30 and 0x31.

It works great now. I made the wrong connections. SCL should connect C5 (Wire1, on Electron only) and SDA to C4 (Wire1, on Electron only).

@rickkas7 @ScruffR Thank you very much.