Outils pour utilisateurs

Outils du site


bluetooth

module HM10

Documentation

SUPER documentation sur le modules (broches supplémentaires, état et pilotage de la led, récupération infos module avec android,commandes AT etc…) Voir la partie “HM-10 Programmable Pins” pour utiliser 10 GPIO directement sur le module (certaines sont ADC, voir DS18B20).

http://www.martyncurrey.com/hm-10-bluetooth-4ble-modules/

Bonne documentation pour le module, pour utilisation en console notamment: http://fab.cba.mit.edu/classes/863.15/doc/tutorials/programming/bluetooth.html

documentation (commandes AT etc…): ftp://imall.iteadstudio.com/Modules/IM130614001_Serial_Port_BLE_Module_Master_Slave_HM-10/DS_IM130614001_Serial_Port_BLE_Module_Master_Slave_HM-10.pdf

http://wiki.sunfounder.cc/images/f/f8/Bluetooth_4.0_BLE_module_datasheet.pdf

Cablage

Cabler pont diviseur sur la broche 3 qui va du TX arduino au RX module Bluetooth pour abaisser la tension à 3V

La broche TX module Bluetooth est connectée directement à la broche RX arduino 2.

Alimenter le module avec le 5V de l'arduino UNO, il y a un régulateur 3.3V sur le module.

Programme pour dialoguer avec le module et utiliser les commandes AT

Programme pour utiliser l'arduino UNO comme un pont série et permettre le dialogue avec le module Bluetooth depuis une console sur le PC:

hm10.ino
#include <SoftwareSerial.h>
const int Rx = 2;
const int Tx = 3; 
SoftwareSerial ModuleBluetooth(Rx, Tx);
unsigned long time=0;
 
///////////////////////////////
void sendCommand(char * chaine){
unsigned long time=0;
Serial.print("sending AT command: ");
Serial.print(chaine);
Serial.print("   ->  ");
while ((*chaine)!=0){
   ModuleBluetooth.write(*chaine);
   chaine++;
   }  
ModuleBluetooth.write('\r');   
ModuleBluetooth.write('\n');   
time=micros();
while (micros()-time<500000){ //Laisse du temps au module pour répondre, et affiche la réponse dans la console Serial
  if (ModuleBluetooth.available()) {
        Serial.write(ModuleBluetooth.read());
    }
  }    
Serial.println("");
delay(100);  
}
///////////////////////////////
void setup() {
  // Ouvre la liaison série classique pour communiquer avec le PC
Serial.begin(9600);
Serial.println("salut");
// Ouvre la liaison série software pour communiquer avec le module bluetooth
ModuleBluetooth.begin(9600); 
time=micros();
delay(200);
//sendCommand("AT+RENEW"); //configuration usine
sendCommand("AT+RESET"); //reboot
sendCommand("AT");
delay(1000);  
sendCommand("AT+ADDR");
sendCommand("AT+VERSION"); //affiche la version du firmware
delay(5000);  
sendCommand("AT");
sendCommand("AT+ROLE0"); //module en mode Peripheral (0)
sendCommand("AT+ROLE"); //module en mode Peripheral (0)
Serial.println("c'est parti!");
}
///////////////////////////////
void loop() {
  // put your main code here, to run repeatedly:
  if (ModuleBluetooth.available()) {
        Serial.write(ModuleBluetooth.read());
    }
    if (Serial.available()) {
        ModuleBluetooth.write(Serial.read());
    }
/*
if ((micros()-time)>100000)
  {
    Serial.print("+");
    time=micros();
  }
*/
 /*
    Serial.print("+");
    delay(100);
 */
 
}
miniterm.py /dev/ttyUSB0 9600

MODULE hm10 BERTRAND

Acheté sur ebay: https://www.ebay.com/itm/Arduino-Android-IOS-HM-10-BLE-Bluetooth-4-0-CC2540-CC2541-Wireless-Module-9H/223084318738?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

Le module de bertrand prend des commandes AT terminées par Entrée, celui de Christophe non.

Tests de commandes AT:

AT+VERR?
  ne répond pas
AT+VERSION?
  +VERSION=Firmware V4.2.0,Bluetooth V4.0 LE
AT+NAMEBT05
  +NAME=BT05
AT+ADDR? 
  +ADDR=00:13:AA:00:2C:AA
AT+CHAR?
  ERROR=102
AT+UUID?
  +UUID=0xFFE0
AT+DISC?

Pour établir un pont entre 2 modules bluetooth, régler l'un en Peripheral mode (the default setting) :

AT+ROLE0

et l'autre en Central mode avec Manual Start

AT+IMME1
AT+ROLE1 
AT+CON1

Certaines commandes AT fonctionnent pas avec ma copie chinoise à 2 balles… Conclusion, acheter un vrai HM10!

Attention: Les commandes AT ne sont appliquées lorsque le module est éteint puis rallumé.

Liste des commandes AT supportées:

AT+HELP?
| reponseATHELP
********************************************************************
* Command             Description			           *
* ---------------------------------------------------------------- *
* AT                  Check if the command terminal work normally  *
* AT+RESET            Software reboot				   *
* AT+VERSION          Get firmware, bluetooth, HCI and LMP version *
* AT+HELP             List all the commands		           *
* AT+NAME             Get/Set local device name                    *
* AT+PIN              Get/Set pin code for pairing                 *
* AT+PASS             Get/Set pin code for pairing                 *
* AT+BAUD             Get/Set baud rate		                   *
* AT+LADDR            Get local bluetooth address		   *
* AT+ADDR             Get local bluetooth address		   *
* AT+DEFAULT          Restore factory default			   *
* AT+RENEW            Restore factory default			   *
* AT+STATE            Get current state				   *
* AT+PWRM             Get/Set power on mode(low power) 		   *
* AT+POWE             Get/Set RF transmit power 		   *
* AT+SLEEP            Sleep mode 		                   *
* AT+ROLE             Get/Set current role.	                   *
* AT+PARI             Get/Set UART parity bit.                     *
* AT+STOP             Get/Set UART stop bit.                       *
* AT+START            System start working.			   *
* AT+IMME             System wait for command when power on.	   *
* AT+IBEA             Switch iBeacon mode.	                   *
* AT+IBE0             Set iBeacon UUID 0.            	           *
* AT+IBE1             Set iBeacon UUID 1.            	           *
* AT+IBE2             Set iBeacon UUID 2.            	           *
* AT+IBE3             Set iBeacon UUID 3.            	           *
* AT+MARJ             Set iBeacon MARJ .            	           *
* AT+MINO             Set iBeacon MINO .            	           *
* AT+MEA              Set iBeacon MEA .            	           *
* AT+NOTI             Notify connection event .                    *
* AT+UUID             Get/Set system SERVER_UUID .            	   *
* AT+CHAR             Get/Set system CHAR_UUID .            	   *
* -----------------------------------------------------------------*
* Note: (M) = The command support slave mode only. 		   *
* For more information, please visit http://www.cyobd.com          *
* Copyright@2013 www.cyobd.com.   All rights reserved.		   *
********************************************************************

Utilisation via terminal bluetooth

Le module est vu comme un périphérique bluetooth BT05

Applications à installer

BLE Scanner sur Android: https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner&hl=en

Détecter le composant BT05 et afficher les informations le concernant. le BT05 est connected mais not-bonded (lié)

Serial Bluetooth Terminal: https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=fr

Lancer l'application puis options→Device→Bluetooth LE→SCAN . Cliquer sur connect à BT05. Ensuite le terminal sur le téléphone échange les caractères ASCII avec le module (éventuellement redirigés sur UART Serial de l'Arduino grâce au programme hm10.ino )

Pour que le module fonctionne dans cette configuration il faut qu'il soit en:

AT+ROLE0

La LED du module clignote tant qu'il n'est pas appairé. Si la LED ne clignote pas c'est que l'application terminal du téléphone est appairée avec le module HM10 et donc celui ci ne tiendra pas compte des commandes AT. Il faut alors déconnecter l'application terminal du téléphone pour saisir les commandes AT.

Différents états pour un module bluetooth

https://www.silabs.com/community/wireless/bluetooth/knowledge-base.entry.html/2017/05/16/understanding_thebl-sICq

Explication des termes Connected,Paired,Bonded et Whitelisted: https://devzone.nordicsemi.com/f/nordic-q-a/11939/connecting-bonding-pairing-and-whitelists/45217#45217

This is a short description of the terms, and how they are linked together:

  1. Connection: A central (master) can connect to a peripheral (slave). While the connection is active the master and slave will communicate regularly at a determined interval. This connection interval can be between 7.5 ms and 4 s.
  2. Pairing: Devices that are initially connected can exchange encryption keys and encrypt the link. When they have, the link is secure and they are paired.
  3. Bonding: Paired devices can be bonded. This means that they store the keys that have already been exchanged when they paired and use those again the next time they connect.
  4. Whitelisting: The whitelist is used to restrict connection or scanning from any other than predetermined (known) devices.

Configuration sous linux

le module est vu comme un périphérique bluetooth BT05

super doc sur bluetooth sous linux: https://www.pcsuggest.com/linux-bluetooth-setup-hcitool-bluez/ et https://www.pcsuggest.com/bluetooth-linux-part-2/

Commandes linux sur: http://denethor.wlu.ca/arduino/bluetooth.shtml

hcitool dev
  Devices:
hci0	64:80:99:F8:2C:34
hciconfig -a
  hci0:	Type: BR/EDR  Bus: USB
BD Address: 64:80:99:F8:2C:34  ACL MTU: 1021:5  SCO MTU: 96:6
UP RUNNING PSCAN ISCAN 
RX bytes:2736 acl:31 sco:0 events:258 errors:0
TX bytes:33050 acl:31 sco:0 commands:212 errors:0
Features: 0xff 0xfe 0x0f 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
Link policy: RSWITCH HOLD SNIFF 
Link mode: SLAVE ACCEPT 
Name: 'rapid'
Class: 0x0c010c
Service Classes: Rendering, Capturing
Device Class: Computer, Laptop
HCI Version: 4.0 (0x6)  Revision: 0x1000
LMP Version: 4.0 (0x6)  Subversion: 0x1000
Manufacturer: Intel Corp. (2)

Pour configurer l'interface Bluetooth en master

sudo hciconfig -a hci0 lm master
hciconfig -a
  hci0:	Type: BR/EDR  Bus: USB
BD Address: 64:80:99:F8:2C:34  ACL MTU: 1021:5  SCO MTU: 96:6
UP RUNNING PSCAN ISCAN 
RX bytes:3290 acl:31 sco:0 events:264 errors:0
TX bytes:33068 acl:31 sco:0 commands:218 errors:0
Features: 0xff 0xfe 0x0f 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
Link policy: RSWITCH HOLD SNIFF 
Link mode: MASTER 
Name: 'rapid'
Class: 0x0c010c
Service Classes: Rendering, Capturing
Device Class: Computer, Laptop
HCI Version: 4.0 (0x6)  Revision: 0x1000
LMP Version: 4.0 (0x6)  Subversion: 0x1000
Manufacturer: Intel Corp. (2)

à partir de la il devient possible de se connecter au module BT05

Pour scanner les périphériques Low Energy

sudo hcitool lescan
bluetoothctl
  [NEW] Controller 64:80:99:F8:2C:34 rapid [default]
  [NEW] Device 00:13:AA:00:2C:AA BT05
  [bluetooth]# list
  Controller 64:80:99:F8:2C:34 rapid [default]
  [bluetooth]# scan on
  Discovery started
  [CHG] Controller 64:80:99:F8:2C:34 Discovering: yes
  [bluetooth]# connect 00:13:AA:00:2C:AA
  Attempting to connect to 00:13:AA:00:2C:AA
  Connection successful
  [BT05]# info
  Device 00:13:AA:00:2C:AA
Name: BT05
Alias: BT05
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
UUID: Unknown                   (0000ffe0-0000-1000-8000-00805f9b34fb)
Modalias: bluetooth:v000Dp0000d0110
  [BT05]# disconnect
  Attempting to disconnect from 00:13:AA:00:2C:AA
  Successful disconnected
  [CHG] Device 00:13:AA:00:2C:AA Connected: no
  [CHG] Device 00:13:AA:00:2C:AA RSSI: -42

Utilisation du bluetooth via python

Terminal Bluetooth sous linux

http://pi19404.github.io/pyVision/2015/04/03/22/

Installation des paquets:

sudo apt-get install bluez bluez-tools

liste des fichiers de ces paquets:

dpkg -L bluez
  /usr/bin/bccmd
  /usr/bin/hciattach
  /usr/bin/bluetoothctl
  /usr/bin/gatttool
  /usr/bin/bluemoon
  /usr/bin/rctest
  /usr/bin/hex2hcd
  /usr/bin/obexctl
  /usr/bin/btmgmt
  /usr/bin/sdptool
  /usr/bin/l2test
  /usr/bin/ciptool
  /usr/bin/rfcomm
  /usr/bin/hcitool
  /usr/bin/l2ping
  /usr/bin/btmon
  /usr/bin/btattach
  ...
dpkg -L bluez-tools
  /usr/bin/bt-network
  /usr/bin/bt-device
  /usr/bin/bt-obex
  /usr/bin/bt-adapter
  /usr/bin/bt-agent
  ...

NB: il existe un paquet python: python-bluez/xenial 0.22-1 amd64

bluez-simple-agent hci0 00:13:AA:00:2C:AA
  RequestPinCode (/org/bluez/3772/hci0/dev_98_D3_31_30_1A_BA)
  Enter PIN Code: 1234
  Release
  New device (/org/bluez/3772/hci0/dev_98_D3_31_30_1A_BA)

bluez-simple-agent n'est pas contenu dans les paquets installés: “The functionality of bluez-simple-agent seems to have been replaced by bluetoothctl.”

bluez-simple-agent remplacé par simple-agent?

apt-file search simple-agent
  bluez-tests: /usr/share/doc/bluez-tests/examples/simple-agent.gz

Création d'un fichier associé au périphérique bluetooth

http://pi19404.github.io/pyVision/2015/04/03/22/

Ceci utilise le module rfcomm, pour vérifier qu'il est bien en fonctionnement:

lsmod |  grep rfcomm

Ceci n est plus à jour

création d'un fichier associé à l'adresse mac du module:

sudo nano /etc/bluetooth/rfcomm.conf
rfcomm.conf
rfcomm0 {
        bind no;
        device 00:13:AA:00:2C:AA;
        channel 1;
        comment "Serial Port";
        }
sudo service bluetooth restart

d'après https://unix.stackexchange.com/questions/128531/rfcomm-device-seems-to-be-missing-dev-rfcomm0 , /etc/bluetooth/rfcomm.conf n'est plus utilisé avec la nouvelle version, il faut faire à la main avec des appels de rfcomm

Ceci est à jour mais ne marche pas pour le Bluetooth BLE

sudo rfcomm connect 0

pour attacher le lien au fichier /dev/rfcomm0

sudo rfcomm bind 0 00:13:AA:00:2C:AA  1

pour détacher le lien au fichier /dev/rfcomm0

sudo rfcomm unbind 0 00:13:AA:00:2C:AA

AIE…. d'après https://raspberrypi.stackexchange.com/questions/71719/raspberry-pi-3-bluetooth-is-not-getting-connected-with-hm-10-bluetooth-module , BLE is different than the classic Bluetooth, so you can't use the rfcomm serial devices to communicate with the HM-10

“ My understanding is the HM-10 only works using Bluetooth 4.0 Low Energy (BLE). BLE is different than the classic Bluetooth, so you can't use the rfcomm serial devices to communicate with the HM-10. Instead you need to use the gatttool to discover the different characteristics of the device and read/write data. 0000ffe1-0000-1000-8000-00805f9b34fb is the characteristic the HM-10 uses by default to read/write up to 20 bytes at a time (ID can be changed using the AT commands).

Alternatively if you are using a recent version of BlueZ (5.46 or newer) then you can use the acquire-write and acquire-notify commands of bluetoothctl to create file descriptors you can use to read and write data. On my Raspberry Pi 3 I had Ubuntu 16.04.3 installed but bluetoothctl -v showed an older version. I came across this script that worked to install a newer version, and after enabling the experimental features in bluetoothd the acquire commands started working.”

Script d'install: https://github.com/muka/go-bluetooth/blob/master/scripts/bluez-install.sh

Commandes pour utiliser le BLE: https://unix.stackexchange.com/questions/392103/using-acquire-write-and-acquire-notify-in-bluetoothctl-for-bluetooth-low-energe

bluetoothctl -v

j'ai la version 5.37

TODO: installer une version plus récente via le script

Module JDY-30

utilisation du module avec DevDuino BT App has been designed with MIT App Inventor : https://www.ebay.fr/itm/JDY-10-HM-11-Bluetooth-4-0-BLE-Serial-Transmission-Module-Comptible-with-CC2541-/173511871746

documentation sur JDY-30 et JDY-31: http://www.ko4bb.com/getsimple/index.php?id=jdy-30jdy-31-bluetooth-modules

http://www.ko4bb.com/getsimple/data/uploads/jdy-30/jdy-30-bluetooth-module.pdf

https://www.banggood.com/3pcs-JDY-31-Bluetooth-Module-2_03_0-SPP-Protocol-Android-Compatible-With-HC-0506-JDY-30-p-1420974.html?rmmds=detail-left-hotproducts__3&cur_warehouse=CN

https://www.ebay.com/itm/JDY-10-HM-11-Bluetooth-4-0-BLE-Serial-Transmission-Module-Comptible-with-CC2541/173511871746?_trkparms=aid%3D111001%26algo%3DREC.SEED%26ao%3D1%26asc%3D20160908105057%26meid%3Dffdf17b37263470cb6aad260f1a063cc%26pid%3D100675%26rk%3D1%26rkt%3D15%26sd%3D173511871746%26itm%3D173511871746&_trksid=p2481888.c100675.m4236&_trkparms=pageci%3A0f8e437d-4778-11e9-b1dd-74dbd18055ad%7Cparentrq%3A83a2827c1690acc76a4396f8fffb7484%7Ciid%3A1

https://www.ebay.fr/itm/JDY-10-HM-11-Bluetooth-4-0-BLE-Serial-Transmission-Module-Comptible-with-CC2541-/173511871746

peut etre soudé sur PCB alim: https://ru.aliexpress.com/item/SPP-C-Bluetooth-serial-pass-through-module-wireless-serial-communication-from-machine-Wireless-SPPC-Replace-HC/32657800452.html?src=google&albslr=220878921&src=google&albch=rmkt&acnt=576-373-4425&isdl=y&aff_short_key=UneMJZVf&albcp=289599368&albag=16806673448&slnk=&trgt=aud-655966866888&plac=www.dl-protect1.com&crea=336816215170&netw=d&device=c&mtctp=&albbt=Google_7_rmkt&aff_platform=google&gclid=CjwKCAjw4LfkBRBDEiwAc2DSlDKhnvIkjIyyAj41Txyb-ua-UEHjh-TDhnl4QMMCuKgB4D_uvOM9yxoCavIQAvD_BwE

PCB alim: https://shopee.sg/2X-Interface-Base-Serial-Board-Transceiver-Bluetooth-Module-Hc-05-For-Arduino-i.16727847.297192581

Bluetooth Mesh

Communication entre PC linux et module HM10 en python

Communication entre PC linux et smartphone android via Bluetooth

Communication entre 2 modules HM10 connectés via FTDI232

Utilisation comme récepteur de télécommande téléphone avec remoteXY

Installation Librairie Arduino sous Linux

 mkdir -p ~/Arduino/libraries/RemoteXY
 cd ~/Arduino/libraries/RemoteXY
 wget http://remotexy.com/download/library/2.3.5/RemoteXY.zip
 unzip RemoteXY.zip
 rm RemoteXY.zip 
 

Programme arduino généré en ligne

programmer le sketch suivant:

hm10_remoteXY.ino
/*
   -- New project --
 
   This source code of graphical user interface 
   has been generated automatically by RemoteXY editor.
   To compile this code using RemoteXY library 2.3.3 or later version 
   download by link http://remotexy.com/en/library/
   To connect using RemoteXY mobile app by link http://remotexy.com/en/download/                   
     - for ANDROID 4.1.1 or later version;
     - for iOS 1.2.1 or later version;
 
   This source code is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.    
*/
 
//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////
 
// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>
 
#include <RemoteXY.h>
 
// RemoteXY connection settings 
#define REMOTEXY_SERIAL_RX 2
#define REMOTEXY_SERIAL_TX 3
#define REMOTEXY_SERIAL_SPEED 9600
 
 
// RemoteXY configurate  
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,2,0,0,0,12,0,8,13,0,
  5,0,42,18,30,30,2,26,31 };
 
// this structure defines all the variables of your control interface 
struct {
 
    // input variable
  int8_t joystick_1_x; // =-100..100 x-coordinate joystick position 
  int8_t joystick_1_y; // =-100..100 y-coordinate joystick position 
 
    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0 
 
} RemoteXY;
#pragma pack(pop)
 
/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////
 
 
 
void setup() 
{
  RemoteXY_Init (); 
  Serial.begin(9600);
 
  // TODO you setup code
 
}
 
void loop() 
{ 
  RemoteXY_Handler ();
 
  Serial.print(RemoteXY.joystick_1_x,DEC);
  Serial.print(" , ");
  Serial.println(RemoteXY.joystick_1_y,DEC);
 
 
  // TODO you loop code
  // use the RemoteXY structure for data transfer
 
 
}
 

Installer RemoteXY depuis AppStore Android et le lancer cliquer sur + et choisir le périphérique Bluetooth Low Energy : BT05 (si échec de connexion, réessayer)

dans console miniterm, la position du joystick doit s'afficher:

44 , 50
bluetooth.txt · Dernière modification: 2019/04/03 10:24 par bvandepo