hi to all...it's possibel to any help me with read 2 bytes of data in the i2c port...in the old librarys i read the data but in the new hal library no work...
i use this in arduplane 2.68 code with librarys ; my sensor address is 0X75...and put in the i2c line 2 byte of data when is request ...
#include <I2C.h>
#define addr 0x75
void setup()
{
I2c.begin();
delay(10);
Serial.begin(115200);
}
void loop()
{
int x = 0;
uint8_t buff[2];
I2c.read(addr,2,buff);
x = buff[1] << 8;
x |= buff[0];
Serial.println(x,DEC);
}
i tried with news hal librarys ,,,the code compile ok...but not read the i2c port...i read the i2c driver and the old library have more functions and the new not...its posible to error in the driver inside the AP_halavr???
#include <AP_Common.h>
#include <AP_Math.h>
#include <AP_Param.h>
#include <AP_Progmem.h>
#include <AP_HAL_AVR.h>
#include <AP_HAL.h>
const AP_HAL::HAL& hal = AP_HAL_BOARD_DRIVER;
#define addr 0x75
void setup()
{
hal.i2c->begin();
hal.scheduler->delay(10);
}
void loop()
{
int x =0;
uint8_t buff[2];
hal.i2c->read(addr, 2, buff);
x= buff[1] << 8 | buff[0];
hal.console->printf_P(PSTR("value= %d \r\n"),x,DEC);
hal.scheduler->delay(10);
}
AP_HAL_MAIN();
thank you very much for your attention to all and sorry my bad english...
best regards.
Replies
Hi Luis, our group recently modified the ArduPlane code to read battery information from a BQ34Z100 gas gauge sensor for LiPos, and we had to do the same transition from 2.6x to 2.7x. Here's a copy/paste of our verified working code in 2.73 (in our case, the code lives in sensors.pde):