Go Down

Topic: I2C Registers (Read 438 times) previous topic - next topic

Robotkid

I have a bunch of I2C sensors with registers but have no way to read the registers. I have looked at the wire library in the reference section of the website but can't seem to find any way to read individual registers at a time via I2C.
What command in the Arduino software can I use to read individual registers?
If it is multiple commands what should I do?
Thanks
Robotkid

PaulS

Quote
I have a bunch of I2C sensors with registers but have no way to read the registers.

How about if you start by posting a link to one of them?

Robotkid


Quote
I have a bunch of I2C sensors with registers but have no way to read the registers.

How about if you start by posting a link to one of them?


Sure here is one.
http://mindsensors.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=61
They are actually for another micro controller (lego mindstorms) but this website sells adapters for breadboards so I am able to connect to Arduino.

retrolefty

You really have to start with the datasheet for the specific I2C device you are working with.

Here is one where I needed to read a word (2 byte) register from a I2C ADC device. First I had to send a single byte 'register pointer' to the device and then request two bytes from the device.

Code: [Select]
//Function to read ADC conversion data from device
int getadcReading()   // read 16 bit analog voltage reading
{
 int data;
 const int deviceAdd = 0x48;              // ADS1115 address with address pin grounded
 Wire.beginTransmission(deviceAdd); // transmit to I2c device address
 Wire.send(0x00);                   // point to device register 0
 Wire.endTransmission();            // stop transmitting

 Wire.requestFrom(deviceAdd, 2);    // request 2 bytes from slave device
 while(Wire.available())            // need two bytes, MSB and LSB of converstion value
 {
   data = Wire.receive();         // get MSB of reading
   data = data << 8;              // shift it to high byte of data
   data = data + Wire.receive();  // add LSB to data
 }
 return data;
}



Lefty

Robotkid

I'll try that, thanks.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy