Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Kirk K

Member Since 18 Apr 2012
Offline Last Active Jun 14 2013 02:03 AM
-----

#49949 NetduinoGo Shieldbase SPI hookup

Posted by Kirk K on 24 May 2013 - 10:59 PM

My fellow Netgoers,

 

I need your help in hooking up a Parallax Gyroscope Module 3-Axis L3G4200D to the shieldbase. I am using the latest firmware for both my GO and Shieldbase, VS2012, .NET Micro 4.2, etc. Based on the pinout diagram provided by Gutworks, I hooked up the devices as followed:

 

Shieldbase   ->   Gyroscope Module 3-Axis L3G4200D Pin D04 NSS  -> CS Pin D11 MOSI -> SDA Pin D12 MISO -> SDO Pin D13 SPCK -> SCL

using System;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.NetduinoGo;using NetduinoGo;namespace Netduino_Go{    public class Program    {        public static void Main()        {            // write your code here            using (ShieldBase sb = new ShieldBase(GoSockets.Socket5))            {                //Data to write to gyroscope                byte x_MSB = 0x29;                byte x_LSB = 0x28;                byte y_MSB = 0x2B;                byte y_LSB = 0x2A;                byte z_MSB = 0x2D;                byte z_LSB = 0x2C;                byte CTRL_Register1 = 0x20;                byte CTRL_Register2 = 0x21;                byte CTRL_Register3 = 0x23;                //Setup device                SPI device = new SPI(new SPI.Configuration(Pins.GPIO_PIN_D4,   //Chip Select pin                                                false,              //Chip Select Active State                                                0,                  //Chip Select Setup Time                                                0,                  //Chip Select Hold Time                                                true,               //Clock Idle State                                                true,               //Clock Edge                                                10000,               //Clock Rate (kHz)                                                sb.SPI_Devices.SPI1));                device.Write(new byte[] { CTRL_Register1, 0x1F });                device.Write(new byte[] { CTRL_Register2, 0x08 });                device.Write(new byte[] { CTRL_Register3, 0x80 });                Thread.Sleep(1);                while (true)                {                    byte[] data = new byte[6];                    device.WriteRead(new byte[] { x_MSB, x_LSB, y_MSB, y_LSB, z_MSB, z_LSB }, data);                    var x = ((read[0] << 8) | read[1]);                    Debug.Print(x.ToString());                    Thread.Sleep(5);                }            }        }    }}

I am not sure what I am doing here, but I am reading values of 255 on all  from the gyro. Any help would be helpful?

 

ps. I have a competition between a fellow co-worker who is using an Arduino. May have to get +2 to compete against him.

 

 

Thanks,

Kirk




home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.