# NewPing library porting for DYP-ME007Y Ultrasonic Sensor

**URL:** <https://community.particle.io/t/newping-library-porting-for-dyp-me007y-ultrasonic-sensor/28002>\
**Category:** Libraries\
**Created:** [December 16, 2016, 2:56pm UTC](https://community.particle.io/t/newping-library-porting-for-dyp-me007y-ultrasonic-sensor/28002 "2016-12-16T14:56:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamg](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@adamg](https://community.particle.io/u/adamg)\
**Post date:** [December 16, 2016, 2:56pm UTC](https://community.particle.io/t/newping-library-porting-for-dyp-me007y-ultrasonic-sensor/28002/1 "2016-12-16T14:56:49Z")

</div>

Hello,

I was wondering if anyone has had success with porting NewPing library on a Particle device? I am looking to interface to a DYP-ME007Y Ultrasonic Sensor.

I have had good success using the NewPing library with the DYP-ME007Y with the Arduino family of boards. I am familiar with the HC-SR04 library for Particle devices, however I would like to use DYP-ME007Y sensor because the ultrasonic transmitter/receiver element is waterproof and can mounted away from the board.

Below is a link for the NewPing libiray developed by Tim Eckel.  
[http://playground.arduino.cc/Code/NewPing](http://playground.arduino.cc/Code/NewPing)

Thanks for the help!

Adam

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 16, 2016, 3:24pm UTC](https://community.particle.io/t/newping-library-porting-for-dyp-me007y-ultrasonic-sensor/28002/2 "2016-12-16T15:24:39Z")

</div>

What exact feature do you want to see ported?  
This lib does have several conditional compile instructions that would allow to build for Particle already (with minor `include` updates).

On first glance that’s the biggest change I could see required in `NewPing.h`

```cpp
#if defined (PARTICLE)
	#include "Particle.h"
#elif defined (ARDUINO) && ARDUINO >= 100
	#include <Arduino.h>
#else
	#include <WProgram.h>
	#include <pins_arduino.h>
#endif

```

and where you find `#if defined ( __arm__ ) && defined (TEENSYDUINO)` you could go with `#if defined ( __arm__ ) && (defined (TEENSYDUINO) || defined (PARTICLE))`

---

<div class="post-metadata">

**Author:** ![adamg](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@adamg](https://community.particle.io/u/adamg)\
**Post date:** [December 16, 2016, 3:37pm UTC](https://community.particle.io/t/newping-library-porting-for-dyp-me007y-ultrasonic-sensor/28002/3 "2016-12-16T15:37:08Z")

</div>

Thank you for the uber fast response!

I am basically just looking to port the library to so it works with the DYP-ME007Y sensor. I will implement the changes you suggested above this evening and report back my results.

Thanks again.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 16, 2016, 3:39pm UTC](https://community.particle.io/t/newping-library-porting-for-dyp-me007y-ultrasonic-sensor/28002/4 "2016-12-16T15:39:46Z")

</div>

I’ve also seen this bit here

```cpp
#if (defined ( __arm__ ) && (defined (TEENSYDUINO) || defined (PARTICLE)))
	#undef PING_OVERHEAD
	#define PING_OVERHEAD 1
	#undef PING_TIMER_OVERHEAD
	#define PING_TIMER_OVERHEAD 1
  #if defined (PARTICLE) // add this
	#define DO_BITWISE false
  #else
	#define DO_BITWISE true
  #endif
#elif !defined ( __AVR__ )
	#undef PING_OVERHEAD
	#define PING_OVERHEAD 1
	#undef PING_TIMER_OVERHEAD
	#define PING_TIMER_OVERHEAD 1
	#undef TIMER_ENABLED
	#define TIMER_ENABLED false
	#define DO_BITWISE false
#else
	#define DO_BITWISE true
#endif

```

---

<div class="post-metadata">

**Author:** ![adamg](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@adamg](https://community.particle.io/u/adamg)\
**Post date:** [December 17, 2016, 2:01am UTC](https://community.particle.io/t/newping-library-porting-for-dyp-me007y-ultrasonic-sensor/28002/5 "2016-12-17T02:01:30Z")

</div>

OK,

So I implemented the changes your outlined and the NewPing library with the DYP-ME007Y sensor works great. I will continue to tinker with it to check the performance and try the multiple sensor performance.

Thanks again for the help
