Multiwii 2.4 as Slave

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
snow-man-01
Posts: 18
Joined: Mon Jul 18, 2016 9:50 am

Multiwii 2.4 as Slave

Post by snow-man-01 »

Hello,

I want to set the Multiwii as Slave. I have another Arduino and I want to sent data from Arduino to Multiwii. Does anybody know where in the Code Multiwii 2.4 I can set the following code for the slave:

#include <Wire.h>

void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}

void loop() {
delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}

gregd72002
Posts: 103
Joined: Fri Dec 12, 2014 5:16 pm

Re: Multiwii 2.4 as Slave

Post by gregd72002 »

Multiwii uses its own I2C implementation and is not using Wire.h. Combining 2 different i2c approaches is not a good idea and most likely will never work.

snow-man-01
Posts: 18
Joined: Mon Jul 18, 2016 9:50 am

Re: Multiwii 2.4 as Slave

Post by snow-man-01 »

Mh,.. Do you have any idea to solve this problem?

gregd72002
Posts: 103
Joined: Fri Dec 12, 2014 5:16 pm

Re: Multiwii 2.4 as Slave

Post by gregd72002 »

it depends on what you are trying to do. Do you have to use i2c, why not to use serial? What data will you be sending, how much of it....

snow-man-01
Posts: 18
Joined: Mon Jul 18, 2016 9:50 am

Re: Multiwii 2.4 as Slave

Post by snow-man-01 »

Yes, I use i2c. what do you mean with serial? ftdi interface?

I want to send int values from an arduino to multiwii. this arduino is connected with 8 ultrasonic sensor. So the arduino sends values from the sensor to the multiwii. There are 100 values sent per second.

The post ist already working when the multiwii controller does not have the code for the quadcopter.

gregd72002
Posts: 103
Joined: Fri Dec 12, 2014 5:16 pm

Re: Multiwii 2.4 as Slave

Post by gregd72002 »

for arduino to arduino communication over i2c you might want to take a look at I2C_GPS_NAV for and example

I2C_GPS_NAV is an arduino based software that interfaces with Multiwii on one end and GPS on the other:

MultiWii <-------[i2c]------> I2C_GPS_NAV <---------- [serial] ---------> GPS

snow-man-01
Posts: 18
Joined: Mon Jul 18, 2016 9:50 am

Re: Multiwii 2.4 as Slave

Post by snow-man-01 »

I do not want to use the GPS. Or must I only use the I2C_GPS_NAV without using GPS to connent the arduino to multiwii?

gregd72002
Posts: 103
Joined: Fri Dec 12, 2014 5:16 pm

Re: Multiwii 2.4 as Slave

Post by gregd72002 »

I2C_GPS_NAV is just an example. You will need to code something yourself.

snow-man-01
Posts: 18
Joined: Mon Jul 18, 2016 9:50 am

Re: Multiwii 2.4 as Slave

Post by snow-man-01 »

can you send me more information (a link) please where I can connect the arduino pro mini to Multiwii? I do not know how I can do that.

User avatar
Hamburger
Posts: 2557
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Multiwii 2.4 as Slave

Post by Hamburger »

Use the msp protocol over serial

snow-man-01
Posts: 18
Joined: Mon Jul 18, 2016 9:50 am

Re: Multiwii 2.4 as Slave

Post by snow-man-01 »

what must I change in the protocoll.cpp? I see two important function: void serialCom and void evaluateCommand.

snow-man-01
Posts: 18
Joined: Mon Jul 18, 2016 9:50 am

Re: Multiwii 2.4 as Slave

Post by snow-man-01 »

I added this under the function evaluateCommand:

case MSP_Data_promini
mspAck();
s_struct_w((uint8_t*),);
break;


But do not know what I must add into.

Zviki
Posts: 25
Joined: Sat May 28, 2016 7:39 pm

Post by Zviki »

I think that sonar could work through digital input pin... Next time try Google. [URL]Arduino Sonar - Arduino Project Hub
https://create.arduino.cc/projecthub/fa ... dar-69b8fe[/URL]

Sent from my SM-N910C using Tapatalk


snow-man-01
Posts: 18
Joined: Mon Jul 18, 2016 9:50 am

Re: Multiwii 2.4 as Slave

Post by snow-man-01 »

Yes, but I want to connect 8 Ultrasonic sensors. There are not enough digital ports.

Zviki
Posts: 25
Joined: Sat May 28, 2016 7:39 pm

Multiwii 2.4 as Slave

Post by Zviki »

snow-man-01 wrote:Yes, but I want to connect 8 Ultrasonic sensors. There are not enough digital ports.

You can connect them through I2C. All on the same port. You just need to assign different address for each one. Also, on second link I posted is explained how to connect Arduino to Arduino.

Sent from my SM-N910C using Tapatalk

Zviki
Posts: 25
Joined: Sat May 28, 2016 7:39 pm

Post by Zviki »

Here is explained how to and also code is there How to connect more than 10 sensors to Arduino uno r3 - Arduino Stack Exchange
http://arduino.stackexchange.com/questi ... ino-uno-r3

Sent from my SM-N910C using Tapatalk

Zviki
Posts: 25
Joined: Sat May 28, 2016 7:39 pm

Post by Zviki »

Or here Raspberry Pi • View topic - Using an I2C expander to connect multiple distance sensors?
https://www.raspberrypi.org/forums/view ... 2&p=934447

Sent from my SM-N910C using Tapatalk

Post Reply