Yes the setup runs completely. I found out that the bus hangs if I terminate communication by uploading new code to the board. I found a piece of code that releases the bus which works. See below:
#if defined(TWCR) && defined(TWEN)
TWCR &= ~(_BV(TWEN)); //Disable the Atmel 2-Wire interface so we can control the SDA and SCL pins directly
I want to push data from the slaves to the master immediately when they receive said data.
So that means, that each slaves becomes master directly after it has received data from the MKR. This is still a multi-master setup, even while you are avoiding collisions through a fixed protocol. The Wire library does not support multi-master.
But I also don't ...
Normal I2C addresses are 7-bit long. On the first frame of an I2C
transaction, the master sends an 8-bit byte containing the address of
the slave followed by a bit specifying whether this is a read or a write
operation. Some people tend to call “address” the whole 8-bit frame,
which causes confusion. Because of this, we end up having three flavors
of I2C ...
You pass flowreading to void getflows (int sensor, float range, float flowreading) as a value and therefore changing flowreading has no effect on the variable you pass to that function.
Instead, you need to do void getflows (int sensor, float range, float *flowreading).
With 2 shielded cables, separate for SDA, SCL no problem to go several meters.
I just connected 2 I2C devices on common shielded cables 6m long SDA, SCL
3.3V and GND on non-shielded cables
Successfully tried also computer mice shielded cables, it's about 1.5m working no problem
Pull up resistors approx. 4k7
You do some strange things that I, at least, don't understand (e.g. I don't see what you need posretry for), but you might have a reason for doing so.
But you don't reset posretry and pos, which means they will very soon be out of a reasonable range. At some point the int will actually overflow to negative values, which is definitely not going to work!
I had the same issue sometime back.I was able to get good results using the example given for the ESP8266 in the MPU6050 library itself.You can make the necessary changes starting from that sketch.Hope this helps.
Heres the github link to the library https://github.com/ElectronicCats/mpu6050