by Anonymous » 27 Dec 2024, 12:34
Ich versuche, Sensordaten vom „Modbus SHT20 Sensor XY-MD02“ mithilfe der „minimalmodbus“-Bibliothek zu lesen, kann die Messwerte jedoch nicht abrufen. Ich wäre Ihnen dankbar, wenn Sie mir helfen könnten, wo ich etwas falsch mache. Es tut mir leid, wenn diese Frage dumm klingt, da dies meine erste Erfahrung mit RS485-Kommunikation ist.
Verdrahtungsdiagramm
https://docs.google.com/document/d/1P_T ... 1PTz5cvIc/ edit?usp=sharing
[Module & Sensoren']
RS485-zu-TTL-Konverter –
https://silicontechnolabs.in/products/r ... -converter
Temperatur- und Feuchtigkeitssender Modbus SHT20 Sensor XY-MD02 -
https://roboticsdna.in/product/temperat ... gn={campai gn}&adgroup={adgroup}&keyword=&matchtype=&gad_source=1&gclid=Cj0KCQiAvbm7BhC5ARIsAFjwNHtxYcYTCSiO4Y6TK0oxffiWH1NYwVIijQOv5MmM6OdBevpQqZE3KG4aAu0PEALw_wcB
und
Raspberry Pi 5 – Dibian OS
Code: Select all
My Config.txt
# For more options and information see
# http://rptl.io/configtxt
# Some settings may impact device functionality. See link above for details
# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=off
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# Additional overlays and parameters are documented
# /boot/firmware/overlays/README
# Automatically load overlays for detected cameras
camera_auto_detect=1
# Automatically load overlays for detected DSI displays
display_auto_detect=1
# Automatically load initramfs files, if found
auto_initramfs=1
# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2
# Don't have the firmware create an initial video= setting in cmdline.txt.
# Use the kernel's default instead.
disable_fw_kms_setup=1
# Run in 64-bit mode
arm_64bit=1
# Disable compensation for displays with overscan
disable_overscan=1
# Run as fast as firmware / board allows
arm_boost=1
[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1
[cm5]
dtoverlay=dwc2,dr_mode=host
[all]
dtparam=uart0=on
enable_uart=1
dtoverlay=i2c-rtc,ds3231
dtparam=rtc=off
#dtoverlay=pi3-miniuart-bt
Mein Code -
Code: Select all
import minimalmodbus
import serial
import time
instrument = minimalmodbus.Instrument('/dev/ttyAMA0', 1)
instrument.serial.baudrate = 9600
instrument.serial.timeout = 2
def read_temperature_humidity():
try:
temperature = instrument.read_register(0x0001, 2)
humidity = instrument.read_register(0x0002, 2)
temperature = temperature / 10.0
humidity = humidity / 10.0
print(f"Temperature: {temperature} °C")
print(f"Humidity: {humidity} %")
except minimalmodbus.NoResponseError:
print("No response from the sensor. Check connections and settings.")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
while True:
read_temperature_humidity()
time.sleep(2)
Ausgabe-
Code: Select all
pi@raspberrypi:~ $ sudo python3 sensor.py
No response from the sensor. Check connections and settings.
No response from the sensor. Check connections and settings.
Ich versuche, Sensordaten vom „Modbus SHT20 Sensor XY-MD02“ mithilfe der „minimalmodbus“-Bibliothek zu lesen, kann die Messwerte jedoch nicht abrufen. Ich wäre Ihnen dankbar, wenn Sie mir helfen könnten, wo ich etwas falsch mache. Es tut mir leid, wenn diese Frage dumm klingt, da dies meine erste Erfahrung mit RS485-Kommunikation ist.
Verdrahtungsdiagramm
https://docs.google.com/document/d/1P_Ts34HH1cGGb3XseNed1IJn0kJBaPhUwH1PTz5cvIc/ edit?usp=sharing
[Module & Sensoren']
RS485-zu-TTL-Konverter – https://silicontechnolabs.in/products/rs485-to-ttl-converter
Temperatur- und Feuchtigkeitssender Modbus SHT20 Sensor XY-MD02 - https://roboticsdna.in/product/temperature-and-humidity-transmitter-modbus-sht20-sensor-xy-md02/?src=google&kwd=&adgroup={adgroup}&device=c&campaign={campai gn}&adgroup={adgroup}&keyword=&matchtype=&gad_source=1&gclid=Cj0KCQiAvbm7BhC5ARIsAFjwNHtxYcYTCSiO4Y6TK0oxffiWH1NYwVIijQOv5MmM6OdBevpQqZE3KG4aAu0PEALw_wcB
und
Raspberry Pi 5 – Dibian OS
[code]My Config.txt
# For more options and information see
# http://rptl.io/configtxt
# Some settings may impact device functionality. See link above for details
# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=off
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# Additional overlays and parameters are documented
# /boot/firmware/overlays/README
# Automatically load overlays for detected cameras
camera_auto_detect=1
# Automatically load overlays for detected DSI displays
display_auto_detect=1
# Automatically load initramfs files, if found
auto_initramfs=1
# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2
# Don't have the firmware create an initial video= setting in cmdline.txt.
# Use the kernel's default instead.
disable_fw_kms_setup=1
# Run in 64-bit mode
arm_64bit=1
# Disable compensation for displays with overscan
disable_overscan=1
# Run as fast as firmware / board allows
arm_boost=1
[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1
[cm5]
dtoverlay=dwc2,dr_mode=host
[all]
dtparam=uart0=on
enable_uart=1
dtoverlay=i2c-rtc,ds3231
dtparam=rtc=off
#dtoverlay=pi3-miniuart-bt
[/code]
Mein Code -
[code]import minimalmodbus
import serial
import time
instrument = minimalmodbus.Instrument('/dev/ttyAMA0', 1)
instrument.serial.baudrate = 9600
instrument.serial.timeout = 2
def read_temperature_humidity():
try:
temperature = instrument.read_register(0x0001, 2)
humidity = instrument.read_register(0x0002, 2)
temperature = temperature / 10.0
humidity = humidity / 10.0
print(f"Temperature: {temperature} °C")
print(f"Humidity: {humidity} %")
except minimalmodbus.NoResponseError:
print("No response from the sensor. Check connections and settings.")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
while True:
read_temperature_humidity()
time.sleep(2)
[/code]
Ausgabe-
[code]pi@raspberrypi:~ $ sudo python3 sensor.py
No response from the sensor. Check connections and settings.
No response from the sensor. Check connections and settings.
[/code]