2

So I bought this nucleo expansion board, the X-NUCLEO-IKS01A1, and on the package it says it is compatible with Arduino Uno.

My goal here is to read data from any sensor on this board. (When I can read one, I can probably read the others too using the same structure)

Here's my code.

#include <Wire.h>

#define ADDRESS 0x1E
#define REGISTER 0x16

void setup() {
  Serial.begin(9600);
  Wire.begin();
}

void loop() {
  // put your main code here, to run repeatedly
  Serial.println(I2CreadByte(ADDRESS, REGISTER));
  delay(5000);
}

uint8_t I2CreadByte(uint8_t address, uint8_t subAddress)
{
  uint8_t data; // `data` will store the register data  

  Wire.beginTransmission(address);      
  Wire.write(subAddress);                  
  Wire.endTransmission(true);         
  Wire.requestFrom(address, (uint8_t) 1); 

  data = Wire.read();                    
  return data;                   
}

This should return the temperature in 2's complement. But all it returns is a 1 (I can guarantee you it's not that cold in my room).

I have the board plugged on my Arduino.

Can anyone tell me what I'm doing wrong?

Here's the datasheet for the sensor I'm trying to communicate with.

Datasheet

The sub addresses are on page 33 and the I2C explantation on 27. It's called the LSM6DS0.

Thanks sooo much in advance.

1

You're using a wrong slave address. From the datasheet:

The Slave ADdress (SAD) associated to the LSM6DS0 is 110101xb. The SDO/SA0 pin can be used to modify the less significant bit of the device address. If the SDO/SA0 pin is connected to a voltage supply, LSb is ‘1’ (address 1101011b), else if the SDO/SA0 pin is connected to ground, the LSb value is ‘0’ (address 1101010b). This solution permits to connect and address two different inertial modules to the same I2C bus.

This means your sketch should contain:

#define ADDRESS 0x6A  // if SDO pin is pulled down

or:

#define ADDRESS 0x6B  // if SDO pin is pulled up

It's also a good idea to check if there's actually anything in the Wire buffer (with Wire.available()) before you attempt reading.

Finally, I suggest you read both OUT_TEMP_H and OUT_TEMP_L registers, in order to calculate the temperature correctly. The datasheet says the temperature output is zero at 25 degrees Celsius and that the sensitivity is 16 LSB/C. This means you have to read both registers, combine their results to get a 16-bit signed integer (OUT_TEMP_H is the MSB), divide it by 16 to get the temperature offset, and add the result to 25 degrees Celsius to get absolute temperature.

  • Where did you find the offset and precision? I can't seem to find them. – Casper Vranken Apr 20 '16 at 9:53
  • @CasperVranken Its all in a table in the datasheet. I dont remember the page but search the pdf for "LSB" and you should come across the 3-row table. The offset is mentioned below the table in a note. – TisteAndii Apr 20 '16 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.