OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why is the ping() function not working on a Pin object?

  • Thread starter Thread starter billyBob456
  • Start date Start date
B

billyBob456

Guest
I am attempting to build a simple program with Arduino, Pyfirmata and an ultrasound sensor where it prints how far away an object is from the sensor. Below is a diagram of my wiring: Wiring chart

My code:

Code:
import pyfirmata
import time

board = pyfirmata.Arduino("COM5")

echoPin = board.get_pin("d:12:o")
trigPin = board.get_pin("d:13:o")

while True:
    trigPin.write(1)
    time.sleep(0.2)
    trigPin.write(1)
    time.sleep(0.5)
    trigPin.write(0.6)
    duration = echoPin.ping()
    distance = (duration * .0343) / 2
    print(distance)

In line 15, duration = echoPin.ping(), I get an error telling me that the "Pin" object has no attribute "ping". However, I am following the official docs and thats what it is telling me to do (doc 1, doc 2)

What I'm expecting is a continuous output into the console of the distance at which the ultrasound sensor is detecting the object. Please let me know how to solve this and all else I am doing wrong as I am new to Arduino and Pyfirmata.
<p>I am attempting to build a simple program with Arduino, Pyfirmata and an ultrasound sensor where it prints how far away an object is from the sensor. Below is a diagram of my wiring:
<a href="https://i.sstatic.net/xF10SZci.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xF10SZci.png" alt="Wiring chart" /></a></p>
<p>My code:</p>
<pre class="lang-py prettyprint-override"><code>import pyfirmata
import time

board = pyfirmata.Arduino("COM5")

echoPin = board.get_pin("d:12:o")
trigPin = board.get_pin("d:13:o")

while True:
trigPin.write(1)
time.sleep(0.2)
trigPin.write(1)
time.sleep(0.5)
trigPin.write(0.6)
duration = echoPin.ping()
distance = (duration * .0343) / 2
print(distance)

</code></pre>
<p>In line 15, <code>duration = echoPin.ping()</code>, I get an error telling me that the "Pin" object has no attribute "ping". However, I am following the official docs and thats what it is telling me to do (<a href="https://github.com/tino/pyFirmata/pull/45/files" rel="nofollow noreferrer">doc 1</a>, <a href="https://ardupython.readthedocs.io/en/latest/index.html#ping-support-pulsein" rel="nofollow noreferrer">doc 2</a>)</p>
<p>What I'm expecting is a continuous output into the console of the distance at which the ultrasound sensor is detecting the object. Please let me know how to solve this and all else I am doing wrong as I am new to Arduino and Pyfirmata.</p>
 

Latest posts

ن
Replies
0
Views
1
نعمان منذر محمود الجميلي
ن
Top