1
\$\begingroup\$

I am trying to read various measurements with a raspberry pi 4. I decided to use an i2c bus to keep the wiring clean and easy. For a soil moisture measurement I decided to go with the SEN-17731. Somehow I cannot find any sample code nor registers I need to address with i2c.

On the website mentioned above only the following is written:

Our Qwiic Soil Moisture Sensor utilizes the I2C protocol with the existing signals and the ATtiny85 MCU as the I2C gateway, which does all the nitty gritty stuff for you. The default I2C address is 0x28. The Qwiic connector should be self-evident, and this board also has pins broken out for SPI programming.

Apparently this code is the firmware on the ATtiny85, since they listed the git repo under "Documents".

It which defines:

#define COMMAND_GET_VALUE 0x05

and later uses this within:

   if (command == COMMAND_GET_VALUE) {
    ADC_VALUE=analogRead(ADC_PIN);
    ADC_VALUE_L=ADC_VALUE;
    ADC_VALUE_H=ADC_VALUE>>8; 
    TinyWire.send(ADC_VALUE_L);  
    TinyWire.send(ADC_VALUE_H);
    command = COMMAND_HAS_BEEN_CHECKED;
  }

Tinywire seems to be an Arduino library (equivalent to SMBus for python?) but how can I address it from outside the Arduino Universe? Am I on the right path here?

EDIT:

Actually it's the same kind of problem for the GY-521 sensor, the only difference is that I found a source with sample code on how to use this sensor. Another difference is that the GY-521 seems to have a quite specific MCU which has a datasheet which describes the different registers to be addressed. Still, I don't find these information sufficient to write a complete python script... How is this supposed to work? Did the manufacturer only consider this to be used within the Arduino Universe and whoever wrote the python code example just reversed engineered the library?

\$\endgroup\$
6
  • \$\begingroup\$ SparkFun Qwiic Soil Moisture Sensor - US$10$9.50 sparkfun.com/products/17731 (1) The Sensor is a simple breakout for measuring the moisture in soil and similar materials. It is pretty straightforward to use. The two large, exposed pads function as probes for the sensor, together acting as a variable resistor. The more water that is in the soil means the better the conductivity between the pads will be, resulting in a lower resistance and a higher SIG out. / to continue, ... \$\endgroup\$
    – tlfong01
    Commented Aug 14, 2022 at 5:19
  • \$\begingroup\$ / continued; ... (2) To get the sensor functioning, all you will need is to connect the VCC and GND pins to your Arduino-based device (or compatible development board). You will receive a SIG out, which will depend on the amount of water in the soil. (3) Note: Check the Hookup Guide below for assembly and weatherproofing instructions, as well as a simple example project that you can put together yourself! (4) (4) Capacitive moisture sensor electronics.stackexchange.com/questions/522956/… \$\endgroup\$
    – tlfong01
    Commented Aug 14, 2022 at 5:19
  • 1
    \$\begingroup\$ As I said, due to wiring etc. I wanted to use I2C, that's why I opted for that version of the sensor, otherwise I would have chosen the analog \$\endgroup\$
    – shoj
    Commented Aug 14, 2022 at 5:26
  • 1
    \$\begingroup\$ If you follow down the Qwiic rabbit-hole, then under sparkfun.com/qwiic#resources you have sparkfun.com/news/2958 which is Python for SparkFun's Qwiic Connect System, which promises to be able to allow to discover devices and construct their driver objects. Python allows good introspection, so even if you don't use it for the final system, it could be a good way of reverse engineering what you have. \$\endgroup\$
    – Neil_UK
    Commented Aug 14, 2022 at 6:01
  • 1
    \$\begingroup\$ @tlfong01 I cannot see anything useful in this datasheet since the ATtiny is multipurpose. Compare to the datasheet from the GY-521 (see EDIT) \$\endgroup\$
    – shoj
    Commented Aug 14, 2022 at 17:05

1 Answer 1

1
\$\begingroup\$

Some of the text quoted is not for the I2C version of the device.

Take a look at the sample code here

You can see the 4 commands that you can use and how to use them.

#define COMMAND_LED_OFF 0x00

#define COMMAND_LED_ON 0x01

#define COMMAND_GET_VALUE 0x05

#define COMMAND_NOTHING_NEW 0x99

While it is an Arduino universe .ino, you should be able to see how to write a comparable program with the Raspberry Pi 4.

-hope it helps

edited to add: You are on the right track and the code you posted is, as you noted, for the on board firmware. The linked example is how to communicate with that firmware.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Thanks for your answer, okay then (see EDIT) I suppose that it is meant to be reverse engineered in my case. \$\endgroup\$
    – shoj
    Commented Aug 14, 2022 at 17:07
  • 1
    \$\begingroup\$ shoj said "Thanks for your answer, okay then (see EDIT) I suppose that it is meant to be reverse engineered in my case." - Yes, basically, but if you look at the ATtiny code (which yu quoted), it basically just returns a 16 bit ADC value, so there is not much reverse engineering that needs to be done. Still, it takes some load off of the Pi as you can query it and see if it has been updated and turn an LED on and off. \$\endgroup\$
    – DrG
    Commented Aug 14, 2022 at 18:03
  • 1
    \$\begingroup\$ Take a look at the 3 schematics for these probes learn.sparkfun.com/tutorials/… - yours is the last one. These are, essentially, voltage dividers where one end is the resistance between the probes which varies with moisture. You read the voltage with ADC and yours has the ADC on-board (the ATtiny). I guess it is 10-bit]. There is no specialized moisture sensor at all, just the resistance between two probes. Your device simply does some work for you and allows you to get that digital number corresponding to the ADC via I2C. \$\endgroup\$
    – DrG
    Commented Aug 14, 2022 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.