EasyManua.ls Logo

Seeed Grove Beginner Kit - Page 57

Seeed Grove Beginner Kit
71 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Software Code
Open Arduino IDE.
Download the 3-Axis Digital Accelerometer( ±2g to 16g) from Github. Click on Sketch >
Include library > Add .ZIP library, import the library into the IED.
Copy the following code, click Verify to check for syntax errors. Verify that there are no
errors, and you can upload the code.
In this program, acceleration information is sent from the sensor to Seeeduino via I2C
bus and then Seeeduino printed them onto the serial monitor. Open the serial monitor
to check the result.
//Gravity Acceleration
#include "LIS3DHTR.h"
#ifdef SOFTWAREWIRE
#include <SoftwareWire.h>
SoftwareWire myWire(3, 2);
LIS3DHTR<SoftwareWire> LIS(I2C_MODE);//IIC
#define WIRE myWire
#else
#include <Wire.h>
LIS3DHTR<TwoWire> LIS(I2C_MODE);//IIC
#define WIRE Wire
#endif
void setup() {
Serial.begin(9600);
while (!Serial) {};
LIS.begin(WIRE); //IIC init
delay(100);
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
}
void loop() {
if (!LIS) {
Serial.println("LIS3DHTR didn't connect.");
while (1);
return;
}
//3 axis
Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.prin
t(" ");
Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.prin
t(" ");
Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
delay(500);
}
56
Grove Beginner Kit For Arduino®

Other manuals for Seeed Grove Beginner Kit

Related product manuals