Controling DAC as OUTPUT pin using pyfirmata

Hi,

I am trying to use pyfirmata to output a target DC voltage from the Arduino Due. I was advised to use the DAC pins for a true DC voltage output, but I get an error saying that the DAC pins are set to only be inputs. I read elsewhere that others could get their Arduinos to output on the DAC pins, but nothing specifically doing this with pyfirmata. ChatGPT gave a suggestion that seemed like a rabbit hole it got lost in. Is there anything straightforward that I can do straight with pyfirmata?

Here's the gist of my code:

import pyfirmata

# Connect to the Arduino 
board = pyfirmata.Arduino('COM7')

# Define the pin for the PWM 
dac_pin = board.get_pin('a:0:o') # analog pin 0, output

# maximum voltage
max_volt = 3.3

# Set the target voltage
target_volt = 3.3

# Set the on voltage with conversion formula
on_volt = target_volt / max_volt

# Start the loop
while True:
    dac_pin.write(on_volt)

Any help is much appreciated.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.