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 904 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
  • shabaz
    0 shabaz over 10 years ago

    Hi Thomas,

     

    If you're seeing corruption of image and sensors, then it is most likely something that is common to both of them - possibly power supply related or cold weather related. Perhaps the 5V (switched mode presumably) power source is dropping out when running everything, or needs supply decoupling.

    You may need to show a photo of the hardware and provide more detail of the environment for deeper examination. What battery (e.g. Li-Po?), and what temperature are you expecting to experience? Did anything else change with the successful flights, or is everything identical except that you've added more sensors?

    By photoresistor, do you mean a light dependent resistor (LDR)? What resistor value do you have in series with it? (Wondering if this is consuming too much current and pushing things into an unstable condition). How are you reading the LDR, the RPI has no analog-to-digital converter, is this some crude hack (schematic will help).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • balearicdynamics
    0 balearicdynamics over 10 years ago in reply to shabaz

    Shabaz , I agree with this troubleshooting but first of all I suggest to check the power source. I had strange behaviours and it was just the power not sufficient for all the peripherals.

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • DAB
    0 DAB over 10 years ago

    I would check all of the connections.

    I know the camera is just a press fit and the cold at high altitudes might lose the connection.

    Also the battery will not work as well at high altitudes or low temperatures.

    Try wrapping insulation around the battery and think about a small heating pad for the battery and circuitry.

     

    You are learning why the requirements for flight worthy components are much more robust.  Most TTL and microcontroller logic starts getting flaky once they get below zero degrees Fahrenheit.

     

    Try testing the device inside a good freezer.

    If it can work there, then you have more confidence that it will work in flight.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • 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
  • ttkoshi
    0 ttkoshi over 10 years ago

    Thank you for the replies, everyone. I tried checking my wiring, and then took the setup outdoors into direct sunlight. Again, I got the same results, with the photos returning green. I believe you were right, Shabaz, and that the light dependent resistor was somehow pushing too much current. Perhaps you can explain this to me? I know the resistor measures light in the Pi by calculating how long it takes to charge up the capacitor, but how would too much light start drawing current from the system? My lack of electronics knowledge is showing here, so I would appreciate any info.


    Right now, I have the Pi running in the window overnight. It's going to capture temperature/pressure data from the BMP180 and lux data from the luminosity sensor, as well as a photo. I've removed the photoresistor, and that seems to have fixed the problem. In the morning, once I know all my images were clean, I'll stick everything in the freezer for a few and see if I get any signal noise. I'll report back how those go, so hopefully we have a definite solution tomorrow.

     

    Thank you again for your help, all of you, this is something that has plagued me for three flights now! Once I know everything is stable due to the removal of the photoresistor, I'll look into a more stable battery. Any recommendations on a 5V 2A battery? Hopefully something light to not add weight on these balloon flights (my current battery is 75 grams). Many thanks to both of you!

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

    Hi Thomas,

     

    Glad to hear progress is being made. Do you have a link or diagram showing the photoresistor circuit you are using (and maybe a photo if feasible), I'm not quite sure what it could be, so I just want to examine it. I'm traveling so I might not be able to pick it up until evening Europe time, but others may also spot the issue meanwhile if you can post the diagram or link.

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

    You might try some of the new 5vdc 2600ma packs that are advertised as chargers for your cell phone. Another option might be to use the 7805 5vdc regulator and a battey pack like the Motorola 9044 7.5vdc cellpack for you pi. Then there's always the extended life battery packs used in R/C model aircrafts. I think the 7.5vdc w/regulator should work nicely for your project. Don't recall the type and ratings of your current power source.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
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