Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with the method ping() #109

Closed
arielkantorovich opened this issue Aug 11, 2021 · 0 comments
Closed

Problem with the method ping() #109

arielkantorovich opened this issue Aug 11, 2021 · 0 comments

Comments

@arielkantorovich
Copy link

Hi,
I want to read PWM Signal, My hardware is Arduino Mega and I use PyFirmata Library because my code run in python.
When I use pin8.ping() i except error.
The ping() Method really work?
I would happy to any help thanks.

My code:
from pyfirmata import ArduinoMega, util
import threading
import time

def trans_pwm(pin):
while True:
x = int(input("Please enter angle for Servo: "))
angle = int(100 / 90 * x + 45)
pin.write(angle)

def receiv_pwm(pin):
while True:
print("Pulse Time= ", pin.ping(), " [Sec]")
time.sleep(0.0002)

try:
# Initialize Hardware Configuration
board = ArduinoMega('COM8')
it = util.Iterator(board)
it.start()

# set up pin D2 as Servo Output
pin2 = board.get_pin('d:2:s')
# set up pin D8 as PWM Input
pin8 = board.get_pin('d:8:o')
pin8.ping()

# Use Threading to Transmit and receive in the same time
t1 = threading.Thread(target=trans_pwm, args=(pin2,))
t2 = threading.Thread(target=receiv_pwm, args=(pin8,))
t1.start()
t2.start()
t1.join()
t2.join()

except:
print("error")

finally:
board.exit()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant