tino / pyFirmata

Python interface for the Firmata (http://firmata.org/) protocol. It is compliant with Firmata 2.1. Any help with updating to 2.2 is welcome. The Capability Query is implemented, but the Pin State Query feature not yet.
MIT License
575 stars 193 forks source link

Save data with analog read #119

Closed ClementMISP2021 closed 2 years ago

ClementMISP2021 commented 2 years ago

I am using a potentiometer to get a value between 0 and 1. I am able to print it in the console but the type of the data is 'NoneType'. Would it be possible to change this data type to a 'float' so that I can save it in a variable? Here is my code for now:

from pyfirmata import Arduino
import pyfirmata
import time
port = "COM3"
board = Arduino(port)
List = []
pin = board.get_pin('a:0:i')
it = pyfirmata.util.Iterator(board)
it.start()
print("Start reading")
for i in range(3):
    analog_value = pin.read()
    print(analog_value)
    List.append(analog_value)
    time.sleep(0.1)
    del List[0]
print(List)