Post a new topicPost a reply Page 1 of 1   [ 6 posts ]
Author Message
 Post subject: Change the .h file
PostPosted: Fri Jun 22, 2012 8:59 am 

Joined: Tue May 22, 2012 11:40 am
Posts: 22
Hi,

I wan to interface an external accelorometer with the waspmote.Can u please tell me how to cahnge the i2c address to access the new slave.

Thanku very much


Top
 Profile  
 
 Post subject: Re: Change the .h file
PostPosted: Mon Jun 25, 2012 8:56 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
Hi jahnavi,

you will have to use direct communication through the I2C, you can check the use of the Wire library upon which the I2C communication is implemented in the Arduino Reference Guide:

http://arduino.cc/en/Reference/Wire

Regards.


Top
 Profile  
 
 Post subject: Re: Change the .h file
PostPosted: Mon Jun 25, 2012 11:04 am 

Joined: Tue May 22, 2012 11:40 am
Posts: 22
Hi Sir,

Is there any function similar to Wire.read() in waspmote?I am trying to read the data from the external accelorometer connected to the waspmopte can u please provide any example code to read the data from the slave.

Thanku very much


Top
 Profile  
 
 Post subject: Re: Change the .h file
PostPosted: Mon Jun 25, 2012 2:56 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
jahnavi,

We do not have this example available. Sorry about that.

However, you can take a look by yourself into wire library. You can use API browser, but keep in mind that is not updated with last API version, so always check .cpp and .h to be sure you are doing what you exactly want.

Regards.


Top
 Profile  
 
 Post subject: Re: Change the .h file
PostPosted: Tue Jun 26, 2012 4:34 am 

Joined: Tue May 22, 2012 11:40 am
Posts: 22
Hi Sir,

In the waspAcc.h file the readregister function is defined as follows

int16_t readRegister(uint8_t address)
{
uint8_t aux = 0;
Wire.beginTransmission(i2cID);
Wire.send(regnum);
Wire.endTransmission();
Wire.requestFrom(i2cID, 1);
if(Wire.available())
{
aux = Wire.receive();
return aux;
}

return -1;
}

I this the address is the address of the register which i want to read from and i2cID is the slave address but how about Wire.send(regnum).Can u please explain me what does this function does and what is the "regnum" means.


Thanku very much


Top
 Profile  
 
 Post subject: Re: Change the .h file
PostPosted: Tue Jun 26, 2012 8:41 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
jahnavi,

This is not correct.

The function defined in WaspACC.cpp is as follows:

// reads a register from the accelerometer
// returns its value or -1 if error
int16_t WaspACC::readRegister(uint8_t regNum)
{
// reset the flag
flag &= ~(ACC_ERROR_READING);

uint8_t aux = 0;
Wire.beginTransmission(i2cID);
Wire.send(regNum);
Wire.endTransmission();

Wire.requestFrom(i2cID, 1);
if(Wire.available())
{
aux = Wire.receive();
return aux;
}

// error, activate the reading flag
flag |= ACC_ERROR_READING;

return -1;
}


where regNum is the register you want to read.

Regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 6 posts ]


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

Search for:
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use