NewPing library wont compile with Teensy 4.0?

zumdar

Member
Does anyone have any success stories of using the NewPing library for multiple sensors on a Teensy 4.0 ?

I was really excited when I found the NewPing library, because I am trying to read many ultrasonic sensors at once! Ive tried in the past to do this and gave up so this library seemed like it might be a some magic for me, buttt i seem to have a problem compiling the example sketch that uses multiple sensors.

So I load up the 'NewPing15SensorsTimer' example sketch that is included in the NewPing library found here: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home

and get an error like this
Code:
C:\Users\moogtron 4k\Documents\Arduino\libraries\NewPing\src\NewPing.cpp: In constructor 'NewPing::NewPing(uint8_t, uint8_t, unsigned int)':
C:\Users\moogtron 4k\Documents\Arduino\libraries\NewPing\src\NewPing.cpp:19:17: error: cannot convert 'volatile uint32_t* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
  _triggerOutput = portOutputRegister(digitalPinToPort(trigger_pin)); // Get the output port register for the trigger pin.
                 ^
C:\Users\moogtron 4k\Documents\Arduino\libraries\NewPing\src\NewPing.cpp:20:13: error: cannot convert 'volatile uint32_t* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
  _echoInput = portInputRegister(digitalPinToPort(echo_pin));         // Get the input port register for the echo pin.
             ^
Using library NewPing at version 1.9.1 in folder: C:\Users\moogtron 4k\Documents\Arduino\libraries\NewPing 
Error compiling for board Teensy 4.0.

well i did some searching and it seems like others have had this problem, and it is reported to be solved with this updated library for Teensy 4.0
https://github.com/mjs513/NewPing_t4

but when I try this library i get this error where it can't find the check_timer , timer_stop , and ping_timer functions. :

Code:
C:\Users\moogtron 4k\Documents\Arduino\libraries\NewPing_t4-master\examples\NewPing15SensorsTimer/NewPing15SensorsTimer.pde:65: undefined reference to `NewPing::check_timer()'
C:\Users\MOOGTR~1\AppData\Local\Temp\arduino_build_837948\sketch\NewPing15SensorsTimer.pde.cpp.o: In function `loop':
C:\Users\moogtron 4k\Documents\Arduino\libraries\NewPing_t4-master\examples\NewPing15SensorsTimer/NewPing15SensorsTimer.pde:55: undefined reference to `NewPing::timer_stop()'
C:\Users\moogtron 4k\Documents\Arduino\libraries\NewPing_t4-master\examples\NewPing15SensorsTimer/NewPing15SensorsTimer.pde:58: undefined reference to `NewPing::ping_timer(void (*)(), unsigned int)'
collect2.exe: error: ld returned 1 exit status
Using library NewPing_t4-master at version 1.9.0 in folder: C:\Users\moogtron 4k\Documents\Arduino\libraries\NewPing_t4-master 
Error compiling for board Teensy 4.0.

I've tried messing around in the .h file, but I really dont know C++ that well sooo needless to say I can't make it work. Does anyone have any suggestions? Am I missing something?

Thank you!
 
Does anyone have any success stories of using the NewPing library for multiple sensors on a Teensy 4.0 ?

I was really excited when I found the NewPing library, because I am trying to read many ultrasonic sensors at once! Ive tried in the past to do this and gave up so this library seemed like it might be a some magic for me, buttt i seem to have a problem compiling the example sketch that uses multiple sensors.

So I load up the 'NewPing15SensorsTimer' example sketch that is included in the NewPing library found here: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home

and get an error like this
......
I've tried messing around in the .h file, but I really dont know C++ that well sooo needless to say I can't make it work. Does anyone have any suggestions? Am I missing something?

Thank you!

@zumdar
Just took a look at the library again after 2 years. Found a couple of errors/typos that were preventing enabling the timer code from ever executing. I created a new branch of the newping_t4 library: https://github.com/mjs513/NewPing_t4/tree/TimerCorrection_WIP that fixes that but I haven't tested the changes as of yet so will stay a WIP. In the meantime you can give it a try if you want to play some before I get to testing. :)

EDIT: Just hooked up a US-100 Ping sensor (this is a 3.3v Ping sensor: https://protosupplies.com/product/us-100-ultrasonic-range-finder-module/) and it looks to be working on a T4.1. So give it a try and let me know.

UPDATE: Just tested on T3.2 and T3.6. Had to make 1 more change and now verified to work on T3.x and T4.x. Will wait to see if you get it works with your setup.
 
Last edited:
@zumdar
Just took a look at the library again after 2 years. Found a couple of errors/typos that were preventing enabling the timer code from ever executing. I created a new branch of the newping_t4 library: https://github.com/mjs513/NewPing_t4/tree/TimerCorrection_WIP that fixes that but I haven't tested the changes as of yet so will stay a WIP. In the meantime you can give it a try if you want to play some before I get to testing. :)

EDIT: Just hooked up a US-100 Ping sensor (this is a 3.3v Ping sensor: https://protosupplies.com/product/us-100-ultrasonic-range-finder-module/) and it looks to be working on a T4.1. So give it a try and let me know.

UPDATE: Just tested on T3.2 and T3.6. Had to make 1 more change and now verified to work on T3.x and T4.x. Will wait to see if you get it works with your setup.

whatt! amazing! thank you so much! so i've compiled it and it works and hopefully later today I will be able to test it with my six SR04 sensors. i was very convinced it was something about my setup or that caused the error, so thank you immensely for looking into it.
Ill keep you posted.
 
Ok.. so it doesnt seem to work unfortunately.

Maybe something about the pins that I want to use it with? I tested all my sensors one by one using the "NewPingExample" file.
Only the sensor connected to pins 11 and 12 worked.

I verified that all the other sensors worked by using this sketch:
Code:
// ---------------------------------------------------------------- //
// Arduino Ultrasoninc Sensor HC-SR04
// Re-writed by Arbi Abdul Jabbaar
// Using Arduino IDE 1.8.7
// Using HC-SR04 Module
// Tested on 17 September 2019
// ---------------------------------------------------------------- //

#define echoPin 21 // attach pin D2 Arduino to pin Echo of HC-SR04
#define trigPin 20 //attach pin D3 Arduino to pin Trig of HC-SR04

// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
  Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
  Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor
  Serial.println("with Arduino UNO R3");
}
void loop() {
  // Clears the trigPin condition
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
  // Displays the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
}

Using that, i verified that my ultrasonics on pins 3 and 4, 5 and 6, 7 and 9, 9 and 10, 21 and 20 all worked.

But when using those same pins in the NewPingExample, I dont get any readings . Just 0.. this isnt even using the multiple sensors yet. The only time i get readings is when i use pins 11 and 12 for echo and trig.

sooo weird!!
any thoughts about this?
 
Ok.. so it doesnt seem to work unfortunately.

Maybe something about the pins that I want to use it with? I tested all my sensors one by one using the "NewPingExample" file.
Only the sensor connected to pins 11 and 12 worked.

I verified that all the other sensors worked by using this sketch:
...

Using that, i verified that my ultrasonics on pins 3 and 4, 5 and 6, 7 and 9, 9 and 10, 21 and 20 all worked.

But when using those same pins in the NewPingExample, I dont get any readings . Just 0.. this isnt even using the multiple sensors yet. The only time i get readings is when i use pins 11 and 12 for echo and trig.

sooo weird!!
any thoughts about this?

Ok know what the problem is but going to take a bit for me to rework it :)
 
When I click on the link I get Error 404 this is not the page you are looking for. Can you send a new link with the current?
 
Back
Top