Skip to content

Commit 3f120b0

Browse files
committed
LIS3DH Library and Examples for block dev
1 parent 3b45cd3 commit 3f120b0

File tree

92 files changed

+12001
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

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

0 commit comments

Comments
 (0)