🎁📬❄️📦 Holiday Shipping Deadlines are approaching! International customers and domestic ground - get your orders in 12/9/2020 📦❄️📬🎁
0

Error when running environmental_monitor.py
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Error when running environmental_monitor.py

by trent_darkside on Wed Nov 04, 2020 11:36 am

Hello Adafruit,

I am experiencing an error when trying to run environmental_monitor.py on the raspberry pi zero w.

The Adafruit BME280 Temp Humidity Pressure Sensor, Adafruit SGP30 Air Quality Sensor Breakout,

and Adafruit VEML6070 UV Index Sensor Breakout are connected to i2c on the Pi Zero W.

The Environmental Monitor Dashboard has been created as instructed at https://learn.adafruit.com/adafruit-io- ... r/overview

This dashboard is not displaying any data from the sensors connected to the pi zero.

I have recently subscribed to Adafruit IO +

What could be causing the issue?

Sensors connected to i2c on pi are detected.

pi@breadboardpi:~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- 38 39 -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- 58 -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77

Here is the error.

pi@breadboardpi:~ $ python3 environmental_monitor.py
Reading sensors...
Traceback (most recent call last):
File "environmental_monitor.py", line 101, in <module>
uv_data = sample_VEML()
File "environmental_monitor.py", line 91, in sample_VEML
uv_raw = uv.read
AttributeError: 'VEML6070' object has no attribute 'read'

Here is the environmental_monitor.py code provided at https://learn.adafruit.com/adafruit-io- ... ython-code

Code: Select all | TOGGLE FULL SIZE



"""
'environmental_monitor.py'
===============================================================================
Example of sending I2C sensor data
from multiple sensors to Adafruit IO.

Tutorial Link: https://learn.adafruit.com/adafruit-io-air-quality-monitor

Adafruit invests time and resources providing this open source code.
Please support Adafruit and open source hardware by purchasing
products from Adafruit!

Author(s): Brent Rubell for Adafruit Industries
Copyright (c) 2018 Adafruit Industries
Licensed under the MIT license.
All text above must be included in any redistribution.

Dependencies:
    - Adafruit_Blinka (CircuitPython, on Pi.)
        (https://github.com/adafruit/Adafruit_Blinka)
    - Adafruit_CircuitPython_SGP30.
        (https://github.com/adafruit/Adafruit_CircuitPython_SGP30)
    - Adafruit_CircuitPython_VEML6070.
        (https://github.com/adafruit/Adafruit_CircuitPython_VEML6070)
    - Adafruit_CircuitPython_BME280.
        (https://github.com/adafruit/Adafruit_CircuitPython_BME280)
"""

# Import standard python modules
import time

# import Adafruit Blinka
import board
import busio

# import CircuitPython sensor libraries
import adafruit_sgp30
import adafruit_veml6070
import adafruit_bme280

# import Adafruit IO REST client
from Adafruit_IO import Client, Feed, RequestError

# loop timeout, in seconds.
LOOP_DELAY = 10

# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'

# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username)
ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'

# Create an instance of the REST client
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

try: # if we already have the feeds, assign them.
    tvoc_feed = aio.feeds('tvoc')
    eCO2_feed = aio.feeds('eco2')
    uv_feed = aio.feeds('uv')
    temperature_feed = aio.feeds('temperature')
    humidity_feed = aio.feeds('humidity')
    pressure_feed = aio.feeds('pressure')
    altitude_feed = aio.feeds('altitude')
except RequestError: # if we don't, create and assign them.
    tvoc_feed = aio.create_feed(Feed(name='tvoc'))
    eCO2_feed = aio.create_feed(Feed(name='eco2'))
    uv_feed = aio.create_feed(Feed(name='uv'))
    temperature_feed = aio.create_feed(Feed(name='temperature'))
    humidity_feed = aio.create_feed(Feed(name='humidity'))
    pressure_feed = aio.create_feed(Feed(name='pressure'))
    altitude_feed = aio.create_feed(Feed(name='altitude'))

# Create busio I2C
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
# Create VEML6070 object.
uv = adafruit_veml6070.VEML6070(i2c)
# Create BME280 object.
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
bme280.sea_level_pressure = 1013.25
# Create SGP30 object using I2C.
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c)
sgp30.iaq_init()
sgp30.set_iaq_baseline(0x8973, 0x8aae)

# Sample VEML6070
def sample_VEML():
    for j in range(10):
      uv_raw = uv.read
    return uv_raw

while True:
    print('Reading sensors...')
    # Read SGP30.
    eCO2_data = sgp30.eCO2
    tvoc_data = sgp30.TVOC

    # Read VEML6070.
    uv_data = sample_VEML()

    # Read BME280.
    temp_data = bme280.temperature
    # convert temperature (C->F)
    temp_data = int(temp_data) * 1.8 + 32
    humid_data = bme280.humidity
    pressure_data = bme280.pressure
    alt_data = bme280.altitude

    print('sending data to adafruit io...')
    # Send SGP30 Data to Adafruit IO.
    print('eCO2:', eCO2_data)
    aio.send(eCO2_feed.key, eCO2_data)
    print('tvoc:', tvoc_data)
    aio.send(tvoc_feed.key, tvoc_data)
    time.sleep(2)
    # Send VEML6070 Data to Adafruit IO.
    print('UV Level: ', uv_data)
    aio.send(uv_feed.key, uv_data)
    time.sleep(2)
    # Send BME280 Data to Adafruit IO.
    print('Temperature: %0.1f C' % temp_data)
    aio.send(temperature_feed.key, temp_data)
    print("Humidity: %0.1f %%" % humid_data)
    aio.send(humidity_feed.key, int(humid_data))
    time.sleep(2)
    print("Pressure: %0.1f hPa" % pressure_data)
    aio.send(pressure_feed.key, int(pressure_data))
    print("Altitude = %0.2f meters" % alt_data)
    aio.send(altitude_feed.key, int(alt_data))
    # avoid timeout from adafruit io
    time.sleep(LOOP_DELAY * 60)


 


Thanks to Adafruit for your support during the pandemic.

Trent

trent_darkside
 
Posts: 45
Joined: Wed Nov 23, 2016 11:11 am

Re: Error when running environmental_monitor.py

by brubell on Wed Nov 04, 2020 12:01 pm

Hi Trent,

The VEML6070 library has been changed a bit since this code has been published.

I've updated the code and submitted a pull request. Would you be able to test this code and let me know if it works?

https://github.com/adafruit/Adafruit_IO_Python/pull/122

- Brent R.

brubell
 
Posts: 1116
Joined: Fri Jul 17, 2015 10:33 pm

Re: Error when running environmental_monitor.py

by trent_darkside on Wed Nov 04, 2020 2:09 pm

Hi Brent,

Thank you for the response.

I would like to test the updated code. Where can it be found?

This is my first time using AdafruitIO and I have limited experience with python.

trent_darkside
 
Posts: 45
Joined: Wed Nov 23, 2016 11:11 am

Re: Error when running environmental_monitor.py

by trent_darkside on Wed Nov 04, 2020 3:07 pm

It's working. Data values have populated the dashboard.
Thank you very much.

pi@breadboardpi:~ $ python3 environmental_monitor.py
Reading sensors...
sending data to adafruit io...
eCO2: 400
tvoc: 0
UV Level: 0
Temperature: 73.4 C
Humidity: 50.1 %
Pressure: 1031.6 hPa
Altitude = -151.90 meters

Can this code be set to run on boot with the method described at https://learn.adafruit.com/running-prog ... y-computer

or should I let it run and quit the putty ssh session?

trent_darkside
 
Posts: 45
Joined: Wed Nov 23, 2016 11:11 am

Re: Error when running environmental_monitor.py

by brubell on Fri Nov 06, 2020 10:24 am

Glad it's working, I'll merge in.

If you want to run on boot, check out this guide instead:
https://learn.adafruit.com/adafruit-min ... -3044386-8

brubell
 
Posts: 1116
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.