Forums > MaxMSP

Reading i2c from Arduino? Maxuino?

October 12, 2011 | 2:34 am

I’ve dug around a lot on the forum and elsewhere and haven’t had any luck. I’m trying to figure out how I might read and make sense of data from sensors that communicate w/ i2c.

Maxuino has been pretty solid for me, and on their page they say "This allows Max to read analog and digital pins, write to digital and PWM pins, control servos, listen to i2c sensors and much much more."

Does anybody here have any experience or ideas for receiving and making sense of i2c sensors in Max?

Thanks in advance for any help.

October 12, 2011 | 5:21 pm

In my experience all the i2c stuff is handled by the arduino (or other microcontroller), then you send the data to the computer via serialUSB, or whatever other options the computer and the arduino can speak. All of the i2C stuff I’ve used have used the "wire" library on the arduino.

October 12, 2011 | 8:43 pm

Hmmm, so no Maxuino. I’ve seen some discussion of Firmata handling i2c, but apparently it doesn’t yet. Anybody else have anything helpful?

October 12, 2011 | 9:27 pm

There are a number of resources on the Arduino website that explain how to interface i2c devices using the Wire library

Additionally, there are several examples included with the Arduino IDE that deal with serial communication that contain Max5 patches (File>Examples>4.Communications).

October 12, 2011 | 11:07 pm

I’m pretty sure the i2c stuff HAS to be handled by the Arduino as it’s a communication protocol in and of itself. I copy/pasted the code from this to get it going:

Thankfully I have that magnetometer, but it gives you a good idea of what needs to happen.

(I found the arduino reference stuff REALLY confusing as it explains everything about wire/i2c, but in a non-practical way.)

October 13, 2011 | 2:57 am

Thanks all for your suggestions. I was hoping to stay in Max because I’ll be teaching this to people with no coding experience. But maybe I can figure out how to make it simple.

April 24, 2012 | 3:33 am


I’m in the same boat. I’m looking to teach a class and want to stay in Max and avoid a lot of hand coding w/ Arduino. I’ve also been using Maxuino for this purpose. I’d like to get them using gyro/magnetometer/accelerometer boards via i2c directly into Max. Did you have any luck figuring this out?

April 29, 2012 | 10:27 pm

i’m exactly in the same situation. ( @lostboy )
any idea guys?

thanks guys

April 30, 2012 | 7:15 am

Reading datas over IC2 with an arduino is quite straightforward but OT. Check the standard Wire.h library. Here is an example with the CMPS10 compass:


April 30, 2012 | 7:38 am

I think they’re saying they don’t want to do it IN Arduino, but rather, in max/maxuino.

April 30, 2012 | 10:38 am

yes guys,
i was talkin’ about doin’ it with maxuino.
but thanks for the info.
seems that i have to write the code in arduino to read all my analog and I2C sensors signals e use the serial object in max to read values.
Do you think is something complicated ?( given that i have some practice with c programming so the synthax seems very easy in arduino )

April 30, 2012 | 1:48 pm

It’s not (that) complicated, especially if you have pervious coding experience. My only coding was object oriented (max) when I got into Arduino, and I didn’t find it too hard to do.

I find using Maxuino to be real clunky either way. Much much easier if you just roll your own using serial object. (There’s a (seemingly buried?) tutorial on the c74 page for setting up an Arduino without needing Maxuino)).

April 30, 2012 | 4:56 pm

There are also the Communication examples that come bundled with the Arduino software, which include Max5/6 patches.

September 20, 2015 | 11:26 am

Hi again guys, I’ll reopen this old Forum. Do you have any idea now on how to use Maxuinto to read I2C protocol ? I cannot get my head around it, I am obtaining data from a breakout board with and L3GD20 Gyroscope and an lsm303 accelerometer and mangnetometer. I have the following code but I cannot manage to receive data in MAXMSP nor MAXUINO. Any thoughts?

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include <Wire.h>

// I2Cdev and L3GD20H 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 <L3GD20H.h>

// specific I2C address may be passed here
L3GD20H gyro;

int16_t avx, avy, avz;

#define LED_PIN 13 // (Arduino is 13, Teensy is 6)
bool blinkState = false;

void setup() {
// join I2C bus (I2Cdev library doesn’t do this automatically)

// initialize serial communication

// initialize device
Serial.println("Initializing I2C devices…");

// verify connection
Serial.println("Testing device connections…");
Serial.println(gyro.testConnection() ? "L3GD20H connection successful" : "L3GD20H connection failed");

//test endian functions
gyro.setEndianMode(not gyro.getEndianMode());
Serial.print("EndianMode: ");
gyro.setEndianMode(not gyro.getEndianMode());
Serial.print(" EndianMode: ");

// configure LED for output

// set scale to 250


void loop() {
// read raw angular velocity measurements from device
gyro.getAngularVelocity(&avx, &avy, &avz);
// int16_t x_single = gyro.getAngularVelocityX();
// int16_t y_single = gyro.getAngularVelocityY();

// //read X memory address directly
// uint8_t xval_l, xval_h;
// uint8_t devAddress = 0x6B;
// uint8_t regAddXL = 0x28;
// uint8_t regAddXH = 0x29;
// I2Cdev::readByte(devAddress, regAddXL, &xval_l);
// I2Cdev::readByte(devAddress, regAddXH, &xval_h);
// //read X memory addresses in single sequential
// uint8_t data[2];
// I2Cdev::readBytes(devAddress, regAddXL| 0x80, 2, data);

// Serial.print("Direct Mem Read: Xl: ");
// Serial.print(xval_l); Serial.print("\tXh: ");
// Serial.print(xval_h); Serial.print("\t");
// Serial.print("Direct readBytes data[0] data[1]: ");
// Serial.print(data[0]); Serial.print("\t");
// Serial.print(data[1]); Serial.print("\t");
// Serial.print("Bitshifted: "); Serial.print((((int16_t)data[1]) << 8) | data[0]);
Serial.print("angular velocity (dps):\t");
Serial.print(avx*0.00875F,DEC); Serial.print("\t");
Serial.print(avy*0.00875F,DEC); Serial.print("\t");
Serial.print(avz*0.00875F,DEC); Serial.print("\t");
// Serial.print(" x read only: "); Serial.print(x_single);
// Serial.print(" y read only: "); Serial.println(y_single);

// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);


September 20, 2015 | 11:27 am

Hi guys!

I need some help with this project…. i’m trying to read data from a Adafruit Breakout board wich consist of a L3GD20 gyroscope and a LSM303 accelerometer/magnetometer connected to an Arduino Uno board, which shows info in the arduino’s serial monitor, but i haven’t found any information about the I2C protocol working with Max/MSP, so i was wandering if some of you have any info about this. I’ve tried the Maxuino approach but i haven’t had any success

Thanks to anyone that can help i any way

Viewing 15 posts - 1 through 15 (of 15 total)

Forums > MaxMSP