-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgy85_example.cpp
65 lines (46 loc) · 1.32 KB
/
gy85_example.cpp
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
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "gy85/gy85.hpp"
// I2C defines
#define I2C_PORT i2c0
#define I2C_SDA 4
#define I2C_SCL 5
int main()
{
stdio_init_all();
gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
// I2C Initialisation. Using it at 400Khz.
i2c_init(I2C_PORT, 400*1000);
gpio_set_function(I2C_SDA, GPIO_FUNC_I2C);
gpio_set_function(I2C_SCL, GPIO_FUNC_I2C);
gpio_pull_up(I2C_SDA);
gpio_pull_up(I2C_SCL);
gpio_put(PICO_DEFAULT_LED_PIN, 1);
sleep_ms(200);
gy85 sensor;
int res = sensor.init();
if (res != PICO_OK)
{
while (true)
{
printf("Error initializing gy85\n");
sleep_ms(1000);
}
}
sensor.calibrate(20);
gpio_put(PICO_DEFAULT_LED_PIN, 0);
int status = 0;
while (1)
{
sensor.read();
printf("Accel: %f %f %f\n", sensor.get_accel().x, sensor.get_accel().y, sensor.get_accel().z);
printf("Gyro: %f %f %f\n", sensor.get_gyro().x, sensor.get_gyro().y, sensor.get_gyro().z);
printf("Mag: %f %f %f\n", sensor.get_mag().x, sensor.get_mag().y, sensor.get_mag().z);
status = !status;
gpio_put(PICO_DEFAULT_LED_PIN, status);
sleep_ms(30);
}
return 0;
}