-
Notifications
You must be signed in to change notification settings - Fork 144
Jeetrohan mpu60xx 1 (BSP-568) #416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeetrohan
wants to merge
11
commits into
espressif:master
Choose a base branch
from
jeetrohan:jeetrohan-mpu60xx-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9c5b6d4
mpu60xx.h
jeetrohan c25ac3c
mpu60xx CMakeLists.txt
jeetrohan b3d079a
mpu60xx.c
jeetrohan 94bba26
Create idf_component.yml
jeetrohan dca48cc
mpu_motion_detect.c
jeetrohan 9562071
idf_component.yml
jeetrohan 6d8b0c6
CMakeLists.txt
jeetrohan 5b8d560
CmakeLists.txt
jeetrohan 13d9955
README.md
jeetrohan 71d132c
Merge branch 'espressif:master' into jeetrohan-mpu60xx-1
jeetrohan ee64ad9
Merge branch 'master' into jeetrohan-mpu60xx-1
jeetrohan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
idf_component_register(SRCS "mpu60xx.c" | ||
INCLUDE_DIRS "include") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# mpu60xx | ||
I2C driver for MPU60xx family IMU. | ||
|
||
## Features | ||
- Read Accelerometer, Gyrometer and Temperature sensor as raw or floating values. | ||
- Use in-buit Motion Detection feature using either interrupt or polling. | ||
|
||
## Limitations | ||
- Does NOT support esp-idf Legacy I2C driver (documentation indicates it'll be removed in future releases). | ||
- Not tested with MPU6000. ( TRM indicates it should also work, same register set as MPU6050.) | ||
- Supports only I2C protocol ( Only MPU6000 has SPI capability.) | ||
|
||
## Important Note | ||
- Use deferred processing to handle interrupts from MPU60xx, I2C driver require interrupt to read/write (see example). | ||
- INT pin of MPU60xx is required to be connected to esp32 gpio for interrupt. | ||
|
||
## Feature for next release (planned) | ||
MPU60xx has many more features which haven't been implemented in this library currently, but are planned to be added in further releases. The next intended feature is | ||
- Zero motion detection. | ||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# For more information about build system see | ||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html | ||
# The following five lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
set(COMPONENTS main) | ||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(mpu60xx_motion_detect) | ||
jeetrohan marked this conversation as resolved.
Show resolved
Hide resolved
|
2 changes: 2 additions & 0 deletions
2
components/mpu60xx/examples/mpu_motion_detect/main/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
idf_component_register(SRCS "mpu60xx_motion_detect.c" | ||
INCLUDE_DIRS ".") |
18 changes: 18 additions & 0 deletions
18
components/mpu60xx/examples/mpu_motion_detect/main/idf_component.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## IDF Component Manager Manifest File | ||
dependencies: | ||
## Required IDF version | ||
idf: | ||
version: ">=4.1.0" | ||
# # Put list of dependencies here | ||
mpu60xx: | ||
version: "*" | ||
# # For components maintained by Espressif: | ||
# component: "~1.0.0" | ||
# # For 3rd party components: | ||
# username/component: ">=1.0.0,<2.0.0" | ||
# username2/component2: | ||
# version: "~1.0.0" | ||
# # For transient dependencies `public` flag can be set. | ||
# # `public` flag doesn't have an effect dependencies of the `main` component. | ||
# # All dependencies of `main` are public by default. | ||
# public: true |
122 changes: 122 additions & 0 deletions
122
components/mpu60xx/examples/mpu_motion_detect/main/mpu_motion_detect.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* mpu60xx.h | ||
* | ||
* Created on: 15-Oct-2024 | ||
* Author: rohan | ||
*/ | ||
|
||
#include "freertos/FreeRTOS.h" | ||
#include "mpu60xx.h" | ||
|
||
|
||
|
||
//i2c configuration values | ||
#define I2C_MASTER_SCL_IO (22) // SCL pin | ||
#define I2C_MASTER_SDA_IO (21) // SDA pin | ||
#define I2C_MASTER_NUM I2C_NUM_0 | ||
#define I2C_MASTER_FREQ_HZ (100000) // I2C frequency | ||
|
||
#define MPU_INTERRUPT_PIN (23) | ||
|
||
|
||
|
||
i2c_master_bus_handle_t my_bus_handle; | ||
i2c_master_dev_handle_t my_mpu_60xx_handle; | ||
|
||
TaskHandle_t handler_task; | ||
static SemaphoreHandle_t s_bin_sem; | ||
|
||
#define ESP_INTR_FLAG_DEFAULT 0 | ||
|
||
|
||
|
||
void i2c_master_init(void) { | ||
i2c_master_bus_config_t i2c_mst_config = { | ||
.clk_source = I2C_CLK_SRC_DEFAULT, | ||
.i2c_port = I2C_MASTER_NUM , | ||
.scl_io_num = I2C_MASTER_SCL_IO, | ||
.sda_io_num = I2C_MASTER_SDA_IO, | ||
.glitch_ignore_cnt = 7, | ||
.flags.enable_internal_pullup = true, | ||
}; | ||
printf("requesting i2c bus handle\n"); | ||
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &my_bus_handle)); | ||
printf("i2c bus handle acquired\n"); | ||
|
||
|
||
} | ||
|
||
volatile uint32_t count =0; | ||
void intr_isr_handler(void * arg) | ||
{ | ||
//vTaskResume(handler_task); | ||
BaseType_t xHigherPriorityTaskWoken = pdFALSE; | ||
xSemaphoreGiveFromISR(s_bin_sem, &xHigherPriorityTaskWoken); | ||
} | ||
|
||
void read_data(void * mpu_handle){ | ||
|
||
mpu60xx_reading_t sensor_data; | ||
mpu60xx_handle_t my_dev_handle = *(mpu60xx_handle_t*)mpu_handle; | ||
bool status; | ||
while (1) { | ||
|
||
if(xSemaphoreTake(s_bin_sem, 20/portTICK_PERIOD_MS) == pdPASS){ | ||
ESP_ERROR_CHECK( mpu60xx_read_sensor (my_dev_handle , &sensor_data )); | ||
printf("aX = %.3f m/s, aY = %.3f m/s, aZ = %.3f m/s, t=%.3f C, gX = %.3f dps gY = %.3f dps gZ = %.3f dps\n", sensor_data.accX, sensor_data.accY, sensor_data.accZ, sensor_data.temperature,sensor_data.gyroX, sensor_data.gyroY, sensor_data.gyroZ); | ||
ESP_ERROR_CHECK(mpu60xx_getMotionInterruptStatus(my_dev_handle,&status)); | ||
} | ||
} | ||
} | ||
|
||
|
||
void app_main(void) { | ||
|
||
//static const mpu60xx_reading sensor_data; | ||
i2c_master_init(); | ||
|
||
mpu60xx_init_config_t mpu_6050_config = | ||
{ | ||
.scl_speed_hz = I2C_MASTER_FREQ_HZ, | ||
.gyro_res= MPU60XX_RANGE_500_DEG, | ||
.accel_res = MPU60XX_RANGE_8_G, | ||
.temp_sensor=true, | ||
.dlpf_bw =MPU60XX_BAND_94_HZ, | ||
.sample_rate= 200 | ||
}; | ||
|
||
mpu60xx_handle_t dev_6050_handle = { | ||
.bus_handle = &my_bus_handle, | ||
.dev_handle = &my_mpu_60xx_handle | ||
}; | ||
|
||
printf("requesting mpu handle\n"); | ||
while (mpu60xx_init(mpu_6050_config, dev_6050_handle) != ESP_OK) | ||
vTaskDelay(200/portTICK_PERIOD_MS); | ||
printf("mpu handle acquired\n"); | ||
|
||
|
||
|
||
mpu60xx_motion_detect_config_t mot_det= | ||
{ | ||
.motion_threshold=2, | ||
.motion_duration=10, | ||
.dhpf_bw=MPU60XX_HIGHPASS_0_63_HZ | ||
}; | ||
|
||
mpu60xx_intrpt_config_t md_intr_conf = { | ||
.interrupt_pin =(gpio_num_t)MPU_INTERRUPT_PIN, | ||
.active_level = MPU60XX_INTERRUPT_PIN_ACTIVE_LOW, | ||
.pin_mode = MPU60XX_INTERRUPT_PIN_PUSH_PULL, | ||
.interrupt_latch = MPU60XX_INTERRUPT_LATCH_UNTIL_CLEARED, | ||
.interrupt_clear_behavior = MPU60XX_INTERRUPT_CLEAR_ON_STATUS_READ, | ||
.isr = intr_isr_handler | ||
}; | ||
|
||
vTaskDelay(200/portTICK_PERIOD_MS); | ||
mpu60xx_en_MotionDetection(&dev_6050_handle,&mot_det,&md_intr_conf); | ||
s_bin_sem=xSemaphoreCreateBinary(); | ||
|
||
xTaskCreate(read_data, "apna_imu_tester", 2500, &dev_6050_handle, 5, &handler_task); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## IDF Component Manager Manifest File | ||
|
||
description: MPU60xx I2C driver | ||
|
||
maintainers: | ||
- "Rohan Jeet <jeetrohan92@gmail.com>" | ||
jeetrohan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
dependencies: | ||
## Required IDF version | ||
idf: | ||
version: ">=4.1.0" | ||
jeetrohan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# # Put list of dependencies here | ||
# | ||
# # For components maintained by Espressif: | ||
# component: "~1.0.0" | ||
# | ||
esp_driver_i2c: "*" | ||
esp_driver_gpio: "*" | ||
# | ||
# # For 3rd party components: | ||
# username/component: ">=1.0.0,<2.0.0" | ||
# username2/component2: | ||
# version: "~1.0.0" | ||
# # For transient dependencies `public` flag can be set. | ||
# # `public` flag doesn't have an effect dependencies of the `main` component. | ||
# # All dependencies of `main` are public by default. | ||
# public: true |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.