Go Down

Topic: firmata analog write error (Read 678 times) previous topic - next topic

bw_ard

I loaded the Standard Firmata on Arduino and ran a Python3 program to test.

The Digital read & write work.
The Analog read works.
But the Analog write gives me an input configuration error ?

"OSError: Analog pin 5 is set up as an INPUT and can therefore not be written to"

analog_5  is defined in python as output ?

Here is the Python3 code:


import pyfirmata
from time import sleep

board = pyfirmata.Arduino('COM12')
it = pyfirmata.util.Iterator(board)
it.start()

sw = board.get_pin('d:2:i')
led = board.get_pin('d:11:o')
analog_0 = board.get_pin('a:0:i')
analog_5 = board.get_pin('a:5:o')

analog_0.enable_reporting()

while True:
    value = sw.read()
    print ("read value : ",value)   
    if value == 1:
        led.write(1)
    else:
        led.write(0)   
    A0 = analog_0.read()
    print ("read A0 : ",A0)
    print ("read volts : ",(5*A0))
    analog_5.write(A0)
   
    sleep(1)
board.exit()

PaulS

Does FIRMATA really allow you to set the state of analog pins? They are input only, so, even if you can set the state, setting an input only pin to output mode does not make sense.

Trying to read an output pin does not make sense.

Trying to write to an input-only pin does not make sense.

Please share whatever you were smoking when you wrote that code. We have a 3 day weekend coming up.
The art of getting good answers lies in asking good questions.

bw_ard

You are right.
Should have checked the hardware.
NO DAC on UNO !

Need to use the Arduino Due.

Go Up