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.

hoquet

Member Since 11 Jul 2012
Offline Last Active Sep 03 2012 01:17 PM
-----

#32169 Netduino Go with MMA7361 Accelerometer

Posted by hoquet on 18 July 2012 - 05:00 AM

Hello everyone,

This is my first mini project with the netduinoGo and learning about robotics. I have a programming background, although 10 years ago in .net. I purchased the NetduinoGo starter kit with the button, led, potentiometer, etc.. I got all of it working and was able to make buttons respond, led's blink, etc.. Cool Huh?

I then added the shield base and got that to work. Atleast blink a light and power on. Now I wanted more. So I purchased an LCD, not knowing anything about whether or not it would work or others have used it and if there is some sample code out ther. Then I managed to get an LCD screen connected through various websites and tutuorials. I finally got the Hacktronics LCD Module working with the Netduino. Someone wrote an interface and class along with diagrams on what to connect the digital I/O to the Hacktronics. I can now write out whatever I want to the LCD screen. Although all string manipulations, truncations, etc. I have to handle myself. But it works, I even learned what the heck a resistor is. I also watched a youtube video on how to solder. Hey, it has been 15 years since I took any kind of physics.

Now I thought I would try my hand at an Virtuobotix MMA7361 Accelerometer which I order even before I wrote my first Netduino application. I learned that next time before ordering the hardware, see if there is some code that people have written is readily available for c#. Trying to convert Arduino classes and interfaces is nearly impossible. Anyways, I connected the accelerometer to the shield and followed code that someone else wrote for another accelerometer: Sparkfun ADXL 335

Very basic code:
 // Define our accelerometer inputs
        static AnalogInput accX;
        static AnalogInput accY;
        static AnalogInput accZ;

        public static void Main()
        {
            // Create the Inputs
            accX = new AnalogInput(Pins.GPIO_PIN_A0);
            accY = new AnalogInput(Pins.GPIO_PIN_A1);
            accZ = new AnalogInput(Pins.GPIO_PIN_A2);

            // Keep application alive via loop
            while (true)
            {
                // Read data from the sensor
                double x = (double)(accX.Read());
                double y = (double)(accY.Read());
                double z = (double)(accZ.Read());

                // Output data to screen
                Debug.Print("X: " + x + " Y: " + y + " Z: " + z);
            }
        }
So, what do I get for an output?

X: 0.48815628815628814 Y: 0.526984126984127 Z: 0.67252747252747258
X: 0.48815628815628814 Y: 0.5252747252747253 Z: 0.6676434676434676
X: 0.48986568986568985 Y: 0.52722832722832724 Z: 0.66935286935286931
X: 0.49108669108669106 Y: 0.52576312576312578 Z: 0.66984126984126979
X: 0.48888888888888887 Y: 0.52649572649572651 Z: 0.67130647130647125
X: 0.48766788766788766 Y: 0.52747252747252749 Z: 0.66862026862026858
X: 0.48888888888888887 Y: 0.52771672771672773 Z: 0.67057387057387052
X: 0.48840048840048839 Y: 0.52503052503052505 Z: 0.66935286935286931
X: 0.4879120879120879 Y: 0.5252747252747253 Z: 0.67106227106227101
X: 0.48913308913308912 Y: 0.5252747252747253 Z: 0.66788766788766785
X: 0.48717948717948717 Y: 0.52503052503052505 Z: 0.67057387057387052
X: 0.4879120879120879 Y: 0.52551892551892554 Z: 0.66984126984126979
X: 0.49108669108669106 Y: 0.52722832722832724 Z: 0.66862026862026858
.....

Great, seems like it is working. How the heck do I veryify that it works? Even though the device is sitting on my desk at home, the numbers keep changing. I read some articles about getting the g-force, radians, and using offsets. I just want something like degrees tilt in either of the 3 axis with 2 decimal places. Any resources anyone would recommend would be great. I'll keep posting my progress as well as I add a motor shield and the xbee shield. I'm just learning, so please keep it simple. I am also attaching the work that I have done. For the hacktronics LCD which is a 4 line 20 char, I would be happy to share my code and board configuration.

Thanks

Attached Files




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.