mirror of
https://github.com/MOSH-Insa-Toulouse/5ISS-2024-2025-MARIN--MULLER-BOUJON.git
synced 2025-06-08 22:10:49 +02:00
Cleaned previous embedded file as microchip chip doesn't work
This commit is contained in:
parent
6a4b93f719
commit
b119a84ff5
10 changed files with 0 additions and 367 deletions
5
embedded/.gitignore
vendored
5
embedded/.gitignore
vendored
|
@ -1,5 +0,0 @@
|
||||||
.pio
|
|
||||||
.vscode/.browse.c_cpp.db*
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
.vscode/launch.json
|
|
||||||
.vscode/ipch
|
|
10
embedded/.vscode/extensions.json
vendored
10
embedded/.vscode/extensions.json
vendored
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"platformio.platformio-ide"
|
|
||||||
],
|
|
||||||
"unwantedRecommendations": [
|
|
||||||
"ms-vscode.cpptools-extension-pack"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
|
|
||||||
This directory is intended for project header files.
|
|
||||||
|
|
||||||
A header file is a file containing C declarations and macro definitions
|
|
||||||
to be shared between several project source files. You request the use of a
|
|
||||||
header file in your project source file (C, C++, etc) located in `src` folder
|
|
||||||
by including it, with the C preprocessing directive `#include'.
|
|
||||||
|
|
||||||
```src/main.c
|
|
||||||
|
|
||||||
#include "header.h"
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Including a header file produces the same results as copying the header file
|
|
||||||
into each source file that needs it. Such copying would be time-consuming
|
|
||||||
and error-prone. With a header file, the related declarations appear
|
|
||||||
in only one place. If they need to be changed, they can be changed in one
|
|
||||||
place, and programs that include the header file will automatically use the
|
|
||||||
new version when next recompiled. The header file eliminates the labor of
|
|
||||||
finding and changing all the copies as well as the risk that a failure to
|
|
||||||
find one copy will result in inconsistencies within a program.
|
|
||||||
|
|
||||||
In C, the usual convention is to give header files names that end with `.h'.
|
|
||||||
It is most portable to use only letters, digits, dashes, and underscores in
|
|
||||||
header file names, and at most one dot.
|
|
||||||
|
|
||||||
Read more about using header files in official GCC documentation:
|
|
||||||
|
|
||||||
* Include Syntax
|
|
||||||
* Include Operation
|
|
||||||
* Once-Only Headers
|
|
||||||
* Computed Includes
|
|
||||||
|
|
||||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
|
|
@ -1,46 +0,0 @@
|
||||||
|
|
||||||
This directory is intended for project specific (private) libraries.
|
|
||||||
PlatformIO will compile them to static libraries and link into executable file.
|
|
||||||
|
|
||||||
The source code of each library should be placed in an own separate directory
|
|
||||||
("lib/your_library_name/[here are source files]").
|
|
||||||
|
|
||||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
|
||||||
|
|
||||||
|--lib
|
|
||||||
| |
|
|
||||||
| |--Bar
|
|
||||||
| | |--docs
|
|
||||||
| | |--examples
|
|
||||||
| | |--src
|
|
||||||
| | |- Bar.c
|
|
||||||
| | |- Bar.h
|
|
||||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
|
||||||
| |
|
|
||||||
| |--Foo
|
|
||||||
| | |- Foo.c
|
|
||||||
| | |- Foo.h
|
|
||||||
| |
|
|
||||||
| |- README --> THIS FILE
|
|
||||||
|
|
|
||||||
|- platformio.ini
|
|
||||||
|--src
|
|
||||||
|- main.c
|
|
||||||
|
|
||||||
and a contents of `src/main.c`:
|
|
||||||
```
|
|
||||||
#include <Foo.h>
|
|
||||||
#include <Bar.h>
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
PlatformIO Library Dependency Finder will find automatically dependent
|
|
||||||
libraries scanning project source files.
|
|
||||||
|
|
||||||
More information about PlatformIO Library Dependency Finder
|
|
||||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
|
@ -1,25 +0,0 @@
|
||||||
#include "sensor.hpp"
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
Sensor::Sensor()
|
|
||||||
{}
|
|
||||||
|
|
||||||
void Sensor::init(const uint8_t pin)
|
|
||||||
{
|
|
||||||
_pin = pin;
|
|
||||||
pinMode(_pin, INPUT);
|
|
||||||
digitalWrite(_pin, HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
float Sensor::get_analog()
|
|
||||||
{
|
|
||||||
return (static_cast<float>(analogRead(_pin))/(1<<12))*3.3f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normally should be 5V, but the ADC can only see up to 3.3 on 12 bits
|
|
||||||
float Sensor::get_RSR0()
|
|
||||||
{
|
|
||||||
float sensor_volt=(static_cast<float>(analogRead(_pin))/(1<<12))*3.3f;
|
|
||||||
float RS_gas = (3.3-sensor_volt)/sensor_volt;
|
|
||||||
return RS_gas/R0;
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
#ifndef HEADER_SENSOR
|
|
||||||
#define HEADER_SENSOR
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
constexpr uint8_t SENSOR_PIN = 34;
|
|
||||||
constexpr float R0 = 0.8;
|
|
||||||
|
|
||||||
class Sensor {
|
|
||||||
public:
|
|
||||||
Sensor();
|
|
||||||
void init(const uint8_t pin);
|
|
||||||
float get_analog();
|
|
||||||
float get_RSR0();
|
|
||||||
private:
|
|
||||||
uint8_t _pin;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // HEADER_SENSOR
|
|
|
@ -1,20 +0,0 @@
|
||||||
; PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[env:esp32dev]
|
|
||||||
platform = espressif32
|
|
||||||
board = esp32dev
|
|
||||||
monitor_speed = 115200
|
|
||||||
framework = arduino
|
|
||||||
lib_deps =
|
|
||||||
adafruit/Adafruit SSD1306@^2.5.13
|
|
||||||
adafruit/Adafruit GFX Library@^1.11.11
|
|
||||||
mbed-seeed/BluetoothSerial@0.0.0+sha.f56002898ee8
|
|
||||||
adafruit/Adafruit BusIO@^1.16.2
|
|
|
@ -1,132 +0,0 @@
|
||||||
#include <Arduino.h>
|
|
||||||
#include <HardwareSerial.h>
|
|
||||||
#include <Wire.h>
|
|
||||||
#include <Adafruit_GFX.h>
|
|
||||||
#include <Adafruit_SSD1306.h>
|
|
||||||
|
|
||||||
#include "sensor.hpp"
|
|
||||||
|
|
||||||
#define SCREEN_WIDTH 128
|
|
||||||
#define SCREEN_HEIGHT 64
|
|
||||||
|
|
||||||
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
|
|
||||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
|
|
||||||
|
|
||||||
// RN2483Serial using RX2 and TX2
|
|
||||||
HardwareSerial RN2483Serial(2);
|
|
||||||
|
|
||||||
Sensor gaz_sensor;
|
|
||||||
|
|
||||||
void printSSD1306(String text) {
|
|
||||||
display.clearDisplay();
|
|
||||||
display.setCursor(0, 0);
|
|
||||||
display.println(text);
|
|
||||||
display.display();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Init_SSD1306() {
|
|
||||||
// SSD1306 initialization
|
|
||||||
if(!display.begin(0x3C, 0x3C)) { // Address 0x3C for 128x64
|
|
||||||
for(;;);
|
|
||||||
}
|
|
||||||
display.display();
|
|
||||||
delay(2000); // Pause for 2 seconds
|
|
||||||
|
|
||||||
display.clearDisplay();
|
|
||||||
display.setTextSize(1); // Normal 1:1 pixel scale
|
|
||||||
display.setTextColor(SSD1306_WHITE); // Draw white text
|
|
||||||
display.setCursor(0, 0); // Start at top-left corner
|
|
||||||
|
|
||||||
display.println("SSD1306 Oled Initialized!");
|
|
||||||
display.display();
|
|
||||||
delay(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_RN2483A() {
|
|
||||||
// Send a command to the RN2483A module
|
|
||||||
RN2483Serial.println("sys get ver");
|
|
||||||
|
|
||||||
// Wait for a response
|
|
||||||
delay(1000);
|
|
||||||
|
|
||||||
// Read the response from the RN2483A module
|
|
||||||
while (RN2483Serial.available()) {
|
|
||||||
String response = RN2483Serial.readString();
|
|
||||||
printSSD1306("RN2483A Response:");
|
|
||||||
Serial.println(response);
|
|
||||||
printSSD1306(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void initGateway() {
|
|
||||||
String devEUI = "9a0698b4e20d4d2f";
|
|
||||||
String joinEUI = "53760ec38137bbf8";
|
|
||||||
String appKey = "4f30040e6b6f1a4f6a0ed332fc6f7ae7";
|
|
||||||
|
|
||||||
RN2483Serial.println("mac set deveui " + devEUI);
|
|
||||||
delay(100);
|
|
||||||
RN2483Serial.println("mac set appeui " + joinEUI);
|
|
||||||
delay(100);
|
|
||||||
RN2483Serial.println("mac set appkey " + appKey);
|
|
||||||
delay(100);
|
|
||||||
RN2483Serial.println("mac set pwridx 5");
|
|
||||||
delay(100);
|
|
||||||
RN2483Serial.println("mac join otaa");
|
|
||||||
|
|
||||||
delay(5000);
|
|
||||||
|
|
||||||
if (RN2483Serial.available()) {
|
|
||||||
String response = RN2483Serial.readString();
|
|
||||||
Serial.println("Join Response: " + response);
|
|
||||||
printSSD1306("Join: " + response);
|
|
||||||
|
|
||||||
if (response.indexOf("accepted") >= 0) {
|
|
||||||
Serial.println("Join accepted");
|
|
||||||
printSSD1306("Join accepted");
|
|
||||||
} else {
|
|
||||||
Serial.println("Join failed");
|
|
||||||
printSSD1306("Join failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendToGateway() {
|
|
||||||
// Send Hello : 48656c6c6f in hex
|
|
||||||
RN2483Serial.println("mac tx uncnf 1 48656c6c6f");
|
|
||||||
delay(1000);
|
|
||||||
|
|
||||||
while (RN2483Serial.available()) {
|
|
||||||
String txResponse = RN2483Serial.readString();
|
|
||||||
Serial.println("TX Response: " + txResponse);
|
|
||||||
printSSD1306("TX Response: " + txResponse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
Serial.begin(115200);
|
|
||||||
|
|
||||||
// Initialize RN2483A Serial communication
|
|
||||||
RN2483Serial.begin(57600);
|
|
||||||
Serial.begin(115200);
|
|
||||||
|
|
||||||
// Initialize SSD1306
|
|
||||||
Init_SSD1306();
|
|
||||||
delay(5000);
|
|
||||||
|
|
||||||
// Initialize Gateway from LoRa
|
|
||||||
initGateway();
|
|
||||||
|
|
||||||
// Initialize Sensor
|
|
||||||
gaz_sensor.init(SENSOR_PIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
// test_RN2483A();
|
|
||||||
// Serial.print("Value from sensor: ");
|
|
||||||
// Serial.println(gaz_sensor.get_value());
|
|
||||||
// delay(1000);
|
|
||||||
|
|
||||||
// Test communication to gateway
|
|
||||||
sendToGateway();
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
#include "Arduino.h"
|
|
||||||
#include "BluetoothSerial.h"
|
|
||||||
#include <Wire.h>
|
|
||||||
#include <SPI.h>
|
|
||||||
|
|
||||||
BluetoothSerial SerialBT;
|
|
||||||
|
|
||||||
const int LED_BUILTIN = 2;
|
|
||||||
|
|
||||||
String receivedMessage = "";
|
|
||||||
|
|
||||||
void processBluetoothMessage(String message);
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
|
||||||
Serial.println("Starting Bluetooth...");
|
|
||||||
|
|
||||||
if (!SerialBT.begin("ESP32 Yohan et Robin")) {
|
|
||||||
Serial.println("Error on starting Bluetooth");
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println("Bluetooth started, waitint for connections...");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
if (SerialBT.available()) {
|
|
||||||
char receivedChar = SerialBT.read();
|
|
||||||
|
|
||||||
receivedMessage += receivedChar;
|
|
||||||
Serial.print("Current message: ");
|
|
||||||
Serial.println(receivedMessage);
|
|
||||||
|
|
||||||
if (receivedMessage.endsWith("o")) {
|
|
||||||
processBluetoothMessage("ON");
|
|
||||||
receivedMessage = "";
|
|
||||||
} else if (receivedMessage.endsWith("f")) {
|
|
||||||
processBluetoothMessage("OFF");
|
|
||||||
receivedMessage = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void processBluetoothMessage(String message) {
|
|
||||||
message.trim();
|
|
||||||
Serial.println("Received: " + message);
|
|
||||||
|
|
||||||
if (message.equalsIgnoreCase("ON")) {
|
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
|
||||||
Serial.println("Turning LED ON");
|
|
||||||
} else if (message.equalsIgnoreCase("OFF")) {
|
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
|
||||||
Serial.println("Turning LED OFF");
|
|
||||||
} else {
|
|
||||||
Serial.println("Invalid command received");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
|
|
||||||
This directory is intended for PlatformIO Test Runner and project tests.
|
|
||||||
|
|
||||||
Unit Testing is a software testing method by which individual units of
|
|
||||||
source code, sets of one or more MCU program modules together with associated
|
|
||||||
control data, usage procedures, and operating procedures, are tested to
|
|
||||||
determine whether they are fit for use. Unit testing finds problems early
|
|
||||||
in the development cycle.
|
|
||||||
|
|
||||||
More information about PlatformIO Unit Testing:
|
|
||||||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
|
Loading…
Add table
Reference in a new issue