I am a newbie to the raspberry pi world, but for the longest time I have wanted to make my own plant watering system. As an engineering student, I want to use this opportunity to learn more about how to hook up devices and use python to make my own flexible system. I have therefore not purchased the complete smart garden package, but rather couple of capacitive moisture sensors, «Pi2Grover Pi Hat» and «Grove 4 Channel 16 bit ADC».
I have used this tutorial www.switchdoc.com/2020/06/tutorial-capacitive-moisture-sensor-grove/ and gotten everything to work up until the part about generating percentage of the moisture readings. I struggle to understand where this code snippet goes and how to put in my moisture readings into it. I’ve tried to save it as its own script, but nothing happens when I run it by itself.
Code snippet in question:
# scale for capacitance sensor 1 def scaleMoistureCapacitance1(Moisture_Raw, PlantNumber): # do the varying scale of the moisture for Capacitance readers # do the varying scale of the moisture # based on 10 bit values # > #0 100% # = #1 0% # scale to 0% from there # if (Moisture_Raw < config.Capacitor1SensorCalibration[PlantNumber]): Moisture_Humidity = 100 else: Moisture_Humidity = ((config.Capacitor1SensorCalibration[PlantNumber] - Moisture_Raw)*100.0)/(config.Capacitor1SensorCalibration[PlantNumber] - config.Capacitor1SensorCalibration[PlantNumber])
if (Moisture_Humidity < 0): Moisture_Humidity = 0.0
Thank you for the reply. I finally found the code on GitHub. Turns out I was looking in the wrong rep.
I have another question to the same setup:
As I mentioned, I have a raspberry pi 4b with a «Grove I2C 4Ch» ADC connected to a Pi2Grover hat. I have a capacitive soil moisture sensor connected to the ADC and a 5v relay that is connected to the GPIO on the RPI. The relay is connected to a small water pump that is powered by a 9v battery. Everything runs smoothly and I get good readings from the sensor until the relay kicks in. Suddenly values start to drop and I get an error that says:
Error accessing 0x48: Check your I2C address
«sudo i2cdetect -y 1» tells me that the connection is there.
Here is where it gets weird:
If I turn on the relay without it sending power to the pump ( the battery pack has an on/off switch), I2C connection is good. If I however switch on the battery pack so the pump pumps, I lose connection after couple of iterations of the loop.