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: APDS_9960 LPS22HB LSM9DS1 HTS221
Revision 0:f1a10797d9f6, committed 2020-02-07
- Comitter:
- kenjiArai
- Date:
- Fri Feb 07 01:21:16 2020 +0000
- Child:
- 1:cce280da16d4
- Commit message:
- only test purpose not official
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/0_Blinky_LED/main0.cpp Fri Feb 07 01:21:16 2020 +0000
@@ -0,0 +1,89 @@
+/*
+ * Mbed Application program
+ * Nano 33 BLE Sense board runs on mbed-OS5
+ * 3 LED (Y+G+RGB) blinky
+ *
+ * Copyright (c) 2020 Kenji Arai / JH1PJL
+ * http://www7b.biglobe.ne.jp/~kenjia/
+ * https://os.mbed.com/users/kenjiArai/
+ * Started: January 22nd, 2020
+ * Revised: Feburary 5th, 2020
+ */
+
+// Pre-selection --------------------------------------------------------------
+#include "select_example.h"
+//#define EXAMPLE_0_BLINKY_LED
+#ifdef EXAMPLE_0_BLINKY_LED
+
+// Include --------------------------------------------------------------------
+#include "mbed.h"
+#include "nano33blesense_iodef.h"
+
+// Definition -----------------------------------------------------------------
+
+// Constructor ----------------------------------------------------------------
+DigitalOut led_y(PIN_YELLOW, 0);
+DigitalOut led_g(PIN_GREEN, 0);
+DigitalOut lr(PIN_LR, 1);
+DigitalOut lg(PIN_LG, 1);
+DigitalOut lb(PIN_LB, 1);
+
+// RAM ------------------------------------------------------------------------
+
+// ROM / Constant data --------------------------------------------------------
+
+// Function prototypes --------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Control Program
+//------------------------------------------------------------------------------
+int main()
+{
+ thread_sleep_for(1000);
+ while (true) {
+ led_y = 1;
+ led_g = 0;
+ lr = 1;
+ lg = 1;
+ lb = 1;
+ thread_sleep_for(1000);
+ led_y = 0;
+ led_g = 1;
+ lr = 1;
+ lg = 1;
+ lb = 1;
+ thread_sleep_for(1000);
+ led_y = 0;
+ led_g = 0;
+ lr = 0;
+ lg = 1;
+ lb = 1;
+ thread_sleep_for(1000);
+ led_y = 0;
+ led_g = 0;
+ lr = 1;
+ lg = 0;
+ lb = 1;
+ thread_sleep_for(1000);
+ led_y = 0;
+ led_g = 0;
+ lr = 1;
+ lg = 1;
+ lb = 0;
+ thread_sleep_for(1000);
+ led_y = 1;
+ led_g = 1;
+ lr = 0;
+ lg = 0;
+ lb = 0;
+ thread_sleep_for(1000);
+ led_y = 0;
+ led_g = 0;
+ lr = 1;
+ lg = 1;
+ lb = 1;
+ thread_sleep_for(1000);
+ }
+}
+
+#endif // EXAMPLE_0_BLINKY_LED
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/1_check_I2C_devices/main1.cpp Fri Feb 07 01:21:16 2020 +0000
@@ -0,0 +1,59 @@
+/*
+ * Mbed Application program
+ * Nano 33 BLE Sense board runs on mbed-OS5
+ * Check I2C control line
+ *
+ * Copyright (c) 2020 Kenji Arai / JH1PJL
+ * http://www7b.biglobe.ne.jp/~kenjia/
+ * https://os.mbed.com/users/kenjiArai/
+ * Started: January 22nd, 2020
+ * Revised: Feburary 5th, 2020
+ */
+
+// Pre-selection --------------------------------------------------------------
+#include "select_example.h"
+//#define EXAMPLE_1_CHECK_I2C_DEVICES
+#ifdef EXAMPLE_1_CHECK_I2C_DEVICES
+
+// Include --------------------------------------------------------------------
+#include "mbed.h"
+#include "nano33blesense_iodef.h"
+#include "USBSerial.h"
+#include "LPS22HB.h"
+#include "LSM9DS1.h"
+#include "HTS221.h"
+#include "glibr.h"
+
+// Definition -----------------------------------------------------------------
+
+// Constructor ----------------------------------------------------------------
+RawSerial pc(STDIO_UART_TX, STDIO_UART_RX, 115200);
+DigitalOut sen_pwr(PIN_VDD_ENV, 1);
+DigitalOut i2c_pullup(PIN_I2C_PULLUP, 1);
+I2C i2c(PIN_SDA1, PIN_SCL1);
+
+// RAM ------------------------------------------------------------------------
+
+// ROM / Constant data --------------------------------------------------------
+
+// Function prototypes --------------------------------------------------------
+extern void check_i2c_connected_devices(void);
+extern void check_i2c_sensors(void);
+
+//------------------------------------------------------------------------------
+// Control Program
+//------------------------------------------------------------------------------
+int main()
+{
+ i2c_pullup = 1;
+ sen_pwr = 1;
+ pc.printf("\r\nCheck I2C line\r\n");
+ thread_sleep_for(200);
+ check_i2c_connected_devices();
+ while (true) {
+ check_i2c_sensors();
+ thread_sleep_for(10000);
+ }
+}
+
+#endif // EXAMPLE_1_CHECK_I2C_DEVICES
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/2_check_LSM9DS1/main2.cpp Fri Feb 07 01:21:16 2020 +0000
@@ -0,0 +1,84 @@
+/*
+ * Mbed Application program
+ * Nano 33 BLE Sense board runs on mbed-OS5
+ * LSM9DS1 -> iNEMO inertial module:
+ * 3D accelerometer, 3D gyroscope, 3D magnetometer
+ * by STMicroelectronics
+ *
+ * Copyright (c) 2020 Kenji Arai / JH1PJL
+ * http://www7b.biglobe.ne.jp/~kenjia/
+ * https://os.mbed.com/users/kenjiArai/
+ * Started: January 22nd, 2020
+ * Revised: Feburary 5th, 2020
+ */
+
+// Pre-selection --------------------------------------------------------------
+#include "select_example.h"
+//#define EXAMPLE_2_CHECK_LSM9DS1
+#ifdef EXAMPLE_2_CHECK_LSM9DS1
+
+// Include --------------------------------------------------------------------
+#include "mbed.h"
+#include "nano33blesense_iodef.h"
+#include "LSM9DS1.h"
+
+// Definition -----------------------------------------------------------------
+
+// Constructor ----------------------------------------------------------------
+RawSerial pc(STDIO_UART_TX, STDIO_UART_RX, 115200);
+DigitalOut sen_pwr(PIN_VDD_ENV, 1);
+DigitalOut i2c_pullup(PIN_I2C_PULLUP, 1);
+I2C i2c(PIN_SDA1, PIN_SCL1);
+LSM9DS1 *imu = NULL;
+Timer t;
+
+// RAM ------------------------------------------------------------------------
+
+// ROM / Constant data --------------------------------------------------------
+
+// Function prototypes --------------------------------------------------------
+extern void check_i2c_connected_devices(void);
+
+//------------------------------------------------------------------------------
+// Control Program
+//------------------------------------------------------------------------------
+int main()
+{
+ i2c_pullup = 1;
+ sen_pwr = 1;
+ pc.printf("\r\nCheck LSM9DS1\r\n");
+ thread_sleep_for(200);
+ check_i2c_connected_devices();
+ imu = new LSM9DS1(PIN_SDA1, PIN_SCL1);
+ uint16_t reg = imu->begin();
+ pc.printf("IMU(LSM9DS1) 0x%x\r\n", reg);
+ imu->calibration();
+ // check I2C line
+ check_i2c_connected_devices();
+ if (reg == 0x683d){
+ pc.printf("ACC+GYR+MAG are ready!\r\n");
+ } else {
+ pc.printf("ACC+GYR+MAG are NOT ready!\r\n");
+ }
+ uint32_t n = 0;
+ while(true) {
+ t.reset();
+ t.start();
+ imu->readAccel();
+ imu->readGyro();
+ imu->readMag();
+ imu->readTemp();
+ pc.printf("acc = %+5.3f, %+5.3f, %+5.3f, ", imu->ax, imu->ay, imu->az);
+ pc.printf("gyr = %+8.3f, %+8.3f, %+8.3f, ", imu->gx, imu->gy, imu->gz);
+ pc.printf("mag = %+5.3f, %+5.3f, %+5.3f, ", imu->mx, imu->my, imu->mz);
+ pc.printf("temperature = %+5.1f, ", imu->temperature_c);
+ ++n;
+ uint32_t passed_time = t.read_ms();
+ pc.printf("processing time: %d [ms], count: %4d\r\n", passed_time, n);
+ if (passed_time < 199){
+ thread_sleep_for(200 - t.read_ms());
+ }
+ }
+}
+
+#endif // EXAMPLE_2_CHECK_LSM9DS1
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/3_check_LPS22HB/main3.cpp Fri Feb 07 01:21:16 2020 +0000
@@ -0,0 +1,80 @@
+/*
+ * Mbed Application program
+ * Nano 33 BLE Sense board runs on mbed-OS5
+ * LPS33HB -> MEMS nano pressure sensor:
+ * 260-1260 hPa absolute Digital output barometer
+ * by STMicroelectronics
+ *
+ * Copyright (c) 2020 Kenji Arai / JH1PJL
+ * http://www7b.biglobe.ne.jp/~kenjia/
+ * https://os.mbed.com/users/kenjiArai/
+ * Started: January 22nd, 2020
+ * Revised: Feburary 5th, 2020
+ */
+
+// Pre-selection --------------------------------------------------------------
+#include "select_example.h"
+//#define EXAMPLE_3_CHECK_LPS22HB
+#ifdef EXAMPLE_3_CHECK_LPS22HB
+
+// Include --------------------------------------------------------------------
+#include "mbed.h"
+#include "nano33blesense_iodef.h"
+#include "LPS22HB.h"
+
+// Definition -----------------------------------------------------------------
+
+// Constructor ----------------------------------------------------------------
+RawSerial pc(STDIO_UART_TX, STDIO_UART_RX, 115200);
+DigitalOut sen_pwr(PIN_VDD_ENV, 1);
+DigitalOut i2c_pullup(PIN_I2C_PULLUP, 1);
+I2C i2c(PIN_SDA1, PIN_SCL1);
+LPS22HB *baro = NULL;
+Timer t;
+
+// RAM ------------------------------------------------------------------------
+
+// ROM / Constant data --------------------------------------------------------
+
+// Function prototypes --------------------------------------------------------
+extern void check_i2c_connected_devices(void);
+
+//------------------------------------------------------------------------------
+// Control Program
+//------------------------------------------------------------------------------
+int main()
+{
+ i2c_pullup = 1;
+ sen_pwr = 1;
+ pc.printf("\r\nCheck LSM9DS1\r\n");
+ thread_sleep_for(200);
+ // check I2C line
+ check_i2c_connected_devices();
+ baro = new LPS22HB(i2c, LPS22HB_G_CHIP_ADDR);
+ uint8_t id = baro->read_id();
+ if (id == I_AM_LPS22HB) {
+ pc.printf("LPS22H is ready. ID = 0x%x\r\n", id);
+ } else {
+ pc.printf("LPS22H is NOT ready. return value = 0x%x\r\n", id);
+ }
+ baro->set_odr();
+ uint32_t n = 0;
+ while(true) {
+ t.reset();
+ t.start();
+ baro->get();
+ while (baro->data_ready() == 0){
+ thread_sleep_for(2);
+ }
+ pc.printf("Pressure: %6.1f [hPa], Temperature: %+4.1f [degC], ",
+ baro->pressure(), baro->temperature());
+ ++n;
+ uint32_t passed_time = t.read_ms();
+ pc.printf("processing time: %d [ms], count: %4d\r\n", passed_time, n);
+ if (passed_time < 999){
+ thread_sleep_for(1000 - t.read_ms());
+ }
+ }
+}
+
+#endif // EXAMPLE_3_CHECK_LPS22HB
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/4_check_HTS221/main4.cpp Fri Feb 07 01:21:16 2020 +0000
@@ -0,0 +1,85 @@
+/*
+ * Mbed Application program
+ * Nano 33 BLE Sense board runs on mbed-OS5
+ * HTS221 -> Capacitive digital sensor for relative humidity and temperature
+ * by STMicroelectronics
+ *
+ * Copyright (c) 2020 Kenji Arai / JH1PJL
+ * http://www7b.biglobe.ne.jp/~kenjia/
+ * https://os.mbed.com/users/kenjiArai/
+ * Started: January 22nd, 2020
+ * Revised: Feburary 5th, 2020
+ */
+
+// Pre-selection --------------------------------------------------------------
+#include "select_example.h"
+//#define EXAMPLE_4_CHECK_HTS221
+#ifdef EXAMPLE_4_CHECK_HTS221
+
+// Include --------------------------------------------------------------------
+#include "mbed.h"
+#include "nano33blesense_iodef.h"
+#include "HTS221.h"
+
+// Definition -----------------------------------------------------------------
+
+// Constructor ----------------------------------------------------------------
+RawSerial pc(STDIO_UART_TX, STDIO_UART_RX, 115200);
+DigitalOut sen_pwr(PIN_VDD_ENV, 1);
+DigitalOut i2c_pullup(PIN_I2C_PULLUP, 1);
+I2C i2c(PIN_SDA1, PIN_SCL1);
+HTS221 *hum = NULL;
+Timer t;
+
+// RAM ------------------------------------------------------------------------
+
+// ROM / Constant data --------------------------------------------------------
+
+// Function prototypes --------------------------------------------------------
+extern void check_i2c_connected_devices(void);
+
+//------------------------------------------------------------------------------
+// Control Program
+//------------------------------------------------------------------------------
+int main()
+{
+ HTS221::HTS221_data_t hum_data;
+
+ i2c_pullup = 1;
+ sen_pwr = 1;
+ pc.printf("\r\nCheck LSM9DS1\r\n");
+ thread_sleep_for(200);
+ // check I2C line
+ check_i2c_connected_devices();
+ hum = new HTS221(PIN_SDA1, PIN_SCL1,HTS221::HTS221_ADDRESS, 400000);
+ hum->HTS221_GetDeviceID (&hum_data);
+ uint8_t id = hum_data.deviceID;
+ if (id == HTS221::WHO_AM_I_VALUE) {
+ pc.printf("HTS221 is ready. ID = 0x%x\r\n", id);
+ } else {
+ pc.printf("HTS221 is NOT ready. return value = 0x%x\r\n", id);
+ }
+ uint32_t n = 0;
+ while(true) {
+ t.reset();
+ t.start();
+ hum->HTS221_SetOneShot();
+ do {
+ thread_sleep_for(2);
+ hum->HTS221_GetOneShot(&hum_data);
+ } while(hum_data.one_shot == HTS221::CTRL_REG2_ONE_SHOT_WAITING);
+ hum->HTS221_GetCalibrationCoefficients (&hum_data);
+ hum->HTS221_GetTemperature(&hum_data);
+ hum->HTS221_GetHumidity(&hum_data);
+ pc.printf("Temperature: %0.1f [degC], RH: %0.1f [%%], ",
+ hum_data.temperature, hum_data.humidity);
+ ++n;
+ uint32_t passed_time = t.read_ms();
+ pc.printf("processing time: %d [ms], count: %4d\r\n", passed_time, n);
+ if (passed_time < 999){
+ thread_sleep_for(1000 - t.read_ms());
+ }
+ }
+}
+
+#endif // EXAMPLE_4_CHECK_HTS221
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/5_Combined_enviromental_sensors/main5.cpp Fri Feb 07 01:21:16 2020 +0000
@@ -0,0 +1,125 @@
+/*
+ * Mbed Application program
+ * Nano 33 BLE Sense board runs on mbed-OS5
+ * HTS221 + LSM9DS1 + LPS22HB sensors
+ *
+ * Copyright (c) 2020 Kenji Arai / JH1PJL
+ * http://www7b.biglobe.ne.jp/~kenjia/
+ * https://os.mbed.com/users/kenjiArai/
+ * Started: January 22nd, 2020
+ * Revised: Feburary 7th, 2020
+ */
+
+// Pre-selection --------------------------------------------------------------
+#include "select_example.h"
+//#define EXAMPLE_5_COMB_ENV_SENSORS
+#ifdef EXAMPLE_5_COMB_ENV_SENSORS
+
+// 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);
+DigitalOut lg(PIN_LG, 1);
+DigitalOut lb(PIN_LB, 1);
+I2C i2c(PIN_SDA1, PIN_SCL1);
+LSM9DS1 *imu = NULL;
+LPS22HB *baro = NULL;
+HTS221 *hum = NULL;
+Timer t;
+
+// 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 msg2 = "Target is ARDUINO_NANO33BLE with Debug mode";
+
+// Function prototypes --------------------------------------------------------
+extern void check_i2c_connected_devices(void);
+extern void check_i2c_sensors(void);
+
+//------------------------------------------------------------------------------
+// Control Program
+//------------------------------------------------------------------------------
+int main()
+{
+ HTS221::HTS221_status_t aux;
+ HTS221::HTS221_data_t hum_data;
+
+ 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);
+ 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);
+ baro->set_odr();
+ check_i2c_sensors();
+ uint32_t n = 0;
+ led_y = 0;
+ led_g = 1;
+ while(true) {
+ t.reset();
+ t.start();
+ // Starting
+ lr = 0;
+ baro->get();
+ hum->HTS221_SetOneShot();
+ imu->begin();
+ lr = 1;
+ // Waiting
+ lg = 0;
+ do {
+ thread_sleep_for(2);
+ aux = hum->HTS221_GetOneShot(&hum_data);
+ } while(hum_data.one_shot == HTS221::CTRL_REG2_ONE_SHOT_WAITING);
+ while (baro->data_ready() == 0){
+ thread_sleep_for(2);
+ }
+ lg = 1;
+ // Reading
+ lb = 0;
+ hum->HTS221_GetCalibrationCoefficients (&hum_data);
+ hum->HTS221_GetTemperature(&hum_data);
+ hum->HTS221_GetHumidity(&hum_data);
+ imu->readTemp();
+ float press = baro->pressure();
+ float temp = baro->temperature();
+ uint32_t passed_time = t.read_ms();
+ 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, ",
+ temp, imu->temperature_c);
+ pc.printf("Humidity[RH %%]: HTS221= %3.1f, ", hum_data.humidity);
+ pc.printf("Pressure[hPa]: LPS22H= %6.2f, ", press);
+ ++n;
+ pc.printf("processing time: %d [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());
+ }
+ }
+}
+
+#endif // EXAMPLE_5_COMB_ENV_SENSORS
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/6_check_APDS_9960/main6.cpp Fri Feb 07 01:21:16 2020 +0000
@@ -0,0 +1,148 @@
+/*
+ * APDS-9960
+ * Digital Proximity, Ambient Light, RGB and Gesture Sensor
+ *
+ * Modified by Kenji Arai / JH1PJL
+ * http://www7b.biglobe.ne.jp/~kenjia/
+ * https://os.mbed.com/users/kenjiArai/
+ *
+ * Started: Feburary 2nd, 2020
+ * Revised: Feburary 3rd, 2020
+ *
+ * Original:
+ * https://os.mbed.com/users/kbhagat6/code/Gesture_User_Interface/
+ */
+
+// Pre-selection --------------------------------------------------------------
+#include "select_example.h"
+//#define EXAMPLE_6_CHECK_APDS_9960
+#ifdef EXAMPLE_6_CHECK_APDS_9960
+
+// Include --------------------------------------------------------------------
+#include "mbed.h"
+#include "nano33blesense_iodef.h"
+#include "PinDetect.h"
+#include "glibr.h"
+
+// Definition -----------------------------------------------------------------
+
+// Object ---------------------------------------------------------------------
+RawSerial pc(STDIO_UART_TX, STDIO_UART_RX, 115200);
+PinDetect apds_int(PIN_APDS_INT);
+DigitalOut sen_pwr(PIN_VDD_ENV, 1);
+DigitalOut i2c_pullup(PIN_I2C_PULLUP, 1);
+DigitalOut led_y(PIN_YELLOW, 0);
+DigitalOut led_g(PIN_GREEN, 0);
+DigitalOut lr(PIN_LR, 1);
+DigitalOut lg(PIN_LG, 1);
+DigitalOut lb(PIN_LB, 1);
+I2C i2c(PIN_SDA1, PIN_SCL1);
+glibr *gesture = NULL;
+
+// ROM / Constant data --------------------------------------------------------
+
+// RAM ------------------------------------------------------------------------
+
+// Function prototypes --------------------------------------------------------
+extern void check_i2c_connected_devices(void);
+void apds_hit_callback (void);
+
+//------------------------------------------------------------------------------
+// Control Program
+//------------------------------------------------------------------------------
+int main()
+{
+ bool gerror = false;
+
+ i2c_pullup = 1;
+ sen_pwr = 1;
+ pc.printf("\r\nCheck APDS_9960\r\n");
+ thread_sleep_for(200);
+ // check I2C line
+ check_i2c_connected_devices();
+ gesture = new glibr(PIN_SDA1, PIN_SCL1);
+ if (gesture->ginit()) {
+ pc.printf("APDS-9960 initialization complete\n\r");
+ } else {
+ pc.printf("Something went wrong during APDS-9960 init\n\r");
+ gerror=true;
+ }
+ uint8_t id = 0;
+ if (id == 0) {
+ pc.printf("??? is ready. ID = 0x%x\r\n", id);
+ } else {
+ pc.printf("??? is NOT ready. return value = 0x%x\r\n", id);
+ }
+ // Start running the APDS-9960 gesture sensor engine
+ if ( gesture->enableGestureSensor(true) ) {
+ pc.printf("Gesture sensor is now running\n\r");
+ } else {
+ pc.printf("Something went wrong during gesture sensor init!\n\r");
+ gerror=true;
+ }
+ //
+ apds_int.mode(PullUp);
+ // Delay for initial pullup to take effect
+ thread_sleep_for(100);
+ // Setup Interrupt callback function for a pb hit
+ apds_int.attach_deasserted(&apds_hit_callback);
+ // Start sampling pb input using interrupts
+ apds_int.setSampleFrequency();
+ while(!(gesture->isGestureAvailable())){
+ ;
+ thread_sleep_for(500);
+ ;
+ thread_sleep_for(500);
+ }
+
+ int temp;
+ while(gerror == false) {
+ /*ret = gesture->isGestureAvailable();
+ pc.printf("Is Gesture Available?: %d\n", ret);
+ val = gesture->readGesture();
+ */
+ if (gesture->isGestureAvailable()) {
+ if(gesture->isGestureAvailable()){
+ temp = gesture->readGesture();
+ }
+ switch ( temp) {
+ case DIR_UP:
+ pc.printf("Forward\r\n");
+ break;
+ case DIR_DOWN:
+ pc.printf("Backward\r\n");
+ break;
+ case DIR_LEFT:
+ pc.printf("LEFT\r\n");
+ break;
+ case DIR_RIGHT:
+ pc.printf("RIGHT\r\n");
+ break;
+ case 67:
+ pc.printf("Collision\r\n");
+ break;
+ case DIR_NEAR:
+ pc.printf("NEAR\r\n");
+ break;
+ case DIR_FAR:
+ pc.printf("FAR\r\n");
+ break;
+ default:
+ pc.printf("NONE\r\n");
+ break;
+ }
+ }
+ //thread_sleep_for(1000);
+ }
+}
+
+void apds_hit_callback (void)
+{
+ led_y =!led_y;
+ //str.append("S");
+ //pc2.printf("%s\n", str);
+ //printSTOP(3, 7);
+ //str.clear();
+}
+
+#endif // EXAMPLE_9_CHECK_APDS_9960
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/APDS_9960.lib Fri Feb 07 01:21:16 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/kenjiArai/code/APDS_9960/#20566fe6ed51
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTS221.lib Fri Feb 07 01:21:16 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mcm/code/HTS221/#1fc3a35d731a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPS22HB.lib Fri Feb 07 01:21:16 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/kenjiArai/code/LPS22HB/#0414b9099641
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LSM9DS1.lib Fri Feb 07 01:21:16 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/kenjiArai/code/LSM9DS1/#e0759c34eb93
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinDetect.lib Fri Feb 07 01:21:16 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/AjK/code/PinDetect/#cb3afc45028b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_revision.cpp Fri Feb 07 01:21:16 2020 +0000 @@ -0,0 +1,26 @@ +/* + * Check Mbed revision + * + * Copyright (c) 2019,'20 Kenji Arai / JH1PJL + * http://www7b.biglobe.ne.jp/~kenjia/ + * https://os.mbed.com/users/kenjiArai/ + * Created: July 17th, 2019 + * Revised: January 30th, 2020 + */ + +#include "mbed.h" + +// RUN ONLY ON mbed-os5.15.0 +// https://github.com/ARMmbed/mbed-os/releases/tag/mbed-os-5.15.0 +#if (MBED_MAJOR_VERSION == 5) &&\ + (MBED_MINOR_VERSION == 15) &&\ + (MBED_PATCH_VERSION == 0) +#else +//#warning "Please use Mbed-os5.15.0" +# error "Please use Mbed-os5.15.0" +#endif + +#ifndef TARGET_NRF52840 +# error "Select Nordic nRF52840-DK" +# warning "see https://os.mbed.com/platforms/Nordic-nRF52840-DK/" +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common.cpp Fri Feb 07 01:21:16 2020 +0000
@@ -0,0 +1,123 @@
+/*
+ * Nano 33 BLE Sense
+ * Arudiono nRF52840 module
+ * Common functions
+ *
+ * Copyright (c) 2020 Kenji Arai / JH1PJL
+ * http://www7b.biglobe.ne.jp/~kenjia/
+ * https://os.mbed.com/users/kenjiArai/
+ * Started: January 22nd, 2020
+ * Revised: Feburary 5th, 2020
+ *
+ */
+
+// Pre-selection --------------------------------------------------------------
+#include "select_example.h"
+//#define USE_COMMON_FUNCTION
+#ifdef USE_COMMON_FUNCTION
+
+// Include --------------------------------------------------------------------
+#include "mbed.h"
+#include "nano33blesense_iodef.h"
+#include "USBSerial.h"
+#include "LPS22HB.h"
+#include "LSM9DS1.h"
+#include "HTS221.h"
+#include "glibr.h"
+
+// Definition -----------------------------------------------------------------
+
+// Constructor ----------------------------------------------------------------
+extern RawSerial pc;
+extern I2C i2c;
+
+// RAM ------------------------------------------------------------------------
+
+// ROM / Constant data --------------------------------------------------------
+
+// Function prototypes --------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Control Program
+//------------------------------------------------------------------------------
+void check_i2c_connected_devices(void)
+{
+ char dt[2];
+ int status;
+
+ // Check I2C line
+ i2c.frequency(400000);
+ dt[0] = 0;
+ pc.printf("check I2C device --> START\r\n");
+ for (uint8_t i = 0; i < 0x80; i++) {
+ int addr = i << 1;
+ status = i2c.write(addr, dt, 1, true);
+ if (status == 0) {
+ pc.printf("Get ACK form address = 0x%x\r\n", i);
+ }
+ }
+}
+
+void check_i2c_sensors(void)
+{
+ char dt[2];
+
+ // LSM9DS1
+ dt[0] = WHO_AM_I_XG;
+ int addr = LSM9DS1_AG_I2C_ADDR(1);
+ i2c.write(addr, dt, 1, true);
+ dt[0] = 0;
+ i2c.read(addr, dt, 1, false);
+ pc.printf("LSM9DS1_AG is ");
+ if (dt[0] != WHO_AM_I_AG_RSP) {
+ pc.printf("NOT ");
+ }
+ pc.printf("available -> 0x%x = 0x%x\r\n", addr >> 1, dt[0]);
+ dt[0] = WHO_AM_I_M;
+ addr = LSM9DS1_M_I2C_ADDR(1);
+ i2c.write(addr, dt, 1, true);
+ dt[0] = 0;
+ i2c.read(addr, dt, 1, false);
+ pc.printf("LSM9DS1_M is ");
+ if (dt[0] != WHO_AM_I_M_RSP) {
+ pc.printf("NOT ");
+ }
+ pc.printf("available -> 0x%x = 0x%x\r\n", addr >> 1, dt[0]);
+ // LPS22HB
+ dt[0] = LPS22HB_WHO_AM_I;
+ addr = LPS22HB_G_CHIP_ADDR;
+ i2c.write(addr, dt, 1, true);
+ dt[0] = 0;
+ i2c.read(addr, dt, 1, false);
+ pc.printf("LPS22HB is ");
+ if (dt[0] != I_AM_LPS22HB) {
+ pc.printf("NOT ");
+ }
+ pc.printf("available -> 0x%x = 0x%x\r\n", addr >> 1, dt[0]);
+ // HTS221
+ dt[0] = HTS221::HTS221_WHO_AM_I;
+ addr = HTS221::HTS221_ADDRESS;
+ i2c.write(addr, dt, 1, true);
+ dt[0] = 0;
+ i2c.read(addr, dt, 1, false);
+ pc.printf("HTS221 is ");
+ if (dt[0] != HTS221::WHO_AM_I_VALUE) {
+ pc.printf("NOT ");
+ }
+ pc.printf("available -> 0x%x = 0x%x\r\n", addr >> 1, dt[0]);
+ // APDS_9960
+ dt[0] = APDS9960_ID;
+ addr = APDS9960_I2C_ADDR << 1;
+ i2c.write(addr, dt, 1, true);
+ dt[0] = 0;
+ i2c.read(addr, dt, 1, false);
+ pc.printf("APDS_9960 is ");
+ if (dt[0] == APDS9960_ID_1 || dt[0] == APDS9960_ID_2) {
+ ;
+ } else {
+ pc.printf("NOT ");
+ }
+ pc.printf("available -> 0x%x = 0x%x\r\n", addr >> 1, dt[0]);
+}
+
+#endif // USE_COMMON_FUNCTION
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Fri Feb 07 01:21:16 2020 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#64853b354fa188bfe8dbd51e78771213c7ed37f7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nano33blesense_iodef.h Fri Feb 07 01:21:16 2020 +0000 @@ -0,0 +1,97 @@ +/* + * Nano 33 BLE Sense + * Arudiono nRF52840 module + * + * Copyright (c) 2020 Kenji Arai / JH1PJL + * http://www7b.biglobe.ne.jp/~kenjia/ + * https://os.mbed.com/users/kenjiArai/ + * Started: January 22nd, 2020 + * Revised: Feburary 5th, 2020 + * + */ + +// LEDs +#define PIN_YELLOW P0_13 +#define PIN_GREEN P1_9 +#define PIN_LR P0_24 +#define PIN_LG P0_16 +#define PIN_LB P0_6 + +// APDS-9960 +#define PIN_APDS_INT P0_19 + +// SPI +#define PIN_SPI_MOSI P1_1 +#define PIN_SPI_MISO P1_8 +#define PIN_SPI_SCK P0_13 + +// External I2C +#define PIN_EXT_SDA P0_31 +#define PIN_EXT_SCL P0_2 + +// Internal I2C +#define PIN_SDA1 P0_14 +#define PIN_SCL1 P0_15 + +// Power line control +#define PIN_I2C_PULLUP P1_0 +#define PIN_VDD_ENV P0_22 +#define PIN_APDS_PWR P0_20 +#define PIN_MIC_PWR P0_17 + +//-------- Reference -------------------------------------------------- +#if 0 +https://github.com/arduino/ArduinoCore-nRF528x-mbedos +\variants\ARDUINO_NANO33BLE\variant.cpp +& +\variants\ARDUINO_NANO33BLE\pins_arduino.h + + // D0 - D7 + P1_3, 0 + P1_10, 1 + P1_11, 2 + P1_12, 3 + P1_15, 4 + P1_13, 5 + P1_14, 6 + P0_23, 7 + + // D8 - D13 + P0_21, 8 + P0_27, 9 + P1_2, 10 PIN_SPI_SS (10u) + P1_1, 11 PIN_SPI_MOSI (11u) + P1_8, 12 PIN_SPI_MISO (12u) + P0_13, 13 LED_BUILTIN (13u) / PIN_SPI_SCK (13u) + + // A0 - A7 + P0_4, 14 PIN_A0 (14u) + P0_5, 15 PIN_A1 (15u) + P0_30, 16 PIN_A2 (16u) + P0_29, 17 PIN_A3 (17u) + P0_31, 18 PIN_A4 (18u) / PIN_WIRE_SDA (18u) + P0_2, 19 PIN_A5 (19u) / PIN_WIRE_SCL (19u) + P0_28, 20 PIN_A6 (20u) + P0_3, 21 PIN_A7 (21u) + + // LEDs + P0_24, 22 LEDR (22u) + P0_16, 23 LEDG (23u) + P0_6, 24 LEDB (24u) + P1_9, 25 LED_PWR (25u) + + P0_19, 26 PIN_INT_APDS (26u) + + // PDM + P0_17, 27 PIN_PDM_PWR (27) + P0_26, 28 PIN_PDM_CLK (28) + P0_25, 29 PIN_PDM_DIN (29) + + // Internal I2C + P0_14, 30 PIN_WIRE_SDA1 (30u) + P0_15, 31 PIN_WIRE_SCL1 (31u) + + // Internal I2C + P1_0, 32 PIN_ENABLE_SENSORS_3V3 (32u) + P0_22, 33 PIN_ENABLE_I2C_PULLUP (33u) +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/readme_1st.txt Fri Feb 07 01:21:16 2020 +0000 @@ -0,0 +1,36 @@ +-------------------------------------------------------------------------------- +Nano 33 BLE Sense --- Arudiono nRF52840 module (Nano 33 BLE Sense) + By Kenji Arai / JH1PJL + http://www7b.biglobe.ne.jp/~kenjia/ + https://os.mbed.com/users/kenjiArai/ + + Feburary 7th, 2020 +-------------------------------------------------------------------------------- + +------- Mbed Online Compiler --------------------------------------------------- + +Target: nRF52840-DK +mbed-os: mbed-os5.15.0 +Select program: + Open select_example.h + Change EXAMPLE_NUMBER (line31) +Compile: +<!!!! CAUTION !!!> + You can compile without error. + Created hex file does NOT run on Nano 33 BLE Sense board. + +------- Mbed Studio ------------------------------------------------------------ + +Target: ARDUINO_NANO33BLE +Mbed Studio: 0.8.1 +Select program: + Same as online program +Compile: + You can compile and use a hex file for the board. +How to write hex file into the board: + Need prepare DAPLink (use SWDIO & SWCLK line). +<!!!! CAUTION !!!> + Orignal board has Arduino bootloarder and + Mbed hex file overwrites it. + As a resule, you cannot use Arduino bootloarder anymore. +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/select_example.h Fri Feb 07 01:21:16 2020 +0000 @@ -0,0 +1,63 @@ +/* + * Mbed Application program + * Nano 33 BLE Sense board runs on mbed-OS5 + * + * Copyright (c) 2020 Kenji Arai / JH1PJL + * http://www7b.biglobe.ne.jp/~kenjia/ + * https://os.mbed.com/users/kenjiArai/ + * Started: January 22nd, 2020 + * Revised: Feburary 7th, 2020 + */ + +/* + You can select several examples as followings. + 0. 0_Blinky_LED + LED Blinky + 1. 1_check_I2C_devices + Check sensors connected to I2C line + 2. 2_check_LSM9DS1 + iNEMO inertial module:3D accelerometer, 3D gyroscope, 3D magnetometer + 3. 3_check_LPS22HB + MEMS nano pressure sensor:260-1260 hPa absolute Digital output barometer + 4. 4_check_HTS221 + Capacitive digital sensor for relative humidity and temperature + 5. 5_Combined_enviromental_sensors + Demonstration sample program SD Card + 6. 6_check_APDS_9960 + Digital Proximity, Ambient Light, RGB and Gesture Sensor + + -> PLEASE SET VCOM BAUDRATE IS 115200 + */ +#define EXAMPLE_NUMBER 0 // select 0 to 6 + +//----------------- You don't need any modification ---------------------------- +#if EXAMPLE_NUMBER == 0 +# define EXAMPLE_0_BLINKY_LED +# warning "Select 0_Blinky_LED" +#elif EXAMPLE_NUMBER == 1 +# define EXAMPLE_1_CHECK_I2C_DEVICES +# define USE_COMMON_FUNCTION +# warning "Select 1_Check_I2C_devices" +#elif EXAMPLE_NUMBER == 2 +# define EXAMPLE_2_CHECK_LSM9DS1 +# define USE_COMMON_FUNCTION +# warning "Select 2_check_LSM9DS1" +#elif EXAMPLE_NUMBER == 3 +# define EXAMPLE_3_CHECK_LPS22HB +# define USE_COMMON_FUNCTION +# warning "Select 3_check_LPS22HB" +#elif EXAMPLE_NUMBER == 4 +# define EXAMPLE_4_CHECK_HTS221 +# define USE_COMMON_FUNCTION +# warning "Select 4_check_HTS221" +#elif EXAMPLE_NUMBER == 5 +# define EXAMPLE_5_COMB_ENV_SENSORS +# define USE_COMMON_FUNCTION +# warning "Select 5_Combined_enviromental_sensors" +#elif EXAMPLE_NUMBER == 6 +# define EXAMPLE_6_CHECK_APDS_9960 +# define USE_COMMON_FUNCTION +# warning "Select 6_check_APDS_9960" +#else +# error " Please set 0 to 6 number for EXAMPLE_NUMBER!!" +#endif \ No newline at end of file