Gyroscope Module 3-Axis L3G4200D on FEZ Cerbuino Bee

So I just purchased a FEZ Cerbuino Bee board and a Parallax gryoscope to do some development, trying to get my feet wet in some hardware/software development. I am trying to use SPI protocol for communication between the devices. According to the pinout found at https://www.ghielectronics.com/docs/45/fez-cerbuino-bee-developer#396, here is

FEZ GYROSCOPE
PIN PB3 SPI1 SCK SCL
PIN PB4 SPI1 MISO SDO
PIN PB5 SPI1 MOSI SDA/SDI/SDO
PIN PB15 CS

Here is the problem that I am encountering. Whenever the SDO pin is connected to the MISO/PB4 pin the FEZ board locks up. For I2C communication, I am also confused as to which pins to use, not a well documented board for a newbie.

Please let me know if anyone has this configured to work with similar devices on this particular board using the Arduino style headers.

Thanks,
Kirk

I have a code for that device.



namespace Test
{
    public class Gyro : I2CDevice
    {
        public const byte L3G4200D_WHO_AM_I      = 0x0F;

        public const byte L3G4200D_CTRL_REG1     = 0x20;
        public const byte L3G4200D_CTRL_REG2     = 0x21;
        public const byte L3G4200D_CTRL_REG3     = 0x22;
        public const byte L3G4200D_CTRL_REG4     = 0x23;
        public const byte L3G4200D_CTRL_REG5     = 0x24;
        public const byte L3G4200D_REFERENCE     = 0x25;
        public const byte L3G4200D_OUT_TEMP      = 0x26;
        public const byte L3G4200D_STATUS_REG    = 0x27;

        public const byte L3G4200D_OUT_X_L       = 0x28;
        public const byte L3G4200D_OUT_X_H       = 0x29;
        public const byte L3G4200D_OUT_Y_L       = 0x2A;
        public const byte L3G4200D_OUT_Y_H       = 0x2B;
        public const byte L3G4200D_OUT_Z_L       = 0x2C;
        public const byte L3G4200D_OUT_Z_H       = 0x2D;

        public const byte L3G4200D_FIFO_CTRL_REG = 0x2E;
        public const byte L3G4200D_FIFO_SRC_REG  = 0x2F;

        public const byte L3G4200D_INT1_CFG      = 0x30;
        public const byte L3G4200D_INT1_SRC      = 0x31;
        public const byte L3G4200D_INT1_THS_XH   = 0x32;
        public const byte L3G4200D_INT1_THS_XL   = 0x33;
        public const byte L3G4200D_INT1_THS_YH   = 0x34;
        public const byte L3G4200D_INT1_THS_YL   = 0x35;
        public const byte L3G4200D_INT1_THS_ZH   = 0x36;
        public const byte L3G4200D_INT1_THS_ZL   = 0x37;
        public const byte L3G4200D_INT1_DURATION = 0x38;

        OutputPort csPort;
        private int m_Timeout = 1000;
        // int Addr = 105; // 0x69 Adress for L3G4200D
        private ushort m_Address;

        public Gyro(Cpu.Pin cs) : this(0x69, cs)
        { }

        public Gyro(ushort address, Cpu.Pin cs)
            : base(new Configuration(address, 100))
        {
            m_Address = address;

            csPort = new OutputPort(cs, true);
        }

        public byte[] Read(byte memoryAddress, int responseLength = 1)
        {
            var buffer = new byte[responseLength];
            I2CDevice.I2CTransaction[] transaction;
            transaction = new I2CDevice.I2CTransaction[]
            {
                I2CDevice.CreateWriteTransaction(new byte[] { memoryAddress }),
                I2CDevice.CreateReadTransaction(buffer)
            };

            int result = Execute(transaction, m_Timeout);
            return buffer;
        }

        public void Write(byte memoryAddress, byte value)
        {
            I2CTransaction[] transaction;
            transaction = new I2CDevice.I2CTransaction[]
            {
                I2CDevice.CreateWriteTransaction(new byte[] { memoryAddress, value })
            };
            int result = Execute(transaction, m_Timeout);
        }

        byte[] buffer = null;
        internal void Read(ref int x, ref int y, ref int z)
        {
           
            buffer = Read(L3G4200D_OUT_X_H);
            x = buffer[0] << 8;
            buffer = Read(L3G4200D_OUT_X_L);
            x |= buffer[0];

            buffer = Read(L3G4200D_OUT_Y_H);
            y = buffer[0] << 8;
            buffer = Read(L3G4200D_OUT_Y_L);
            y |= buffer[0];

            buffer = Read(L3G4200D_OUT_Z_H);
            z = buffer[0] << 8;
            buffer = Read(L3G4200D_OUT_Z_L);
            z |= buffer[0];

            x = (x&0x8000) != 0 ? -(short)~(x - 1) : x;
            y = (y & 0x8000) != 0 ? -(short)~(y - 1) : y;
            z = (z & 0x8000) != 0 ? -(short)~(z - 1) : z;
            x /= 114;
            y /= 114;
            z /= 114;
        }
    }
    //public class Program
    //{

    //    public static void Main()
    //    {
    //        Gyro t = new Gyro();
    //        t.Write(0x1F, 0x20);   // Turn on XYZ axes
    //        t.Write(0x08, 0x22);   // control 
    //        t.Write(0x80, 0x23);   // Scale to 500 deg/sec            
    //        Thread.Sleep(1000);

    //        int timerPeriod = 50;
    //        Timer timer = new Timer(delegate(object o)
    //        {

    //            byte[] MSBx = t.Read(0x29, 1);
    //            byte[] LSBx = t.Read(0x28, 1);

    //            int x = ((MSBx[0] << 8) | LSBx[0]);

    //            byte[] MSBy = t.Read(0x2B, 1);
    //            byte[] LSBy = t.Read(0x2A, 1);

    //            int y = ((MSBy[0] << 8) | LSBy[0]);

    //            byte[] MSBz = t.Read(0x2D, 1);
    //            byte[] LSBz = t.Read(0x2C, 1);

    //            int z = ((MSBz[0] << 8) | LSBz[0]);

    //            Debug.Print("X: " + x + " Y: " + y + " Z: " + z);

    //        }, null, 0, timerPeriod);

    //        // Make sure the device runs the timer and doesnt end execution.
    //        while (true)
    //        {
    //            Thread.Sleep(Timeout.Infinite);
    //        }
    //    }
    //}
}


Edit:

For I2C you or only need SCL and SDA pins. Ignore CS in the code above. I think it is a leftover from the attempt to get it working using SPI.

Thanks for a speedy response. Do you mind if I try this code sample? And what were the pins used for I2C?

On Cerbuino Bee you need to use Pin8 (SDA) on Gadgeteer Socket 2 and Pin9 (SCL) on Gadgeteer Socket 2. These are the hardware I2C1 pins.

If not sure you can always check with the schematics:

http://www.ghielectronics.com/downloads/schematic/FEZ_Cerbuino_Bee_SCH.PDF

I just finished writing some code to get Gyro, Accelerometer and Temperature from a cheap MPU6050 breakout board that I got from AliExpress. It works quite well, but now I just need an idea for a project to use it in! :wink: