muhteeus
Posts: 2
Joined: Wed Nov 19, 2014 9:29 pm

Tkinter/Wiring Pi PWM

Mon Jul 20, 2015 3:27 pm

I have written a python script to control a 12VDC fan through wiringpi and hardware PWM. The PWM uses a MOSFET buffer. There is a slider that adjusts the fan speed between 0-1023 for a range of 1024.

The script works flawlessly, but when I am above roughly 40% of full speed, the fans will speed up (audibly) to 90ish%. If I move the slider down, the fans stay at the same speed. However if I adjust to full, speed and then back down... the fans will slow. If I stay under 40% speed.... this does not happen. Also, moving the slider slowly between 0-1023 produces good results and accurate control.

Am I missing anything obvious? How can I find out what is changing my value?

Code: Select all

from Tkinter import *       
import wiringpi2 as wiringpi
import opc, time

# Set up wiringpi
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(18,2)
wiringpi.pwmSetClock(6)
wiringpi.pwmSetRange(1024)

    def __init__(self, master):
        frame = Frame(master)
        frame.pack()
        Label(frame, text='Fan').grid(row=0, column=1)
        scaleFan = Scale(frame, from_=307, to=1023,
              orient=HORIZONTAL, command=self.updateFan,
              length=400, width=50)
        scaleFan.grid(row=1, column=1)

    def updateFan(self, duty):
        wiringpi.pwmWrite(18, int(duty))

root = Tk()
root.wm_title('Drank Fan Control')
app = App(root)
root.geometry("800x480+0+0")
root.mainloop()



User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Tkinter/Wiring Pi PWM

Tue Jul 21, 2015 12:22 pm

I'd start by printing the value of duty in the updateFan function, then at least you'll know if you're getting the correct info from the slider.

Dave.
Apple say... Monkey do !!

muhteeus
Posts: 2
Joined: Wed Nov 19, 2014 9:29 pm

Re: Tkinter/Wiring Pi PWM

Tue Jul 21, 2015 1:22 pm

Let me try that.

Return to “Python”