def main(): wm=wimote.connect(Led) while True: button=wimote.whichbutton(wm) time.sleep(0.05) wm.rumble=False #Moving Forwards if button==3: distance_front = usonic.reading(Trigger_front,Echo_front) print distance_front if distance_front < Collision: wm.rumble=True #led.off(Led) motor.stop() elif distance_front >= Collision: #led.on(Led) motor.forward() #Reverse if button==4: motor.reverse() if button==7: motor.cleanup() led.cleanup() usonic.cleanup() sys.exit() if button==None: led.off(Led) motor.stop()
def usonicgraph(): xar = [] yar = [] for i in range(50): x = usonic.reading(0) xar.append(float(i)) yar.append(float(x)) draw(xar, yar) pylab.show()
def hello(): #Grab well tank level tankPercentFull = usonic.reading(0) #Access and read temperature id = '28-021502fbc0ff' mytemp = '' filename = 'w1_slave' f = open('/sys/bus/w1/devices/' + id + '/' + filename, 'r') line = f.readline() # read 1st line crc = line.rsplit(' ',1) crc = crc[1].replace('\n', '') if crc=='YES': line = f.readline() # read 2nd line mytemp = line.rsplit('t=',1) else: mytemp = 9999 f.close() #change temp into readable format (this is ugly, but it works) mytempstr = str(mytemp[-1]) mytempstr = mytempstr.strip() mytempformatint = int(mytempstr) / 1000 #Establish javascript to set the page to reload once a minute refresh_ms = 5000 refresh_code = '<body onload="setInterval(function() {window.location.reload();}, 100000);">' if tankPercentFull > 100: wellLevel = "Full" else: wellLevel = str(tankPercentFull)[:5] + '%' return refresh_code + "<h2>Bucket Temp: " + str(mytempformatint) + " C<br>Tank Level: " + wellLevel + "</h2>\n" + last_lines("/home/pi/wellsensor/hourlyTankRecord", 25)
def helloCallBack1(): import usonic data=usonic.reading(0) #import test01.py #data=test01.graph() tkMessageBox.showinfo( "ultrasoni",data)
import plotly.plotly as py from plotly.graph_objs import Scatter, Layout, Figure import time import usonic import datetime usonic.initialize() print usonic.reading(0) username = '******' api_key = 'd6k9457d4a' stream_token = 'lx3pcmffpp' py.sign_in(username, api_key) trace1 = Scatter(x=[], y=[], stream=dict(token=stream_token, maxpoints=2000)) layout = Layout(title='Raspberry Pi Streaming Sensor Data') fig = Figure(data=[trace1], layout=layout) print py.plot(fig, filename='Raspberry Pi Streaming Example Values') # temperature sensor connected channel 0 of mc #i = 0 stream = py.Stream(stream_token) stream.open() print usonic.reading(0) #the main sensor reading loop while True: print usonic.reading(0)