Student: Mihai-Paul Fîrțală, ACES
The project aims to provide real time data acquisition (suspension force, GPS, accelerations etc.) capabilities for UPB Drive's formula student race car. The system consists of 2xESP32 microcontrollers transferring data using 2xLoRa transceivers. For this project only the suspension force will be measured because the GPS and the accelerometer malfunctioned. One ESP32 is equipped with additional sensors such as linear potentiometers and will be mounted on the car to measure the suspension force which will be translated into a variable voltage that will be captured by the internal ADC of the ESP32. These data will further be sent via LoRa protocol to the second ESP32 which is connected to the local WiFi router and will load the received information to a server which can be accessed using WebSocket protocol.
The hardware components needed for this project are:
Fig. 2.1. - Overview diagram
Fig. 2.2. - Electrical wiring
Fig. 2.3. - Acquisition System
In this section I will describe the configurations needed for the transmitter module. The code starts by including the SPI libraries which is used by the ESP32 to send and receive commands and data to the LoRa RFM96 module.
#include <SPI.h> #include <LoRa.h>
In order to set the pins used by LoRa, the next function is used:
LoRa.setPins(ss, rst, dio0);
Where ss
is thte slave select pin used by SPI protocol. This can be set to any available digital I/O pin. For example #define ss 5
. rst
pin is used to reset the LoRa and is set to pin 17. dio0
is a default pin set to 2 and is not used.
Next code snippet will initialize the LoRa transceiver to transmit and receive the radio packets with a frequency of 868 MHz, which is the frequency available in Europe.
while (!LoRa.begin(866E6)) { Serial.println("."); delay(500); }
To begin sending the packets, the next lines are used.
LoRa.beginPacket(); LoRa.print("Analog read: "); LoRa.print(potValue); LoRa.endPacket();
The suspension force is acquired using a linear potentiometer that varies the voltage captured by the internal ADC (Analog to Digital Converter) depending on how much the suspension has moved.
potValue = analogRead(potPin);
To configure the receiver module additional libraries will be included, as seen below.
// Include libraries #include <SPI.h> #include <LoRa.h> #include <WiFi.h> #include <WebServer.h> #include <WebSocketsServer.h>
Set the WiFi credentials where the ESP32 will be connected according to the macros:
#define WIFI_SSID "WiFi Name" #define WIFI_PASSWORD "Password"
The website is stored as a string which contains the JSON format. More details of this are present in the code.
String website = "<!DOCTYPE html><html>...>"
Connect to the wifi using the following function.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
The ESP32 on the receive module will host the website where the received data will be loaded. Access to the website will be done using the web socket protocol.
server.begin(); webSocket.begin();
Next snippet is used as an interrupt, meaning that every time an event occurs (i.e loss of connection, a message from a client) the webSocketEvent
function will be called and will prompt .
webSocket.onEvent(webSocketEvent);
To keep the server on and to handle all the clients, the next lines are used:
server.handleClient(); webSocket.loop();
The following function loads the received data on the server
webSocket.broadcastTXT(receivedVoltageArray);
To read the data received by the LoRa module .read
method can be used.
receivedVoltage = (char)LoRa.read();
Although the approach of acquiring the data in this manner is not the most efficient one because the baud rate is limited, this approach provide the capability to observe and analyze the behavior of the monopost in real time.
Here is a link to the github repository: https://github.com/BlackSeaArmadillos/RTASdrive/tree/develop
Video can be seen on my YouTube channel: https://www.youtube.com/watch?v=LqijF9BFF4c