def get_BMP180_pressure(cmd, message, recdata): successflag=0 Pressure=0 # Initialise the BMP085 and use STANDARD mode (default value) # bmp = BMP085(0x77, debug=True) # bmp = BMP085(0x77, 1) # To specify a different operating mode, uncomment one of the following: # bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode # bmp = BMP085(0x77, 1) # STANDARD Mode # bmp = BMP085(0x77, 2) # HIRES Mode bmp = BMP085(0x77, 3) # ULTRAHIRES Mode #temp = bmp.readTemperature() try: isok, Pressure = bmp.readPressure() if isok: Pressure = '{0:0.2f}'.format(Pressure/100) # the reading is in Hpa successflag=1 except: #print " I2C bus reading error, BMP180 , pressure sensor " logger.error(" I2C bus reading error, BMP180 , pressure sensor ") #pressure is in hecto Pascal recdata.append(cmd) recdata.append(Pressure) recdata.append(successflag) return True
def get_BMP180_data(cmd, message, recdata, datatype): successflag=0 reading=0 msgarray=message.split(":") measureUnit="" if len(msgarray)>4: measureUnit=msgarray[4] SensorAddress="0x77" if len(msgarray)>6: if msgarray[6]!="": SensorAddress=msgarray[6] # Initialise the BMP085 and use STANDARD mode (default value) # bmp = BMP085(0x77, debug=True) # bmp = BMP085(0x77, 1) # To specify a different operating mode, uncomment one of the following: # bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode # bmp = BMP085(0x77, 1) # STANDARD Mode # bmp = BMP085(0x77, 2) # HIRES Mode Hiresmode=3 bmp = BMP085(int(SensorAddress, 0), Hiresmode) # ULTRAHIRES Mode #temp = bmp.readTemperature() try: if datatype=="pressure": isok, reading = bmp.readPressure() if isok: reading = '{0:0.2f}'.format(reading/100) # the reading is in Hpa successflag=1 if datatype=="temperature": isok, reading = bmp.readTemperature() if isok: if (measureUnit=="F"): reading=reading*1.8+32 reading = '{0:0.2f}'.format(reading) successflag=1 except: #print " I2C bus reading error, BMP180 , pressure sensor " logger.error(" I2C bus reading error, BMP180 sensor %s " , datatype) print("Error, BMP180 reading " , datatype) recdata.append(cmd) recdata.append("I2C bus reading error, BMP180") recdata.append(0) #pressure is in hecto Pascal recdata.append(cmd) recdata.append(reading) recdata.append(successflag) return True
def __init__(self, mode=1): print("a") # Initialise the BMP085 and use STANDARD mode (default value) # bmp = BMP085(0x77, debug=True) self.bmp = BMP085(0x77, mode) # To specify a different operating mode, uncomment one of the following: # bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode # bmp = BMP085(0x77, 1) # STANDARD Mode # bmp = BMP085(0x77, 2) # HIRES Mode # bmp = BMP085(0x77, 3) # ULTRAHIRES Mode rev = GPIO.RPI_REVISION if rev == 2 or rev == 3: bus = smbus.SMBus(1) else: bus = smbus.SMBus(0)
#!/usr/bin/python import smbus import RPi.GPIO as GPIO #import grovepi from grove_i2c_barometic_sensor_BMP180 import BMP085 # =========================================================================== # Example Code # =========================================================================== # Initialise the BMP085 and use STANDARD mode (default value) # bmp = BMP085(0x77, debug=True) bmp = BMP085(0x77, 1) # To specify a different operating mode, uncomment one of the following: # bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode # bmp = BMP085(0x77, 1) # STANDARD Mode # bmp = BMP085(0x77, 2) # HIRES Mode # bmp = BMP085(0x77, 3) # ULTRAHIRES Mode rev = GPIO.RPI_REVISION if rev == 2 or rev == 3: bus = smbus.SMBus(1) else: bus = smbus.SMBus(0) temp = bmp.readTemperature() # Read the current barometric pressure level pressure = bmp.readPressure()
## File Location log_file = "/home/pi/Desktop/weather_station_log.csv" # This is the name of the file we will save data to. # This is hard coded to the Desktop. ################################################################# ## Sensors light_sensor = 2 #Light Sensor Port Number temp_humidity_sensor = 4 #Temperature sensor Port Number # Temp humidity sensor type. You can use the blue or the white version. # Note the GrovePi Starter Kit comes with the blue sensor blue = 0 white = 1 therm_version = blue # If you change the thermometer, this is where you redefine. bmp = BMP085(0x77, 1) #Initialize the pressure sensor (barometer) # camera = picamera.PiCamera() # Initialize the camera. ################################################################# # Timings # You can adjust the frequency of the operations here: how frequently the sensors are read, # how frequently the data is written to csv, and how frequently pictures are taken. time_for_sensor = 1 * 60 * 60 # Take sensor data every 1 hour time_for_picture = 8 * 60 * 60 # Take sensor data every 8 hours time_to_sleep = 10 # The main loop runs every 10 seconds. # Timings #################################################################
def __init__(self, address=0x77, mode=3): self.sensor = BMP085(address, mode)
def get_data(self, now_ts, last_ts): record = {} record['dateTime'] = now_ts # required record['usUnits'] = weewx.METRIC # required record['interval'] = int((now_ts - last_ts) / 60) # required rev = GPIO.RPI_REVISION if rev == 2 or rev == 3: bus = smbus.SMBus(1) else: bus = smbus.SMBus(0) air_sen = 0 gas_sen = 1 hcho_sen = 2 light_sen = 0 water_sen = 3 sound_sensor = 2 senC = 1 grovepi.pinMode(air_sen, "INPUT") grovepi.pinMode(gas_sen, "INPUT") grovepi.pinMode(hcho_sen, "INPUT") grovepi.pinMode(water_sen, "INPUT") #grovepi6.pinMode(light_sen, "INPUT") #grovepi6.pinMode(senC, "INPUT") #grovepi6.pinMode(sound_sensor, "INPUT") #grovepi.pinMode(i2c-2, "INPUT") bmp = BMP085(0x77, 1) tempaaaa = bmp.readTemperature() pressure = bmp.readPressure() altitude = bmp.readAltitude(101560) sensor = 4 blue = 1 try: loginf("START BYTE GOOD") temp = bmp.readTemperature() pressure = bmp.readPressure() altitude = bmp.readAltitude(101560) [temp1, humidity] = grovepi.dht(sensor, blue) watsen = grovepi.digitalRead(water_sen) if watsen == 1: watwert = 100 else: watwert = 0 record['air_sensor'] = grovepi.analogRead(air_sen) record['gas_sensor'] = grovepi.analogRead(gas_sen) record['hcho_sensor'] = grovepi.analogRead(hcho_sen) #record['light_sensor'] = senorli record['water_sensor'] = watwert record['inTemp'] = temp1 record['inHumidity'] = humidity #record['sound'] = grovepi6.analogRead(sound_sensor) #record['gasC_sensor'] = grovepi6.analogRead(senC) record['pressure'] = pressure / 100.0 record['temp'] = tempaaaa record['altitude'] = altitude #record['hcho_sensor'] = hcho_se #record['gasN_sensor'] = grovepi.analogRead(gas_sen) #record['gasO_sensor'] = grovepi.read_i2c_byte(0x29) #record['lightD_sensor'] = liDig loginf("END BYTE GOOD") except IOError: print "Error" return record
import grovepi as gpi import time from grove_i2c_barometic_sensor_BMP180 import BMP085 from gps import GPS from lcd import LCD from modem import SatModem import csv TEMP_SENSOR = 0 # Port A0 is for the Temperature Sensor SOUND_SENSOR = 2 # Port A2 is for the Sound Sensor bmpSensor = BMP085(0x77, 1) # Register pressure sensor Port I2C-1 gpsSensor = GPS('/dev/ttyAMA0', 4800) # Connect Serial to GPS Device lcdDisplay = LCD() # Create a reference to the LCD Display satModem = SatModem('/dev/ttyUSB0') # Create a Reference to the Sat Modem secondElapsed = 0 lcdDisplay.setText("Hello!") time.sleep(2) lcdDisplay.setText("Prepping Sensors!") time.sleep(2) lcdDisplay.setText("Ready to Go!") time.sleep(2) with open(str(int(time.time())) + '.csv', 'wb') as csvfile: datawriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) datawriter.writerow([ 'temperature', 'sound', 'pressure', 'latitude', 'longitude', 'altitude'