diff --git a/RP2040/MPU6050/examples/README.md b/RP2040/MPU6050/examples/README.md index 49587d77..4bc90006 100644 --- a/RP2040/MPU6050/examples/README.md +++ b/RP2040/MPU6050/examples/README.md @@ -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()`. diff --git a/RP2040/MPU6050/examples/mpu6050_DMP_V6.12/CMakeLists.txt b/RP2040/MPU6050/examples/mpu6050_DMP_V6.12/CMakeLists.txt index 646890a2..8214ca67 100644 --- a/RP2040/MPU6050/examples/mpu6050_DMP_V6.12/CMakeLists.txt +++ b/RP2040/MPU6050/examples/mpu6050_DMP_V6.12/CMakeLists.txt @@ -1,21 +1,33 @@ # 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") @@ -23,14 +35,7 @@ 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) diff --git a/RP2040/MPU6050/examples/mpu6050_DMP_V6.12/mpu6050_DMP_port.cpp b/RP2040/MPU6050/examples/mpu6050_DMP_V6.12/mpu6050_DMP_port.cpp index 20665e49..bc9c1725 100644 --- a/RP2040/MPU6050/examples/mpu6050_DMP_V6.12/mpu6050_DMP_port.cpp +++ b/RP2040/MPU6050/examples/mpu6050_DMP_V6.12/mpu6050_DMP_port.cpp @@ -1,6 +1,9 @@ #include #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; @@ -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) @@ -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 === diff --git a/RP2040/MPU6050/examples/mpu6050_calibration/CMakeLists.txt b/RP2040/MPU6050/examples/mpu6050_calibration/CMakeLists.txt index c25fd7bb..7429697e 100644 --- a/RP2040/MPU6050/examples/mpu6050_calibration/CMakeLists.txt +++ b/RP2040/MPU6050/examples/mpu6050_calibration/CMakeLists.txt @@ -1,21 +1,32 @@ # 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") @@ -23,13 +34,6 @@ 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) diff --git a/RP2040/MPU6050/examples/mpu6050_calibration/mpu6050_calibration.cpp b/RP2040/MPU6050/examples/mpu6050_calibration/mpu6050_calibration.cpp index 987a1d2f..4ac496d6 100644 --- a/RP2040/MPU6050/examples/mpu6050_calibration/mpu6050_calibration.cpp +++ b/RP2040/MPU6050/examples/mpu6050_calibration/mpu6050_calibration.cpp @@ -1,6 +1,9 @@ #include #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; @@ -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(); @@ -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++)