Implementing SRF05

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

Implementing SRF05

Post by snow-man-01 »

Hello,

I want to implement the ultrasonic SRF05 in the Software Multiwii 2.4.

Can anyone tell me how I can do it? I have the code for the SRF05:

// Community of Robots//

//SRF05 sample code//

int duration; //Stores duration of pulse in
int distance; // Stores distance
int sensorpin = 7; // Pin for SRF05

void setup()
{
Serial.begin(9600);
}

void loop()
{
pinMode(sensorpin, OUTPUT);
digitalWrite(sensorpin, LOW); // Make sure pin is low before sending a short high to trigger ranging
delayMicroseconds(2);
digitalWrite(sensorpin, HIGH); // Send a short 10 microsecond high burst on pin to start ranging
delayMicroseconds(10);
digitalWrite(sensorpin, LOW); // Send pin low again before waiting for pulse back in
pinMode(sensorpin, INPUT);
duration = pulseIn(sensorpin, HIGH); // Reads echo pulse in from SRF05 in micro seconds
distance = duration/58; // Dividing this by 58 gives us a distance in cm
Serial.println(distance); // Wait before looping to do it again
delay(100);
}

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

Re: Implementing SRF05

Post by gregd72002 »

you cannot use pulseIn as this might introduce unexpected delay and the whole timing in MultiWii will be out of sync.

A potential way around it would be to read by undersampling - read it in a loop and apply LPF. But there might be other ways to do it too.

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

Post by Zviki »

Maybe this can help... MultiWii • View topic - Attemp to integrate sonar (ultrasonic sensor)
viewtopic.php?f=7&t=1033&start=200

Sent from my SM-N910C using Tapatalk

Post Reply