def readdustsensor(self, config): sensordata = [] pin = config.configuredsensors['dustsensor'], item['port'] atexit.register(grovepi.dust_sensor_dis) print("Reading from the dust sensor") grovepi.dust_sensor_en() try: [new_val, lowpulseoccupancy] = grovepi.dustSensorRead() print "new_val: " + str(new_val) print "lowpulseoccupancy: " + str(lowpulseoccupancy) if new_val: print(lowpulseoccupancy) sensordata.append( SensorValue(lowpulseoccupancy, 'none', 'Dust', 'location')) except IOError: print("Error") return sensordata
def read(self): [new_val, lpo] = grovepi.dustSensorRead() if new_val: return { 'value': lpo, 'level': self.get_level(lpo, self.levels), } else: return None
def get_dust() -> Tuple[datetime, int]: atexit.register(grovepi.dust_sensor_dis) grovepi.dust_sensor_en() attempts = 100 for _ in range(attempts): timestamp = datetime.now() new_val, low_pulse_occupancy = grovepi.dustSensorRead() if new_val: return timestamp, low_pulse_occupancy time.sleep(3) else: raise ValueError('Cannot read values from dust sensor')
def run(self): while not self.stop: try: [new_val,lowpulseoccupancy] = grovepi.dustSensorRead() self.new_value = new_val self.value = lowpulseoccupancy time.sleep(5) except IOError as e: print ("dust sensor exception: %s" % (e)) grovepi.dust_sensor_dis()
def readdustsensor(location): atexit.register(grovepi.dust_sensor_dis) print("Reading from the dust sensor") grovepi.dust_sensor_en() while True: try: [new_val,lowpulseoccupancy] = grovepi.dustSensorRead() if new_val: print(lowpulseoccupancy) sensordata = SensorValue(lowpulseoccupancy, 'none', 'Dust', location) writetofile(sensordata) time.sleep(5) except IOError: print ("Error")
def getValue3(self): print "getting dust values v3..." # try: [new_val, lowpulseoccupancy] = grovepi.dustSensorRead() print "new_val = ", new_val, " lowpulseoccupancy = ", lowpulseoccupancy sensors3["dustSensor.newValue"] = new_val sensors3["dustSensor.dustLevel"] = lowpulseoccupancy # if new_val: # print(lowpulseoccupancy) # time.sleep(5) # except IOError: # print ("Error") return sensors3
def getValue(self): print "getting dust values..." # try: [new_val, lowpulseoccupancy] = grovepi.dustSensorRead() print "new_val = ", new_val, " lowpulseoccupancy = ", lowpulseoccupancy sensors['dustSensor'][0]['value'] = new_val sensors['dustSensor'][1]['value'] = lowpulseoccupancy # if new_val: # print(lowpulseoccupancy) # time.sleep(5) # except IOError: # print "Error" return sensors
all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import time import grovepi import atexit atexit.register(grovepi.dust_sensor_dis) grovepi.dust_sensor_en() while True: try: [new_val, lowpulseoccupancy] = grovepi.dustSensorRead() [temp, humidity] = grovepi.dht(4, 1) a0 = grovepi.analogRead(0) a1 = grovepi.analogRead(1) a2 = grovepi.analogRead(2) print new_val, lowpulseoccupancy, "temp =", temp, " humidity =", humidity, "a0", a0, "a1", a1, "a2", a2 except: print("Error")
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' # USAGE # # Connect the dust sensor to Port D2 on the GrovePi. The dust sensor only works on that port # The dust sensor takes 30 seconds to update the new values # # the fist byte is 1 for a new value and 0 for old values # second byte is the concentration in pcs/0.01cf import time import grovepi import atexit atexit.register(grovepi.dust_sensor_dis) print("Reading from the dust sensor") grovepi.dust_sensor_en() while True: try: [new_val,lowpulseoccupancy] = grovepi.dustSensorRead() if new_val: print(lowpulseoccupancy) time.sleep(5) except IOError: print ("Error")
grovepi.dust_sensor_en() grovepi.setDustSensorInterval(5000) grovepi.ir_recv_pin(ir) # grovepi.ledBar_init(ledbar, 0) data = { 'sound': 0, 'light': 0, 'button': 0, 'temp': 0, 'humidity': 0, 'prox': 0, 'dust': 0, 'ir': 3 * [0] } while True: data['sound'] = grovepi.analogRead(sound_sensor) data['light'] = grovepi.analogRead(light_sensor) # [data['temp'],data['humidity']] = grovepi.dht(dht_sensor,0) data['button'] = grovepi.digitalRead(button) data['prox'] = grovepi.ultrasonicRead(ultrasonic_ranger) data['dust'] = grovepi.dustSensorRead() grovepi.analogWrite(led, val % 256) # grovepi.ledBar_setBits(ledbar, val % 1024) if grovepi.ir_is_data(): data['ir'] = list(grovepi.ir_read_signal()) val += 10 print(json.dumps(data)) time.sleep(0.2)
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' # USAGE # # Connect the dust sensor to Port 8 on the GrovePi. The dust sensor only works on that port # The dust sensor takes 30 seconds to update the new values, so you can send the 'run_in_bk=1' as a parameter to the read, e.g. grovepi.dustSensorRead(run_in_bk=1) to run the dust sensor code in the background. This basically allows the dust sensor to keep running in the background and you can read from it once every 30 seconds # # the fist byte is 1 for a new value and 0 for old values # second byte is the concentration in pcs/0.01cf import time import grovepi print "Reading from the dust sensor" while True: try: [new_val,conc] = grovepi.dustSensorRead() if new_val: print conc time.sleep(.5) except IOError: print ("Error")
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' # USAGE # # Connect the dust sensor to Port 8 on the GrovePi. The dust sensor only works on that port # The dust sensor takes 30 seconds to update the new values, so you can send the 'run_in_bk=1' as a parameter to the read, e.g. grovepi.dustSensorRead(run_in_bk=1) to run the dust sensor code in the background. This basically allows the dust sensor to keep running in the background and you can read from it once every 30 seconds # # the fist byte is 1 for a new value and 0 for old values # second byte is the concentration in pcs/0.01cf import time import grovepi print "Reading from the dust sensor" while True: try: [new_val, conc] = grovepi.dustSensorRead() if new_val: print conc time.sleep(.5) except IOError: print("Error")