... | ... | @@ -22,11 +22,11 @@ Vérifier que vos drivers sont présents. [Ce driver](https://www.silabs.com/dev |
|
|
Vous pouvez ensuite l'ajouter directement depuis le gestionnaire de périphérique pour Windows.
|
|
|
|
|
|
## Connecter la carte ##
|
|
|
Dans cet exemple, on utilisera le modèle `DOIT ESP32 DEVKIT V1`.
|
|
|
Dans `Select Other Board and Port`, on utilisera le modèle `DOIT ESP32 DEVKIT V1`.
|
|
|
|
|
|
## Tester l'installation ##
|
|
|
Ceci est un code pour tester si la carte est bien installer.
|
|
|
Normalement, une led devrait clignoter toutes les secondes et des messages sont envoyé sur le `serial monitor` (baux 115200).
|
|
|
Ceci est un code pour tester si la carte est bien installée.
|
|
|
Normalement, une led devrait clignoter toutes les secondes et des messages sont envoyés sur le `serial monitor` (baux 115200).
|
|
|
|
|
|
```cpp
|
|
|
/*********
|
... | ... | @@ -54,3 +54,75 @@ void loop() { |
|
|
delay(1000);
|
|
|
}
|
|
|
```
|
|
|
|
|
|
# Connection Bluetooth #
|
|
|
Ici on va utilisé une librairie Bluetooth pour faire des connexions serialisé
|
|
|
|
|
|
on va utilisé la librairie `BluetoothSerial.h`
|
|
|
Couplé avec l'application [Serial Bluetotth Terminal](https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal) pour Android.
|
|
|
|
|
|
Exemple de code :
|
|
|
```cpp
|
|
|
#include "BluetoothSerial.h"
|
|
|
#include <Arduino.h>
|
|
|
#include <string.h>
|
|
|
|
|
|
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
|
|
|
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
|
|
|
#endif
|
|
|
|
|
|
#define LED 2
|
|
|
|
|
|
#define BUF_MAX 50
|
|
|
|
|
|
char buffer[BUF_MAX];
|
|
|
|
|
|
BluetoothSerial SerialBT;
|
|
|
|
|
|
void setup() {
|
|
|
Serial.begin(115200);
|
|
|
SerialBT.begin("ESP32test"); //Bluetooth device name
|
|
|
Serial.println("The device started, now you can pair it with bluetooth!");
|
|
|
|
|
|
//set led
|
|
|
pinMode(LED, OUTPUT);
|
|
|
}
|
|
|
|
|
|
void loop() {
|
|
|
if (SerialBT.available()) {
|
|
|
char c[2];
|
|
|
c[0] = (char) SerialBT.read();
|
|
|
c[1] = '\0';
|
|
|
|
|
|
if(c[0] == '\r' || c[0] == '\n'){ // detect crlf (\r \n)
|
|
|
|
|
|
// check if the buffer is empty
|
|
|
if(buffer[0] == '\0') return;
|
|
|
|
|
|
Serial.println(buffer);
|
|
|
exeCommande();
|
|
|
buffer[0] = '\0';
|
|
|
}else{
|
|
|
strncat(buffer, c, BUF_MAX);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void exeCommande()
|
|
|
{
|
|
|
// led on
|
|
|
if(strcmp(buffer,"led on") == 0){
|
|
|
digitalWrite(LED, HIGH);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// led off
|
|
|
if(strcmp(buffer,"led off") == 0){
|
|
|
digitalWrite(LED, LOW);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//default
|
|
|
SerialBT.println("Unknow command");
|
|
|
}
|
|
|
``` |