SCL in use error with BME280 and Adalogger RTC

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
remohn
 
Posts: 6
Joined: Fri Nov 24, 2017 6:36 pm

SCL in use error with BME280 and Adalogger RTC

Post by remohn »

I have an Adafruit RP2040 with a BME280 connected. On that I have stacked a feather airlift, adalogger, 128x32 monochrome featherwing.

All works well until I get to printing the data from the BME280 and RTC at the same time. I get and "SCL in use" error as soon as I try to pull the date and time from the adalogger RTC. Independently pulling data and printing from the BME280 works, and pulling the data and time from the RTC and printing works. But the two together gives me the "SCL in use" error.

Is there a way to get around this conflict.

Thanks.

User avatar
dastels
 
Posts: 15820
Joined: Tue Oct 20, 2015 3:22 pm

Re: SCL in use error with BME280 and Adalogger RTC

Post by dastels »

Can you post your code. Related: are you creating two i2c objects explicitly using board.SCL and board.SDA?

Dave

User avatar
remohn
 
Posts: 6
Joined: Fri Nov 24, 2017 6:36 pm

Re: SCL in use error with BME280 and Adalogger RTC

Post by remohn »

Below is the code I am using. I took it from the learning examples.

The error seems to happen when the get_rtc_datetime() function is called in the get_bem280_data() function. I highlighted the i2c objects created.

Is the SCL parameter related to and address or pin number. Whe the boards are stacked can the SCL be unique for each device or featherwing?

def get_rtc_datetime():
import busio
import adafruit_pcf8523
import time
import board

# ********************************************
myI2C = busio.I2C(board.SCL, board.SDA) # ERROR IS TRIGGERED HERE WHEN FUNCTION CALLED BELOW
rtc = adafruit_pcf8523.PCF8523(myI2C)
# ********************************************

days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")

"""
while True:
t = rtc.datetime
#print(t) # uncomment for debugging

mydate = ("%s %d/%d/%d" % (days[t.tm_wday], t.tm_mday, t.tm_mon, t.tm_year))
mytime = ("%d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec))

print(str(mydate) + " - " + str(mytime))

time.sleep(1) # wait a second
"""

t = rtc.datetime
mydate = ("%s %d/%d/%d" % (days[t.tm_wday], t.tm_mday, t.tm_mon, t.tm_year))
mytime = ("%d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec))
return (str(mydate) + " - " + str(mytime))

# my_time_and_date = get_rtc_datetime()
# print(my_time_and_date)

def get_bem280_data():
import time
import board
import adafruit_bme280

import displayio
import terminalio
from adafruit_display_text import label
import adafruit_displayio_ssd1306

# Create sensor object, using the board's default I2C bus.
# ******************************************************
i2c = board.I2C() # uses board.SCL and board.SDA
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
# ******************************************************

# Change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25

bme280.mode = adafruit_bme280.MODE_NORMAL
bme280.standby_period = adafruit_bme280.STANDBY_TC_500
bme280.iir_filter = adafruit_bme280.IIR_FILTER_X16
bme280.overscan_pressure = adafruit_bme280.OVERSCAN_X16
bme280.overscan_humidity = adafruit_bme280.OVERSCAN_X1
bme280.overscan_temperature = adafruit_bme280.OVERSCAN_X2
# The sensor will need a moment to gather initial readings
time.sleep(1)

x = 1

while True:

print("\nTemperature: %0.1f C" % bme280.temperature + " - " + "%0.1f F" % ((bme280.temperature * 1.8) + 32))
print("Humidity: %0.1f %%" % bme280.relative_humidity)
print("Pressure: %0.1f hPa" % bme280.pressure + " - " + "%0.1f inHg" % (bme280.pressure * 0.030))
print("Altitude = %0.2f meters" % bme280.altitude + " - " + "%0.2f feet" % (bme280.altitude * 3.2808))
print(time.time())
time.sleep(1)

# CODE WORKS THROUGH HERE BUT ERRORS OUT LATER

displayio.release_displays()

# ***************************************************************************
i2c = board.I2C()
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
# ***************************************************************************
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)

# Make the display context
splash = displayio.Group(max_size=10) #10 is max elements
display.show(splash)

color_bitmap = displayio.Bitmap(128, 32, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF # White
#color_palette[0] = 0x000000 # Black

bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)

# Draw a smaller inner rectanlgle
inner_bitmap = displayio.Bitmap(128, 32, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x000000 # Black
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=0, y=0)
splash.append(inner_sprite)

# Draw a label
text = "%0.1fF" % ((bme280.temperature * 1.8) + 32) + " - " + "%0.1f%%" % bme280.relative_humidity
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00, x=26, y=5)
splash.append(text_area)

text = "%0.1finHg" % (bme280.pressure * 0.030) + " - " + "%0.2fft" % (bme280.altitude * 3.2808)
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00, x=8, y=15)
splash.append(text_area)

# This seems to trigger error
text = get_rtc_datetime()
# **********************************

text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00, x=8, y=25)
splash.append(text_area)
x = 0
time.sleep(10)
pass

get_bem280_data()

User avatar
remohn
 
Posts: 6
Joined: Fri Nov 24, 2017 6:36 pm

Re: SCL in use error with BME280 and Adalogger RTC

Post by remohn »

I fixed the issue by changing the code in the get_rtc_datetime() function

FROM:
# ********************************************
myI2C = busio.I2C(board.SCL, board.SDA) # ERROR IS TRIGGERED HERE WHEN FUNCTION CALLED BELOW
rtc = adafruit_pcf8523.PCF8523(myI2C)
# ********************************************

TO:
# ********************************************
i2c = board.I2C()
rtc = adafruit_pcf8523.PCF8523(i2c)
# ********************************************

I guess the issue was mixing the busio.i2c and board.i2c. Once every instatiation was board.i2c all worked as desired.

Thanks.

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

Return to “Adafruit CircuitPython”