Go Down

Topic: Reading the state of a squere wave pin and Multitasking (Read 412 times) previous topic - next topic

Robin2

Post the complete program that uses a FALLING (or RISING - whichever you consider to be the most sensible) interrupt.

"The loop stucks" is not very helpful for diagnostic purposes.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

wvmarle

Yes, because as i said and tested, not using one will result in a time between the pulses of even 1200ms because of other functions from my skatch (like lcd print, serial print, maths, more)
This is one of the parts that I don't really get from you. What could you possibly be doing on a car control Arduino that takes such a long time to complete? LCD and Serial take mere milliseconds, if that much. Maths, well hard to think of anything an Arduino can do with it's tiny memory that would take so long. That leaves the "more" part.

You're also complaining that a 555 timer would take 10 mA of current (wonder which version you're looking at - the common NE555 takes about 3 mA, the TS555CN only 100 uA), but you don't have a problem with an Arduino that's working hard (thus taking well over that 10 mA) plus an LCD plus something that's on the Serial. Sounds like easily 200-300 mA there.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

prologikus

#17
Aug 17, 2017, 12:40 pm Last Edit: Aug 17, 2017, 01:10 pm by prologikus
Post the complete program that uses a FALLING (or RISING - whichever you consider to be the most sensible) interrupt.

"The loop stucks" is not very helpful for diagnostic purposes.

...R
Seems like as soon as i plug in the ground pin to an interrupt pin the arduino is not working anymore(even if i don't attach the interrupt)
And if i restart it it got stuck at "lcd.begin"
It's very strange because i already have 2 pins connected to interrupt pins
Edit: if i remove lcd begin from the setup, then i can connect any pins to interrupt pins and nothing happends
Edit2: I only connected my lane on INT0 and INT1, pin 20 and 21, but i forget i also have 3 as INT5 , (the rest of (INT2,3,4 was already in use)) so i connected it there and now the arduino doens't stuck anymore, now i have to redo all my tests to see if now the code is working...

Still... Why my INT0 and INT1 stuck my arduino program is the LCD is in use?

I just posted my code here, it's very long however, because it's all my code
https://gist.github.com/prologikus/4bd0abb483aae43b00ab3328dd1371fa
This is one of the parts that I don't really get from you. What could you possibly be doing on a car control Arduino that takes such a long time to complete? LCD and Serial take mere milliseconds, if that much. Maths, well hard to think of anything an Arduino can do with it's tiny memory that would take so long. That leaves the "more" part.

You're also complaining that a 555 timer would take 10 mA of current (wonder which version you're looking at - the common NE555 takes about 3 mA, the TS555CN only 100 uA), but you don't have a problem with an Arduino that's working hard (thus taking well over that 10 mA) plus an LCD plus something that's on the Serial. Sounds like easily 200-300 mA there.
In the end i think i'll buy TS555CN and use it as pulse extender, seems to be a very simple and effective solution!

about the consumption it's simple, the lcd go to sleep, the arduino do this too, and the serial is only for debuging

Robin2

I just posted my code here, it's very long however, because it's all my code
Where, in all that code, is the ISR that responds to the RISING or FALLING signal? My text editor could not find either word in it.

When you have a programming problem it is much better to work it out in a short program that only deals with that single problem.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

prologikus

Where, in all that code, is the ISR that responds to the RISING or FALLING signal? My text editor could not find either word in it.

When you have a programming problem it is much better to work it out in a short program that only deals with that single problem.

...R
Ok, i solved it by changing the pin from 20 or 21 (arduino mega) to pin 3
Seems like those 2 pins are not working when i use the LCD, i don't know why..

In the end i used this code:
Code: [Select]

//in the setup
attachInterrupt(digitalPinToInterrupt(doorlockPin), doorlockPin_change, RISING);


//ISR
void doorlockPin_change()
{
  doorlock_temp = true;
}


//in the loop
  if ((millis() - last_millis_b) >= 150) {
    last_millis_b = millis();
    if (doorlock_step == 0) {           //if this is the first step
      doorlock_temp = false;            //drop the bait
      doorlock_step++;                  //set this step as done
    }
    else {                              //if this is the second step
      if (doorlock_temp == false) {     //if the bait wasn't bitted
        if (doorlock != true) {
          doorlock = true;              //this means the car is locked
          DEBUG_PRINT("Doorlock:");
          DEBUG_PRINT(doorlock);
        }
      }
      else {
        if (doorlock != false) {
          doorlock = false;
          DEBUG_PRINT("Doorlock:");
          DEBUG_PRINT(doorlock);
        }
      }
      doorlock_step = 0;
    }
  }


Don't know if this is the best way from all the ways that i tried when i connected it to the "broken" pins but for now is working..

Still, i'm very courios why those 2 pins are not working when i use the LCD :(, i might need them too

PaulS

Quote
Still, i'm very courios why those 2 pins are not working when i use the LCD :(, i might need them too
Can you tell me in which reply you posted ALL of your code?
Can you tell me in which reply you mentioned using an LCD (not including the last one)?
The art of getting good answers lies in asking good questions.

prologikus

Can you tell me in which reply you posted ALL of your code?
Can you tell me in which reply you mentioned using an LCD (not including the last one)?
reply #17 the code
https://gist.github.com/prologikus/4bd0abb483aae43b00ab3328dd1371fa

and i mentioned using a LCD even in the first post

cattledog

Quote
Ok, i solved it by changing the pin from 20 or 21 (arduino mega) to pin 3
Seems like those 2 pins are not working when i use the LCD, i don't know why..
Pins 20 and 21 are the i2c bus pins on the Mega and are used by the lcd.

You mentioned the word "lcd" in the first post, but only in code 17 posts later showed it was an i2c lcd.
We do not have crystal balls, and you have created much of your own problem with your snippet postings.

prologikus

Pins 20 and 21 are the i2c bus pins on the Mega and are used by the lcd.

You mentioned the word "lcd" in the first post, but only in code 17 posts later showed it was an i2c lcd.
We do not have crystal balls, and you have created much of your own problem with your snippet postings.
I thought there was 2 sets of scl sda on arduino mega but seems like they are the same.
:d :d :d

Go Up