GithubHelp home page GithubHelp logo

redbearlab / ble_hci Goto Github PK

View Code? Open in Web Editor NEW
103.0 31.0 57.0 707 KB

Allows external systems or MCUs to connect BLE (CC2540) using HCI as BLE Central Role

C++ 35.16% C 8.68% Processing 1.07% Arduino 10.06% Python 45.03%

ble_hci's Introduction

BLE_HCI

Allows external systems or MCUs to control BLE chip (CC2540) using Bluetooth HCI mode such as Windows/Linux/Mac, Arduino (AVR), Teensy 3.0 (ARM Cortex-M4), Respberry Pi (ARM11), etc.

This library was written for Python (Tested on Windows, Linux and Mac OSX) and Arduino platforms.

This is in beta and still a work in progress, not all HCI commands and events have been implemented or fully tested.

The HCI firmware is built from TI CC254x SDK, refer to the HostTestApp project if you want to study the firmware code.

You can use it to connect to other BLE devices such as our BLE Mini and BLE Shield. Note that, it is also possible to connect to other BLE devices but modify the source code is required.

To learn more about HCI mode, you can refer to BTool in TI CC254x SDK.

Example 1

PC/Mac as BLE central role and via the BLE link, connecting to BLE Mini running Biscuit firmware as peripheral role

Typical connections:

  1. PC <-> USB <-> BLE Mini (HCI) <----- BLE Link ------> BLE Mini (Biscuit) <-> Serial <-> Ardino
  2. Mac <-> USB <-> BLE Mini (HCI) <----- BLE Link ------> BLE Mini (Biscuit) <-> USB <-> Raspberry Pi
  3. Raspberry Pi <-> USB <-> BLE Mini (HCI) <----- BLE Link -----> BLE Mini (Biscuit) <-> Serial <-> Arduino

Requirements:

  1. A PC running Windows, Linux or a Mac running Mac OS X
  2. Raspberry Pi with Linux is also possible
  3. HCI firmware (USB) and Biscuit firmware (USB or Serial)
  4. Two BLE Mini boards, first one running the HCI firmware, another one running the Biscuit firmware
  5. Install Python 2.7.2 32-bit
  6. Install PySerial 2.5
  7. For Windows, install USB CDC driver
  8. Biscuit central Python script

How it works:
When you connect the BLE Mini (HCI) to your PC via the USB port, it will function as an USB CDC (Virtual COM Port). On Windows, it will ask for a device driver, so you need to install the USB CDC driver. It shows as a COM port (e.g. COM5). For Linux or Mac OS X, it will work as a tty device (e.g. ttyACM0 or tty.usbmodem1311).

The Biscuit central Python script controls the virtual COM port, sending BLE command over the port, and listening to the HCI events.

You need to change the following lines to match your COM port and bardrate:

if os.name == 'posix':
    TX.port = '/dev/tty.usbmodem1431'
else:
    TX.port = 'COM5'
TX.baudrate = 115200

Press 'd' to start discovery, it will show if any device is found, and then press 'e' to establish a BLE link with the device, you need then enable the notification before you can receive data from the device.

Press '1', it will send a string 'Hello World!' to the device and press '2' will send 'I love BLE!'.

You can do many other interesting things as you want with BLE.

Supported systems:

  1. Windows
  2. Linux (includes Raspberry Pi)
  3. Mac OS X

Example 2

Arduino as BLE central role and via the BLE link, connecting to BLE Mini running Biscuit firmware as peripheral role

Typical connections:

  1. Arduino (A) <-> Serial <-> BLE Mini (A) <----- BLE Link -----> BLE Mini (B) <-> Serial <-> Arduino (B)
  2. Arduino (A) <-> Serial <-> BLE Mini (A) <----- BLE Link -----> BLE Mini (C) <-> USB <-> Raspberry Pi
  • Suggest to use Arduino Leonardo or other boards with more than one serial to try this example.
  • We use the USB CDC serial for debug/UI and one for connecting to the BLE Mini on Leonardo board.
  • Uno has only one serial and we do not use SoftwareSerial because sometimes data recevied incorrectly.
    -> We used AltSoftSerial, so Uno works now, but the baudrate limited to 57600bps.
    -> http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
  • Tested with Uno (use pin 8, 9), Leonardo (use pin 0, 1), Mega 2560 (use TX1, RX1)

Requirements:

  1. BLE HCI library for Arduino
  2. Arduino (A) running HCI library
  3. AltSoftSerial (requred for Arduino Uno)
  4. BLE Mini (A) running HCI firmware (Serial)
  5. BLE Mini (B or C) running Biscuit firmware (Serial or USB)

How it works:
Similar to the Example 1, the Arduino will keep tracks of HCI events from the serial port. You can see those events and send command using the Arduino IDE's Serial Monitor.

Supported Arduino boards or compatible:

  1. Arduino UNO (R3)
  2. Arduino Leonardo (R3)
  3. Arduino Mega 2560 (R3)
  4. Seeeduino V3.0 (Atmega 328P)
  5. Teensy 3.0
    Write to us if any other boards you tested.

ble_hci's People

Contributors

alexbonhomme avatar cheong2k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ble_hci's Issues

Unable to handle 0x0600 event

C:\Codes\BLE>python SensorTag_Central_HCI.py
Biscuit Central via HCI

Discovery...

-Type : 0x04
-EventCode : 0xFF
-Data Length : 0x06
Event : 0x067F
Status : 0x00
GAP_HCI_ExtentionCommandStatus

OpCode : 0xFE00

-Type : 0x04
-EventCode : 0xFF
-Data Length : 0x2C
Event : 0x0600
Status : 0x00
1536
-> Not handled yet.
Discovery...

Setup information

Great work!
Is there any other additional setup required? I am trying to communicate a linux computer/intel galileo with my Blend or Blend micro(arduino) via bluetooth. My ultimate aim is to get the RSSI in realtime between these 2 devices. Any recommendations will be hugely appreciated! I've been looking at node js and Noble..

Arduino Library

Hi
I am trying to write my own HCI library for an Arduino in c++. I am familiar with writing header and cpp file. I can see at TI BLE Vendor Specific Guide the Commands its OPCode, Command parameters and its values and octets and return parameters.
I just want to know how to implement specific command.
Like....

GAP_DeviceInit(profilerole, maxScanResponses, IRK, CSRK, signCounter)
opcode is 0xFE00 for this command whereas, 0x08, 0x03, 0x00, 0x00, 0x00 - 0x01 values are suitable for the command parameters respectively. The octets are 1, 1, 16, 16, 4 for command parameters respectively.
And return parameter has 1 octet and 2 values for success 0x00 and 0x02 for invalid parameter.

Looking at your python program I am more confused in starting to write library. If you could show me just to write one command then I would write rest in c++.

Thanks

I would like to know more parameter spec. for HCI firmeare

Dears,
I would like to know more parameter spec. for requests and responces.
Now, I can discovery a BLE mini from the other with this firmware, but I seem not to be able to connect to the BLE mini. So, I would like to understand responce parameters from the firmware. Then I would like to know whether it has a disconnect function in the firmware.

Thank you in advance.
Hirofumi

Scanning for BLE Beacons?

I was wondering if I could use the BLEMini to scan for iBeacons using this HCI Library. Thanks for pointing me in the right direction if you can.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.