-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor_test.c
More file actions
87 lines (71 loc) · 2.25 KB
/
sensor_test.c
File metadata and controls
87 lines (71 loc) · 2.25 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "lib/i2c_handler.h"
#include "sens/sht21.h"
#include "sens/adxl345_i2c.h"
#include "pico/cyw43_arch.h"
int main(){
static i2c_device_handler_t I2C_USED = {
.pin_sda = 14,
.pin_scl = 15,
.i2c_mod = i2c1,
.fi2c_khz = 100,
.init_done = false
};
static sht21_handler_t sht21_device = {
.i2c_mod = &I2C_USED,
.heater_enable = SHT21_HEATER_OFF,
.otp_enable = SHT21_DISABLE_OTP,
.resolution = SHT21_RESOLUTION_12_14,
.init_done = false
};
static adxl345_i2c_handler_t adxl345_device = {
.i2c_mod = &I2C_USED,
.init_done = false,
// Variables for calibrating sensor
.offset_x = 0.0f,
.offset_y = 0.0f,
.offset_z = 0.0f,
};
// --- Init of Serial COM-Port
stdio_init_all();
if (cyw43_arch_init()) {
printf("Wi-Fi init failed");
}
// Wait until USB is connected
/*while(!stdio_usb_connected()){
};*/
sleep_ms(10000);
// Init of device
scan_i2c_bus_for_device(&I2C_USED);
SHT21_init(&sht21_device);
ADXL345_init(&adxl345_device);
//**************Main Loop for communication*******************
//Sensor: SHT21
float hum = 0.0;
float temp = 0.0;
bool led_state = false;
//Sensor: ADXL345
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
// calibrate sensor
ADXL345_reset_offset(&adxl345_device);
calibrate_ADXL345(&adxl345_device, &adxl345_device.offset_x, &adxl345_device.offset_y, &adxl345_device.offset_z);
while (true){
hum = SHT21_get_humidity_float(&sht21_device);
temp = SHT21_get_temperature_float(&sht21_device);
printf("... RH = %f %%, T = %f K\n", hum, temp);
if (ADXL345_get_acceleration(&adxl345_device, &x, &y, &z) == 0) {
printf("Beschleunigung: X=%.3fg, Y=%.3fg, Z=%.3fg\n", x, y, z);
} else {
printf("Fehler beim Lesen der Beschleunigung\n");
}
sleep_ms(1000);
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, led_state);
led_state = !led_state;
};
return 0;
}