개발자/Arduino

NANO 33 BLE Sense - 5 온보드 제스처 센싱 실습

지구빵집 2020. 5. 10. 15:18
반응형

 

NANO 33 BLE Sense - 5 온보드 제스처센서 실습

 

이번 실습은 NANO 33 BLE Sense의 온보드 제스처 센서(APDS-9960)에 대해 알아보고, 제스처를 인식하여 RGB LED로 표현하고 제스처 방향을 시리얼 모니터에 출력하는 실습을 한다.

 

Arduino nano 33 BLE Sense 보드 모든 구성품 실습 강의

 

NANO 33 BLE Sense - 1. 온보드 RGB LED 실습

NANO 33 BLE Sense - 2. LSM9DS1, 9축 IMU센서 정보 활용

NANO 33 BLE Sense - 3. 기압 센서 사용해보기

NANO 33 BLE Sense - 4. 온습도 센서 HTS221 실습

NANO 33 BLE Sense - 5. 온보드 제스처 센싱 실습

NANO 33 BLE Sense - 6. 온보드 컬러 인식 RGB 센서 실습

NANO 33 BLE Sense - 7. 온보드 거리센서 실습

NANO 33 BLE Sense - 8. 더 살펴볼 것, 리소스와 더 많은 기능

 

 

Arduino NANO 33 BLE Sense의 온보드 센서 중 하나인 APDS-9960은 제스처 인식 이외에도 다양한 기능이 있다. 근접, RGB 색상, 주변광 인식이 가능한데, 자세한 정보는 아래를 참고한다.

 

- 작동 전압: 2.4 ~ 3.6 V(센서), 3.0 ~ 4.5 V(LED)

- 작동 온도: -30 ~ 85 °C

- 작동 전류: 790µA(근접센싱), 790µA(제스처센싱), 38µA(대기)

- 인터페이스: I2C

 

참고: 아두이노 APDS-9960 라이브러리  

 

ArduinoAPDS9960 library 설명

 

Arduino APDS9960 라이브러리를 사용하면 Arduino Nano 33 BLE Sense에서 제공되는 APDS9960 센서를 사용하여 동작, 색상, 빛의 강도 및 근접성을 읽을 수 있습니다.

 

제스처 판독 값은 센서 내부의 4 개의 포토 다이오드에서 손의 움직임을 감지 한 것에 기초한 반면, 근접성은 센서로 다시 반사되는 것 (IR을 반사하는 모든 것)에 의해 반사되는 적외선의 양에 의해 판독됩니다. R, G, B 및 흰색 구성 요소에 대해 16 비트 값으로 색상이 제공됩니다. 센서에 닿는 빛이 주변 물체이고 일부 물체에 반사되지 않으면 색 온도를 계산할 수 있습니다. 그렇지 않으면 센서에 빛을 반사하는 물체의 색을 감지 할 수 있습니다.

 

이 라이브러리를 사용하려면 아래 코드를 제일 위에 넣어야 한다.

 

#include <Arduino_APDS9960.h>

 

아래는 제공하는 함수(api) 리스트.

 

begin()

end()

gestureAvailable()

readGesture()

colorAvailable()

readColor()

proximityAvailable()

readProximity()

setGestureSensitivity()

setInterruptPin()

setLEDBoost()

 

 

#include <Arduino_APDS9960.h>

const int RED = 22;
const int GREEN = 23;
const int BLUE = 24;

void setup()
{
  // RGB LED 세팅
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  digitalWrite(RED, HIGH);
  digitalWrite(GREEN, HIGH);
  digitalWrite(BLUE, HIGH);
  Serial.begin(9600);
  if (!APDS.begin()) { // 센서 초기화가 실패하면 오류를 발생시킵니다.
    Serial.println("APDS9960센서 오류!");
    while (1)
      ;
  }
  // APDS.setSensitivity(80); //감도 조절 (1~100)
  Serial.println("제스처 인식 시작!");
}

void loop() 
{
  if (APDS.gestureAvailable()) { // 제스처가 인식되면 true를 반환합니다.
    Serial.println("Gesture!");
    int gesture = APDS.readGesture(); // 인식된 제스처를 gesture 변수에 저장
    switch (gesture) { // 각 제스처에 맞는 항으로 이동
      case GESTURE_UP: // 상승 제스처
        Serial.println("윗쪽!");
        digitalWrite(RED, LOW);
        delay(1000);
        digitalWrite(RED, HIGH);
        break;
      case GESTURE_DOWN: // 하강 제스처
        Serial.println("아랫쪽!");
        digitalWrite(GREEN, LOW);
        delay(1000);
        digitalWrite(GREEN, HIGH);
        break;
      case GESTURE_LEFT: // 왼쪽 제스처
        Serial.println("왼쪽!");
        digitalWrite(BLUE, LOW);
        delay(1000);
        digitalWrite(BLUE, HIGH);
        break;
      case GESTURE_RIGHT: // 오른쪽 제스처
        Serial.println("오른쪽!");
        digitalWrite(RED, LOW);
        digitalWrite(GREEN, LOW);
        delay(1000);
        digitalWrite(RED, HIGH);
        digitalWrite(GREEN, HIGH);
        break;
      default:
        break;
    }
  }
}

 

소스코드 출처: 제스처 센서 사용하기

 

소스코드를 컴파일하고 업로딩을 완료했다면 BLE sense 보드를 아래에 놓고 위에서 손을 전후좌우로 움직이며 씨리얼 모니터를 확인하면 아래와 같은 결과를 볼 수 있다.

 

 

참고로 제스처 센서에서 확인하는 다른 값들이 있다.

 

Gesture Description
UP A swipe from the bottom of the board to the top and out of range of the sensor. Make sure that your wrist/arm is not in the sensor's range at the end of the swipe!
DOWN A swipe from the top of the board to the bottom and out of range of the sensor.
LEFT A swipe from the right side of the board to the left and out of range of the sensor.
RIGHT A swipe from the left side of the board to the right and out of range of the sensor.
NEAR Object (e.g. hand) starts far above the sensor, moves close to the sensor, hovers for at least 1 second, and moves out of range of the sensor.
FAR Object starts near the sensor, hovers for at least 1 second, and then moves up above and out of range of the sensor.
NONE The sensor could not correctly guess the gesture being performed.

 

여기까지. 놀러나가야지. ^^

 

이미지 출처와 예제도 있는 곳. https://learn.sparkfun.com/tutorials/apds-9960-rgb-and-gesture-sensor-hookup-guide/all

 

 

 

 

반응형