Having difficulty figuring out I2C. Where do I start?
tosjduenfs
Posts: 37
I'm trying to build a balance bot with stepper motors and the pololu AltIMU-10 v3 https://www.pololu.com/product/2469. I got my parts a few nights ago, I've got the stepper motors going using a square wave generator (since all I want to do is control the rotation rate of the motors as part of my PID scheme). I've used analog gyros and accelerometers before with other projects but this time I thought I'd skip the ADC and try using an I2C sensor. When I ordered it thought "how hard could it be?" now here I am after two nights of trying to figure out how to talk to this thing and I don't feel like I am much closer than when I started. I've gone through tutorials (mostly for other Microprocessors) and the datasheets and I read through them but I am still having trouble on where to start with getting data from this thing.
My goal right now is to simply read the raw data from the gyro and the accelerometer and display it into the parallax serial terminal. If I can get there I'll have just about everything I need to start. Can someone please point me in the right direction?
Regards,
Mike
My goal right now is to simply read the raw data from the gyro and the accelerometer and display it into the parallax serial terminal. If I can get there I'll have just about everything I need to start. Can someone please point me in the right direction?
Regards,
Mike
Comments
There is a spin file here: http://obex.parallax.com/object/335 for a similar gyro. May be a place to start. At first glance, registers seem to be the same.
Here's a link to the PEK tutorial.
http://forums.parallax.com/showthread.php/97625-PE-Kit-Lab-Applications-%96-EEPROM-Datalogging-and-I2C?p=678271#post678271
The Propeller's EEPROM is an I2C device. You can see how the code works to communicate with the EEPROM and apply the techniques to your sensor. One of the things which will be different is the I2C address.
Some I2C addresses are listed as 7-bit addresses and other include the read/write bit and use an 8-bit address. You want to make sure you know which type you're using.
1. It is serial communication, not parallel
2. It is synchronous, so it needs a clock line to coordinate the serial signal. (RS-232 is asynchonous, no clock)
3. It is a fancier synchonous serial than SPI.
4. It usually requires pullup resistors on some or all of its lines.
5. Actual specifics of I2C depend on the device that requires its use... so you have to read the IMU documentation in detail.
http://forums.parallax.com/showthread.php/159885-help-I2C-in-SPIN
Dave
Data is bi-directional so you have to switch DIRA often.
Clk is always provided by master, but slave can keep it low if it use clock stretching to signal it's not ready for more data etc
So even clk pin have to change DIRA if you want to support clock stretching
I2C - Bus Master - Step 1
https://www.youtube.com/watch?v=skkyudHHSWY
But there are many already made available in obex
Thanks you Dave I will check this out.
tonyP12
No I'm not trying to make my own driver. I've download pretty much all of the I2C drivers from the OBEX and looked through them hoping something would click in my head but I'm not there yet. I've slept on it now so I'm going to try reading through some of the drivers again to see if I can get anywhere. Mostly I'm confused about the the initial start of the sensors although looking through the data sheets it looks like the default settings will work for what I need. I'm also confused about reading multiple 16bit values (x,y,z) from a single request, the data comes in 8bit chunks and then I need to combine the bytes into the respective values for x y and z.
I tried to write the drivers to be as easy to use as possible. For 16-bit values, you need to determine how the data is stored, whether a value of $0123 is stored as $01, $23 (big-endian) or $23, $01 (little-endian).
For big-endian values, my drivers have a read_word method, for little-endian a page_read can be used.
This is it! I was looking at the data sheet for the L3G4200D and it has essentially the same registers as the L3GD20H i'm trying to use so your gyroscope demo is working for me. All I had to do was change the device address and I am getting data in the serial terminal. Thank you so much. I am going to study your examples. Now that I can actually see some output I think I can work from here. Thanks everyone for your input.
Mike
Mike