I2C soil moisture sensor's calibration using Micropython

I would like to use the Micropython library and did not see any code in Micropython related to the sensor’s calibration. In fact, I saw the following lines in its library:
def moisture(self):
return self.get_reg(0, 2)

What can I do to read the humidity in percentage using Micropython with ESP32?

There are multiple Moisture Sensors out there and you did not indicate which one you are using.

However, what you posted will more then likely error without its CLASS object. The statements are only a snipit of python code from the Class Object.

def moisture(self) statement is the definition statement of a method within the Class called “moisture” with no parameters, the (self) is not a parm, it is used within Class Objects to indicate to the Class it can be called within itself. Usually once, at Class Initialization time of the Object, as python parses the statement into byte code and prepares the class in memory for later calls. Since SELF is used for this purpose, the statement is a snipit of code from a Class Object.

return self.get_get_reg(0,2) statement again, is also a snipit from a Class Object. It is the statement that would cause logic to be returned back to the Class caller module, and returning a value that was fetched via another method within the Class named get_reg which requires two parmameters that would require that method to be posted in order to know exactly what parm1 and parm2 would be referencing with those value numbers.

What is missing is the entire Class Object, and the get_reg function that is defined within that Class. Without all that, the two statements will error hard, or if trapped via some higher level TRY/EXCEPT statements previously, not halt and just fall thru logic, being ignored.

Search for the Python Class Object for the particular moisture sensor you are using. Two snipits of code will not cut it.

Acigan International