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!
Top comments (3)
In one instance I switched from
iter()
tointo_iter()
to change the first reference into a move.May not work for you in this case, but when ref and mut get out of hand don't forget copy/clone/move.
Update: I successfully modified the circuit board to control power to the moisture sensors with an NPN transistor and an additional GPIO pin. Power them up, wait a few milliseconds, read values and power down. The MCP3008 already has a chip select pin and according to the datasheet a 5 nanoAmp standby current, so I left it alone. Similarly the BME280 is 0.1µA so it should be fine too. Just need a sunny day to recharge my battery and I'll be in business again!
I’m using the AM2302 temp/humidity sensor, it’s cheap, accurate and only powers on reads. Maybe an option?