Pages: [1]   Go Down
Author Topic: I2C Registers  (Read 324 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46224
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16540
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
//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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll try that, thanks.
Logged

Pages: [1]   Go Up
Jump to: