Connect an iPhone to Arduino over Bluetooth

2019-03-08 16:12发布

问题:

I would love to be able to let my iPhone-App communicate to my Arduino over Bluetooth. I found some Bluetooth shields that support the following protocols: BCSP, DUN, LAN, GAP SDP, RFCOMM, and L2CAP. From what i found while googling a bit, is that the iPhone is hiding it's bluetooth stack away?!? Is this correct? Is there really no chance to let my iPhone communicate with an other bluetooth enabled device without jailbreaking (which as far as I know would be required if i'd use btstack: http://code.google.com/p/btstack/)?

If bluetooth is really not possible, what other ways (expect WLAN) would you suggest to realize a communication? What I would love to realize is something like here: http://theiopage.blogspot.com/2011/08/yanis-android-wireless-eos-controller.html

Thanks for any tips!

回答1:

There are several connection technologies available.

As others have mentioned, standard Bluetooth (3.0) is controlled by the MFi program. The only way to connect to a non-jailbroke iPhone is to join the MFi program.

Serial access is interesting. You have to join MFi to distribute a serial device, but you can use the Redpark Serial Cable to connect your own iPhone to a serial device.

There are several ways to connect Bluetooth LE devices to the Arduino. One I've used is the RedBearLabs BLE Shield. It works pretty darn well.

You can also connect to an Arduino using a WiFi-serial bridge. I've had success with the WiFly device.

One of the neat things about the BLE Shield and WiFly is you don't have to use Objective C or a Macintosh--although that's an option, of course. You can access both through techBASIC, running right on the iPad or iPhone.

You can probably figure these out on your own with some research and effort, but these connection technologies (plus a few more that don't apply directly to Arduino) are also covered in Building iPhone and iPad Electronics Devices, a new book from O'Reilly.



回答2:

Information about connecting to Bluetooth 3.0 or lower devices from stock OS iOS devices is only available after being accepted into Apple's MFi program.

Bluetooth 4.0 (BLE) is accessible both in development and commercially to iOS developers (without needing access to the MFi program), using the public Core Bluetooth framework available in iOS 5 or later on iPhone 4S, iPad 3 and later devices carrying BT4.0 on-board.

Added a few years later: There are now several BLE shields and Arduino compatible or Arduino-like products with built-in BLE (LightBlue Bean, RFduino, etc.) available in the market.



回答3:

Actually you can make it happen now without Jailbreaking or MFi enrollment.

Take a look ate Bluetooth 4.0 in newer iOS devices and Arduino BT 4.0 shield.

This might help: http://blog.makezine.com/2012/03/19/bluetooth-4-0-from-arduino-to-iphone-no-jailbreaking-no-mfi/



回答4:

So I don't know how to implement, but I think your Arduino should simulate an Bluetooth Headset and let the App parse the data. Because iPhones only support Bluetooth Headsets this would be one of the only methods. And it would be very hard.

I recommend you to do things like this over Wifi with an Wifi-Shield. Than you could use Apples genial bonjour systeme, to automatically detect your hardware.

Hope that gives you some idea, how to solve the problem,

Leo



回答5:

Improving this answer and cover all details probably needs some article or similar. I will try to keep things short and make focus on iOS side, since Arduino basically doesn't have limitations on Bluetooth peripherals which are widely available via Arduino BLE shields, such is RedBearLab BLE Shild

Bluetooth v2.0 + EDR, v2.1 + EDR, v3.0 + HS....

Bluetooth stack specification prior to v4.0 doesn't contain Low Energy part. Although it is easy to use protocol, especially if simplified around SPP (Serial Port Profile) it is not available on Apple iOS devices without MFi program. There are few Bluetooth modules on the market such is Pan1321 from Panasonic which includes Apple authentication coprocessor and which could be used with iOS. Sad part of the story is that if you take look on this official page iOS: Supported Bluetooth profiles SPP is not there so you can choose between listed profiles (what you probably will if you are making audio or HID device).

Bluetooth Low Energy (BLE)

Migration from Bluetooth v3.0 specification to v4.0 introduced BLE. New part of specification has very little in common with previous. Basically you could look on it as Bluetooth v3.0 + BLE = v4.0 or Bluetooth Smart. BLE part of v4.0 specification is what we are interested for.

CoreBluetooth

Beside all the advantages of BLE such are low power consumption, small size, low cost, the most important was adoption by mobile manufacturers, including Apple (no MFi needed). BLE is fully supported by CoreBluetooth and implementation on iOS side is straightforward. One thing that you have to keep in mind is that BLE is low energy but also low speed. Although standard specifies minimal connection interval of 7.5ms Apple documentation says recommendation is 30ms :-D What I have experienced using bunch of different chips and iOS devices is that you will be capable to transmit 20bytes every 20-30ms. If acknowledgment is needed, than make it double, like 40-60ms.

Custom Profiles

The list of standard BLE profiles is available by Bluetooth Special Interest Group (SIG). Take a look on GATT Based. Unfortunately, if you don't make an heart rate monitor or device from list you will probably use battery service or similar from a profiles list. Fortunately it is not complicated to create custom profile, which will be "placeholder" for application specific data you have to transmit. Understanding of Roles, GATT (Services and Characteristics), UUIDs and other is mandatory, but learning curve or BLE stack is not difficult in my opinion.

Once when BLE profile, running on embedded device is known, connection and communication over BLE is very simple using CoreBluetooth library.

iBeacon

Apple made little hack using BLE standard as "carrier" for iBeacon. They are using manufacturer specific data in BLE advertising packet to "claim" that some device is iBeacon. Which is perfectly OK, I would say. What you should keep in mind is that BLE is not iBeacon, but all iBeacons are BLE (device with hardcoded manufacturer specific data, exposing RSSI, UUID, major and minor in broadcast BLE mode). Additionally, iBeacon is handled by CoreLocation not CoreBluetooth. This makes clear what was Apple intension with iBeacon.

Conclusion

If you want to integrate iOS device with Arduino or some other embedded device BLE is definitely something that you want to consider. There are additional reasons why you want to learn more about BLE if you take a look on IoT hype and available RF options. BLE is here to stay with v4.1 and upcoming v4.2 specifications which will improve bandwidth, bring support for IPv6, better security, etc.

At the end, not so short, but I hope it helps.



回答6:

Some BLE modules can be used in iBeacon mode and are connectable to IOs. I worked with modules HM10 and HM11, based on CC2540/CC2541. They have several AT commands for iBeacon setup. Changable registers are UUID, Major, Minor and Measured Power. More detailes in this article "Turn your CC2541 based HM-10 Bluetooth Smart Module into an iBeacon"