PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Devices
Sensor
Accelerometer 3-Axis LIS3DH
LIS3DH Test Temperature Sensor.c
1
/*
2
LIS3DH Test Temperature Sensor.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
Notes about the Temperature Sensor:
20
21
The LIS3DH chip includes an accurate relative temperature sensor, the output of which varies by 1 digit with each 1 degree Celcius change.
22
To use the temperature sensor, it is necessary to record the ambient starting temperature,
23
which will be used by the sensor to calculate absolute temperature based on the relative output from the sensor.
24
Using Celcius is the most accurate unit,
25
as the sensor uses Celcius internally and therefore no temperature conversions are necessary which may result in conversion (rounding) errors.
26
Wrapper functions are provided for Fahrenheit calibration and temperature reading, which convert the Celcius data available from the sensor.
27
*/
28
29
#include "
simpletools.h
"
// Include simpletools header
30
#include "
lis3dh.h
"
// Include lis3dh header
31
32
#define RoomTemperature_Degrees_Celcius 23 // Room temperature calibration value - Change this value to ambient (room) temperature!
33
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 Temperature Sensor %c \r\r"
,
CLREOL
);
46
47
48
49
int
t;
50
51
LIS3DH =
lis3dh_init
(8, 7, 6);
// Initialize sensor with pins SCK, SDI, CS
52
53
54
// Set ambient (room) temperature - Use Celcius for best accuracy
55
lis3dh_tempCal_C
(LIS3DH, RoomTemperature_Degrees_Celcius);
56
// lis3dh_tempCal_F(LIS3DH, RoomTemperature_Degrees_Fahrenheit);
57
58
59
60
while
(1) {
// Continuously read from sensor and print results to debug terminal
61
62
63
print
(
"Temperature is %dC, %dF %c \r"
,
lis3dh_temp_C
(LIS3DH),
lis3dh_temp_F
(LIS3DH),
CLREOL
);
64
65
66
pause
(500);
// 1/2 second pause before repeat
67
68
print
(
"%c"
,
CRSRUP
);
// Terminal up one line
69
70
}
71
72
}
73
74
75
lis3dh_tempCal_C
void lis3dh_tempCal_C(lis3dh_t *device, int actualTempC)
Sets the actual temperature to provide a reference for the relative temperature sensor.
Definition:
temp.c:66
CLS
#define CLS
CLS character (16) clears SimpleIDE's screen, erasing all characters and placing the cursor in the to...
Definition:
simpletools.h:363
CRSRUP
#define CRSRUP
CRSRUP character (5) sends the SimpleIDE Terminal's cursor one row (carriage return) upward from its ...
Definition:
simpletools.h:267
HOME
#define HOME
HOME character (1) sends SimpleIDE Terminal's cursor to top-left "home" position.
Definition:
simpletools.h:233
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
lis3dh.h
Simplifies reading Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
term_cmd
void term_cmd(int termConst,...)
Send a command to SimpleIDE Terminal. Examples of commands include HOME, CLS, BKSP,...
Definition:
term_cmd.c:44
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
main
int main(void)
Definition:
GraphicsTest.c:20
lis3dh_init
lis3dh_t * lis3dh_init(int pinSCK, int pinSDI, int pinCS)
Initialize the sensor with typical configuration for reading axis and adc. Uses 3-Wire SPI mode.
Definition:
init.c:21
lis3dh_st
Definition:
lis3dh.h:122
lis3dh_temp_C
int lis3dh_temp_C(lis3dh_t *device)
Reads the calibrated (referenced) temperature value from the sensor.
Definition:
temp.c:48
lis3dh_temp_F
int lis3dh_temp_F(lis3dh_t *device)
Reads the calibrated (referenced) temperature value from the sensor.
Definition:
temp.c:57
CLREOL
#define CLREOL
CLREOL character (11) erases all SimpleIDE Terminal characters to the right of the cursor.
Definition:
simpletools.h:323
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17