Shop OBEX P1 Docs P2 Docs Learn Events
Question to Parallax Regarding the Gyroscope Module — Parallax Forums

Question to Parallax Regarding the Gyroscope Module

Hello,

I was wondering if Parallax could develop a Learn tutorial on the Gyroscope Module 3-Axis L3G4200D in Propeller C. I am primarily interested in a tutorial in which SPI is used, similar to what was published for the MMA7455 Three-Axis Accelerometer. Others might be interested in seeing a tutorial for the Gyroscope Module with the I2C interface. Would it be possible to put together a tutorial for us?

Respectfully,
David

Comments

  • Do you teach a class or are you looking to learn this yourself?
  • Hi Keith,

    I'm looking to learn this myself.

    David
  • I have a library function for this device that you can have. It is setup to do I2C but could easily enough be converted to SPI which is actually a little easier to do than i2c.

    Mike
  • 1450f467a31c6a3bfbb5d03cbe01b1.png

    We have Blockly support for this sensor, which means we also have C code for it. You could click on "code view" and download the Blockly-generated code.

    Aside from this, what kind of tutorial did you want? Are you interested in exposing some of the more advanced features of this sensor?

    Ken Gracey
    Parallax, Inc
    703 x 632 - 46K
  • Hi Ken,

    Thanks for your reply. I downloaded the Blockly IDE but was not able to find the gyroscope sensor module, only the accelerometer module. I am looking for a tutorial that shows how to use the gyroscope module with SPI, similar to the tutorial here (which is for the accelerometer module):

    http://learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-protocols/spi-example

    I was not successful in adapting the SPI example for the accelerometer module to the gyroscope module. The SPI example is great because it displays the code and explains how everything works, while including sections on "How the SPI Test Works" and "Bit Masks for Better Code". I am a mechanical engineer and have never had formal training in programming/computer science so these Learn tutorials have been extremely helpful to me.

    Respectfully,
    David
  • Hi iseries,

    I would love to see your library for the gyroscope module.

    Thanks,
    David
  • Hi David,

    I won't pretend that PropWare is anything close to the Learn content - it isn't meant to be - but if another library implementation in C++ would be helpful then I can point you in the right direction.

    Here's PropWare's L3G implementation: https://github.com/parallaxinc/PropWare/blob/develop/PropWare/sensor/gyroscope/l3g.h

    And here is the demo provided with PropWare which uses the L3G: https://github.com/parallaxinc/PropWare/blob/develop/Examples/PropWare_L3G/L3G_Demo.cpp
    #include <PropWare/PropWare.h>
    #include <PropWare/gpio/simpleport.h>
    #include <PropWare/sensor/gyroscope/l3g.h>
    
    using PropWare::Pin;
    using PropWare::SPI;
    using PropWare::L3G;
    
    static const Pin::Mask MOSI = Pin::Mask::P0;
    static const Pin::Mask MISO = Pin::Mask::P1;
    static const Pin::Mask SCLK = Pin::Mask::P2;
    static const Pin::Mask CS   = Pin::Mask::P6;
    
    int main() {
        int16_t rawGyroValues[3];
        float   gyroValues[3];
    
        SPI spi = SPI::get_instance();
        spi.set_mosi(MOSI);
        spi.set_miso(MISO);
        spi.set_sclk(SCLK);
        L3G gyro(spi, CS);
    
        gyro.start();
    
        while (1) {
            gyro.read_all(rawGyroValues);
    
            gyroValues[L3G::X] = gyro.convert_to_dps(rawGyroValues[L3G::X]);
            gyroValues[L3G::Y] = gyro.convert_to_dps(rawGyroValues[L3G::Y]);
            gyroValues[L3G::Z] = gyro.convert_to_dps(rawGyroValues[L3G::Z]);
    
            pwOut << "X: " << gyroValues[L3G::X] << '\t'
                  << "Y: " << gyroValues[L3G::Y] << '\t'
                  << "Z: " << gyroValues[L3G::Z] << '\n';
    
            waitcnt(100 * MILLISECOND + CNT);
        }
    }
    
  • It's been a while that I have looked at this but it should be straight forward c code.

    Mike
Sign In or Register to comment.