def poll_th():
    #data polling thread is main thread
    #setup gyro and altimeter
    alt = BMP180.BMP180(POWER_ON_ALT)
    #motion = LSM9DS0.LSM9DS0()
    gyro = LSM9DS0.LSM9DS0_GYRO()
    accel = LSM9DS0.LSM9DS0_ACCEL()

    f_log = open(DATA_LOG, 'a')
    f_log.write("starting log\n")

    last_measure = POWER_ON_ALT

    #sensors are up, start the xbee thread
    start_new_thread(xbee_th, ())

    while True:
        try:
            dict['time'] = datetime.datetime.utcnow()
            dict['agl'] = alt.read_agl()
            dict['temp'] = alt.read_temperature()

            last_measure = dict['agl']

            (x, y, z) = accel.read_accel()
            dict['a_x'] = x
            dict['a_y'] = y
            dict['a_z'] = z

            (x, y, z) = gyro.read()
            dict['g_x'] = x
            dict['g_y'] = y
            dict['g_z'] = z

            (x, y, z) = accel.read_magnetometer()
            dict['m_x'] = x
            dict['m_y'] = y
            dict['m_z'] = z
            dict['new_dat_flag'] = 1

            f_log.write(str(dict) + "\n")

        except IOError as e:
            try:
                logging.exception('Got I2C exception on main handler' +
                                  str(dict['time']))

                alt = BMP180.BMP180(last_measure)
                accel = LSM9DS0.LSM9DS0_ACCEL()
                gyro = LSM9DS0.LSM9DS0_GYRO()
            except:
                logging.exception('Gotexception on recovery attempt')

        except KeyboardInterrupt:
            break
        except:
            logging.exception('Got an exception on main handler')
Beispiel #2
0
thingspeak = thingspeak_driver.thingspeak_driver()
thingspeak_delay = 60
thingspeak_last_update = 0

# LED strip configuration:
strip = led_driver.led_driver()

#TelegramBot configuration:
telegram_bot = telegram_driver.telegram_driver()
TOKEN = telegram_bot.token
OWNER_CHAT_ID = telegram_bot.owner_id
user_interactions = 0  #Number of user interactions to be updated on ThingSpeak

#Pressure Sensor:
pressure_sensor = BMP180.BMP180()

#Wifi Stuff
wifi_driver = wifi_driver.wifi_driver()
wifi_setup_started = False

#Alarm stuff
global alarm_time
alarm_time = None

#Command List
commands = {
    'commands': ['commands', 'command', '/command', '/commands'],
    'google': ['look like', 'make it', 'make the cat'],
    'color blocks': ['color blocks', 'simplify colors', '/colorblocks'],
    'top': ['top', '/top', 'top ', '/top '],
def poll_th():
    #data polling thread is main thread
    #setup gyro and altimeter
    alt = BMP180.BMP180(POWER_ON_ALT)
    #motion = LSM9DS0.LSM9DS0()
    gyro = LSM9DS0.LSM9DS0_GYRO(
        LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1,
        LSM9DS0.LSM9DS0_GYROSCALE_2000DPS)
    accel = LSM9DS0.LSM9DS0_ACCEL()

    f_log = open(DATA_LOG, 'a')
    f_log.write("starting log\n")

    #sensor are up, start the xbee and gps threads
    start_new_thread(xbee_th, ())
    start_new_thread(gps_th, ())
    # start_new_thread(log_th, ())

    while True:
        try:
            trx_data['time'] = datetime.datetime.utcnow()
            trx_data['agl'] = alt.read_agl()
            trx_data['temp'] = alt.read_temperature()

            (x, y, z) = accel.read_accel()
            trx_data['a_x'] = x
            trx_data['a_y'] = y
            trx_data['a_z'] = z

            (x, y, z) = gyro.read()
            trx_data['g_x'] = x
            trx_data['g_y'] = y
            trx_data['g_z'] = z

            f_log.write(str(trx_data) + "\n")

        except IOError as e:
            try:
                logging.exception('Got I2C exception on main handler' +
                                  str(trx_data['time']))

                err_lock.acquire()
                trx_data['xbee_errors'] += 1
                error_trace['error'] += e + '\n'
                err_lock.release()

                alt = BMP180.BMP180(trx_data['agl'])
                accel = LSM9DS0.LSM9DS0_ACCEL()
                gyro = LSM9DS0.LSM9DS0_GYRO(
                    LSM9DS0.LSM9DS0_GYRODR_95HZ
                    | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1,
                    LSM9DS0.LSM9DS0_GYROSCALE_2000DPS)
            except:
                logging.exception('Gotexception on recovery attempt')

                err_lock.acquire()
                trx_data['xbee_errors'] += 1
                error_trace[
                    'error'] += 'error in recovery attempt of ' + e + '\n'
                err_lock.release()
        except KeyboardInterrupt:
            break
        except:
            logging.exception('Got an exception on main handler')
Beispiel #4
0
def poll_th():
    #data polling thread is main thread
    #setup gyro and altimeter
    alt = BMP180.BMP180(POWER_ON_ALT)
    #motion = LSM9DS0.LSM9DS0()
    gyro = LSM9DS0.LSM9DS0_GYRO(
        LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1,
        LSM9DS0.LSM9DS0_GYROSCALE_2000DPS)
    accel = LSM9DS0.LSM9DS0_ACCEL()

    f_log = open(DATA_LOG, 'a')
    f_log.write("starting log\n")

    last_measure = POWER_ON_ALT

    #sensor are up, start the xbee and gps threads
    start_new_thread(xbee_th, ())
    start_new_thread(gps_th, ())
    #start_new_thread(log_th, ())
    #for servo testing
    #remove this part after testing
    #TODO
    #start_new_thread(nav_th, ())

    while True:
        try:
            dict['time'] = datetime.datetime.utcnow()
            temp_agl = alt.read_agl()
            if abs(dict['agl'] - last_measure) < 60:
                dict['agl'] = temp_agl
            dict['temp'] = alt.read_temperature()

            #act on altimeter, in case accel fails in some way
            if (dict['agl'] > MIN_ALT) and (last_measure >
                                            MIN_ALT) and (not dict['arm_cut']):
                dict['arm_cut'] = 1
                f_log.write("armed cutter\n")

            if dict['arm_cut'] and (not dict['start_cut']):
                if dict['agl'] <= CHUTE_DEPLOY and last_measure <= CHUTE_DEPLOY:
                    dict['start_cut'] = 1
                    start_new_thread(nav_th, ())

            last_measure = temp_agl

            (x, y, z) = accel.read_accel()
            dict['a_x'] = x
            dict['a_y'] = y
            dict['a_z'] = z

            (x, y, z) = gyro.read()
            dict['g_x'] = x
            dict['g_y'] = y
            dict['g_z'] = z

            (x, y, z) = accel.read_magnetometer()
            dict['m_x'] = x
            dict['m_y'] = y
            dict['m_z'] = z
            dict['new_dat_flag'] = 1

            f_log.write(str(dict) + "\n")

        except IOError as e:
            try:
                logging.exception('Got I2C exception on main handler' +
                                  str(dict['time']))

                err_lock.acquire()
                dict['xbee_errors'] += 1
                error_trace['error'] += e + '\n'
                err_lock.release()

                alt = BMP180.BMP180(last_measure)
                accel = LSM9DS0.LSM9DS0_ACCEL()
                gyro = LSM9DS0.LSM9DS0_GYRO()
            except:
                logging.exception('Gotexception on recovery attempt')

                err_lock.aqcuire()
                dict['xbee_errors'] += 1
                error_trace[
                    'error'] += 'error in recovery attempt of ' + e + '\n'
                err_lock.release()
        except KeyboardInterrupt:
            break
        except:
            logging.exception('Got an exception on main handler')
Beispiel #5
0
 def bmp180(self):
     BMP180.run_program(self.app_log)
Beispiel #6
0
#!/usr/bin/python

import time
import BMP180

# Initialise the BMP085 and use STANDARD mode (default value)
# bmp = BMP085(0x77, debug=True)
bmp = BMP180.BMP180()

# 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
t_start = time.time()
while True:
    temp = bmp.read_temperature()

    # Read the current barometric pressure level
    pressure = bmp.read_pressure()

    # To calculate altitude based on an estimated mean sea level pressure
    # (1013.25 hPa) call the function as follows, but this won't be very accurate
    altitude = bmp.read_altitude()

    # To specify a more accurate altitude, enter the correct mean sea level
    # pressure level.  For example, if the current pressure level is 1023.50 hPa
    # enter 102350 since we include two decimal places in the integer value
    # altitude = bmp.readAltitude(102350)

    print "Temperature: %.2f C" % temp
Beispiel #7
0
#setup the gps and transmitter uart ports
UART.setup("UART1")
UART.setup("UART2")

#open a log file
f_log = open('/home/osu_rocketry/alt_log.out', 'a')

f_log.write("starting a full test\n")

#initialize the cutter pin, it is triggered on a high signal
GPIO.setup(CUTTER_PIN, GPIO.OUT)
GPIO.output(CUTTER_PIN, GPIO.LOW)

#setup gyro and altimeter
alt = BMP180.BMP180(POWER_ON_ALT)

#open a log file
f_log = open('/home/osu_rocketry/alt_log.out', 'a')
f_log.seek(0)
f_log.write("\n")
f_log.write("starting a full test")
gyro = LSM9DS0.LSM9DS0_gyro(LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1, LSM9DS0.LSM9DS0_GYROSCALE_200DPS)
accl = LSM9DS0.LSM9DS0_accel()

start_cut = 0
arm_cutter = 0

i = 0

while True:
Beispiel #8
0
CUTTER_PIN = "P9_12"
TRX_DEVICE = "/dev/ttyO1"
POWER_ON_ALT = 79   #altitude in meters of power on
CHUTE_DEPLOY = 330  #altitude to deploy main chute at
MIN_ALT	     = 800  #target minimum altitude before coming back down

#setup the gps and transmitter uart ports
UART.setup("UART1")
UART.setup("UART2")

#initialize the cutter pin, it is triggered on a high signal
GPIO.setup(CUTTER_PIN, GPIO.OUT)
GPIO.output(CUTTER_PIN, GPIO.LOW)

#setup gyro and altimeter
alt = BMP180.BMP180(POWER_ON_ALT)
#motion = LSM9DS0.LSM9DS0()
gyro = LSM9DS0.LSM9DS0_GYRO(LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1, LSM9DS0.LSM9DS0_GYROSCALE_2000DPS)
accel = LSM9DS0.LSM9DS0_ACCEL()

#open a log file
f_log = open('/home/osu_rocketry/alt_log.out', 'a')
#f_log.seek(0)
f_log.write("\n")
f_log.write("starting a full test")

start_cut = 0
arm_cutter = 0
last_measure = 0
i = 0
Beispiel #9
0
def poll_th():
  #data polling thread is main thread
  #setup gyro and altimeter
  alt = BMP180.BMP180(POWER_ON_ALT)
  gyro = LSM9DS0.LSM9DS0_GYRO(LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1, LSM9DS0.LSM9DS0_GYROSCALE_2000DPS)
  accel = LSM9DS0.LSM9DS0_ACCEL()
  
  f_log = open(DATA_LOG, 'a')
  f_log.write("starting log\n")
  
  agl_arr = [0] * 10
  i = 0
  
  #sensor are up, start the xbee and gps threads
  start_new_thread(xbee_th, ())
  start_new_thread(gps_th, ())
  #start_new_thread(log_th, ())
  #for servo testing
  #remove this part after testing
  #TODO
  #start_new_thread(nav_th, ())
  
  while True:
    try:
      dict['time'] = datetime.datetime.utcnow()
      dict['agl'] = round(alt.read_agl(), 2)
      dict['temp'] = alt.read_temperature()
      
      #act on altimeter, in case accel fails in some way
      agl_arr[i] = dict['agl']
      agl_avg = sum(agl_arr)/10
      dict['agl_avg'] = agl_avg
      i += 1
      if i == 10:
        i = 0

      if PAYLOAD == 1:
         if (agl_avg > MIN_ALT) and (not dict['arm_cut']):
           dict['arm_cut'] = 1
           f_log.write("armed cutter\n")
         if dict['arm_cut'] and (not dict['start_cut']):
           if agl_avg <= CHUTE_DEPLOY:
             dict['start_cut'] = 1
             start_new_thread(nav_th, ())
     
      (x, y, z) = accel.read_accel()
      dict['a_x'] = round(x, 5)
      dict['a_y'] = round(y, 5)
      dict['a_z'] = round(z, 5)
  
      (x, y, z) = gyro.read()
      dict['g_x'] = round(x, 5)
      dict['g_y'] = round(y, 5)
      dict['g_z'] = round(z, 5)

      (x, y, z) = accel.read_magnetometer()
      dict['m_x'] = round(x, 5)
      dict['m_y'] = round(y, 5)
      dict['m_z'] = round(z, 5)
      #dict['new_dat_flag'] = 1
    
      f_log.write(str(dict) + "\n")
      #f_log.write("track:" + str(dict['track']) + "   speed:" + str(dict['speed']) + "\n")

    except IOError as e:
      try:
        logging.exception('Got I2C exception on main handler' + str(dict['time']))
        
        err_lock.acquire()
        dict['xbee_errors'] += 1
        error_trace['error'] += e + '\n'
        err_lock.release()
  
        alt = BMP180.BMP180(last_measure)
        accel = LSM9DS0.LSM9DS0_ACCEL()
        gyro = LSM9DS0.LSM9DS0_GYRO()
      except:
        logging.exception('Gotexception on recovery attempt')
  
        err_lock.aqcuire()
        dict['xbee_errors'] += 1
        error_trace['error'] += 'error in recovery attempt of ' + e + '\n'
        err_lock.release()
    except KeyboardInterrupt:
      break
    except:
      logging.exception('Got an exception on main handler')
from Adafruit import Adafruit_GPIO_Platform as Platform
platform = Platform.platform_detect()

import BME280  # air pressure, temperature, humidity
import BMP180  # air pressure, temperature
import DS1820  # temperature
import HTU21DF  # temperature, humidity
import MCP9808  # temperature
import TSL2561  # luminosity

import SSD1306  # display

import CPU

bmp180 = BMP180.BMP180()
bme280 = BME280.BME280()

ds1820 = DS1820.DS1820("/sys/bus/w1/devices/28-000006b67845/w1_slave")
htu21df = HTU21DF.HTU21DF()

MCP9808_1_ADDR = 0x18
MCP9808_2_ADDR = 0x19
mcp9808_1 = MCP9808.MCP9808(address=MCP9808_1_ADDR)
mcp9808_2 = MCP9808.MCP9808(address=MCP9808_2_ADDR)
tsl2561 = TSL2561.TSL2561()

display = SSD1306.SSD1306()

cpu = CPU.CPU()
Beispiel #11
0
        return round(float(num), 2)


database.check_failed_data_handling()

try:

    # Measuring temperature and humidity
    humidity, temperature = DHT22.take_measurements()
    windchill_temperature = DS18B20.take_measurements()

    # Measuring luminosity
    full_spectrum, infrared, visible = TSL2561.take_measurements()

    # Measuring air pressure and altitude
    pressure, altitude = BMP180.take_measurements()

    database.store_in_database(format_measurement(temperature),
                               format_measurement(windchill_temperature),
                               format_measurement(humidity),
                               format_measurement(full_spectrum),
                               format_measurement(infrared),
                               format_measurement(visible),
                               format_measurement(pressure),
                               format_measurement(altitude))

except Exception:

    logging.basicConfig(filename="error.log", level=logging.DEBUG)
    logging.exception("message")
Beispiel #12
0
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import BMP180 as BMP180
import time

# Default constructor will pick a default I2C bus.
#
sensor = BMP180.BMP180()

while True:
    print('Temp = {0:0.2f} ⁰C'.format(sensor.read_temperature()))
    print('Pressure = {0:0.2f} Pa'.format(sensor.read_pressure()))
    print('Altitude = {0:0.2f} m'.format(sensor.read_altitude()))
    print('Sealevel Pressure = {0:0.2f} Pa'.format(
        sensor.read_sealevel_pressure()))
    time.sleep(1)
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
import time

sys.path.append('../libs')
sys.path.append('../libs/sensors')

import BMP180

b = BMP180.BMP180()

while True:
    print("Druck: {}".format(b.read_pressure() / 100.0))
    print("Temp: {}".format(b.read_temperature()))
    time.sleep(60)