Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
United Kingdom
Asked — Edited

Reading From An I2c Device

Hi there,

I've done some C programming in the past but only using notepad as an editor, so I'm trying to learn Visual Stuido and C#. I have a i2c device with a gyro, accelerometer and compass all on one chip and for now I just want to be able to read off values from certain registers but am a bit confused as to how the acknowledgements work.(I have read the linked article amoung others but I'm still unclear)
For an example I want to read from slave device (mpu3500 gyro - 7 bit device address 1101000), and read data from its address register 0x1D.

Heres what I think should be happening, it's just a rough outline of what should be happening is it along the right lines?

i2c.start() //start i2c bus

ic2.writebinary(1,1,0,1,0,0,0,0) // send slave address with lsb bit set to write

// slave should send acknowledge bit here, do I need do anything here in the program?

ic2.writebinary(0,0,1,1,1,0,1,0) // address of register with lsb set to write, dummy write.

//again another acknowledge sent from slave?

i2c.start() // Repeated start

ic2.writebinary(0,0,1,1,1,0,1,1) // address of register with lsb set to read

//slave should then send ack then 8 bits of data from register

Master sends ack? how?


Basically I'm confused with the whole acknowledge parts and how these are handled etc.

If anyone could shed some light on the subject I would be very grateful! Am I even on the right tracks?!

Cheers Tom

AI Support Bot
Related Content
United Kingdom
It's ok, Ive figured it out now.:)
Share:) I'd love to know what hardware you are connecting to and what your code was.
United Kingdom
Hi, the module I'm using is a RoBoard RM-146, it's got a LSM303DLH (3 axis gyro and 3 axis magnetometer) and a MPU-3050 (3 axis gyro) on it and so far it seems pretty cool.
I'm making an inertial navigation system for my uni project using it so unfortunately I can't really post much code as they check for collusion etc when we submit anything, however once I've finished and it's been marked I'll put the code up if anyones interested.;)
That's great! I'd certainly like to see:) Sounds like a fun project! Thanks for sharing
Hi Tom,

I am very interested in your code. I have the MPU-6050 which is very similar to the 3050 and haven't been able to get as far as you. But does your code require MS developer Studio or can it be run with the built in ARC C# script? I have no interest in the steep learning curve and expense for MS developer Studio.

Thanks much,
United Kingdom
Hi Bill,

Yeah you can just use the C# script in EZB to read values etc, mine started to run pretty slow if you make the program more complicated though so I'm going to go to studio but I'm just at the testing stage at the moment so its all good for now.

Basically you only really need to use the ,I2CStart(), I2C.Read, I2C.Write and I2C.Stop() commands for most things I've found so far, all the acks are handled automatically. So to start the i2c you would just type.


Then you can put what you want it to do.

Sorry I can't put my code up yet, its a pain but all our submitted work is cross referenced with internet content so it would flag up etc if its reused anywhere. If you put up some of your code then I'll try help point you in the right direction.
Thanks Tom,

That's helpful to know about the ARC C# script.

I see about difficulty posting code here. Any chance you could save an example to the public cloud?