Exemplo n.º 1
0
def main(max_time, altitude_dif, delay_sample):
    formatted_time = datetime.datetime.utcnow().isoformat()
    print('[{}][main] Starting main'.format(formatted_time))

    bmp280_0 = bmp280.BMP280(delay_sample - 0.01)
    dht11_0 = dht11.DHT11(pin=4)
    mpu9250_0 = mpu9250.MPU9250()
    servo_0 = servo.Servo(0)

    deployer_0 = parachute_deployer.Deployer(bmp280_0, servo_0, altitude_dif,
                                             delay_sample)
    logger_0 = data_logger.Logger(bmp280_0, dht11_0, mpu9250_0)
    camera_0 = camera.Camera()

    deployer_thread = threading.Thread(target=deployer_0.main)
    logging_thread = threading.Thread(target=logger_0.log)

    deployer_thread.start()
    logging_thread.start()

    camera_0.start_recording()

    finisher_input_thread = threading.Thread(target=finisher_input,
                                             args=(deployer_0, logger_0,
                                                   camera_0),
                                             daemon=True)
    finisher_time_thread = threading.Thread(target=finisher_time,
                                            args=(deployer_0, logger_0,
                                                  camera_0, max_time),
                                            daemon=True)
    finisher_input_thread.start()
    finisher_time_thread.start()
def logTemp():
    logger.log('Clearing memory...')
    gc.collect()
    logger.log('Setting up I2C pins...')
    i2c = machine.I2C(1, scl=machine.Pin(18), sda=machine.Pin(19))
    sensor = bmp280.BMP280(i2c)
    logger.log('Reading temperature...')
    temp = str(sensor.getTemp())
    waterLevel = 6.66
    waterQuality = 7.77
    press = str(sensor.getPress())
    logger.log('Temperature read: ' + str(temp))
    logger.log('Pressure read: ' + str(press))
    logger.log('Logging measurements to Firebase...')
    localtime = time.localtime()
    now = str(localtime[3]) + ":" + str(localtime[4]) + ":" + str(localtime[5])

    post_data = ujson.dumps({
        "deviceName":
        "Water1000",
        "measurements": [{
            "type":
            "WATER_LEVEL",
            "value":
            10,
            "unitOfMeasurement":
            "METER",
            "deviceDateTime":
            str(localtime[2]) + "-" + str(localtime[1]) + "-" +
            str(localtime[0])
        }, {
            "type":
            "WATER_TEMP",
            "value":
            temp,
            "unitOfMeasurement":
            "CENTIGRADE",
            "deviceDateTime":
            str(localtime[2]) + "-" + str(localtime[1]) + "-" +
            str(localtime[0])
        }, {
            "type":
            "WATER_QUALITY",
            "value":
            press,
            "unitOfMeasurement":
            "PPM",
            "deviceDateTime":
            str(localtime[2]) + "-" + str(localtime[1]) + "-" +
            str(localtime[0])
        }]
    })

    res = urequests.post(
        'http://192.168.9.102:8080/api/devices/receiveDeviceData',
        headers={
            'content-type': 'application/json'
        },
        data=post_data).json()
Exemplo n.º 3
0
def bmp280_example():
    # Pin SDA1 and SCL1
    bmp280_0 = bmp280.BMP280(0.05)
    temperature, pressure, altitude = bmp280_0.read_last_data()
    print('BMP280')
    print("Temperature: ", temperature, "C")
    print("Pressure: ", pressure, "kPa")
    print("Altitude: ", altitude, "m\n")
Exemplo n.º 4
0
    def __init__(self, logger=None):
        # Configuration
        try:
            self.sensor = bmp280.BMP280(i2c_dev=SMBus(1))
            self.sensor.setup()
        except:
            self.sensor = None

        self.logger = logger
        self.temp = 0
        self.hum = 0
        self.pressure = 0
        self.altitude = 0
        self.actualTime = time()

        if self.sensor != None: self.read(True)  # Get the first reading
Exemplo n.º 5
0
import machine
import bmp280

i2c = machine.I2C(scl=machine.Pin(23), sda=machine.Pin(22))
'''
confirm your device is present on the bus
it should return [118] for this particular sensor
if this returns nothing, check your wiring
then check the Pin GPIO numbers are correct 
'''

print(i2c.scan())

sensor = bmp280.BMP280(i2c)
sensor.get()
#returns a list of temp float and barometric pressure int

sensor.getTemp()
#returns float temp in Celcius

sensor.getPress()
#returns int pressure in Pascals

sensor.getAltitude()
#returns float calculated altitude in metres
Exemplo n.º 6
0
def senBMP():
    bmp = bmp280.BMP280(i2c_gy91)
    global p, altitud, talt
    p = bmp.pressure
    altitud = (log(101325 / p)) / 0.00012
    talt = time.ticks_ms()
Exemplo n.º 7
0
import machine
import sht21
import bmp280
import time
import collectd
import uos
import weather
import sh1106

# Start up I2C
i2c = machine.I2C(sda=machine.Pin(21), scl=machine.Pin(22), freq=400000)

sens = sht21.SHT21(i2c)
bmp = bmp280.BMP280(i2c=i2c)
adc = machine.ADC(machine.Pin(35))

disp = sh1106.SH1106_I2C(128, 64, i2c)

led = machine.Pin(5, machine.Pin.OUT)
led.value(1)

disp.init_display()
disp.invert(False)
disp.rotate(True)
disp.fill(1)
disp.show()
time.sleep_ms(200)
disp.fill(0)
disp.show()

send_adc = False
import machine
import sdcard
import uos
#import max31865
import bmp280
import adxl345
import network

from machine import ADC, Pin, I2C, SPI

led = Pin(5, Pin.OUT)
led.value(0)

i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000)

bmp280 = bmp280.BMP280(i2c)
adxl345 = adxl345.ADXL345(i2c)

ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.config(essid="uPy Payload")

xpin = 34
ypin = 32
zpin = 34

xadc = ADC(Pin(xpin))
yadc = ADC(Pin(ypin))
zadc = ADC(Pin(zpin))

xadc.atten(ADC.ATTN_11DB)
Exemplo n.º 9
0
mqtt = MQTTClient(clientname, config.mqtt_server)

topic = "node/" + mac_addr[-4:] + "/sensors"

while not wlan.isconnected():
    time.sleep(2)
    wlan.active(True)
    wlan.connect(config.wifi_network, config.wifi_passwd)

# sensors
from machine import Pin, I2C, ADC
import bmp280
import dht

i2cbus = I2C(sda=Pin(4), scl=Pin(5))
bmp = bmp280.BMP280(address=0x76, i2c=i2cbus)

dht22 = dht.DHT22(Pin(14))  # is D5 on NodeMCU

ldr = ADC(0)


#
def send_sensordata():
    data = {}
    dht22.measure()
    data["dhtTemp"] = dht22.temperature()
    data["dhtHum"] = dht22.humidity()

    data["bmpTemp"] = bmp.read_temperature()
    data["bmpPres"] = bmp.read_pressure()
Exemplo n.º 10
0
from microbit import *  #importa la librería con las órdenes propias de microbit
import bmp280  #importa la librería con las instrucciones para el sensor bmp280
#uart.init(9600,tx=pin14,rx=pin15)
uart.init(57600, tx=pin13,
          rx=pin14)  #inicializa una comunicación serie a 9600 baudios
b = bmp280.BMP280()  #crea un elemento b del tipo bmp280
graba = False  #variable booleana para controlar el envío de datos o no
buffer = "tiempo" + "," + "temperatura" + "," + "presion" + "," + "altitud" + "," + "dirección" + "," + "acel_z\r\n"  #variable tipo string que contiene lo que se envia por puerto serie
uart.write(buffer)  #envia a puerto serie la variable buffer
compass.calibrate()

while True:  #bucle infinito
    if button_a.is_pressed():  #si el botón "a" está presionado
        graba = not graba  #cambia el estado de graba por su contrario de False a True o de True a False
        sleep(200)  #se espera 200 ms
    if button_b.is_pressed():  #si el botón "b" está presionado
        display.show(Image.SNAKE)  #enseña dibujo de una serpiente
        break  #sale del bucle (lo interrumpe)
    if graba == True:  # si graba es cierto
        display.show(Image.YES)  # enseña dibujo de verificado
        buffer = "soto," + str(running_time()) + "," + str(
            b.Temperature()) + "," + str(b.Pressure()) + "," + str(
                b.Altitude()) + "," + str(compass.heading()) + "," + str(
                    accelerometer.get_z()) + "," + "fin\r\n"
        #al buffer añade texto soto,tiempo,temperatura,presion,altitud,fin seperados por coma y al final con retorno de carro
        uart.write(buffer)  #envia a puerto serie la variable buffer
        sleep(500)  #se espera 500 ms
    else:
        display.show(Image.NO)  #enseña dibujo de cruz
Exemplo n.º 11
0
print('Scanning i2c bus...')
devices = i2c.scan()
if len(devices) == 0:
    print("No i2c devices found.")
else:
    print('i2c devices found:', len(devices))
    for device in devices:
        if device == addr_oled:
            print('OLED at ', addr_oled)
            oled_conn = True
            oled = ssd1306.SSD1306_I2C(w_size, h_size, i2c, addr_oled)
        if device == addr_bmp:
            print('BMP at ', addr_bmp)
            bmp_conn = True
            bmp = bmp280.BMP280(i2c_bus=i2c, addr=addr_bmp)
            bmp.use_case(bmp280.BMP280_CASE_WEATHER)
            bmp.force_measure()

        print(device)

while True:
    if bmp_conn:
        print("BMP280 values:")
        temp = bmp.temperature
        pr = bmp.pressure
        print("temp:", temp)
        print("pr:", pr)
        send_mqtt(temp, pr)

    if oled_conn:
Exemplo n.º 12
0
'''
    BMP280 demo

    Author: shaoziyang
    Date:   2018.2

    http://www.micropython.org.cn

'''
from microbit import *
import bmp280

b = bmp280.BMP280()

while True:
    sleep(500)
    b.get()
Exemplo n.º 13
0
'''

#bmp280 lib
import bmp280

#导入luma相关库,oled lib
from luma.core.render import canvas
from luma.oled.device import ssd1306

import time

#初始化oled,I2C接口1,oled地址是0x3c
device = ssd1306(port=1, address=0x3c)

#构建BMP280对象,I2C接口1
b = bmp280.BMP280(port=1)

while True:

    #获取温度
    Temp = b.getTemp()

    #获取大气压强
    Pressure = b.getPressure()

    #获取海拔高度
    Altitude = b.getAltitude()

    with canvas(device) as draw:
        draw.text((0, 0), '01Studio', fill="white")
        draw.text((0, 15), 'BMP280 test:', fill="white")
Exemplo n.º 14
0
import machine
import bmp280
SDA = machine.Pin(26)
SCL = machine.Pin(27)
bus = machine.I2C(1, sda=SDA, scl=SCL)

# bus=machine.I2C(0)
bmp = bmp280.BMP280(bus, addr=0x77)
print(bmp.temperature)
print(bmp.pressure)
Exemplo n.º 15
0
日期:2021.1
作者:01Studio 【www.01Studio.org】
说明:测量BMP280温度、气压和计算海拔值,并在OLED上显示。。
'''

import time,bmp280
from machine import Pin,SoftI2C
from ssd1306 import SSD1306_I2C

#初始化oled
i2c1 = SoftI2C(scl=Pin(10), sda=Pin(11))   #软件I2C初始化:scl--> 10, sda --> 11
oled = SSD1306_I2C(128, 64, i2c1, addr=0x3c) #OLED显示屏初始化:128*64分辨率,OLED的I2C地址是0x3c

#初始化BMP280,软件模拟I2C
i2c2 = SoftI2C(scl=Pin(4), sda=Pin(5))   #软件I2C初始化:scl--> 4, sda --> 5
BMP = bmp280.BMP280(i2c2)

while True:

    oled.fill(0)  # 清屏,背景黑色
    oled.text('01Studio', 0, 0)
    oled.text('Air Pressure:', 0, 15)

    # 温度显示
    oled.text(str(BMP.getTemp()) + ' C', 0, 35)
    # 湿度显示
    oled.text(str(BMP.getPress()) + ' Pa', 0, 45)
    # 海拔显示
    oled.text(str(BMP.getAltitude()) + ' m', 0, 55)

    oled.show()
Exemplo n.º 16
0
'''
    BMP280 demo

    Author: shaoziyang
    Date:   2018.2

    http://www.micropython.org.cn

'''
from machine import I2C
import time

import bmp280

b = bmp280.BMP280(I2C(1))

while True:
    time.sleep_ms(500)
    b.get()
Exemplo n.º 17
0
日期:2019.5.1
作者:01Studio 【www.01Studio.org】
说明:测量BMP280温度、气压和计算海拔值,并在OLED上显示。。
'''

import pyb
import bmp280
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C

#初始化OLED
i2c = I2C(sda=Pin("Y8"), scl=Pin("Y6"))
oled = SSD1306_I2C(128, 64, i2c, addr=0x3c)

#初始化BMP280,I2C接口2
BMP = bmp280.BMP280(I2C(2))

while True:

    oled.fill(0)  # 清屏,背景黑色
    oled.text('01Studio', 0, 0)
    oled.text('Air Pressure:', 0, 15)

    # 温度显示
    oled.text(str(BMP.getTemp()) + ' C', 0, 35)
    # 湿度显示
    oled.text(str(BMP.getPress()) + ' Pa', 0, 45)
    # 海拔显示
    oled.text(str(BMP.getAltitude()) + ' m', 0, 55)

    oled.show()
Exemplo n.º 18
0
DHTPIN = 17

GPIO.setmode(GPIO.BCM)

MAX_UNCHANGE_COUNT = 100

STATE_INIT_PULL_DOWN = 1
STATE_INIT_PULL_UP = 2
STATE_DATA_FIRST_PULL_DOWN = 3
STATE_DATA_PULL_UP = 4
STATE_DATA_PULL_DOWN = 5

DO = 17
GPIO.setmode(GPIO.BCM)
bar = bmp.BMP280()

endpoint = 'https://cuentacosmodbsql.documents.azure.com:443/'
key = '5AXLXjixvRAJK3tDyVrcDiME0lwxhqnTbn0sPe9Rx0FFBVL7sFxndHWiVffmzZM8sRZq4GCBGDvh2MEnYZ9yvQ=='
database_name = 'meteo'
container_name = 'medidas'

client = azc.CosmosClient(endpoint, key)
database = client.create_database_if_not_exists(id=database_name)
container = database.get_container_client(container_name)


def setup():
    print("Raspberry Pi wiringPi DHT11 Temperature test program\n")
    ADC.setup(0x48)
    GPIO.setup(DO, GPIO.IN)