Generating PWM using Box0

Electrical Connection

PWM0 Electrical connection

Python Code

In [1]:
import box0
import time

# Get all the required resources
dev = box0.usb.open_supported()
pwm = dev.pwm()

pwm.output_prepare()

# Increment count every 1/1000 second, count upto 250 and toggle when reach at 150
# effectively giving a 4Hz with 50% duty cycle output on channel 0
# So, LED will blink 4 per second!
pwm.speed_set(1000)
pwm.period_set(250)
pwm.width_set(0, 125)

# Start generating!
pwm.output_start()

# Wait till we are not asked to exit
try:
    while True:
        time.sleep(0.1)
except KeyboardInterrupt:
    pass

# give back all the required resources
pwm.output_stop()
pwm.close()
dev.close()