Problems with IMU via I2C + Bluetooth

Hi

I've been poking around with a bluetooth module and a 10DOF IMU.

I've managed to send the joystick values (from a gamepad connected to the computer) to the arduino via bluetooth using Processing, and to read the inclination angles from the IMU using this Kalman filter.

This was done in two separate projects, while I tried to learned how this works (still unsure if it's the best approach, but it was working.... until now). When I merged the two projects, it stops working. The Wire.endTransmission() returns an error 4. I read somewhere this may have to to with too much interrupts, but i'm not sure.

I read the bluetooth values using just this:

  if (bluetooth.available() >= 4) {
    last_command_time = cur_time;
    stick_l.x = bluetooth.read();
    stick_l.y = bluetooth.read();
    stick_r.x = bluetooth.read();
    stick_r.y = bluetooth.read();
    bluetooth.write('A'); // Asks for values (The processing code sends the new values when it detects an incoming byte from the arduino)
  }

Where bluetooth is a SoftwareSerial port.

Can anyone help em troubleshoot this? And if someone has a better way to send the computer commands to the arduino via bluetooth, it is also welcome. This way sometimes the leds flicker, meaning it isn't transmitting flawlessly :s

Thanks in advance :slight_smile:

Hi Volpix

Can you post your complete program, please. Attach it using the "additional options" button if it is too long to fit between code tags.

And can I check I understand the configuration?

Joystick -> computer -> Processing program on computer -> bluetooth on computer -> bluetooth module -> serial -> Arduino.

IMU -> I2C -> Arduino -> Kalman sketch on Arduino -> then where?

Thanks

Ray

Yes, the configuration is like that. For now the Kalman values go nowhere, they will be used later in the PID (this is the very basic start of a quadcopter, depending on how it goes. For now is just a bunch of LEDs :D)

I have attached both the arduino and processing sketches. I'm sure this isn't the best way to communicate via bluetooth, but I don't know a better one (yet, at least).

EDIT: Just realized the gamepad commands aren't being received in the correct order, for some reason. I got to find a better way to send them via bluetooth. But the previous problem still stands.

imu_and_blu.zip (614 KB)