View unanswered posts | View active topics It is currently Wed Mar 29, 2017 7:20 am

Reply to topic  [ 4 posts ] 
iPhone app to display sensor data using BLEShield 
Author Message

Joined: Fri Aug 03, 2012 11:41 pm
Posts: 1

I am attempting to test a series of analog sensors with an iPhone 4s, using your BLEShield. I am writing the iPhone app in Xcode 4.4, using the CoreBluetooth framework, developing on a MacBook Pro running MacOS 10.7.4. I can verify that the hardware components are working correctly and I can connect to the BLEShield and explore the services via your BLExplr app. I am able to verify that the sensors are working correctly when using a physical USB connection and viewing the results in the serial monitor of the IDE, with the selected com port. But I am having difficulty figuring out how to connect to the BLEShield using the iPhone app to view the returned sensor data. For the iPhone app, I am currently working with sample apps included in the IOS SDK, and I am looking at examples found online. Working with sample code, I entered the UUID of the BLEShield, but all attempts to connect to the BLEShield have so far been unsuccessful. Can you please point me in the right direction? What do I need to do to sense the BLE device, connect to it, then read the connected analog sensor data? If you know of any sample code that can help, I would greatly appreciate it.

You had mentioned that you would provide an open sourced sample iPhone app. Is that available for download?



Mon Aug 06, 2012 12:37 am
Site Admin

Joined: Thu Aug 02, 2012 11:36 am
Posts: 166
Hello Bart,

you need to discover to a peripheral which is advertising the BLE Shield Service (UUID F9266FD7-EF07-45D6-8EB6-BD74F13620F9)
See for a listing with what UUIDs you have to deal with.

Try to discover for peripherals which are advertising a service with UUID F9266FD7-EF07-45D6-8EB6-BD74F13620F9, connect to it and then try to get notifications on the RX characteristic with UUID 4585C102-7784-40B4-88E1-3CB5C4FD37A3.

I have currently no sample app available which is open source, but I will work on a BLE Shield App asap, which I will open source and illustrate how to connect to the BLE Shield.

There is a BLE Sample Application in the Apple iOS Developer Programme available which should be a good starting point for a simple BLE Shield app as well.
Have you tried this app?


Mon Aug 06, 2012 8:05 pm
Profile WWW

Joined: Sun Aug 05, 2012 9:00 am
Posts: 5
Bart, here is some sample code that should get you started.

In the header file where you will run the following code, make sure it is a CBCentralManagerDelegate, and #import <CoreBluetooth/CoreBluetooth.h>

In viewDidLoad:

 mgr =
[[CBCentralManager alloc] initWithDelegate:self queue:nil];
[mgr scanForPeripheralsWithServices:nil options:nil];

Implement the following code to identify discovered BLE Devices. You will notice I have some code to identify Michael's Arduino BLE Shield, which is identified as "BLE Shield". I also created a mutable dictionary called "peripherals" which I can use to store peripherals that were found during the search, by their pUUID, so there will never be dupes.

- (void)centralManager:(CBCentralManager *)central
 didDiscoverPeripheral:(CBPeripheral *)peripheral
     advertisementData:(NSDictionary *)advertisementData
                  RSSI:(NSNumber *)RSSI {
    NSLog(@"Peripheral: %@ \n", peripheral);
    NSLog(@"pUUID: %@", [NSString stringWithCString:[self UUIDToString:[peripheral UUID]] encoding:NSStringEncodingConversionAllowLossy]);
    NSString *pUUID = [NSString stringWithCString:[self UUIDToString:[peripheral UUID]] encoding:NSStringEncodingConversionAllowLossy];
    [peripherals setObject:peripheral forKey:pUUID];
    NSLog(@"Identified Device: %@",[advertisementData objectForKey:@"kCBAdvDataLocalName"]);
    if([[advertisementData objectForKey:@"kCBAdvDataLocalName"] isKindOfClass:[NSString class]]) {
        if([[advertisementData objectForKey:@"kCBAdvDataLocalName"] isEqualToString:@"BLE Shield"]) {
            [self connectPeripheral:peripheral];


My connectPeripheral method uses the CentralManager connect method to connect.
- (void) connectPeripheral:(CBPeripheral *)peripheral {
    NSLog(@"Connecting to peripheral with UUID : %@\r\n",[NSString stringWithCString:[self UUIDToString:peripheral.UUID] encoding: NSStringEncodingConversionAllowLossy]);

    [mgr connectPeripheral:activePeripheral options:nil];


In the delegate method for connected peripherals, we search for available services:
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
    printf("Connection to peripheral with UUID : %s successfull\r\n",[self UUIDToString:peripheral.UUID]);
    activePeripheral = peripheral;
    [activePeripheral discoverServices:nil];

Once a service is discovered, the delegate method for that is called. From there, we call discoverCharacteristics, which I have wrapped in a method I made called getAllCharacteristicsFromArduino:
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
    if (!error) {
        printf("Services of peripheral with UUID : %s found\r\n",[self UUIDToString:peripheral.UUID]);
        [self getAllCharacteristicsFromArduino:peripheral];
    else {
        printf("Service discovery was unsuccessfull !\r\n");

-(void) getAllCharacteristicsFromArduino:(CBPeripheral *)p{
    for (int i=0; i <; i++) {
        CBService *s = [ objectAtIndex:i];
        printf("Fetching characteristics for service with UUID : %s\r\n",[self CBUUIDToString:s.UUID]);
        [p discoverCharacteristics:nil forService:s];

This will allow you to discover all the characteristics from the BLE Shield. That should get you started. Once you get that far, I can walk you through some more advanced stuff (i.e. reading/wrting to the shield)

Fri Aug 17, 2012 4:29 am

Joined: Wed Feb 26, 2014 8:50 pm
Posts: 3

I just modified the "didUpdateValueForCharacteristic" a bit:

uint8_t databuffer [[_allData length]];
[characteristic.value getBytes:databuffer length:[characteristic.value length]];
uint8_t i;
for(i=0; i<[characteristic.value length]; i++)

     NSString *hexData = [NSString stringWithFormat:@"%x", databuffer[i]];
     NSString *str = hexData;
     NSMutableString * newString = [NSMutableString string];
     NSArray *components = [str componentsSeparatedByString:@""];
     for ( NSString * component in components )
          int value = 0;
           sscanf([component cStringUsingEncoding:NSASCIIStringEncoding], "%x", &value);
           [newString appendFormat:@"%c", (char)value];
           NSLog(@"Sensor Data: %@", newString);

** /EDIT

@rosenjon, Thank you so much for your time in posting this example for calling the characteristics.

I've successfully connected and can see all of the characteristics from our BLEBees via the FIO V3 as described by Dr. Kroll. I'm wondering if you could briefly describe how one might parse the data from the Arduino serial monitor and present it in the Xcode NSLog?

Arduino sketch:

void setup()   {
  Serial.print("BLEbee v1.0.0 Sketch setup...");
  Serial1.println(" done.");
void loop() // run over and over
    for (int x = 0; x < 10000; x++){

  if (Serial.available()) {
    int ch =;
  if (Serial1.available()) {

Thanks again!

Mon Mar 03, 2014 6:49 pm
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.