Pages: [1]   Go Down
Author Topic: Arduino/Ethernet Shield HVAC System Monitor  (Read 3002 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am having an issue with my code for an automation system.  The goal of the project is to monitor the heating and air conditioning system, send emails if there are problems with it, log the data with ThingSpeak.com (or similar) and communicate with the thermostat to make changes as needed.  This system will be installed at several locations that are not nearby so the system needs to be reliable as I cant drive to each site to reset the arduino every day.

My hardware is the Uno, Ethernet Shield (v6 I think. It has the Uno "infinity" logo on it.  No mention of it on the hardware page), and a sparkfun proto shield.  I am using a MAX485 chip to convert the serial pins to RS485 for communication with the thermostat I have.  I have a shift register with 8 led’s acting as a display.  I also use a couple analog temp sensors and a few relays/switches for monitoring.

I have written my own code for monitoring the HVAC system and communicating with the thermostat.  The sketch works fine on its own.
I have modified example code from thingspeak to upload my data.  It also works fine on its own.
However when I combine the code into one sketch, the system hangs or constantly restarts whenever it reaches a certain point in the code (any time it tries to upload to thingspeak).

I do not have any pins that are conflicting. I have made sure that my wiring does not use pins 4, 10, 11, 12 or 13. 

I have attached the sketch as it was too big to insert as code here.

Just by copy/pasting the thingspeak functions and required variables out of the code and into a new sketch, it uploads properly to thingspeak.  So I know the code works.  Same for the rest of the code, if I remove the thingspeak functions, the sketch works perfectly

Any help in finding a solution would be great.

Thanks
Steven

* HVAC_Monitor.pde (29.65 KB - downloaded 32 times.)
Logged

'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3219
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

maybe you're exhausting your memory?
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

maybe you're exhausting your memory?
This. You have a large number of strings in the combined application - consider moving them to progmem.
Logged

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

Thanks for your replys.

The compliled sketch size is only about half of the availabe. 14950 bytes to be exact.

I only count 3 String variables.  Is this what you are refering to?  Or are you talking about all the text in the Serial.print's?
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 111
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which Thermostat are you using that you're communicating to the Arduino with??


I'm doing the same thing as you, except, with no thermostat.

My arduino is acting as the thermostat, using 2 analog temperature sensor, it reads in the average temp, display it on an LCD with a couple buttons so I can change the set temp.

A relay is used to control the HVAC. I measured the power on the AC control line, it's 30V AC to turn on the AC, FAN, or HEAT. Ofcourse the FAN has to be on first, then either of the other two. I used three relays to do this, and I always make sure the fan goes on about a minute before the AC or HEAT turns on, then stay on an extra minute after HEAT or AC shuts off. Also a 5 minute between the AC turning on/ and turning on again... apparently this was one of the feature on my old thermostat so I re-implemented it just to be safe.

In order to communicate with the internet and control, I used a PHP script, so if there's an issue, it emails to my Gmail using phpmailer script.
Besides that, I can control it directly through the web using HTML...

I'm moving away from PHP, so I can use Android App and remove my home server computer from the equation for less failure point. So I'm trying to serve the whole web page on the Arduino. I'll let you know how that work out.
Logged

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

Quote
Which Thermostat are you using that you're communicating to the Arduino with??
I am using the RCS TR16 from http://www.resconsys.com/
I wanted to keep a stand alone thermostat so that it works even if my system doesn't.  It’s just more reliable that way. 
It was a little difficult getting the communications to happen.  In order to transmit on the RS485 line via the MAX 485 chip, you have to pull a pin high and then to listen you have to pull it low. I was not getting a reply from the thermostat after sending a request for its status.  I had to use an o-scope to diagnose what was happening on the serial line. It turns out the pin was being pulled low before the serial data finished sending so I had to add a small delay after sending out the serial command. 
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your replys.

The compliled sketch size is only about half of the availabe. 14950 bytes to be exact.

I only count 3 String variables.  Is this what you are refering to?  Or are you talking about all the text in the Serial.print's?
All the text in the Serial.prints. The size of your sketch is not really relevant here - Arduino has very limited RAM - 2K if you're using an Uno and all of that text is stored there.
Logged

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

Thanks wildbill.

I have changed my code so almost all of the Serial.print text is in flash.  That has given me much better results.  It is now not hanging/restarting immediately and it ran for about 30 min before I reset it to make another change in the code.  It has still locked up a couple times on me since I made the main changes however. 

I will keep you updated.
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another potential issue is the use of the String class. Changing Strings can require dynamic memory allocation, with the accompanying possibility of fragmentation and eventually, a failure because there's no suitable chunk of memory to allocate. May not be your issue, but consider using char arrays instead.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It turns out the pin was being pulled low before the serial data finished sending so I had to add a small delay after sending out the serial command. 
That's because the function returns when the last character is written to the UART, but at that point it hasn't been transmitted. The delay will get you out of trouble but you really should test the appropriate UART register flag.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 928
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have had significant problems with the ethernet shield hanging up.  When I try to use it for an extended period, it will eventually fail to connect in some fashion or other and there is no easy way to get it working again.  Yes, I know all about the reset problem that they fixed with the new board, but that isn't what was happening.  The code or board would just fail to connect to whatever web service I was trying to reach.  I solved this by working up some code and hardware changes that senses when this happens and resets the ethernet board, if it still fails, I reset the arduino.  This requires logic to recover from a reset and storing some critical values in rom, but it works now.

I've used several of the boards and this is a consistent problem over all of them so I suspect code problems either in the library or the code on the 5100.  Other folk have experienced this same situation when they are trying to use the ethernet to store data over long periods of time.  Our advantage in this is that the arduino can reboot and pick up where it left off in a few seconds making such a thing possible.  There's the added advantage of my devices can survive a power failure just fine, hardly a hiccup.
Logged

Trying to keep my house under control http://www.desert-home.com/

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

Thanks for the continued responses.  
My code is fairly stable at the moment thanks to storing all my strings in flash.  But it will still freeze up, after a few hours of operating as expected, right after it connects to thing speak. Once it does freeze up, the only way for it to reestablish a connection to thing speak is by cycling power.  Pressing reset does not work.  Resetting will restart the code but I continually get my message saying that a connect to thing speak failed.

That's because the function returns when the last character is written to the UART, but at that point it hasn't been transmitted. The delay will get you out of trouble but you really should test the appropriate UART register flag.

______
Rob

How do I go about doing this?  I did a quick search but I didn't find anything very specific.

I have had significant problems with the ethernet shield hanging up.  When I try to use it for an extended period, it will eventually fail to connect in some fashion or other and there is no easy way to get it working again.  Yes, I know all about the reset problem that they fixed with the new board, but that isn't what was happening.  The code or board would just fail to connect to whatever web service I was trying to reach.  I solved this by working up some code and hardware changes that senses when this happens and resets the ethernet board, if it still fails, I reset the arduino.  This requires logic to recover from a reset and storing some critical values in rom, but it works now.

I've used several of the boards and this is a consistent problem over all of them so I suspect code problems either in the library or the code on the 5100.  Other folk have experienced this same situation when they are trying to use the ethernet to store data over long periods of time.  Our advantage in this is that the arduino can reboot and pick up where it left off in a few seconds making such a thing possible.  There's the added advantage of my devices can survive a power failure just fine, hardly a hiccup.
Thanks draythomp.  I actually came across your site while researching my issues.  I will likely have to do the same things you did.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How do I go about doing this?
Have a look in the UART section of the 328 data sheet.

Quote
• Bit 6 – TXCn: USART Transmit Complete
This flag bit is set when the entire frame in the Transmit Shift Register has been shifted out and
there are no new data currently present in the transmit buffer (UDRn). The TXCn Flag bit is automatically
cleared when a transmit complete interrupt is executed, or it can be cleared by writing
a one to its bit location. The TXCn Flag can generate a Transmit Complete interrupt (see
description of the TXCIEn bit).

You need to test the TXCn bit in the UCSRnA register.

Something like

Code:
// we just sent the last byte
while (UCSR0A & (1 << TXC0) == 0); // do nothing until bit set

There may be an issue if the serial library dicks with the flags but from what I can see it doesn't. However I believe the 1.0 IDE is interrupt driven with Tx and this may cause a problem because the flag will be reset by the ISR and your code will never see it. Cross that bridge when/if you get to it.
______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: