Watering tomatoes with a Raspberry Pi (7 Part Series)
At a basic level everything has been working for a few weeks now and the plants are all growing well and looking healthy. But two major, and probably related, problems have emerged.
Firstly the battery has run low several times, causing the charge controller to cut power to the Raspberry Pi to prevent over-draining the battery. We've had pretty dull weather and a fair amount of rain for several weeks so maybe the panel just hasn't been able to provide enough energy. But I suspect another issue.
The moisture sensors are corroding really quickly, lasting about two weeks before enough metal has gone to affect the readings. I think the fundamental problem here, and maybe in both cases, is I didn't build any switching into the circuit. All the sensors are powered continuously, even though I only read them very infrequently. There is a constant current flowing through those moisture electrodes powering a continuous chemical reaction with the water in the soil. Similarly the BME280 weather circuit is continually powered even though I only read it every 5 minutes. Reading takes a few milliseconds at most, so even if its energy demand is modest, 99.99% of it is wasted.
It'll be messy but I'm planning to add some additional circuitry using NPN transistors to switch the power to the sensors and control these from Raspberry PI GPIO pins - I still have a few left. A little code tweak would then switch the power on, wait an appropriate time for everything to settle, read the sensor and power it down again.
I've also attempted a few refactors of the code and run into Rust borrowing issues. I guess this is the normal Rust learning curve, but at times it has started to feel like hard work. One particular problem I keep hitting is iterating over one part of a data structure, accessing another part inside the loop - the iterator borrows the whole thing so I can't get a second borrow in the loop body. I'm sure there's a Rust idiom to deal with this but my searches have so far come up with nothing. Clearly I need to read more of other people's Rust code.
I'll update again on the performance of modified electronics. Time is running out before we head off on holiday for a couple of weeks and I need something I can rely on by then!
Claim your page on DEV before someone else does
Level up every day