My "HK MultiWii Pro" is having a onboard 5v I2C Interface (Level-Converters)...
When i compile the Arduino I2C-Examples ..
MultiWii Arduino I2C - Master Receiver:
Code: Select all
// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.requestFrom(2, 6); // request 6 bytes from slave device #2
while(Wire.available()) // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
delay(500);
}
Arduino I2C-Slave-Sender
Code: Select all
// Wire Slave Sender
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Sends data as an I2C/TWI slave device
// Refer to the "Wire Master Reader" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup()
{
Wire.begin(2); // join i2c bus with address #2
Wire.onRequest(requestEvent); // register event
}
void loop()
{
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}
Everything works FINE!!
But if i re-upload the MultiWii Firmware .. i receive the i2c commands but it seams like the multiwii is not receiving the answer ?! ...
What do i try to do?
I own a hc-sr04 ultra-sonic-sensor .. it's a 5v sensor .. i wanna use the arduino as an i2c-emulation for a srf02 i2c ultra-sonic sensor.
cause i wanna implement a sonar based althold.
well as it looks like i am confused *g* ...
multiwii contains:
Code: Select all
void i2c_srf08_discover() {
uint8_t addr;
uint16_t x;
// determine how many sensors are plugged in
srf08_ctx.sensors=0;
addr = SRF08_SENSOR_FIRST;
for(int i=0; i<SRF08_MAX_SENSORS && x!=0xff; i++) {
// read the revision as a way to check if sensor exists at this location
x = i2c_try_readReg(addr, SRF08_REV_COMMAND); <<<<<----------- I recv. this I2C-Message (well 0x00) and do a I2cWrite ... but
if(x!=0xffff) {
// detected a sensor at this address <<<<--------------------- this point is not reached, cause the result is always 0xffff ????
srf08_ctx.sensors++;
addr += 2;
}
}
........
well the arduino code looks basicly like:
Code: Select all
...setup...
Wire.begin(0xF0); // join i2c bus with address 0xF0
Wire.onReceive(receiveEvent); // register event
......
...receiveevent....
void receiveEvent(int howMany)
{
if (howMany < 1) return;
cntevt++;
byte cmd = Wire.read();
if (cmd == 0) { Wire.write(1); } // Req. for Firmware Version, blocking if busy
if (cmd == 2) { Wire.write(1);Wire.write(2); } // GetRange request ...
.....
Is there any special thing i should know about i2c in the multiwii firmware????
greetz and thanks for reading Dorty