Attempting to interface DFRobot Tipping Bucket with Particle Boron

Hi all,

I am currently trying to interface a Particle Boron with the DFRobot Tipping Bucket. This product’s wiki includes I2C and UART code and associated libraries which I have been using in Particle Workbench in VS Code. I have attempted to modify the arduino style code to match this IDE and have had no success of the Boron even initializing the rainfall sensor… it is as if it doesn’t “see” it. I have listed a few things I have tried in order.

1. I have directly copy and pasted the rainfall library and I2C code linked in the rainfall sensor's wiki.

2. I have edited portions of the code to align with Partice VS Code instead of using Arduino IDE. There has been no success with multiple edits. I keep recieving this error “Sensor Init Error!!”. This is true when I use UART too.

3. I moved forward with an even more simplified code to determine if these two electronics were even talking. No success.

4. I created a fresh project that simply scanned for an I2C connection from the Boron to Rainfall sensor which came up with nothing. It seems as if the boron does not even “see” the rainfall sensor after multiple attempts.

I will attach a wiring diagram of what I have done so far. In the diagram it shows I use 4.7 pull up resistor which I have tried, but I have also tried a 10K pull up resistor.

I am also working on determining if this could be a DFRobot rainfall sensor problem.

Lastly, and another intersting point, is that I attempted to use a ESP32-S3 with the same code and libraries addresses in the DFRobot product wiki and it still gave me the error “Sensor Init Error”. I have tried two different electronics and a variety of edits to the code and libraries with no success.

All the help is appreciated! Thank you!

It should work. Your diagram for I2C looks correct. Verify that your wiring is correct and I2C mode is selected on the interface board. Then flash the I2C scanner firmware to your device to see if it can be see that way.

Hi, the sensor seems to have a switch that selects I2C vs UART at the bottom

Is it on I2C?

Best

@rickkas7 @gusgonnet Thank you for you quick responses!

@rickkas7 I reverified my wiring and it matched the schematic. I ran the I2C scanner from Particle docs and see this in the serial monitor "ScanningNo I2C devices found".

@gusgonnet Thank you for pointing this out. Yes I do have the gravity switch set on I2C.

I have switched out Borons too just in case it was a one off error but keep getting the same errors. It seems like it must be a hardware issue based on all the things I have ruled out or just some off incapability with this rainfall sensor?

Another thing I would try is to remove the pull ups you added. Their drawing doesn’t show any, so maybe the sensor comes with pull-ups onboard?

Other than that, I would disconnect everything then start from scratch, maybe a wrong wire or even a wrong breadboard (if you are using one).

Good luck!

@gusgonnet

Yes, I have done some complete hardware changes a few times with no success. If this helps give a picture… I have a Boron on a breadboard and M-M wires connected from the Boron to the F side of the rainfall sensor wires (wires on the left of this image).

Thanks for all the help!

ok, can you show pictures of your boron connected to the sensor, showing how the wires run?

@gusgonnet Yes, here they are! Let me know if you need better quality or angles.

Thanks for the pics, nothing stands out.

You said that you had another MCU (ESP32-S3). I would run the I2C scanner in it to see if it detects the sensor.

If it does not detect it, this is a bad sensor.

If it does detect it, I would switch the boron for another one (in case you had one, of course). One time I inadvertently burned the i2c on one device, still unsure how.

if you had another I2c sensor around, whatever type, you can connect it and run the i2c scanner from the boron to see if the i2c bus on it is working.

Thank you so much for the help! I will try this.

Alright I have tried with an Argon and still recieve the same issue. I have even tried to use an Arduino Uno which is recommended by DFRobot with no luck still. Based on all these attempts it seems right to assume it may be the rainfall sensor.

As a last attempt and on an MCU that you don’t care too much about, since it would be running a bit of a risk of damage, I would switch the sensor to UART mode via its switch and try the I2C scanner again.

Who knows? Maybe the switch is inverted or maybe the pcb is upside down.

But this is a risky move! :bomb: I’m not 100% sure of the consequences…

The tipping bucket will have a reed switch. You can count the pulses directly with an interrupt on the Boron and skip the I2C & it’s hardware. That’s what I’ve done in the past, works fine with a 1-second debounce.

Thanks for the advice! Does this mean you just used UART with an interrupt and debounce?

Seems like I2C is not working between Boron and DFRobot at all.

I just used 2 GPIO pins.


//    Connect Reed Switch to D2 (0V) and D3 (3.3V).  Use a current limiting resistor
pinMode(D3, OUTPUT);
digitalWrite(D3, HIGH);

pinMode(D2, INPUT_PULLDOWN);
attachInterrupt(D2, gotRain, RISING);

.....and.....

void gotRain()  { // Interrupt for Bucket Tipping
  if (millis() - previousRain >= (debounce)) {
    rainCounter = rainCounter + bucketValue;
    previousRain = millis();
  }
}  // End Got Rain Interrupt

I didn't get very sophisticated with the Coding.
I'm sure @gusgonnet could stretch this to at least 1,000 lines..... easy :wink:

Wonderful, thank you for the help. I will try incorporating this in my code!

Alright so here is the solution we found for interfacing DFRobot Tipping Bucket and Particle Boron.

/------------ DFRobot rainfall read adapted to Particle Boron--------//

#include "Particle.h"

#include "DFRobot_RainfallSensor.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

DFRobot_RainfallSensor_I2C Sensor(&Wire);

SerialLogHandler logHandler(LOG_LEVEL_INFO);

void setup() {

Cellular.off();

Serial1.begin(9600);  // UART to sensor

delay(3000);



Log.info("anything?");



// Initialize sensor

while (!Sensor.begin()) {

    Log.info("Sensor init err!!!");

    delay(1000);

}



Log.info("Firmware Version:\\t");

Log.info(Sensor.getFirmwareVersion());

}

void loop() {

// Log via Particle console

Log.info("Sensor WorkingTime: %.2f H", Sensor.getSensorWorkingTime());

Log.info("Rainfall: %.2f mm", Sensor.getRainfall());

Log.info("1 Hour Rainfall: %.2f mm", Sensor.getRainfall(1));

Log.info("Raw Tipping Counts: %lu", Sensor.getRawData());



Log.info("looping");

delay(1000);

}

Cool! did you find out what was wrong?

It seemed like adding this line off code was helpful but It is hard to say what the exact issue was. I did use the logHandler in other attempts with no results, nonetheless, specific to this chunk of code adding the logHandler helped.