I'm working on a code for a High Altitude Weather Balloon and I wanted the camera to start recording after a certain Altitude. The first output of information is correct but then it spits out wrong information after. The camera also records but it pauses every second after and there isn't any time.sleep()
Here's my python code.
import datetime
import picamera
import time
import smbus2
bus = smbus2.SMBus(1)
# MPL3115A2 address, 0x60(96)
# Select control register, 0x26(38)
# 0xB9(185) Active mode, OSR = 128, Altimeter mode
bus.write_byte_data(0x60, 0x26, 0xB9)
# MPL3115A2 address, 0x60(96)
# Select data configuration register, 0x13(19)
# 0x07(07) Data ready event enabled for altitude, pressure, temperature
bus.write_byte_data(0x60, 0x13, 0x07)
# MPL3115A2 address, 0x60(96)
# Select control register, 0x26(38)
# 0xB9(185) Active mode, OSR = 128, Altimeter mode
bus.write_byte_data(0x60, 0x26, 0xB9)
time.sleep(1)
camera = picamera.PiCamera()
camera.resolution = (640, 480)
timeStopRec = None
while True:
data = bus.read_i2c_block_data(0x60, 0x00, 6)
tHeight = ((data[1]*65536)+(data[2]*256)+(data[3]&0xF0))/16
temp = ((data[4]*256)+(data[5]&0xF0))/16
altitude = tHeight / 16.0
cTemp = temp / 16.0
fTemp = cTemp * 1.8 + 32
bus.write_byte_data(0x60, 0x26, 0x39)
time.sleep(1)
data = bus.read_i2c_block_data(0x60, 0x00, 4)
pres = ((data[1] * 65536) + (data[2] * 256) + (data[3] & 0xF0)) / 16
pressure = (pres / 4.0) / 1000.0
print "Pressure : %.2f kPa" %pressure
print "Altitude : %.2f m" %altitude
print "Temperature in Celsius : %.2f C" %cTemp
print "Temperature in Fahrenheit : %.2f F" %fTemp
if tHeight > 100 and not camera.recording:
print('start recording')
camera.start_recording(datetime.datetime.now().strftime('%Y%m%d-%H%M%S.h264'))
timeStopRec = datetime.datetime.now() + datetime.timedelta(minutes=210)
if camera.recording and timeStopRec != None and datetime.datetime.now() > timeStopRec:
print('stop recording')
camera.stop_recording()