Saturday, July 12, 2014

MPU6050 (GY-521 Breakout) + Arduino Mega 2560 Accelerometer and Gyroscope Application

Hi All,

I’m going to show you today how we can use the GY-521 Breakout with the Arduino Mega 2560 to get the readings from the sensor.

First I have to say that, I am totally new to Arduino and I have a limited knowledge in working with the registers and all the deep stuff. I’m trying to learn them and yes, this will be a beginning. J

So first let me show you what I have already bought.
First GY-521 Breakout for MPU-6050

 

Let me provide you some brief introduction about this product.
The InvenSense MPU-6050 sensor contains a MEMS accelerometer and a MEMS gyro in a single chip. It is very accurate, as it contains 16-bits analog to digital conversion hardware for each channel. Therefor it captures the x, y, and z channel at the same time.
- Chip: MPU-6050
- Power supply: 3.5V (But as there is a voltage regulator on the breakout board, you can use 5V directly)
- Communication mode: standard IIC communication protocol
- Chip built-in 16bit AD converter, 16bit data output
- Gyroscopes range: +/- 250 500 1000 2000 degree/sec
- Acceleration range: +/- 2g, +/- 4g, +/- 8g, +/- 16g
MPU-6050 Datasheet can be found here. Register map can be found here
Here is the schematic of GY-521



Now we have to get the Arduino Mega 2560 Board.



All the information related to this product can be found here.
So we have our items and the next important thing is to hookup these two together. Note the wiring is different for Arduino UNO. This wiring is for Arduino Mega 2560.



Here the connections are
GY-521                                  Arduino Mega
VCC                                        3.3V or 5V
GND                                      GND
SCL                                         Pin 21 (SCL)
SDA                                        Pin 20 (SDA)
INT                                         Pin 2 (Interrupt 0) – for more interrupt pins in Arduino click here


Now for the program. As we have a lot of resources regarding the usage of Arduino, let’s try the code from them (Although I had to spend several hours to work with them :P ).

First let’s try to find whether our device is connected with the Arduino. For that we can use the I2C Scanner code by Krodal to find out the connected I2C devices to Arduino. You can find the code here
Also following is the code. Compile the code and upload it to Arduino. Open the serial monitor and reset the Arduino.



It will find your GY-521 at the address 0x68 or 0x69. If it doesn’t find the IMU at that location, there might be an issue with your wiring. Please check it again. 


Now we can use the Krodal’s next code to get the raw outputs from the sensor. Krodal’s sketch can be found here. Please scroll to the end of the page and you’ll be able to find the code. Also I’ll be posting it here.


Here's the output.


Now we are ready to try the code from Jeff Rowberg. Download the I2C library from github. Here’s the link.

Now unzip the file and find the Arduino folder. Copy the I2Cdev and MPU6050 libraries to your Arduino libraries located at C:\Program Files (x86)\Arduino\libraries.



Now you are ready to use the I2Cdev and MPU6050 libraries. Locate example code in \Arduino\MPU6050\Examples\MPU6050_DMP6 and upload it to the Arduino. Now you will get the output from the Serial monitor. The output provides you the sensible values from the sensor unlike the raw outputs. Here Jeff has used the onboard Digital Motion Processor™ (DMP™) capable of processing complex 9-axis MotionFusion algorithms. You can find Jeff’s work here.






Now we can use the Processing demo provided by Jeff with the MPU6050 example. You can download Processing hereYou also have to install the toxiclib for Processing. You can find that here.

To install the toxic library just copy the contents of the zip file to the library folder in Pocessing projects directory.

Also create a folder named MPUTeapot in the Processing projects folder and copy the MPUTeapot.pde file to that folder from MPU6050 example code location.

Now you have to do the following changes in the Jeff’s MPU6050_DMF code.
  1. Comment the line  : #define OUTPUT_READABLE_YAWPITCHROLL
  2. Uncomment the line : #define OUTPUT_TEAPOT
  3. Now load the updated MPU6050_DMP code to Arduino.
  4. Run the MPUTeapot.pde in Processing
  5. You’ll see the small plane moving
So hope this would help someone. 
Thank You. 

Tuesday, May 6, 2014

Install Windows Identity Foundation on Windows 8.1

Hi All,

"Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified"

If you get this error on authenticating CRM 2011 you will have to install the Windows Identity Foundation in your PC.

When trying to install Windows Identity Foundation on Windows 8.1, I got the following error.


To fix this issue, you can go to "Turn Windows Features On or Off", and turn on the following features.

Now the issue is fixed. :-)

Hope this helps.
Thank You.

Tuesday, February 18, 2014

How to Remove Week Numbers from the GridDateTimeColumn/ RadDatePicker in Telerik Grid.

Hi all,

You may have used the date pickers from Telerik controls, either in RadGrid’s GridDateTimeColumn or in RadDatePicker. In both of these scenarios, by default the Telerik control will add a week column from the side of the calendar. Following is the calendar with week columns.




But for some applications we don’t need this column and we will want to remove it. So following is the way that you can achieve that.

The first approach is to remove the week column from the GridDateTimeColumn in RadGrid.

<telerik:GridDateTimeColumn UniqueName="Column2" Visible="true" 
DataFormatString="{0:MM/dd/yyyy}">
                <ItemStyle Wrap="true" />
                <HeaderStyle VerticalAlign="Top" />
</telerik:GridDateTimeColumn>


protected void GridFourColumns_ItemDataBound(object sender, GridItemEventArgs e)
        {           
           RadDatePicker date2 = editItem["Column2"].Controls[0] as RadDatePicker;
           if (date2 != null)
           {
              date2.SharedCalendar.ShowRowHeaders = false;
           }               
           
        }

The following approach is to remove the week column from the RadDatePicker.

 <telerik:RadDatePicker ID="dtpStartDate" runat="server"
      <Calendar ShowRowHeaders="false"></Calendar> 
 </telerik:RadDatePicker> 

Following is the final output without week columns.



Hope this will be helpful.
Thanks J

Thursday, November 14, 2013

Common Issues with Rad Grid : telerik Unable to get property 'documentElement' of undefined or null reference

Hi all,

When developing ASP.Net applications using Telerik Controls, you may have come across this error saying "telerik Unable to get property 'documentElement' of undefined or null reference" which will ask you to debug using the javascript debugger. 

I came across this error when working with Telerik Controls in IE 10. When the browser mode is changed to IE 9, the issue fixed.  But this is not good for your Client.

If you are using a Telerik version which is outdated you will face this problem. One thing you can do is to upgrade your Telerik version.

Next you can fix this issue by adding the following lines in your web page. 

<head runat="server">
    <!-- Mimic Internet Explorer 9 -->
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
</head>

Another fix that is discussed in various posts in web is to edit the web.config file as follows. (This fix didn’t work for me and I have also seen others who have not been able to fix by editing the web.config file.) Anyway following is the way you can do that.

<system.webServer>

    <httpProtocol>
      <customHeaders>
        <clear />
        <add name="X-UA-Compatible" value="IE=9"/>
      </customHeaders>
    </httpProtocol>
   
</system.webServer>



Start Developing ASP.Net Applications Using Telerik Controls

Hi all,

Today I’m going to show you how to setup the environment to work with Telerik controls in ASP.Net web applications. In a previous tutorial I showed you how to develop a simple grid using Telerik RadGrid. When developing the grid, we have to add the references and edit the web.config file to avoid the errors that come on our way.

First you have to add the reference to “Telerik.Web.UI.dll”.





















Next the web.config should be edited as following. (Note: I have done this to support a basic rad grid and this may change according to your application)
 <configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
   
    <httpHandlers>
      <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
    </httpHandlers>
    <pages>
      <controls>
        <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI"/>
      </controls>
    </pages>
   
  </system.web>

  <system.webServer>
    <handlers>
      <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource"/>
    </handlers>
  </system.webServer>

  <location path="Telerik.Web.UI.WebResource.axd">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
 
</configuration>

Finally you have to add the  “Telerik.Web.UI.dll” to the bin folder of your project.

Now you can start developing ASP.Net applications using Telerik.


Hope this helps J

Friday, November 8, 2013

Common Issues with Rad Grid : Input string was not in a correct format.

If you get this error "Error: Sys.WebForms.PageRequestManagerServerErrorException: Input string was not in a correct format." when u click on the edit button of your radgrid data item, what you have to do is first check whether the data-format-strings are correct in your grid. I got this error because I have incorrectly configured the data-format-string for the given object's fields.

Hope this helps, thanks :-)

Wednesday, October 30, 2013

How to Truncate a String in a Telerik Grid (RadGrid) Column

Hi all, this small blog post is to show how you can truncate a string in a telerik grid when the string is too long to be shown inside the column. Truncation should be done at the ItemDataBound event of telerik grid.

Following is the column template :

<telerik:GridBoundColumn UniqueName="Column1" Visible="true" ShowSortIcon="true">
<ItemStyle Wrap="true" />                   

</telerik:GridBoundColumn>

The ItemDataBound Column will look like this. 

protected void Grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{

if (e.Item is GridDataItem)
{
GridDataItem dataBoundItem = e.Item as GridDataItem;
if (dataBoundItem["Column1"].Text.Length > 10)
       {
        dataBoundItem["Column1"].Text = dataBoundItem["Column1"].Text.Substring(0, 10) + "...";
       }
}

}



Hope this helps J
Thank You J