Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
compass
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ajk1e20
compass
Commits
27b81048
Commit
27b81048
authored
3 years ago
by
ajk1e20
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
9b5d1857
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
compass.c
+62
-0
62 additions, 0 deletions
compass.c
with
62 additions
and
0 deletions
compass.c
0 → 100644
+
62
−
0
View file @
27b81048
#include
<stdio.h>
#include
"pico/stdlib.h"
#include
"lib/fonts.h"
#include
"lib/st7735.h"
#include
"lib/ICM20948.h"
// Based off the helpful guide from plaaosert (ct2g20)
void
SetupIMU
()
{
// Apparently this is important ¯\_(ツ)_/¯
i2c_init
(
i2c0
,
400
*
1000
);
gpio_set_function
(
4
,
GPIO_FUNC_I2C
);
gpio_set_function
(
5
,
GPIO_FUNC_I2C
);
gpio_pull_up
(
4
);
gpio_pull_up
(
5
);
sleep_ms
(
1000
);
IMU_EN_SENSOR_TYPE
enMotionSensorType
;
imuInit
(
&
enMotionSensorType
);
if
(
IMU_EN_SENSOR_TYPE_ICM20948
!=
enMotionSensorType
)
{
printf
(
"Failed to initialise IMU..."
);
}
printf
(
"IMU initialised!"
);
}
int
main
()
{
stdio_init_all
();
// Initialise serial in/output
setvbuf
(
stdout
,
NULL
,
_IONBF
,
0
);
// Disable line and block buffering on stdout (for serial comm.)
sleep_ms
(
1000
);
ST7735_Init
();
ST7735_FillScreen
(
ST7735_BLACK
);
SetupIMU
();
// TODO: initialize variables
float
tmp_x
=
0
.
0
f
;
float
tmp_y
=
0
.
0
f
;
float
tmp_z
=
0
.
0
f
;
char
xString
[
5
];
char
yString
[
5
];
char
zString
[
5
];
while
(
true
)
{
// TODO: read from IMU
icm20948MagRead
(
&
tmp_x
,
&
tmp_y
,
&
tmp_z
);
sprintf
(
xString
,
"%.1f"
,
tmp_x
);
sprintf
(
yString
,
"%.1f"
,
tmp_y
);
sprintf
(
zString
,
"%.1f"
,
tmp_z
);
// TODO: draw something to the LCD
ST7735_WriteString
(
5
,
20
,
xString
,
Font_16x26
,
ST7735_WHITE
,
ST7735_BLACK
);
ST7735_WriteString
(
5
,
45
,
yString
,
Font_16x26
,
ST7735_WHITE
,
ST7735_BLACK
);
ST7735_WriteString
(
5
,
65
,
zString
,
Font_16x26
,
ST7735_WHITE
,
ST7735_BLACK
);
sleep_ms
(
100
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment