Hey All,
anyone had this type of error before using the PiicoDev Atmospheric Sensor BME280?
Too many open files: ‘/dev/i2c-1’
is there a close command to end this during a loop?
.close()
Cheers in advance
Hey All,
anyone had this type of error before using the PiicoDev Atmospheric Sensor BME280?
Too many open files: ‘/dev/i2c-1’
is there a close command to end this during a loop?
.close()
Cheers in advance
Hi @Phil204480 - can you post your full source code?
This error is a quirk that arises when the device is initialised too many times. It’s because of how Linux treats everything like a file, including peripherals.
Every time a PiicoDev device is initialised, the OS touches the peripheral i2c-1
file. Linux has a limit on how many concurrent users are accessing a file. Do you have any loops where you initialise the device?
Hi @Michael, makes sense in what you are saying.
yes, I have the code here:
aprs-weather/aprs_weather.py at main · PhilKern65/aprs-weather (github.com)
Thanks again in advance!
Cheers
@Phil204480 this looks like a project!
I think the cuprit is here around line 89, 90
while True:
try:
bme280 = PiicoDev_BME280()
bme280_data = PiicoDev_BME280()
tempC, presPa, humRH = bme280.values() # read all data from the sensor
pres_hPa = presPa / 100 # convert air pressurr Pascals -> hPa (or mbar, if you prefer)
pres_aprs = presPa / 10 # convert air pressurr Pascals -> hPa (or mbar, if you prefer)
It looks like you’re initialising the sensor (twice?) every loop.
I’m unsure what the difference is between bme280
and bme280_data
.
Take another look at the tutorial and try moving your initialisation code outside your main loop so you only set up the sensor once.
Hi @Michael. I have modified the code and now running to see if the error still occurs.
There is no difference with bme280
and bme280_data
and was legacy code, which has been cleaned up.
I will update you…
thanks again.
Cheers!
@Phil204480 is that your latest code on Github? If so, you have 3 calls that initialize the BME, line 85, line 89 and line 90. There is also a commented out reference at line 104.
Change the one at line 85 to bme280 = PiicoDev_BME280
and clean up any other references to be just bme280
, e.g. lines 105, 106.
I think you’ve cut and pasted from a few sources… if you need to check that the bme returns ‘real’ data move the test (lines 106,7,8) to that start of the try
, but I think that code will actually return true if the device is found, and does not actually check the data (tempC, presPa, humRH
read at line 91).
Dave (ex VK2XPX )
p.s. I’m not a python expert, but hope that points you in the right direction.
Hi @dave50358 thanks for your feedback.
I have modified the code about a week ago and it seems to be running ok without failures. I will push the update to GitHub shortly.
FYI, the code is running here: The Sensor is in an air-conditioned hut, so you won’t see our 40+C days!
APRS/CWOP weather report from VK5RKW – Google Maps APRS
I still have a few teething problems in adding a comment. I get “X” any clues?
Cheers in advance de VK5ZEY
Hi @Michael. I haven’t had any more issues, since removing the legacy bme280 items.
I have uploaded the update to gitHub.
Cheers again!