Shop OBEX P1 Docs P2 Docs Learn Events
Can't get HMC5883L Compass to work in spin - works in bs2 — Parallax Forums

Can't get HMC5883L Compass to work in spin - works in bs2

reppigreppig Posts: 35
edited 2012-05-10 09:09 in Accessories
I am trying to get the HMC5883L Compass working for an AZ drive system. Using the spin demo code from:

https://sites.google.com/site/parallaxinretailstores/home/compass-module-3-axis-hmc5883l

It works fine except the Y axis reading is always -4096 which is an overflow or underflow or math error. HOWEVER, if I run the bs2 code from that page it works fine - no Y axis error.

The same is true for the programs listed on the HMC5883L part page. Can anyone tell me why the spin code gives an error and the bs2 code doesn't?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-08 09:49
    You may have copied the demo code incorrectly. I just hooked up an HMC5883L as shown on the demo code page, copied and pasted the demo program from the demo code page, and compiled and ran it with correct results. Note that the math engine isn't needed and the OBJ line for it can be commented out. I used BST and its terminal window rather than the Propeller Tool and the Propeller Serial Terminal since I'm using a Mac.
  • reppigreppig Posts: 35
    edited 2012-05-08 11:07
    Yes, it works with BST but not with the Propeller Tool and the Propeller Serial Terminal. But I need it working with the Propeller.

    I have still been playing with the propeller demo code - I added some print binary on the x, y, & z variables. Y raw is always 1111 0000 0000 0000. I changed the clock speed to see if I am reading to fast or slow no change.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-08 12:13
    I booted up my Windows XP under Parallels Desktop on the Mac, ran the Propeller Tool and PST and the compass works just as well as with the Mac BST. The only thing different from your setup is that I still commented out the reference to "SL32_INTEngine_2" because it's not used. Maybe later I'll try it with that OBJ reference in there.
  • TymkrsTymkrs Posts: 539
    edited 2012-05-08 16:59
    I don't know exactly what the problem is, but I got mine working this way:
    Part 1:
    http://tymkrs.tumblr.com/post/22237323716/parallax-compass-module-3-axis-hmc5883l-29133
    Part 2:
    http://tymkrs.tumblr.com/post/22258810035/parallax-compass-module-3-axis-hmc5883l-29133-part

    And I believe I did use the demo code. I might have altered it slightly just to get rid of some extraneous spaces... but I used it in PropTool and PST.
  • reppigreppig Posts: 35
    edited 2012-05-09 07:48
    I tried the commenting out the SL32_INTEngine_2 and still no joy. I have cut and paste the program several times, no joy. I tried the program from the product page "HMC5883L_demo.spin" - no joy.

    I understand how the program works and I see no errors. It is interesting that the Y axis is read out last - the X and Z axis do work. It's almost like the last read is having a problem. I even modified the program to only read the Y axis with no success. Yet the BS2 program works fine.

    Are you running at 80MHz?? Is it possible, I have a module on the edge so that the propeller fails yet the BS2 works?
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-05-09 08:07
    You might want to ensure you're using the latest Propeller Tool (latest is v1.3; be careful as some searches for the Propeller downloads page result in an old page with old software), and that you've got a solid power source for the Prop and sensor. If you're using a Prop board that derives its power from USB you may wish to try it with a secondary power source, and/or select a different USB port on your PC. Try a different ground connection.

    -- Gordon
  • reppigreppig Posts: 35
    edited 2012-05-09 08:14
    Running 1.3 using regulated power supply. Trial several USB ports. Just tried only reading z and y axis on the assumption of a timing issue -- z reads fine y no joy.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-05-09 09:17
    If you feel comfortable interfacing the compass to the Prop with appropriate 3.3<->5V level shifting, you might try feeding the sensor 5V rather than 3.3V.

    On the chance that pullup resistors would benefit you could try some 2.2K to 6.8K resistors between V+ and clock and data. I'm guessing the board has these pullups, but I don't see a schematic in the documentation so it's hard to know.

    You've never mentioned what Propeller board you're using or how you've connected it.

    You wrote above "Yes, it works with BST." Does that mean you actually tried it with BST and found it functional, using the same Propeller hardware you're using with Propeller Tool?

    -- Gordon
  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-09 09:30
    I literally took the HMC5883 out of the anti-static bag, plugged it into a mini-breadboard, ran jumpers from my standard QuickStart board as shown on the web page, plugged the USB cable into a USB port and the board, started up Windows and ran the Propeller Tool (1.3). I cut and pasted the program text from the web page you mentioned, commented out the line for the math engine and ran the program. It worked exactly "as advertised". Maybe you have a bad sensor ... it's rare, but not impossible. Call Parallax Tech Support.
  • PublisonPublison Posts: 12,366
    edited 2012-05-09 10:10
    I have verified that the code in the first post works on the PPDB with a VIN of 3V3. I tried the "DOWNLOAD" and Cut and Paste method, and the both worked as advertised.

    Try and do a "CLEAR" on the PST after the program has started running. I have noticed some extraneous data hanging out on the right hand side after start up, and it never changes until I hit "CLEAR".

    Jim

    EDIT: I used Propeller Tool 1.3
  • TtailspinTtailspin Posts: 1,326
    edited 2012-05-09 10:21
    Just a note, the Kickstart program for the BS2 shows SCL as Pin1 and SDA as Pin0, where as,
    The Propeller program shows SCL as Pin0 and SDA as Pin1... It got me the first time, and it looks like it got Tymkrs too. :)


    -Tommy
  • reppigreppig Posts: 35
    edited 2012-05-09 10:40
    I got it. I tried Gordon's suggestion of powering the compass with 5 volts and running the data line through a voltage divider into the propeller. It worked. I then tried again hooking everything backup at 3.3 volts and it still works. The only thing I can think of is that there was some kind of latchup situation that was cleared running at 5 volts.

    Thank you all for your suggestions and help.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-05-09 11:23
    Ttailspin wrote: »
    Just a note, the Kickstart program for the BS2 shows SCL as Pin1 and SDA as Pin0, where as,
    The Propeller program shows SCL as Pin0 and SDA as Pin1... It got me the first time, and it looks like it got Tymkrs too.

    As an FYI, this is so the setup is more consistent with the "master" demos the KickStarts are often derived from. Most users don't have both a BS2 and Prop, but they may go from the KickStart to the full demo. In this case, the data/clock lines mirror whatever is in the full demo. This isn't always the case, but it's an attempt to have a little more internally consistency. It also means any inconsistencies in the source material are reflected.

    -- Gordon
  • TtailspinTtailspin Posts: 1,326
    edited 2012-05-09 11:42
    I don't think I have mentioned what a great book you put together GordonMcComb,
    Microcontroller KickStarts is well organized, easy to follow, and just all around useful, Thanks. :thumb::thumb:
    I have tried every example except the Altimeter and GPS modules, and have had no problems.(other than my own laziness to double check my wiring)...

    -Tommy
  • JimInCAJimInCA Posts: 80
    edited 2012-05-10 09:09
    I had an interesting problem with a HMC5843 and the Propeller Demo Board a while back. You may want to read this thread and see if it applies to you as well.

    http://forums.parallax.com/showthread.php?133813-Issue-with-Propeller-Demo-Board...

    Jim...
Sign In or Register to comment.