I2C crashes code

Hey everyone!

I have found so much help in this forum so far, but tonight it is time for my own first post – I am really desperate!

The project I am working on uses recordings of vibration microphones to trigger LEDstripes. I used processing to analyze the sounds and pass on values first two one arduino, which then communicates them to two other arduinos via I2C, all arduinos trigger different lights. So far, so good.

Now, the I2C Bus is giving up on me and I don't know why. In a previous version, there was a lot of data running through the Arduinos, frequently changing floats for all the different soundtracks. I only made it to three tracks before the signals got to weak or seemed to get lost on the way. So I decided to transfer all that calculating business to processing, which now only sends simple values of a counter from 1 to 9 that will trigger the pins.

It worked great when I tried it with one single Arduino, but once I added the lines for the I2C communication, the program stops working (without any error message). When without the I2C, the LEDs shine when they have to on that one arduino, they stop doing so with the I2C lines in the code, needless to say that the other Arduino won't react either. Depending on where I added the lines in the code, not even the ground settings of my lights would shine. When I moved the lines a little down, the LEDs were at least on, but nor reactive.

And I just don't see why it would act like this. It had worked before with so much more data!
Please, can some one help?

Thank you so much in advance guys.

theNonProcessor.ino (919 Bytes)

theReceiver.ino (634 Bytes)

Why is soundSignal an int on one end and a byte on the other?

receiveEvent() is an interrupt service routine (ISR). Interrupts are disabled when it is running. You can NOT use delay() in an ISR.

There is NO point in making loop() wait with it's thumb up its ass for any length of time. You are not charged for every iteration of loop().

Q1. Can the delay() be called upon in the ISR by enabling the interrupt just arriving at the ISR?

Q2. Is the interrupt automatically enabled when exiting the ISR?

Good morning guys! Thank you so much for taking a look and replying.

I hope I am understanding you right now. First, the soundSignal byte/integer: I have tried so many things to solve the problem, one of which was changing the data type back and forth. I must have forgotten to change half of it back. Now that I did, the problem still exists, sadly.

I have had a delay in ISR in my previous code too, as I wanted to control the lights timing easily and it didn't give me any problems. I2C is still not working though after deleting those delays.

I am sorry @Golam, I don't think I can answer your questions... What does "interrupt" refer to? Not the ISR? Do you mean the interrupting of my code by the error?

Guys, it is working now! I will figure our what I changed and then let you know! Thank you for the input!!!

@miaparie

I am sorry @Golam, I don't think I can answer your questions... What does "interrupt" refer to? Not the ISR? Do you mean the interrupting of my code by the error?

You may consult this topic to acquire some idea on the meaning of 'Interrupting the Microcontroller and ISR'.

BTW: My questions of Post#2 are presented in respect of Post#1