pulseIn Not Currently Supported in the Core

Was just testing a ping sensor (US-100) and it is failing because of pulseIn not defined. Any idea when pulseIn will be supported in the ArduinoCore.

I see that there is an open pr in the core: zephyrCommon: Implement pulseIn · arduino/ArduinoCore-zephyr@3674743.

EDIT: Tested the US-100 with the NewPing library and that seems to work well instead of using Pulse In

3 Likes

May I ask how to import NewPing to AppLab?

That gets complicated since it does not look like NewPing is available via the App donwloader. I tested it through the IDE.

Try one of the methods here: How to Manually Install a Custom Library - Development Tools / App Lab - Arduino Forum

or here

Arduino App Lab Libraries Upload - Development Tools / App Lab - Arduino Forum

1 Like

Thank you! I used first approach and copied lib sources to subfolder inside sketch, all good - my robot can avoid obstacles now

#include <Servo.h>
#include <NewPing.h>

Servo right_servo;
Servo left_servo;

const int trigPin = 3;
const int echoPin = 4;
const int left_wheel = 6;
const int right_wheel = 10;

NewPing sonar(trigPin, echoPin, 1000);

int speed = 20;  //0..90

float duration, distance = 100;

void setup() {
  pinMode(right_wheel, OUTPUT);
  pinMode(left_wheel, OUTPUT);
  right_servo.attach(right_wheel);
  left_servo.attach(left_wheel);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  distance = sonar.ping_cm();

  if (distance > 25) {
    right_servo.write(90 - speed);
    left_servo.write(90 + speed);
  } else {
    right_servo.write(90 + speed);
    left_servo.write(90 - speed);
    delay(2000);
    right_servo.write(90 - speed);
    left_servo.write(90 - speed);
    delay(1000);
  }

  delay(200);
}

Also, I managed to run simultaneously webcam WebUI from object detection - it is funny to see with robot eyes :slight_smile:

2 Likes