Vielen Dank für Eure geballte Know How Power.
Grundsätzlich lässt sich das Gerät anmelden und die Funktion ist gegeben.
Was mir aber aufgefallen ist:
Zurzeit versorge ich die Platine über die https://github.com/psi-4ward/HMSensor-FlashStation von. Da wird die Spannung über den Vcc-Pin eingespeist. Das heißt, dass am Pin Vin keine Spannung anliegt. Da an diesem Punkt jedoch über R4 und R5 gemessen wird, sollte Doch jetzt ein "critical" ausgelöste werden, oder? Das ist aber nicht der Fall (ich habe im Sketch den Wert 9 eingegeben.
Mit einer 1,5V Batterie am Vin habe ich noch nicht getestet.
Und was ich auch ich nicht verstanden habe: wo werden die Pins (D7 und 17 (A3)) für die Spannungsmessung definiert?
In dem Sketch von Patrick werden die Pins ja doch wohl in "typedef AskSin<LedType,IrqExternalBatt<17,7>,RadioType> BaseHal; " definiert, oder verstehe ich das falsch?
Ich habe meinen angepassten Sketch und die Schematic mal angehängt.
Tut mir leid, wenn ich Euch so nerve, ich habe aber jetzt unheimlich viel Zeit und möchte gerne ein bisschen mehr von der Materie verstehen..
Code: Alles auswählen
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
// ci-test=yes board=328p aes=no
//- -----------------------------------------------------------------------------------------------------------------------
// Dies ist die neue Version
// Ich verwende hier die Step Up Version. Dazu muß in der Zeile 34 CGF_STEPUP_ON eingestellt werden
// Die Werte 10 und 9 stehen für Low_Bat und critical
// "Low_Bat" ist der Wert, wann die Low-Bat Meldung kommt. Bei "critical" wird "sleepForever()" aufgerufen
// define this to implement new RHS3 device
// #define RHS3
// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER
// use background internal VCC measure
// #define BATTERY_IRQ // wird nur bei interner Batteriemessung genutzt (ohne Step Up)
#ifdef RHS3
// send battery value
#define CONTACT_STATE_WITH_BATTERY
#endif
#define CFG_STEPUP_BYTE 0x00
#define CFG_STEPUP_OFF 0x00
#define CFG_STEPUP_ON 0x01
#define CFG_BAT_LOW_BYTE 0x01
#define CFG_BAT_CRITICAL_BYTE 0x02
// define device configuration bytes
// #define DEVICE_CONFIG CFG_STEPUP_OFF,22,19
#define DEVICE_CONFIG CFG_STEPUP_ON,10,9
// 24 0030 4D455130323134373633 80 910101
#define EI_NOTEXTERNAL
#include <EnableInterrupt.h>
#include <AskSinPP.h>
#include <LowPower.h>
#include <Register.h>
#include <ContactState.h>
// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
#define LED1_PIN 4
#define LED2_PIN 5
// Arduino pin for the config button
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8
#define SENS1_PIN 14
#define SENS2_PIN 15
#define SABOTAGE_PIN 16
// activate additional open detection by using a third sensor pins
// #define SENS3_PIN 16
// #define SABOTAGE_PIN 0
// number of available peers per channel
#define PEERS_PER_CHANNEL 10
// all library classes are placed in the namespace 'as'
using namespace as;
// define all device properties
#ifdef RHS3
const struct DeviceInfo PROGMEM devinfo = {
{0xa9,0xb8,0xc7}, // Device ID
"papaa9b8c7", // Device Serial
{0xF2,0x09}, // Device Model
0x10, // Firmware Version
as::DeviceType::ThreeStateSensor, // Device Type
{0x01,0x00} // Info Bytes
};
#else
const struct DeviceInfo PROGMEM devinfo = {
{0x09,0x56,0x38}, // Device ID
"CRFenster5", // Device Serial
{0x00,0xC3}, // Device Model
0x22, // Firmware Version
as::DeviceType::ThreeStateSensor, // Device Type
{0x01,0x00} // Info Bytes
};
#endif
class SwitchSensor {
InternalVCC internal;
ExternalVCC<17,7,LOW,3000> external;
uint8_t mod;
public:
typedef uint16_t ValueType;
static const int DefaultDelay = 250;
SwitchSensor() : mod(0) {}
void mode (uint8_t m) {
mod = m;
init();
}
void init () {
if( mod == 0 ) {
internal.init();
DPRINTLN("InternalVCC");
}
else {
external.init();
DPRINTLN("Stepup - ExternalVCC");
}
}
void start () {
if( mod == 0 ) internal.start();
else external.start();
}
uint16_t finish () {
return mod == 0 ? internal.finish() : external.finish();
}
};
#ifdef BATTERY_IRQ
typedef IrqInternalBatt BatSensor;
#else
typedef BattSensor<AsyncMeter<SwitchSensor> > BatSensor;
#endif
/**
* Configure the used hardware
*/
typedef AvrSPI<10,11,12,13> SPIType;
typedef Radio<SPIType,2> RadioType;
typedef DualStatusLed<LED2_PIN,LED1_PIN> LedType;
typedef AskSin<LedType,BatSensor,RadioType> BaseHal;
class Hal : public BaseHal {
public:
void init (const HMID& id) {
BaseHal::init(id);
}
} hal;
#ifdef RHS3
DEFREGISTER(Reg0,DREG_CYCLICINFOMSG,MASTERID_REGS,DREG_TRANSMITTRYMAX,DREG_SABOTAGEMSG,DREG_LOWBATLIMIT)
#else
DEFREGISTER(Reg0,DREG_CYCLICINFOMSG,MASTERID_REGS,DREG_TRANSMITTRYMAX,DREG_SABOTAGEMSG)
#endif
class RHSList0 : public RegList0<Reg0> {
public:
RHSList0(uint16_t addr) : RegList0<Reg0>(addr) {}
void defaults () {
clear();
cycleInfoMsg(true);
transmitDevTryMax(6);
sabotageMsg(true);
#ifdef RHS3
lowBatLimit(22); // default low bat 2.2V
#endif
}
};
DEFREGISTER(Reg1,CREG_AES_ACTIVE,CREG_MSGFORPOS,CREG_EVENTDELAYTIME,CREG_LEDONTIME,CREG_TRANSMITTRYMAX)
class RHSList1 : public RegList1<Reg1> {
public:
RHSList1 (uint16_t addr) : RegList1<Reg1>(addr) {}
void defaults () {
clear();
msgForPosA(1); // CLOSED
msgForPosB(2); // OPEN
msgForPosC(3); // TILTED
// aesActive(false);
// eventDelaytime(0);
ledOntime(100);
transmitTryMax(6);
}
};
#ifdef SENS3_PIN
class ThreePinPosition : public TwoPinPosition {
uint8_t pin3;
public:
ThreePinPosition () : pin3(0) {}
void init (uint8_t p1,uint8_t p2,uint8_t p3,const uint8_t* pmap) {
TwoPinPosition::init(p1,p2,pmap);
pin3 = p3;
}
void measure (__attribute__((unused)) bool async=false) {
TwoPinPosition::measure(async);
if( _position == State::PosA && AskSinBase::readPin(pin3) == HIGH) {
_position = State::PosB;
}
}
};
template <class HALTYPE,class List0Type,class List1Type,class List4Type,int PEERCOUNT>
class ThreePinChannel : public ThreeStateGenericChannel<ThreePinPosition,HALTYPE,List0Type,List1Type,List4Type,PEERCOUNT> {
public:
typedef ThreeStateGenericChannel<ThreePinPosition,HALTYPE,List0Type,List1Type,List4Type,PEERCOUNT> BaseChannel;
ThreePinChannel () : BaseChannel() {};
~ThreePinChannel () {}
void init (uint8_t pin1,uint8_t pin2,uint8_t pin3,uint8_t sabpin,const uint8_t* pmap) {
BaseChannel::init(sabpin);
BaseChannel::possens.init(pin1,pin2,pin3,pmap);
}
};
typedef ThreePinChannel<Hal,RHSList0,RHSList1,DefList4,PEERS_PER_CHANNEL> ChannelType;
#else
typedef ThreeStateChannel<Hal,RHSList0,RHSList1,DefList4,PEERS_PER_CHANNEL> ChannelType;
#endif
class RHSType : public ThreeStateDevice<Hal,ChannelType,1,RHSList0> {
public:
typedef ThreeStateDevice<Hal,ChannelType,1,RHSList0> TSDevice;
RHSType(const DeviceInfo& info,uint16_t addr) : TSDevice(info,addr) {}
virtual ~RHSType () {}
virtual void configChanged () {
TSDevice::configChanged();
// set battery low/critical values
#ifdef RHS3
battery().low(getList0().lowBatLimit());
battery().critical(getList0().lowBatLimit()-3);
#else
battery().low(getConfigByte(CFG_BAT_LOW_BYTE));
battery().critical(getConfigByte(CFG_BAT_CRITICAL_BYTE));
#endif
#ifndef BATTERY_IRQ
// set the battery mode
battery().meter().sensor().mode(getConfigByte(CFG_STEPUP_BYTE));
#endif
}
};
RHSType sdev(devinfo,0x20);
ConfigButton<RHSType> cfgBtn(sdev);
const uint8_t posmap[4] = {Position::State::PosB,Position::State::PosC,Position::State::PosA,Position::State::PosB};
void setup () {
DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
sdev.init(hal);
buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
#ifdef SENS3_PIN
sdev.channel(1).init(SENS1_PIN,SENS2_PIN,SENS3_PIN,SABOTAGE_PIN,posmap);
#else
sdev.channel(1).init(SENS1_PIN,SENS2_PIN,SABOTAGE_PIN,posmap);
#endif
sdev.initDone();
// measure battery every 1h
hal.battery.init(seconds2ticks(60UL*60),sysclock);
// wait for valid battery value
while( hal.battery.current() == 0 ) ;
}
void loop() {
bool worked = hal.runready();
bool poll = sdev.pollRadio();
if( worked == false && poll == false ) {
// deep discharge protection
// if we drop below critical battery level - switch off all and sleep forever
if( hal.battery.critical() ) {
// this call will never return
hal.sleepForever();
}
// if nothing to do - go sleep
hal.sleep<>();
}
}
Code: Alles auswählen
16:52:49.289 -> AskSin++ v5.0.0 (Feb 14 2021 15:57:28)
16:52:49.289 -> Address Space: 32 - 103
16:52:49.289 -> CC init1
16:52:49.289 -> CC Version: 04
16:52:49.336 -> - ready
16:52:49.336 -> Config Freq: 0x2165D2
16:52:49.336 -> Activate Cycle Msg
16:52:49.336 -> Stepup - ExternalVCC
16:52:49.336 -> Stepup - ExternalVCC
16:52:49.570 -> eVcc: 2438
16:52:53.742 -> AskSin++ v5.0.0 (Feb 14 2021 15:57:28)
16:52:53.742 -> Address Space: 32 - 103
16:52:53.742 -> CC init1
16:52:53.742 -> CC Version: 04
16:52:53.742 -> - ready
16:52:53.742 -> Config Freq: 0x2165D2
16:52:53.742 -> Activate Cycle Msg
16:52:53.742 -> Stepup - ExternalVCC
16:52:53.789 -> Stepup - ExternalVCC
16:52:54.023 -> eVcc: 2387
16:53:01.382 -> debounce
16:53:01.476 -> pressed
16:53:01.710 -> released
16:53:01.710 -> <- 1A 01 84 00 095638 000000 22 00 C3 43 52 46 65 6E 73 74 65 72 35 80 01 01 00 - 456
16:53:01.757 ->
16:53:44.193 -> debounce
16:53:44.287 -> pressed
16:53:44.381 -> released
16:53:44.475 -> <- 1A 02 84 00 095638 000000 22 00 C3 43 52 46 65 6E 73 74 65 72 35 80 01 01 00 - 20686
16:53:44.475 ->
16:53:44.615 -> -> 10 01 A0 01 00FFFF 095638 00 05 00 00 00 00 00 - 20879
16:53:44.756 -> <- 0A 01 80 02 095638 00FFFF 00 - 20998
16:53:44.803 -> -> 13 0A A0 01 00FFFF 095638 00 08 02 01 0A 00 0B FF 0C FF - 21037
16:53:44.896 -> <- 0A 0A 80 02 095638 00FFFF 00 - 21157
16:53:44.943 -> -> 0B 13 A0 01 00FFFF 095638 00 06 - 21188
16:53:44.943 -> Activate Cycle Msg
16:53:44.943 -> Stepup - ExternalVCC
16:53:45.037 -> <- 0A 13 82 02 095638 00FFFF 00 - 21307
16:53:45.083 -> -> 10 1C A0 01 00FFFF 095638 00 04 00 00 00 00 00 - 21346
16:53:45.224 -> <- 18 1C 80 10 095638 00FFFF 02 09 01 0A 00 0B FF 0C FF 14 06 10 01 00 00 - 21481
16:53:45.284 -> -> 10 25 A0 01 00FFFF 095638 01 04 00 00 00 00 01 - 21518
16:53:45.425 -> <- 16 25 80 10 095638 00FFFF 02 08 00 20 6C 21 00 22 64 30 06 00 00 - 21649
16:53:45.747 -> -> 10 2E A0 01 00FFFF 095638 01 05 00 00 00 00 01 - 21966
16:53:45.840 -> <- 0A 2E 80 02 095638 00FFFF 00 - 22085
16:53:45.884 -> -> 0D 37 A0 01 00FFFF 095638 01 08 08 01 - 22120
16:53:45.978 -> <- 0A 37 80 02 095638 00FFFF 00 - 22237
16:53:46.024 -> -> 0B 40 A0 01 00FFFF 095638 01 06 - 22267
16:53:46.164 -> <- 0A 40 82 02 095638 00FFFF 00 - 22386
16:53:46.164 -> -> 0B 49 A0 01 00FFFF 095638 01 03 - 22419
16:53:46.304 -> <- 0E 49 80 10 095638 00FFFF 01 00 00 00 00 - 22540
16:53:49.835 -> ignore 0D D7 A6 10 37AE2E 255E33 06 01 00 00 - 26064
16:53:49.976 -> ignore 11 D7 A0 02 255E33 37AE2E 04 33 11 2B 17 0B FA 00 - 26195
16:53:50.083 -> ignore 19 D7 A6 03 37AE2E 255E33 0B 9F A1 6B C4 00 BF B3 04 5B 9A C5 A7 4E D3 D8 - 26329