BASIC4MCU | 질문게시판 | 아두이노 나노33 IOT 의 BLE 연결 문제
페이지 정보
작성자 가루밀 작성일2023-02-24 09:53 조회70회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=22333
본문
아두이노 나노33 iot 의 ble 연결 때문에 고민하고 있습니다.
pc에 아두이노 스케치 프로그램 띄우고 보드와 USB로 연결한 상태로는 스마트폰과 BLE 연결 잘 됩니다.
스마트폰에는 "라이트블루" 앱이 깔려 있습니다.
자세히 설명하면
1. 스케치 프로그램의 시리얼 모니터를 실행하기 전에는 스마트폰 앱에서 보드를 검색하지 못합니다
2. 시리얼모니터를 실행하면 스마트폰의 앱에서 보드 검색 됩니다.
3. 앱과 BLE 연결하여 기능을 확인 가능합니다
화면 캡처해서 정리 했습니다
PC 에서는 이렇게 BLE 연결 되는데, 문제는 PC연결이 아니고 외부전원 사용할 때입니다.
어댑터(5V1A )를 전원으로 보드에 연결해서 앱에서 검색을 시도하면, PC연결에서 시리얼모니터 실행전 상황처럼 스마트폰 앱에서 검색이 안됩니다
아두이노 보드의 리셋 버튼 눌러도 안됩니다.
웹에서 이것저것 검색해도 저의 짧은 지식으로는 어렵네요.
이후에 배터리를 전원으로 연결해서 사용할 예정인데, 난감 합니다.
사용 코드는 스케치 프로그램의 BLE 샘플코드로 테스트 하고 있습니다.
=================================
/*LEDThis example creates a Bluetooth® Low Energy peripheral with service that contains acharacteristic to control an LED.The circuit:- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) ornRF Connect (Android), to interact with the services and characteristicscreated in this sketch.This example code is in the public domain.*/#includeBLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by centralBLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);const int ledPin = LED_BUILTIN; // pin to use for the LEDvoid setup() {Serial.begin(9600);while (!Serial);// set LED pin to output modepinMode(ledPin, OUTPUT);// begin initializationif (!BLE.begin()) {Serial.println("starting Bluetooth® Low Energy module failed!");while (1);}// set advertised local name and service UUID:BLE.setLocalName("LED");BLE.setAdvertisedService(ledService);// add the characteristic to the serviceledService.addCharacteristic(switchCharacteristic);// add serviceBLE.addService(ledService);// set the initial value for the characeristic:switchCharacteristic.writeValue(0);// start advertisingBLE.advertise();Serial.println("BLE LED Peripheral");}void loop() {// listen for Bluetooth® Low Energy peripherals to connect:BLEDevice central = BLE.central();// if a central is connected to peripheral:if (central) {Serial.print("Connected to central: ");// print the central's MAC address:Serial.println(central.address());// while the central is still connected to peripheral:while (central.connected()) {// if the remote device wrote to the characteristic,// use the value to control the LED:if (switchCharacteristic.written()) {if (switchCharacteristic.value()) { // any value other than 0Serial.println("LED on");digitalWrite(ledPin, HIGH); // will turn the LED on} else { // a 0 valueSerial.println(F("LED off"));digitalWrite(ledPin, LOW); // will turn the LED off}}}// when the central disconnects, print it out:Serial.print(F("Disconnected from central: "));Serial.println(central.address());}}
댓글 0
조회수 70등록된 댓글이 없습니다.