How to add NewPing.h libary on Particle cloud ide?

I am trying to get hr sc04 ultrasonic working on the particle photon using the cloud ide. I didnt find the NewPing library in the community library. Is it possible to add that library???

http://playground.arduino.cc/Code/NewPing

Thanks

I have create a github repository to do the port over to Particle.

However, i don’t have an estimate of when it will be completed. The initial smoke test says that it’s not compiling (yet)

I haven’t published the library but it seems like NewPingExample works!

If you are familiar with Particle CLI, i can guide you on how to use it. :wink:

With the help of ScruffR I was able to get the NewPing library to work great.

See the thread below:

Let me know how it works out

1 Like

Thanks to @ScruffR for the port!

https://build.particle.io/libs/New_Ping

Enjoy everyone :slight_smile:

1 Like

@kennethlimcp @ScruffR

Wow glad New Ping is becoming a community library.

but am I missing something???

Can you change it to " " instead ?

i was able to start using the sample code and it build fine.

Only thing the sensor is giving only 0cm. Tried 2 different ones. yikes

Powered with 5v and tried with 3v3. Tried it using 4pin and 3pin wirings. Didnt use any resistors though. I read pins are 5v tolerent

I remember having issues with the ultrasonic if it is a 5V version.

Which two pins are you using for trig and echo?

Be careful as not all pins are 5V tolerant: https://docs.particle.io/datasheets/photon-datasheet/#peripherals-and-gpio

I would recommend using D0 and D1 which are I2C pins and known to be 5V tolerant pins.

It might well be that the NewPing lib doesn’t fully function since I mainly focused on getting it to build first before going into the how does it work.
The TEENSYDUINO specifics might not fully apply, but I haven’t gone there yet.

The solution proposed in the linked thread above should work, though a bit slower.

@kennethlimcp Nice switched it to D0,D1 and 5v power and sensor seems to be working. :slight_smile:

HR-SC04 is only work when the sound bounces of right back any other angles it will show 0 I believe.

I just ordered some of the newer time-of-flight modules from ST. hoping to try these new mini LIDARS with particle.

1 Like

Hey Guys,

I’m trying to add to add the NewPing library to a project with no success. I must be missing something, but I couldn’t figure out what. Here is what happens:
A) The library inclusion is successful, it shows in the project code:

   1 // This #include statement was automatically added by the Particle IDE.
   2 #include <New_Ping.h> 

B) Compilation results in the following “fatal error”:
testnewping.ino:2:22: New_Ping.h: No such file or directory
C) The RAW version is seen below the line herebelow

Your help would be greatly appreciated.

Processing  newping.ino
Checking library New_Ping...
Installing library New_Ping 1.8.0 to lib/New_Ping ...
Library New_Ping 1.8.0 installed.
Checking library SparkIntervalTimer...
Installing library SparkIntervalTimer 1.3.7 to lib/SparkIntervalTimer ...
Library SparkIntervalTimer 1.3.7 installed.
make -C ../modules/photon/user-part all
make[1]: Entering directory '/firmware/modules/photon/user-part'
make -C ../../../user 
make[2]: Entering directory '/firmware/user'
Building cpp file: src/newping.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-6-msrc/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=6 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD006 -DUSBD_PID_CDC=0xC006 -DSPARK_PLATFORM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=6 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=0.7.0 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../services/inc -I../communication/src -I../hal/inc -I../hal/shared -I../hal/src/photon -I../hal/src/stm32f2xx -I../hal/src/stm32 -I../hal/src/photon/api -I../hal/src/photon/include -I../hal/src/photon/wiced/security/BESL/host/WICED/ -I../hal/src/photon/wiced/security/BESL/include -I../hal/src/photon/wiced/security/BESL -I../hal/src/photon/wiced/security/BESL/crypto -I../hal/src/photon/wiced/WWD/include/ -I../hal/src/photon/wiced/platform/include/ -I../hal/src/photon/wiced/platform/GCC/ -I../hal/src/photon/wiced/security/BESL/supplicant/ -I../hal/src/photon/libraries/crypto -I../platform/shared/inc -I../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F2xx/CMSIS/Include -I../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../dynalib/inc -Isrc -I./libraries -Ilib/SparkIntervalTimer/src -Ilib/New_Ping/src -I. -MD -MP -MF ../build/target/user/platform-6-msrc/newping.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DBOOTLOADER_SDK_3_3_0_PARTICLE -DPARTICLE_DCT_COMPATIBILITY -DSPARK_PLATFORM_NET=BCM9WCDUSI09 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc  -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=5 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,207 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\""  -fno-exceptions -fno-rtti -fcheck-new -std=gnu++11 -c -o ../build/target/user/platform-6-msrc/newping.o src/newping.cpp
newping.ino:2:22: fatal error: New_Ping.h: No such file or directory
compilation terminated.
../build/module.mk:267: recipe for target '../build/target/user/platform-6-msrc/newping.o' failed
make[2]: Leaving directory '/firmware/user'
make[2]: *** [../build/target/user/platform-6-msrc/newping.o] Error 1
../../../build/recurse.mk:11: recipe for target 'user' failed
make[1]: Leaving directory '/firmware/modules/photon/user-part'
make[1]: *** [user] Error 2
../build/recurse.mk:11: recipe for target 'modules/photon/user-part' failed
make: *** [modules/photon/user-part] Error 2

Common first question for issues like that: "What system version are you targeting with your build?"
It needs to be 0.5.3 or later

@ScruffR Thanks for your quick response!
System firmware target:
On the device: 0.7.0

The “On the device” version is only half of the equation.
What does the dropdown list say just above that.
image

Capture

I see, but looking at the library examples, the problem becomes obvious.
While the library is called New_Ping the include actually needs to be #include <NewPing.h> (which is bad style on the contributors side, I dare say :wink: )

Hence it’s always good to give the samples a go before starting own applications - at least to check whether the library works at all or not.

1 Like

Thank you very much! I’d have never figured this out.
This might explain why this library has not been used more extensively.2PNG

1 Like

Any plans on having this library work with Argon?

lib/SparkIntervalTimer/SparkIntervalTimer.h:37:4: #error “*** PARTICLE device not supported by this library. PLATFORM should be Core or Photon ***”

@stewsterl, the SparkIntervalTimer library is STM32 hardware dependent and as such, only works on Gen2 devices. If you search, I believe @rickkas7 had an example of using a Nordic hardware timer but you would need to adapt the code to work with this library.

1 Like