September 2019 Update

New! We're moving to the new forum!

ALL new Blog posts will be on the forum.

Please join us there.

This Blog will no longer be updated...

Saturday, August 31, 2019

Back to coding...

Posted: 11:55pm

Alright, we're back in business, no more reboots on the esp8266, however, the OLED display is not working. I guess that's the first thing on the list for tonight...

I'll post an update when I find something.

Update: 12:20am

  • First thing I did was check the voltage on the OLED connector I mounted on my shield, and there was 5v there as there should be.  
  • Then I pulled the shield off the Mega and measured the continuity from the OLED connector to the SDA and SCL pins which go into the mega when the two mate. That was good.
  • Next, with the shield removed, I used breadboard wires to connect the OLED display tot he Mega directly, and it works.

This tells me the problem is with my shield...  So I pop it back onto the Mega, and I notice a row of pins is not seated in the header on the shield, the header is slightly bent, likely from all the on and off, but no problem, I eseated the shield, and the display works now, so that was a simple fix.

Now we can continue....    Updates to come through the night...

The end of the endless reboots?

I mentioned in my previous post that I thought it might be a problem caused by installing a different version of a library, well, that was it. The MySql Connector library to be exact.

Looks like a change was made 8 days ago.  This is the only change listed on GitHub.  It looks like lines 39 and 40 were added.   I have no idea how or why it has caused the problem, but I think I can rest easy knowing that this is definitely the cause.

Making do...

I tried, but just couldn't stretch the money this month to get everything I needed, so ended up having to put a priority to everything and let that dictate what I could buy...

I really miss whiteboards, but they are expensive. Check out my link on my DIY whiteboard. I can make as many as I want for next to nothing.

As for my broken Magnifying Lamp, a new one was going to set me back $100 or more, but a tube of 5-minute epoxy was under $10 :)   The spot where it broke was was, well, let me get a picture, same me typing 1000 words :)

So you can see my fix too...  The lamp broke where the head swivels left and right... there is a metal bolt, but the nut was embedded in the plastic, and it was the plastic that broke, so there was nothing holding it, and it just dangled on the cord.  I clamped it together with two pieces of wood and some zip ties, and just kept pouring 5-minute epoxy into the opening.  I left it clamped until the next morning, and now, it's as strong as new, probably even stronger!

I only ordered two water pumps for the automatic watering, I've got 3 or 4 here still, and my initial installation will be limited to 4 plants rather than the whole flower tent.

I picked up some 17 liter pails at Home Depot, 4 of them, and 4 dish pans at the dollar store.  I drilled drainage holes in the bottom of the pails, and the dish pans fits perfectly at the bottom to catch any drainage 

These new "pots" will be the biggest ones I have, and I'm going to put my mothers in them.  I have 4 strains now, so 4 mothers, 4 pots, and 4 Automatic Watering setups, how convenient :)  I think by installing this first on my mothers shows just how much confidence I have in the system, let's hope it's not misplaced...

$4 for the pail, $2 for the pan, can't get much better than that.  I do want to find something to go under the pail inside the pan though, maybe some gravel, or plastic ring, something to keep it out of the water if there is any overflow...

These pans give me a nice option, add a drain tube. Since my veg plants all sit on a raised platform, I can put a large tote underneath with the drain tubes draining any water in there, and just put a water detection sensor (home made of course) in it to warn me if it gets much water in it. Maybe with winter coming, it will just evaporate, and help raise the humidity? That would be helpful...

I did buy a 25 foot roll of panda plastic, and am going to replace the plastic on the walls and platform. I'm hoping to build a wood frame for the platform, like a waterbed frame, and line it with the plastic, like the safety liner on a waterbed. You remember those don't you?  That would be an emergency water catch once automatic watering goes fully online.

Let there be white! (boards)

In a previous post, I talked about how I miss having whiteboards. I would love to fill the walls here at home with them, but instead, I'll make do with this, my newest DIY creation.

It's hard to see the writing because I need new markers for it, these are quite old...

So, are you curious?   It's two dollar store foam boards (color is irrelevant) with a piece of light plywood sandwiched between them, all taped together with duct tape. I then cut a piece of Panda Plastic (white on one side, black on the other) like you might already use in your grow space.  I got the idea when I remembers back before I create Grow By Wire, I used to used dry erase markers to write on the walls (that were lined with panda plastic) with dates for each plant etc.  I found that if you leave the writing on for a log time, it won't wipe off with a paper towel, but just add a little water and it cleans right up.  I put the plastic on both sides, so I can just flip it over and I have another white board...

Material List:

2 x Dollar Store Foam Board
Thin plywood roughly same size as foam board
two pieces of panda plastic to fit.
Duct Tape

I had everything already, so mine was free!

Endless reboots :(

Posted: 1:45am

Since re-installing windows 10 on my development machine, when I compile and upload my code to an ESP8266 sends it into an endless loop of rebooting. 

I do have a full backup if it comes to that, but the whole idea was to start fresh, so I'd rather make this work. I suspect I may have picked up a new version of some library which I need to make a change for, or perhaps I made a change to my copy of the library and now that it was re-installed, my changes were lost. I have been known to change code in libraries early on, but I learned my lesson, only do it if absolutely necessary, and DOCUMENT the changes!  

Here is my plan of attack, I have two programs, one for the Mega 2560, and one for the ESP8266 (actually all my boards) which are just blank sketches. They do the absolute bare minimum, and I use them when I am finished with a board and put it back, just so I can start clean every time. I also use them in times like this.  I have installed the blank firmware on both the 2560 and the 8266, and at this point, it is stable, not rebooting, and I can do OTA updates on the 8266.

This tells me that the problem is not in the compiler or core libraries, it is either in my code, or in one of the libraries I'm using. The next step will be to comment out everything in setup() and loop() that is not needed, so they will resemble the blank versions when compiled. If they run, then I simply start uncommenting sections until it fails, and that gives me somewhere to look for the problem.

Update: 8:30am

Well, I didn't make a lot of progress overnight, I got sidetracked with a ton of other tasks. I did manage to install the new sensor module firmware with everything commented out, so it was basically the same as my blank firmware, and it ran without issue, so that's one positive step. I enabled the moduleCfg read, and it still ran without issue, but as soon as I enabled the send to the 2560, it started giving me random (seemingly) watchdog timeouts and rebooting.  This is where I got sidetracked, and haven't made any further progress.

I did however find a bug in my method which waits for an acknowledgement when it sends data from the 8266 to the 2560. I  recently added a database close after every use to fix another problem, and the way this method was written, I put it in the wrong place, and if the data was not acknowledged on the first "wait cycle" (it will try 5 times to read an acknowledgement, with a timeout in between) then the database was closed, and never reopened during the cycles, this was causing the initial reboots. I was adding serial prints to the code so I could follow it as it executed, and this is when I saw the mistake.

So right now, it still throws intermittent wdt reboots, and I feel like a complete newb because I can't stop them... I know it happens when you go into a loop or process that takes longer than the timeout value, which I forget at the moment.

It's been a long night, maybe a nap will help.

Friday, August 30, 2019

Let there be light!

If you want to turn HID lights on and off, a cheap little 5v relay isn't going to cut it, and I know this from experience. When I tried it before, within 2 days, the relay had fused closed, and the light stayed on. After doing some research, I found out I needed something called a contactor, basically a heavy duty relay. So off I went to Home Depot and a few other places, but nobody knew what I was talking about :(  

While I was at the local grow shop picking up some ProMix, I thought why not ask if he knew what I was looking for. Turns out they had ONE, although it took him a bit to find it.  

While a 600W light at 120v will only draw 5 amps, it's when you first turn it on that it draws quite a bit more. This relay is rated for 40A@220v, so roughly 20A at 120v.  The coil voltage is 120v though, so I can't control it directly from an Arduino digital pin, so I'll use a small 5v relay to switch the 110v on to the coil, which in turn will switch the main 120v on for the light.

One of the main reasons for wanting to control the light in the flower tent rather than leave it on a timer, if the exhaust fan were to die, or the ducting came off, the tent will get very hot very quickly... the plants wouldn't last long. This way, if the temp rises above a certain threshold, I can shut the light off, saving the plants.  I've also read where a lot of people swear by using a contactor, even if driven by a timer, just to avoid a fire hazard with the timers.

I also ran across some nice buckets at Home Depot that I'll be using as pots. I'll drill some holes in the bottom for drainage, and they should provide plenty of room for a nice root system, and therefore a nice big bushy plant.   Then I tried to find some trays to go underneath to catch runoff, and couldn't. At least, not until we went through the dollar store and I found some dish pans for $2 each. So $4 for a bucket, $2 for the tray, and I'm set with a trial run of 4 plants.

It is with these 4 plants I will set up the automatic watering to get started.

But first, after re-installing windows, and all the programming tools, everything I upload to the ESP8266 sends it into a reboot frenzy due to the watchdog timer. I finally gave up and went to bed last night, and actually for the first time in ages, slept for more than two hours...  We spent today doing our shopping and stuff, so tonight I'll be getting back at it. Right now, the sensor modules are working without issue, so there is no real rush to get things compiling properly again, but the sooner the better.

Thursday, August 29, 2019

Windows Re-Install

I've been using Microsoft Windows since at least Windows 3.1, likely earlier, and before that, DOS.

One habit I got into was to re-install windows once a year as it always got slower and slower, and a re-install would bring life back to an old machine.

The laptop I'm using as my main development machine is a nice fast one, and I've had it for quite a few years, so there's lots of junk installed on it, and I've never wiped it and started over, I've always been afraid I'd never get everything configured and working again, such as the ability to program all the little gadgets I've collected and used over the years. Some of them were a pain to get working...

It's been getting slower and slower, and it was really causing me a lot of wasted time...  30 - 40 seconds just to rename a folder...  15 - 20 seconds to enter a folder and display the files...  

I had no choice...  So last night at dinner time I started a backup of my C drive, there were about 200Gb of files on it.  It took until noon today to back it up to an external drive, that's how slow it was... 

I have daily backups of all my source code and database, so I decided to go ahead with a complete wipe of the C drive and reinstall windows.  If you have ever re-installed older versions of windows, but not windows 10, you'll be in for a pleasant surprise...  It's much easier now, and much less work. In the past I had to struggle with getting the network going again, and my display set up, all that stuff was automatic in Windows 10.  All I had to do was re-install my apps, which this time are quite limited. I've only installed the stuff I need for my current projects.

Now I can rename a folder in a second! It's so nice to have my computer back!  And if you're thinking I had a virus, or malware, no, I didn't...  I've worked with computers since the first pc came out, before actually, and I've NEVER had a virus, and I've been online since we used 300 baud modems....

Everything went smoothly, except for one thing...  I lost any changes I made since the last backup at 1:30am last night until this morning...  Since I tend to do most of my work at night, this could have been a problem, except I spent most of last night working on the transistor switches for the water pumps. I did make a few changes, just adding some prints to help me debug an issue, so those are easily added back in, since I can just copy and paste it from the serial monitor of the code that's running on the sensor module.

Overall a great experience compared to the past...    Now that I have a fast computer again, I should be able to work faster! :)

Wednesday, August 28, 2019

Water Pump Switching with Transistors?

Posted: 11:45pm

I'm doing an experiment, or proof of concept, to see if I can control the pumps for the Automatic Watering System using transistors to switch the power on and off.  I'm using 2N222A NPN transistors and will control them using digital pins from the arduino. In order to do that, I need to put a 1K Ohm resistor between the pin and the BASE leg of the transistor, and I'm switching the ground line so that the sensors get the full 5v and avoid the voltage drop caused by the transistor itself.

The yellow are the control lines, connected to the BASE leg of the transistors, and they hook up to the arduino digital pins. When the pin is HIGH, then current can flow through the transistor, and the sensor is powered. When the arduino set it's pin LOW, then current cannot flow, and the sensor has no power. The Red/Black pins are to supply 5v to the sensors, switched by the transistors. The Black, which is ground, hooks up to the EMITTER leg of the transistor, and supplied the path to ground for the current. Red is common to all sensors, and is attached to all edge pins on the top row. All sensors are connected to 5v, and it's the ground wire that is switched..  The edge pins on the bottom row are ground, but each pin goes to it's own transistor, to the COLLECTOR leg, where if the transistor is switched on, provides a path to ground.  On the right of the yellow pins is a black pin, this is ground, tied to the ground beside the red pin. If your power supply to the sensors doesn't already share a common ground with the arduino, then adding the ninth wire to the connection will tie them together.

I just finished building this, and it's pretty ugly as I'm down to re-using scraps of perf-board, and you can see a damaged spot on the bottom where I screwed up removing some component.  I'll be ordering more in a couple days. 

I haven't tested it yet, not even my usual continuity checks on the circuit, so it will be a bit before I start pumping water, but one step at a time.

Flower Tent Rewiring Complete!

I finally got around to upgrading the wiring for the sensors in the flowering tent. Now that Module 2 has the new connector board in it, the wiring hangs off the back so much better. There are 16 analog and two digital ports configured, and they are all used. 

Plugged into the module is about a foot of standard three conductor servo wire, with the 10K Ohm voltage divider, then the two conductor speaker wire which goes into the tent and ends with a female JST connector (the red ones)

 This is not Module 2, but is to show the connection to a module..

The veg area is raised by these plastic shelving units, just one level deep. This keeps the plants up where it is easier to work with them. It also provided a nice place to fasten the bundles of wire to keep them off the floor. Before when they were loose, I would occasionally catch one with my clumsy feet, in fact, I once pulled both Sensor Modules AND the laptop right off the shelf and they landed on the floor!   Now I bundled all the wires in 4's. Since each of my grow areas is divided into 4 rows of 4 plants, I've bundled them by row. In the flower tent, I only actually use 3 rows, and occasionally less than 4 per row if they are big.

The wire bundles are then zip-tied to the underside lip on the shelves, I just drilled some holes through it for the zip-ties. There is also an ethernet cable for the laptop and the twisted servo wire for the digital DHT22 sensor.

The bundle enters the tent through a ventilation opening, and is then distributed throughout the tent. The lights are out in there right now so I can't get a picture, but I'll try to remember to get one in the morning and add it here.

All this was motivated by the fact that two ports weren't working, one digital and one analog. I replaced the sensor and it didn't help, so I started with the wiring, and it led to this....

Tuesday, August 27, 2019

The shopping list!

While I'm planning on spending a little more money this month (very little 😒) I need a lot of things, some are cheap, some are not.

I originally planned on buying all the pumps, hose, relays, etc I needed to get the Automatic Watering system up and running, but I can';t see spending all my money on that, when I need not only the usual replacement of consumables, but things like a new magnifying lens/light, a new cordless drill, a more comfortable chair, a whiteboard, plus my normal supplies for the grow room, a bale of promix, some nutrients, peat pellets...

The batteries for my Ryobi +ONE 18v drill are shot, they hold a charge for about 2 minutes, so you gotta hurry. I'd probably be able to get by with a corded drill, but eventually I'd end up needing cordless, and then I'm spending twice... I have learned that some things, you need to just spend the money and get something that will last.

I bought a cheap magnifying light, a plastic one, last time, and a couple days ago I grabbed it and twisted it into the position I needed it, and the plastic snapped, leaving the lamp dangling... I managed to put a wooden splice on it to hold it in place for now, but it isn't going to last long...

I use this lamp ALL THE TIME... I can't solder or wire up the shields without it, both for the light, and the magnifying effect.  So either I have to replace it with a better quality one, or try to make do...

As a compromise on the Automatic Watering, rather than automate all the plots, I'll just do the flower tent, so only 12 plots, and since the small pumps I'm going to use only draw 300mA,  I'm going to try powering the pump using a transistor to switch it on and off rather than a relay. I have a bunch of S8050's that are rated for 500mA, and some 2N222A's rated for 600mA.  I'll do a separate post on this.

WiFi Repeater repeater repeat...

Posted: 3:00am

I had this tiny little wireless router I picked up a long time ago, hopefully the link still works when you read this, the product has been discontinued for some time I think.

I've played with it in the past, but never had much luck with it, until tonight!  One of the biggest problems I have is the WiFi connection in the grow room. While it is the bedroom closest to our internet router, I usually got between 50%-60% signal strength, and sometimes couldn't connect at all. I'm not happy with their service but we are locked in for another 2 years :(

This is from an earlier post, you can see it was a good day, the signal strength was in the 60's.

This is with the router plugged in and configured as a WiFi Repeater. It is located about halfway between the modules and the internet router, and has increased the signal strength by a large factor.

I'm curious if I'll notice a difference in reliability, it would be pretty hard, since the system has been really reliable lately. The Switch Module usually had the most problems, so that's where I should notice it most. I think that's because it is located tucked out of the way, where the other modules are out in the on on a shelf.

Hmmm, what else do I have tucked away here that I might be able to use... 

Water Sensor Washout!

Posted: 1:45am

Some time ago I picked up 10 of these Water Sensors from an online retailer in China.

I only paid $0.35 Canadian each for them in October last year (2018) and now they are $0.52 each, plus $1.19 shipping...

Tonight I pulled them out, thinking they might be useful for keeping track of the water level in the jug used by the automatic clone mister.  With something monitoring the water level, I pretty well don't even need to pay any attention to the clones until they root.

They are simple analog sensors, give them 5v and read the S pin with an analog pin on your arduino. 

I hooked one up, configured it in the system, which was made much easier because of the modification allowing me to define a set of "calculation id's" that tell the system which calculation to use when converting the raw numbers to something useful.  I just had to add a new sensor type, and tell it which calculation to use, then add a sensor and tell it what type it is (water sensor) and which module/port it's connected to, and assign it to a plot, which in this case is a virtual plot (not assigned to a specific plant)

First off, it read pretty well the same value no matter how much water it sat in. Because I only enable power to the sensors when actually reading them, to prevent corrosion from electrolysis, the power comes on and I read the sensor 100 times and take an average, then turn off the power again. That's done using another digital pin to switch a transistor.  This switching behavior is configurable, so I went and configured it to stay powered up all the time.  That didn't work very well, I'm doing this on the new firmware for the sensor modules, and the power didn't get switched on at all!  So, off to find and fix the bug..

Found it, fixed it, and now the sensor stays powered all the time. I'm thankful this sensor has a power led on it, I was able to know that it wasn't receiving power, I didn't have to get my multimeter out.

I played with it for about an hour, trying different depths, even calibrating it like the soil moisture sensors...  The end result?  First off, it will only measure about 1.5 inches depth, anything higher, and the electronics on the board are under water. If you mount it near the top of the container, then it will read empty after 1.5" is gone, so the size makes it useless for my application.

I couldn't get stable readings from the sensor at all, it really had no bearing on the depth, either reading 0, or around 640 when the water was at the top, but anything in between from a couple mm to 1.25" always read around 620.

So the range is too small (1.5") and the readings seem meaningless other than it's wet, or it's not wet. They say it is for measuring the level, but I think it's moree for just detecting the presence of water.

As for why I power off my sensors (that are in moist conditions) have a look at the corrosion on the water sensor on the right. It has only had power applied to it for maybe 20 minutes total, can you imagine running it 24/7? The one on the left is unused.

In this next picture, the corroded one is on the left... but I probably didn't have to tell you that did I? :)

While I'm not going to be using these for this task, it did give me an idea for a new feature to add to the code.  Now, either a sensor is always powered, or when it is time to read it, the power is turned on, wait half a second, then read it 100 times, take the average, and shut it off.  I'm going to make the initial wait time configurable, so with a sensor like this, I can say 1 second or 5 seconds or whatever it takes for the sensor to become stable once it is powered up. It will be a simple addition, just a little time consuming so I'll put it on my todo list, as it's not something I need now anyways.

As for measuring the water depth, simply hang two wires in the container, add a voltage divider, and you have something like a soil moisture sensor. I imagine some experimentation is in order, but it should work. The container for my mister is too small to use the ultrasonic sensor like I do on the Automatic Watering reservoir. Perhaps the mister could draw its water from there once it is installed, that would solve a few problems :)

Monday, August 26, 2019

Humidity and the DHT22

It turns out these temperature/humidity sensors don't like to be kept in a high humidity environment for very long.  I had one in my clone chamber, which was consistently about 28C and 90-100% humidity. That sensor now reads 99.9% humidity no matter what the actual humidity.  Apparently this is pretty common.  The good news is, they are only about $4 each, so I'll order some spares this time :) I wanted to create this post so I could share the link to some information on how you might fix it.  For $4 I'll skip the fixing and just replace them as needed...

Item #5 describes how to fix it.

Excerpt from

Item 4 is interesting, considering I keep one in each grow space, generally directly in the light, because that's where I want to measure the temperature...

OLED Display messes up my serial comms

If I try to update the display while receiving data from the ESP8266 on the hardware serial port, it drops incoming characters, so my CRC check fails, and it has to resend the data. That's not really a problem, since it will resend, but I hate knowing there's an issue...

I was updating the display every second since I display the time on it, with seconds... 

My first thought was I just needed a flag to check to see if it was safe to update the screen, and it just so happens that I have two flags I set while reading data from the serial port, so I know if I'm reading a tag or data.  By checking these two flags I can decide whether to continue and update the display. 

I figured if there was that much overhead in the display updates that it would cause an issue reading the serial port, I really don't need to update it every second. It would be nice if I'm standing there looking at it, but out of an entire day, I'll be lucky if I look at it at all, and certainly won't be to see the time...

I've changed it to update every 10 seconds now, and I'm going to remove the clock display.  I'm thinking of trying to display something related to the sensor readings... it would be nice to just glance at the screen and know if anything needs watering, or a temperature is off...

This won't be a high priority, but I'll work on that when I get stuck or frustrated with something else.

Sensor Module "Mega Shield" v2

In a previous post, I added an OLED 4-way mounting adapter to a new Sensor Module shield I'm creating.  Today I added the pins for the i2c header, and 2 digital ports. I can always add a couple more if I need them.

The I2C header is the black, red, green, blue pins.  The digital ports power is switchable using the transistors if desired

Do we need to be perfect?

Out of roughly 3,500 sensor readings being passed from the Mega to the ESP then on to the MySql server, only 2 records were not saved to the database.  That number is so small that I'm not even going to go try to find out why :)

That's only  0.0005% of the records had an issue, or as I like to see it, a 99.9994% success rate! :)

Sunday, August 25, 2019

I miss having whiteboards...

When I was working, we had an obsession with whiteboards, they were everywhere... almost every available wall space had whiteboards on it.  It made design much easier, write, erase, rewrite, draw lines, boxes, arrows...  Then once you have it all sorted out, you take a picture, and go to work....

The whiteboard was particularly useful to either design or understand software architecture. Since I'm in the middle of reviewing the Sensor Module software, and rewriting it, I sure could benefit from a whiteboard rather than trying to do it on paper.

I could use the whiteboard paint on the walls, but that's not overly appealing...  I need to buy some Panda Plastic anyhow, perhaps I can just hang a sheet, white side out, on the wall when I need it?

Maybe I'll get lucky and find a great deal on a new or used one somewhere... and even luckier to have the funds for it :)

For every problem, there's a solution!

Posted: 12:35am

I recently purchased two small .96" 128x64 OLED screens and the first place I used it was on my prototype Mega Shield where I discovered that the I2C pin-out has the clock and data lines reversed, so my "universal i2c" connectors won't work with it.  No problem, I'll put a "reverse wired" i2c 4-pin female header on the Mega Shield so I can just plug it in there.

That's not the problem though.  The issue is, if I am placing a non-standard (at least for me) connector on the Mega Shield, what orientation should it be?   It is a display screen after all, and I'll likely want to be able to read it.

Since the Sensor Module has power and USB connectors at one end, and analog sensor connectors at the other end, the orientation of the Sensor Module itself may change. Right now, I have it on a shelf, so the sensor wires can't go to the back, there's no room with the wall right there, so I have it with the sensor wires hanging off the front of the shelf.  In an ideal setting, it will sit with the sensor wires hanging off the back of a shelf or cabinet etc.  Sensor Module 1 actually sits sideways on a shelf with the sensor wires hanging off the side of the shelf.  Since the order of the pins dictate the orientation of the screen when I plug it in, I may end up with a screen I can't easily read.

That's the problem I'm referring to.  I did manage to come up with a solution, a universal screen module mount :)

On the bottom of the board are the 4 pins, in standard i2c order, Ground, VCC, Data, Clock. On the top of the board, which you can see, 4 female headers, each connected to the pins underneath, but all of them have clock and data reversed, so they all work with the screen. Once I plug this into the Mega Shield in whatever orientation it requires, I can plug the screen into any of those 4 headers to ensure the screen is oriented so I can easily read it... I'm still working on it, that's why there are wires coming out the back :)   I can see the need for one that will hold the screen vertical eventually, or maybe even just a cable and the ability to mount the screen somewhere else. Possibly even a larger version of this, but with some buttons, so you could scroll through a menu, or make selections for configuration. The possibilities are endless :)

Speaking of "standard" or "universal connectors, most actually do have standards, but a lot of what I'm doing involves coming up with my own "standards". For example, if there is no real standard to dictate the order, I always place ground on the right, then VCC, then whatever else there is. This way, I'm less likely to mess up the wiring.  

I'll update this post once I've installed this and know it works (or not)

Update: 12:37am

Just as I posted this, and did a final proof read, I noticed something in the picture...

On the prefboard, look at the top left corner... see that black wire?   These connectors are supposed to be Black, Red, Blue, Green, and the screen will plug in and cover the whole board, so the top connector in the picture is correct, black on the left, but you see the wire diagonal to the connector on the left, and it's connected to the top pin.  If you turn the board 90 degrees to the right, so that left connector is on top, the black wire will be on the right, not the left where it should be...  I messed up because I was working on the back of the board, and soldered the black wire to the left pin, but turn the board over and that pin is now on the right <sigh>

Easy fix, glad I caught it before I destroy something....

Ok, I'll be back...

Update: 8:00am

Ugly ugly ugly...   There wasn't much room for the wiring, considering all 4 wires needed 5 connections each...   I managed to get them hooked up, now I just have to add a connector to the Mega Shield and test it...

Left is top, right is bottom...

Update: 9:20am

It works!  Did you doubt it?  I did, after the last couple days...

I ended up soldering those pins directly to the shield, since adding another header raised the screen up too high off the board and made it wobbly... I expect the solder joints would end up failing before long.

Here it is in action!

As long as I don't mount the module upside down, I'll be able to read the screen :)

Another successful mini-project :)  Now back to trying to figure out why the new code for the sensor module isn't working properly. Once I find and fix it, I can install these shields on the live modules. I have this one, plus the original prototype.

Saturday, August 24, 2019

New plan for Module 2

I have the new Sensor Module "Mega Shield" and a new version of the firmware for the sensor module which I had planned on implementing, but due to the outstanding bugs, I've decided not to go forward with this until I resolve those issues.

So back to Module 2, and it's rats nest of wires...

Plugging stuff in at the back was a nightmare, the pins were so close together. The power wire for Port 1 has an intermittent failure, and its all hot glued to the case, so no way its coming apart with anything intact :(

Since I need to go back to this version, I decided to compromise...  No firmware update, but I've really cleaned up the wiring by adding a separate pcb with the connector on it, and the pins are now double spaced to make it easier to find the right pins, and to connect something,

It's back up and running now after two days without monitoring in the flower tent...  Gosh, I actually had to walk in there, unzip the tent, and check for myself.   Now I can relax again! :)

Friday, August 23, 2019

2 steps forward, one step back...

It never fails, when things are going well, strange things happen.  

The prototype "Mega Shield" I've been running here for days now without problem, suddenly doesn't work.   

I decided to take a break from building the new sensor module shield, and hooked up the prototype, planning to start some testing, and every sensor on every port was failing the initial power test. Eventually I grabbed the multi-meter and started measuring voltages...  

  • At the Port connector pins where the sensor plugs in, nothing, no fluctuation of the voltage when it is supposed to go high.
  • Next I measured at the transistor when it was switched on, nothing
  • Then I measured at the pin that switches the transistor, 5v
  • Then I measured at the BASE terminal of the transistor, 5v
  • If the transistor BASE is getting 5v, then the transistor should close the circuit from the 5v power supply to ground yet I couldn't measure any voltage through the transistor.
  • I measure the voltage from the 5v power module, it was 5v
  • Interesting, the digital pin to control the transistor is supposed to only go high when measuring or testing the transistor so that it doesn't promote corrosion of the sensor, yet is was reading 5v the whole time.
  • I pulled the shield off, and measured the voltage on the digital pin again, on the bare arduino, and it did switch on and off as it should....

So, something is causing the pin to stay high when the shield is attached.

Question: Why now? This was working yesterday, exact same software/hardware, no changes whatsoever.

Suspect: I feed 12v into the shield from a walwart, the shield routes that 12v to the VIN pin on the Mega.  That is within the 7-16v rating.  

Is it possible that my shield is either tying pins together, or causing a short, or sending power somewhere it shouldn't?  What else could cause the pin to stay at 5v even when set to LOW in code?

I thought maybe I had blown up all the transistors, so I pulled the shield off the arduino, applied 5v to the pin which connects to the digital pin on the arduino, in effect, mimicking the pin going HIGH, rather than the arduino turning on the transistor, I did it manually. To test the transistor, I simply measured the resistance between the collector and emitter as I applied power, and it went from a complete open circuit, to a short circuit, so I know the transistor is working, So, I hooked the shield back up on the arduino, and did not power the dc-dc converter, so there was no other power on the entire module except for the power on the USB connector...  The digital pin still measured 5v all the time, but the transistor never closed the circuit...   This is very weird...

The ONE thing that seems to make a difference is whether or not the shield is plugged in...

So, I just typed all this in, mainly for my own use, it helps me gather my thoughts and also acts as a reference I can come back to to see what I did, and what happened...  It also lets you see how I tackle these kinds of problems...   not overly efficient, but it has served me well over the years :)  

I'm confident I'll solve all these issues, and get to take 2 more steps forward!

Update: 5 minutes later

I plugged the sensor into the arduino without the shield, and it reads it ok...  The shield is really starting to look like the culprit...

Update: 10 minutes after last update...

Ok, I'm having another one of those days...

It's working now...  I was right, there were NO changes to the software or the hardware...  I DID change the configuration of the module and ports though because the new shield I'm working on routes different pins to control the transistors, so naturally, the configuration needed to change so it knew which pins to toggle... I knew that, but I changed it back before I even started, however, I entered even numbered pins rather than odd numbered pins as I should have...

Perhaps this isn't the best day to try debugging?  Oh well, I've got nothing better to do :)

Thursday, August 22, 2019

Sensor Module 2 Hardware/Software Upgrade

Posted: 8:00pm

Yesterday I replaced all the sensor wires on Sensor Module #2 which hosts the sensors for the Flower Tent.  There were a hodgepodge of wire types from really thin wire, that was part of a 20 wire ribbon cable, up to the speaker wire I'm using now.  I did this for a few reasons, but mainly because I'm replacing all the DuPont connectors with JST connectors which are much more secure. Another reason is the different qualities of wire probably had some effect on the readings,  plus having all the same type of wire looks much more pleasing :)

Ah, speaking of looking much more pleasing, you remember my sensor modules and their absolute mess of wires?

Above is Sensor Module #1 which monitors the Veg Area and Clone Chamber

This is Sensor Module #2. The White wires are the A0 - A15 analog inputs, and the Black wire is ground.  The Orange wires are hooked to digital pins D23 - D53 (odd numbers only). The Mega has a double row of digital pins along the bottom (top in this picture) and I'm using the outside row, hence only using odd numbered pins. All of these wires plug into a 3x16 right angle pins, but rather than soldered on a PCB, the row is hot-glued to the module case.

So I replaced all the wires leading from this module into the flower tent. It also meant replacing the connectors on the sensors in the pots.  It took me 2 days of on and off puttering to get that done, and once I had everything hooked up and plugged in, I noticed that the sensor on Port 1 was reporting a really low number, the soil was dry, and I remember that it was getting close to notifying me that it needed watering, so I just assumed that removing and replacing the sensor in the soil probably
affected the readings, plus with a new wire, perhaps the old one was a thin one... 

So, I watered the plant... and waited...  the sensor reading didn't change.

This is where the Blynk App on my phone comes in handy, because I can pick a specific sensor, and tell it to rescan it. The request goes to the maintenance server, which routes it to the proper sensor module, and then sends the result back to my phone. I can also calibrate the dry value (in air), the wet value (dipped in water) and the AutoWatering value, the level where it will automatically water the plant (or tell me to water it)

So I pulled the sensor out of the soil, and told it to rescan, same reading...
Unplugged the sensor from the wire leading to the module, slight change... not much
Unplugged the wire from the 10K Ohm voltage divider, no change

and so on...

Finally, getting nowhere, I grabbed the sensor, voltage divider, and the module itself and brought it back to my work space. I tested all the ports, they all worked except the first one.  I pulled all the wires off the arduino, and using breadboard jumper wires, I hooked the sensor/voltage divider up to the arduino directly, and lo and behold, it worked!

The wires themselves tested OK using my voltmeter to measure continuity, so I plugged them back in, and tested the sensor again, and it worked...   Great!  I started getting it ready to take back to the grow room, and it failed again :(  I got my meter out again and measured the voltage on the pins when it was energized (setting a digital pin HIGH and using it as a 5v source). It should be 5v, but it was about 0.14v ???  Huh?  I pulled the wire off and measured it, it was fine, so I started measuring from different places, and ended up discovering that wriggling the connector around where all three come together in a row for 16 inputs, would result in fluctuations on the supply voltage, so a bad connection in there...

This is one of the reasons I'm moving toward the "shield" or "backpack" idea.  I've been working on the new Sensor Module "Mega Shield", and really like the concept, especially adding the 5vdc power supply to power sensors and I2C devices.  I'm also using the digital pins to switch transistors now, which will provide power from the 5v power supply to the sensors rather than use the arduinos power.

I've tested the new board and it works, so I know the design is good, the transistor switching works fine. 

Rather than mess with all those wires, I'm just going to build a new backpack for Sensor Module 2. This one will have all the transistors mounted, the prototype is missing 4 of them.

I started on it earlier,a and have the transistors all mounted along with the resistors, and am working on the wiring layout to get all the pins routes to the right connections.  This got pretty messy on the prototype, so I think my new layout will work better.

The transistors are all lined up nicely.Because I spaced them out this time, they aren't stacked on top of each other, and there is room for the wires to get where they need to go.

Getting from the pins to the transistors was a mess on the prototype, but with the pins located at the end of the board instead of on the side, plus the fact that I removed every second set of pins, so the connectors are spaced out, it makes it so much easier...

These green wires are the 16 control wires, the digital pins which will trigger the transistors. They go to the center pin of the S8050 NPN transistor, who's pin-out is EBC or Emitter, Base, Collector.  In my configuration, the green wire will go to the center pin. The purple wire in the picture is from the Analog A0 pin, this is connected to the top pin on the row of connectors, which is the "signal" pin.

The center pin, actually the whole row of center pins will be hooked to +5v and the bottom pin will connect to the transistors Collector terminal.  The Emitter terminals are all joined together and connect to ground. In this configuration, we have the transistors AFTER the load (sensors), on the ground side, or LOW SIDE... This is because the transistors will cause a small voltage drop, so by placing the sensors BEFORE the transistors, we get the full 5v which is important, because we are referencing our reading against 5v in the ADC, or Analog to Digital Converter.

Here is top and bottom, you can see the wiring is not finished... 

The 16 Analog Ports take up the entire bottom edge, so I'll have to put some Digital Ports somewhere else, with their transistors and resistors, but I only need 4 of them, so I should be able to find room somewhere.. I also need to add the dc-dc converter to provide the 5v for the sensors. This one will not have a real time clock. It doesn't provide any benefit over simply syncing time with the database.
There will be no LCD or button to scan sensors, but I will be adding one of those nifty little OLED screens :)

So this is gonna take me the rest of the night to complete, maybe even longer, I'm not in a rush, and sometimes my tremors get so bad I have to stop for a while... Soldering isn't much fun at that point.

Update: 2:10am

What a mess!   I sure hope this works out like I envision it..

I've got 16 wires, and only 5 rows of holes to route them through on the outside of the arduino pins. I don't want to route them on the inside of the pins because I may need that room for other things. I'm running 3 wires per row of holes, and the final wire is on it's own...

Update: 5:30am

Whew!  I managed to get all the wires connected where they need to go, and it doesn't look too bad...

Here's the Top

and the bottom

The red wire will go to the 5v power supply once it is installed, also a ground wire will connect all the Emitter terminals on the transistors to the ground on the power supply, which will be shared with the Arduino as you always should.

Once I have the dc-dc converter (power supply) module installed, I should be able to plug this onto an Arduino Mega and test the ports to make sure they are wired correctly, and that the transistors are all good :)

I still have lots to do...

Wednesday, August 21, 2019

Restless night...

Posted: 4:25am

I can't seem to stay focused tonight...

I'm going through the code trying to figure out why it has problems with MySql, but only in two places... So as I'm following through some code, I get to the section that does the compare of CRC values in the payloads to see if it is a valid payload. 

Here's the code I found....

I marked the problem in red...   If you aren't a programmer, don't worry, you will still understand this...  bool means that this "method" or "function" will return a true or false. The method is called payloadCRC32IsOk, so you can figure out what it does just from the name.  This isn't really the problem, but if you want the method to return a value, you have to do so, with a RETURN statement, like RETURN true;

I modified the code, like so....

In green, we can see the GOOD things I did.  

  1. I created a boolean (true/false) variable called retVal.
  2. When the CRC does not match, I set retVal to false
  3. At the end of the method, I return the value of retVal, which could be either true or false

In Red, the mistakes, which I blame on cut and paste!

  1. Redefining the variables by placing a type (bool) in front means it is a different retVal than the one created at the beginning of the method, so whatever I set it to, this is not the variable that is returned from the method at the end.
  2. Same issue for when they do match, whatever this is set to will not be returned from the method.
  3. Also note, it would have returned false because I cut and paste and did not change it.

So I made those changes above NOT realizing the mistakes I made, and ran the code...  Disaster! Everything was saying Failed CRC Check...

Suddenly my heart sank... () I started thinking this whole rewrite was falling apart, and based on a false sense of security. I'm guessing that without any return value specified, it was returning TRUE since I never saw failed crc checks.  When I "fixed" it, and they were ALL failing, I just assumed that it was working properly now, and everything I had was wrong....

When I realized my mistakes, having now spent a couple hours fiddling with this, I finally fixed it, and here's how it is supposed to look...

No more failed CRC checks :)

Keeping track of ideas...

Posted: 3:00am

This is a different sort of post.  I've mentioned before that I keep a text file open in my Visual Studio IDE while I'm coding, so if I have an idea I can jot it down immediately...  It's absolutely true what they say about smoking pot, and short term memory...  and I smoke a lot of pot... lol

This acts as my to-do list, although it often contains thoughts that haven't quite coalesced into a coherent idea.  It's like my "idea incubator", I often just glance through it, add new thoughts, update previous ones.. it is entirely free-form, grammar and spelling aren't important. 

I'll even use it when I am trying to solve a problem, as I find that either writing it down, or describing it to another person (my wife is a good listener) I think it makes you go into more detail, and gives you insight you don't get by just thinking about it, at least I find that...

So, I said this post was a little different than the others, here's why...

My THOUGHTS.TXT file contents at the moment (it changes, lots, always)
Sorry if it doesn't format well...  if it doesn't make any sense to you, don't worry, it does to me :)

Each "thought" or "idea" is separated from the next with the line of equal signs....


if sensor test fails, it should not check alarms etc... just fail it
use new field, doNotLog - alarm code checks this before processing.


Display any errors - create array of messages, and keep a messageCounter
- in 5 second timer, increment messageCounter so next refresh (every second) will display the same message
      for 5 seconds, then the next, and so on. if counter = numberOfMessages then roll back to the first one.


8266 sends rssi with all payloads now, good... but if no payloads, then no updates.
need "lastpayloadtime" = millis when payload sent, if > X then send rssi

payload contains WAITFORACK tags?  <ACKME> :)

Only First four digital ports (17, 18, 19, and 20) will support DHT22
17=dht1 IF sensorTypeId=4
18=dht2 IF sensorTypeId=4
19=dht3 IF sensorTypeId=4
20=dht4 IF sensorTypeId=4
This makes it easy to know which dht object based on the sensorId
sensorId is mapped to a portNumber

clone mister - auto adjust over time,  day 1-3 every 5 min, day 4-7 every 10 min, etc
database is a mess, must clean it up!
Serial Terminal needs to be looked at, it locks up too often, 
and then bursts ahead. Would also like to process 1 char at a time instead of a line at a time but its so jerky

Switch module - should log clone misting so it can be confirmed.
- create table, any time a switch is "switched" it will be updated.
- maintenance module can monitor to ensure critical actions happen
Serial Terminal - tail debug log - get rid of autorefresh, add 
button to refresh. Load more lines, add scroll bars if needed
I'm thinking a table defining common math functions

1) A+B
2) A-B
3) B-A
4) A*B
5) A/B

So in the configuration for the sensors calibration, say for the LM35 Temperature Sensor, who's calculation is 

 Result = (X/1024.0) * 5000) / 10   where X is the Raw value read from the sensor.

Using multiple lines, this can be rewritten as:

Result = X/1024.0
Result = Result * 5000
Result = Result / 10

So if our configuration table allowed multiple lines per sensor, the record might look like:

wireless sensors for outdoor plants
solar charge battery oprerated
how long 9v battery last?

Even better, a battery powered sensor module in a weatherproof enclosure
to place in garden.
small solar panel to trickle charge
Lines of code Aug 8, 2019

autoWater2560 1960
autoWater8266 1488
maintenance 8266 2429
sensor 2560 3017
sensor 8266 3020
Switch 2560 2053
Switch 8266 1496
Webserver 8266 5301
Maint module
- min/max can be sped up by only looking at NEW data since last scan and compare to stored min/max
min/max table should include last logid of record scanned for min and max, so next time, 
we can scan > logid get the min a dn max, and compare those to the running min/max amounts.
Side effect of starting fresh log table, watering estimates no longer work until enough data is collected :(
Keep data in skinny table?
VPD: How Can Vapour Pressure Deficit Boost Cannabis Yields?
rpc server table - list each, with ip and rpc port...  assign id via commandline
add rpcServerId, and rpcServerComPort to module_ip table
If the existing com port is not valid, or points to wrong module, then option to choose another, 
and once connected, the module will update it
switch - mistSprayer
what about results or confirmation?  maybe water remaining? - can use water depth sensors I bought
Servo on switch module need more options...
Should be able to do the following
void servo.minus(degrees)
int   // degrees?