Sonar HC-SR04 Support MultiWii Pro FC and etc.

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
nikes
Posts: 1
Joined: Sat Apr 25, 2015 9:28 pm

Sonar HC-SR04 Support MultiWii Pro FC and etc.

Post by nikes »

I read this topic and i edit my programm, and.... its don't work, i take my adruino mega and start debuging it.... 7 hours and yes its work.
I integrated it in my MW 2.3 Gui version and connected to MultiWii Pro FC, yesss its work.
I copy code from this topic, but i edit main function.

Sensors.cpp
look for this line

Code: Select all

// ************************************************************************************************************
// I2C Sonar SRF08
// ************************************************************************************************************
// first contribution from guru_florida (02-25-2012)
//
#if defined(SRF02) || defined(SRF08) || defined(SRF10) || defined(SRC235)
   .
   .
   .
   .
   .
#else
   void Sonar_init() {}
   void Sonar_update() {}
#endif


and in the

Code: Select all

#else
   inline void Sonar_init() {}
   void Sonar_update() {}
#endif


change the two line inside the #else and #endif to this

Code: Select all

#if defined(SONAR_GENERIC_ECHOPULSE)
// ************************************************************************************************************
// Generic Sonar Support
// ************************************************************************************************************
void Sonar_init()
{
  pinMode(SONAR_GENERIC_TRIGGER_PIN, OUTPUT);
  pinMode (SONAR_GENERIC_ECHO_PIN, INPUT);
}

void Sonar_update()
{
  long temp;
  digitalWrite(SONAR_GENERIC_TRIGGER_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(SONAR_GENERIC_TRIGGER_PIN, HIGH);
  delayMicroseconds(5);
  digitalWrite(SONAR_GENERIC_TRIGGER_PIN, LOW);
  temp = pulseIn(SONAR_GENERIC_ECHO_PIN, HIGH) / SONAR_GENERIC_SCALE;
  sonarAlt = (temp >= 0 && temp <= SONAR_GENERIC_MAX_RANGE) ? temp : 0;
}
#else
inline void Sonar_init() {}
void Sonar_update() {}
#endif



Yes, in Sensors.cpp its main metod.
And it work.

MultiWii Pro FC + HC-SR04
https://dl-web.dropbox.com/get/sonar/20150425_235502.jpg?_subject_uid=67557891&w=AABwwmhRSyyET_KurrNsJEFaVPs9lLX6pl2wshthqvjIhA
https://dl-web.dropbox.com/get/sonar/20150425_235356.jpg?_subject_uid=67557891&w=AADsv4IpKITB2Bo2xOt6at1Osqc-cnx2fEAp5cFtq5Wk0g
https://dl-web.dropbox.com/get/sonar/20150425_235429.jpg?_subject_uid=67557891&w=AAAtSuTfsX7uPdx7PEp2c_I5oWgIcVN0AcubWsNCYyIy2g

P.S. sorry for my english

FengShuiDrone
Posts: 234
Joined: Wed Dec 24, 2014 1:20 am
Location: ......

Re: Sonar HC-SR04 Support MultiWii Pro FC and etc.

Post by FengShuiDrone »

Pretty nice. Finally got the sonar light to come on everywhere it should when I flip the switch for it. Thanks Nikes.

ItsOnlyMe
Posts: 18
Joined: Sat Apr 18, 2015 4:25 pm

Re: Sonar HC-SR04 Support MultiWii Pro FC and etc.

Post by ItsOnlyMe »

Please can you zip and attach your whole Sensors.cpp here?
I don't get it which changes you made here :|

QuadX
Posts: 1
Joined: Thu May 07, 2015 12:54 am

Re: Sonar HC-SR04 Support MultiWii Pro FC and etc.

Post by QuadX »

First of all you need to apply the changes from this topic, except the changes in Sensors.cpp.

After that you open Sensors.cpp and replace:

Code: Select all

inline void Sonar_init() {}
void Sonar_update() {}

with:

Code: Select all

#if defined(SONAR_GENERIC_ECHOPULSE)
// ************************************************************************************************************
// Generic Sonar Support
// ************************************************************************************************************
void Sonar_init()
{
  pinMode(SONAR_GENERIC_TRIGGER_PIN, OUTPUT);
  pinMode (SONAR_GENERIC_ECHO_PIN, INPUT);
}

void Sonar_update()
{
  long temp;
  digitalWrite(SONAR_GENERIC_TRIGGER_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(SONAR_GENERIC_TRIGGER_PIN, HIGH);
  delayMicroseconds(5);
  digitalWrite(SONAR_GENERIC_TRIGGER_PIN, LOW);
  temp = pulseIn(SONAR_GENERIC_ECHO_PIN, HIGH) / SONAR_GENERIC_SCALE;
  sonarAlt = (temp >= 0 && temp <= SONAR_GENERIC_MAX_RANGE) ? temp : 0;
}
#else
inline void Sonar_init() {}
void Sonar_update() {}
#endif


That's it.
If you can't find the first two lines hit ctrl+f(search) and search for:inline void Sonar_init() {}

ItsOnlyMe
Posts: 18
Joined: Sat Apr 18, 2015 4:25 pm

Re: Sonar HC-SR04 Support MultiWii Pro FC and etc.

Post by ItsOnlyMe »

Thank you :!:
will give it a try and report back in the next couple of days

Post Reply