This page looks best with JavaScript enabled

Bluetooth module in Arduino

 ·  🎃 kr0m

Many times we need to transmit data wirelessly, a good way to do it is by using Bluetooth, an old technology but that serves our purposes. In the following article, we explain how to make the connection with the device using minicom.

To begin, we will install minicom:

emerge -av minicom

We configure the minicom port, as root:

minicom -s

We change the port to ttyUSB0, now we can start minicom as a regular user.

We connect the FDDI RX to the BT TX and vice versa.

In the minicom console, we paste with the middle mouse button:

AT
AT+VERSION
AT+BAUD4
AT+NAMENemesis

With this, we get the firmware version, configure the serial port transfer rate to 9600 bps, and give it a name.

The different transfer rates are:

    1 for 1200 bps
    2     2400 bps
    3     4800 bps
    4     9600 bps
    5    19200 bps
    6    38400 bps
    7    57600 bps
    8   115200 bps
    9   230400 bps
    A   460800 bps
    B   921600 bps
    C  1382400 bps

The pin could be changed with:

AT+PINxxxx

By default: 1234

Now we can pair the PC with the BT.

hcitool scan

Scanning ...
    AA:AA:AA:AA:AA:AA    Nemesis

We power the BT and run simple-agent to associate with it:

simple-agent hci0 AA:AA:AA:AA:AA:AA

bluez-test-device trusted AA:AA:AA:AA:AA:AA yes
bluez-test-device trusted AA:AA:AA:AA:AA:AA
1
vi /etc/bluetooth/rfcomm.conf
rfcomm0 {
        # Automatically bind the device at startup
        bind yes;

        # Bluetooth address of the device
        device AA:AA:AA:AA:AA:AA;

        # RFCOMM channel for the connection
        channel 1;

        # Description of the connection
        comment "Nemesis connection";
}
vi /etc/bluetooth/hcid.conf
# HCId options
options {
   # Automatically initialize new devices
   autoinit yes;

   # Security Manager mode
   #   none - Security manager disabled
   #   auto - Use local PIN for incoming connections
   #   user - Always ask user for a PIN
   #
   security user;

   # Pairing mode
   #   none  - Pairing disabled
   #   multi - Allow pairing with already paired devices
   #   once  - Pair once and deny successive attempts
   pairing multi;

   # Default PIN code for incoming connections
   #passkey "1234";
    pin_helper /etc/bluetooth/pin;
}

device AA:AA:AA:AA:AA:AA {
        name "Nemesis";
        auth enable;
        #encrypt enable;
}
/etc/init.d/bluetooth restart

We create our BT serial port:

rfcomm bind 0 AA:AA:AA:AA:AA:AA

Now we have a device in /dev/rfcomm0

We can start minicom with:

minicom -D /dev/rfcomm0

To speed up this process we can create a script:

vi /home/USER/.scripts/ardBT.sh

#! /bin/bash
simple-agent hci0 AA:AA:AA:AA:AA:AA
bluez-test-device trusted AA:AA:AA:AA:AA:AA yes
rfcomm bind 0 AA:AA:AA:AA:AA:AA
minicom -D /dev/rfcomm0

We configure sudo to be able to execute it from a regular user:

visudo

USER ALL=NOPASSWD: /home/USER/.scripts/ardBT.sh
If you liked the article, you can treat me to a RedBull here