User Guide

1/16/2018 H3LIS331DL Accelerometer Breakout Hookup Guide - learn.sparkfun.com
https://learn.sparkfun.com/tutorials/h3lis331dl-accelerometer-breakout-hookup-guide?_ga=2.255828235.2084638943.1516049849-204410570.150963…
6/7
COPY CODE
Example Code
Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time
using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library,
please check out our installation guide.
You will also need FTDI drivers installed in order to upload code to the Arduino Pro. If this is your first time using an FTDI,
make sure to follow our tutorial: USB Serial Driver Quick Install.
To follow along with the examples, the code requires the LIS331 Arduino library. Make sure that the library has been installed.
SPARKFUN LIS331 ARDUINO LIBRARY
For the most part, the example code for SPI mode and I C mode is identical. The only part that differs is the intial setup where you
configure the pins to be used and the library’s settings.
I C Mode Setup
Here’s an example of the same section of code from an I C configured system. It’s important to note that order matters
here: Wire.begin() and xl.setI2CAddr() must be called before xl.begin() .
#include "SparkFun_LIS331.h"
#include <Wire.h>
LIS331 xl;
void setup()
{
// put your setup code here, to run once:
pinMode(9,INPUT); // Interrupt pin input
Wire.begin();
2
2
2