View unanswered posts | View active topics It is currently Mon Feb 27, 2017 12:25 am

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

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

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;
while(nI2CStatus[S1]== STAT_COMM_PENDING)

byte replyMessage[6];

TI2C_Output sOutput;

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


sendI2CMsg(S1,sOutput.nMsgSize ,6);

while (nI2CStatus[S1]==STAT_COMM_PENDING)

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;

sendI2CMsg(S1, sOutput.nMsgSize, 0);
while(nI2CStatus[S1]== STAT_COMM_PENDING)

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.


Sun Apr 22, 2007 5:12 am

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
I posted a reply to this same question on the forum. Read the following post from that forum

Thu Apr 26, 2007 9:26 am
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.