I have an infrared sensor(OTI 301) which in order to display the desired temperature I need to apply a formula that depends on 3 binary numbers extracted from the sensor itself. I have tried different approaches but no success yet to extract these binary numbers. Please see link for the data sheet of the sensor where you can see useful information regarding the formula and the binary numbers. https://drive.google.com/file/d/1XMRDCNzY3fn0q6lkGejs5D-pqksfRuZ8/view also here is the code I have tried in the Arduino IDE. Also, attached picture are the needed commands to extract the data from the second data sheet, https://drive.google.com/file/d/1mmdkHkNbwC5VgQxGMrq07XolajNvgBkN/view. enter image description here
#include <Wire.h>
byte val[2] = {0x20,0x80};
void setup() {
Wire.begin(0x20); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop() {
//master writter
Wire.beginTransmission(0x20); // transmit to device
Wire.write(val,2);
//Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
//master reader
Wire.requestFrom(0x20, 6); // request 6 bytes from slave device
while (Wire.available()) { // slave may send less than requested
Serial.println("H");
char c = Wire.read(); // receive a byte as character
}
delay(500);
}
-
Try making your write data just 1 byte long, with value 0x80.The Photon– The Photon2019年11月12日 16:00:12 +00:00Commented Nov 12, 2019 at 16:00
-
0x20 is the shifted address (to make room for the read/write bit). Arduino expects the unshifted address, i.e. 0x10.Codo– Codo2019年11月12日 16:05:44 +00:00Commented Nov 12, 2019 at 16:05
1 Answer 1
There are likley two problems:
- An invalid device address is used. The device address is 0x10 and the Arduino Wire library expects it that way (and not in the shifted version with read/write bit).
- Your code uses two separate transactions, however the datasheet specifies a single transaction with a repeated START condition for separating the write and read part.
So an improved version looks like so:
#define DEVICE_ADDRESS 0x10
void loop() {
Wire.beginTransmission(DEVICE_ADDRESS);
Wire.write(0x80); // readout command
Wire.endTransmission(false); // stop sending without ending transaction (repeated START)
Wire.requestFrom(DEVICE_ADDRESS, 6); // request 6 bytes
uint8_t data[6];
for (int i = 0; i < 6; i++) {
data[i] = Wire.read();
}
}