Heroduino - Viewing Profile: Likes - Netduino Forums
   
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.

Heroduino

Member Since 24 Jun 2012
Offline Last Active Dec 02 2017 10:24 AM
-----

#51120 MPU6050 with Netduino

Posted by Heroduino on 05 July 2013 - 05:29 PM

Hallo Netduino Community,

 

I think it is time to post my example here in the Netduino Forum. My first post was in German, but I see many webcalls come from around the world and the google translater is not quite good at understanding my descriptions. Well, my English is very rusty. So, I am sorry for any mistakes I might (and will) make.

 

Last year, I bought the sensor MPU-6050 and at first I couldn't run it. I saw the code library in C++ and read how to function the sensor. It was not very helpful for me. But it helped me to understand the code from Jeff Rowbergs Librarys. The code is awesome, but unfortunately not for a quick understanding.

 

First half of the year, I succeeded to run my prorgam with the sensor and posted it on my blog for sharing. Later I wrote a short Version for arduino. It fitted on a page side ;)

 

Ok, what does my program do.

public class MPU6050Sensor{    // I²C Class for connecting to the sensor    private I2CDevice _i2CDevice;    // The Contructor initialized the connecting and the sensor    public MPU6050Sensor()    {        // I²C connecting:        // The first HEX value 0x68 is the address from the sensor and        // the value 100 is for the transmission speed.        // Well you can use 400kHz,        // if you have a clean cable connection.        _i2CDevice = new I2CDevice(new I2CDevice.Configuration(0x68, 100));        // Sensor init        // Sleep und Reset execute:        // The HEX value 0x6B is for the Power Management 1        // The secound Hex value includes the 'Bit' for reset.        StatusMessage(Write(new byte[] { 0x6B, 0x80 }));        Thread.Sleep(10);        // Stop sleep and Clock setup:        // The HEX value 0x6B is for the Power Management 1        // The secound Hex value 0x00 set the 'Clock Select'        // to 'Internal 8MHz oscillator'        // If you don't need the temperature sens,        // you can set the HEX value 0x08.        StatusMessage(Write(new byte[] { 0x6B, 0x00 }));        // Configuration setup:        // This Configuration activates the Low Pass Filter (DLPF).        // Setting => Acc=5Hz, Delay=19.0ms, Gyro=5Hz, Delay=18.6ms, Fs=1kHz        StatusMessage(Write(new byte[] { 0x1A, 0x06 }));    }    // Send a byte array to the sensor    private int Write(byte[] buffer)    {        I2CDevice.I2CTransaction[] transactions = new I2CDevice.I2CTransaction[]        {            I2CDevice.CreateWriteTransaction(buffer)        };        return _i2CDevice.Execute(transactions, 1000);    }    // Read a byte array the sensor results    private int Read(byte[] buffer)    {        I2CDevice.I2CTransaction[] transactions = new I2CDevice.I2CTransaction[]        {            I2CDevice.CreateReadTransaction(buffer)        };        return _i2CDevice.Execute(transactions, 1000);    }    // Give a status message of result    private void StatusMessage(int result)    {        if (result == 0)        {            Debug.Print("Status: Fehler beim Senden oder Empfangen");        }        else        {            Debug.Print("Status: OK");        }    }    // Call the object SensorData with the sensor result    public SensorData GetSensorData()    {        // Byte Array for reading        byte[] buffer = new byte[14];        buffer[0] = 0x3B;        // The HEX Value set the first byte        // of the acceleration axis X        Write(new byte[] { 0x3B });        // Read from the sensor        Read(buffer);        // Give the byte array result to the object,         // and convert it to usable values        return new SensorData(buffer);    }}

The last method shows the SensorData object class and how it Looks.

public class SensorData{    public uint Acceleration_X = 0;    public uint Acceleration_Y = 0;    public uint Acceleration_Z = 0;    public uint Temperatur = 0;    public uint Gyroscope_X = 0;    public uint Gyroscope_Y = 0;    public uint Gyroscope_Z = 0;    public SensorData(byte[] buffer)    {        // Result of the acceleration axis        Acceleration_X = (((uint)buffer[0]) << 8) | buffer[1];        Acceleration_Y = (((uint)buffer[2]) << 8) | buffer[3];        Acceleration_Z = (((uint)buffer[4]) << 8) | buffer[5];        // Restult of temperature        Temperatur = (((uint)buffer[6]) << 8) | buffer[7];        // Result of the gyroscope axis        Gyroscope_X = (((uint)buffer[8]) << 8) | buffer[9];        Gyroscope_Y = (((uint)buffer[10]) << 8) | buffer[11];        Gyroscope_Z = (((uint)buffer[12]) << 8) | buffer[13];    }}

The next part is to connect the hardware, before you can deploy. Netduino to Sensor 3.3V >> VCC GND  >> GND AnalogIn 4 >> SDA AnalogIn 5 >> SCL

At last, for the Main() Methode

public static void Main(){    MPU6050Sensor mpu = new MPU6050Sensor();    SensorData data = mpu.GetSensorData();    while (true)    {        data = mpu.GetSensorData();        Debug.Print(            "Acc X: " + data.Acceleration_X + " " +            "Acc Y: " + data.Acceleration_Y + " " +            "Acc Z: " + data.Acceleration_Z + " " +            "Gyro X: " + data.Gyroscope_X + " " +            "Gyro Y: " + data.Gyroscope_Y + " " +            "Gyro X: " + data.Gyroscope_Z + " " +            "Temperatur: " + data.Temperatur);    }}

Well, that is all and I hpoe you have fun :)

Greetings from Germany, have a nice weekend!!

 

 

 

Edit:

My reposting on my blog (Language German)

http://meineweltinme...en-mit-dem.html

Attached Files




#47224 MPU 6050 Data are not constant

Posted by Heroduino on 15 March 2013 - 11:36 AM

Hello,

 

i have found the problem and I have fixed.

For interest, I post my solution.

 

http://dl.dropbox.co...nsorEnglish.zip

 

 

Heroduino




#42078 MPU 6050 Data are not constant

Posted by Heroduino on 24 December 2012 - 04:00 AM

Hallo,

for several days now I try to program with my Netduino plus to read values from the sensor MPU 6050.

So, i don't have any idea, it doesn`t work, what can i do? I have tried many configurations, without success.

Here is a result at the Moment, if I start to read:

Initialisiere den Beschleunigungs- und Gyrosensor MPU-6050
-----------------------------------------------------------------------
Status: OK
Status: OK
Status: OK
Status: OK
Verbindung testen:
Status: Error
-----------------------------------------------------------------------
Acceleration: X: 162 Y:43647 Z:64764 Gyro: X: 53751 Y: 30329 Z: 57686
Acceleration: X: 0 Y:65403 Z:31771 Gyro: X: 61390 Y: 65385 Z: 1442
Acceleration: X: 28752 Y:46264 Z:0 Gyro: X: 0 Y: 0 Z: 0
Acceleration: X: 0 Y:0 Z:0 Gyro: X: 0 Y: 0 Z: 0
Acceleration: X: 0 Y:0 Z:0 Gyro: X: 0 Y: 0 Z: 0
Acceleration: X: 1281 Y:59647 Z:31809 Gyro: X: 254 Y: 29182 Z: 61951
...


The Connections to the sensor, i have already tested.
So I hope anyone can help me :o


Heroduino

PS: Sorry for my bad English. <_<


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.