Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • mateis.frambourt/relf
1 result
Show changes
Commits on Source (2)
......@@ -27,6 +27,8 @@
"stdlib.h": "c",
"sd_card.h": "c",
"mpu6050.h": "c",
"i2c.h": "c"
"i2c.h": "c",
"bmp180.h": "c",
"dreq.h": "c"
}
}
......@@ -12,6 +12,7 @@ pico_sdk_init()
# rest of your project
add_executable(${PROJECT_NAME}
main.c
hw_config.c
)
add_subdirectory(rpi-pico-bmp180)
#add_library(rpi-pico-bmp180 INTERFACE)
......@@ -20,6 +21,9 @@ add_subdirectory(rpi-pico-bmp180)
add_subdirectory(rpi-pico-mpu6050)
add_subdirectory(no-OS-FatFS-SD-SPI-RPi-Pico/FatFs_SPI build)
target_include_directories(${PROJECT_NAME} PRIVATE ${PICO_SDK_PATH}/src/rp2_common/hardware_pwm/include)
target_link_libraries(${PROJECT_NAME}
pico_stdlib
haw_bmp180
......@@ -27,8 +31,13 @@ haw_mpu6050
FatFs_SPI
hardware_i2c
hardware_spi
hardware_pwm
)
pico_add_extra_outputs(${PROJECT_NAME} )
pico_enable_stdio_usb(${PROJECT_NAME} 1)
......
......@@ -20,7 +20,18 @@ ensuite :
## PICO W
![alt text](image.png)
| Fonction | Pin |
Capteurs :
| Nom | Type | Lien |
| ---- | ---- | --- |
| BMP180 | capteur de pression | https://www.amazon.fr/gp/product/B07FRW7YTK?ie=UTF8&th=1|
| MPU-6050 | IMU | https://www.amazon.fr/gp/product/B07XRK5FHP?ie=UTF8&psc=1 |
| | Lecteur de carte SD | https://www.amazon.fr/AZDelivery-Reader-m%C3%A9moire-compatible-Arduino/dp/B06X1DX5WS?th=1 |
|TBS GPS M8.2 | GPS | https://www.drone-doctors.fr/gps/1532-mini-gps-tbs-m82-ublox-pour-drone-racer-fpv.html |
| Buzzer | Buzzer | |
| Fonction | Pin |
| --------- | ------- |
| SD/SCK | 14 |
| SD/MOSI | 15 |
......
/* hw_config.c
Copyright 2021 Carl John Kugler III
Licensed under the Apache License, Version 2.0 (the License); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
*/
/*
This file should be tailored to match the hardware design.
There should be one element of the spi[] array for each hardware SPI used.
There should be one element of the sd_cards[] array for each SD card slot.
The name is should correspond to the FatFs "logical drive" identifier.
(See http://elm-chan.org/fsw/ff/doc/filename.html#vol)
In general, this should correspond to the (zero origin) array index.
The rest of the constants will depend on the type of
socket, which SPI it is driven by, and how it is wired.
*/
#include <assert.h>
#include <string.h>
//
#include "my_debug.h"
//
#include "hw_config.h"
//
#include "ff.h" /* Obtains integer types */
//
#include "diskio.h" /* Declarations of disk functions */
/*
This example assumes the following hardware configuration:
| | SPI0 | GPIO | Pin | SPI | MicroSD | Description |
| ----- | ---- | ----- | --- | -------- | --------- | ---------------------- |
| MISO | RX | 16 | 21 | DO | DO | Master In, Slave Out |
| MOSI | TX | 19 | 25 | DI | DI | Master Out, Slave In |
| SCK | SCK | 18 | 24 | SCLK | CLK | SPI clock |
| CS0 | CSn | 17 | 22 | SS or CS | CS | Slave (or Chip) Select |
| DET | | 22 | 29 | | CD | Card Detect |
| GND | | | 18,23 | | GND | Ground |
| 3v3 | | | 36 | | 3v3 | 3.3 volt power |
*/
// Hardware Configuration of SPI "objects"
// Note: multiple SD cards can be driven by one SPI if they use different slave
// selects.
static spi_t spis[] = { // One for each SPI.
{
.hw_inst = spi1, // SPI component
.miso_gpio = 16, // GPIO number (not Pico pin number)
.mosi_gpio = 15,
.sck_gpio = 14,
// .baud_rate = 1000 * 1000
.baud_rate = 12500 * 1000
// .baud_rate = 25 * 1000 * 1000 // Actual frequency: 20833333.
}};
// Hardware Configuration of the SD Card "objects"
static sd_card_t sd_cards[] = { // One for each SD card
{
.pcName = "0:", // Name used to mount device
.spi = &spis[0], // Pointer to the SPI driving this card
.ss_gpio = 17, // The SPI slave select GPIO for this SD card
.use_card_detect = false,
.card_detect_gpio = 22, // Card detect
.card_detected_true = 1 // What the GPIO read returns when a card is
// present.
}};
/* ********************************************************************** */
size_t sd_get_num() { return count_of(sd_cards); }
sd_card_t *sd_get_by_num(size_t num) {
assert(num <= sd_get_num());
if (num <= sd_get_num()) {
return &sd_cards[num];
} else {
return NULL;
}
}
size_t spi_get_num() { return count_of(spis); }
spi_t *spi_get_by_num(size_t num) {
assert(num <= spi_get_num());
if (num <= spi_get_num()) {
return &spis[num];
} else {
return NULL;
}
}
/* [] END OF FILE */
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "hardware/pwm.h"
#include "rpi-pico-bmp180/include/haw/BMP180.h"
#include "rpi-pico-mpu6050/include/haw/MPU6050.h"
#include "sd_card.h"
#include "ff.h"
#include "hw_config.h"
int main() {
FRESULT fr;
FATFS fs;
FIL fil;
int ret;
char buf[100];
char filename[] = "test02.txt";
stdio_init_all();
i2c_init(i2c_default, 100 * 1000);
printf("Hello, world!\n");
sd_init_driver();
gpio_set_function(6, GPIO_FUNC_I2C);
gpio_set_function(7, GPIO_FUNC_I2C);
gpio_set_function(29,GPIO_FUNC_PWM);
pwm_set_clkdiv_int_frac (pwm_gpio_to_slice_num(29), 38, 3);
gpio_pull_up(6);
gpio_pull_up(7);
i2c_init(i2c0, 10000);
uart_init(uart1,9600);
bmp180_t bmp = bmp180_init(i2c0);
mpu6050_t mpu6050 = mpu6050_init(i2c_default, MPU6050_ADDRESS_A0_GND);
mpu6050_begin(&mpu6050);
bmp180_begin(&bmp);
mpu6050_set_scale(&mpu6050, MPU6050_SCALE_2000DPS);
mpu6050_set_range(&mpu6050, MPU6050_RANGE_8G);
mpu6050_set_temperature_measuring(&mpu6050, true);
mpu6050_set_gyroscope_measuring(&mpu6050, true);
mpu6050_set_accelerometer_measuring(&mpu6050, true);
mpu6050_set_int_free_fall(&mpu6050, false);
mpu6050_set_int_motion(&mpu6050, false);
mpu6050_set_int_zero_motion(&mpu6050, false);
// Enable temperature measurings
bmp180_set_temperature_measuring(&bmp, 1);
// Enable pressure measurings
bmp180_set_pressure_measuring(&bmp, 1);
while (true) {
bmp180_event(&bmp);
mpu6050_event(&mpu6050);
mpu6050_vectorf_t *accel = mpu6050_get_accelerometer(&mpu6050);
mpu6050_vectorf_t *gyro = mpu6050_get_gyroscope(&mpu6050);
float tempC = mpu6050_get_temperature_c(&mpu6050);
printf("Accelerometer: %f, %f, %f - Gyroscope: %f, %f, %f - Temperature: %f°C\n", accel->x, accel->y, accel->z, gyro->x, gyro->y, gyro->z, tempC);
printf("Temperature: %f°C - Temperature: %f°F - Pressure: %fhPa (mbar) - Altitude(Compared to 1013.25): %fhPa (mbar) - @SeaLevel(10): %fhPa (mbar)\n", bmp180_get_temperature_c(&bmp), bmp180_get_temperature_f(&bmp), bmp180_get_pressure(&bmp), bmp180_get_altitude(&bmp, 1013.25), bmp180_get_sea_level(&bmp, 10.0));
sleep_ms(200);
}
......