Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: AQM0802A BME280 MPU9250_SPI SakuraIO gps mbed
Fork of SakuraIO_Evaluation_Board_Standard by
Revision 0:db3ec2781484, committed 2017-09-07
- Comitter:
- misodengaku
- Date:
- Thu Sep 07 08:32:10 2017 +0000
- Child:
- 1:faf04d99f302
- Commit message:
- init
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AQM0802A.lib Thu Sep 07 08:32:10 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/tetsuya256/code/AQM0802A/#5cc8d4df601d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BME280.lib Thu Sep 07 08:32:10 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/MACRUM/code/BME280/#c1f1647004c4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MPU9250_SPI.lib Thu Sep 07 08:32:10 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/kylongmu/code/MPU9250_SPI/#084e8ba240c1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SakuraIO.lib Thu Sep 07 08:32:10 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/SAKURA-Internet/code/SakuraIO/#cf0b9cf1c832
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SakuraPinNames.h Thu Sep 07 08:32:10 2017 +0000 @@ -0,0 +1,63 @@ +#ifndef __SAKURA_PIN_NAMES_H__ +#define __SAKURA_PIN_NAMES_H__ + +#define DAP_UART_TX PB_6 +#define DAP_UART_RX PB_7 + +// GPIO +#define SW1 PC_14 +#define SW2 PH_0 +#define SW3 PC_0 +#define SW4 PC_1 +#define SW5 PC_2 +#define SW6 PC_3 +#undef LED1 +#undef LED2 +#undef LED3 +#undef LED4 +#define LED1 PC_13 +#define LED2 PC_15 +#define LED3 PH_1 +#define LED4 PC_4 + +// LCD +#define LED_LCD PC_5 + +// MPU-9250 +#define MPU9250_INT PB_2 + +// GPS +#define GPS_EN PA_11 +#define GPS_INT PB_5 +#define GPS_1PPS PB_4 +#define GPS_WAKEUP PD_2 +#define GPS_TX PC_6 +#define GPS_RX PC_7 + +// sakura.io +#define SCM_WAKE_IN PC_8 +#define SCM_WAKE_OUT PA_9 + +/* Bus */ + +// I2C (LCD, BME280) +#define I2C_INTERNAL_SCL PB_8 +#define I2C_INTERNAL_SDA PB_9 + +// I2C (sakura.io) +#undef I2C_SCL +#undef I2C_SDA +#define I2C_SCL PA_8 +#define I2C_SDA PC_9 + +// I2C (External) +#define I2C_EXTERNAL_SCL PB_10 +#define I2C_EXTERNAL_SDA PB_3 + +// SPI (MPU-9250) +#define SPI_MPU_MISO PA_12 +#define SPI_MPU_MOSI PA_10 +#define SPI_MPU_SCK PB_0 +#define SPI_MPU_CS PB_1 + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Sep 07 08:32:10 2017 +0000 @@ -0,0 +1,153 @@ +#include <mbed.h> +#include <AQM0802A.h> +#include <BME280.h> +#include <MPU9250.h> +#include <SakuraIO.h> +#include "SakuraPinNames.h" +#include "sensors.h" + +// Serial over CMSIS_DAP +Serial pc(DAP_UART_TX, DAP_UART_RX, 9600); + +// GPS +Serial gps(GPS_TX, GPS_RX, 9600); +DigitalOut gps_en(GPS_EN); + +// LED +DigitalOut led_1(LED1); +DigitalOut led_2(LED2); +DigitalOut led_3(LED3); +DigitalOut led_4(LED4); + +// LCD backlight +DigitalOut lcd_led(LED_LCD); + +// Switch +DigitalIn sw_1(SW1); +DigitalIn sw_2(SW2); +DigitalIn sw_3(SW3); +DigitalIn sw_4(SW4); +DigitalIn sw_5(SW5); +DigitalIn sw_6(SW6); + +// Internal I2C +I2C internal_i2c(I2C_INTERNAL_SDA, I2C_INTERNAL_SCL); +AQM0802A lcd(internal_i2c); +BME280 bme280(internal_i2c); + +// SPI +SPI internal_mpu9250_spi(SPI_MPU_MOSI, SPI_MPU_MISO, SPI_MPU_SCK); +mpu9250_spi mpu9250(internal_mpu9250_spi, SPI_MPU_CS); + +// sakura.io +SakuraIO_I2C sakuraio(I2C_SDA, I2C_SCL); + +SensorData sensor_data; + + +void setup() +{ + lcd_led = 1; + pc.printf("Hello World !\r\n"); + lcd.cls(); + lcd.printf("Hello"); + + // Initialize sensors + bme280.initialize(); + pc.printf("BME280 ok.\r\n"); + mpu9250.init(1, BITS_DLPF_CFG_188HZ); + pc.printf("MPU9250 ok. WHOAMI=%02x\r\n", mpu9250.whoami()); + if (mpu9250.whoami() != 0x71) { + pc.printf("[ERROR] MPU9250 init fail.\r\n"); + } + + mpu9250.set_gyro_scale(BITS_FS_2000DPS); //Set full scale range for gyros + mpu9250.set_acc_scale(BITS_FS_16G); //Set full scale range for accs + mpu9250.calib_acc(); + mpu9250.AK8963_calib_Magnetometer(); + + gps_en = 1; +} + +void read_sensor_data() +{ + sensor_data.bme280.temperature = bme280.getTemperature(); + sensor_data.bme280.pressure = bme280.getPressure(); + sensor_data.bme280.humidity = bme280.getHumidity(); + + mpu9250.read_all(); + sensor_data.mpu9250.temperature = mpu9250.Temperature; + for (int i = 0; i < 3; i++) { + sensor_data.mpu9250.accelerometer[i] = mpu9250.accelerometer_data[i]; + sensor_data.mpu9250.gyroscope[i] = mpu9250.gyroscope_data[i]; + sensor_data.mpu9250.magnetometer[i] = mpu9250.Magnetometer[i]; + } +} + +void enqueue_sensor_data(int counter) +{ + sakuraio.enqueueTx(0, counter); + sakuraio.enqueueTx(1, sensor_data.bme280.temperature); + sakuraio.enqueueTx(2, sensor_data.bme280.pressure); + sakuraio.enqueueTx(3, sensor_data.bme280.humidity); + + sakuraio.enqueueTx(4, sensor_data.mpu9250.temperature); // これいる? + sakuraio.enqueueTx(5, sensor_data.mpu9250.accelerometer[0]); + sakuraio.enqueueTx(6, sensor_data.mpu9250.accelerometer[1]); + sakuraio.enqueueTx(7, sensor_data.mpu9250.accelerometer[2]); + sakuraio.enqueueTx(8, sensor_data.mpu9250.gyroscope[0]); + sakuraio.enqueueTx(9, sensor_data.mpu9250.gyroscope[1]); + sakuraio.enqueueTx(10, sensor_data.mpu9250.gyroscope[2]); + sakuraio.enqueueTx(11, sensor_data.mpu9250.magnetometer[0]); + sakuraio.enqueueTx(12, sensor_data.mpu9250.magnetometer[1]); + sakuraio.enqueueTx(13, sensor_data.mpu9250.magnetometer[2]); + //sakuraio.enqueueTx(14, lon); + //sakuraio.enqueueTx(15, lat); +} + + +void loop() +{ + pc.printf("\r\n\r\nGPS\r\n"); + while(gps.readable()) { + pc.putc(gps.getc()); + } + pc.printf("\r\n"); + static int i = 1; + read_sensor_data(); + wait(1); + pc.printf("This program runs since %d seconds.\r\n", i); + pc.printf("BME280\r\n"); + pc.printf("\tTemp: %fC\r\n", sensor_data.bme280.temperature); + pc.printf("\tPres: %fhPa\r\n", sensor_data.bme280.pressure); + pc.printf("\tHum: %f%%\r\n", sensor_data.bme280.humidity); + pc.printf("MPU9250\r\n"); + pc.printf("\tTemp: %fC\r\n", sensor_data.mpu9250.temperature); + for (int j = 0; j < 3; j++) { + pc.printf("\tacc[%d]: %f\r\n", j, sensor_data.mpu9250.accelerometer[j]); + pc.printf("\tgyro[%d]: %f\r\n", j, sensor_data.mpu9250.gyroscope[j]); + pc.printf("\tmag[%d]: %f\r\n", j, sensor_data.mpu9250.magnetometer[j]); + } + lcd.cls(); + if( (sakuraio.getConnectionStatus() & 0x80) == 0x80 ) { + lcd.printf("Online\n", i); + } else { + lcd.printf("Offline\n", i); + } + lcd.printf("%d", i); + i++; + led_1 = !led_1; + led_4 = !sw_4; + + enqueue_sensor_data(i); + sakuraio.send(); +} + + +int main() +{ + setup(); + while(1) { + loop(); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Sep 07 08:32:10 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sensors.h Thu Sep 07 08:32:10 2017 +0000 @@ -0,0 +1,17 @@ +typedef struct { + float temperature; + float pressure; + float humidity; +} BME280Data; + +typedef struct { + float temperature; + float accelerometer[3]; + float gyroscope[3]; + float magnetometer[3]; +} MPU9250Data; + +typedef struct { + BME280Data bme280; + MPU9250Data mpu9250; +} SensorData;