Does 1-wire work on any digital pin?

I have several Mega2560 boards and I need 1-wire devices. I can use only serial 3, pins 14 and 15. Will there be problems?

load the library,
designate the pin
make sure you have the correct pull-up
and try it out.

Why do you refer to "serial 3"? What has serial to do with "1-wire" devices?

I

Paul__B:
Why do you refer to "serial 3"? What has serial to do with "1-wire" devices?

Because it is really serial bus 3 what is free for Onewire. I have no idea how Onewire or 1-wire library uses Arduinos resources.

Unless you initialise serial 3, the pins are nothing more than simple I/O pins.

Paul__B:
Unless you initialise serial 3, the pins are nothing more than simple I/O pins.

Yes, I know. But do 1-wire devices work with those pins?

The 1-wire library is "bit-banged" in software AFAIK, which is to say it should work with quite any digital pin (as long as that pin is of course, not being used by some other function at the time).

Looking at the source, yes, totally bitbanged.

It doesn't even seem to use interrupts for the receiving part - it does disable interrupts frequently during operation (interestingly, from reading that code I learn that delayMicroseconds() still works while interrupts are disabled - I thought that function depends on timer interrupts?).

Any time-critical code - 1-wire, neoPixels, video - which means any that does not use a clock line, must necessarily disable interrupts - including timer interrupts.

There is a tendency to forget or overlook the fact that interrupts take time to execute, with two consequences:
You cannot expect an interrupt routine to execute within a microsecond, so delayMicroseconds() clearly cannot use interrupts in any manner. And to make it practical to use an interrupt in the "background" - the timer interrupt - it must take an absolutely negligible proportion of the time. One interrupt of a couple of microseconds each millisecond (and noting that the timer interrupt has to perform certain additional corrections to actually count milliseconds, so there is extra code involved) is just tolerable.

Interesting, I hope 1-wire the bit banged code isn't too slow.

wvmarle:
. . . (interestingly, from reading that code I learn that delayMicroseconds() still works while interrupts are disabled - I thought that function depends on timer interrupts?).

On AVR, delayMicroseconds() is implemented as an assembly coded spin loop without involving timers or interrupts. Source is in "./hardware/arduino/avr/cores/arduino/wiring.c".

LMI1:
Interesting, I hope 1-wire the bit banged code isn't too slow.

That comment is nonsense! The 1-wire protocol specifies actual timings for the data transmissions. The code must comply with these timings, and that is what it does. As I mentioned, the same applies to driving NeoPixels. There is nothing more to say. :roll_eyes:

LMI1:
Interesting, I hope 1-wire the bit banged code isn't too slow.

Or I hope the bitbanged 1-wire code does not slow other code too much. I am sure Onewire works as it should. But luckily, I don't have to do the programming.

Those couple dozen bits transmitted don't take much time.