raspberry pi i2c enable problems

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
brentschmidt
 
Posts: 26
Joined: Wed Oct 17, 2018 11:42 am

raspberry pi i2c enable problems

Post by brentschmidt »

Trying to follow the environmental tutorial (https://learn.adafruit.com/adafruit-io- ... r?view=all). I've done all the wiring and soldering on the port board, and double checked all of the connections with the multimeter. When I execute the .py file I get the following:

Code: Select all

pi@raspberrypi:~/io-client-python/examples/basics $ sudo python3 environmental_monitorKBS.py 
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/adafruit_bus_device/i2c_device.py", line 68, in __init__
    i2c.writeto(device_address, b'')
  File "/usr/local/lib/python3.5/dist-packages/busio.py", line 65, in writeto
    return self._i2c.writeto(address, buffer, stop=stop)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 38, in writeto
    self._i2c_bus.write_bytes(address, buffer[start:end])
  File "/usr/local/lib/python3.5/dist-packages/Adafruit_PureIO/smbus.py", line 244, in write_bytes
    self._device.write(buf)
OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/adafruit_bus_device/i2c_device.py", line 74, in __init__
    i2c.readfrom_into(device_address, result)
  File "/usr/local/lib/python3.5/dist-packages/busio.py", line 55, in readfrom_into
    return self._i2c.readfrom_into(address, buffer, stop=stop)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 44, in readfrom_into
    readin = self._i2c_bus.read_bytes(address, end-start)
  File "/usr/local/lib/python3.5/dist-packages/Adafruit_PureIO/smbus.py", line 155, in read_bytes
    return self._device.read(number)
OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "environmental_monitorKBS.py", line 79, in <module>
    uv = adafruit_veml6070.VEML6070(i2c)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_veml6070.py", line 130, in __init__
    self.i2c_cmd = I2CDevice(i2c_bus, _VEML6070_ADDR_CMD)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_bus_device/i2c_device.py", line 76, in __init__
    raise ValueError("No I2C device at address: %x" % device_address)
ValueError: No I2C device at address: 38
And when I run i2cdetect -y 1 I get:

Code: Select all

pi@raspberrypi:~/io-client-python/examples/basics $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --   
I'm thinking there that there is still something missing from the i2c setup, but I'm not exactly sure.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: raspberry pi i2c enable problems

Post by adafruit_support_carter »

The I2C scan should show it if it's there. This is most often a wiring issue. Can you post a photo of your setup showing how you have everything connected.

User avatar
brentschmidt
 
Posts: 26
Joined: Wed Oct 17, 2018 11:42 am

Re: raspberry pi i2c enable problems

Post by brentschmidt »

It’s hard to see. Everything seems to ohm out correctly.
Attachments
6CE1BA1B-8E2E-4B5C-B158-FE0F5C5C0F4D.jpeg
6CE1BA1B-8E2E-4B5C-B158-FE0F5C5C0F4D.jpeg (865.92 KiB) Viewed 1518 times
9CB5305D-762E-42AB-A1A5-8D661C47367F.jpeg
9CB5305D-762E-42AB-A1A5-8D661C47367F.jpeg (865.92 KiB) Viewed 1518 times

User avatar
FactoryFactory
 
Posts: 7
Joined: Wed Aug 19, 2015 5:28 am

Re: raspberry pi i2c enable problems

Post by FactoryFactory »

Check me, is that the MakerSpot proto board? If so, then what you did was use the two rail sections to bring out 1) power/ground and 2) SDA/SCL, right?

Have you tried just one sensor board at a time? It can also help to sanity check your wiring by inserting the boards, unpowered, and making sure your lines beep out with labels, as well - gnd to gnd, SDA to RPi pin BCM2, etc. While you are doing that, make sure nothing pings out to something it shouldn't. Sometimes e.g. I've had one strand of a stranded wire reach out and short a signal line to ground, and it was so small I didn't see it until I knew to look and used a magnifying glass.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: raspberry pi i2c enable problems

Post by adafruit_support_carter »

Your soldering looks fine, so I would suspect something with that protoboard. Can you bypass that and just set things up on a breadboard and use jumper wires?

User avatar
brentschmidt
 
Posts: 26
Joined: Wed Oct 17, 2018 11:42 am

Re: raspberry pi i2c enable problems

Post by brentschmidt »

FactoryFactory wrote:Check me, is that the MakerSpot proto board? If so, then what you did was use the two rail sections to bring out 1) power/ground and 2) SDA/SCL, right?
. Exactly. The adafruit port board was sold out. Bought this one on Amazon. Using the rail sections just like you say.
FactoryFactory wrote:Have you tried just one sensor board at a time? It can also help to sanity check your wiring by inserting the boards, unpowered, and making sure your lines beep out with labels, as well - gnd to gnd, SDA to RPi pin BCM2, etc. While you are doing that, make sure nothing pings out to something it shouldn't. Sometimes e.g. I've had one strand of a stranded wire reach out and short a signal line to ground, and it was so small I didn't see it until I knew to look and used a magnifying glass.
Go figure. I shutdown the pi. Unplugged all sensors. Booted up pi. Did i2cdetect. Plugged in 6070. Did i2cdetect. Plugged in BME280. Did i2cdetect. Plugged in SGP30. Did i2cdetect. All seems to be happy. I'm sure its the nut behind the wheel but not sure what happened here.

Code: Select all

pi@raspberrypi:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
pi@raspberrypi:~ $ 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: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
pi@raspberrypi:~ $ 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: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- 77                         
pi@raspberrypi:~ $ 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   

User avatar
brentschmidt
 
Posts: 26
Joined: Wed Oct 17, 2018 11:42 am

Re: raspberry pi i2c enable problems

Post by brentschmidt »

So now the i2c seems to be working, but I'm getting the following error.

Code: Select all

pi@raspberrypi:~/io-client-python/examples/basics $ sudo python3 environmental_monitorKBS.py
Reading sensors...
Traceback (most recent call last):
  File "environmental_monitorKBS.py", line 98, in <module>
    eCO2_data = sgp30.co2eq
AttributeError: 'Adafruit_SGP30' object has no attribute 'co2eq'

Code: Select all

pi@raspberrypi:~/io-client-python/examples/basics $ cat environmental_monitorKBS.py 
"""
'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 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 = '*********'

# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username)
ADAFRUIT_IO_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.co2eq
    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)
pi@raspberrypi:~/io-client-python/examples/basics $ 

User avatar
millercommamatt
 
Posts: 832
Joined: Tue Jul 31, 2018 4:57 pm

Re: raspberry pi i2c enable problems

Post by millercommamatt »

I think you want sgp30.eCO2 and not sgp30.co2eq

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: raspberry pi i2c enable problems

Post by adafruit_support_carter »


User avatar
brentschmidt
 
Posts: 26
Joined: Wed Oct 17, 2018 11:42 am

Re: raspberry pi i2c enable problems

Post by brentschmidt »

millercommamatt wrote:I think you want sgp30.eCO2 and not sgp30.co2eq
Yes. That's it.

Changed line 98 from sgp30.co2eq to sgp30.eCO2
Changed line 99 from sgp30.tvoc to sgp30.TVOC
Changed line 134 from time.sleep(LOOP_DELAY * 60) to time.sleep(LOOP_DELAY)


FYI, I copied this code from /io-client-python/examples/basics on the raspberry pi. It was installed during the setup of the pi.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: raspberry pi i2c enable problems

Post by adafruit_support_carter »

Thanks. It looks like the Python code for the guide is still using the older property names. Changes were made ~Oct 2018. I will see about getting that updated.

User avatar
brentschmidt
 
Posts: 26
Joined: Wed Oct 17, 2018 11:42 am

Re: raspberry pi i2c enable problems

Post by brentschmidt »

Is "control c" the prescribed way to end the loop?

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: raspberry pi i2c enable problems

Post by brubell »

@brentschmidt:

I've updated the example code (https://github.com/adafruit/Adafruit_IO ... 0de3e7815a).

CTRL+C is the best way to exit out of the Python interpreter. However, you can run the script with an ampersand at the end (python3 environmental_monitor.py &) if you'd like to run it in the background. If you want to terminate the script after a period of time, you could

Code: Select all

 import sys
, then call

Code: Select all

sys.exit()
from the code.

User avatar
brentschmidt
 
Posts: 26
Joined: Wed Oct 17, 2018 11:42 am

Re: raspberry pi i2c enable problems

Post by brentschmidt »

I'm having trouble getting that to work. Can you tell me what I might be doing wrong?

Code: Select all

pi@raspberrypi:~/io-client-python/examples/basics $ sudo python3 environmental_monitorKBS.py &
[1] 514
pi@raspberrypi:~/io-client-python/examples/basics $ Reading sensors...
sending data to adafruit io...
eCO2: 400
tvoc: 0
UV Level:  1
Temperature: 82.4 C
Humidity: 23.7 %
Pressure: 910.1 hPa
Altitude = 895.73 meters

pi@raspberrypi:~/io-client-python/examples/basics $ sudo import sys
sudo: import: command not found
pi@raspberrypi:~/io-client-python/examples/basics $ import sys
-bash: import: command not found
pi@raspberrypi:~/io-client-python/examples/basics $ sys.exit()
> Reading sensors...
sending data to adafruit io...
eCO2: 400
tvoc: 0
UV Level:  1
Temperature: 82.4 C
Humidity: 24.0 %
Pressure: 910.3 hPa
Altitude = 894.72 meters

> import sys
-bash: syntax error near unexpected token `import'
pi@raspberrypi:~/io-client-python/examples/basics $ import sys
-bash: import: command not found
pi@raspberrypi:~/io-client-python/examples/basics $ sys.exit
-bash: sys.exit: command not found
pi@raspberrypi:~/io-client-python/examples/basics $ sys.exit()
> Reading sensors...

> sending data to adafruit io...
eCO2: 400
tvoc: 0
UV Level:  1
Temperature: 84.2 C
^C
pi@raspberrypi:~/io-client-python/examples/basics $ Humidity: 22.6 %
Pressure: 910.2 hPa
Altitude = 895.98 meters


User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: raspberry pi i2c enable problems

Post by adafruit_support_carter »

Those are python commands, so need to be in your script, not executed from the command line.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”