티스토리 뷰
python/Lecture
[arduino] DS18B20 Digital Sensor 연결 및 BLE 통신 to App.
jinozpersona 2023. 11. 23. 15:17Arduino UNO R4 Wifi : DS18B20 연결도
[Arduino IDE 사용] / [Visual Studio Code사용]
Arduino IDE or VS code 초기 셋팅 및 설정 참고
https://jinozblog.tistory.com/207
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ArduinoBLE.h>
#define ONE_WIRE_BUS 13
OneWire Wire(ONE_WIRE_BUS);
DallasTemperature sensor(&Wire);
char value[8];
const int ledPin = LED_BUILTIN; // pin to use for the LED
static const char* sensing = "Hello, persona!";
BLEService sensingService("0454e724-abec-43e1-8bbd-46db509439c4"); // User defined service
BLEStringCharacteristic sensingCharacteristic("0454e724-abec-43e1-8bbd-46db509439c4", BLERead | BLENotify, 15);
void setup() {
Serial.begin(9600); // initialize serial communication
while (!Serial);
pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin
if (!BLE.begin()) { // initialize BLE
Serial.println("starting BLE failed!");
while (1);
}
BLE.setLocalName("ArduinoR4_persona"); // Set name for connection
BLE.setAdvertisedService(sensingService); // Advertise service
sensingService.addCharacteristic(sensingCharacteristic); // Add characteristic to service
BLE.addService(sensingService); // Add service
// assign event handlers for connected, disconnected to peripheral
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
// assign event handlers for characteristic
sensingCharacteristic.setValue(sensing); // Set sensing string
BLE.advertise(); // Start advertising
Serial.println(("Bluetooth® device active, waiting for connections..."));
}
void loop() {
BLE.poll();
sensor.requestTemperatures();
dtostrf(sensor.getTempCByIndex(0) , 5, 2, value);
sensingCharacteristic.writeValue(value);
}
void blePeripheralConnectHandler(BLEDevice central) {
// central connected event handler
Serial.print("Connected event, central: ");
Serial.println(central.address());
Serial.println("LED on");
digitalWrite(ledPin, HIGH);
}
void blePeripheralDisconnectHandler(BLEDevice central) {
// central disconnected event handler
Serial.print("Disconnected event, central: ");
Serial.println(central.address());
}
Serial Monitor
iPhone App. : LightBlue
우측 상단 Hex 클릭 : to UTF-8
Read again : 온도계 손으로 잡고 있으면 올라가는 거 확인 가능
반응형
'python > Lecture' 카테고리의 다른 글
[arduino][python] HC-06 Bluetooth 통신 Test (0) | 2023.11.27 |
---|---|
[arduino][python] DS18B20 Digital Sensor pyserial 통신 (0) | 2023.11.23 |
[arduino] DS18B20 Digital Sensor 연결 및 wifi 통신 to Web (0) | 2023.11.23 |
[arduino] DS18B20 Digital Sensor 연결 및 wifi 통신 with MariaDB (0) | 2023.11.22 |
[arduino][python] DS18B20 Digital Sensor Bluetooth 통신 (0) | 2023.11.21 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- sublime text
- Model
- arduino
- MacOS
- template
- Pandas
- Templates
- DS18B20
- github
- 라즈베리파이
- r
- server
- vscode
- SSH
- DAQ
- pyserial
- Django
- 코로나19
- analysis
- COVID-19
- 확진
- CSV
- Regression
- raspberrypi
- Python
- Raspberry Pi
- 자가격리
- 코로나
- git
- ERP
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
글 보관함