Shop OBEX P1 Docs P2 Docs Learn Events
Two accelerometers at once — Parallax Forums

Two accelerometers at once

MoskogMoskog Posts: 554
edited 2011-03-24 14:13 in Propeller 1
Hello, I have a simple questions for you Prop-experts:

Im testing an accelerometer 2125 using this Object:

accel: "MXD2125 Simple"

Reading:

PUB Setup:
accel.start (X-outPin, Y-outPin)

This works great, but I need another accelerometer to be read at the same time.
Can I use the same Object or do I need to make another copy of MXD2125 Simple, so the whole thing will be like this:

OBJ
accel: "MXD2125 Simple"
accel2: "MXD2125 Simple2"

PUB Setup
accel.start (X-outPin, Y-outPin)
accel2.start (X-outPin2, Y-outPin2)

Is there a more simple way to do this?

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2011-03-23 14:22
    Well ... this can not be answered in general.

    There is code in the ObEx which has problems to be started twice. I guess the graphics driver could be an example (maybe you can have several objects but they'd show the same graphics).

    But usually objects can be "instanciated" more than once by the SAME SPIN filename. accel1, accel2 like you used it in your code is one way, using an object array is another one:

    OBJ
    acc[2]: "MXD2125 Simple"

    Problems can occur if the object uses DAT variables that need to store different values per instance. And as in the TV driver if an object uses HUB-RAM to store different data but has a fixed HUB-RAM address.
  • kf4ixmkf4ixm Posts: 529
    edited 2011-03-24 05:15
    yes, i've done it before with another object before, you're on the right track. just do this:
    OBJ
    accel: "MXD2125 Simple"
    accel2: "MXD2125 Simple" 
    
    PUB Setup 
    accel.start (X-outPin, Y-outPin)
    accel2.start (X-outPin2, Y-outPin2)
    
    you don't have to rename the same object, just make sure the variable that refers to it is different in name and the data it pulls from that object has different names.

    Hope this helps.
  • MoskogMoskog Posts: 554
    edited 2011-03-24 08:25
    OK, thanks to both of you, the Object file in this case seems very simple without any DAT-statesments so there should probably be no trouble there.
    Before reading the replies I was thinking about some modifications to the Object file to be able to handle to pairs of X- and Y-outputPins. In that case PUB Setup would start like this: accel.start ( X-outPin, Y-outPin, X2-outPin, Y2-outPin) I suppose that should work pretty well too.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2011-03-24 09:45
    That would normally be fine, but in this case the object uses the counters to measure the duty cycle of the signal produced by the accelerometer, and there are only two counters per cog. If the code was altered to do the measurements "directly" it wouldn't be hard to make it do both at once.
  • MoskogMoskog Posts: 554
    edited 2011-03-24 12:32
    OK, JasonDorie, see I still have a lot to learn and the people here are the best teachers you can find. The whole forum is a big supercomputer!

    I just connected the two accelerometers and programmed the Prop the way suggested by kf4ixm. It seems like that was the best solution because now I can read both of the 2125's easy and without any problems.

    Thank you so much MaglO2, kf4ixm and JasonDorie for your replies!
  • kf4ixmkf4ixm Posts: 529
    edited 2011-03-24 14:13
    Glad it worked for ya! i'm not sure if it's the best way to do it, but in my tests, it has worked great every time!
Sign In or Register to comment.