How to receive I2C data in vvvv?

Hi there,

I have a question regarding the I2C decoding with firmata in VVVV.

I am trying to receive the data from the Triple Axis Accelerometer & Gyro Breakout - MPU-6050 https://www.sparkfun.com/products/11028. I am using the latest StandardFirmata_v2.3.3. https://github.com/firmata/arduino/downloads and the latest vvvversion 45beta29.2. Also I am using the Arduino Leonardo.

I don’t get any data from the I2CDecode node.

What do I have to do to get data out of this sensor? Does anybody has experience with I2C and vvvv?

So, after some more online research and try and error action, it seems like you can only decode I2C messages, with firmata, but not encode. Can anybody confirm that?
So if that is the case, do I have to send some custom HEX messages directly through the RS232 Node to the sensor, without using firmata at all?

Has anybody successfully done sth. like this? I would greatly appreciate any hint that leads me in the right direction!

hi jancouver,
as i am the author for the plugin, i guess it is me who should respond :) sorry for the response latency, as i am not too often on the fourm. i also got your message through mail from u7angel this morning.

i2c (copyrighted! be careful… two wire protocol is the free name ;) is a bit special when it comes to using small sensor boards with it. usually a device does not just send data. you have to tell it to do so. annoying in cases where everything arround you is realtime, i know. nevertheless, this can be done by the Firmata protocol, but sending i2c messages (configuration or other) to the board is currently not yet supported/implemented in the encoder plugin. This is due to design issues on how to deal with the special message formats of firmata, without having to write a lot of extra nodes. Sorry for the yet. it is currently priority on the feature list though. these special messages also include SHIFT out, stepper related things and servo configuration stuff. so in the future it will work, because the Firmata protocol does support this kind of messages. This gets another dimension, as i don’t or rarely have access to i2C devices, but tested with a stack of multiple Arduinos sending i2c between them. So lovely community donate some devices ;)

but this is the theory stuff behind it. to get you up and running with the current implementation, there are wo ways you could follow. either you should go hybrid with the question you asked. i think it is valuable to use FirmataDecode in combination with the I2CDecode to get your bytes decoded easily. But to initialize the reading from the sensor you must send a custom byte (a.k.a. Raw) packet to the board (which does still run the StandardFirmata). It is a bit hard to fiddle the message together, but somehow it should be feasible. The protocol message spec shows you what to send: http://firmata.org/wiki/Protocol#I2C The binary operator nodes i did a while ago can help you with the LSB and MSB stuff binary-operators But still, this approach is not for starters… Just to make it complete, as far as the Datasheet goes, the address of the chip is 0x68! This you will need for sending data to it as well as putting this (as decimal 104) into the Address of the i2c decoder node.
And yes, nothing to argue, this is definitely what the plugin should cover. Any help with the plugin code is much appreciated :)

Or, and this i think is the faster way, you use the Arduino Library which is linked from Sparkfun (https://github.com/jrowberg/i2cdevlib/tree/master). It includes an example on how to get the raw values (https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/Examples/MPU6050_raw/MPU6050_raw.ino). Given this example, you can then bake your own Firmata firmware, which should look something like this:

- include <Firmata.h>

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
- include "Wire.h"

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
- include "I2Cdev.h"
- include "MPU6050.h"

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

void setup() {
  // Enable Firmata as transmission
  Firmata.setFirmwareVersion(2, 3);
  Firmata.begin(57600);  

  // join I2C bus (I2Cdev library doesn't do this automatically)
  Wire.begin();

  accelgyro.initialize();

}

void loop() {
  while(Firmata.available())
    Firmata.processInput();

  // read raw accel/gyro measurements from device
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  // these methods (and a few others) are also available
  //accelgyro.getAcceleration(&ax, &ay, &az);
  //accelgyro.getRotation(&gx, &gy, &gz);

  // Send the values through firmata using its analog message format (for bigger numbers)
  Firmata.sendAnalog(0,ax); 
  Firmata.sendAnalog(1,ay); 
  Firmata.sendAnalog(2,az); 
  Firmata.sendAnalog(3,gx); 
  Firmata.sendAnalog(4,gy); 
  Firmata.sendAnalog(5,gz);

}

With this on the board, you can use the FirmataDecode to simply get your values which where (shamlessly) send as analog messages. This is what we did in the second workshop with capacitive sensing as the source of values.

Of course the Firmata plugins are not the only solution on how to get values from the Arduino to vvvv, but as you can see in the Arduino code, it is pretty straight forward + you don’t have to patch your own decoder + it saves you some bytes ;)

btw. the current Firmata version shipped with the Arduino IDE is perfectly fine. i2c has been in it since a couple of minor versions afaik.

Hi Jens,

Thanks so much for your response! This is very helpful! Fortunately I’ll have someone to help me with the Arduino side of this, so together with your links and code snipet, we should be able to get this to work. Thanks again for your thorough answer! :)