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.
Photo

HMC5883L Magnetometer Netduino Code


  • Please log in to reply
7 replies to this topic

#1 <Jeremy>

<Jeremy>

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationNorthern Ireland

Posted 14 September 2011 - 09:54 PM

Hey everyone I just bought a HMC588CL magnetometer, and after a bit of googling I haven't found any records of existing Netduino code for getting started with it. So since I've got mine working, I've attached my code. Let me know if there's any bugs in my code, but hopefully not - you'll see that it's very simple code - the application doesn't really do anything except output the X and Y readings, but it gets you started with the device. You can use these readings to calculate your bearing from North. I hope someone out there in the community finds a use for it in a project! Cheers, Jeremy

Attached Files



#2 willgeorge

willgeorge

    Member

  • Members
  • PipPip
  • 25 posts

Posted 10 December 2011 - 11:50 AM

Jeremy I realize this is old post but I had to Thank You! for your sample code. I once thought I was a 'reasonably intelligent' person UNTIL I tried to code for my HMC5883L. Actually, my problem was very simple, but it turned out to be a sort of the 'Can't see the trees because the forest is blocking the view'..... Anyway.. I will be using your code for a project I have in mind for a home project (non commercial) Thanks again and have a GREAT day!

#3 <Jeremy>

<Jeremy>

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationNorthern Ireland

Posted 10 December 2011 - 06:10 PM

Hey willgeorge No problems at all! I'm really glad you were able to use it :) Jeremy

#4 ZakieM

ZakieM

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • LocationIsrael

Posted 10 February 2012 - 09:55 AM

When it comes to IMU units, you might need more than one device on the I2C bus, and frankly NETMF is too tedious for handling multiple devices.
So I borrowed the code from here plus a lot of code from http://LoveElectronics.co.uk to integrate 3 I2C devices on the same bus:

HMC5883L Magnetometer
ADXL345 Accelerometer
ITG3200 Gyro
And glued those together to display results on ST7565 LCD display (code from thttp://inyclr.com).

I hope that what I found simpler to use in order to access multiple devices on the bus will be useful for others too.

Attached Files


Zakie Mashiah
Just a curious guy

#5 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 05 March 2012 - 06:59 PM

Zakie, Thank you for publishing this code! Exactly what I was looking for. Does your hardware embed all three on a 9 degrees of freedom type board? If so are you using pullup resistors?

#6 ZakieM

ZakieM

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • LocationIsrael

Posted 06 March 2012 - 07:36 AM

I actually use 3 different boards, Gyro is ITG-3200, Accelerometer is ADX345 and Compass is HMC5883L. I found all three on eBay for substantially smaller price than the typical Arduino/Netduino online stores. Yes, I did add 2x Pullup resistors on the I2C bus. One of the issues I found even with the posted code was tilt compensation for the Compass was not working too good. It manged pitch well, but roll was changing the heading too much. Last night while digging more, I found some good PDF published by Honeywell on magnetic sensors and a tilt compensation algorithm that seems to work perfectly (on my breadboard still). If you are using the ST7565 display too, I added graphical functions to it and drastically improved its performance now too, All of that in the attached

Attached Files


Zakie Mashiah
Just a curious guy

#7 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 06 March 2012 - 04:06 PM

I'm not using it... yet. But because of your code I ordered one. :P Thanks for the update. I found a board on ebay with all 3 of the chips you mentioned for 35 bucks. Hopefully the quality is as good as Sparkfun's. I just have to wait 2 weeks for it to get here.

#8 121424D

121424D

    New Member

  • Members
  • Pip
  • 1 posts

Posted 06 June 2014 - 06:22 AM

Hi Everyone. Jeremy. When I use your code with my magnetometer and runs with Microsoft visual studio 2010. It return a error message [Additional Information:  Did not return Device ID  0x48/0x34/0x33 as expected]. This is due to the failure of the device? Or is code problem?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.