I just purchased the BCRobotics board and tried to install the required
software for it. I ran into problems when I tried to test the BME280 using
the Adafruit ADS1x15 library. Kept getting errors and the python
Adafruit_BME280 library is deprecated.
Instead of trying to fix the errors I went the hard way and upgraded to the
adafruit-circuitpython libraries so I can also run Python3
sudo pip3 install adafruit-circuitpython-bme280
sudo pip3 install adafruit-circuitpython-ads1x15
I then modified the BCRobotics-test-app.py to run under Python3 and the
upgraded Adafruit libraries.
Tested the program and it works!
I have attached the modified program.
I need to modify the driver to work the same as the updated code but not
sure how to do that. Can I just substitute the same modifications that I
made to the test program?
Thanks
Terry
On Sunday, 24 November 2019 at 10:25:09 UTC-8 [email protected] wrote:
> Louis,
>
> thank you very much for your reply.
>
> I didn't realize they first did it with Python 2.7. I though you used it
> in order for it to work with the interceptor driver.
>
> I'll keep using python 2.7 and your code but it seems that I'm missing
> some libraries.
>
> (I think I had them all but I keep getting a " BME280_OSAMPLE_8' is not
> defined
> " etc. errors)
>
> I'll try and find the original code and libraries for Python 2.7 and do
> the necessary adjustments.
>
> Thanks again!
>
> On Sun, Nov 24, 2019 at 7:15 PM Louis De Lange <[email protected]> wrote:
>
>> George,
>>
>> At the time when I completed that project the tutorial on the BC-Robotics
>> website was written in Python 2.7 so I used all the 2.7 libraries in my
>> code. With some research you should be able to convert the original code
>> to work with python 3 libraries.
>>
>> Sorry, I have not updated anything because if it works why break it.
>>
>> LDL
>>
>> On Saturday, 23 November 2019 13:06:57 UTC-8, George Nimrodel wrote:
>>>
>>> Hey Louis,
>>>
>>> I'm trying to do exactly what you've done with the difference that I
>>> have weewx running on the RPi and I'm using only the BME280 for temperature
>>> in a separate enclosure.
>>>
>>> I'm having a bit of a trouble with your code. I keep getting errors
>>> regarding the libraries.
>>>
>>> I've noticed that you are not using the python 3 libraries from the
>>> tutorial.
>>>
>>> I would appreciate it if you could tell me which steps you took that are
>>> not included in the tutorial in order for your code to work.
>>>
>>> Any other pointers would also be appreciated
>>>
>>> Thank in advance!
>>>
>>> On Wednesday, December 12, 2018 at 5:53:25 AM UTC+2, Louis De Lange
>>> wrote:
>>>>
>>>> I recently came across a really excellent solution for putting together
>>>> your own weather station on the cheap with high quality sensors - and most
>>>> importantly a very useful weather HAT to use with a Raspberry PI to
>>>> connect
>>>> all the sensors.
>>>>
>>>> It comes complete with a 4 part step by step tutorial to assemble the
>>>> whole station, and basic code to upload the data to and online service -
>>>> see link below:
>>>>
>>>>
>>>> https://www.bc-robotics.com/tutorials/raspberry-pi-weather-station-part-1/
>>>>
>>>> I completed my own installation based on the instructions in the
>>>> tutorial and my station running on weewx is active at the link below
>>>>
>>>> http://peachlandweather.ca/mystation/
>>>>
>>>> For the outdoor portion I used a Raspberry Pi Zero W, with the weather
>>>> HAT. Weewx is running indoors in a FreeBSD jail, using a stock
>>>> Interceptor
>>>> driver. I modified the basic upload code provided in the tutorial quite
>>>> extensively to generate upload loops that matched the Observer URLs
>>>> supported by the Interceptor driver, and also to produce derived
>>>> observations not included in the original code.
>>>>
>>>> The upload code is attached for anyone who might be interested in
>>>> trying to assemble their own.
>>>>
>>>> I tested the results from using the station against my Vantage Pro 2
>>>> and so far it seems to be pretty close - for less than 20% of the cost of
>>>> a
>>>> Vantage Pro.
>>>>
>>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "weewx-user" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/weewx-user/udZCCCJlNE8/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/weewx-user/db1a607e-3fb0-4ed1-974e-0930406e7e6a%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/weewx-user/db1a607e-3fb0-4ed1-974e-0930406e7e6a%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/3ddea820-bf91-44ff-9a93-90a3214241c3n%40googlegroups.com.
import time
import board
import busio
import adafruit_bme280
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
from w1thermsensor import W1ThermSensor
import RPi.GPIO as GPIO
try:
ds18b20 = W1ThermSensor()
except Exception as err:
print ('Error:', err)
noTemp = True
else:
print ('carry on')
noTemp = False
i2c = busio.I2C(board.SCL, board.SDA)
bme = adafruit_bme280.Adafruit_BME280_I2C(i2c)
ads = ADS.ADS1115(i2c, gain=1)
chan = AnalogIn(ads, ADS.P0)
interval = 2 # Time between loops (seconds)
windTick = 0 # Count of the wind speed input trigger
rainTick = 0 # Count of the rain input trigger
# Set GPIO pins to use BCM pin numbers
GPIO.setmode(GPIO.BCM)
# Set digital pin 17 to an input and enable the pullup (wind speed)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Set digital pin 23 to an input and enable the pullup (rain)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Event to detect wind (4 ticks per revolution)
GPIO.add_event_detect(17, GPIO.BOTH)
def windtrig(self):
global windTick
windTick += 1
GPIO.add_event_callback(17, windtrig)
# Event to detect rain (0.2794mm per tick)
GPIO.add_event_detect(23, GPIO.FALLING)
def raintrig(self):
global rainTick
rainTick += 1
GPIO.add_event_callback(23, raintrig)
while True:
time.sleep(interval)
# Get temperature from DS18B20 sensor
temperature = ds18b20.get_temperature()
# Get Temperature from BME280
case_temp = bme.temperature
# Get Barometric Pressure from BME280 and convert to kPa from pascals
pressure_pa= bme.pressure
pressure = pressure_pa / 1000
# Get Humidity from BME280
humidity = bme.humidity
# Calculate wind direction based on ADC reading
# Read ADC channel 0 with a gain of 1
val = chan.value
windDir = "Not Connected" # In case wind sensor not connected
if 19600 <= val <= 20999:
windDir = "N"
if 9000 <= val <= 10799:
windDir = "NNE"
if 10800 <= val <= 13999:
windDir = "NE"
if 2000 <= val <= 2299:
windDir = "ENE"
if 2300 <= val <= 2999:
windDir = "E"
if 1000 <= val <= 1999:
windDir = "ESE"
if 4000 <= val <= 4999:
windDir = "SE"
if 3000 <= val <= 3999:
windDir = "SSE"
if 6600 <= val <= 8999:
windDir = "S"
if 5000 <= val <= 6599:
windDir = "SSW"
if 15900 <= val <= 16999:
windDir = "SW"
if 14000 <= val <= 15899:
windDir = "WSW"
if 24000 <= val <= 24999:
windDir = "W"
if 21000 <= val <= 21999:
windDir = "WNW"
if 22000 <= val <= 23999:
windDir = "NW"
if 17500 <= val <= 19599:
windDir = "NNW"
# Calculate the average wind speed over
# this 'interval' in km/h
windSpeed = (windTick * 1.2) / interval
windTick = 0
#Calculate the rainfall over this 'interval' in mm
rainFall = rainTick * 0.2794
rainTick = 0
# Print results
print ('Temperature: ', temperature, 'C')
print ('Humidity: ', humidity, '%')
print ('Case Temp: ', case_temp, 'C')
print ('Pressure: ', pressure, 'kPa')
print ('Dir ADC val: ', val)
print ('Wind Dir: ', windDir)
print ('Wind Speed: ', windSpeed, 'km/h')
print ('Rainfall: ', rainFall, 'mm')
print (' ')