Skip to content
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

fixing problem "MPU6050/examples/ do not support PICO W" #724

Merged
merged 1 commit into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions RP2040/MPU6050/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ Also, if the libraries files (I2Cdev.h, I2Cdev.cpp, MPU6050.h, MPU6050.cpp, MPU6

#### Instructions for building examples
1. ```cd``` to the folder of the example you want to build.
2. ```mkdir build && cd build```
3. ```cmake ..```
4. ```make```
5. Copy the uf2 file to your Pico board, using ```cp``` or the file explorer you have.
6. ```sudo minicom -D /dev/ttyACM0``` to watch the serial output. Use ```sudo```, otherwise minicom will fail to open the device and show no warnings. On Windows you can use PuTTY, choosing the COM port that was assigned (check the Device Manager) and a baudrate of 115200.
2. If you have PICO W (PICO board with Infineon CYW43439 wireless chip), you need to uncommented 3 lines in CMakeLists.txt file.
3. ```mkdir build && cd build```
4. ```cmake ..```
5. ```make```
6. Copy the uf2 file to your Pico board, using ```cp``` or the file explorer you have.
7. ```sudo minicom -D /dev/ttyACM0``` to watch the serial output. Use ```sudo```, otherwise minicom will fail to open the device and show no warnings. On Windows you can use PuTTY, choosing the COM port that was assigned (check the Device Manager) and a baudrate of 115200.

#### Sensor calibration
You will get better results if you measure the gyro and accelerometer offsets for your sensor *(e.g. with the accompanying calibration example)*. Set the initial offsets using `mpu.setXAccelOffset()` and friends in mpu6050_DMP_port.cpp after the call to `mpu.dmpInitialize()`.
Expand Down
33 changes: 19 additions & 14 deletions RP2040/MPU6050/examples/mpu6050_DMP_V6.12/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
# Generated Cmake Pico project file

cmake_minimum_required(VERSION 3.13)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Pull in Raspberry Pi Pico SDK (must be before project)
# Pull in SDK (must be before project)
# set(PICO_BOARD pico_w) # Needed only for PICO W
# set(CYW43_LWIP 1) # Needed only for PICO W
include(pico_sdk_import.cmake)

project(mpu6050_DMP_port C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()

# Add executable. Default name is the project name, version 0.1

add_executable(mpu6050_DMP_port mpu6050_DMP_port.cpp I2Cdev.cpp MPU6050.cpp )
add_executable(mpu6050_DMP_port
mpu6050_DMP_port.cpp
MPU6050.cpp
I2Cdev.cpp
)

# Add any user requested libraries
target_link_libraries(mpu6050_DMP_port
pico_stdlib
# pico_cyw43_arch_none # we need Wifi to access the GPIO. Needed only for PICO W
hardware_i2c
pico_double
)

pico_set_program_name(mpu6050_DMP_port "mpu6050_DMP_port")
pico_set_program_version(mpu6050_DMP_port "0.1")

pico_enable_stdio_uart(mpu6050_DMP_port 0)
pico_enable_stdio_usb(mpu6050_DMP_port 1)

# Add the standard library to the build
target_link_libraries(mpu6050_DMP_port pico_stdlib)

# Add any user requested libraries
target_link_libraries(mpu6050_DMP_port
hardware_i2c
pico_double
)

# create map/bin/hex file etc.
pico_add_extra_outputs(mpu6050_DMP_port)

50 changes: 42 additions & 8 deletions RP2040/MPU6050/examples/mpu6050_DMP_V6.12/mpu6050_DMP_port.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#ifndef PICO_DEFAULT_LED_PIN // PICO w with WiFi
#include "pico/cyw43_arch.h"
#endif
#include "MPU6050_6Axis_MotionApps_V6_12.h"

MPU6050 mpu;
Expand Down Expand Up @@ -33,6 +36,42 @@ void dmpDataReady() {
mpuInterrupt = true;
}

void initLED() {
#ifndef PICO_DEFAULT_LED_PIN // PICO w with WiFi
printf ("we have board with wifi (pico w) \n");
if (cyw43_arch_init()) {
printf("WiFi init failed");
exit(3);
}
#else
printf ("we have board without wifi\n");
gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
#endif // PICO_DEFAULT_LED_PIN

} // initLED()

void waitForUsbConnect() {
#ifdef _PICO_STDIO_USB_H // We are using PICO_STDIO_USB. Have to wait for connection.

#ifndef PICO_DEFAULT_LED_PIN
while (!stdio_usb_connected()) { // blink the pico's led until usb connection is established
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
sleep_ms(250);
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
sleep_ms(250);
}
#else
while (!stdio_usb_connected()) { // blink the pico's led until usb connection is established
gpio_put(PICO_DEFAULT_LED_PIN, 0);
sleep_ms(250);
gpio_put(PICO_DEFAULT_LED_PIN, 1);
sleep_ms(250);
}
#endif // PICO_DEFAULT_LED_PIN
#endif // _PICO_STDIO_USB_H
} // waitForUsbConnect

int main() {
stdio_init_all();
// This example will use I2C0 on the default SDA and SCL (pins 6, 7 on a Pico)
Expand All @@ -44,14 +83,9 @@ int main() {
// Make the I2C pins available to picotool

// setup blink led
gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
while (!stdio_usb_connected()) { // blink the pico's led until usb connection is established
gpio_put(PICO_DEFAULT_LED_PIN, 1);
sleep_ms(250);
gpio_put(PICO_DEFAULT_LED_PIN, 0);
sleep_ms(250);
}
// setup blink led
initLED();
waitForUsbConnect();

// ================================================================
// === INITIAL SETUP ===
Expand Down
34 changes: 19 additions & 15 deletions RP2040/MPU6050/examples/mpu6050_calibration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
# Generated Cmake Pico project file

cmake_minimum_required(VERSION 3.13)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Pull in Raspberry Pi Pico SDK (must be before project)
# Pull in SDK (must be before project)
# set(PICO_BOARD pico_w) # Needed only for PICO W
# set(CYW43_LWIP 1) # Needed only for PICO W
include(pico_sdk_import.cmake)

project(mpu6050_calibration C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()

# Add executable. Default name is the project name, version 0.1

add_executable(mpu6050_calibration mpu6050_calibration.cpp I2Cdev.cpp MPU6050.cpp )
add_executable( mpu6050_calibration
mpu6050_calibration.cpp
MPU6050.cpp
I2Cdev.cpp
)

# Add any user requested libraries
target_link_libraries( mpu6050_calibration
pico_stdlib
# pico_cyw43_arch_none # we need Wifi to access the GPIO. Needed only for PICO W
hardware_i2c
)

pico_set_program_name(mpu6050_calibration "mpu6050_calibration")
pico_set_program_version(mpu6050_calibration "0.1")

pico_enable_stdio_uart(mpu6050_calibration 0)
pico_enable_stdio_usb(mpu6050_calibration 1)

# Add the standard library to the build
target_link_libraries(mpu6050_calibration pico_stdlib)

# Add any user requested libraries
target_link_libraries(mpu6050_calibration
hardware_i2c
)

pico_add_extra_outputs(mpu6050_calibration)
# create map/bin/hex file etc.
pico_add_extra_outputs( mpu6050_calibration)

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#ifndef PICO_DEFAULT_LED_PIN // PICO w with WiFi
#include "pico/cyw43_arch.h"
#endif
#include "MPU6050.h"

MPU6050 accelgyro;
Expand Down Expand Up @@ -200,6 +203,42 @@ void PullBracketsOut(){
} // keep going
} // PullBracketsOut

void initLED() {
#ifndef PICO_DEFAULT_LED_PIN // PICO w with WiFi
printf ("we have board with wifi (pico w) \n");
if (cyw43_arch_init()) {
printf("WiFi init failed");
exit(3);
}
#else
printf ("we have board without wifi\n");
gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
#endif // PICO_DEFAULT_LED_PIN

} // initLED()

void waitForUsbConnect() {
#ifdef _PICO_STDIO_USB_H // We are using PICO_STDIO_USB. Have to wait for connection.

#ifndef PICO_DEFAULT_LED_PIN
while (!stdio_usb_connected()) { // blink the pico's led until usb connection is established
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
sleep_ms(250);
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
sleep_ms(250);
}
#else
while (!stdio_usb_connected()) { // blink the pico's led until usb connection is established
gpio_put(PICO_DEFAULT_LED_PIN, 0);
sleep_ms(250);
gpio_put(PICO_DEFAULT_LED_PIN, 1);
sleep_ms(250);
}
#endif // PICO_DEFAULT_LED_PIN
#endif // _PICO_STDIO_USB_H
} // waitForUsbConnect

int main()
{
stdio_init_all();
Expand All @@ -213,14 +252,8 @@ int main()
gpio_pull_up(PICO_DEFAULT_I2C_SCL_PIN);

// setup blink led
gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
while (!stdio_usb_connected()) { // blink the pico's led until usb connection is established
gpio_put(PICO_DEFAULT_LED_PIN, 1);
sleep_ms(250);
gpio_put(PICO_DEFAULT_LED_PIN, 0);
sleep_ms(250);
}
initLED();
waitForUsbConnect();

Initialize();
for (int i = iAx; i <= iGz; i++)
Expand Down