Arduino Tutorial: Integrating Bluetooth LE and iOS with Swift

Hi alombardi,
To receive the value changes from a Characteristic do the following (Core Bluetooth):

  1. In the didDiscoverCharacteristicsFor peripheral delegate method, register to be notified when the characteristic value changes by calling peripheral.setNotifyValue(true, for: characteristic).
  2. Then you will begin receives callbacks on the didUpdateValueFor peripheral delegate method as the values change. Grab the value from characteristic.value.

Owen

Hi. This is a great tutorial. Thank you for it.

I am trying to deploy this, but without the servo.
I am just trying to pass the slider value from iOs, then use that value on the arduino.
That said, I am not sure if I am really passing any data.
When I run the iOs app, it shows ‘Connected’, but when running the following code, I do not get any indication via serial monitor that ‘BLE_Shield.available()’ contains any data, and wondering why.

I have made the arduino code super simple, to just indicate when/if data is present.
Any insight greatly appreciated.

Arduino Uno with Black Widow BLE
Xcode 8 / iOs 10.3.3

// Arduino Bluetooth LE Servo Controlled by iOS

#include <SoftwareSerial.h>
int LED = 13; // Most Arduino boards have an onboard LED on pin 13
SoftwareSerial BLE_Shield(4,5, true);

void setup() // Called only once per startup
{
Serial.begin(9600);
BLE_Shield.begin(9600); // Setup the serial port at 9600 bps.
Serial.println(“Starting”);
}

void loop() // Continuous loop
{

// See if new position data is available
if (BLE_Shield.available()) {
Serial.println(“DATA DETECTED”);
// Serial.println(BLE_Shield.read());
// myservo.write(); // Write position to servo
}
}

Hi Robd,
Are you sure the iOS side is writing to the TX characteristic?
If you have a servo on hand, I try downloading the final tutorial project and see if it works okay, then work backwards adding your changes.

Also, I didn’t check the SoftwareSerial library, but what is the ‘true’ parameter for?

I’m building this soon, in the mean-time I thought I’d mention the Bluetooth shield link changed to: Back-40 - Black Widow BLE Arduino shield It actually has a link back to this tutorial in it’s description. And the price for the jumper wires is actually only $1.95 for 30.

Thanks. I updated the link and text.

This tutorial is more than six months old so questions regarding it are no longer supported for the moment. We will update it as soon as possible. Thank you! :]