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
  • 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
  • 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
Reply
  • 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
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