[Arduino] Read BLE Byte Array On Arduino 101 - Qiita

  1. Trend
  2. Question
  3. Advent Calendar
  4. Official Event
  5. Official Column
  6. Organization
  7. Qiita Careers
  8. AI x Dev x Team
00

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CancelDelete

More than 5 years have passed since last update.

@Dreamwalker[Arduino] Read BLE Byte Array on Arduino 101
  • Arduino
  • intel
  • Arduino101
Last updated at 2018-07-28Posted at 2018-07-28 Arduino101?
  1. Core uP : Intel Curie[ x86 Quark core ]
  2. Bit : 32 Bit
  3. About Arduino 101
CODE

Important

  1. BLECharCharacteristic --> BLECharacteristic
ble_callback.ino /* Copyright (c) 2016 Intel Corporation. All rights reserved. See the bottom of this file for the license terms. */ # include <CurieBLE.h> const int ledPin = 13; // set ledPin to use on-board LED BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service // create switch characteristic and allow remote device to read and write BLECharacteristic switchChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, 20); void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); // use the LED on pin 13 as an output // begin initialization BLE.begin(); // set the local name peripheral advertises BLE.setLocalName("LEDCB"); // set the UUID for the service this peripheral advertises BLE.setAdvertisedService(ledService); // add the characteristic to the service ledService.addCharacteristic(switchChar); // add service BLE.addService(ledService); // assign event handlers for connected, disconnected to peripheral BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); // assign event handlers for characteristic switchChar.setEventHandler(BLEWritten, switchCharacteristicWritten); // set an initial value for the characteristic switchChar.setValue(0,0); // start advertising BLE.advertise(); Serial.println(("Bluetooth device active, waiting for connections...")); } void loop() { // poll for BLE events BLE.poll(); } void blePeripheralConnectHandler(BLEDevice central) { // central connected event handler Serial.print("Connected event, central: "); Serial.println(central.address()); } void blePeripheralDisconnectHandler(BLEDevice central) { // central disconnected event handler Serial.print("Disconnected event, central: "); Serial.println(central.address()); } int rxHead = 0; volatile static uint8_t rxBuffer[20]; void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) { // central wrote new value to characteristic, update LED Serial.print("Characteristic event, written: "); size_t len = switchChar.valueLength(); const unsigned char *data = switchChar.value(); Serial.print("Got data:"); Serial.write(data, len); } void addReceiveBytes(const uint8_t* bytes, size_t len) { // note increment rxHead befor writing // so need to increment rxTail befor reading for (size_t i = 0; i < len; i++) { rxHead = (rxHead + 1) % sizeof(rxBuffer); rxBuffer[rxHead] = bytes[i]; } } Result

image.png

000

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing upSign upLogin00

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CancelDelete

Tag » Arduino Ble Byte Array