I am doing a project with an arduino UNO with an Xsens connected by I2C and sends the data via bluetooth to matlab in a PC. Right now, if I load the master code from a computer it works. If I load the same sketch from another one (with the same libraries), it gives me one of the variables continuously 0. The variable is xsens.getRot(). My wire buffer is in 132 bytes. This is my code:
#include <XSens.h>
#include <Wire.h>
char sinc = '0';
bool recibir = false;
float tTimeStamp = 0.0;
//Initializing XSens at ADDRESS 0X6B
int j =0;
XSens xsens(0x6B);
void setup() {
Serial.begin(9600);
Wire.begin();
xsens.begin();
}
void loop() {
if (Serial.available() > 0) {
sinc = Serial.read();
}
if (sinc == '1') {
recibir = true;
}
else if (sinc == '0') {
recibir = false;
}
if (recibir) {
RecibirDatos();
}
}
void RecibirDatos(){
//Read mesurements (Reads all data given by the AHRS)
xsens.updateMeasures();
for(int i = 0 ; i < 3; ++i){
Serial.println(xsens.getAccel()[i],6);
}
for(int i = 0 ; i < 3; ++i){
Serial.println(xsens.getRot()[i],6);
}
for(int i = 0 ; i < 3; ++i){
Serial.println(xsens.getEulerd()[i],6);
}
for(int i = 0 ; i < 3; ++i){
Serial.println(xsens.getMag()[i],6);
}
delay(100);
}
It is the same sketch in the same arduino uno with the same xsens. The only thing that changes is the pc I upload the sketch from. So I thougt it would be a library thing, but I also have the same libraries and the same IDE version, so I can not understand what happens.
I copy paste the librarys (to have the same version) in the correct spot. I add wire.h in C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire and xsens.h in C:\Users\nperez091\Documents\Arduino\libraries\XSens
why? The one .h file - is not a correct library. You should copy entire XSens dir from the PC where the code works to the one where is not. Regarding wire.h - this file is part of Arduino IDE installation and you do not need copying it manually.
Yes, I copy the entire Xsens dir, maybe I I have explained myself . I know I can install wire from arduino but I was not working so I finally copy it. Also I had to change the buffer from wire.h and twi.h, but that works fine in my other pc.