Replies: 8 comments 4 replies
-
The problem is with the SHT3x_Sensor.py file. You instantiate it with
And change 43 of your file into: |
Beta Was this translation helpful? Give feedback.
-
Hi Robert,
thanks for your prompt answer.
I followed the suggestions, but, now I'm getting this error
MPY: soft reboot
Traceback (most recent call last):
File "", line 43, in
SyntaxError: positional arg after keyword arg
I've tried to understand what are positional and keyword arguments and Iit seems to me that Pythjon uses by default positional arguments and doesn't allow for mixing keyword args and positional args but this matter is really too complicated for me and I'm not even able to identify in my code which are the two different types of arguments
So I need again your help.
Thanks again
Bruno
PS I wrote the same text in GitHub because it's my first time and I didn't know where I had to place my reply.
… Il 20/12/2023 18:03 CET Robert Hammelrath ***@***.***> ha scritto:
The problem is with the SHT3x_Sensor.py file. You instantiate it with SHT3x_Sensor(freq=100000, sdapin=5, sclpin=4) in line 43, which will create a new I2C object and discards the i2c object created in line 29, which is used for BME280 and the DS3231. You have to change the SHT3X driver to accept an i2c object instead of the sda and scl arguments. Which is simple. Just replace lines 8 and 9 of the driver with:
def __init__(self, freq, i2c):
self.i2c = i2c
And change 43 of your file into:
SHT3x_Sensor(freq=100000, i2c)
—
Reply to this email directly, view it on GitHub #13242 (comment), or unsubscribe https://github.com/notifications/unsubscribe-auth/A5BIYK4HWK6LT2ZBSBUWKQTYKMK5TAVCNFSM6AAAAABA5CYIJ2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TSMJQGUYTI.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi,
just made what you suggested but still I get
MPY: soft reboot
Temp_BME is 16.07C
Hum_BME is 40.41%
Temp_SHT is -45.0
Hum_SHT is 0.0
13:16:22 21:12:2023
I'm enclosing again my code and the sht3x.py just to be sure that I followed correctly your suggestions
Really a big thanks for the time you're spending for my problem
Bruno
Il 21/12/2023 07:45 CET Robert Hammelrath ***@***.***> ha scritto:
Just change line 43 to:
SHT3x_Sensor(100000, i2c)
—
Reply to this email directly, view it on GitHub #13242 (reply in thread), or unsubscribe https://github.com/notifications/unsubscribe-auth/A5BIYK3PN7CCAWV65VACAV3YKPLJXAVCNFSM6AAAAABA5CYIJ2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TSMJUHE4DQ.
You are receiving this because you authored the thread.Message ID: ***@***.***>
from machine import deepsleep
from machine import Pin, SoftI2C
from ds3231_port import DS3231
from sht3x import SHT3x_Sensor
import utime
import sys
import uos
import BME280
import ssd1306
from time import sleep
import machine, os, sdcard
# Assign chip select (CS) pin (and start it high)
cs = machine.Pin(15, machine.Pin.OUT)
# Intialize SPI peripheral (start with 1 MHz)
spi = machine.SPI(1,
baudrate=1000000,
polarity=0,
phase=0,
bits=8,
firstbit=machine.SPI.MSB,
sck=machine.Pin(25),
mosi=machine.Pin(14),
miso=machine.Pin(13))
# Initialize SD card
sd = sdcard.SDCard(spi, cs)
os.mount(sd, '/sd')
i2c = SoftI2C(scl=Pin(4), sda=Pin(5))
rtc = DS3231(i2c)
ds3231 = DS3231(i2c)
ds3231.get_time()
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
while True:
oled.fill(0)
bme = BME280.BME280(i2c=i2c)
TEMP= str(bme.temperature)
HUM = str(bme.humidity)
sht3x_sensor = SHT3x_Sensor(freq=100000, sdapin=5, sclpin=4)
measure_data = sht3x_sensor.read_temp_humd()
temp = measure_data[0]
humd = measure_data[1]
temp = str(temp)
humd = str(humd)
print('Temp_BME is ', TEMP)
print('Hum_BME is ', HUM)
print('Temp_SHT is ', temp)
print('Hum_SHT is ', humd)
print('{:02d}:{:02d}:{:02d} '.format(utime.localtime()[3], utime.localtime()[4], utime.localtime()[5]), end='')
print('{:02d}:{:02d}:{:04d} '.format(utime.localtime()[2], utime.localtime()[1], utime.localtime()[0]), end='')
oled.text("Temp_BME "+TEMP, 0, 0)
oled.text("Hum_BME "+HUM, 0, 15)
oled.text("Temp_SHT "+temp, 0, 30)
oled.text("Hum_SHT " +humd, 0, 45)
oled.show()
sleep(5)
oled.fill(0)
file = open('/sd/test.txt', 'a')
file.write(str(bme.temperature) + '; ' + str(temp) + '; ' + str(bme.humidity) + '; ' + str(humd)+ '; ' +str(utime.localtime()[3:6]) +'; \n' )
file.close()
oled.text('Awake', 0, 0)
oled.text('but sleeping', 0, 10)
oled.text('in 5 seconds', 0, 20)
oled.text('for 5 minutes', 0, 30)
oled.text(str(utime.localtime()[3:6]),0,45)
oled.show()
sleep(5)
oled.fill(0)
oled.poweroff()
deepsleep(60000)
import sys
import utime
from machine import Pin
from machine import SoftI2C
class SHT3x_Sensor:
def __init__(self, freq, i2c):
self.i2c = i2c
addrs = self.i2c.scan()
if not addrs:
raise Exception('no SHT3X found at bus on SDA pin %d SCL pin %d' % (sdapin, sclpin))
self.addr = addrs.pop()
def read_temp_humd(self):
status = self.i2c.writeto(self.addr,b'\x24\x00')
# delay (20 slow)
utime.sleep(1)
# read 6 bytes
databytes = self.i2c.readfrom(self.addr, 6)
dataset = [databytes[0],databytes[1]]
dataset = [databytes[3],databytes[4]]
temperature_raw = databytes[0] << 8 | databytes[1]
temperature = (175.0 * float(temperature_raw) / 65535.0) - 45
# fahreheit
# temperature = (315.0 * float(temperature_raw) / 65535.0) - 49
humidity_raw = databytes[3] << 8 | databytes[4]
humidity = (100.0 * float(humidity_raw) / 65535.0)
sensor_data = [temperature, humidity]
return sensor_data
|
Beta Was this translation helpful? Give feedback.
-
Are you sure that you added the changed code? File |
Beta Was this translation helpful? Give feedback.
-
Hi Robert,
you're perfectly right.
I sent you the old version but I'm using the modified one
line 43 sht3x_sensor = SHT3x_Sensor(100000, i2c)
… Il 21/12/2023 13:38 CET Robert Hammelrath ***@***.***
b.com> ha scritto:
Are you sure that you added the changed code? File ESP32_BME280_SHT3X_RTCDS3231_OLED1306SSD_SDCARD.txt seems still to be the same and cannot work with the appended sht3x.txt.
—
Reply to this email directly, view it on GitHub #13242 (comment), or unsubscribe https://github.com/notifications/unsubscribe-auth/A5BIYK6YUJLBMJ4XIFJTYHTYKQUUPAVCNFSM6AAAAABA5CYIJ2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TSMJXHEZTO.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi,
thanks fro your suggestion.
I'm going to try this driver.
Have a nice day
Bruno
… Il 21/12/2023 13:42 CET Robert Hammelrath ***@***.***> ha scritto:
I have a SHT3x driver here which worked with MicroPython: https://github.com/robert-hh/SHT30
—
Reply to this email directly, view it on GitHub #13242 (reply in thread), or unsubscribe https://github.com/notifications/unsubscribe-auth/A5BIYK7HVJMYCFDJPM5H64TYKQVCLAVCNFSM6AAAAABA5CYIJ2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TSMJXHE3TA.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
As of your previous driver: It misses the wait time between starting the measurement and reading the result. There is a line
And it will be called e.g. with: |
Beta Was this translation helpful? Give feedback.
-
Hi Robert,
your suggestion was perfect.
Now everything works fine with the sht30.py driver( both BME280 and SHT3x and DS3231)
Really thanks for your precious help and have a Merry Christmas
Bruno
… Il 21/12/2023 13:42 CET Robert Hammelrath ***@***.***> ha scritto:
I have a SHT3x driver here which worked with MicroPython: https://github.com/robert-hh/SHT30
—
Reply to this email directly, view it on GitHub #13242 (reply in thread), or unsubscribe https://github.com/notifications/unsubscribe-auth/A5BIYK7HVJMYCFDJPM5H64TYKQVCLAVCNFSM6AAAAABA5CYIJ2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TSMJXHE3TA.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I need your help because I encountered a strange problem ( at least for me, a newbie of micropython).
I connected a BME280 and a DS3231 to an ESP32 and was able to save data on a SDcard while putting into deepsleep the ESP32 for fixed intervals.
When I added a SHT3X sensor to my breadboard using sht3x.py library (https://github.com/HAIZAKURA/esp-sht3x-micropython) I got from this sensor wrong values such as temp : -45.0 humd : 0.0%.
I tried to detect the sensor with I2Cscanner but neither BME280 that works fine together with DS3231 nor the SHT3X connected to the same pins SDA(5) and SCL(4) were found.
The same problem happens when I tried with another SHT sensor, while both these sensors work fine when using Arduino IDE instead of Micropython. So I think that the problem is with my code.
Thanks in advance for your help
Bruno
PS I'm enclosing my code
ESP32_BME280_SHT3X_RTCDS3231_OLED1306SSD_SDCARD.txt
Beta Was this translation helpful? Give feedback.
All reactions