Go Down

Topic: BGLib Arduino library for Bluegiga BLE112 Bluetooth Low Energy module (Read 30237 times) previous topic - next topic


Sep 24, 2013, 02:38 am Last Edit: Sep 24, 2013, 02:55 am by theunixbeard Reason: 1
So I am trying to use the PJRC Teensy 3 with the BGLib Arduino library but unfortunately not having any luck... (Commands like system_hello to BLE112 timeout, though I do receive notification when the BLE112 boots...)

I have tried the BGLib_U1A1P_38400_noflow and BGLib_U1A1P_38400_noflow_wake16 firmwares (programmed using the TI CC Debugger) w/ both sample Arduino programs (Scanner & Stub Slave) The only change I made to the sketchs was altering the SoftwareSerial pins to 0,1 from 2,3. The reason for this is the Teensy 3 pinout has the first Serial port on these pins (See: http://www.pjrc.com/teensy/pinout.html)

As for the hardware connections I have:
Teensy 1 (RX) <==> BLE P04 (TX)
Teensy 2 (TX) <==> BLE P05 (RX)
Teensy 5 <==> BLE P16 (Wakeup)
Teensy 6 <==> BLE !RESET

Any troubleshooting suggestions? Is the Teensy 3 in someway incompatible w/ BGLib as written? (I see it was originally intended for the Uno)


I solved my own problem, here is the answer for posterity:

I had never used the physical reset button on the BLE-112 breakout board. After pressing that the scanner sketch worked immediately! (I assumed using the BLE-Update tool to reflash firmware would be the same as the reset button but in this specific case it seemed I needed to use the reset button for whatever reason)

Unfortunately I then had problems w/ the stub_slave sketch. For this, my problem turned out to be these lines of code at the very end of setup:

digitalWrite(BLE_RESET_PIN, LOW);
delay(5); // wait 5ms
digitalWrite(BLE_RESET_PIN, HIGH);

I'm not 100% clear on why the reset caused a problem, but it appeared that an extra 0x00 byte was added to the front of the packet. Hence, it went from:

80 0C 00 00 01 00 01 00 01 00 47 00 03 00 01 01
00 80 0C 00 00 01 00 01 00 01 00 47 00 03 00 01 01

As we can see from the BG-API binary packet description:

BGAPI packet structure (as of 2012-11-07):
  Byte 0:
    [7] - 1 bit, Message Type (MT)         0 = Command/Response, 1 = Event
    [6:3] - 4 bits, Technology Type (TT)     0000 = Bluetooth 4.0 single mode, 0001 = Wi-Fi
    [2:0] - 3 bits, Length High (LH)         Payload length (high bits)
  Byte 1:     8 bits, Length Low (LL)          Payload length (low bits)
  Byte 2:     8 bits, Class ID (CID)           Command class ID
  Byte 3:     8 bits, Command ID (CMD)         Command ID
  Bytes 4-n:  0 - 2048 Bytes, Payload (PL)     Up to 2048 bytes of payload

This completely threw off the meaning of the packet and future packets as well. (Interpreted as a command/response rather than event w/ a packet length of 128 rather than 12!!!


Dear Jeff,

I'm using your firmware for the BLE112 and your arduino APIs (BGLib_U1A1P_38400_noflow and BGLib_stub_slave). I successfully connected to my iPad and received data from the BLE112 by issuing a ble_cmd_attributes_write. However, I can't seem to get it to write 20bytes of data. The most I could write and send to my iPad in a packet is 19bytes. Is this a limitation?



Hello jeff,
if i load your code in arduino than i also programme BLE112 ?
and this code is also running in BLE113?
Thank you 


Do you know if this can be used to flash the arduino? If so, do you have a schematic or know where i can find one? thanks!

Go Up