Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
1,108 Views

Could you please help me to use HC-SR04 ultrasonic sensor in Intel Galileo 1G?

Jump to solution

In my class we have tried for many weeks to run this sensor with Python , but we couldn't. Someone could help me with some code to make it work in Python.

Tags (1)

Accepted Solutions
Highlighted
Employee
11 Views

Hello mafe,

I recommend you to check the following threads about ultrasonic sensors with Galileo. You will find useful information regarding how to properly wire the sensor in case it's a 3-pin sensor. You will also find tips shared by other users for 3-pin and 4-pin sensors:

The threads above discuss the use of the ultrasonic sensor from the Arduino side. Since you are using the sensor with Python, I recommend you to write a Python script based on the Arduino examples. The ultrasonic sensor uses the pulseIn() method, you could check how this method works and try to write a similar method in Python based on the Arduino version. Please check the following thread: . The user in that thread asked a similar question, she wanted to use the sensor in C++ so she ported the pulseIn() method from Arduino to hers own version to be used in C++. You might want to do a similar approach but using Python instead.

Additionally, there is an example code available for C++ here: https://github.com/intel-iot-devkit/upm/blob/master/examples/c%2B%2B/hcsr04.cxx upm/hcsr04.cxx at master · intel-iot-devkit/upm · GitHub. Unfortunately, there is not a Python version of it, but you could check the library used in that example and try to port it to Python.

I hope you find these suggestions useful.

Regards,

Diego.

View solution in original post

1 Reply
Highlighted
Employee
12 Views

Hello mafe,

I recommend you to check the following threads about ultrasonic sensors with Galileo. You will find useful information regarding how to properly wire the sensor in case it's a 3-pin sensor. You will also find tips shared by other users for 3-pin and 4-pin sensors:

The threads above discuss the use of the ultrasonic sensor from the Arduino side. Since you are using the sensor with Python, I recommend you to write a Python script based on the Arduino examples. The ultrasonic sensor uses the pulseIn() method, you could check how this method works and try to write a similar method in Python based on the Arduino version. Please check the following thread: . The user in that thread asked a similar question, she wanted to use the sensor in C++ so she ported the pulseIn() method from Arduino to hers own version to be used in C++. You might want to do a similar approach but using Python instead.

Additionally, there is an example code available for C++ here: https://github.com/intel-iot-devkit/upm/blob/master/examples/c%2B%2B/hcsr04.cxx upm/hcsr04.cxx at master · intel-iot-devkit/upm · GitHub. Unfortunately, there is not a Python version of it, but you could check the library used in that example and try to port it to Python.

I hope you find these suggestions useful.

Regards,

Diego.

View solution in original post