View unanswered posts | View active topics It is currently Fri Apr 18, 2014 2:24 pm






Reply to topic  [ 2 posts ] 
Hitechnic accelerometer help needed. 
Author Message
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post Hitechnic accelerometer help needed.
Hello,

I’m new to the forums, RobotC, and I2C messaging.

I’m trying to use the Hitechnic Accelerometer Sensor and I’m not really sure how to get the data from the sensor.

I tried writing a simple program to learn how to do it, but I’m not really having much luck.

Here’s the program.

task main()
{
int xUpper,xLower;
int yUpper,yLower;
int zUpper,zLower;
int xVal,yVal,zVal;

typedef struct{
byte nMsgSize;
byte nDeviceAddress;
byte nLocationPtr;
byte nData;
} TI2C_Output;

SensorType[S1] = sensorI2CCustom;
wait10Msec(5);
nI2CBytesReady[S1]=0;
while(nI2CStatus[S1]== STAT_COMM_PENDING)
wait1Msec(2);

byte replyMessage[6];

TI2C_Output sOutput;

sOutput.nMsgSize = 6;
sOutput.nDeviceAddress = 0x02;
sOutput.nLocationPtr = 0x42;

while(true)
{
nI2CBytesReady[S1]=0;

sendI2CMsg(S1,sOutput.nMsgSize ,6);

while (nI2CStatus[S1]==STAT_COMM_PENDING)
wait1Msec(2);

if (nI2CStatus[S1]==NO_ERR) {

readI2CReply(S1, replyMessage[0], 6);

xUpper = (int)replyMessage[0];
yUpper = (int)replyMessage[1];
zUpper = (int)replyMessage[2];
xLower = (int)replyMessage[3];
yLower = (int)replyMessage[4];
zLower = (int)replyMessage[5];

xVal = (xUpper<<4)+xLower;
yVal = (yUpper<<4)+yLower;
zVal = (zUpper<<4)+zLower;

if(xVal > 511)
xVal -= 1024;
if(yVal > 511)
yVal -= 1024;
if(zVal > 511)
zVal -= 1024;

nxtDisplayTextLine(4, "x-val %d", xVal);
nxtDisplayTextLine(5, "y-val %d", yVal);
nxtDisplayTextLine(6, "z-val %d", zVal);

} else
{
nxtDisplayTextLine(3, "i2c err %d", nI2CStatus[S1]);
}
}
}

I put this together by looking at the robotC compass driver and a RobotC accelerometer program written for another sensor.

I’m not sure if the sensor needs to be initialized or not, there’s no information on Hitechnic’s site or elsewhere that I’ve been able to find.

I’ve tried initializing with:

sOutput.nMsgSize = 6;
sOutput.nDeviceAddress = 0x02;
sOutput.nLocationPtr = 0x42;
sOutput.nData = 0x00;
SensorType[S1] = sensorI2CCustomStd9V;

wait10Msec(5);
nI2CBytesReady[S1]=0;
sendI2CMsg(S1, sOutput.nMsgSize, 0);
while(nI2CStatus[S1]== STAT_COMM_PENDING)
wait1Msec(2);

I’m also not sure that I have the right device address.
I’m sure there are other problems here as well.

Any help I can get would be appreciated.

-Scott


Sun Apr 22, 2007 5:12 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post 
I posted a reply to this same question on the nxtasy.org forum. Read the following post from that forum http://forums.nxtasy.org/index.php?showtopic=1103&hl=acceleration.


Thu Apr 26, 2007 9:26 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.