I have a project where I measure the water depth under a buoy using bluerobotics.com depth sensor up to 10m (I2C communication). A high power winch (40 A) is motorized through a polulu driver (Roboclaw) according to the depth readings of the sensor. I'm using an ESP32 to control the motor and obtain data from the depth sensor.
The problem is, that when the motor is actuated I get garbage values from the depth sensor.
We have tried to power the motor, sensor and microcontroller from deperate sources with joined ground but still get this problem.
I was wondering if anyone has any ideas I should check? We think this might be some sort of a communication problem or SoftwareSerial issue.
The first thing that comes to mind is interference from the winch motor.
Your diagram, that was oriented correctly by @xfpd, does not give a key to the label numbers. Best not to assume things. Is No12 an Uno, or ESP32? What is No11? Etc.
Also, could you please post a link to the actual sensor, rather than the general web site.
Link to the actual motor data sheet.
Hi! The sketch was before we changed a Mega to ESP32.
11 is a standalone IMU.
10 are for leak sensors which are disconnected currently
9 in a USB hub
8 is the depth sensor
7 is the winch motor
6 is the Polulu motor driver
5 is a diode
4 is a kill switch
3 is a fuze box
2 is an heatsnik
1 are batteries
The motor for the winch appears to be a high current brushed motor. They do generate a lot of interference.
I2C is a short distance protocol (as per its name) and is typically used for short distance communication only. It is not particularly robust in a noisy environment, since the signal is not carried on differential pairs.
I had initially though your depth sensor was an ultrasonic type stationary sensor!
Your diagram shows the depth sensor is connected to the winch. If that is the case, that poor I2C bus is having to travel along 10m of cable regardless of how much it has been deployed.
The Blue Robotics schematic shows no pull-up resistors.
If you look at the data sheet for the actual sensor, MS5837-02BA, it shows that for the I2C bus, min Vin is 80% of VDD.
Questions for you:
Is the depth sensor being lowered into the water?
Is the wiring wrapped around the winch drum?
What is the total length of the cable from the sensor to the ESP?
Where are the pull-up resistors for the I2C bus, and what values?
A bit more information on the system - it is basically a depth keeping water buoy.
The depth sensor is lowered 3-5 [m] underwater inside a waterproof case (marked bright yellow below) to be connected to an AUV so it needs to keep its depth while being exposed to sea waves.
We try to minimize the affects of the ocean waves on the underwater case using a depth sensor and a motorized winch.
The cable is wired around the winch drum on the sea surface buoy and passed through an IP68 slipring.
Total length of the cable including wiring on the drum is around 10 [m] from the water depth sensor to the ESP.
We use the following level converter, installed inside the underwater case:
I think this is the problem. 10m, so close to the motor is just not likely to work. There will be too much capacitance on the line, not to mention that that length of cable will also pick up a lot of interference.
I don't understand the need for the level converter (pricey, ones at Adafruit are like $4). Aren't you using an ESP32, a 3.3V part?
How are you supplying 5V to the pressure sensor?
Do you have access to an oscilloscope? It would really help to be able to scope the signals without the motor and with the motor running.
Some suggestions that may or may not work. Use one or more:
Use strong I2C pull-up resistors. You may be using 10k resistors (we still don't know), which is pretty common to find. Strong in this context means lower values. Try 2.2k or even 1k
SLow down the I2C bus speed. It may be set to 400k. Try 100k or even slower.
Use an I2C range extender chip such as the Adafruit LTC 4311 or the P82B715 or similar.
Use shielded cable, one each for SDA and SCL. The first wire would carry the signal, the second would be ground, grounded only at the ESP end. This could be telephone cable or Cat5 ethernet cable. The only gotcha is to not use solid conductor cable; it will crack with repeated winding on and off. You will need multiconductor cable. You may be able to find flexible cable used for industrial control. Some people have recommended ribbon cable. 6 conductors, with signal, GND alternating and VCC.
Put capacitors across the motor terminals to try and reduce interference: motor case to +ve lead, case to neg lead and lead to lead (3 in total).
HI,
Can you please post a schematic of your ESP32 project?
Please do not use Fritzy, a hand drawn image will be fine.
Include ALL power supplies, component names and pin labels.
Also some images of your project so we can see your component layout?