BBB and HMC5883L compass I2C?

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
heltones
 
Posts: 6
Joined: Mon Apr 28, 2014 4:45 pm

BBB and HMC5883L compass I2C?

Post by heltones »

I'm sorry, but I'm confused and can't find anything to answer this question definitively. The HMC5883L magnetometer says it's 3.3v and 5v logic capable, but sort of vague on the I2C output voltage. Will the output follow the input voltage, so that if I give it 3.3v from the BBB, it'll follow suit. Or, will it use the 5v I2C voltage and require that I use a level shifter?

I haven't used I2C before and am just starting with the BBB, so I'm being cautious and don't want to push 5v across it.

Thanks!

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: BBB and HMC5883L compass I2C?

Post by adafruit_support_mike »

Short version: it depends on what supply voltage you feed the HMC5883L breakout.

An I2C bus uses pull-up resistors, and each device has a transistor that can pull the bus voltage LOW. No device can send the bus voltage HIGH though.. that would cause problems if one device was trying to send the line HIGH while another was trying to pull it LOW.

Some I2C devices come with their own pull-up resistors because that saves you from having to add them externally. Most microcontrollers have built-in pull-ups on their IO pins that can be used as well.

The HMC5883L has 10k pull-ups connected to the Vin pin, with on-board level shifters so you can connect the breakout to a 5v system without killing the chip. The level shifters aren't visible off the breakout though, so the HIGH voltage on the SDA and SCK pins will be whatever you've connected to Vin.

If you want to use the HMC5883L with a BBB, the simplest option is just to feed Vin 3.3v and not worry about 5v problems.

User avatar
heltones
 
Posts: 6
Joined: Mon Apr 28, 2014 4:45 pm

Re: BBB and HMC5883L compass I2C?

Post by heltones »

Awesome, thanks! I appreciate that you included the longer answer, helping me ratchet up my knowledge. This is on my list for getting operational this week.
-Eric

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: BBB and HMC5883L compass I2C?

Post by adafruit_support_mike »

That's what we do. We're a Maker company, and Makers want to understand things. ;-)

User avatar
heltones
 
Posts: 6
Joined: Mon Apr 28, 2014 4:45 pm

Re: BBB and HMC5883L compass I2C?

Post by heltones »

I'm really having trouble trying to get this compass to work with my BBB. Can you help point me in the right direction? I'm working on a small autonomous vehicle that uses a compass for its heading and GPS for determining heading and distance to goal. And I'm running out of time, so I'm trying to figure out the most efficient direction forward...

There doesn't appear to be a library/tool/python program that I can find to have the BBB communicate with it. I found a partially-ported python program for the LSM303 in an Adafruit GitHub repository (for the Raspberry Pi). I also did get the compass and the Ultimate GPS together on an Arduino Uno.

This is the LSM303 code: https://github.com/adafruit/Adafruit-Ra ... uit_LSM303.

The options I see are:

1. Buy the LSM303 and hope that the code in the repository works enough to get readings and figure out getting orientation from there.
2. Modify the code for the LSM303 to ditch the accelerometer portions and change the register addresses and whatnot to get it to work with the HMC5883.
3. Attempt to write my own Python code based on the HMC5883 code for the Arduino. I looked at this briefly, but the Unified Sensor Library portion was confusing to my tired mind.
4. Use the Arduino Uno. However, I'm worried about memory and processing speed. My test program with the Ultimate GPS, the HMC5883, and driving two PWM pins based on compass orientation took up 16+k of the 32+ k Bytes of memory.

I don't have much experience on the coding side and have never done any nitty gritty work with the serial data, commands, and registers.

Any advice would be helpful. Thanks!

User avatar
heltones
 
Posts: 6
Joined: Mon Apr 28, 2014 4:45 pm

Re: BBB and HMC5883L compass I2C?

Post by heltones »

Refining my question...

I'm throwing in the towel on using the BBB on this project. I still want to figure out how to use this compass and the Ultimate GPS with it, but I don't know enough about Linux and programming required to interface with serial hardware to be able to turn around something usable in short order.

So, really, I think I would love two bits of advice for the BBB:

1. General strategy to writing Python code to interact with the HMC5883L. Is it best to start with trying to port the Arduino code?
2. Approach to getting the GPS to work. I can't even figure out how to get gpsd onto my BBB with Angstrom without using Ubuntu, like most others seem to be running.

Sorry for the melted brain. I didn't realize I was in so over my head.

Thanks.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: BBB and HMC5883L compass I2C?

Post by adafruit_support_mike »

Working with low-level hardware in Linux does kind of throw you into the deep end of the pool.

1) The BBIO library will give you sample code that shows how to make the BBB talk to an I2C device. The Arduino and RasPi libraries will give you working code references that show how to talk to the HMC5883L.. what constants to use, what signals to send, how long to wait if a delay is necessary, etc. The ideas will port directly, even if the exact code doesn't.

2) Don't bother running Angstrom unless you specifically need it. Angstrom is a very thin version of Linux that was originally designed as a cell phone OS, and contains little more than the kernel and the services necessary to run a GUI. The basic idea is that a company would write applications using a development kit, and users would interact with the device through the GUI. Ubuntu is more of a standard Linux/Unix distro, with all the tools and documentation hackers have come to expect. The BBB port of Ubuntu is about as mature as the Angstrom port by now, so don't worry about using it.

User avatar
heltones
 
Posts: 6
Joined: Mon Apr 28, 2014 4:45 pm

Re: BBB and HMC5883L compass I2C?

Post by heltones »

Thanks for the reassurance about Ubuntu. In my panic mode, I've fallen into the bad behavior of skimming for easy answers. : ) I'll do more research in a relaxed and thorough fashion when I get back to this after the competition. I think I have a good idea of how to proceed with the magnetometer as well.

Thanks for the help, Mike.

User avatar
joshlucy
 
Posts: 4
Joined: Tue May 29, 2012 2:11 pm

Re: BBB and HMC5883L compass I2C?

Post by joshlucy »

Hey all, I just wrote a python library for this in case you need it: https://github.com/ThreeSixes/py-hmc5883l. You'll need the i2c-dev kernel module loaded and you'll need py-smbus installed. It should work work the BBB or the RPi.

User avatar
heltones
 
Posts: 6
Joined: Mon Apr 28, 2014 4:45 pm

Re: BBB and HMC5883L compass I2C?

Post by heltones »

Thanks, joshlucy. I haven't gotten back around to working with the compass on the BBB, but I have been meaning to for this year's vehicle. The arduino worked just fine for what I did last year. I've noted your repository for this and will certainly give it a spin in the near future. Thanks!

Locked
Please be positive and constructive with your questions and comments.

Return to “Beagle Bone & Adafruit Beagle Bone products”