Raspberry Pi 5 с датчиком SHT20 (XY MD02) Проблемы и проблемы при чтении данных с использованием MinimalmodbusPython

Программы на Python
Ответить
Anonymous
 Raspberry Pi 5 с датчиком SHT20 (XY MD02) Проблемы и проблемы при чтении данных с использованием Minimalmodbus

Сообщение Anonymous »

Я пытаюсь прочитать данные датчика из «Modbus SHT20 Sensor XY-MD02», используя библиотеку «minimalmodbus», но не могу получить показания. Буду признателен, если поможете мне, где я делаю не так. Прошу прощения, если этот вопрос покажется глупым, поскольку это мой первый опыт связи по RS485.
Схема подключения
https://docs.google.com/document/d/1P_T ... 1PTz5cvIc/ edit?usp=sharing
[Модули и Датчики]
Преобразователь RS485 в TTL - https://silicontechnolabs.in/products/r ... -converter
Преобразователь температуры и влажности Датчик Modbus SHT20 XY-MD02 - https://roboticsdna.in/product/temperat ... gn={campai gn}&adgroup={adgroup}&keyword=&matchtype=&gad_source=1&gclid=Cj0KCQiAvbm7BhC5ARISAFjwNHtxYcYTCSiO4Y6TK0oxffiWH1NYwVIijQOv5MmM6OdBevpQqZE3KG4aAu0PEALw_wcB
и
Raspberry pi 5 — ОС Dibian
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

Мой код –
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)

Вывод-
pi@raspberrypi:~ $ sudo python3 sensor.py
No response from the sensor. Check connections and settings.
No response from the sensor. Check connections and settings.


Подробнее здесь: https://stackoverflow.com/questions/793 ... ta-using-m
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»