This library implements a way to get values from l3g4200d.
Calibration is suggested to get more accurate parameters.
Setup parameters are stored in file l3g4200d.h
This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 1MHz.
Code
Notes
- read risk disclaimer
- excuse my bad english
hey! This is great work for L3G4200 gyroscope. So i need to use this library on my AVR-5 compiler. How can use this? Please give me a tip. (Actually I tried to work on AVR compiler, didn't work. Only just stopped whole my programm)
ReplyDeleteTo me the simpler way of working with atmega is Eclipse + AVR plugin for Eclipse + avrgcc as compiler, or AVR studio. But i prefer Eclipse.
DeleteIf you use other than avrgcc compiler i suppose you should port this code to your compiler.
Anyway, using Eclipse for AVR is really simple, you can just google around here and you will find a lot of tutorial on how to do it.
I suggest you to start from a simple "hello world" blinking led, just to see if your compiler works ;)
Yeah! My atmel processor's compiler is AVR studio. Recently I installed Eclipse+ Avrplugin. I couldn't find out how to import L3G4200 gyroscope's C code, header file to my eclipse C project. Could you give a all completed L3G4200 gyroscope C projecd based on Eclipse?
DeleteMake a src directory.
DeleteImport all code files. Compile. It should be as simple.
Anyway, just send me an email, and i will reply you with my eclipse directory for this project.
You have got mail.
Deletehello, sorry for the inconvenience, but I have a problem with i2c_readNak and i2c_readAck twimaster.c library functions. The problem is that they do not return the call to the function i2c_readAck and i2c_readNak, ie remain in the whille (!(...)); and never leaves donot how to fix it, I could help? Please. Thank you.
ReplyDeleteHello, it could be hardware or software problem. Double check your wiring. Check that the hardware (your board), works on other software, like an arduino board. Also check that you write the code and compile it with the same frequency FCPU settings. If you have logic analyzer, you could also try to inspect the I2C line. Try to define a SCL_CLOCK at 10000L or 50000L if you are working at 1Mhz. Check that you have selected the correct device I2C address "(0x68<<1)" or "(0x69<<1)" depending on the SDO pin. As datasheet states, to enable the I2C line, CS has to tied high.
DeleteI'm using avr studio 4.15 and WinAVR avr_gcc
ReplyDeleteHI good library. How do you convert the data to angles?
ReplyDeleteRaw data it is converted to deg/sec, angular velocity. Not to angles. If you look at the datasheet you will find the Sensitivity parameter for this IC. You can use this parameter to convert raw values to deg/sec. Look at the l3g4200d_getdata function to see the conversion forumla.
DeleteHi davide, how do I know that the raw data are correct?
DeleteLooking at the datasheet, if your IC is not damaged, you should have +-2% error. Also, if you calibrate the gyroscope, you can reduce this error.
DeleteHi I get these values without using offset and calibration
DeleteX: -8192 Y: 17376 Z: -8192
X: -7864 Y: 17367 Z: -7864
X: -8192 Y: 17376 Z: -8192
And this when I roll it on the X-axi
X: -20644 Y: -15228 Z: -20644
X: -20644 Y: -15228 Z: -20644
X: -20644 Y: -15228 Z: -20644
Can it be correct?
Shouldnt it be 0 when its still?, the data are jumping all over the place
DeleteConsider that, even if you have setup the sensitivity to 250 dps,
Deletea raw value of of 8192 it is converted to: 8192*0.00875
= deg/sec, more than 50 deg/sec, which is too much for a still device.
Check with a logic analizer what's going on the bus, and compare the reading with the value you get.
Check that the IC is well initialized. Double check your wiring. Check that you F_CPU it is well setted up. Check you IC with other hardware, try it on Arduino as example. Just to prove that you IC works.
Shouldnt it be 0 when its still?, the data are jumping all over the place
DeleteI want to ask a question,
ReplyDeletewhat differrent about getrawdata and getdata?
Hello, the getrawdata return raw data (not converted, as it is read by the data registers), get data return converted to deg/sec data. Hope this help.
Deletehi I have a question, do I connect SDA (gyro) to SDA (atmega) and then both to VCC through 4,7k resistor?? Same with SCL and do I have to connect SDO somehow?
ReplyDeleteHello, you are right SDA to SDA of your micro, SCL to SCL of your micro, then one pullup 4k7 resistor for each bus to VCC. SDO unconnected.
DeleteI compiled your code and it has no errors :) although nothing happened after uploading it to my ATmega8, I'm using USB-UART FTDI converter and Realterm Terminal to watch data on PC and nothing, I have also this avrdude: warning: cannot set sck period. please check for usbasp firmware update, but I've searched for solutions online and ppl said to ignore it basically. Dunno if to invest in some analyzer or try sending some text via your program to PC.
ReplyDeleteHello, at first just use the uart library to check if the code complies and output a simple message to your serial. Something like this should emit a message to your serial output
Deletefor(;;) { uart_puts("Test\r\n"); _delay_ms(500); }
Uart worked! :) I changed baud rate to 9600, bcs i remembered it as more "bulletproof" when I built my tachometer, but nothing happens if I "uncomment" l3g4200d_init() and I'm wondering what now. I see on your schematics that AREF of ATmega is connected to VCC, is it really necessary?, also do I have to connect VIN of my gyro to VCC? I believe that your code is perfect after reading it, but what do you mean by typing: "adapt the SCL and SDA port and pin definitions and eventually the delay routine in the module i2master.s? (why ".s" though), do I have to find some info in my datasheet and implement in your code in i2cmaster.h? And finally do I have to uncomment int main (void) in this header? Sorry for my amateurishness xd
ReplyDeleteHello. AREF is not needed for this project, you can leave it unconnected. I do not know your module wiring, what's the VIN pin? "adapt..." that is Peter Fleury, cause the i2c library if from him. I suppose he mean to change SCL and SDA port and pin when you are using the .s module (which is the assembler versione of the i2c libary I'm using). Do not uncomment the main, that is a library example. I suppose you do not have a logic analyzer, so you have to debut if by uart, test it putting debug poit in the init function. One think it may be is a wrong L3G4200D_ADDR.
DeleteHmmm is there a chance that I broke the gyro by connecting VCC to 5 [V]? do i need some pull-up resistor?
DeleteIf your module does not support 5V, yes. I mean, if your module did not have a 3.3V voltage regulator you may have burn the main gyro chip, which works from 2.4v to 3.6v. No pull-up resistor is needed on the VCC input.
Delete