def getSpectrumData(): global leftData, rightData io.digitalWrite(pinReset, 1) io.digitalWrite(pinClock, 1) time.sleep(0.001) io.digitalWrite(pinClock, 0) time.sleep(0.001) io.digitalWrite(pinReset, 0) io.digitalWrite(pinClock, 1) time.sleep(0.004) for s in range(0, 7): io.digitalWrite(pinClock, 0) time.sleep(0.004) # allow output to settle leftData[s] = scaleReading(io.analogRead(70), s, 0) rightData[s] = scaleReading(io.analogRead(71), s, 1) io.digitalWrite(pinClock, 1)
def main(): global clip, stop, pendingStop, mode, clipShift, nextPhase, stepTime initGPIO() print "Get A Grip - sequencer" clip = 0 clipShift = 0 stop = False mode = False pendingStop = False while True: if io.digitalRead(modePush) == 0 and io.digitalRead(startPush) == 0: terminate() if not stop: stepTime = 0.004 + (io.analogRead(71) / 2000.0) nextStep = time.time() + stepTime setMux(clip) #print clip, clipShift while time.time() <= nextStep: readStart() readMode() if mode and time.time() > nextPhase: echoSequence() readAD(clip) incrementClip() else: readStart()
def readAD(step): value = io.analogRead(70) # read multiplex look = 0 while value >= threshold[look]: look += 1 if look > 0 and look < 16: seqSound[look - 1].play()
def run(self): self.is_running == True wiringpi.wiringPiSetup() wiringpi.mcp3442Setup(0) while self.is_running == True: 'Read from pin 10 (MOSI SPI pin)' current_voltage = wiringpi.analogRead(10) print 'Voltage read: ' + current_temp time.sleep(1)
def readAD(step): global gripState value = io.analogRead(70) # read multiplex look = 0 while value >= threshold[look]: look += 1 gripState[step] = look if look > 0 and look < 16: seqSound[look - 1].play()
def getSpectrumData(): # set up the chip ot read in the data global leftData, rightData io.digitalWrite(pinReset, 1) io.digitalWrite(pinClock, 1) time.sleep(0.001) io.digitalWrite(pinClock, 0) time.sleep(0.001) io.digitalWrite(pinReset, 0) io.digitalWrite(pinClock, 1) time.sleep(0.004) # now read in each channel in turn for s in range(0, 7): io.digitalWrite(pinClock, 0) time.sleep(0.004) # allow output to settle leftData[s] = scaleReading(io.analogRead(70), s, 0) rightData[s] = scaleReading(io.analogRead(71), s, 1) io.digitalWrite(pinClock, 1)
def main_pub_inf_office_sensor() : # Initialize WiringPi wiringpi.wiringPiSetup() # Initialize mcp3004 ADC - first parm is pin base (must be > 64) # Second param is SPI bus number wiringpi.mcp3004Setup(100,0) # Initialize zmq context = zmq.Context() socket = context.socket(zmq.PUB) socket.bind(zmqSocket) try: while True: sensorReading = {} sensorReading['readTimeString'] = datetime.datetime.now().strftime("%m/%d/%y %I:%M%p") # Try to grab a DHT22 sensor reading. Use the read_retry method which will retry up # to 15 times to get a sensor reading (waiting 2 seconds between each retry). sensor = Adafruit_DHT.DHT22 # pin is GPIO numbering, not wiringpi numbering humidity, temperature = Adafruit_DHT.read_retry(sensor, 12) sensorReading['temperatureF'] = round((1.8 * temperature) + 32) sensorReading['humidity'] = round(humidity,1) # ADC read # pin 0 is lux meter 100 + 0 = 100 value = wiringpi.analogRead(100) sensorReading['lux'] = rawToLux(value) if doAnalog == True: # pin 2 is analog temp value = wiringpi.analogRead(102) atemp = (((value / 1024.0) * 3.3) * 100.0) - 50 sensorReading['temperatureC'] = round(atemp,1) sensorString = json.dumps(sensorReading) socket.send_multipart(['INF_SENSOR',sensorString]) time.sleep(5) except KeyboardInterrupt: print ("Exit by KeyboardInterrupt\n")
import wiringpi2, time class AnalogReader(object): OUTPUT = 1 status = False def __init__(self, pin): self.pin = pin wiringpi2.pinMode(self.pin,self.OUTPUT) def read(self): return wiringpi2.analogRead(self.pin) wiringpi2.wiringPiSetup() #reader = AnalogReader(0) wiringpi2.pinMode(0,1) while 1: time.sleep(0.2) print wiringpi2.analogRead(0)
def readAnalog(chan): try: return wp.analogRead(chan) except: return -1
import wiringpi2 as wiringpi from time import sleep wiringpi.wiringPiSetupGpio() wiringpi.pinMode(4,0) try: while True: if wiringpi.digitalRead(7): print "Printing the vibration" + str( wiringpi.analogRead(4)) sleep(0.5) finally: print " end of the program"
def read_raw(self): return wiringpi2.analogRead(self.analog_pin)
import wiringpi2 as wpi import time import redis import math rs = redis.StrictRedis(host='localhost', port=6379, db=0) wpi.wiringPiSetup() wpi.mcp3004Setup(70,0) rawvoltage = [0,0,0,0,0,0,0,0,0,0] i=0 while True: rawvoltage[i] = (wpi.analogRead(73) *33)/1024.0 i = (i+1)%10 sumvoltage =0 for j in range(10): sumvoltage += rawvoltage[j] power = int(math.floor(13 * sumvoltage)) if 200 < power: power = 200 r = rs.set('voltage', sumvoltage) r = rs.set('power', power) time.sleep(.1)
# GPIO number LED_PIN = 25 # threshold THRESHOLD = 200 # setup wp.mcp3002Setup (PIN_BASE, SPI_CH) wp.wiringPiSetupGpio() wp.pinMode(LED_PIN, wp.GPIO.OUTPUT) # if a sensor value is over THRESHOLD, # flash led. while True: value = wp.analogRead(PIN_BASE) print (value) if value > THRESHOLD: wp.digitalWrite(LED_PIN, wp.GPIO.HIGH) time.sleep(0.2) wp.digitalWrite(LED_PIN, wp.GPIO.LOW) time.sleep(0.2) requests.post("http://maker.ifttt.com/trigger/button_pressed/with/key/7nP8omSWbqca3Cdryst5c", json={"value1": "Yes"}) connector = MySQLdb.connect(host="localhost", db="logging", user="******", passwd="choooh1031", charset="utf8") cursor = connector.cursor() sql = u"insert into pressure values(now(), %s)" % value cursor.execute(sql) connector.commit() cursor.close() connector.close()
def distance(self): volts = wiringpi2.analogRead(200) * 3.3 / 256.0 return 60.495 * math.pow(volts, -1.1904)
def read(self): return wiringpi2.analogRead(self.pin)
import wiringpi2 as wiringpi wiringpi.wiringPiSetup() print wiringpi.digitalRead(1) print wiringpi.analogRead(1)
def getJoyData(): global leftData, rightData for s in range(0, 4): joyData[s] = scaleReading(io.analogRead(70 + s))
thread = threading.Thread(target=reader) thread.start() # end nfc setup count = 0 mlux = mpir = mmat = msound = mvolume = 0 while True: time.sleep(3) # read sensor data ts = int(time.time()) lux = tsl.lux() pir = wpi.digitalRead(2) mat = wpi.digitalRead(3) sound = wpi.digitalRead(21) volume = wpi.analogRead( 0) * 255 / 2047 # 0-10=quiet, 10-30=moderate, 30-127=loud mom = 0 dad = 0 if mat == 0: if nfcid == 'F10B330F': mom = 1 elif nfcid == '833BC4A2': dad = 1 if lux > mlux: mlux = lux if pir > mpir: mpir = pir if mat < mmat: mmat = mat