cbalint13 / tinnymodbus

RS485 ModBus tiny multi-sensor module
Other
99 stars 31 forks source link

Can't read sensors #11

Closed Fux2 closed 8 months ago

Fux2 commented 3 years ago

Hello, I built up two of the tinnymodbus. Flashing over modbus works fine. I can also read out the internal voltage (0x03 0x0003), the internal temperature is too high. I tested with a DS18S20 and a I2C SHT21 sensor. Both can't be read.

When using the Python script "sensors-1w-read.py" the readout works once (beside of wrong sensor values) and the Attiny hangs up afterwards and power has to be removed and connected again for further working. I tried also an older firmware - same results. How can I debug the readout of the sensors or do you have any suggestions? Any help is appreciated.

$ python3.8 ./sensors-i2c-read.py 
0x03 0x0000
0  running mode

0x03 0x0001
0.01  software version 

0x03 0x0002
1  slave address

0x03 0x0003
4.989590167999268  V (internal)

0x03 0x0004
39.000003814697266  C (internal)

0x04 0x1200
-46.849998474121094  C (sht21)

0x04 0x1201
-6.0  % (sht21)

0x04 0x1210
0.0  lux VI (si1145)

0x04 0x1211
0.0  lux IR (si1145)

0x04 0x1212
0.00 UV index (si1145)

0x04 0x1220
 0.000000 VI lux (bh1750)

0x04 0x1230
 0.00 C (bmp280)

0x04 0x1231
 0.00 hPa (bmp280)

0x04 0x1240
No BME280 found.
The shown values are at each readout identical:
0x04 0x1200
-46.849998474121094  C (sht21)
0x04 0x1201
-6.0  % (sht21)
// first execution
$ python3.8 ./sensors-1w-read.py 
0x03 0x0000
0  running mode

0x03 0x0001
0.01  software version 

0x03 0x0002
1  slave address

0x03 0x0003
4.989590167999268  Volt (internal)

0x03 0x0004
39.000003814697266  Celsius (internal)

0x04 0x0000
32  maximum devices 

0x04 0x0001
Traceback (most recent call last):
  File "./sensors-1w-read.py", line 124, in <module>
    decoder = BinaryPayloadDecoder.fromRegisters(result.registers, byteorder=Endian.Big, wordorder=Endian.Big)
AttributeError: 'ModbusIOException' object has no attribute 'registers'

// second execution immediately after first --> Attiny hanged up
$ python3.8 ./sensors-1w-read.py 
0x03 0x0000
Traceback (most recent call last):
  File "./sensors-1w-read.py", line 80, in <module>
    decoder = BinaryPayloadDecoder.fromRegisters(result.registers, byteorder=Endian.Big, wordorder=Endian.Big)
AttributeError: 'ModbusIOException' object has no attribute 'registers'
cbalint13 commented 3 years ago

@Fux2 ,

Most common mistakes:

The only way to further debug is to attach a signal analyser, since signals are slow a low end debugger is fine. I can recommend to look into sigrok backend & pulseview GUI supported ones.

no-ahnu commented 8 months ago

Unfortunately I cannot read any data from the BME280. The following is output on the BMP280: 0x04 0x1230 0.00 C (bmp280) 0x04 0x1231 0.00 hPa (bmp280)

The BME280 says “No BME280 found”.

To test I changed the address of BMP280 to 76 ( here ). My Raspberry displayed this address on I2C.

Now the measured values from the BMP280 are correct, but the BME280 still says "No BME280 found".

0x04 0x1230 21.29C (bmp280) 0x04 0x1231 1012.02 hPa (bmp280)

0x04 0x1240 No BME280 found.

Do you have a tip for me? Thanks

cbalint13 commented 8 months ago

@no-ahnu ,

Did you enable -DBME280 flag (and may remove -DBMP280) in the make.sh script ? https://github.com/cbalint13/tinnymodbus/blob/024dad54e0ae67c3fa570620e4a8934f21528c19/make.sh#L21

no-ahnu commented 8 months ago

Hello cbalint13 and thank you for the quick answer. I think the project is very great.

I changed the line in Make.sh. DEVS_ENABLE="-DDS18B20 -DBME280"

0x04 0x1230 No BMP280 found.

0x04 0x1240 11018751.18C (bme280)

0x04 0x1241 11490358.07 hPa (bme280)

0x04 0x1242 11118287.26 %RH (bme280)

The BME280 now delivers values, but unfortunately the wrong ones.

cbalint13 commented 8 months ago

Hello cbalint13 and thank you for the quick answer. I think the project is very great.

I changed the line in Make.sh. DEVS_ENABLE="-DDS18B20 -DBME280"

0x04 0x1230 No BMP280 found.

0x04 0x1240 11018751.18C (bme280)

0x04 0x1241 11490358.07 hPa (bme280)

0x04 0x1242 11118287.26 %RH (bme280)

The BME280 now delivers values, but unfortunately the wrong ones.

I don't own/use bme280 variant , since it is untested by me i left this as a experimental driver.

@stif , do you have ideas what might be wrong with these bad values ?

no-ahnu commented 8 months ago

thanks for the tip. I activated the "-DCALIBRATION", unfortunately no success:

user@rtu:~/tinnymodbus/tools$ sudo python3 examples/pymodbus3.x/sensors-read2.py 0x03 0x0000 0 running mode

0x03 0x0001 0.06 software version

0x03 0x0002 1 slave address

0x03 0x0003 5.166972637176514V (internal)

0x03 0x0004 38.7674446105957 C (internal)

1-wire 0x04 0x0001 2 devices found id: 0 0x04 0x0100 28b0315704f53ceb id: 0 0x04 0x0200 22.75 Celsius

id: 1 0x04 0x0101 289e3581e37c3c79 id: 1 0x04 0x0201 22.5 Celsius

i2c 0x04 0x1240 11018698.75C (bme280) 0x04 0x1241 11490341.68 hPa (bme280) 0x04 0x1242 11118287.26 %RH (bme280)

I hope for an answer from stif

cbalint13 commented 8 months ago

thanks for the tip. I activated the "-DCALIBRATION", unfortunately no success:

i2c 0x04 0x1240 11018698.75C (bme280) 0x04 0x1241 11490341.68 hPa (bme280) 0x04 0x1242 11118287.26 %RH (bme280)

I hope for an answer from stif

no-ahnu commented 8 months ago

Here I first have to understand what I should do. But I will definitely try it. Thanks for the tip!

cbalint13 commented 8 months ago

Here I first have to understand what I should do. But I will definitely try it. Thanks for the tip!

@no-ahnu ,

I just pushed this commit upstream, you can update your local copy now with git pull & recompile it.

Some notes:

Let me know about the outcome of results on your side.

no-ahnu commented 8 months ago

I just saw that you have already made the changes to main.c. Then I no longer have to think about what needs to be adjusted. I have now downloaded the new main.c and created a new main.hex with DEVS_ENABLE="-DDS18B20 -DBME280" in make.sh.

Flashed this and here is the output.

user@rtu:~/tinnymodbus/tools$ sudo python3 examples/pymodbus3.x/sensors-read2.py 0x03 0x0000 0 running mode

0x03 0x0001 0.06 software version

0x03 0x0002 1 slave address

0x03 0x0003 5.119999885559082 V (internal)

0x03 0x0004 38.7674446105957 C (internal)

1-wire 0x04 0x0001 2 devices found id: 0 0x04 0x0100 28b0315704f53ceb id: 0 0x04 0x0200 22.9375 Celsius

id: 1 0x04 0x0101 289e3581e37c3c79 id: 1 0x04 0x0201 22.5625 Celsius

i2c 0x04 0x1240 21.81C (bme280)

0x04 0x1241 1011.56 hPa (bme280)

0x04 0x1242 49.29%RH (bme280)

That looks really GREAT. THANKS!!!

cbalint13 commented 8 months ago

@no-ahnu

i2c 0x04 0x1240 21.81C (bme280)

0x04 0x1241 1011.56 hPa (bme280)

0x04 0x1242 49.29%RH (bme280)

That looks really GREAT. THANKS!!!

Thank you too for the time and patience !