element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Raspberry Pi failing with camera, BMP180, and TSL2561
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 7 replies
  • Subscribers 666 subscribers
  • Views 907 views
  • Users 0 members are here
  • raspberry_pi
  • bmp180
  • tsl2561
Related

Raspberry Pi failing with camera, BMP180, and TSL2561

ttkoshi
ttkoshi over 10 years ago

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)


Attachments:
image
image
  • Sign in to reply
  • Cancel
Parents
  • saturnv
    0 saturnv over 10 years ago

    Thomas, All of the replies to your conundrum are great courses of action to follow to try to isolate your trouble with the Pi. I'd like to throw my 2 cents into the mix as well. Based on the photos and the data graphs supplied. I'd like to offer the following:

     

    The pictures appear to be obvious results of temperature, mainly cold and quite possibly light sensitivity as would be expected. The washed out green-screen effect could very well just be a simple case of over-exposure of light. As previously suggested, try to duplicate the symptoms with your Pi in the freezer which would test both temperature and (lack of) light conditions. Then, while the device is still cold from the freezer, operate it in a room where the light is extremely bright or at least pointed towards the camera lens to shine different amounts of light at the aperture during multiple  tests.

     

    In addition though, and this is solely based on the graphs you supplied, try adjusting the "ranges" that you are using within your software. Somewhere, there must be a constant of some type that you can apply to change the "visible" apertures range of light for your camera exposure as well as an adjustable range for the temperature and humidity. Unless I'm misreading your graphs, your results appear to be getting 'clipped' at certain ranges, elevations, or temperatures. Clipped, or saturated readings, depending on your preferred terminology appears to be, at least in part, some of the problem you are facing.

     

    If there is a way that you you can change the range used by your software based on the elevation of the balloon and compensate for the variations in temperature and elevation and lighting, you might solve your dilemma. Use your tst results from all of the above to narrow down your conclusions.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • saturnv
    0 saturnv over 10 years ago

    Thomas, All of the replies to your conundrum are great courses of action to follow to try to isolate your trouble with the Pi. I'd like to throw my 2 cents into the mix as well. Based on the photos and the data graphs supplied. I'd like to offer the following:

     

    The pictures appear to be obvious results of temperature, mainly cold and quite possibly light sensitivity as would be expected. The washed out green-screen effect could very well just be a simple case of over-exposure of light. As previously suggested, try to duplicate the symptoms with your Pi in the freezer which would test both temperature and (lack of) light conditions. Then, while the device is still cold from the freezer, operate it in a room where the light is extremely bright or at least pointed towards the camera lens to shine different amounts of light at the aperture during multiple  tests.

     

    In addition though, and this is solely based on the graphs you supplied, try adjusting the "ranges" that you are using within your software. Somewhere, there must be a constant of some type that you can apply to change the "visible" apertures range of light for your camera exposure as well as an adjustable range for the temperature and humidity. Unless I'm misreading your graphs, your results appear to be getting 'clipped' at certain ranges, elevations, or temperatures. Clipped, or saturated readings, depending on your preferred terminology appears to be, at least in part, some of the problem you are facing.

     

    If there is a way that you you can change the range used by your software based on the elevation of the balloon and compensate for the variations in temperature and elevation and lighting, you might solve your dilemma. Use your tst results from all of the above to narrow down your conclusions.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube