상세 컨텐츠

본문 제목

드론에 들어가 보다_02(보드준비)

안드로이드+드론 제작

by 김일국 2022. 10. 11. 13:02

본문

이전 포스트에 안드로이드 앱 준비에 이어서

오늘은 ESP32 칩셋의 블루투스 작동여부를 확인한다.

- ESP32칩셋의 자세한 정보는 예전 포스트 에 있다. -> https://kimilguk.tistory.com/773 

- 예전 학원에서 강의할 때 사용한 NODE MCU보드(ESP8266칩셋)은 무선 통신으로 와이파이만 지원하지만 ESP32는 와이파이와 함께 블루투스를 사용 가능하다.

### lilygo higrow 보드(ESP32칩셋)의 블루투스 테스트 하기

1). 예전 작업물인 온도, 습도, 광도 데이터를 WiFi 로 ThinkPost 사이트로 보내기 실습 소스를 분해한다.

- 충전용 태양광 패널 분리(아래)

- 본체 케이스 분리(아래)

- 충전지 분리하가 : lilygo higrow 보드(ESP32칩셋) 상단의 콘덴서가 있는 보드는 태양광패널과 충전지 사이 컨트롤 보드이다. (아래)

- 노트북(duo CPU, 6G 램, 윈10)과 보드 USB Type C 케이블로 연결(아래)

- 연결 후 윈도우 드라이버 설치 후(이전 포스트 참조: https://kimilguk.tistory.com/773 ) 장치관리자에서 포트 확인(아래)

- 아두이노 스케치 프로그램에서 환경설정에서 추가적인 보드 매니저 URLs 추가(아래)

- 아두이노 스케치 프로그램에서 보드 매니저에서 esp32 추가(아래)

- 아두이노 스케치 프로그램에서 보드 선택(아래)

- 노르딕 블루투스 앱 설치 : https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&hl=ko&gl=US
 블루투스 보드와 앱사이 통신 작동 확인용(아래)

- 갤러시 S1에 nRF Connect for Mobile 앱을 설치한 후 앱에서 ESP32 블루투스 장치를 검색한 화면(아래)

- 아두이노 스케치 프로그램으로 내장된 ESP32 보드용 예제 소스 불러오기(아래)

- 참고로, 예전 포스트에서 사용한 메뉴 하단의 BH1750은 광도(조도)센서 테스트, DHT12 는 온도/습도센서 예제 소스 이다.

- ESP32 칩셋에 위 예제 소스를 라이팅 후 아두이노 스케치 프로그램의 시리얼 모니터에서 연결, 스마트폰에서 전송된 값 확인(아래)

- 위 스케치 예제 프로그램 소스에서 3가지 사항을 수정했다.(아래 수정,추가 한 곳 표시)

//주의) 현재 예제에 사용된 UUID 값은 안드로이드 앱의 UUID로 변경한다.
// 00001101-0000-1000-8000-00805F9B34FB
#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
//중략...
void loop() {
    // notify changed value
    if (deviceConnected) {
        pCharacteristic->setValue((uint8_t*)&value, 4);
        pCharacteristic->notify();
        Serial.println(value, HEX);//추가
        value++;
        delay(500); // 3밀리초에서 0.5초로 수정
    }
    // disconnecting
    if (!deviceConnected && oldDeviceConnected) {
        delay(500); // give the bluetooth stack the chance to get things ready
        pServer->startAdvertising(); // restart advertising
        Serial.println("disconnecting");//출력 단어start advertising 수정
        oldDeviceConnected = deviceConnected;
    }
    // connecting
    if (deviceConnected && !oldDeviceConnected) {
        // do stuff here on connecting
        oldDeviceConnected = deviceConnected;
        Serial.println("connecting");//추가
    }
}

여기 까지 기존 보드를 재 사용하기 위한 블루투스 장비 테스트를 해 보았다.

위 예제와 준비된 안드로이드 앱과 연결이 되지 않아서 다른 스케치 프로그램으로 테스트가 진행 되었다.(아래)

//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
}

void loop() {
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(20);
}

그래서, Bluetooth Termianl 앱으로 보드와 연결 시켜 보았다.(아래 안드로이드 앱 정보)

https://play.google.com/store/apps/details?id=ptah.apps.bluetoothterminal&hl=ko&gl=US

더 자세한 사항은 다음 참조 사이트에 있다. https://dronebotworkshop.com/esp32-intro/

위 참조 사이트에서 앱 만 다른 것으로 설치해서 테스트 해 보았다.(다음 포스트에서)

관련글 더보기

댓글 영역