Multiwii 2.4 with multiple hc-sr04 sonar module

Post Reply
ameliacv
Posts: 2
Joined: Mon Mar 21, 2016 6:52 am

Multiwii 2.4 with multiple hc-sr04 sonar module

Post by ameliacv »

Image

i’m using quadcopter with X frame, i’m using pin 2,3,5,6, for motor. so, there’re six pins for sensor ultrasonic , the pin configuration is as follows:
Image
Vcc of all sensors will go into +5V
GND of all sensors will go into GND
Trig Pin of first sensor into Pin # 8 (signal pin)
Echo Pin of first sensor into Pin # 7 (signal pin)
Trig Pin of second sensor into Pin # 9 (signal pin)
Echo pin of second sensor into Pin # 10 (signal pin)
Trig Pin of third sensor into Pin # 12 (signal pin)
Echo pin of third sensor into Pin # 11 (signal pin)
MAKE SURE SENSOR PIN INTO SIGNAL PIN

add new parameter in multiwii.cpp, put it before :

/*********** RC alias *****************/

const int trigPin1 = 8; //Trig Pin of first sensor
const int echoPin1 = 7; //Echo Pin of first sensor
const int trigPin2 = 9; //Trig Pin of second sensor
const int echoPin2 = 10; //Echo Pin of second sensor
const int trigPin3 = 12; //Trig Pin of third sensor
const int echoPin3 = 11; //Echo Pin of third sensor
long duration, distance, FrontSensor, RightSensor, LeftSensor ;


still in multiwii.cpp

look for method setup(), put it the end of the method, before ‘}’

pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);


look for method loop(), add this

SonarSensor(trigPin1, echoPin1); //method SonarSensor
FrontSensor= distance;
debug[0]= FrontSensor; //will display on the GUI multiwii
SonarSensor(trigPin2, echoPin2);
RightSensor = distance;
debug[1]= RightSensor ; //will display on the GUI multiwii
SonarSensor(trigPin3, echoPin3);
LeftSensor = distance;
debug[2]= LeftSensor; //will display on the GUI multiwii


before methode loop(), create new method SonarSensor()

void SonarSensor(int trigPin,int echoPin)
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
}


Then, click the upload button highlighted above Arduino will then Compile the sketch and report any problems if there are any and then start the upload process, you should see the rx tx leds flashing at side of the Usb port when this happens,if all goes well Arduino will report upload completed and you can then connect to the board using the multi wii gui.


Make sure the quadcopter battery is connected


Image


Website : http://amelia.my.id/2016/04/06/multiwii-2-4-with-multiple-hc-sr04-sonar-module/

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

Multiwii 2.4 with multiple hc-sr04 sonar module

Post by Zviki »

ameliacv wrote:Image

i’m using quadcopter with X frame, i’m using pin 2,3,5,6, for motor. so, there’re six pins for sensor ultrasonic , the pin configuration is as follows:
Image
Vcc of all sensors will go into +5V
GND of all sensors will go into GND
Trig Pin of first sensor into Pin # 8 (signal pin)
Echo Pin of first sensor into Pin # 7 (signal pin)
Trig Pin of second sensor into Pin # 9 (signal pin)
Echo pin of second sensor into Pin # 10 (signal pin)
Trig Pin of third sensor into Pin # 12 (signal pin)
Echo pin of third sensor into Pin # 11 (signal pin)
MAKE SURE SENSOR PIN INTO SIGNAL PIN

add new parameter in multiwii.cpp, put it before :

/*********** RC alias *****************/

const int trigPin1 = 8; //Trig Pin of first sensor
const int echoPin1 = 7; //Echo Pin of first sensor
const int trigPin2 = 9; //Trig Pin of second sensor
const int echoPin2 = 10; //Echo Pin of second sensor
const int trigPin3 = 12; //Trig Pin of third sensor
const int echoPin3 = 11; //Echo Pin of third sensor
long duration, distance, FrontSensor, RightSensor, LeftSensor ;


still in multiwii.cpp

look for method setup(), put it the end of the method, before ‘}’

pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);


look for method loop(), add this

SonarSensor(trigPin1, echoPin1); //method SonarSensor
FrontSensor= distance;
debug[0]= FrontSensor; //will display on the GUI multiwii
SonarSensor(trigPin2, echoPin2);
RightSensor = distance;
debug[1]= RightSensor ; //will display on the GUI multiwii
SonarSensor(trigPin3, echoPin3);
LeftSensor = distance;
debug[2]= LeftSensor; //will display on the GUI multiwii


before methode loop(), create new method SonarSensor()

void SonarSensor(int trigPin,int echoPin)
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
}


Then, click the upload button highlighted above Arduino will then Compile the sketch and report any problems if there are any and then start the upload process, you should see the rx tx leds flashing at side of the Usb port when this happens,if all goes well Arduino will report upload completed and you can then connect to the board using the multi wii gui.


Make sure the quadcopter battery is connected


Image


Website : http://amelia.my.id/2016/04/06/multiwii-2-4-with-multiple-hc-sr04-sonar-module/

Well, there's no pictures anymore. Can you upload the multiwii.cpp file please?
Also, in which directions you mounted sensors?

Sent from my SM-N910C using Tapatalk

Post Reply