United Kingdom
Asked — Edited

Questions With Reading From Gyro Using I2c

Hi I'm trying to integrate gyro data to give angle of rotation but am having difficulty getting a high enough sample rate. For instance I've tried timing how long the following line takes to execute using the Diagnostics.Stopwatch


System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); 
timer.Start(); 

byte gyro_xvalh = ezb0.I2C.Read(gyro,0x1D); // read from x value register address msb

timer.Stop(); // 
MessageBox.Show(string.Format("Elapsed time is: {0}", timer.ElapsedMilliseconds));


Its around 60ms which seems a long time, I'm running and compiling the test script from the c# script in ARC. I could really do with a much faster read time as I want to get as accurate rotation angle as possible.

If anyone knows what the limiting factors are that are resulting in this delay that would be a great help.

Thanks

Tom


ARC Pro

Upgrade to ARC Pro

Take control of your robot's destiny by subscribing to Synthiam ARC Pro, and watch it evolve into a versatile and responsive machine.

United Kingdom
#1  

I've tried running it through VisualStudio by changing the code to


byte gyro_xvalh = ezB_Connect1.EZB.I2C.Read(gyro, 0x1D); // read from x value register address msb
etc

and now its taking about 1.4 secconds to read from 6 registers? Is ezB_Connect1 the wrong thing to be using each time? Is it reconnecting or something each time which is causing the delay?

Really stuck on this at the moment and need to make some headway so any help would be great.

PRO
Synthiam
#2  

Are you connected to the EZ-B when you run the code?

United Kingdom
#3  

Yeah thats with it connected, the test program so far is just a basic form with the pre made connect button out of the toolbox from the ezb.dll file and then a click button to run the code.

PRO
Synthiam
#4  

Are you receiving correct data also?

I ask because usually a high query time is due to communication timeout by not being connected or the i2c device having a slow response.

United Kingdom
#5  

Yeah the data seems to be ok, I used a similar method for getting a heading using a compass with tilt compensation combined with an accelerometer (all on the same RM-G146 module) but it wasn't time critical so I didnt look at the communication speed then. Would it help if I put some of the code up in case I've missed something simple? Thanks Tom

PRO
Synthiam
#6  

You can zip up your project and upload it as an attached file:)

United Kingdom
#8  

Any ideas? I've tried adding some pull up resistors but that didnt seem to make any difference? The wire to the device is reasonably long but its what came with the sensor (aprox 30cm). I've tired 1k and 4k7 but not 10k yet as I need to pick some up tomorrow.

United Kingdom
#9  

Ok I've just got an MMA7455 to check that its not an issue with my i2c device. A read from the x data register using the tutorial example is still taking 50ms so I guess thats as fast as I can expect? Whats the reason for this duration as I know using Arduino's etc you can get much faster readings in order to use gyro data properly?

PRO
Synthiam
#10  

On an Arduino, you program the microcontroller directly. With EZ-Robot, your computer speaks to the microcontroller over a wireless communication protocol - which introduces a delay.

There is a new firmware coming out with some enhancements to the i2c protocol. It will be quite a bit faster. Also, there is a new bluetooth module that will be on the store shortly with a faster communication speed.:)

Both of those will help you greatly:D