Skip to content

Instantly share code, notes, and snippets.

@ozkansen
Last active September 21, 2020 11:36
Show Gist options
  • Save ozkansen/6813c6b4af435f53a6f58fad8fc66669 to your computer and use it in GitHub Desktop.
Save ozkansen/6813c6b4af435f53a6f58fad8fc66669 to your computer and use it in GitHub Desktop.
Ardunio analog pin is not attached sensor read value problem
#!/usr/bin/env python3
# Using python package : https://pypi.org/project/pyFirmata/
from pyfirmata import Arduino, util
board = Arduino("/dev/ttyACM0")
it = util.Iterator(board)
it.start()
temp_sensor = board.get_pin("a:1:i")
def read_status_analog_pin(pin, counter: int = 10) -> float:
pin.enable_reporting()
read_list = []
for _ in range(counter):
read_list.append(pin.read())
board.pass_time(1)
pin.disable_reporting()
result = round(sum(read_list) / len(read_list), 4)
return result
if __name__ == "__main__":
print(read_status_analog_pin(temp_sensor))
# ! # Read list
# 0.1697
# 0.1697
# 0.234
# 0.234
# 0.2664
# 0.2664
# 0.2661
# 0.2661
# 0.2679
# 0.2679
# 0.2694
# 0.2694
# 0.2693
# 0.2693
# 0.2683
# 0.2683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment