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: 6_check_APDS_9960/main6.cpp
- Revision:
- 0:f1a10797d9f6
- Child:
- 1:cce280da16d4
--- /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