Hi,
I saw a few posts on this group describing how to integrate some sensors but was unable to find how to actually port lets say the Wire.h library from older Arduino distributions. I want to know how to do this for Pixhawk and for the older ArduPilot boards.
Particularly, I'm trying to integrate a heart rate monitor to the quad in order to measure pilots excitement and perhaps switch to autopilot based on how nervous the guy is :) Full code to translate con be found here: heart sensor
Technically what I want to know the equivalent instructions to the following:
- Wire.begin();
- Wire.requestFrom(addr,numberOfBytes);
And if the following methods are equivalent to write() and read() from AP_HAL_AVR/I2CDriver.cpp.
from AP_HAL_AVR/I2CDriver.cpp :
- uint8_t AVRI2CDriver::write(uint8_t addr, uint8_t len, uint8_t* data), main differente with writeRegister() is that here I can choose to send 1 or many values.
- int8_t AVRI2CDriver::read(uint8_t addr, uint8_t len, uint8_t* data), seems to be pretty much the same as GetData()
void writeRegister(int deviceAddress, byte address, byte val) {
//I2C command to send data to a specific address on the device
Wire.beginTransmission(deviceAddress); // start transmission to device
Wire.write(address); // send register address
Wire.write(val); // send value to write
Wire.endTransmission(); // end transmission
}
boolean GetData(byte addr, byte numBytes, byte* dataArray){
//Get data from sensor and fill dataArray byte with responce
//Returns true if it was able to get it, false if not
Wire.requestFrom(addr, numBytes);
if (Wire.available()) {
for (int i=0; i<numBytes; i++){
dataArray[i] = Wire.read();
}
return true;
}else{
return false;
}
}
Thanks for your support! :) And I'm sure this'll help others also trying to get their old arduino sensors to work with the next generation of APMs.
Replies
Hi Craig,
THANKS for your comment!
I do not intend to reinvent the wheel, I'm just trying to keep it "simple". After all, there's the user loop in the arducopter firmware for a reason.
For other applications I have done as you said using either Raspberry Pi or Intel Edison but in this case I want to keep the hardware at a minimum and make the best out of the HAL libraries.
Craig said:
I personally think you are taking the wrong approach here and would not need to re-invent the wheel if you just used an arduino/teensy in conjunction with the APM/Hawks as an off board computer setup. The Arduino would do all grunt work and then just issue commands to the APM/Hawk over mavlink.