HMC5883L driver + example
This commit is contained in:
parent
0a8c61ffb7
commit
4e7362f2d4
5 changed files with 461 additions and 0 deletions
4
examples/hmc5883l/Makefile
Normal file
4
examples/hmc5883l/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
|||
PROGRAM = hmc5883l
|
||||
EXTRA_COMPONENTS = extras/i2c extras/hmc5883l
|
||||
#ESPBAUD = 460800
|
||||
include ../../common.mk
|
41
examples/hmc5883l/main.c
Normal file
41
examples/hmc5883l/main.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Example of using HMC5883L driver
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Copyright (C) 2016 Ruslan V. Uss <unclerus@gmail.com>
|
||||
* BSD Licensed as described in the file LICENSE
|
||||
*/
|
||||
#include <esp/uart.h>
|
||||
#include <espressif/esp_common.h>
|
||||
#include <stdio.h>
|
||||
#include <i2c/i2c.h>
|
||||
#include <hmc5883l/hmc5883l.h>
|
||||
|
||||
#define SCL_PIN 5
|
||||
#define SDA_PIN 4
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
printf("SDK version:%s\n\n", sdk_system_get_sdk_version());
|
||||
|
||||
i2c_init(SCL_PIN, SDA_PIN);
|
||||
|
||||
while (!hmc5883l_init())
|
||||
printf("Device not found\n");
|
||||
|
||||
hmc5883l_set_operating_mode(HMC5883L_MODE_CONTINUOUS);
|
||||
hmc5883l_set_samples_averaged(HMC5883L_SAMPLES_8);
|
||||
hmc5883l_set_data_rate(HMC5883L_DATA_RATE_07_50);
|
||||
hmc5883l_set_gain(HMC5883L_GAIN_1090);
|
||||
|
||||
while (true)
|
||||
{
|
||||
hmc5883l_data_t data;
|
||||
hmc5883l_get_data(&data);
|
||||
printf("Magnetic data: X:%.2f mG, Y:%.2f mG, Z:%.2f mG\n", data.x, data.y, data.z);
|
||||
|
||||
for (uint32_t i = 0; i < 1000; i++)
|
||||
sdk_os_delay_us(250);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue