Per programmare questa scheda con Arduino Ide si deve selezionare la board ESP32 Wrover
Uno dei limiti di questa scheda e' ha solo un led di stato di colore blu sul GPIO5. Per rendere piu' interattivo l'avviso all'utente ho provato a montare un motore coreless con peso asimmettrico su GPIO13. Non e' possibile pilotare un motore direttamente da un GPIO si impiegare un ponte ad H (esistono dei breakout gia' costruiti, basta collegare VCC a 5V, GND ed un GPIO)
La vibrazione non e' molto forte
Skecth di sola scansione di prossimita'
-----------------------------------------------------------------------------------
/*
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
Ported to Arduino ESP32 by Evandro Copercini
*/
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
int scanTime = 5; //In seconds
BLEScan* pBLEScan;
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
String address = advertisedDevice.getAddress().toString().c_str();
String name;
if (advertisedDevice.haveName ())
{
name = advertisedDevice.getName().c_str();
//Serial.printf("%s\n",name);
}
int rssi = advertisedDevice.getRSSI();
if (name.equals("SocialDistance"))
{
Serial.println(address);
Serial.println(rssi);
Serial.println("==");
if (rssi > -55)
{
Serial.println("Vicino");
digitalWrite(5, HIGH);
digitalWrite(13, HIGH);
}
else
{
Serial.println("Lontano");
digitalWrite(5, LOW);
digitalWrite(13, HIGH);
}
}
}
};
void setup() {
Serial.begin(115200);
Serial.println("Scanning...");
pinMode(5, OUTPUT);
pinMode(13, OUTPUT);
// led
digitalWrite(5, LOW);
// motore
digitalWrite(13, LOW);
BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(100);
pBLEScan->setWindow(99); // less or equal setInterval value
}
void loop() {
// put your main code here, to run repeatedly:
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
Serial.print("Devices found: ");
Serial.println(foundDevices.getCount());
Serial.println("Scan done!");
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
delay(2000);
}
Nessun commento:
Posta un commento