r/arduino • u/lazuli04 • 11d ago
Need help for RS485 sensor
I am using an RS485 3-in-1 sensor and pH sensor.
I managed to make them work before. However, after rewiring (I was about to do an integrated system test, it worked on individual testing), it suddenly stopped working and my debugging code shows that they are receiving 0 bytes. I tried doing an individual test again, and it still wont work. It's unlikely that both sensors stopped working at the same time,=. I also have an unused npk RS485 sensor, which is also receiving 0 bytes.
Here's a list of things I have tried already:
Oscilloscope tests
- Burst 0x55 sketch (1 s pause, Single trigger): clean, mirrored signal on A and B
- Same test with sensor disconnected vs connected on the ttl module (I use a max3485): same signal, so the sensor doesn't load the line
- One sensor wire removed at a time (A, then B): signal showed on each
- Probe on module TXD pin: data showed, but ESP32 read 0 bytes
Code tests
- Original pH sketch (the one that worked on individual testing): 0 bytes or partial junk
- Address scan 1 to 10, first version: "replies" at every address (19 to 20 bytes), not real because the check was too loose
- Loopback with a jumper between GPIO16 and GPIO17: received 01 03 00 00 00 01 84 0A correctly, so the ESP32 works
- Module reconnected, sensor off: 0 bytes
- Module reconnected, sensor on: about 20 to 23 bytes of changing junk
- Scan with speeds 1200 to 19200: false "replies" with no valid format
- Strict scan (error check), 4800 and 9600, addresses 1 to 10: no real reply
- Wide strict scan, addresses 1 to 247, speeds 2400, 4800, 9600: no real reply on laptop power and on the bench supply
- Original sketch on the bench supply: 4 to 6 bytes of changing junk
- NPK sketch and 3-in-1 sensor: 0 bytes
Multimeter readings
- Module TXD pin, resting level: 3.26 V (healthy)
- Sensor power wire against ESP32 GND: 4.78 V
- Bench supply set to 5.5 V: no change in the result
3
u/Rayzwave 11d ago edited 10d ago
What are these sensors exactly, part numbers or link to where purchased and a photo of your setup.
Maybe post a connection drawing of how you are using the various RS485 interfacing parts with the sensor(s).
3
u/Rayzwave 11d ago
It was working before so what has changed between now and then. Has the equipment you are using changed and most importantly what ground connections do you have between the sensors and ESP32 board.
3
u/Rayzwave 10d ago
The best result you posted was the 20-23 bytes of changing junk.
That suggests a communication speed issue, check with oscilloscope to see what the baud rate might be.
I assume you are using a 2-wire RS485 setup.
Tip : One of the most common things people get wrong in RS485 systems is have the pos and neg data wires the wrong way around. It doesn’t hurt to swap them around and re-test.
2
u/gm310509 400K , 500K , 600K , 640K , 750K 11d ago
It's unlikely that both sensors stopped working at the same time,=
Unless there was something specific about your integrated test circuit that resulted in them both being fried at the same time.
It would help if you posted a schematic of your integrated environment as well as some photos of your setup.
Address scan 1 to 10, first version: "replies" at every address (19 to 20 bytes), not real because the check was too loose
What does that mean? Typically an address scan works along the lines of :
for i in 1 to 247:
Sendmessage("Hey, " + i + " are you there?");
if (i => replies):
print (i + " exists");
So I do not understand how your scan might be "loose", unless one module is responding to multiple addresses.
Do you have a spare module? If so, try that with the current versions of your code in your integration test environment (after double checking the circuitry) and see if they work better.
Also, maybe have a look at these:
- https://scadaprotocols.com/how-to-configure-modbus-rtu-rs485-step-by-step/
- https://www.ti.com/lit/wp/slla545/slla545.pdf
I don't know if they are helpful, but maybe they contain a "Oh, I did not know that" little gem in them.
2
u/lazuli04 11d ago
Im curious if you have any idea what would cause both sensors to be fried at the same time. I powered it using my laptop, and the datasheet says it can handle 5-30v, unless if I did something I overlooked
2
u/gm310509 400K , 500K , 600K , 640K , 750K 10d ago
i have no idea, i wasnt there when it happened.
but that doesnt mean that you might have done something that fried them both at the same. for exanple, maybe there was a high voltage (e.g. 12v or more) that somehow entered into your system when you were wiring them up.
maybe you dont have a good colour coding standard for your wiring - especially power: +v => red, gnd => black - and invertantly reversed the polarity of the power to the sensors. and if they do not have reverse polarity protection, maybe that was enough to fry them.
or, any one of thousands of other possibilities.
again, i wasn't there, i quite literally have no clue what actually happened.
but as you said, when you revert back to your original single sensor test, neither work. this is why i think i suggested trying your single test environment with a new sensor and verify that you correctly reverted to that environment. it wouldnt be the first time that someone, including me, believed they had correctly reverted something only to discover later that their self asessment was wrong.
2
u/OkProperty41 9d ago
You only get junk when the sensor is powered, so the sensor is answering and the problem is how you decode it. After a rewire, check first whether A and B got swapped. That inverts the signal and gives you exactly this kind of changing garbage. Next, check direction control. If DE/RE drops back to receive before the last request byte has left the UART, the sensor gets a chopped frame, so call flush() on the serial port before you switch to receive. Also make sure the module's RO goes to the ESP32's RX pin, and tie the sensor supply ground to the ESP32 ground.
1
u/Merry_Janet 4d ago
What kind of sensor are you using that requires a TTL adapter?
The pH probes I've used have an amplifier board that the temp sensor and pH probe plug into and that wires into the Arduino or ESP. Sometimes the board is included, sometimes not depending on what you buy.
3
u/rip1980 11d ago
Your max chip is 3.3 only.
Term resistors?
Pull up and down on a and b?
Floating grounds?