Don't worry I can work around it, it was just if you knew a way to do it in its current state. The REPL over USB is far more useful! Thankyou for showing me what pins I can use, it really helped me to work through the code. Here is the class I wrote to control the pins. ( first time I wrote one so might be a bit clunky! ) map is borrowed from Arduino map function!Damien wrote:I can change the timer code so it allows you to control timer 3. If you don't need usb then it's not a problem changing the frequency of this timer. If you don't want to wait for a code change you can access the timer registers using the stm module.clack wrote: I can call the same frequency on all pins except the blue LED as it is fixed?
Code: Select all
from time import sleep
import pyb
class ledpwm:
def __init__(self,pin,timer,channel,freq):
self.freq = freq
self.timer = timer
self.channel = channel
self.pin = pin
if pin == 'X5' or pin == 'X6':
self.pinpwm = pyb.Pin(pin)
elif pin == 'P18':
self.ch = pyb.LED(4)
else:
self.pinpwm = pyb.Pin(pin)
timerset = pyb.Timer(self.timer, freq=self.freq)
self.ch = timerset.channel(self.channel, pyb.Timer.PWM, pin=self.pinpwm)
def pwm(self,PWM):
if self.pin == 'X5' or self.pin == 'X6':
buf = bytearray(100)
dac = pyb.DAC(self.pin)
for i in range(len(buf)):
if i < PWM:
buf[i] = 255
else:
buf[i] = 0
dac.write_timed(buf,self.freq * len(buf), mode=pyb.DAC.CIRCULAR)
elif self.pin == 'P18':
PWM = self.map(PWM,0,255,0,256)
self.ch.intensity(PWM)
else:
if self.pin in ('Y6','Y11','Y12'):
PWM = int(self.map(PWM,0,100,100,0))
self.ch.pulse_width_percent(PWM)
def map(self,x, in_min, in_max, out_min, out_max):
return int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)
Thanks Dave and Damien, Sorry I was caught out by the double sided PCB I made, I had a disconnected through hole. It just seemed like it was not booting!Damien wrote:Do the pyboard leds light up in any way? Did you check voltage level on VIN and 3V3? Did you try pressing RST button?Clack wrote: When I unplug the USB ( and it is connected to 5v on Vin ) though it is does not boot?If it boots via usb then is should boot fine without usb.
edit:
ooh one more thing, in REPL soft reboot stops working, I cant work out what pin it is, but is there a pin that breaks soft reboot when it is re-assigned?