OneWireArduinoSlave
OneWireArduinoSlave copied to clipboard
Same code works in Uno and not in Mega2560
Hello, I have something rather wierd.
I'm trying to join several arduinos in 1-wire network. I wrote simple test bellow to check stuff - it just checks device presense. It contains both code for master (BOARD_NUMBER=1) and slave(everything else).
Problem is, when I use Arduino Uno as a slave - it works fine. However when I upload the same code to Arduino Mega 2560 and use it in the same setup master node doesn't see slave (slave initialized though - printed it's address in serial).
(Tried both with receive callback and without one. Tried both Uno and Mega as master)
Relevant part (quite basic though):
#include <OneWireSlave.h>
#define PIN 2
#define DEVICE_TYPE 0
byte address[8] = {};
void generate_address(){
randomSeed(analogRead(A0));
address[0] = DEVICE_TYPE;
for (int i=0; i<7; i++){
address[i] = random();
}
address[7] = OneWire::crc8( address, 7);
}
void setup_onewire(){
//OWSlave.setReceiveCallback(&receive);
OWSlave.begin(address, PIN);
}
void setup() {
Serial.begin(9600);
generate_address();
setup_onewire();
Serial.print("One wire address: ");
for( int i = 0; i < 8; i++) {
Serial.print(address[i], HEX);
Serial.print(" ");
}
Serial.println();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
Full code: one-wire-test-code.txt
If someone makes it work on other boards that Arduino Uno (the only board I've tested), I'm interested to know ; but otherwise I can't help myself since I don't have the hardware to test, nor the motivation to work on it.
I leave the issue open so others can know which boards support are most requested.
I would also be very interested for a support for the ATMega2560 board!