RF Controlled Greenhouse Light Controller .... Pretty Close

OK, so maybe jumping up and down with joy because you found a really bad, really dumb programming error was not cause to publish a computer program. But.. Done deal. Some years ago I discovered that the APC220 RF module was a drop in replacement for RS232 wired serial communications for use with remote machinery, for example, between a laptop and say an Arduino microcomputer. It has a 3000 foot range, suitable for a small farms and does a fair job. I've been working at getting a greenhouse controller built. It would have a VB6 program at the base station which would communicate with a remote, self controlled greenhouse lighting and maybe heat controller, in this case, an Arduino Uno with a tft touch display. Now, to be honest, nothing has been implemented or tuned up so far. The Uno does not have quite enough memory. And the original plan was to use a wifi transmitter/receiver combination, still an option, but there is enough done so far to be a real and effective controller if joined with the APC220 and an opto-relay. The auto-restart function on the Arduino needs to be disabled (good reading on the web) to prevent unexpected resets. And an output pin for the lighting would need to be wired and programmed. Now programmed as pin 12, good luck getting physical access with the display on top. Plus, there is currently no way to set the time at the Arduino controller end . Details... But all the goodies are here/there.

Computer Versions
Older Newer
Newest
Older
Newer
Newest
........................................... Arduino versions......................................


The reason I am celebrating, I had a serious glitch in the comms portion of the VB6 program that I could not find. Matter of fact, there are still some mammoth ghosts in the machine (like the wandering com port # of Arduino fame). But I could send strings to the Arduino manually and successfully using the Arduino serial monitor program (copy, paste, send), thereby programming the lighting times on the Arduino, I could show that. But VB6, more specifically the Visual Basic 6 mscomm.ocx communications subroutine module didn't seem to work. I could send the current time of day, retrieve time and light status, but I could not assemble and send a simple alphanumeric string to the Arduino representing the lighting times. One early problem discovered was that the buffer size in the Arduino was 64 bytes whereas I was trying to send 96 time periods as ones and zeroes in a string!! Got around that by cutting the string in half, sending two 48 byte half strings, That worked. But one of the final problems traced down to using the "str" command in VB6 instead of the more conservative "cstr" command to assemble the strings from known lighting times. My bad, got in a hurry, Str adds a space to each number, cstr does not. If I had not, out of frustration, done a cut and paste from the VB6 monitor to the Arduino serial monitor during one particular lighting paradigm, I might never have noticed the error, spaces had been added to every number in the data string, but were cleverly removed by the proportional printing of strings on the computer screen. Additionally, the Arduino is based on a unix like C/C++ compiler. By contrast, Microsoft generally terminates strings with a line feed AND a carriage return. Unix uses only a line feed. This also introduced stray characters into the data stream. and meant a lot of characters were left in the serial buffers, some rather capriciously, those characters had to be purged before each transmission and the mscomm module was not sufficient by itself at purging those buffers.. So here is most of the code. The Arduino code old , Arduino code newer, the newest Arduino code, and a recent, not newest VB6 code and executable

To operate the Arduino, first a 9341 tft shield was installed on top of the Arduino Uno board (The Adafruit Arduino tft drivers used here are each given their own ID# (Depending on where they come from in China?). Adafruit was started by a woman from MIT. It sells tech toys and has simplified a ton of technology for millions of people like myself by writing a ton of software.). Any other tft shield (add- on board) should work after some serious but grizzly tweaking of the display dimensions within the Arduino program. Touching the green square on the display, any subsequent touching then within the outer circle of the timer will add turn-on times in 15 minute increments. Doing the same, touching the red square first, will cause the lighting times to turn off, very much like raising and lowering the studs on a mechanical timer. Time and on/off status are displayed. The same math used to turn on and off the times could be used to move the time of day... not yet implemented. Hint: the two-argument arctangent is a hoot on the Arduino.

To operate the computer end, touching, or clicking with the mouse, will turn on and off times similar to the Arduino. The built in computer clock sets the time on the computer. Sliders are also available for setting on/off times. A clear all button is provided to start over, as well as a lock down button to prevent accidental touching/reprogramming. A crude file system is provided to save and retrieve clock patterns (for inducing flower forcing, fruiting, senescence, etc.). The send/receive button opens a form which allows sending and receiving data from the Arduino: send time, retrieve time, send light pattern, retrieve current pattern, get current status, etc. I know, I know, severe cabin fever... believe me, I know.


I may add some other things before putting this up on the net... some garbage collection, ability to delete light times on the VB6 basic program, retrieve light times, etc. Don't worry about it..."Things change, always do."
:) Insert rap music here :) .........Apologies for typos, program sections commented out, and bad grammar... Sorry, life's too short :)
Last edit: March 28,2021