Difficulty using write_analog()

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
capybara
Posts: 1
Joined: Sat Apr 08, 2017 8:36 am

Difficulty using write_analog()

Post by capybara » Sat Apr 08, 2017 8:45 am

Hi,
I'm trying to use the PWM output of the microbit to control a fan. I have a simple transistor circuit to drive the fan, and the pin0 output is connected to the base of the transistor via a resistor. i have verified that the circuit works by using pin0.write_digital(1) - the fan duly turns.

However I wanted to use the PWM and using pwm to control the speed. Using pin0.write_analog(x) with x varying from 0 to 1023. With any settting of x I get no output measured on the pin. I am using a DVM so I reasoned that the PWM might be too fast for it to register, so I used set_analog_period(1000) reasoning that would set the on/off period to 1S so the DVM could track it. Still nothing.
HAS anyone successfully used the PWM on microbit micropython?

Many thanks in advance

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Difficulty using write_analog()

Post by deshipu » Sat Apr 08, 2017 10:27 pm

I'm using PWM on the microbit all the time to control hobby servos -- with the frequency set to 50Hz and duty between ~11 and ~70 it work fine. Are you doing anything else in that code?

Post Reply