Micro-controller based sensors
With phyphox version 1.1.0 external sensors via Bluetooth Low Energy (BLE) are supported, making it possible to develop sensor modules based on a micro-controller. So far we have used two different micro-controllers. On the one hand an Arduino with a BLE shield and on the other hand the ESP32 which already supports BLE. Of course there are many other micro-controllers which support BLE that can also be used.
In this article we provide one example for each micro-controller. Both examples are quite similar to each other. The differences in the sketch occur due to the fact that two different libraries are used. Both micro-controllers are programmed with the official Arduino-IDE. The goal of these examples is to send the value of the analog input to phyphox.
Warning: This tutorial requires basic knowledge in programming of a micro-controller. If you have never used an Arduino you should do a basic Arduino tutorial first.
Using a Arduino:
The Arduino itself does not have BLE on board. To support BLE, a BLE shield has to be used. In this case we use the „BLE Shield“ by RedBearLab in combination with the Arduino Library „arudino-BLEPeripheral“ by sandeepmistry from github.
[https://github.com/sandeepmistry/arduino-BLEPeripheral ]
Furthermore the library “Timer1” is used which can be found here:
[https://playground.arduino.cc/code/timer1 ]
Since the BLE library is also used for other BLE shields like the “Bluefruit LE” by Adafruit the tutorial for this shield can also be used. Ideally, just the port numbers for the specific shield have to be changed, as can be seen on github under the topic „Pinouts“.
These zip files can be included directly via:
(In the Arduino IDE) Sketch > Include Library > Add .ZIP Library... > select the downloaded file > Open
After both libraries are installed the following sketch can be used to initialize a Bluetooth Low Energy server with one service and one characteristic. In this sketch the analog input A0 is readout and the value is written into the characteristic. The additional phyphox file notifies this characteristic and plots the received values.
File:BLE Arduino.ino File:AnalogReadTutorial.phyphox
Using a ESP32:
In this example we use the HIMALAYA ESP32 Dev Board. Since the ESP32 isn't an official Arduino Board, a library to support this micro-controller in the Arduino-IDE has to be used. To do so start the Arduino-IDE and open: File > Preferences Then past the following link into the Field “Additional Board Manager URLs:”
https://dl.espressif.com/dl/package_esp32_index.json
Afterwards open the Board Manager:
Tools > Board > Boardmanager
Search for ESP32 platform and install the library. Choose the Board DOIT ESP32 DEVKIT V1
Tools > Board: ”DOIT ESP32 DEVKIT V1”
To check if the library is installed correctly, flash one of the basic examples on the micro-controller:
File > Examples > Basic > Blink
After the sketch is flashed on the ESP32 the LED should start flashing. Afterwards a library has to be installed in order to use BLE on the ESP32. For Example the BLE library by Neil Kolban which can be found on github:
[https://github.com/nkolban/ESP32_BLE_Arduino ]
Download the library as a zip file. These zip file can be included directly via
(In the Arduino IDE) Sketch > Include Library > Add .ZIP Library... > select the downloaded file > Open
After both libraries are installed the following sketch can be used to initialize a Bluetooth Low Energy server with one service and one characteristic. In this sketch the analog input on Pin 36 is readout and the value is written into the characteristic. The additional phyphox file notifies this characteristic and plots the received values.