Asked — Edited
Resolved Resolved by Jeremie!

Hmc5883

Hi,

Has anyone successfully connected and used a HMC5883L compass on I2C port without systematically crashing at init ?

I'm kind of stuck and wish to know if I should go on trying again or give up.

Did read former threads about same topics Did find datasheet and Hex address of chip DId use I2Cwrite and Read commands Did use tutorial's script did use everything I can think of. Wires are connected sda to sda scl to scl and then 3.3V.

Let me know if any of you guys have a robot capable to know where it's heading thanks to a compass.

Is there not a more simple compass hardware like with an analog output readable on ADC ? Just asking in case it makes any sense.

Thanks in advance.


ARC Pro

Upgrade to ARC Pro

Subscribe to ARC Pro, and your robot will become a canvas for your imagination, limited only by your creativity.

PRO
Synthiam
#1  

i2c is a sensitive protocol and is vulnerable to interference and capacitance issues. The really only way around i2c issues is to use a PCB with small traces, filter caps and smart placement of resistors. Also the type of wire used to connect from the i2c device to the ez-b also needs to be correct. The wire cannot have each +3, gnd, sda and scl merely floating around, otherwise they act like antennas and collect interference. Unless you're using a i2c pcb that has been properly designed by an experienced electrical engineer, it's a tough thing to get working:)

Jeremie will chime in on his design schematic for the ez-robot test module we created. Of course, due to jeremie's awesome electronic design experience, the ez-robot i2c devices always work.

To this day, i still have not gotten an i2c device to work that i designed myself. So don't feel bad:) I leave it to the engineers!

PRO
Canada
#2  

@elfege what breakout are you using? Do you have a picture?

#3  

Beakout?:) Not even sure to know what you are referring to... sorry. Probably the actual hardware, I figure. Here is a link :

JBtek Electronic Compass (3-axis Magnetic Field Sensor) GY-271

Below are the models I ordered for replacement (I think I killed the other one... reversed polarity... but long after I tried using them and in a moment of despair...) I had bought two, though, in case this kind of accident happened. :D And killed them both... stress

4 of GY-273 HMC5883L 3-Axis Magnetic Electronic Compass 3-5V Blue

And this one, not sure how useful it'll be, but as I was saying, I'm hopeless :

Diymall® Mpu-9250 9dof Module Nine-axis Attitude Gyro Compass Acceleration Magnetic Field Sensor

Thanks a lot for your support.

NB : Did I understand well ? Did Dj mentioned that EZB provides a model that is fully compatible with EZB V4? Not sure I got it all though. If so, then I'd love to buy it, but I can't find it on the website.

Thanks Elfege

PRO
Canada
#5  

Thanks @RR! Actually the only place to get the 4-in-1 is Brookstone:) at this moment in time.

@elfege the 4-in-1 has an MPU-9150 on it which has a compass built-in, should be a good fit.

Yes what you have is a HMC5883 breakout board. That's what they call little application boards that usually have a single chip's pins broken out on a PCB. If you like to continue to use the HMC5883 with the EZ-B you'll need to either change the SMD pull-up resistors to a stronger (lower resistance) pull-ups like 330ohms if you don't want to do SMD soldering you can place some lower resistance pull-ups in parallel (via a breadboard or otherwise) with the existing 2.2k pull-ups on the breakout board.

#6  

THanks a lot Jeremie, Dj and RR. I saw the product in EZ store little after I had asked my question, but it is indeed currently out of stock. Maybe I'll look into BRookstone later.

About the previously mentioned HMC5883 I received today : This time, using 150 ohms resistors between SDA and SCL on the chip and an old EZB's V3 I got the device to not crash the EZB's connection. However, not joy yet on EZB V4 and this is mainly due the fact, I know, that I didn't really understand all the intricacies sent by Jeremie in his message.

What is the PCB ? Power Cutoff board ? ? I guess not. What are the pull-ups ? To me its a way of working out...:D And finally, I can't identify the resistors I am suppose to bypass / replace.

And I couldn't find 330 ohms resistors so I tried with 450 and... same : EZB V3 ok, but no joy on V4. oh... did I mension that the data returned by the command print($compassx) is -1 and this whatever direction it's pointing at, so I guess I still have some serious work ahead.

Sorry... I really see how I didn't get much to what you said Jeremie and I don't want to take too much of your time so maybe I'll do some research online because it feels like there's everything I need to know in that message you sent me.

But if you feel like guiding me a little bit more (for instance about where I'm suppose to solder the parallel resistors), I'd be more than happy !

I assumed, though that it was the two little things marked "472" that are located right between the chip and the SCL and SDA ports. SMD soldering = ? Pulling out the two little resistor and replacing them ?

Thanks a lot. I'm learning so much !

ELfège.

PRO
Canada
#7  

Sorry @elfege things got busy and this post slipped my mind.

PCB = Printed Circuit Board Pullups = A resistor used to tie a signal high (i.e. 330ohm resistor from SDA to 3.3V)

You won't need a resistor connected from SDA to SCL.

You will need a resistor from SDA to 3.3V and SCL to 3.3V.

If the pullup resistors on your HMC5883 Breakout board are "472" this means that they are 4.7Kohm resistors. One way to make the circuit work is to desolder those resistors and solder "331" (330ohm) resistors there instead.

Another way would be to take your 450ohm resistors and connect one from the SDA pin to 3.3V and the other from SCL pin to 3.3V. This would place the onboard 4.7K resistors in parallel with the 450ohm resistors which would make ~410ohms. 410ohms should be close enough to 330ohms to have it work.

#8  

Thanks a lot Jeremie,

The MPU 9150 seems to workers well. However now I need to figure out how to use it... It looks like the $compassheading doesn't return very consistent data. For example if I turn something like 45 dog left it returns 155 and if, from the same starting point, I turn 45 dog right it returns again 155 . The starting point returns 158 and if I turn 180 set I get something like 112...

Now if I move forward, I don't get the same values again for the same degrees. Basically it's like I can't get a fixed point of reference which is much needed and the very use of a compass...

I was lately trying to combine $compassX values with $compassY values since they differ from the 155 left heading and the 155 right heading. But I'm pretty sure I'm missing something here:)

Other question : where am I to connect all the other ports on the MPU to use gyro and other variables? And what are the respective functions of these ports ? Init, something-sync, etc. ? (Sorry typing from work on my iPhone )

Thank you so much for your support,

Elfege

PRO
Canada
#9  

I'm not sure about your compass readings, I'd have to look further into it.

All the accelerometer, gyro, and compass readings are all available via I2C. Please check out this tutorial for more info. The Variable Watcher in ARC is likely what you'll want to use.

#10  

@Jeremie (or @elfege)

Have you had any luck looking at the compass question? I just got a 4in1 from Brookstone, and am seeing the same thing, the $CompassHeading variable seems to be fairly meaningless. It changes when the robot changes direction, but in no way that makes any sense. Is there a preferred orientation to mount the device? I have tried almost every position/orientation and it doesn't seem to make a difference.

The other compass variables also appear to jump randomly around when the device is sitting still. Gyro and Accel are relatively stable, but since they return to their starting positions when movement stops, they are not going to meet the need I have (I want to adapt Rich's "Ping roam" script so that rather than doing timed moves left and right, I can get the current heading, set a new heading 45 or 90 degrees left or right, and then move until current heading = new heading).

Thanks,

Alan

PRO
Canada
#11  

Sorry, I got distracted with other priorities but yes I will definitely look into this.

#12  

The pull ups resistors did the trick. Thanks a lot Jeremie!

#13  

Pull up Resistors? I have the same 4in1 I got from a local Brookstone, and have the same issues with the compass. I am wanting to make the compass read north, and then the robot be able travel based on the north starting position.

#14  

@Robohappy, the pull up resisters were for making a different board with the same chip work. Jeremie is going to look into the compass problem. I should hav started a seperate thread for it.

Alan

#15  

Hi Alan, I bought a compass a while ago and haven't used it yet. I assume you want to build a tracker that tracks on a compass heading until it pings a distance, then does another compass reading then tracks that heading. Am I correct.

I want to use a script like I just mentioned in my adventure bot to prove out, then into my R2D2.

Is this your idea ?

Ron R

#16  

Ron, basically. I am not worried about actual direction (ie, compass does not need to be accurate, but doea need to be precise). I want, when I reach an obstacle, to turn a certain number of degrees to the the left, if still blocked turn double that number of degrees right, and so on until not blocked.

The ping roam script dies this but it uses timers to decide how long to turn. Since different surfaces can determine the turn rate, I want to ise relative compass heading instead.

Accurate compass headings would be a bonus for navigation scripts too.

Alan

#17  

@Alan wouldnt you be better off using encoders equipped motors for this? (Hooping that this time I'll be the one helping!):)

Elfege

#18  

@elfege,

Probably, and when I build my large robot, I very well may go that way (although that doesn't resolve the issue of wheel slip on some surfaces), but for now, I am trying to do this with a modified RoLi revolution bot.

The goal of the project, which involves a lot of different functions, is to randomly wander around the house picking up cat toys when it recognizes them (which my cat leaves at random places, and I need to go around picking up so I have them available to throw.. My last cat would fetch and return, or just bring toys when she wanted to play, but my current cat is an idiot). When it has picked up a certain number, it will send me a notification (probably an email for now) and wait for instructions, at which point I would probably manually drive it to my location or wherever I want the toys dropped off. At some point I would add the ability to automatically navigate to a particular place automatically, but baby steps.....

Rich's Ping Roam script does a pretty good job on the randomly wandering piece, but occasionally it gets itself helplessly stuck in a corner or behind a piece of furniture. The compass would be used to determine if the turn was successful and allow alternate actions until free or until it has tried too many times and calls me for help.

Alan

PRO
Canada
#19  

Hey @Alan

Just wanted to let you know I haven't forgotten about this. I have also observed some inconsistencies in the raw compass values coming from the 4-in-1. We will be working on an optimized solution soon.

I also wanted to note (as a just-in-case) that with compass readings you do have to be mindful of ferrous metal and magnetic objects around the sensor. A compass is also called a magnetometer due to the fact that it can give you rough gauss readings of materials around the sensor. We are using the 4-in-1 as a true compass so you'll have to be mindful that a even servo output gear in close proximity to the sensor can effect compass readings.

#20  

@Jeremie I have the same issues as Alan... I don't think the random readings have anything to do with metallic interference. I have tried mine in several different areas in my house with the same results... .. We really appreciate you looking into this...

#21  

@Jeremie,

Thanks for the update. Yeah, I thought about the possible interference from the servos, so I hooked it up to an EZ-B on a power shell with nothing else connected or near it, and it still had numbers that made no sense. Putting my Android phone with a compass application in the same location, had dead-on readings as did a real magnetic compass.

Personally, I am not as concerned with accuracy as precision. ie, I don't care what direction is north, but if I move 10 degrees to the left, I want it to reflect that I have moved 10 degrees.

Alan

PRO
Canada
#22  

Cool, thanks for the info guys.

Just so I know that we are all on the same page you guys are monitoring the $CompassHeading variable, correct?

#23  

Correct, although the X, Y, and Z variables also don't seem to have any consistency to them. Not knowing the scale or exactly what they are trying to show doesn't help, but moving the same direction, the same difference, gets different results, so they are also not currently valuable.

Alan