Hi everyone-
I'm working on some sensors for a high-altitude ballooning project. I've wired together a BMP180 and a TSL2561 sensor together, and in addition added a camera and photoresistor. When I run my code in the lab, everything runs fine. However, when I am outdoors, once the sensors are off the ground, they start misbehaving. I have launched this payload twice, and twice received bad data. I have attached the graphs that were the result of the data, and you can see that there is a lot of noise from the sensors. The baseline before the changes is basically the payload sitting on the ground. In addition, the images that get taken start developing a green tint, but only once in the air. It seems my sensor is afraid of heights. I've posted the info here, as well as the code used to run it all. This is all powered by a 5V battery that returns to the ground with half charge, so I know the battery isn't being used up. I'm at my wits end, trying to find out why everything works on the ground, but not up at altitude. Other teams that I'm working with have sent up the BMP180, or a camera, but never together, I was the first to try rigging the two together. In addition, in the code you'll see that I was trying to write the altitude and temperature to the image metadata, which has worked so far. Any help would be greatly appreciated. Thank you!
Configuration:
- Raspberry Pi 2
- Raspberry Pi Camera
- TSL2561 Digital Luminosity Sensor (to 3.3V, reading via I2C)
- BMP 180 Temperature / Pressure sensor (to 5V, reading via I2C)
- Photoresistor (hooked to 1 microfarad capacitor) (to 5V, reading from pin 17)
#!/usr/bin/python
# Import libraries needed for program
import RPi.GPIO as GPIO, Adafruit_BMP.BMP085 as BMP085, os, datetime, time, math
from Adafruit_I2C import Adafruit_I2C
# This prevents warnings from crashing the program due to GPIO issues
GPIO.setwarnings(False)
DEBUG = 1
GPIO.setmode(GPIO.BCM)
# Define the Lux sensor and its address
address = 0x39
i2c = Adafruit_I2C(address)
control_on = 0x03
control_off = 0x00
# Initialize the BMP085 sensor in high resolution mode
sensor = BMP085.BMP085()
# Enable the Lux sensor
def enable():
i2c.write8(0x80, control_on)
def disable():
i2c.write8(0x80, control_off)
def getLight():
ch0 = i2c.readU16(0xAC) # Broad spectrum reading
ch1 = i2c.readU16(0xAE) # IR Reading
return ch0, ch1
def getLux():
ch0, ch1 = getLight()
ratio = 0
lux = 0
if ch0 > 0:
ratio = float(ch1) / float(ch0)
if ch0 == 0:
ratio = 1.35
if ratio > 1.30:
lux = 0
elif ratio > 0.80:
lux = (0.00146 * ch0) - (0.00112 * ch1)
elif ratio > 0.61:
lux = (0.0128 * ch0) - (0.0153 * ch1)
elif ratio > 0.50:
lux = (0.0224 * ch0) - (0.031 * ch1)
elif ratio <= 0.50:
lux = (0.0304 * ch0) - (0.062 * ch0 * ((ch1/ch0) ** 1.4))
return lux, ch0, ch1
# Function to read light from photoresistor
def RCtime (RCpin):
reading = 0
GPIO.setup(RCpin, GPIO.OUT)
GPIO.output(RCpin, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(RCpin, GPIO.IN)
while (GPIO.input(RCpin) == GPIO.LOW):
reading += 1
return reading
# Function to enable Lux sensor
# Main Loop
while True:
# Assigning values to variables
enable()
light = getLight()
lux, spectrum, infrared = getLux()
now = datetime.datetime.now()
timeStamp = now.strftime("%m%d%Y_%H%M%S")
photoResistor = RCtime(17)
temp = sensor.read_temperature()
altitude = sensor.read_altitude()
pressure = sensor.read_pressure()
seaPressure = sensor.read_sealevel_pressure()
#disable()
dataString = "Image = " + str(timeStamp) + ".jpg, Temp = " + str(temp) + ", Alt = " + str(altitude) + ", Pres = " + str(pressure) + ", SL Pres = " + str(seaPressure) + ", Photoresistor = " + str(photoResistor) + ", Lux = " + str(lux) + ", Spectrum = " + str(spectrum) + ", IR = " + str(infrared)
# Open file for logging and record data
logging = open('/home/pi/Code/AtmoAP/flight_data.txt','a')
logging.write(dataString + "\n")
# Take and save photo while embedding temp to EXIF Make and altitude to EXIT Model
takephoto = "raspistill -md 2 -n -t 1 --exif IFD0.Make={} --exif IFD0.Model={} -o /home/pi/Code/AtmoAP/images/{}.jpg".format(str(temp),str(altitude),timeStamp)
os.system(takephoto)
#Pause
time.sleep(2)






