-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathRAK1904_Accelerate_LIS3DH.ino
72 lines (64 loc) · 1.41 KB
/
RAK1904_Accelerate_LIS3DH.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
@file RAK1904_Accelerate_LIS3DH.ino
@author rakwireless.com
@brief Setup and read values from a lis3dh sensor
@version 0.1
@date 2020-12-28
@copyright Copyright (c) 2020
**/
#include <Arduino.h>
#include "SparkFunLIS3DH.h" //http://librarymanager/All#SparkFun-LIS3DH
#include <Wire.h>
LIS3DH SensorTwo(I2C_MODE, 0x18);
void lis3dh_read_data()
{
// read the sensor value
uint8_t cnt = 0;
Serial.print(" X(g) = ");
Serial.println(SensorTwo.readFloatAccelX(), 4);
Serial.print(" Y(g) = ");
Serial.println(SensorTwo.readFloatAccelY(), 4);
Serial.print(" Z(g)= ");
Serial.println(SensorTwo.readFloatAccelZ(), 4);
}
void setup()
{
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
if (SensorTwo.begin() != 0)
{
Serial.println("Problem starting the sensor at 0x18.");
}
else
{
Serial.println("Sensor at 0x18 started.");
// Set low power mode
uint8_t data_to_write = 0;
SensorTwo.readRegister(&data_to_write, LIS3DH_CTRL_REG1);
data_to_write |= 0x08;
SensorTwo.writeRegister(LIS3DH_CTRL_REG1, data_to_write);
delay(100);
data_to_write = 0;
SensorTwo.readRegister(&data_to_write, 0x1E);
data_to_write |= 0x90;
SensorTwo.writeRegister(0x1E, data_to_write);
delay(100);
}
Serial.println("enter !");
}
void loop()
{
lis3dh_read_data();
delay(1000);
}