extend sensor vbatt and hall

This commit is contained in:
2021-11-29 16:51:17 +01:00
parent dc285288f0
commit 8c6cbbf247
8 changed files with 83220 additions and 17 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[env:esp32-pico] [env:esp32-pico]
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream platform = espressif32 #https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
board = m5stack-atom board = m5stack-atom
framework = arduino framework = arduino
lib_deps = lib_deps =
@@ -20,5 +20,5 @@ lib_ldf_mode = deep+
extra_scripts = ./littlefsbuilder.py extra_scripts = ./littlefsbuilder.py
build_flags = build_flags =
-DHARDWARE=2 -DHARDWARE=2
;upload_protocol = espota -DNDEF_DEBUG=1
;upload_port = 192.168.2.254 -DCORE_DEBUG_LEVEL=3

View File

@@ -74,7 +74,7 @@ void initAudio()
mp3 = new AudioGeneratorMP3(); mp3 = new AudioGeneratorMP3();
mp3->RegisterStatusCB(StatusCallback, (void *)"mp3"); mp3->RegisterStatusCB(StatusCallback, (void *)"mp3");
Serial.println("init Audio Done"); Serial.println("init Audio Done");
playSong(audio_current_Song); //playSong(audio_current_Song);
} }
void handleAudio() void handleAudio()

View File

@@ -10,11 +10,16 @@
#include "ota.h" #include "ota.h"
#include "game.h" #include "game.h"
uint32_t looptime = 0;
void setup() void setup()
{ {
initPower(); initPower();
Serial.begin(115200); Serial.begin(115200);
delay(2000); Serial.setDebugOutput(true);
Serial.println("muziekdoos v2");
Serial.flush();
delay(1000);
initStorage(); initStorage();
initConfig(); initConfig();
@@ -28,12 +33,14 @@ void setup()
void loop() void loop()
{ {
looptime = millis();
debugHandle(); debugHandle();
handleAudio(); handleAudio();
handleRfid(); //handleRfid();
handleSensor handleSensor();
//handleGame(); //handleGame();
handlePower(); handlePower();
//handleOta(); //handleOta();
log_i("main: looptime = %d", millis() - looptime);
} }

View File

@@ -19,12 +19,12 @@ void handleRfid()
uint32_t timeNow = millis(); uint32_t timeNow = millis();
if (lastRFID - timeNow > RFIDINTERVAL) if (lastRFID - timeNow > RFIDINTERVAL)
{ {
if (nfc.tagPresent()) if (nfc.tagPresent())
{ {
NfcTag tag = nfc.read(); NfcTag tag = nfc.read();
String uid = tag.getUidString(); //String uid = tag.getUidString();
Serial.println(uid); //Serial.println(uid);
lastRFID = timeNow;
} }
} }
} }

View File

@@ -2,6 +2,7 @@
ADS1115 ADS(0x48); ADS1115 ADS(0x48);
uint32_t lastADS = 0; uint32_t lastADS = 0;
uint32_t lastVbatt = 0;
uint16_t BatterySensor = 0; uint16_t BatterySensor = 0;
uint16_t HallSensor = 0; uint16_t HallSensor = 0;
@@ -9,16 +10,34 @@ uint16_t HallSensor = 0;
void initSensor(void) void initSensor(void)
{ {
ADS.begin(I2C_SDA, I2C_SCL); Serial.print("sensor init ADS1x15:");
bool result = ADS.begin(I2C_SDA, I2C_SCL);
pinMode(MEAS_EN, OUTPUT);
Serial.printf("%s\n", (result? "OK":"FAIL"));
} }
void handleSensor(void) void handleSensor(void)
{ {
uint32_t timeNow = millis(); uint32_t timeNow = millis();
if(lastADS - timeNow > SENSORINTERVAL) if(lastADS - timeNow > ADSINTERVAL)
{ {
HallSensor = ADS.readADC(HALL_INPUT); HallSensor = ADS.readADC(HALL_INPUT);
BatterySensor = ADS.readADC(MEAS_ADC); lastADS = timeNow;
Serial.printf("Read sensor: Hall=%d, vbatt=%d",HallSensor, BatterySensor);
} }
if(lastVbatt - timeNow > VBATTINTERVALL-VBATTMEASPRECHARGE)
{
digitalWrite(MEAS_EN,HIGH);
log_i("precharge vbatt measurement");
}
if(lastVbatt - timeNow > VBATTINTERVALL)
{
BatterySensor = ADS.readADC(MEAS_ADC);
digitalWrite(MEAS_EN,LOW);
lastVbatt = timeNow;
}
log_i("Read sensor: Hall=%d, vbatt=%d",HallSensor, BatterySensor);
} }

View File

@@ -3,7 +3,9 @@
#include "ADS1X15.h" #include "ADS1X15.h"
#include "board.h" #include "board.h"
#define SENSORINTERVAL 250 #define ADSINTERVAL 250
#define VBATTINTERVALL 500
#define VBATTMEASPRECHARGE 100
void initSensor(void); void initSensor(void);

View File

@@ -3,7 +3,15 @@
#include <Arduino.h> #include <Arduino.h>
#include "FS.h" #include "FS.h"
#include <LITTLEFS.h>
#if defined ESP_ARDUINO_VERSION_VAL
#if (ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0)
#include <LittleFS.h>
#define ESP_V2
#endif
#else
#include <LITTLEFS.h>
#endif
#ifndef CONFIG_LITTLEFS_FOR_IDF_3_2 #ifndef CONFIG_LITTLEFS_FOR_IDF_3_2
#include <time.h> #include <time.h>