This is the first time I text on this forum , so ... Hi :)

Well , I made a 5dof robotic arm controlled by arduino and I am adding some sensors. I can't find a working code for the Ultrasonic sensor hcsr-04 . I found a couples of examples ( very simple and short codes) but they did not work. Can somebody help me ?  I just need an example that shows how to print the distance of a generic obstacole and how to use the upper bar of the service .

This is one of the codes I tried to use (my sensor version has separate trigger and echo pins) :

python = Runtime.start("python","Python")
sr04 = Runtime.start("sr04", "UltrasonicSensor")
sr04.attach("COM3", 7, 8)
def onRange(distance):
  print distance


6 years 5 months ago

Ahoy Danilo !

Sorry it took so long to respond, we have been busy trying to get things fixed for the up-coming SFO.

I'm really excited about seeing your 5dof arm .. Post a picture !

I'll try to see what is borked with the Ultrasonic Sensors.

Welcome !



6 years 5 months ago

Hi and welcome.

I looked at the code for the UltrasonicSensor and how it's implemented in the Arduino. I think it once was working but the piece of code that does the measurement never gets called. In MRLComm there is a method getUltrasonicRange that I think should do the job, but I can't find that it's beeing used. So it needs some repair. 


I've tried with my ultrasonic sensors, and a get these errors :

SR04 error can not create peer from reservedkey SR04.controller - no type definition !
SR04 error could not create service from key controller