Skip to content
Snippets Groups Projects
Commit 013c57d7 authored by Bilal Hassan's avatar Bilal Hassan
Browse files

drs26 sensor adaption to the sensor interface foter_sensor.hpp

parent bbe19333
No related branches found
No related tags found
5 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!10merge serial comm and sd write into espnow,!2Draft: Read Sensors on ESP32 Client device
Showing
with 408 additions and 0 deletions
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
!lib/
{
// 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"
]
}
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
#ifndef _FORTE_SENSOR
#define _FORTE_SENSOR
class Forte_Sensor {
public:
virtual void* read_data() = 0;
virtual void setup() = 0;
private:
};
#endif
\ No newline at end of file
#ifndef _FORTE_PINOUT
#define _FORTE_PINOUT
// Pins for I2C
#define I2C_SDA 18
#define I2C_SCL 19
#define SDI_DATA 8
#endif
\ No newline at end of file
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 a 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
#include <drs26.hpp>
#include <pinout.hpp>
#include "Wire.h"
/*
It happens for some reason that the sensor cant get reached every 2 time
Because the sensor use sdi12 protocoll we have to wait aproxemettly 1 secound between the commands
It is not known how lond the response takes so we use a while loop which can be a risk wehre the programm can get stuck
*/
void Forte_DRS26 ::setup()
{
drs26.begin(SDI_DATA);
}
out_data *Forte_DRS26 ::read_data()
{
String sdiResponse = "";
drs26.sendCommand("1M!");
delay(1000);
drs26.sendCommand("1D0!");
while (drs26.available())
{
char c = drs26.read();
if ((c != '\n') && (c != '\r'))
{
sdiResponse += c;
delay(10); // 1 character ~ 7.5ms
}
}
if (sdiResponse.length() > 1)
{
data.id = sdiResponse.substring(0, 8).toInt();
data.circumference = sdiResponse.substring(9, 15).toFloat();
data.temperatur = sdiResponse.substring(16, 22).toFloat();
return &data;
}
return 0;
}
\ No newline at end of file
#ifndef _INA219
#define _INA219
#include <forte_sensor.hpp>
#include <pinout.hpp>
#include <SparkFun_SCD30_Arduino_Library.h>
#include <INA219_WE.h>
#include <SDI12.h>
struct out_data {
int id;
float circumference;
float temperatur;
};
class Forte_DRS26 : public Forte_Sensor{
public:
void setup();
out_data* read_data();
private:
SDI12 drs26;
out_data data;
};
#endif
\ No newline at end of file
#ifndef _FORTE_SENSOR
#define _FORTE_SENSOR
class Forte_Sensor {
public:
virtual void* read_data() = 0;
virtual void setup() = 0;
private:
};
#endif
\ No newline at end of file
#ifndef _FORTE_PINOUT
#define _FORTE_PINOUT
// Pins for I2C
#define I2C_SDA 5
#define I2C_SCL 4
#define SDI_DATA 8
#endif
\ No newline at end of file
#ifndef _FORTE_SENSOR
#define _FORTE_SENSOR
class Forte_Sensor {
public:
virtual void* read_data() = 0;
virtual void setup() = 0;
private:
};
#endif
\ No newline at end of file
#include "ina219.hpp"
#include "Wire.h"
#include <SparkFun_SCD30_Arduino_Library.h>
#include <INA219_WE.h>
void Forte_INA219 :: setup(){
Wire.begin(I2C_SDA, I2C_SCL);
if(!ina219.init()){
// Sensor init went wrong
return;
}
}
out_data* Forte_INA219 :: read_data(){
if(!ina219.getOverflow())
{
data.shuntVoltage_mV = ina219.getShuntVoltage_mV();
data.busVoltage_V= ina219.getBusVoltage_V();
data.current_mA= ina219.getCurrent_mA();
data.power_mW= ina219.getBusPower();
data.loadVoltage_V = data.busVoltage_V + (data.shuntVoltage_mV/1000);
data.ina219_overflow=ina219.getOverflow();
return &data;
}
else
return 0;
}
\ No newline at end of file
#ifndef _INA219
#define _INA219
#include <forte_sensor.hpp>
#include <pinout.hpp>
#include <SparkFun_SCD30_Arduino_Library.h>
#include <INA219_WE.h>
struct out_data {
float shuntVoltage_mV = 0.0;
float loadVoltage_V = 0.0;
float busVoltage_V = 0.0;
float current_mA = 0.0;
float power_mW = 0.0;
bool ina219_overflow = false;
};
class Forte_INA219 : public Forte_Sensor{
public:
void setup();
out_data* read_data();
private:
INA219_WE ina219;
out_data data;
};
#endif
\ No newline at end of file
#ifndef _FORTE_PINOUT
#define _FORTE_PINOUT
// Pins for I2C
#define I2C_SDA 5
#define I2C_SCL 4
#endif
\ No newline at end of file
#ifndef _FORTE_SENSOR
#define _FORTE_SENSOR
class Forte_Sensor {
public:
virtual void* read_data() = 0;
virtual void setup() = 0;
private:
};
#endif
\ No newline at end of file
#ifndef _FORTE_PINOUT
#define _FORTE_PINOUT
// Pins for I2C
#define I2C_SDA 18
#define I2C_SCL 19
#endif
\ No newline at end of file
#include "scd30.hpp"
#include "Wire.h"
#include <SparkFun_SCD30_Arduino_Library.h>
void Forte_SCD30 :: setup(){
Wire.begin(I2C_SDA, I2C_SCL);
if(!airSensor.begin()){
// Sensor init went wrong
return;
}
}
float* Forte_SCD30 :: read_data(){
if(airSensor.dataAvailable())
{
data1[0] = airSensor.getCO2();
data1[1] = airSensor.getTemperature();
data1[2] = airSensor.getHumidity();
return data1;
}
else
return 0;
}
\ No newline at end of file
#ifndef _SCD30
#define _SCD30
#include <forte_sensor.hpp>
#include <pinout.hpp>
#include <SparkFun_SCD30_Arduino_Library.h>
class Forte_SCD30 : public Forte_Sensor{
public:
void setup();
float* read_data();
private:
SCD30 airSensor;
float data1[3];
};
#endif
\ No newline at end of file
; 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:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
lib_deps =
sparkfun/SparkFun SCD30 Arduino Library@^1.0.18
Wire
wollewald/INA219_WE@^1.3.1
envirodiy/SDI-12@^2.1.4
#include <Arduino.h>
#include <drs26.hpp>
Forte_DRS26 sensor1;
void setup() {
Serial.begin(9600);
sensor1.setup();
}
void loop() {
out_data* data;
sensor1.read_data();
data = sensor1.read_data();
if(data==0)
{
Serial.println("Waiting for data");
}
else{
Serial.print("Sensor ID "); Serial.println(data->id);
Serial.print("Cicumfence "); Serial.println(data->circumference);
Serial.print("Temperature "); Serial.println(data->temperatur);
Serial.println();
}
delay(5000);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment