HC Sr04 with arduino due error

I am using New ping library 1.6 beta. whenever i verify my code for arduino due, it gives following errors, whereas with arduino mega, it is fine. please help me out.

my code

// ---------------------------------------------------------------------------
// Example NewPing library sketch that does a ping about 20 times per second.
// ---------------------------------------------------------------------------

#include <NewPing.h>

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");
}

My errors with arduino due

C:\Users\DeAdLy_pHaNt0mS\Documents\Arduino\libraries\NewPing\NewPing.cpp: In constructor 'NewPing::NewPing(uint8_t, uint8_t, unsigned int)':
C:\Users\DeAdLy_pHaNt0mS\Documents\Arduino\libraries\NewPing\NewPing.cpp:21:17: error: cannot convert 'RwReg* {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\DeAdLy_pHaNt0mS\Documents\Arduino\libraries\NewPing\NewPing.cpp:22:13: error: cannot convert 'RoReg* {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.
             ^
C:\Users\DeAdLy_pHaNt0mS\Documents\Arduino\libraries\NewPing\NewPing.cpp:24:75: error: 'portModeRegister' was not declared in this scope
  _triggerMode = (uint8_t *) portModeRegister(digitalPinToPort(trigger_pin)); // Get the port mode register for the trigger pin.
                                                                           ^
Error compiling.

why no reply :frowning:

I have the same problem, I am waiting for the developer's answer, he may have the solution:

umer427:
I am using New ping library 1.6 beta. whenever i verify my code for arduino due, it gives following errors, whereas with arduino mega, it is fine. please help me out.

There may be a problem in the library NewPing.h, to be able to consider it. I successfully tested the ultrasonic sensors on Arduino due, without using NewPing.h library. there’s the only thing to note is due Arduino digital port has an input voltage of fewer than 3.3 volts, while the output port echo is 5 volts, then the solution is to connect to a voltage divider circuit, you can see details circuit, for ultrasonic sensor and Arduino due.