I am using mega with interrupt pins 2, 3 and 19.. The problem is when pin voltage (5V) change from 0 to 5V it triggered but when 5V to 0 sometimes it does not triggerred
I have tried debouncing as 5 to 1000microseconds but only 500microseconds is more stabil but it still cant catch the change sometimes... changing periods are not very short more than 3 seconds
I am using a latching button to change pin voltage
Serial.println("Initializing..........");
pinMode(arizaPin1,INPUT);
pinMode(arizaPin2,INPUT);
pinMode(arizaPin3,INPUT);
attachInterrupt(digitalPinToInterrupt(arizaPin1),
arizaflag1,
CHANGE);
attachInterrupt(digitalPinToInterrupt(arizaPin2),
arizaflag2,
CHANGE);
attachInterrupt(digitalPinToInterrupt(arizaPin3),
arizaflag3,
CHANGE);
delay(2000);
Welcome to the forum
Please post your full sketch
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum
So why are you using interrupts? You can simply poll the pins for changes.
Is this only for testing? It's not appropriate to use interrupts for buttons/switches.
It does not seem likely that these problems are related to the V1.x IDE, so I will move this topic for you.
do you have external pull-up or pull-down resistors?
can you share the circuit you are using?
That defeats the use of interrupts, which you shouldn't use for human-operated buttons/switches anyway.
Leo..
//Murat CANER Şubat 2024 GND teknik 800C GPS modülü ile database e 3 sinyal göneriyor mega TX3-RX3 GNDTeknik TX1-RX1 bağlı
// çalışan MEGA 3lÜ harici 5V ile interrupt programı Murat CANER 2024 OCAK
#include <String.h>
#define arizaPin1 2
#define arizaPin2 3
#define arizaPin3 19
volatile unsigned long lastTimebt_rl=millis();
unsigned long interval=0;
volatile bool flag1=false;
volatile bool flag2=false;
volatile bool flag3=false;
String apn="internet"; //çalışan değişken tanımlı son hali
String ariza_sin1;
String ariza_sin2;
String ariza_sin3;
String asansor_kodu="ÇYM7";
void setup()
{
Serial.begin(9600);
Serial3.begin(115200); // GPS shield baud rate
Serial.println("Initializing..........");
pinMode(arizaPin1,INPUT);
pinMode(arizaPin2,INPUT);
pinMode(arizaPin3,INPUT);
attachInterrupt(digitalPinToInterrupt(arizaPin1),
arizaflag1,
CHANGE);
attachInterrupt(digitalPinToInterrupt(arizaPin2),
arizaflag2,
CHANGE);
attachInterrupt(digitalPinToInterrupt(arizaPin3),
arizaflag3,
CHANGE);
delay(2000);
}
void loop()
{
if (Serial3.available()){ // if the shield has something to say
Serial.write(Serial3.read()); // display the output of the shield
}
else if (Serial.available()){ // if the shield has something to say
Serial3.write(Serial.read()); // display the input of the shield
}
if (flag1){
flag1=false;
ariza1();
SetupModule();
ariza_sin1="1";
SendData1();
}
if (flag2){
flag2=false;
ariza2();
SetupModule();
ariza_sin2="1";
SendData2();
}
if (flag3){
flag3=false;
ariza3();
SetupModule();
ariza_sin3="1";
SendData3();
}
delay(500);
}
void SetupModule(){
//if (Serial3.available())Serial.write(Serial3.read());
Serial3.println("AT");
delay(500);
Serial3.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
delay(2000);
ShowSerialData();
Serial3.println("AT+SAPBR=3,1,APN,"+apn);//APN
//Serial3.println("AT+SAPBR=3,1,\"APN\",+apn+");//APN
delay(2000);
ShowSerialData();
Serial3.println("AT+SAPBR=1,1");
delay(6000);
ShowSerialData();
Serial3.println("AT+SAPBR=2,1");
delay(3000);
ShowSerialData();
}
void ShowSerialData(){
while(Serial3.available()!=0)
Serial.write(Serial3.read());
delay(2000);
}
void SendData1(){
Serial3.println("AT+HTTPINIT");
delay(2000);
ShowSerialData();
Serial3.println("AT+HTTPPARA=\"CID\",1");
delay(1000);
ShowSerialData();
Serial3.println("AT+HTTPPARA=\"URL\",\"http://**.***.***.*/yurtkur/ariza1.php?ariza1="+ariza_sin1+"&asansor_kodu="+asansor_kodu+"\""); //Server address
delay(8000);
ShowSerialData();
Serial3.println("AT+HTTPACTION=0");
delay(6000);
ShowSerialData();
Serial3.println("AT+HTTPREAD");
delay(2000);
ShowSerialData();
Serial3.println("AT+HTTPTERM");
delay(2000);
ShowSerialData;
Serial3.println("AT+SAPBR=0,1");
delay(1000);
ShowSerialData();
}
void SendData2(){
Serial3.println("AT+HTTPINIT");
delay(2000);
ShowSerialData();
Serial3.println("AT+HTTPPARA=\"CID\",1");
delay(1000);
ShowSerialData();
Serial3.println("AT+HTTPPARA=\"URL\",\"http://**.***.***.*/yurtkur/ariza2.php?ariza2="+ariza_sin2+"&asansor_kodu="+asansor_kodu+"\""); //Server address
delay(8000);
ShowSerialData();
Serial3.println("AT+HTTPACTION=0");
delay(6000);
ShowSerialData();
Serial3.println("AT+HTTPREAD");
delay(2000);
ShowSerialData();
Serial3.println("AT+HTTPTERM");
delay(2000);
ShowSerialData;
Serial3.println("AT+SAPBR=0,1");
delay(1000);
ShowSerialData();
}
void SendData3(){
Serial3.println("AT+HTTPINIT");
delay(2000);
ShowSerialData();
Serial3.println("AT+HTTPPARA=\"CID\",1");
delay(1000);
ShowSerialData();
Serial3.println("AT+HTTPPARA=\"URL\",\"http://**.***.***.*/yurtkur/ariza3.php?ariza3="+ariza_sin3+"&asansor_kodu="+asansor_kodu+"\""); //Server address
delay(8000);
ShowSerialData();
Serial3.println("AT+HTTPACTION=0");
delay(6000);
ShowSerialData();
Serial3.println("AT+HTTPREAD");
delay(2000);
ShowSerialData();
Serial3.println("AT+HTTPTERM");
delay(2000);
ShowSerialData;
Serial3.println("AT+SAPBR=0,1");
delay(1000);
ShowSerialData();
}
void ariza1()
{
Serial.println("Arıza 1 sinyali");
}
void ariza2()
{
Serial.println("Arıza 2 sinyali");
}
void ariza3()
{
Serial.println("Arıza 3 sinyali");
}
void arizaflag1()
{
unsigned long timeNow=millis();
if (timeNow-lastTimebt_rl>interval and digitalRead(arizaPin1)){
lastTimebt_rl=timeNow;
flag1=!flag1;
}
}
void arizaflag2()
{
unsigned long timeNow=millis();
if (timeNow-lastTimebt_rl>interval and digitalRead(arizaPin2)){
lastTimebt_rl=timeNow;
flag2=!flag2;
}
}
void arizaflag3()
{
unsigned long timeNow=millis();
if (timeNow-lastTimebt_rl>interval and digitalRead(arizaPin3)){
lastTimebt_rl=timeNow;
flag3=!flag3;
}
}
If I try without interrupt in loop code run continuously and in setup part it runs only one time
I need to send fault information when it occured
The button represents voltage signal when fault detected..
loop() is supposed to run continuously. setup() is supposed to run one time. This does not indicate a problem. Please describe your problem more accurately.
If you test for the pin to be HIGH, why do you track changes, just track RISING and you’ll be sure the pin is HIGH in the ISR ? Why do you invert the flag? you should just set it.
In the loop you should use a critical section when you check and reset the flag.
Not sure you really need interrupts at all unless you don’t want to miss a flag that would be set whilst handling something else that is long
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.