I could some help on my aquarium and room controller project. :)
Hi everyone and welcome!
Rather than open up a new thread for each and every of my sure to be many upcoming questions I figured I would save the mods and anyone trying to follow my progress a headache and start a single thread for the whole project. I plan to post all my questions, pictures, schematics and code for everyone to see and learn from right here. With that said I am very open to any comments and ideas that anyone in this great community might have to offer. I hope people can read this thread to learn and be inspired like I was from some other very interesting threads then grabs some of the great products from Parallax and bring their dream projects to life [noparse]:)[/noparse]
Now on to some details of my project!
I hope to be placing my order tomorrow for some parts to kick start my first phase of the project. I have been doing a little research and have selected some sensors I wish to start working with my Basic Stamp 2 and Board of Education. I will be starting with and AD592 Temperature Probe to monitor the water temps and a Sensirion Temperature/Humidity Sensor to monitor the room in my basement where the aquarium will be located. I would also like to add some relays to the design in order control some basic 120v items such as a heater for the water, a pump to manage water levels, the tank lighting and maybe even an auto feeder somewhere down the road.
Question #01:
I would like to start my relay system with the first task of managing the lighting for the aquarium. I understand the basics of this task is more or less just coding a function to turn on a pin on and trip a larger relay to turn the lights on and off, but I would like to have this happen on a schedule which would require a clock build into the design to allow me to turn the lights off at say every night at 9pm and on every morning at 7am or whatever. Also, a basic clock that allows the project to be time aware would be very useful for other future features that will make use of schedules. So, my question is can anyone recommend simple low overhead way to implement a clock in my project for the functions that require it? I have a feeling with all my crazy ideas for features I will out grow my single BASIC Stamp 2 at one point, but I’m also sure I will be able to pack some fun and useful stuff in there before that happens, but that is why I am big on low overhead and pin usage to get the most bang from the power of the Stamp for as long as I can.
Thanks in advance and until next time happy coding, building, and planning [noparse]:)[/noparse]
-Brann
Rather than open up a new thread for each and every of my sure to be many upcoming questions I figured I would save the mods and anyone trying to follow my progress a headache and start a single thread for the whole project. I plan to post all my questions, pictures, schematics and code for everyone to see and learn from right here. With that said I am very open to any comments and ideas that anyone in this great community might have to offer. I hope people can read this thread to learn and be inspired like I was from some other very interesting threads then grabs some of the great products from Parallax and bring their dream projects to life [noparse]:)[/noparse]
Now on to some details of my project!
I hope to be placing my order tomorrow for some parts to kick start my first phase of the project. I have been doing a little research and have selected some sensors I wish to start working with my Basic Stamp 2 and Board of Education. I will be starting with and AD592 Temperature Probe to monitor the water temps and a Sensirion Temperature/Humidity Sensor to monitor the room in my basement where the aquarium will be located. I would also like to add some relays to the design in order control some basic 120v items such as a heater for the water, a pump to manage water levels, the tank lighting and maybe even an auto feeder somewhere down the road.
Question #01:
I would like to start my relay system with the first task of managing the lighting for the aquarium. I understand the basics of this task is more or less just coding a function to turn on a pin on and trip a larger relay to turn the lights on and off, but I would like to have this happen on a schedule which would require a clock build into the design to allow me to turn the lights off at say every night at 9pm and on every morning at 7am or whatever. Also, a basic clock that allows the project to be time aware would be very useful for other future features that will make use of schedules. So, my question is can anyone recommend simple low overhead way to implement a clock in my project for the functions that require it? I have a feeling with all my crazy ideas for features I will out grow my single BASIC Stamp 2 at one point, but I’m also sure I will be able to pack some fun and useful stuff in there before that happens, but that is why I am big on low overhead and pin usage to get the most bang from the power of the Stamp for as long as I can.
Thanks in advance and until next time happy coding, building, and planning [noparse]:)[/noparse]
-Brann
Comments
For a clock function, the DS1302 RTC is a good place to start - there is a lot of sample code and documetation on the this chip as well. Chris Savage ( of Parallax) has an indepth thread on this IC in the Projects section.
Aloha
Robert
·· I was just joking with a few co-workers about how I try to put a DS1302 into every project.· Even if I don't need the clock I can always use the battery-backed RAM.· Here are 2 threads which show that the BASIC Stamp 2 is quite capable of doing what you want and that, properly planned, would be unlikely you would outgrow it that easily.· I will also attach code I was working on (read, not done, but functional) for a digital thermostat which shows the scheduling function.
http://forums.parallax.com/showthread.php?p=531080
http://forums.parallax.com/showthread.php?p=552892
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
First of all I would skip the mechanical relays and go for a solid state relay. Inputs to the solid state relays are 5 to 30 volts DC. Very easy for a Stamp output and comes in varing current / voltage ratings (120/240 VAC - 1, 5, 10 ,25 amps). Very simple to connect - power and ground for control and placed in series like a power switch for the "switch" side. No noisy clicking just power on /power off.
Check online at any hobby electronics site and search for solid state relays
John
After looking at the threads posted by Chris Savage it got me thinking on LCDs. I have a Matrix Orbital LK204-25-PC (the manual is located here http://www.matrixorbital.ca/manuals/legacy/LK204-25-PC.pdf ). I ended up getting this LCD when I was building my last modded computer with all kinds of crazy neon light kits and what not during my LAN party days which are long gone. This nifty little LCD has been powered down sitting in my case collecting dust for more than a few years. I remember in its prime when I used it I could do more than a few cool things like control winamp and a few other apps with a little button interface I built that sadly ended up getting lost over the years. It also has 8 750mA output pins built into it that I never really found a use for, but maybe they could trigger relays or something in this project? Since I am putting in my order tomorrow I figured I would ask if anyone can think of any components I might need to buy in order to interface this LCD with my BASIC Stamp 2 other than a serial connector to connect the female serial port on the LCD to my project. I would just hate to get my parts in only to have a never fun duh-me moment and find out I forgot something stupid that prevents me from using the LCD.
Thanks in advance,
Brann
P.S Thanks johntech for the heads up on the solid state relays. I did not know that and will be sure to keep what you said in mind when I start shopping for them [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I just rechecked the manual and it said this:
"GPOs can control 12V devices. Maximum allowable current is 750 mA per GPO, which allows the
GPOs to be used for controlling fans, stepper motors, etc., directly without the need for a relay in many
cases."
It was ment to pull power from a ATX Power supply via the floppy drive power cable. Maybe that would explain it?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Yes it is an RS-232 version with a femail DB-9 connector on the back. The PDF manual says that while it does not use TTL by default with a jumper and a few quick solder point it can be converted. I would rather not take an iron to the LCD if I can help it. Would it be a big pain to use it in RS-232 mode or should I just say to hell with it and mod it?
Also, for the record... its 1:13am over here and I'm sitting here getting some prime info from you.... can't say much other than thats why this forum is amazing [noparse]:)[/noparse]
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I cant wait to read more as your project progresses.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I know just enough to tinker with something... but not enough to fix it when I break it. Thank the techie gods theres forums...
Here is a quick update on my progress:
I spent pretty much all day working on my Matrix Orbital LK204-25-PC talking with the Matrix Orbital staffers and reading forum posts without much luck. I managed to swtich the LCD into TTL mode in order to interface with the BASIC Stamp 2, but for the life of me I can not manage to get the baud rate to stay at 9600 to allow me to connect to it correctly. I am pretty sure there is a way to store the setting as a new default on this LCD. I followed a thread that talked about using the RAW Data upload function of the LCD to set it into memory, but sadly still everytime I power down the LCD it resets the rate to 19200 which is killing me. If anyone knows anything about this problem feel free to post and if not I am sure the Matrix Orbital people will help me then I will be sure to share the fix with everyone else over here [noparse]:)[/noparse]
-Brann
why not just set the BS2 for 19200 baud? The baudmode number isn't in the chart in the BS2 IDE help file, but the formula is there for calculating it.
I had thought about looking into changing the rate on the BS2, but then I thought that 9600 was the standard for pretty much all TTL stuff unless I am wrong. I figured with that in mind I would try to have the LCD play nice in order to not break compatibility later down the road when adding more things to the project. But, hey if I am wrong and it is as simple as changing the SEROUT command for dealing with the LCD and I can mix and match baud rates for different devices I think I will spend tomorrow working on that... any day you spend learning new things about something is not a total waste of a day i guess[noparse]:)[/noparse]
****UPDATE****
After a little looking around unless someone can chime in and tell me differently running the LCD at 19200 works pretty much without a hitch [noparse]:)[/noparse] I calculated the baudmode to be 32 and was able to write pretty much without any problems! I only seem to have one small hang up... for some reason after it run my sample code it just write a little solid block character that looks like the blocks you see after turning the contrast way too high on the LCD. They show up one after the next every second or so until it fills the screen.
This is all I am running for my test:
It is just a screen clear that clears the model number that auto displays when you power the LCD up. So, I guess now all I need to know is if running the LCD at something other than 9600 baud will cause problems down the road and if anyone knows about those little block characters… maybe my baudmode is off a little for the SEROUT ?
****UPDATE**** 8/16/06
I talked to some more people at the Matrix Orbital support forum and found out the root of my problem... It seems that the version of the LCD I am working with has a bug that does not allow the default baud rate to be saved and everytime power is cut it will revert back to its old standard of 19200 baud [noparse]:([/noparse] I guess looking on the bright side I now know where I stand and what I am working with.
Now that I know this I was thinking I could just code a startup function into my BS2 code that will first talk to the LCD at 19200 and then tell it to switch to 9600 then send all my real commands over in 9600. Or am I doing this for nothing and should I just talk to the LCD at 19200 and call it a day? I have not messed with anything yet today, but I guess I will see if I can figure out why it still displays the blocks. I figure is either my wiring where I have the LCD on pin1 or the baud rate... or so I hope [noparse]:)[/noparse]
I will report back on this goofy stuff and if someone that know a little about this TTL serial baud rate business could give me a little input as to if I should be spending the time to get it at 9600 or if I should use 19200 and just move on that would be awesome [noparse]:)[/noparse]
Thanks in advance
-Brann
Post Edited (Brann Fenix) : 8/16/2006 7:00:32 PM GMT
I have the LCD baud rate stuff all figured out and I am not having problems sending commands anymore which is awesome. The only problem I'm still having is that goofy character that keeps getting printed to the LCD. Here is some updated info on it and a picture of what it looks like in action, I really hope someone out there has some ideas how I can either fix or at least cancel the stupid things out as they are printed to the display.
Here are my new findings:
1. It seems the characters are not really basic sqaures or blocks as I first thought. I have attached a picture of the character in question to this post. Maybe the first step to fixing out how to get rid of it is to figure out wtf it is...
2. The LCD outputs these characters one at a time in a neat little row until the first line is full then it just moves on to the second line and seems to loop forever.
3. I did not take a stopwatch to it, but it seems to output on of these characters every 3ish seconds or so.
4. This problem only happens when I am hooked up to the BS2 in TTL mode no matter what the baud rate is. When I change it back to RS232 mode and hook it up to my computer everything is 100% fine.
Please let me know if anyone can think of anything at all. I just put in a nice sized order for a bunch of sensors and stuff and would really love to get this figured out in time for the new stuff coming in since I know I will be all over it once the mail man drops it off [noparse]:)[/noparse]
How much are you offering for a solution? I know exactly what it is
Change:
END
to
Finish:
GOTO Finish
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
How about I offer tons of my thanks and you let me know if there is ever anything I can ever do for you [noparse]:)[/noparse]
Again I find myself going duh for not figuring it out, but hey it’s a learning experience and getting schooled is part of it. Anyways, it seems that what creates that character is the fact that the LCD pin is staying HIGH after it has displayed the text. Now, I have tried adding Finish: into my code, but while looping to it does stop the character it also stops the code in its tracks. The other thing that seemed to work was setting the LCD pin LOW. The only problem with setting the pin LOW is that it sends a single funky character which I assume is the LCD reading the pin going LOW and trying to display it as a character. I think turning the pin LOW is the simple fix I want, but I am kinda anal and getting rid of this new single character that results from turning it LOW is my new goal… so close [noparse]:)[/noparse]
Here is the code
When this code run it outputs Display is On[noparse][[/noparse]FunkyChar] and stops. Is this a code problem or maybe I need some thing connected to the Pin in order to buffer communication from the BS2 to the LCD? I am 99% there now and if I could grab this 1% i think I would sleep better at night [noparse]:)[/noparse]
I had another side question about the code that I am sure is even easier, so people do not mind my pbasic n00b self. As you can see from my code all LCD commands start with 254 so the clear screen command is 254, 88 or LcdCmd, LcdCls. I could not figure out how to combine both numbers into one constant I could define like this:
Any hints on this one? It is far from a problem, but I figure losing one unneed constant gives me room for one more I might need a year from now [noparse]:)[/noparse]
Thanks in advance,
Brann
Post Edited (Brann Fenix) : 8/17/2006 6:37:56 PM GMT
Just use TWO characters, like this
LCDInit con 254
LCDCls con 88
SEROUT LCD, LDCBAUD, [noparse][[/noparse]LCDInit, LCDCls]
Why complicate matters
So long as you use the END statement, or noththing at the end of your program, you stand the chance of those funky characters returning at some time in the future. Change that pin to INPUT mode (which may or may not work) at the end, or end with a loop as I showed you, or the PBASIC STOP command.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
As I read more code examples it seems that two characters are the standard and if it is good enough for everyone else it is good enough for me [noparse]:)[/noparse]
As far as the funky output I think I will be able to fix that by looping some code to work with the LCD keypad based on the example posted here http://forums.parallax.com/forums/default.aspx?f=5&m=129698&g=129707#m129707 that might do the trick. It just makes things interesting that if I idle my code for 2~3 seconds the character shows its funky little face heh... I am sure I will figure something out in time [noparse]:)[/noparse]
I worked on some more of the Applied Sensors book and calibrate the AD592. I think I will also be adding a logger for water usage since I should be able to track the levels using a setup like the conductivity sensor in the book. It should work out since you can chart the RCTIME output based on how much water is covering the probe. Applied Sensors is a great book full of all kinds of things that will spark some nifty ideas [noparse]:)[/noparse] I think it is a must read for anyone trying something like my project.
I have pretty much all my basic sensors figured out, so I am 100% waiting on the relays. I will be spending the rest of my time researching relays and I'll be sure to post my finding [noparse]:)[/noparse] But, if anyone would still like to recommend some I am always open to new ideas and information.
***Update***
In the last few days I have had some good things and then some really crappy things happen. On the good side I managed to get some test code working with my Sensirion Temperature/Humidity Sensor take readings from the air and my DS1302 setup as a scheduler that I can use to control my lighting relays and such. I am about to start working on connect and getting code working to read water temps with a AD592 Temperature Probe and then I should have all the sensors I need at the moment ready to go [noparse]:)[/noparse] Now, the bad news... I was working with a nice little Matrix Orbital LCD that thanks to the help of a few people I had 100% working with my project, heck I even got the keypad working perfect with my little push buttons and everything. I went out to get a project box from Radio Shack to pretty everything up then after cutting the holes for it I managed to crack the damn thing while screwing it in [noparse]:([/noparse] A turn of a screw driver killed my poor LCD which made me more than a little sad... the lesson learned here is never over tighten one screw and make sure everything is even... a little too much pressure and bye bye mr. LCD.
Here is the thread I started for my Sensirion sensor questions if anyone is interested:
http://forums.parallax.com/showthread.php?p=602595
***Question***
Now that I have most of my sensor code and my scheduler working I am in the market for some relays. I have never worked with any form of relays before, but I have been doing a little reading that is giving me a better idea of how they work. johntech recommended solid state relays and after a little more looking I think they should do the trick to control my pumps, heaters, lights, ect. So, I am in the market for a few 120v 5amp and 10amp relays that require 5v or less to switch on and off. I would like to find something that can work with my BS2 without too many extra components crowding my board. If anyone with more experience in relays than me could recommend a model that would best fit this task and maybe a reliable place to buy a low quantity of them from it would be very helpful [noparse]:)[/noparse]
Thanks in advance!
-Brann
Post Edited (Brann Fenix) : 8/24/2006 8:25:03 PM GMT
Thanks for the reply! I needed the GPOs on the LCD for relays to free up as much of the BS2 for other work loads as I can. I was just really nice how I could connect the LCD with 2 pins to the BS2 then turn the 10 GPOs on and off with a simple command... gone are those days [noparse]:([/noparse]
It seems after adding 3 sensors and a clock to my project I am out of variable space. I read about double checking the size of the VARs to save space by not using a WORD when all you need is a BYTE and I think I am pretty good in that repsect. I merged the TempF and TempC variable for both the SHT1x and AD592 without any problem. I also removed the "true humidity" variable since the linearized one always seems to come very close to the temp corrected one. I was just wondering if anyone could give my code a once over and point out anything I have missed that could save me some more variable space. I see my biggest space hog as being the DS1302 clock, but I think reusing those variable might start a naming nightmare... any ideas there? I had planned to still add a pH and TDS sensor and my needed relays... Here I was thinking that I/O pins running out with be my first road block heh...
A few points to keep in mind when reading over my code:
1) This is really the first attempt at PBASIC and expect it to be kinda messy and newbieish.
2) Don't mind any spelling or typing errors in the comments as I have not really gone over everything word for word.
3) I have some small to large blocks of codes commented out that I am goofing arouding with, so don't mind them [noparse]:)[/noparse]
4) If runs fine as is and is just out of space of variable [noparse]:([/noparse]
I think that is about it... heh
Thanks in advance,
Brann
Take for example code that reads:
tempC = rawTemp * formula (fictional code, I don't have the code handy)
Instead you could use:
rawTemp = rawTemp * formula (you get the idea...No intermediate values)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
·· Thought of one more thing you could do...While the BS2 doesn't have ScratchPad RAM you could make use of the RAM on the DS1302 to store values temporarily for calculations.· This could save a few words as you'd only need to use a few temp variables for calculations on Temperature and Humidity.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
EXCELLENT POINT, and something that many of us overlook. Who can turn down FREE MEMORY!
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
One question on this for starters... Since writing to a location on an EEPROM can only take place so many times before the address is toast... I would assume storing something like a temp Var that changes every half a second would toast my DS1302... is this true? If it is true... what can I do to work around this? I guess what I am asking is what is the smart way to take advance of the DS1302 space without killing it in a few months.
Thanks in advance,
Brann
*EDIT*
Thanks Chris for the idea of not using all those working VARs for my tempF and empC readings... so simple yet over looked by me [noparse]:)[/noparse] I have managed to get rid of 2 word VARs by doing that for the temps. If you can remember a way to save some space on the humidity sensors or point in the right direction that would be awesome and I bet save me a little more space! [noparse]:)[/noparse]
Thanks again!
Post Edited (Brann Fenix) : 8/30/2006 2:45:54 AM GMT
·· the DS1302 has SRAM, which is why I suggested it.· As Bruce pointed out, you can't turn down free RAM.· It's as good as ScratchPad RAM on the BS2e+ models...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Post Edited (Chris Savage (Parallax)) : 8/30/2006 3:16:45 PM GMT
It seems that I just had a quick crash course in what a scratchpad RAM even was heh [noparse]:)[/noparse] Now, after using my friend the search button and reading the DS1302 data sheet again I have come up with the facts that like you said. The DS1302 does in fact had a 7 byte scratchpad along with the 31 bytes of static RAM. From your clock demo code I have an example of how to store data and read data from the static ram, but what about the scratchpad? I have seen posts about dealing with the BS2 models that have scratchpads, but nothing on the DS1302. I was wondering if you could please give me a push into the directions of docs explaining how it works.
Thanks,
Brann
Just a minor correction. The plain BS-2 has no scratchpad RAM. Only the more advanced Stamps, the BS-2SX and above have it.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
Thanks for the post [noparse]:)[/noparse]
I was aware that the BS2 I am working on does not have any scratchpad RAM, but the data sheet of the DS1302 says that the DS1302 has 7 bytes of it. While 7 bytes is not hugest amount to work with... it being 7 bytes more than I have I will gladly make use of it [noparse]:)[/noparse] That is why I was asking about the code require to access the 7 byte scratchpad on the DS1302 since all I could find was the code for the 30 bytes of static ram in the example Chris made. Unless I missed something and it is one in the same... either way if someone could clear it up that would be great [noparse]:)[/noparse]