Oh nevermind about the pin nums, I was looking at the first one which
didn't appear to have any constants.
Could you explain how the sub works and how it returns anything to
whatever called it?
--- In , "Jonathan" <Jonathan@p...> wrote:
>
> Thank you all for your replys. I knew it must've been done before
> because I found some old messages (with no source code or useful
> information of any kind I think.)
> Jeff - would you mind me using the source code in an educational
> project? (Credit given where due, of course.) Also what pins go where?
>
> Sorry I'm so late in responding to this, I have too many projects
> going and the one I'm planning on using the compass for is close to
> the back of the list and I still need to get some more metal stock and
> use of a mill to even put control systems on. (Planning on using a
> Motor Mind C by Solutions^3 on it, anyone have example code for that?
> Heh I'm too lazy...)
>
> Anyone know the best source for 3" x 1/8" x 1' of aluminum
stock? They
> don't carry that width at any of the "home improvement"
stores in my
area.
>
> I should've made this robot in gold anodized aluminum that'd be
awesome.
>
> -Jonathan
>
> --- In , Jeff Sampson <jsampson@p...> wrote:
> > wrote:
> >
> > > Message: 8
> > > Date: Thu, 27 Jan 2005 01:20:12 -0600
> > > From: Mike Perks <basicx@a...>
> > > Subject: Re: Vector 2x compass module
> > >
> > > Jonathan,
> > >
> > > Google is your friend. I found the following links which will
help a
> > > lot. It should be easy to convert
them.
> > >
> > > http://www.phanderson.com/printer/compass/compass.html
> > > http://www.seanet.com/~karllunt/vector2x.htm
> > > http://handyboard.com/software/contrib/tomb/
> > > http://www.robotics.com/arobot/vector.html
> > >
> > > I'm not sure why this guy had a problem with using SPI to
the
> device but
> > > worth knowing:
> > > http://robots.tonkaland.com/list-archive/msg01054.html
> > >
> > > Mike
> > >
> > >
> > >>I recently ordered a Vector 2x compass module...
> > >>How do I interface it with the basicX?
> > >>Example code?
> > >>
> > >>function getCompassDirection() as integer
> > >>Anyone have the above?
> >
> >
> > "this guy" just happened to be listening... :-)
> >
> > I finally decided it is because the SPI on the BX24 drops slave
select
> > between accesses to the Vector 2X comapss. It
has to do this since
the
> > BX24 fetches more instructions from its
EEPROM before it can
proceeed.
> > The compass apparently resets the interface
if you drop the slave
> select
> > line.
> >
> > But if you bit-bang the interface it works fine.
> >
> > Hey, it's miracle!!!! The source code from about 3 computers ago
is
> > buried on this one. :-)
> >
> > I'll attach the subroutine for the compass. It has a note that
says
> that
> > I started with (eGroups BasicX msg #3086). You can see the SPI
> > instructions commented out. Maybe someone else will notice
something I
> > was doing wrong... And this was a long time
ago. Maybe something has
> > changed on the BX24 or a new compass.
> >
> > I have the rest of the code I was using if you need that in
addition to
> > the subroutine.
> >
> > --
> > Jeff Samspon
> >
> > ==== First Version ====
> >
> > ' V2X.Bas - For the BasicX BX24 processor module
(http://www.basicx.com)
> > '
> > ' Reads Vector 2X compass and sends results out serial port.
> > '
> > ' Based on:
> > ' DispEEPROM.bas by Peter H. Anderson, Baltimore, MD
> > ' The subroutine GetV2XData by Victor Fraenckel (eGroups
BasicX msg
> > #3086)
> > ' Vector 2X manual
> > '
> > Sub V2X()
> >
> > Dim temp as byte
> > Dim Dummy as byte ' Fake send byte
> > dim high as integer
> > dim low as integer
> > dim ct as byte
> > dim i as byte
> > dim j as byte
> > dim int_out as integer
> >
> > ' call putpin(V2X_SS,1)
> >
> > 'request a heading by setting P/C low for 10 milliseconds
> > Call Putpin(pc, 0) 'V2X P/C pin low
> > Delay(0.01)
> > Call Putpin(pc, 1) 'set V2X P/C high again
> >
> > 'wait for V2X to read heading
> > do while(Getpin(eoc) = 0) 'eoc=1 signals complete
> > loop
> >
> > Delay(0.01) 'wait 10ms
> >
> > ' ' Read 2 bytes from V2X through the SPI port
> > ' Call SPICmd(1, 0, Dummy(1), 2, Recv_Dat(1)) ' On channel
1,
> > send 0 bytes, receive 2 bytes
> >
> > ' ' Read 2 bytes from V2X through the SPI port
> > ' Call SPICmd(1, 0, Dummy(1), 1, Recv_Dat(2)) ' On channel
1,
> > send 0 bytes, receive 2 bytes
> >
> > call putpin(V2X_SS,0)
> >
> > high=0
> > low=0
> >
> > delay(0.005)
> > for ct=1 to 8
> > call putpin(sclk,0)
> > call putpin(sclk,1)
> > high=high*2+cint(getpin(sdin))
> > next
> >
> > delay(0.005)
> > for ct=1 to 8
> > call putpin(sclk,0)
> > call putpin(sclk,1)
> > low=low*2+cint(getpin(sdin))
> > next
> >
> > delay(0.010)
> >
> > call putpin(V2X_SS,1)
> >
> > ' debug.print CStr(high); " "; CStr(low)
> >
> > ' int_out=cint(cuint(high) and
15))*100+(low\16)*10+cint((cuint(low)
> > and 15))
> > ' debug.print int_out
> >
> > debug.print CStr(cuint(high) and 15); CStr(low\16);
CStr(cuint(low)
> > and 15)
> >
> > ' delay(0.5)
> >
> > ' debug.print CStr(Recv_Dat(1)); CStr(Recv_Dat(2)) ' ;
> > CStr(Recv_Dat(3)); CStr(Recv_Dat(4))
> >
> > ' ' I have the BCD/Bin grounded so the data is BCD, so
display the
> > 4 nibbles as numeric digits
> > ' debug.print CStr(Recv_Dat(1)\16); CStr(Recv_Dat(1) and 15);
> > CStr(Recv_Dat(2)\16); CStr(Recv_Dat(2) and 15)
> >
> > End Sub
> >
> > ==== Another version ====
> >
> > Option Explicit
> >
> > ' BX-24 I/O pins
> > Const V2X_SS as Byte = 12
> > Const V2X_PC as Byte = 11
> > Const V2X_EOC as Byte = 10
> > Const V2X_SCLK as Byte = 8
> > Const V2X_SDIN as Byte = 7
> >
> > ' V2X.Bas - For the BasicX BX24 processor module
(http://www.basicx.com)
> > '
> > ' Reads Vector 2X compass and sends results out serial port.
> > ' This is based on the subroutine GetV2XData by Victor Fraenckel
> > (eGroups BasicX msg #3086)
> >
> > public sub v2x_init()
> > call putpin(V2X_SCLK,1)
> > call putpin(V2X_SS,1)
> > end sub
> >
> > public sub read_v2x()
> >
> > Dim temp as byte
> > Dim Dummy as byte ' Fake send byte
> > dim high as integer
> > dim low as integer
> > dim ct as byte
> > dim i as byte
> > dim j as byte
> >
> > ' request a heading by setting P/C low for 10 milliseconds
> > Call Putpin(V2X_PC, 0) 'V2X P/C pin low
> > Delay(0.01)
> > Call Putpin(V2X_PC, 1) 'set V2X P/C high again
> >
> > 'wait for V2X to read heading
> > do while(Getpin(V2X_EOC) = 0) 'eoc=1 signals complete
> > loop
> >
> > Delay(0.01) 'wait 10ms
> >
> > ' ' Read 2 bytes from V2X through the SPI port
> > ' Call SPICmd(1, 0, Dummy(1), 2, Recv_Dat(1)) ' On channel
1,
> > send 0 bytes, receive 2 bytes
> >
> > ' ' Read 2 bytes from V2X through the SPI port
> > ' Call SPICmd(1, 0, Dummy(1), 1, Recv_Dat(2)) ' On channel
1,
> > send 0 bytes, receive 2 bytes
> >
> > call putpin(V2X_SS,0)
> >
> > high=0
> > low=0
> >
> > delay(0.005)
> > for ct=1 to 8
> > call putpin(V2X_SCLK,0)
> > call putpin(V2X_SCLK,1)
> > high=high*2+cint(getpin(V2X_SDIN))
> > next
> >
> > delay(0.005)
> > for ct=1 to 8
> > call putpin(V2X_SCLK,0)
> > call putpin(V2X_SCLK,1)
> > low=low*2+cint(getpin(V2X_SDIN))
> > next
> >
> > delay(0.010)
> >
> > call putpin(V2X_SS,1)
> >
> > debug.print "Angle =";CStr(high\16); CStr(cuint(high) and
15);
> > CStr(low\16); CStr(cuint(low) and 15); " ";
> >
> > end sub
|