Hello forum,
I found this read only thread which got me in the right direction in solving my failing probes on long cables.
https://forum.arduino.cc/index.php?topic=20574.0
I did what the contributors suggested and replaced the 4.7k resitor with a 2.2k one and it sends back a reasonable value, mostly just when I plug in the sensor, and then it sends back -127.
I use a MEGA with a total of 6 probes. The first two have cable of around 3 meters (works fine) the second pair is on roughly 8 meter cable (works fine) and the last set on about 18 meter cable, and its here that I'm having a challenge. I use CAT 6 SFTP cable and I doubled up one twisted pair to send 5V to the sensors and doubled up another pair to send GND.
I power these 6 probes with a DC converter that takes 12V from a continually charged 9Ah 12V battery and makes available 5A at 5V. The signal wires coming back from each probe goes to its own digital pin, from 2 and ending at 7. The two problematic (long) cables are on pins 2 and 3.
In the thread I mentioned above someone mentioned the need to change the onewire.cpp file, but this was back in 2009 and when looking at the current version (I use 2.3.4) it seems like these delays have been included.
If someone here could tell me if the current onewire.cpp is adequate to deal with long cable runs, or if I should change anything here, I would appreciate some advice. Also, if I need to change anything on the hardware side I would appreciate some guidance.
Thanks,
Hein
This is the onewire.cpp that I currently have:
void OneWire::write_bit(uint8_t v)
{
IO_REG_TYPE mask=bitmask;
volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
if (v & 1) {
noInterrupts();
DIRECT_WRITE_LOW(reg, mask);
DIRECT_MODE_OUTPUT(reg, mask); // drive output low
delayMicroseconds(10);
DIRECT_WRITE_HIGH(reg, mask); // drive output high
interrupts();
delayMicroseconds(55);
} else {
noInterrupts();
DIRECT_WRITE_LOW(reg, mask);
DIRECT_MODE_OUTPUT(reg, mask); // drive output low
delayMicroseconds(65);
DIRECT_WRITE_HIGH(reg, mask); // drive output high
interrupts();
delayMicroseconds(5);
}
}
//
// Read a bit. Port and bit is used to cut lookup time and provide
// more certain timing.
//
uint8_t OneWire::read_bit(void)
{
IO_REG_TYPE mask=bitmask;
volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
uint8_t r;
noInterrupts();
DIRECT_MODE_OUTPUT(reg, mask);
DIRECT_WRITE_LOW(reg, mask);
delayMicroseconds(3);
DIRECT_MODE_INPUT(reg, mask); // let pin float, pull up will raise
delayMicroseconds(10);
r = DIRECT_READ(reg, mask);
interrupts();
delayMicroseconds(53);
return r;
}