J’ai fait une config toute simple sur le pin 2 de l’arduino
J’ai compris la génération du sketch ainsi que la configuration des pin après le téléversement.
J’ai l’impression que l’état bagotte un peu malgré la présence de la résistance interne de tirage.
J’ai tenté un montage Pull-Up ou Pull-Down avec une résistance de 10k supplémentaire mais cela ne change pas grand chose on dirait.
Par contre je constate qu’autant quand j’ouvre le capteur le changement d’état est quasi instantané mais quand je ferme le capteur cela peut prendre de 2 secondes à 50 secondes pour changer d’état !!
Là je ne comprends pas trop ce qu’il se passe.
On vente les biens faits de l’arduino de son aspect filaire et fiable mais là je trouve ça moyen moyen
Il doit y a voir un truc que je ne fais pas comme il faut, mais quoi je ne sais pas du tout et j’en appelle à votre aide.
Mon arduino est un officiel, le shield ethernet aussi.
Par contre j’ai fait le test avec un relais et cela fonctionne plutôt bien là par contre
/**
*******************************
** The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2017 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*
* DESCRIPTION
*
* détecteur de contact par ils sur pile
* détection sur interruption
* une émission toutes les 24 heures si pas de détection
* transmission de la tension batterie
* gestion ack
*/
// Enable debug prints
// #define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_RF24
//#define MY_RF24_PA_LEVEL RF24_PA_MAX
//#define MY_RF24_PA_LEVEL RF24_PA_HIGH
#define MY_RF24_PA_LEVEL RF24_PA_LOW
//#define MY_RF24_PA_LEVEL RF24_PA_MIN
#define MY_TRANSPORT_WAIT_READY_MS 5000 // au cas ou gateway hs saute void presentation
//#define MY_TRANSPORT_SANITY_CHECK
#define MY_TRANSPORT_MAX_TX_FAILURES 1
#include <MySensors.h>
bool debug = false; // mettre à 1 pour affichage sur moniteur ******************************************************************************************************
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
float batt ; // batterie
bool ack = false ; // pour réception
bool controle = false;
bool tripped = false;
bool onetime = true;
int reveil;
int triggered = 0;
unsigned long SLEEP_TIME = 86400000; // Sleep time 24x60x60x1000 soit 24 heures
#define DIGITAL_INPUT_SENSOR 2 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define reset_node_id 3
// Initialize motion message
MyMessage msgMotion(1,V_TRIPPED);
MyMessage msgBattery(2,V_VOLTAGE); // tension de batterie
void setup()
{
pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the ils sensor digital pin as input
pinMode(reset_node_id, INPUT_PULLUP); // set digital pin as input
// use the 1.1 V internal reference
#if defined(__AVR_ATmega2560__)
analogReference(INTERNAL1V1);
#else
analogReference(INTERNAL);
#endif
// regarde si reset node id demandé
if (!digitalRead(reset_node_id)) { // reset node id demandé
for (uint16_t i=0; i<EEPROM_LOCAL_CONFIG_ADDRESS; i++) {
hwWriteConfig(i,0xFF);
}
sleep(3600000);
}
}
void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Contact", "2.0");
wait(200);
present(1, S_DOOR); // capteur ils
wait(200);
present(2, S_MULTIMETER); // batterie
wait(200);
}
//************************************************************************************************************
void loop()
{
wait(50);
tripped = digitalRead(DIGITAL_INPUT_SENSOR); //== LOW; // lecture du capteur ils
if (debug) { Serial.print("Motion :"); Serial.println(tripped); }
for ( int i = 0 ; i < 3 ; i++ ) { // 3 tentatives
send(msgMotion.set(tripped?"1":"0"),true); // Send tripped value to gw avec demmande ack
if (reception_ack()) {
batterie(); // mesure la tension de batterie
send(msgBattery.set(batt,2)); // sans demande ack
break ; // sortie de boucle for
}
}
if (!ack) { // deuxième tentative apres sommeil de 30secondes
sleep(30000); // en sommeil pour 30secondes
for ( int i = 0 ; i < 3 ; i++ ) { // 3 tentatives
send(msgMotion.set(tripped?"1":"0"),true); // Send tripped value to gw avec demmande ack
if (reception_ack()) {
batterie(); // mesure la tension de batterie
send(msgBattery.set(batt,2)); // sans demande ack
break ; // sortie de boucle for
}
}
}
// Sleep until interrupt comes in on ils sensor. Send update every SLEEP_TIME hours.
if (debug) { Serial.println("Sleep......24heures."); Serial.println(" "); }
reveil = sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
if (reveil == triggered) { // réveil par ouverture ou fermeture fenetre
if (debug) { Serial.println("Sleep......30secondes."); }
sleep(30000); // en sommeil pour 30s pour attendre fin de manipulation fenetre
}
} // fin loop
//**************************************************************************************************************
/* ======================================================================
Function: reception_ack
// attend la réception
// sortie au bout de 2 secondes si pas de reception ack
====================================================================== */
bool reception_ack () {
unsigned long previousMillis = 0 ;
unsigned long interval = 2000 ; // 2 secondes
previousMillis = millis() ;
ack = false ;
while (! ack) {
wait(1) ;
if (millis() - previousMillis >= interval) { // regarde si timeout
return false ; // sortie sur timeout
}
}
if (debug) { Serial.print("Retournement ack :"); Serial.println((millis() - previousMillis)); }
return true ;
}
/* ======================================================================
Function: batterie
// mesure la tension de batterie
====================================================================== */
void batterie ()
{
int sensorValue = analogRead(BATTERY_SENSE_PIN); // get the battery Voltage
// 1M, 300K divider across battery and using internal ADC ref of 1.1V
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
// ((1e6+470e3)/470e3)*1.1 = Vmax = 3.4331210 Volts
// 3.4331210/1023 = Volts per bit = 0.003355934
int batteryPcnt = sensorValue / 10;
batt = sensorValue * 0.003355934 ;
//int batt = sensorValue * 0.004664342 * 100;
if (debug == 1) {
Serial.print("battery :"); Serial.println(batt);
}
}
// -----------------------------------------------------------------------------
void receive(const MyMessage &message)
{
//We only expect one type of message from controller. But we better check anyway.
if (message.isAck()) {
ack = true;
//Serial.print("ack :"); Serial.println(ack);
}
//Serial.print("type :"); Serial.println(message.type);
//Serial.print("sensor :"); Serial.println(message.sensor);
//Serial.print("getbool :"); Serial.println(message.getBool());
}
Merci @jlb je vais regarder ceci
Mais du coup tu as ajouté ton code dans la partie prévue dans le code jeedouino c’est ça ?
@olive ok sur le phénomène physique dont j’avais quelques souvenirs d’école mais là je suis incapable à la lecture de dire : la j’ai la solution
Je vais le lancer dans la recherche
Ensuite je comprends mais les temps sont quand même hyper long dans le sketch d’origine généré par le plugin
Bonsoir,
Pour voir l’état de tes entrées à chaque ‹ tour › de programme tu peux utiliser la console de debug de arduino, en ajoutant : Serial.println(la valeur à surveiller);
Ça te permettra de localiser ton pb de fermeture ou d’ouverture du contact.