Skip to content

Commit 53a9cd6

Browse files
committed
lis3dh library code example updates for tilt functions added
v1.4.139
1 parent 78806ec commit 53a9cd6

14 files changed

+105
-73
lines changed

Learn/Examples/Devices/Sensor/Accelerometer 3-Axis LIS3DH/LIS3DH Test ADC mV.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
/*
22
LIS3DH Test ADC mV.c
33
4-
Test Harness for the Parallax LIS3DH 3 Axis Accelerometer module with ADC.
5-
64
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
75
8-
96
I/O Pins connections:
107
118
P8 -> CLK (SCK)
129
P7 <-> DATA (SDI)
1310
P6 -> /ENABLE (CS)
14-
1511
1612
Instructions:
1713
1814
Connect LIS3DH module to Propeller using the pins shown above
1915
Also connect 3.3V and GND to the LIS3DH module
2016
Upload this code to the Propeller
2117
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
22-
2318
2419
Apply voltage to measure to any of the three ADC inputs:
2520
@@ -30,9 +25,6 @@
3025
3126
Note: Voltages lower or higher than the acceptable range will be rounded to
3227
the minimum or maximum range value. Do NOT exceed 2.5VIN on AD2 or AD3.
33-
34-
35-
3628
*/
3729

3830
#include "simpletools.h" // Include simpletools header

Learn/Examples/Devices/Sensor/Accelerometer 3-Axis LIS3DH/LIS3DH Test ADC.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
/*
22
LIS3DH Test ADC.c
33
4-
Test Harness for the Parallax LIS3DH 3 Axis Accelerometer module with ADC.
5-
64
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
75
8-
96
I/O Pins connections:
107
118
P8 -> CLK (SCK)
129
P7 <-> DATA (SDI)
1310
P6 -> /ENABLE (CS)
14-
1511
1612
Instructions:
1713
@@ -26,7 +22,6 @@
2622
AD1 (Sip header, accepts 0-8 VDC)
2723
AD2 (PCB top pad, accepts 900mV - 1800mV)
2824
AD3 (PCB top pad, accepts 900mV - 1800mV)
29-
3025
*/
3126

3227
#include "simpletools.h" // Include simpletools header

Learn/Examples/Devices/Sensor/Accelerometer 3-Axis LIS3DH/LIS3DH Test Acceleration.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
/*
22
LIS3DH Test Acceleration.c
33
4-
Test Harness for the Parallax LIS3DH 3 Axis Accelerometer module with ADC.
5-
64
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
75
8-
96
I/O Pins connections:
107
118
P8 -> CLK (SCK)
129
P7 <-> DATA (SDI)
1310
P6 -> /ENABLE (CS)
1411
15-
1612
Instructions:
1713
1814
Connect LIS3DH module to Propeller using the pins shown above
1915
Also connect 3.3V and GND to the LIS3DH module
2016
Upload this code to the Propeller
2117
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
22-
2318
*/
2419

2520
#include "simpletools.h" // Include simpletools header

Learn/Examples/Devices/Sensor/Accelerometer 3-Axis LIS3DH/LIS3DH Test Range.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
/*
22
LIS3DH Test Range.c
33
4-
Test Harness for the Parallax LIS3DH 3 Axis Accelerometer module with ADC.
5-
64
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
75
8-
96
I/O Pins connections:
107
118
P8 -> CLK (SCK)
129
P7 <-> DATA (SDI)
1310
P6 -> /ENABLE (CS)
1411
15-
1612
Instructions:
1713
1814
Connect LIS3DH module to Propeller using the pins shown above
1915
Also connect 3.3V and GND to the LIS3DH module
2016
Upload this code to the Propeller
2117
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
22-
2318
2419
Notes:
2520
@@ -29,9 +24,6 @@
2924
Higher values are less sensitive but with a larger total measurement range.
3025
3126
Valid values are 2, 4, 8 or 16 representing g-Force ranges of +/- 2, +/-4, +/- 8, +- 16 g.
32-
33-
34-
3527
*/
3628

3729
#include "simpletools.h" // Include simpletools header

Learn/Examples/Devices/Sensor/Accelerometer 3-Axis LIS3DH/LIS3DH Test Resolution.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
/*
22
LIS3DH Test Resolution.c
33
4-
Test Harness for the Parallax LIS3DH 3 Axis Accelerometer module with ADC.
5-
64
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
75
8-
96
I/O Pins connections:
107
118
P8 -> CLK (SCK)
129
P7 <-> DATA (SDI)
1310
P6 -> /ENABLE (CS)
1411
15-
1612
Instructions:
1713
1814
Connect LIS3DH module to Propeller using the pins shown above
1915
Also connect 3.3V and GND to the LIS3DH module
2016
Upload this code to the Propeller
2117
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
22-
2318
2419
Notes:
2520
2621
Resolution options are 8, 10 or 12-bit for accelerometer readings
2722
and 8 or 10-bit for ADC readings
28-
29-
3023
*/
3124

3225
#include "simpletools.h" // Include simpletools header

Learn/Examples/Devices/Sensor/Accelerometer 3-Axis LIS3DH/LIS3DH Test SPI 3-Wire Init.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
/*
22
LIS3DH Test SPI 3-Wire Init.c
33
4-
Test Harness for the Parallax LIS3DH 3 Axis Accelerometer module with ADC.
5-
64
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
75
8-
96
I/O Pins connections:
107
118
P8 -> CLK (SCK)
129
P7 <-> DATA (SDI)
1310
P6 -> /ENABLE (CS)
1411
15-
1612
Instructions:
1713
1814
Connect LIS3DH module to Propeller using the pins shown above
1915
Also connect 3.3V and GND to the LIS3DH module
2016
Upload this code to the Propeller
2117
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
22-
23-
24-
2518
*/
2619

2720
#include "simpletools.h" // Include simpletools header

Learn/Examples/Devices/Sensor/Accelerometer 3-Axis LIS3DH/LIS3DH Test SPI 4-Wire Init.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
/*
22
LIS3DH Test SPI 4-Wire Init.c
3-
4-
Test Harness for the Parallax LIS3DH 3 Axis Accelerometer module with ADC.
5-
3+
64
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
7-
8-
5+
96
I/O Pins connections:
107
118
P8 -> CLK (SCK)
129
P7 -> DATA (SDI)
1310
P6 <- DATA (SDO)
1411
P5 -> /ENABLE (CS)
15-
16-
12+
1713
Instructions:
1814
1915
Connect LIS3DH module to Propeller using the pins shown above
2016
Also connect 3.3V and GND to the LIS3DH module
2117
Upload this code to the Propeller
2218
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
23-
24-
25-
2619
*/
2720

2821
#include "simpletools.h" // Include simpletools header

Learn/Examples/Devices/Sensor/Accelerometer 3-Axis LIS3DH/LIS3DH Test Temperature Sensor.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
/*
22
LIS3DH Test Temperature Sensor.c
33
4-
Test Harness for the Parallax LIS3DH 3 Axis Accelerometer module with ADC.
5-
64
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
75
8-
96
I/O Pins connections:
107
118
P8 -> CLK (SCK)
129
P7 <-> DATA (SDI)
1310
P6 -> /ENABLE (CS)
1411
15-
1612
Instructions:
1713
1814
Connect LIS3DH module to Propeller using the pins shown above
1915
Also connect 3.3V and GND to the LIS3DH module
2016
Upload this code to the Propeller
2117
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
2218
23-
2419
Notes about the Temperature Sensor:
2520
2621
The LIS3DH chip includes an accurate relative temperature sensor, the output of which varies by 1 digit with each 1 degree Celcius change.
@@ -29,8 +24,6 @@
2924
Using Celcius is the most accurate unit,
3025
as the sensor uses Celcius internally and therefore no temperature conversions are necessary which may result in conversion (rounding) errors.
3126
Wrapper functions are provided for Fahrenheit calibration and temperature reading, which convert the Celcius data available from the sensor.
32-
33-
3427
*/
3528

3629
#include "simpletools.h" // Include simpletools header
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
LIS3DH Test Tilt Angles.c
3+
4+
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
5+
6+
I/O Pins connections:
7+
8+
P8 -> CLK (SCK)
9+
P7 <-> DATA (SDI)
10+
P6 -> /ENABLE (CS)
11+
12+
Instructions:
13+
14+
Connect LIS3DH module to Propeller using the pins shown above
15+
Also connect 3.3V and GND to the LIS3DH module
16+
Upload this code to the Propeller
17+
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
18+
*/
19+
20+
#include "simpletools.h" // Include simpletools header
21+
#include "lis3dh.h" // Include lis3dh header
22+
23+
lis3dh *LIS3DH;
24+
25+
int main() // Main function
26+
{
27+
28+
pause(1000); // Start-up pause for debug terminal
29+
term_cmd(CLS);
30+
term_cmd(HOME);
31+
32+
print("Parallax LIS3DH 3 Axis Accelerometer module with ADC %c \r", CLREOL);
33+
print("Test Tilt Angles (Degrees from each Axis) %c \r\r", CLREOL);
34+
print("Motion value is with reference to gravity, %c with 0 being motionless at ground level. %c \r\r", LF, CLREOL);
35+
36+
37+
int x, y, z, motion;
38+
39+
LIS3DH = lis3dh_init(8, 7, 6); // Initialize sensor with pins SCK, SDI, CS
40+
41+
//lis3dh_tiltConfig(LIS3DH, 0); // Optional config, to disable or configure tilt sensor low-pass filter
42+
43+
44+
while(1) { // Continuously read from sensor and print results to debug terminal
45+
46+
if (lis3dh_tilt(LIS3DH, &x, &y, &z, &motion)) { // XYZ Data Available
47+
48+
print(" tilt : x = %d, y = %d, z = %d, motion = %d%c \r",
49+
x, y, z, motion, CLREOL ); // Display measurements
50+
51+
} else {
52+
53+
print("No xyz data %c \r\r", CLREOL );
54+
55+
}
56+
57+
58+
pause(500); // 1/2 second pause before repeat
59+
60+
print("%c", CRSRUP); // Terminal up one line
61+
62+
}
63+
64+
}
65+
66+
67+
68+
/**
69+
* TERMS OF USE: MIT License
70+
*
71+
* Permission is hereby granted, free of charge, to any person obtaining a
72+
* copy of this software and associated documentation files (the "Software"),
73+
* to deal in the Software without restriction, including without limitation
74+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
75+
* and/or sell copies of the Software, and to permit persons to whom the
76+
* Software is furnished to do so, subject to the following conditions:
77+
*
78+
* The above copyright notice and this permission notice shall be included in
79+
* all copies or substantial portions of the Software.
80+
*
81+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
82+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
83+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
84+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
85+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
86+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
87+
* DEALINGS IN THE SOFTWARE.
88+
*/
89+
90+
91+
92+
93+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
LIS3DH Test Tilt Angles.c
2+
>compiler=C
3+
>memtype=cmm main ram compact
4+
>optimize=-Os
5+
>-m32bit-doubles
6+
>-fno-exceptions
7+
>-lm
8+
>BOARD::ACTIVITYBOARD

0 commit comments

Comments
 (0)