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 __init__ (self): Thread.__init__(self) self.name = "Grove dust sensor" self.shortname = "dust" self.new_value = 0 self.value = 0 self.stop = False grovepi.dust_sensor_en()
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 __init__(self): print "Initialising dust sensor" try: print "Registering..." atexit.register(grovepi.dust_sensor_dis) print "Enabling..." grovepi.dust_sensor_en() except: print "FAILED TO INITIALISE"
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")
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")
def __init__(self, key): super(GroveDustReader, self).__init__(key) atexit.register(grovepi.dust_sensor_dis) grovepi.dust_sensor_en()
def __init__(self, sourceId, conf=Configuration()): Sensor.__init__(self, sourceId, conf) grovepi.dust_sensor_en()