I have a project with 2 Nano connected together driving a set of lights each, with the sequences played by the lights being determined by an external device (in effect its sending Serial communication through the USB) but only on one of those devices.
Only one of those devices is EVER connected to the PC by USB, but the program that will eventually start to talk to the connected Nano can't do so until its run through about 20 minutes of verification.
I cannot have any difference in the sketch that is running on the two Nanos, as the parts need to be interchangeable, hence the need for the
I'm hoping I might have missed something obvious, or overthought, but I can't see a Wire.End() or equivalent, nor can I see anything other than "You should only need to call this once" for Wire.Begin()
Is it possible to change to master in response to external stimuli? For that matter, can I have both devices initially joined as Slave on the same address, as they won't be talking until one of them gets poked into Master state?
I'm hoping I might have missed something obvious, or overthought, but I can't see a Wire.End() or equivalent, nor can I see anything other than "You should only need to call this once" for Wire.Begin()
First, there is a Wire.end() (attention: lower-case e) which disables the I2C hardware. There is no reason why you cannot call Wire.begin() multiple times (on the AVR platform). To change from slave to master mode you must call it with an argument:
pylon:
First, there is a Wire.end() (attention: lower-case e)
Apologies for the typo - invokedWire.end() and, strangely enough, works just fine! Thank you very much
It does seem happy for me to use Wire.end() then Wire.begin() and establish the board as master rather than passing 0
In case it helps someone later:
int I2C_Mode = 2; //Global, used to decide how to run other functions later in the code
..
..
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent);
}
int ReadSerial() { //Called on receipt of an RS232 command from the controlling non-Arduino
if(Serial.available())
{
if(I2C_Mode==2)
{
Wire.end();
delay(500);
Wire.begin();
}
I2C_Mode=1;
}
This doesn't seem to mention the Wire.end() function at all - my humble apologies if I have just .. missed it