Sunday, April 19, 2015

Configuring Ibeacons using Raspberry Pi B+ and Python

CP2104 Module is the perfect way not only to configure the ibeacons by connecting it to the usb port as described in my previous post (How to connect Ibeacon V2.0 to a PC with CP2104 USB 2.0 to TTL Converter) but can also be used to check the battery charge level of the ibeacon's battery as well by checking the brightness of the led on the module while the ibeacon is connected. But I have run out of stock and these modules are not readily available, so once they're gone, they're gone. But I have learned that the raspberry pi which is a small pc and can be used like an arduino can be an excellent substitute. Raspberry is readily available so configuring the ibeacon should not be a problem.

Here's how to use the raspberry to configure the Ibeacon:
1. The Connection. Connect the ibeacon module(HM10) to the UART/Serial port of the raspberry pi, see illustration below:

2. Raspberry Pi Set-up. The raspberry pi will still need to be set up because by default, the uart port serves as another gateway for controlling the computer remotely, so all bootup sequences and messages are being transmitted on the port, but all we need is to configure the  uart port to configure the ibeacon so we will need to eliminate this unwanted data. Here is how to do it:
  1. Modify the file /boot/cmdline.txt by removing console keyword related to the serial port. Typically the file looks like this: "
    dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 ....". Just remove the part in bold letters.
  2. The next step is to modify the file /etc/inittab by commenting the line "
    T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100". You could just add "#" at the beginning of the line.

    Restart the raspberry pi
Further reading:  RPi Serial Connection

3. The Python Code.  And finally we are ready to configure the ibeacon. I used the following python code to achieve this:
import serial

port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=3.0)

while True:
    rcv = port.readline() 
    print rcv
    rcv = ""
    rcv = port.readline() 
    print rcv
    rcv = ""
 Just follow the rest of the configuration process as described below:


for more detailed instructions you may check this website .

The ibeacon should respond to every command sent by the python program.

1 comment: