The assignment this week is to write or modify an application that interfaces with an input and.or an output device.
Measuring the Wind
In an effort to complete a section of my final project, I've chosen to work on my anemometer. Although I'm not convinced that my proposed solution is the best, it is one of my options.
In intial testing of my mechanism I discovered that the rotational force provided by the wind is exponetially effected by the turning mass. This means that I need to cut down on any contacts, or phyical generators to provide a reading. I am going to try to use my hello.reflect board to generate a usable signal. A very light cardstock piece will be attached to the shaft. It will be placed so that it interfers with the IR LED. When the shaft spins faster, a higher signal will be produced.
All I need to do is modify the existing reflect.py program in the archive to restricted it to my single desired signal.
I downloaded the program and found that it was most easily edited in wordpad. I would normally work in notepad, put it does not display the format correctly. This makes it much harder to work on.
The program was stripped down of unneeded GUI components. As this is interface is designed to be used out on a field at possibly a large distance, I enlarged the GUI box. Additionally, I enlarged the font and chose colors with higher contrasts.
Further work that needs to be performed is the calibration. I need to borrow a commercial anemometer to compare and give a multipler to the proper variable.
Additionally, I am going to further enlarge the GUI to almost full screen. This will allow for easier reading.
# # wind.py # # receive and display rotational wind speed # # # # (c) Dan Bihary - 2015 This work may be reproduced, modified, distributed, # performed, and displayed for any purpose, but must acknowledge "FabPad". # Copyright is retained and must be preserved. The work is provided as is; # no warranty is provided, and users accept all liability. # from Tkinter import * import serial WINDOW = 800 # window size eps = 0.9 # filter time constant filter = 0.0 # filtered value nloop = 100.0 # number of loops accumulated amp = 50.0 # difference amplitude def idle(parent,canvas): global filter, eps # # idle routine # byte2 = 0 byte3 = 0 byte4 = 0 ser.flush() while 1: # # find framing # byte1 = byte2 byte2 = byte3 byte3 = byte4 byte4 = ord(ser.read()) if ((byte1 == 1) & (byte2 == 2) & (byte3 == 3) & (byte4 == 4)): break on_low = ord(ser.read()) on_high = ord(ser.read()) on_value = (256*on_high + on_low)/nloop x = int(.25*WINDOW + (.9-.25)*WINDOW*on_value/1024.0) canvas.itemconfigure("text_on",text="on %.1f"%on_value) canvas.coords('rect1_on',.25*WINDOW,.05*WINDOW,x,.2*WINDOW) canvas.coords('rect2_on',x,.05*WINDOW,.9*WINDOW,.2*WINDOW) off_low = ord(ser.read()) off_high = ord(ser.read()) off_value = (256*off_high + off_low)/nloop x = int(.25*WINDOW + (.9-.25)*WINDOW*off_value/1024.0) canvas.itemconfigure("text_off",text="Wind Speed %.1f"%off_value) canvas.coords('rect1_off',.25*WINDOW,.25*WINDOW,x,.4*WINDOW) canvas.coords('rect2_off',x,.25*WINDOW,.9*WINDOW,.4*WINDOW) filter = (1-eps)*filter + eps*amp*(on_value-off_value) x = int(.25*WINDOW + (.9-.25)*WINDOW*filter/1024.0) canvas.itemconfigure("text_diff",text="diff %.1f"%filter) canvas.coords('rect1_diff',.25*WINDOW,.45*WINDOW,x,.6*WINDOW) canvas.coords('rect2_diff',x,.45*WINDOW,.9*WINDOW,.6*WINDOW) canvas.update() parent.after_idle(idle,parent,canvas) # # check command line arguments # if (len(sys.argv) != 2): print "command line: hello.light.45.py serial_port" sys.exit() port = sys.argv[1] # # open serial port # ser = serial.Serial(port,9600) ser.setDTR() # # set up GUI # root = Tk() root.title('wind.py (q to exit)') root.bind('q','exit') canvas = Canvas(root, width=WINDOW, height=.65*WINDOW, background='black') canvas.create_text(.5*WINDOW,.125*WINDOW,text=".33",font=("Helvetica", 72) ,tags= "text_off",fill="white") canvas.create_rectangle(.25*WINDOW,.25*WINDOW,.3*WINDOW,.4*WINDOW, tags='rect1_off', fill='white') canvas.create_rectangle(.3*WINDOW,.25*WINDOW,.9*WINDOW,.4*WINDOW, tags='rect2_off', fill='red') # # # start idle loop # root.after(100,idle,root,canvas) root.mainloop()