Mesmic 2125 accelerometer
Don French
Posts: 126
Now that I have my compass module working fairly well, I have a problem with the Mesmic 2125 accelerometer.· I got it to work perfectly with the example code·for the BS2, but on the Javelin I get nothing back but zero values.· I am only trying to read the X axis and am only interested in the raw value.· I thought this single line of code should do the trick:
·int value =· CPU.pulseIn(20000, CPU.pin7, true);
It appears to be wired up correctly and pins 3 and 4·are tied together and go to ground, so I don't know why I am not getting any results.· Could it be something about the CPU.pulseIn() method that is different than the BASIC PULSEIN?
·int value =· CPU.pulseIn(20000, CPU.pin7, true);
It appears to be wired up correctly and pins 3 and 4·are tied together and go to ground, so I don't know why I am not getting any results.· Could it be something about the CPU.pulseIn() method that is different than the BASIC PULSEIN?
Comments
to reflect the same time.
regards peter
A standard BS2 has a 2 uS unit, the javelin has a 8.68 uS unit and may not
detect pulses smaller than 8.68 uS (the BS2 would detect those).
regards peter
But if I remember it right there is an error in the code.
"findDutyFactor" in "Accelerometer.java" have the line:
It can give wrong values (if I remeber it right).
So, next I tried running a loop that sets the timeout value to every possible value between 0 and 32000. I never got anything but 0 for output on the X pin. (I was not interested in the Y pin and didn't have it connected.) But for grins I connected the Y pin and tried the the same loop with it pin and I got a non-zero value when timeout got to 300. So, this makes me think that the X pin on the Mesmic isn't working. But there was one more thing to try before returning it (can you do that?). And that was to change the Javelin I/O pin used for the pulsing the X pin. And guess what? It worked! It seems my Javelin I/O pin 7 is dead. (Which sucks, but at least my accelerometer module now works!)
You can find the 32bit integer class here:
http://www.parallax.com/javelin/applications.asp#AN011
So to fix the error returned by the line "return ( (50 * onTime) / (t2Time / 2) );" You coud do the following with that entire method
public int findDutyFactor( char axis )
{
Int32 dutyfactor= new Int32(0);
int onTime = 0;
switch (axis)
{
case 'x': dutyfactor.set(0,findPulseWidth( txPin )*50);
break;
case 'y': dutyfactor.set(0,findPulseWidth( tyPin )*50);
break;
default: System.out.println("Error: Invalid Axis");
break;
}
dutyfactor.divide(t2Time/2);
return dutyfactor.low;
}
You will, of course, have to have the Int32 class from the above link and the import line below in the Accelerometer class
import stamp.math.Int32;
That should fix that error