Guide: Arduino based LED controller for Current Satellite LED+ - Page 21
Planted Tank Forums
Your Tanks Image Hosting *Tank Tracker * Plant Profiles Fish Profiles Planted Tank Guide Photo Gallery Articles

Go Back   The Planted Tank Forum > Specific Aspects of a Planted Tank > DIY


Reply
 
Thread Tools Display Modes
Old 08-18-2013, 02:39 AM   #301
Dahammer
Algae Grower
 
PTrader: (0/0%)
Join Date: Oct 2010
Location: Mississippi
Posts: 118
Default

How often are you wanting to update the temperature readings? I noticed that you have 2 calls to lcd.begin() in setup, only one is needed. You can also call sensors.getTempF instead of sensors.getTempC if you want the temp in Fahrenheit. But getTempF just calls toFahrenheit which is what you are doing as well. Haha!

You can also add the special character degree symbol using createChar function, which is part of the LiquidCrystal library.

Edit:
Actually, it may already be included, try this or check the datasheet for your LCD:

lcd.print((char)223));

Last edited by Dahammer; 08-18-2013 at 03:32 AM.. Reason: Added comment
Dahammer is offline   Reply With Quote
Sponsored Links
Advertisement
 
Old 08-18-2013, 02:56 AM   #302
mistergreen
No more Bow ties
 
mistergreen's Avatar
 
PTrader: (13/100%)
Join Date: Dec 2006
Location: Cincinnati
Posts: 13,989
Default

hmmm, actually since you guys are using the timeAlarms library, use that instead of millis()
It's neater.

Code:
Alarm.timerRepeat(60, temperaturePrint);
//Create a timer that will call a function every at an interval of "seconds".
mistergreen is online now   Reply With Quote
Old 08-18-2013, 03:08 AM   #303
Dahammer
Algae Grower
 
PTrader: (0/0%)
Join Date: Oct 2010
Location: Mississippi
Posts: 118
Default

Quote:
Originally Posted by mistergreen View Post
hmmm, actually since you guys are using the timeAlarms library, use that instead of millis()
It's neater.

Code:
Alarm.timerRepeat(60, temperaturePrint);
//Create a timer that will call a function every at an interval of "seconds".
Yeah that's what I'd do also and update it every how often you like. He'd just need to move his print code to the printTemperature and modify it so it didn't require passing the device address or use another function and pass them with it.
Dahammer is offline   Reply With Quote
Old 08-18-2013, 04:52 AM   #304
Caver
Algae Grower
 
PTrader: (0/0%)
Join Date: Jun 2013
Location: Austin TX
Posts: 56
Default

Quote:
Originally Posted by Dahammer View Post
Actually, it may already be included, try this or check the datasheet for your LCD:

lcd.print((char)223));
Your above trick works to print the degree symbol, but I had to remove one of the close parenthesis to get it to compile.

Thanks for all the ideas. I'm going to have to study to figure out how to implement them.

This was my very clumsy beginner attempt at programming the Arduino for my specific application. I haven't done any programming in literally decades...so I'm going to make a lot of very basic mistakes.

For this sketch I literally copied pieces of a tutorial sketch for an indoor/outdoor thermometer and pasted the pieces into v4 where I thought they needed to go. I'm sure there's all kinds of 'wrong' stuff!

Some things I've noticed with my controller running on the bench tonight...Every so often, right after a code is sent, the temperature goes to 3 decimal places. I thought I had it set for 2 by setting the sensors to 9 bit resolution. Obviously I'm missing something. Actually, I'd be satisfied with 1 decimal place for the temp.

Oh well...almost bedtime. Maybe some of this coding stuff will make more sense to me after I get some sleep and a couple of cups of coffee in the morning.
__________________
--
Tom
Caver is offline   Reply With Quote
Old 08-18-2013, 03:03 PM   #305
Dahammer
Algae Grower
 
PTrader: (0/0%)
Join Date: Oct 2010
Location: Mississippi
Posts: 118
Default

Oops, sorry. Yeah, 1 too many parenthesis.

What sensor do you have? Check out the calculateTemperature function in DallasTemperature.cpp. Looking at the datasheet, I'm guessing you have a DS18S20 based sensor, since it allows for more than 1 sensor on the same wire. For that sensor, the code in calculateTemperature function calculates an extended resolution regardless of what you set it too.

Last edited by Dahammer; 08-18-2013 at 03:24 PM.. Reason: Added comment
Dahammer is offline   Reply With Quote
Old 08-18-2013, 03:16 PM   #306
Caver
Algae Grower
 
PTrader: (0/0%)
Join Date: Jun 2013
Location: Austin TX
Posts: 56
Default

Morning DaHammer.

I'm using the DS18b20 sensors. I got some already on a cable and waterproofed.

The ends are a stainless steel cap. Hope that's ok for Red Cherry Shrimp...
__________________
--
Tom
Caver is offline   Reply With Quote
Old 08-18-2013, 03:59 PM   #307
Dahammer
Algae Grower
 
PTrader: (0/0%)
Join Date: Oct 2010
Location: Mississippi
Posts: 118
Default

Hmm. Then 9 bit resolution should yield a temperature to the nearest 0.5 degree.
Dahammer is offline   Reply With Quote
Old 08-18-2013, 04:19 PM   #308
Caver
Algae Grower
 
PTrader: (0/0%)
Join Date: Jun 2013
Location: Austin TX
Posts: 56
Default

Yeah,

The temp reading to 2 decimal places is a pretty minor thing.

I'm studying the coding for reading the sensors so I can understand the delays and your suggestions for using millis. If I'm understanding what I'm reading correctly...the sensors need approx. 750 mS to complete a read and transfer data.

I just want to clean up the code so the system doesn't barf on me after running a few hours/days...

Of course if someone on here wants to do the thermometer thing and knows how to clean it up, I have no qualms with riding coat tails...
__________________
--
Tom
Caver is offline   Reply With Quote
Old 08-18-2013, 04:52 PM   #309
mistergreen
No more Bow ties
 
mistergreen's Avatar
 
PTrader: (13/100%)
Join Date: Dec 2006
Location: Cincinnati
Posts: 13,989
Default

Can't you limit the decimal places like this?

print(val,format);
lcd.print(4.3224,1) -> 4.3
mistergreen is online now   Reply With Quote
Old 08-18-2013, 08:03 PM   #310
Caver
Algae Grower
 
PTrader: (0/0%)
Join Date: Jun 2013
Location: Austin TX
Posts: 56
Default

Boy...

That Alarm.timerRepeat is kicking my butt!

I've read several tutorials on it and I keep getting compiler errors.

I'm going to keep playing with it and reading while I finish laundry. I'll figure it out eventually...
__________________
--
Tom
Caver is offline   Reply With Quote
Old 08-18-2013, 08:46 PM   #311
mistergreen
No more Bow ties
 
mistergreen's Avatar
 
PTrader: (13/100%)
Join Date: Dec 2006
Location: Cincinnati
Posts: 13,989
Default

what's your code and what error message are you getting?
mistergreen is online now   Reply With Quote
Old 08-18-2013, 09:18 PM   #312
Caver
Algae Grower
 
PTrader: (0/0%)
Join Date: Jun 2013
Location: Austin TX
Posts: 56
Default

Quote:
Originally Posted by mistergreen View Post
what's your code and what error message are you getting?
I'm not sure how to even begin mistergreen...

Basically I'm trying to clean up my sketch from post #296, where I patched in code for two DS18B20 thermometers to the light controller.

There were some comments that the 1 second delay in the loop function for the sensors would cause problems, so I'm trying to do something other than the standard delay that stops the whole device. From what I've read on the sensors, they need a delay in polling or they'll get errors.

You and DaHammer suggested the Alarm.timerRepeat and moving the print code...etc. I've tried multiple iterations based on the tutorials I've read and get many different errors.

I suspect it has to do with the passing of the sensor device addresses and I'm probably messing up moving the print and sensor address code.

I'm so new at this coding process, I'm probably overlooking something very basic. I can build hardware all day long, but software is much more difficult for me.
__________________
--
Tom
Caver is offline   Reply With Quote
Old 08-18-2013, 09:29 PM   #313
Dahammer
Algae Grower
 
PTrader: (0/0%)
Join Date: Oct 2010
Location: Mississippi
Posts: 118
Default

Quote:
Originally Posted by Caver View Post
I'm not sure how to even begin mistergreen...

Basically I'm trying to clean up my sketch from post #296, where I patched in code for two DS18B20 thermometers to the light controller.

There were some comments that the 1 second delay in the loop function for the sensors would cause problems, so I'm trying to do something other than the standard delay that stops the whole device. From what I've read on the sensors, they need a delay in polling or they'll get errors.

You and DaHammer suggested the Alarm.timerRepeat and moving the print code...etc. I've tried multiple iterations based on the tutorials I've read and get many different errors.

I suspect it has to do with the passing of the sensor device addresses and I'm probably messing up moving the print and sensor address code.

I'm so new at this coding process, I'm probably overlooking something very basic. I can build hardware all day long, but software is much more difficult for me.
Post the code and we will help. Basically, what you need to do is remove the code you put into the loop() function, create a function to handle your alarm events, and then set an alarm to call your new function ever how often you want. If it were me, I'd think an updated temp every hour or so would be sufficient.

You shouldn't need a delay as long as you don't query the temp sensors for a temp every second or so.

Last edited by Dahammer; 08-18-2013 at 10:55 PM.. Reason: typo
Dahammer is offline   Reply With Quote
Old 08-18-2013, 09:48 PM   #314
Dahammer
Algae Grower
 
PTrader: (0/0%)
Join Date: Oct 2010
Location: Mississippi
Posts: 118
Default

Try this:

Up at the top, redefine your sensor addresses to this (makes more sense since you're not really doing inside & outside):

Code:
DeviceAddress thermometer_1 = { 0x28, 0x98, 0x82, 0xA8, 0x04, 0x00, 0x00, 0x6D }; //Red
DeviceAddress thermometer_2 = { 0x28, 0xA6, 0x33, 0xA8, 0x04, 0x00, 0x00, 0x11 }; //blue
Changing the names will also require changing the setResolution calls in Setup():
Code:
  sensors.setResolution(thermometer_1, 9);
  sensors.setResolution(thermometer_2, 9);
Then add this following code to the SetAlarms() function, doesn't matter where you add it. You can also change the alarm frequency if you like. It's second based, but alarming every second would probably cause problems.
Code:
  Alarm.timerRepeat(1800, PrintTemp);  // Print temps every 30 minutes
  PrintTemp(); // Display initial temps
Then add the following function somewhere:
Code:
void PrintTemp()
{
  float tempC = sensors.getTempC(thermometer_1);
  lcd.setCursor(0,2);
  lcd.print("Tank: 1 ");
  lcd.print(DallasTemperature::toFahrenheit(tempC), 1);
  lcd.print((char)223);
  
  tempC = sensors.getTempC(thermometer_2);
  lcd.setCursor(0,3);
  lcd.print("Tank 2: ");
  lcd.print(DallasTemperature::toFahrenheit(tempC), 1);
  lcd.print((char)223);
}
Then remove the code you put in the loop() function, as well the printTemperature function that you added. You could also add code to the TestCodes() function so that you could initiate a test from the serial terminal.

Code:
void TestCodes (int cmd)
{
  // Handles commands sent in from the serial monitor
  if (cmd >= 1 && cmd <= 32)
    { 
      // cmd must be 1 - 32
      SendCode(cmd-1, 1);
    }
    else if (cmd == 33)
    {
    	PrintTemp();  // Send 33 to test temp sensors
    }
    else { printf_P(PSTR("Invalid Choice\n")); }
}

Last edited by Dahammer; 08-19-2013 at 02:23 AM.. Reason: Added code
Dahammer is offline   Reply With Quote
Old 08-18-2013, 11:19 PM   #315
Caver
Algae Grower
 
PTrader: (0/0%)
Join Date: Jun 2013
Location: Austin TX
Posts: 56
Default

Let me play with it for a bit and when I get my best guess I'll post something.

Right now I've tried 5-6 variations and I don't have any idea which is closer and I get different and complex error messages each time.

One specific question...the example sketch in the TimeAlarms library shows the "Alarm.timerRepeat(15, Repeats);" statement going in "void setup()".

I'm assuming I should be able to add the same statement to the setup section of the controller code as in the above example and pull the section of code dealing with polling and printing the sensors currently in "void loop()" and creating another function (for the sake of simplicity) called "void Repeats()".

Also as I understand it, I can change the 15 to any value down to 1. Can 'Repeats' be changed to another function name?

The section of code I'm pulling out of the loop is

delay(1000) // Supposedly this is what needs to be pulled out of the loop
sensors.requestTemperatures();
lcd.setCursor(0,2);
lcd.print("Tank 1: ");
printTemperature(insideThermometer);
lcd.print((char)223);
lcd.setCursor(0,3);
lcd.print("Tank 2: ");
printTemperature(outsideThermometer);
lcd.print((char)223);

I'm adding it back in outside the loop as...

void Repeats();
{
sensors.requestTemperatures();
lcd.setCursor(0,2);
lcd.print("Tank 1: ");
printTemperature(insideThermometer);
lcd.print((char)223);
lcd.setCursor(0,3);
lcd.print("Tank 2: ");
printTemperature(outsideThermometer);
lcd.print((char)223);
}

I'm thinking there's something in there that the Alarm.timerRepeat can't process. It doesn't seem to matter where I put it. I get different error messages every time.

That's basically what I've been trying.

As for polling frequency...I'd like something at least every few seconds so it would react quickly to changing conditions. Sure...most of the time it wouldn't be necessary, but the nerd in me wants 'realtime' data...

I see DaHammer has responded with some code for me to try. I just tried it, but I got some errors. I probably made a typo or something. I'm going to get something to eat and play with it some more.

Thanks for all the help. I don't mean to distract from the original direction of the thread for my customizations. If we get too far out in left field, just say so. This is a really cool gadget even without the thermometers...
__________________
--
Tom

Last edited by Caver; 08-18-2013 at 11:20 PM.. Reason: corrected typo
Caver is offline   Reply With Quote
Reply

Tags
arduino, automation, current led+, diy, light controller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:16 PM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright Planted Tank LLC 2012