Hi all,
I’m tying to adapt this arduino code for a particle photon but I get wrong values from my sensor (see below). I tried the arduino code and it works well with my uno.
Any ideas?
Thanks a lot !
#include <Wire.h>
void writeI2CRegister8bit(int addr, int value) {
Wire.beginTransmission(addr);
Wire.write(value);
Wire.endTransmission();
}
unsigned int readI2CRegister16bit(int addr, int reg) {
Wire.beginTransmission(addr);
Wire.write(reg);
Wire.endTransmission();
delay(20);
Wire.requestFrom(addr, 2);
unsigned int t = Wire.read() << 8;
t = t | Wire.read();
return t;
}
void setup() {
Wire.begin();
Serial.begin(9600);
writeI2CRegister8bit(0x20, 6); //reset
}
void loop() {
Serial.print(readI2CRegister16bit(0x20, 0)); //read capacitance register
Serial.print(", ");
Serial.print(readI2CRegister16bit(0x20, 5)); //temperature register
Serial.print(", ");
writeI2CRegister8bit(0x20, 3); //request light measurement
Serial.println(readI2CRegister16bit(0x20, 4)); //read light register
}
Here is my Particle code:
#include "application.h"
void writeI2CRegister8bit(int addr, int value) {
Wire.beginTransmission(addr);
Wire.write(value);
Wire.endTransmission();
}
unsigned int readI2CRegister16bit(int addr, int reg) {
Wire.beginTransmission(addr);
Wire.write(reg);
Wire.endTransmission();
delay(20);
Wire.requestFrom(addr, 2);
unsigned int t = Wire.read() << 8;
t = t | Wire.read();
return t;
}
void setup() {
Wire.begin();
Serial.begin(9600);
writeI2CRegister8bit(0x20, 6); //reset
}
void loop() {
Particle.publish("test", String(readI2CRegister16bit(0x20, 0))); //read capacitance register
Particle.publish("test", String(readI2CRegister16bit(0x20, 5))); //temperature register
writeI2CRegister8bit(0x20, 3); //request light measurement
Particle.publish("test", String(readI2CRegister16bit(0x20, 4))); //read light register
}
The data i get from all the particile.publish:
{“data”:“4294967295”,“ttl”:“60”,“published_at”:“2016-02-01T20:04:17.514Z”,“coreid”:“210025001047343339383037”,“name”:“test”}