Arduino board run on Mbed-os6.8.1 (only test purpose not official). Need Mbed Studio(1.3.1) not online compiler. If you compile on the online compiler, you can get a hex file but it does NOT work!!!
Dependencies: APDS_9960 LPS22HB LSM9DS1 HTS221
1) DAPLink(LPC11U35)の準備
使用したボード →https://akizukidenshi.com/catalog/g/gK-12144/
プログラムは、nRF52840-MDK用に公開されているDAPLinkのコンパイル済のバイナリコードを使わせていただきました。
https://github.com/makerdiary/nrf52840-mdk/tree/master/firmware/daplink
LPC11U35への書込みは、SW1(ISP)を押したままSW2(RESET)を操作するとPCに「CRP DISABLD」という名称でマウントされるので、書込まれているfirmware.binを削除してから、上記のbinファイルをコピーすれば書き込みが行われます。
書込み完了後にSW1を押さずに起動すれば、「DAPLINK」として認識されます。
DETAILS.TXTでDAPLinkの内容を確認できます。
2) 接続
Arduino Nano 33 BLE Sense | LPC11U35 Interface CPU | コメント |
J3:Pin2 (ボード裏のパッド) | CN1:Pin3 P0_7 | SWDIO |
J3:Pin3 (ボード裏のパッド) | CN1:Pin4 P0_8 | SWCLK |
JP2:Pin14 GND | CN2:Pin1 GND | GND |
3)USBSerial
シリアル出力は、NANO 33 BLE SENSEボードのUSB端子経由で出力されます。
4)Mbed Studio 1.3.1を使って開発のこと!(オンラインコンパイラでは動作しません!)
5)ボードピン配置
Diff: 5_Combined_enviromental_sensors/main5.cpp
- Revision:
- 1:cce280da16d4
- Parent:
- 0:f1a10797d9f6
--- a/5_Combined_enviromental_sensors/main5.cpp Fri Feb 07 01:21:16 2020 +0000 +++ b/5_Combined_enviromental_sensors/main5.cpp Sun Feb 28 07:31:58 2021 +0000 @@ -1,13 +1,13 @@ /* * Mbed Application program - * Nano 33 BLE Sense board runs on mbed-OS5 + * Nano 33 BLE Sense board runs on mbed-OS6 * HTS221 + LSM9DS1 + LPS22HB sensors * - * Copyright (c) 2020 Kenji Arai / JH1PJL + * Copyright (c) 2020,'21 Kenji Arai / JH1PJL * http://www7b.biglobe.ne.jp/~kenjia/ * https://os.mbed.com/users/kenjiArai/ * Started: January 22nd, 2020 - * Revised: Feburary 7th, 2020 + * Revised: February 28th, 2021 */ // Pre-selection -------------------------------------------------------------- @@ -18,18 +18,15 @@ // Include -------------------------------------------------------------------- #include "mbed.h" #include "nano33blesense_iodef.h" -#include "USBSerial.h" #include "LPS22HB.h" #include "LSM9DS1.h" #include "HTS221.h" -#include "glibr.h" // Definition ----------------------------------------------------------------- // Object --------------------------------------------------------------------- DigitalOut sen_pwr(PIN_VDD_ENV, 1); DigitalOut i2c_pullup(PIN_I2C_PULLUP, 1); -RawSerial pc(STDIO_UART_TX, STDIO_UART_RX, 115200); DigitalOut led_y(PIN_YELLOW, 0); DigitalOut led_g(PIN_GREEN, 0); DigitalOut lr(PIN_LR, 1); @@ -44,13 +41,16 @@ // RAM ------------------------------------------------------------------------ // ROM / Constant data -------------------------------------------------------- -const char *const msg0 = "Run Nano 33 BLE Sense module on Mbed-os5.15.0"; -const char *const msg1 = "Compiled on Mbed Studio:0.8.1"; +const char *const msg0 = "Run Nano 33 BLE Sense module on Mbed-os"; +const char *const msg1 = "Compiled on Mbed Studio:1.3.1"; const char *const msg2 = "Target is ARDUINO_NANO33BLE with Debug mode"; // Function prototypes -------------------------------------------------------- -extern void check_i2c_connected_devices(void); -extern void check_i2c_sensors(void); + +// subroutin (must be at this below line and do NOT change order) ------------- +#include "usb_serial_as_stdio.h" +#include "check_revision.h" +#include "common.h" //------------------------------------------------------------------------------ // Control Program @@ -60,11 +60,13 @@ HTS221::HTS221_status_t aux; HTS221::HTS221_data_t hum_data; + usb_serial_initialize(); + print_revision(); led_y = 1; i2c_pullup = 1; sen_pwr = 1; - pc.printf("\r\n%s\r\n%s\r\n%s\r\n", msg0, msg1, msg2); - thread_sleep_for(200); + print_usb("%s\r\n%s\r\n%s\r\n", msg0, msg1, msg2); + ThisThread::sleep_for(200ms); imu = new LSM9DS1(PIN_SDA1, PIN_SCL1); baro = new LPS22HB(i2c, LPS22HB_G_CHIP_ADDR); hum = new HTS221(PIN_SDA1, PIN_SCL1,HTS221::HTS221_ADDRESS, 400000); @@ -100,24 +102,25 @@ imu->readTemp(); float press = baro->pressure(); float temp = baro->temperature(); - uint32_t passed_time = t.read_ms(); + uint32_t passed_time = chrono::duration_cast<chrono::milliseconds>( + t.elapsed_time()).count(); lb = 1; // Showing lr = 0; lg = 0; lb = 0; - pc.printf("Temperature[degC]: HTS221= %+4.1f, ", hum_data.temperature); - pc.printf("LPS22HB= %+4.1f, LSM9DS1= %+4.1f, ", + print_usb("Temperature[degC]: HTS221=,%+4.1f,", hum_data.temperature); + print_usb("LPS22HB=,%+4.1f,LSM9DS1=,%+4.1f,", temp, imu->temperature_c); - pc.printf("Humidity[RH %%]: HTS221= %3.1f, ", hum_data.humidity); - pc.printf("Pressure[hPa]: LPS22H= %6.2f, ", press); + print_usb("Humidity[RH %%]: HTS221=,%3.1f,", hum_data.humidity); + print_usb("Pressure[hPa]: LPS22H=,%6.2f,", press); ++n; - pc.printf("processing time: %d [ms], count: %4d\r\n", passed_time, n); + print_usb("processing time:,%2d,[ms],count:,%4d\r\n", passed_time, n); lr = 1; lg = 1; lb = 1; if (passed_time < 999){ - thread_sleep_for(1000 - t.read_ms()); + ThisThread::sleep_for(chrono::milliseconds(1000 - passed_time)); } } }