cambios picha
This commit is contained in:
2
hardware/.vscode/settings.json
vendored
2
hardware/.vscode/settings.json
vendored
@@ -17,7 +17,7 @@
|
|||||||
"initializer_list": "cpp"
|
"initializer_list": "cpp"
|
||||||
},
|
},
|
||||||
"github.copilot.enable": {
|
"github.copilot.enable": {
|
||||||
"*": true,
|
"*": false,
|
||||||
"plaintext": false,
|
"plaintext": false,
|
||||||
"markdown": false,
|
"markdown": false,
|
||||||
"scminput": false,
|
"scminput": false,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include <MD_Parola.h>
|
#include <MD_Parola.h>
|
||||||
#include <MD_MAX72XX.h>
|
#include <MD_MAX72xx.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
|
||||||
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
|
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
|
||||||
@@ -9,8 +9,8 @@
|
|||||||
#define CLK_PIN 17
|
#define CLK_PIN 17
|
||||||
|
|
||||||
void MAX7219_Init();
|
void MAX7219_Init();
|
||||||
void MAX7219_DisplayText(const char *text, textPosition_t align, int speed, int pause);
|
void MAX7219_DisplayText(const char *text, textPosition_t align, uint16_t speed, uint16_t pause);
|
||||||
void MAX7219_StartAnimation();
|
bool MAX7219_StartAnimation();
|
||||||
void MAX7219_StopAnimation();
|
void MAX7219_ResetAnimation();
|
||||||
void MAX7219_ClearDisplay();
|
void MAX7219_ClearDisplay();
|
||||||
void MAX7219_SetBrightness(uint8_t brightness);
|
void MAX7219_SetBrightness(uint8_t brightness);
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#define ANALOG_MQ7 33
|
#define HEATER_PIN 16
|
||||||
#define DIGITAL_MQ7 32
|
#define SENSOR_PIN 34
|
||||||
|
|
||||||
void MQ7_Init();
|
void MQ7_Init();
|
||||||
void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue);
|
void MQ7_Read(float &sensorValue);
|
||||||
|
void pwmBitBang(int totalMs, int highPct, int cycleMs);
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#include "BMP280.h"
|
|
||||||
|
|
||||||
|
|
||||||
void BMP280_Init()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t BMP280_DataReady()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void BMP280_Read(float &temperature, float &humidity, float &pressure, float &altitude)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#include "MQ7.h"
|
|
||||||
|
|
||||||
void MQ7_Init()
|
|
||||||
{
|
|
||||||
pinMode(digitalMQ7, INPUT);
|
|
||||||
pinMode(analogMQ7, INPUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue)
|
|
||||||
{
|
|
||||||
analogWrite(analogMQ7, 1023);
|
|
||||||
delay(60000);
|
|
||||||
analogWrite(analogMQ7, (1023/5)*1.4 );
|
|
||||||
|
|
||||||
for(int i = 0; i<100; i++)
|
|
||||||
{
|
|
||||||
sensorValue = sensorValue + analogRead(analogMQ7);
|
|
||||||
delay(90000);
|
|
||||||
}
|
|
||||||
|
|
||||||
sensorValue = sensorValue/100.0;
|
|
||||||
sensorVolt = sensorValue/1024*5.0;
|
|
||||||
RSAir = (5.0-sensorVolt)/sensorVolt;
|
|
||||||
R0 = RSAir/(26+(1/3));
|
|
||||||
|
|
||||||
Serial.print("R0 = ");
|
|
||||||
Serial.println(R0);
|
|
||||||
|
|
||||||
delay(1000);
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
upload_port = COM3
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
knolleary/PubSubClient@^2.8
|
knolleary/PubSubClient@^2.8
|
||||||
mikalhart/TinyGPSPlus@^1.0.2
|
mikalhart/TinyGPSPlus@^1.0.2
|
||||||
|
|||||||
@@ -5,21 +5,21 @@ MD_Parola display = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVI
|
|||||||
void MAX7219_Init()
|
void MAX7219_Init()
|
||||||
{
|
{
|
||||||
display.begin();
|
display.begin();
|
||||||
display.setIntensity(15); // 0-15
|
display.setIntensity(1); // 0-15
|
||||||
display.displayClear();
|
display.displayClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MAX7219_DisplayText(const char *text, textPosition_t align, int speed, int pause)
|
void MAX7219_DisplayText(const char *text, textPosition_t align, uint16_t speed, uint16_t pause)
|
||||||
{
|
{
|
||||||
display.displayText(text, align, speed, pause, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
|
display.displayText(text, align, speed, pause, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MAX7219_StartAnimation()
|
bool MAX7219_StartAnimation()
|
||||||
{
|
{
|
||||||
display.displayAnimate();
|
return display.displayAnimate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MAX7219_StopAnimation()
|
void MAX7219_ResetAnimation()
|
||||||
{
|
{
|
||||||
display.displayReset();
|
display.displayReset();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,25 +2,44 @@
|
|||||||
|
|
||||||
void MQ7_Init()
|
void MQ7_Init()
|
||||||
{
|
{
|
||||||
pinMode(DIGITAL_MQ7, INPUT);
|
pinMode(HEATER_PIN, OUTPUT);
|
||||||
pinMode(ANALOG_MQ7, INPUT);
|
pinMode(SENSOR_PIN, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue)
|
void MQ7_Read(float &sensorValue)
|
||||||
{
|
{
|
||||||
// preheat
|
Serial.println("\t - Calentando MQ7");
|
||||||
analogWrite(ANALOG_MQ7, 1023);
|
digitalWrite(HEATER_PIN, HIGH);
|
||||||
delay(60000);
|
delay(60000);
|
||||||
analogWrite(ANALOG_MQ7, (1023/5)*1.4 );
|
|
||||||
|
|
||||||
for(int i = 0; i<100; i++)
|
Serial.println("\t - Enfriando MQ7");
|
||||||
{
|
pwmBitBang(90000, 28, 100);
|
||||||
sensorValue = sensorValue + analogRead(ANALOG_MQ7);
|
|
||||||
delay(1200);
|
|
||||||
}
|
|
||||||
|
|
||||||
sensorValue = sensorValue/100.0;
|
const int N = 1;
|
||||||
sensorVolt = sensorValue/1024*5.0;
|
long sum = 0;
|
||||||
RSAir = (5.0-sensorVolt)/sensorVolt;
|
for (int i = 0; i < N; i++)
|
||||||
R0 = RSAir/(26+(1/3));
|
{
|
||||||
|
sum += analogRead(SENSOR_PIN);
|
||||||
|
delay(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
sensorValue = sum / float(N);
|
||||||
|
//sensorVolt = sensorValue * (3.3 / 4095.0); // ADC 12 bits, 3.3V
|
||||||
|
}
|
||||||
|
|
||||||
|
// generamos PWM por software usando bit banging
|
||||||
|
void pwmBitBang(int totalMs, int highPct, int cycleMs)
|
||||||
|
{
|
||||||
|
int onTime = cycleMs * highPct / 100;
|
||||||
|
int offTime = cycleMs - onTime;
|
||||||
|
int elapsed = 0;
|
||||||
|
|
||||||
|
while (elapsed < totalMs)
|
||||||
|
{
|
||||||
|
digitalWrite(HEATER_PIN, HIGH);
|
||||||
|
delay(onTime);
|
||||||
|
digitalWrite(HEATER_PIN, LOW);
|
||||||
|
delay(offTime);
|
||||||
|
elapsed += cycleMs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,44 +4,44 @@ const uint32_t deviceId = getChipID();
|
|||||||
|
|
||||||
extern HTTPClient httpClient; // HTTP client object
|
extern HTTPClient httpClient; // HTTP client object
|
||||||
String response; // HTTP Response
|
String response; // HTTP Response
|
||||||
float sensorVolt, sensorValue, RSAir, R0; // MQ7 vars
|
float sensorVolt, sensorValue; // MQ7 vars
|
||||||
float temperature, pressure, humidity; // BME280 vars
|
float temperature, pressure, humidity; // BME280 vars
|
||||||
float lon, lat; // GPS vars
|
float lon, lat; // GPS vars
|
||||||
extern MD_Parola display; // Display object
|
extern MD_Parola display; // Display object
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
/*GPS_Init();
|
||||||
|
Serial.println("GPS inicializado"); */
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
/*Serial.println("Iniciando...");
|
Serial.println("Iniciando...");
|
||||||
MQ7_Init();
|
|
||||||
Serial.println("Sensor MQ7 inicializado");
|
|
||||||
BME280_Init();
|
BME280_Init();
|
||||||
Serial.println("Sensor BME280 inicializado");
|
Serial.println("Sensor BME280 inicializado");
|
||||||
GPS_Init();
|
|
||||||
Serial.println("GPS inicializado"); */
|
|
||||||
MAX7219_Init();
|
MAX7219_Init();
|
||||||
Serial.println("Display inicializado");
|
Serial.println("Display inicializado");
|
||||||
|
MQ7_Init();
|
||||||
|
Serial.println("Sensor MQ7 inicializado");
|
||||||
|
|
||||||
//prettyReadBME280();
|
prettyReadBME280();
|
||||||
testMatrix();
|
testMatrix();
|
||||||
//prettyReadMQ7();
|
prettyReadMQ7();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
if(MAX7219_StartAnimation())
|
||||||
|
{
|
||||||
|
MAX7219_ResetAnimation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void prettyReadMQ7()
|
void prettyReadMQ7()
|
||||||
{
|
{
|
||||||
Serial.println("Leyendo sensor MQ7...");
|
Serial.println("Leyendo sensor MQ7...");
|
||||||
MQ7_Read(sensorVolt, RSAir, R0, sensorValue);
|
MQ7_Read(sensorValue);
|
||||||
Serial.print("\t - Voltaje: "); Serial.print(sensorVolt); Serial.print("V\r\n");
|
//Serial.print("\t - Voltaje: "); Serial.print(sensorVolt); Serial.print("V\r\n");
|
||||||
Serial.print("\t - Valor sensor: "); Serial.print(sensorValue); Serial.print("\r\n");
|
Serial.print("\t - Valor sensor: "); Serial.print(sensorValue); Serial.print("\r\n");
|
||||||
Serial.print("\t - Resistencia aire: "); Serial.print(RSAir); Serial.print("kOhm\r\n");
|
|
||||||
Serial.print("\t - Resistencia aire: "); Serial.print(R0); Serial.print("kOhm\r\n");
|
|
||||||
Serial.print("\t - Concentración CO: "); Serial.print(sensorValue); Serial.print("ppm\r\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void prettyReadBME280()
|
void prettyReadBME280()
|
||||||
@@ -64,7 +64,7 @@ void prettyReadGPS()
|
|||||||
void testMatrix()
|
void testMatrix()
|
||||||
{
|
{
|
||||||
Serial.println("Escribiendo en el display...");
|
Serial.println("Escribiendo en el display...");
|
||||||
MAX7219_DisplayText("Prueba de texto", PA_LEFT, 100, 500);
|
MAX7219_DisplayText("Prueba de texto", PA_LEFT, 50, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user