Pages: [1]   Go Down
Author Topic: Millis as timer interferes with IR remote. Alternatives or corrections needed.  (Read 631 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello! I have a project I'm working on and I hope someone will be able to offer some guidance.

The primary purpose of my project works just fine and isn't relevant, so my pasted code may appear lacking - I've removed all distraction from the code.

I am using an IR remote for the bulk of the project and I'm trying to add a temperature and humidity reading from a DHT22 (and it seems to work just fine), the problem is that I want it to poll the sensor every 2 seconds(every 5 or 10 seconds in the final project) and serial.print out the results... but using millis interferes with the IR remote. The project without the dht-22 portions works just fine. The dht22 portions work fine. They just don't work well together.

I'm looking for a way to have the DHT22 polled every interval without interfering with the infrared receiver. When using millis I have to press a button on the remote about 10 times before it's recognized. Without adding this sensor/code, the IR is received just fine, first press, every time.

Hopefully I've explained this clearly, if not, let me know and I'll try and clarify.

Any assistance is greatly appreciated, and I hope to be able to return the favor in the future. Thanks in advance!



Code:
void loop() {
 
  //need millis counter for temp/humidity reading
  // 2000 millis minimum(2 sec) between readings
  //temptime = current millis
  //milliCount is the last temptime that sensor was polled
 temptime = millis();
 Serial.print("Elapsed Millis: ");//for debugging
 Serial.println(temptime);//for debugging
 temptime = temptime - milliCount;
  if (temptime > 2000) {//if it's been 2 sec then get temp/humidity readings
    milliCount = temptime;//set set millicount to current time
  gettemp();//function for DHT22 temp and humidity readings
  }
 
  if (irrecv.decode(&results)) {
   //stuff to do when buttons on remote are pressed
    irrecv.resume(); // Receive the next value
  }
  delay(10);
 
}

Logged

"Politics: the distract, divide, and conquer game. It is football. It is the roman circus. Wake the hell up."

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 197
Posts: 12744
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've removed all distraction from the code.

Incorrect.  What you have done is removed all hope of helping you.  Post the entire sketch.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nevermind, I'll figure it out on my own. Thank you for your helpful reply.
Logged

"Politics: the distract, divide, and conquer game. It is football. It is the roman circus. Wake the hell up."

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 197
Posts: 12744
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for your helpful reply.

You are welcome.

Quote
Nevermind, I'll figure it out on my own.

Posting your sketch is just too much effort, eh?

In any case, I hope you get the problem resolved.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Posting your sketch is just too much effort, eh?

In any case, I hope you get the problem resolved.


No, not too much effort, just unwilling to reveal every detail of the project right now. I've found help on another website and was able to find a solution to the problem - with identical code posted. Imagine that... all hope wasn't lost, just the hope for assistance from the actual arduino forum. After many many months of reading the forums here, I admit that I'm not shocked. So long.
« Last Edit: July 17, 2013, 09:35:44 pm by Bt7cs » Logged

"Politics: the distract, divide, and conquer game. It is football. It is the roman circus. Wake the hell up."

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No, not too much effort, just unwilling to reveal every detail of the project right now.

All you had to do was post a sketch that reproduces the problem. Not reveal all your secrets. Often people post their whole sketch. Some isolate down the problem to a few functions and post that. We aren't mind readers here, perhaps the other site employed them all.

Code:
sketch_jul18e.ino: In function 'void loop()':
sketch_jul18e:7: error: 'temptime' was not declared in this scope
sketch_jul18e:10: error: 'milliCount' was not declared in this scope
sketch_jul18e:13: error: 'gettemp' was not declared in this scope
sketch_jul18e:16: error: 'irrecv' was not declared in this scope
sketch_jul18e:16: error: 'results' was not declared in this scope

Without knowing the data types, it's just guesswork, sorry.

Quote
After many many months of reading the forums here, I admit that I'm not shocked.

Another troll. Every day we get thanks for helping solve problems, and solve them quickly at that. Then we get people who claim the forum is hopeless, without a shred of evidence.

Quote
I've found help on another website and was able to find a solution to the problem - with identical code posted.

What other site? What was the solution? Or aren't you telling?

Quote
So long.

See ya.
Logged

Estonia
Offline Offline
Full Member
***
Karma: 1
Posts: 180
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually, if you could post what the issue was and how you solved it, it might be helpful for me. I am having issues with a RF receiver and am also using the millis() function as a timer. While I don't think that is my issue it could actually be something useful for me
Logged

Pages: [1]   Go Up
Jump to: