Shop OBEX P1 Docs P2 Docs Learn Events
Weird Problem: BS2 + Devantech CMPS03 Digital Compass. — Parallax Forums

Weird Problem: BS2 + Devantech CMPS03 Digital Compass.

koolitudekoolitude Posts: 37
edited 2007-02-26 15:13 in BASIC Stamp
I'm trying to·interface the CMPS03 compass with a BS2·on a Board of Education.

I downloaded the demo program from:
http://www.robot-electronics.co.uk/htm/cmps2bs2.shtml

The Compass Bearing·can then be shown on the debug window.

For the first 1-2 minute:
I got:
Compass Bearing (0-255 BRAD) 060
Compass Bearing (0-359 Degrees) 085
When I turned the compass, I got some other values that make sense.

But then,·(after around 1-2 minute; sometimes, several seconds)·I got the following values in the debug windows:
Compass Bearing (0-255 BRAD) 255
Compass Bearing (0-359 Degrees) 533

And the values do NOT change ANYMORE no matter to which direction I turn the compass.

In order to reset the whole thing, I gotta power off the circuit, download the program to BS2 again and run the program again.· Sometimes I needa repeat this procedure for several times before the compass gives values that make sense.

I notice that everytime when the values begin to oscillate between two values, say 085-087(Degrees)... It gets a higher chance to turn to 533 and stays there.

What's the cause of it???
Hardware problem? Software problem? Wiring Problem?
What should I do to fix this problem??

By the way, I have disconnected all other components from the BS2.· I just connected the compass with its circuitry to the BS2.

Please help! Million Thanks!!!!!!





Post Edited (koolitude) : 2/26/2007 6:15:09 PM GMT

Comments

  • LucLuc Posts: 8
    edited 2007-02-26 09:38
    '
    [noparse][[/noparse] Subroutines ]
    GoCap:
    DO

    pause 250

    GOSUB ReadBoussole
    IF angle > consigneCap THEN
    errCap = angle - consigneCap
    ELSE
    errCap = consigneCap - angle
    ENDIF

    IF errCap < errCapPermise THEN
    RETURN
    ENDIF

    DEBUG 2,0,0,"Consigne :", DEC3 consigneCap, " Compas :", DEC3 angle, " errCap :", DEC3 errCap
    i = i +1
    IF consigneCap < 180 THEN

    IF angle > consigneCap AND angle < consigneCap+180 THEN
    DEBUG 2,0,1, "Gauche"
    GOSUB gauche
    ELSE
    DEBUG 2,0,1, "Droite"
    'GOSUB droite
    ENDIF
    ELSEIF consigneCap >= 180 THEN

    IF angle < consigneCap AND angle > consigneCap-180 THEN
    DEBUG 2,0,1, "Droite"
    GOSUB droite
    ELSE
    DEBUG 2,0,1, "Gauche"
    GOSUB gauche
    ENDIF
    ENDIF

    LOOP




    ReadBoussole:
    devNum = 0 ' device address %000
    slvAddr = CMP03 | (devNum << 0) ' setup slave ID
    addrLen = 1
    wrdAddr = 1 ' addresse compas sur un octet $00->$FF
    GOSUB Read_Byte
    angle = i2cData
    DEBUG 2,0,2, "cmp :", DEC3 i, " angle :", DEC3 angle
    RETURN
  • LucLuc Posts: 8
    edited 2007-02-26 09:39
    '
    [noparse][[/noparse] Subroutines ]
    GoCap:
    DO

    pause ' <
    if not add this pause, not work perhaps is your PB

    GOSUB ReadBoussole
    IF angle > consigneCap THEN
    errCap = angle - consigneCap
    ELSE
    errCap = consigneCap - angle
    ENDIF

    IF errCap < errCapPermise THEN
    RETURN
    ENDIF

    DEBUG 2,0,0,"Consigne :", DEC3 consigneCap, " Compas :", DEC3 angle, " errCap :", DEC3 errCap
    i = i +1
    IF consigneCap < 180 THEN

    IF angle > consigneCap AND angle < consigneCap+180 THEN
    DEBUG 2,0,1, "Gauche"
    GOSUB gauche
    ELSE
    DEBUG 2,0,1, "Droite"
    'GOSUB droite
    ENDIF
    ELSEIF consigneCap >= 180 THEN

    IF angle < consigneCap AND angle > consigneCap-180 THEN
    DEBUG 2,0,1, "Droite"
    GOSUB droite
    ELSE
    DEBUG 2,0,1, "Gauche"
    'GOSUB gauche
    ENDIF
    ENDIF

    LOOP




    ReadBoussole:
    devNum = 0 ' device address %000
    slvAddr = CMP03 | (devNum << 0) ' setup slave ID
    addrLen = 1
    wrdAddr = 1 ' addresse compas sur un octet $00->$FF
    GOSUB Read_Byte
    angle = i2cData
    DEBUG 2,0,2, "cmp :", DEC3 i, " angle :", DEC3 angle
    RETURN
  • koolitudekoolitude Posts: 37
    edited 2007-02-26 09:42
    Sorry...how can·I use this? I'm new to Basic stamp... not quite sure where should I put this..

    By the way, some symbols and subroutines are not defined in your program...

    What are they exactly?

    Anyway, Thank you very much!



    Post Edited (koolitude) : 2/26/2007 11:34:34 AM GMT
  • koolitudekoolitude Posts: 37
    edited 2007-02-26 15:13
    Any idea? Please help... Thank so much
Sign In or Register to comment.