Community
OpenEnergyMonitor

OpenEnergyMonitor Community

Ds18b20 and emonTX3CM firmware

Is it possible to adjust the precision of any ds18b20 sensors attached to the emonTX using the CM firmware? Is there any reason just to be a whole number by default?

I cannot see where the precision is set in the sketch.

[edit]
This has moved on to a more fundamental problem connecting a temperature sensor.

[edit2] TL;DR some DS18B20 sensors are better than others. If it is not, found wire to terminal 2 (permanently powered). If then found and the second to last number set of the address is a ‘3’ then they are probably poor sensors.

Try Line 211 of the sketch.

There it sets 11 bits (actually a waste of time because emonLibCM defaults to an 11-bit value, which equates to ⅛ °C, except when the reporting interval is such that there is not the time to wait while the sensor converts the reading). Therefore, the documentation states: “temperature reporting is not reliable with a datalogging period of less than 1 s, and not permitted with a datalogging period of less than 0.2 s.”
See EmonLibCM_setTemperatureResolution(byte _resolution)
which also tells you that the resolution is set back to 9 bits (½ °C) when the datalogging period is less than 1 s.

@Robert.Wall, if it is set to 11 bits, why is it only reporting whole numbers?

My example sketch doesn’t, nor does the version of Trystan’s that I have.

I have now downloaded V1.7 of the sketch, complied and loaded it, and my emonGLCD running the “debugging” sketch shows bytes 30 & 31 of the RF packet as 0xB1, 0x08 (2212 = 22.12 °C, bytes 32 & 33 as 0x08, 0x09 (2312 = 23.12 °C) and bytes 34 & 35 as 0x30, 0x75 (30000 = absent sensor).

Using the on-line calibration to turn off the radio and enable serial output, I see:

RF off

Continuing…
NO CT’s detected
Temperature Sensors found = 2 of 3, with addresses…
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

Temperature measurement is enabled.

AC missing
MSG:1,Vrms:3.25,T1:22.00,T2:22.00,pulse:1
MSG:2,Vrms:0.32,T1:22.00,T2:22.00,pulse:1
MSG:3,Vrms:0.36,T1:22.00,T2:23.37,pulse:1
MSG:4,Vrms:0.38,T1:21.87,T2:23.37,pulse:1

I cannot reproduce your problem.

Oh stupid me, I had not turned on the temperature logging (although a T1 does appear, with a temperature of 25 and then a temperature of 0) - actually, I think it is on by default so not so stupid.

Note this is a serial connected setup, not RF.

However, other issues…

So back to the start - sensor wired to terminal block as per Wiki, pin 3 GND, Pin5 Power & Pin 6 data. Sensor tested on an RPi so known good sensor.

This sensor is never recognised (it seems) by the emonTX.

Took me a while to work out that I needed the data to be flowing first (yes I know that is what it says - RTFM) and also that I needed to save it to go across a reset (obvious to folk that work with micro-controllers - not obvious to those that don’t).

To replicate (note Temp sensor is not initially attached) - restored sketch by clearing EEPROM, reset, disable RF, save, reset,

Erasing EEPROM...
Done. Sketch will now restart using default config.
emonTx V3.4 EmonLibCM Continuous Monitoring V1.60
OpenEnergyMonitor.org
No EEPROM config
Settings:
Group 210, Node 15, Band 433 MHz

Calibration:
vCal = 268.97
i1Cal = 90.90
i1Lead = 4.20
i2Cal = 90.90
i2Lead = 4.20
i3Cal = 90.90
i3Lead = 4.20
i4Cal = 16.67
i4Lead = 6.00
datalog = 10.00
pulses = 1
pulse period = 100
temp_enable = 1
Temperature Sensors found = 0 of 1
Temperature measurement is NOT enabled.

RF whitened
RFM69CW only Node: 15 Freq: 433MHz Group: 210

POST.....wait 10s
'+++' then [Enter] for config mode
CT1 detected, i1Cal:90.90
AC present
emonTx V3.4 EmonLibCM Continuous Monitoring V1.60
OpenEnergyMonitor.org
No EEPROM config
Settings:
Group 210, Node 15, Band 433 MHz

Calibration:
vCal = 268.97
i1Cal = 90.90
i1Lead = 4.20
i2Cal = 90.90
i2Lead = 4.20
i3Cal = 90.90
i3Lead = 4.20
i4Cal = 16.67
i4Lead = 6.00
datalog = 10.00
pulses = 1
pulse period = 100
temp_enable = 1
Temperature Sensors found = 0 of 1
Temperature measurement is NOT enabled.

RF whitened
RFM69CW only Node: 15 Freq: 433MHz Group: 210

POST.....wait 10s
'+++' then [Enter] for config mode
Entering config mode...

help text deleted

RF off
Saving...
0F 01 D2 29 7C 86 43 CD CC B5 42 66 66 86 40 CD CC B5 42 66 66 86 40 CD CC B5 42 66 66 86 40 29 5C 85 41 00 00 C0 40 00 00 20 41 01 64 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Done. New config saved to EEPROM

Continuing...
CT1 detected, i1Cal:90.90
AC present
MSG:1,Vrms:246.94,P1:94,E1:0,pulse:1
MSG:2,Vrms:247.00,P1:97,E1:0,pulse:1

All good so far, a MSG without a T.

However - note temp_enable = 1, so I should be able to just connect a sensor.

Shutdown emonTX (not sure if I need to do this).

Connect sensor (as above).

Power emonTX (and Pi) wait for Pi to boot

$ tail -f /var/log/emonhub/emonhub.log
2020-06-01 09:23:30,263 DEBUG    SerialTx   81 NEW FRAME : MSG:83,Vrms:246.70,P1:89,E1:23,T1:0.00,pulse:1

So I am getting a ‘T’ value but it is Zero.

reset emonTX - no change.

Check via miniterm

emonTx V3.4 EmonLibCM Continuous Monitoring V1.60
OpenEnergyMonitor.org
Loaded EEPROM config
Settings:
Group 210, Node 15, Band 433 MHz

Calibration:
vCal = 268.97
i1Cal = 90.90
i1Lead = 4.20
i2Cal = 90.90
i2Lead = 4.20
i3Cal = 90.90
i3Lead = 4.20
i4Cal = 16.67
i4Lead = 6.00
datalog = 10.00
pulses = 1
pulse period = 100
temp_enable = 1
Temperature Sensors found = 0 of 1
Temperature measurement is NOT enabled.

RF off
POST.....wait 10s

It would seem the sensor is not recognised - thoughts @Robert.Wall, @TrystanLea?

I’ve thrown away my V1.6 of Trystan’s sketch. However, I’ve made a small change to the way emonLibCM handles the array of temperature sensor addresses, and I’m still working on that area. So it’s probably not worth spending too much time on chasing something that’s soon going to be 2 versions behind.

You see

Temperature Sensors found = 0 of 1
Temperature measurement is NOT enabled.

because at that point, even though the default is enabled, temperature sensing is not yet enabled.
If you are not using the sensor address array pre-loaded with addresses (i.e., you set the array address with keep true when you call EmonLibCM_setTemperatureAddresses(...), a sensor must be attached at the time when the temperatures are enabled.
If the address of your sensor is stored, then a missing sensor reports 304 °C.

Ignore that. This is the latest sketch plus the latest CM library.

If it doesn’t work, that needs to be flagged and might affect shop shipped units @Gwil, @TrystanLea.

That’s most interesting - indeed, most weird. The version I downloaded and tested - post no. 5 - has on line 20 in the comment near the top

v1.7: Check radio channel is clear before transmit

And a little lower down

const byte version = 17;

So has V1.7 been replaced by a V1.6 again? My V1.7 was downloaded some tens of minutes before I posted at 21:33 BST on 31st May

Guilty as charged, I think I must have downloaded it from Master before the release (which is why it should use a release tag) but ho hum, hasn’t changed the fact the temp sensor doesn’t work.

emonTx V3.4 EmonLibCM Continuous Monitoring V1.70
OpenEnergyMonitor.org
Loaded EEPROM config
Settings:
Group 210, Node 15, Band 433 MHz

Calibration:
vCal = 268.97
i1Cal = 90.90
i1Lead = 4.20
i2Cal = 90.90
i2Lead = 4.20
i3Cal = 90.90
i3Lead = 4.20
i4Cal = 16.67
i4Lead = 6.00
datalog = 10.00
pulses = 1
pulse period = 100
temp_enable = 1
Temperature Sensors found = 0 of 1
Temperature measurement is NOT enabled.

RF off
POST.....wait 10s
'+++' then [Enter] for config mode
CT1 detected, i1Cal:90.90
AC present
MSG:1,Vrms:248.96,P1:92,E1:0,T1:25.00,pulse:1
MSG:2,Vrms:249.00,P1:90,E1:0,T1:0.00,pulse:1

Libraries in use:

Dependency Graph
|-- <EmonLibCM> 2.3.0 #8d0539c [git+https://github.com/openenergymonitor/EmonLibCM.git] (/opt/openenergymonitor/EmonTxV3CM/.pio/libdeps/emontx_pi/EmonLibCM)
|   |-- <DallasTemperature> 3.7.7 (/opt/openenergymonitor/EmonTxV3CM/.pio/libdeps/emontx_pi/DallasTemperature_ID54)
|   |   |-- <OneWire> 2.3.5 (/opt/openenergymonitor/EmonTxV3CM/.pio/libdeps/emontx_pi/OneWire_ID1)
|   |-- <OneWire> 2.3.5 (/opt/openenergymonitor/EmonTxV3CM/.pio/libdeps/emontx_pi/OneWire_ID1)
|   |-- <SPI> 1.0 (/home/pi/.platformio/packages/framework-arduino-avr/libraries/SPI)
|   |-- <Wire> 1.0 (/home/pi/.platformio/packages/framework-arduino-avr/libraries/Wire)
|-- <EEPROM> 2.0 (/home/pi/.platformio/packages/framework-arduino-avr/libraries/EEPROM)
|-- <OneWire> 2.3.5 (/opt/openenergymonitor/EmonTxV3CM/.pio/libdeps/emontx_pi/OneWire_ID1)
|-- <SPI> 1.0 (/home/pi/.platformio/packages/framework-arduino-avr/libraries/SPI)
|-- <Wire> 1.0 (/home/pi/.platformio/packages/framework-arduino-avr/libraries/Wire)

I don’t think there’s anything wrong with the library.

Temperature measurement is enabled, and the sensors detected, after this user interaction is completed. So at the instant when this

is printed, it knows that one sensor can be expected (the default maximum, that can be changed by the sketch), but the 1-wire bus has not been searched and temperature measurements have not been enabled, therefore no sensors have been found and measurements are not enabled.

If you wish, you can take advantage of the option to include the sensor address in the sketch, which means that it has no need to search for sensors - moreover their positions in the list of sensors are fixed, and won’t move if a sensor is physically removed or fails to respond to the address search.

OK, I’ve thrown away my emonLibCM library that I was working on and compiled the V1.7 sketch with this emonLibCM: “Version 2.03 25/10/2019”. As far as I am concerned, that is the current release.

Here’s what I get, starting from power-up:

emonTx V3.4 EmonLibCM Continuous Monitoring V1.70
OpenEnergyMonitor.org
No EEPROM config
Settings:
Group 210, Node 15, Band 868 MHz

Calibration:
vCal = 268.97
i1Cal = 90.90
i1Lead = 4.20
i2Cal = 90.90
i2Lead = 4.20
i3Cal = 90.90
i3Lead = 4.20
i4Cal = 16.67
i4Lead = 6.00
datalog = 9.96
pulses = 1
pulse period = 100
temp_enable = 1
Temperature Sensors found = 0 of 1
Temperature measurement is NOT enabled.

RF on
RFM69CW only Node: 15 Freq: 868MHz Group: 210
 
POST.....wait 10s
'+++' then [Enter] for config mode
NO CT's detected
AC missing 
emonTx V3.4 EmonLibCM Continuous Monitoring V1.70
OpenEnergyMonitor.org
No EEPROM config
Settings:
Group 210, Node 15, Band 868 MHz

Calibration:
vCal = 268.97
i1Cal = 90.90
i1Lead = 4.20
i2Cal = 90.90
i2Lead = 4.20
i3Cal = 90.90
i3Lead = 4.20
i4Cal = 16.67
i4Lead = 6.00
datalog = 9.96
pulses = 1
pulse period = 100
temp_enable = 1
Temperature Sensors found = 0 of 1
Temperature measurement is NOT enabled.

RF on
RFM69CW only Node: 15 Freq: 868MHz Group: 210
 
POST.....wait 10s
'+++' then [Enter] for config mode
Entering config mode...

Available commands for config during start-up:
  b<n>      - set r.f. band n = a single numeral: 4 = 433MHz, 8 = 868MHz, 9 = 915MHz (may require hardware change)
  g<nnn>    - set Network Group  nnn - an integer (OEM default = 210)
  i<nn>     - set node ID i= an integer (standard node ids are 1..30)
  r         - restore sketch defaults
  s         - save config to EEPROM
  v         - show firmware version
  w<x>      - turn RFM Wireless data on or off:
            - x = 0 for OFF, x = 1 for ON, x = 2 for ON with whitening
  x         - exit and continue
  ?         - show this text again

Available commands only when running:
  k<x> <yy.y> <zz.z>
            - Calibrate an analogue input channel:
            - x = a single numeral: 0 = voltage calibration, 1 = ct1 calibration, 2 = ct2 calibration, etc
            - yy.y = a floating point number for the voltage/current calibration constant
            - zz.z = a floating point number for the phase calibration for this c.t. (z is not needed, or ignored if supplied, when x = 0)
            -  e.g. k0 256.8
            -       k1 90.9 2.00
  l         - list the config values
  m<x> <yy> - meter pulse counting:
               x = 0 for OFF, x = 1 for ON, <yy> = an integer for the pulse minimum period in ms. (y is not needed, or ignored when x = 0)
  p<xx.x>   - xx.x = a floating point number for the datalogging period
  s         - save config to EEPROM
  t0 <y>    - turn temperature measurement on or off:
            - y = 0 for OFF, y = 1 for ON
  t<x> <yy> <yy> <yy> <yy> <yy> <yy> <yy> <yy>
            - change a temperature sensor's address or position:
            - x = a single numeral: the position of the sensor in the list (1-based)
            - yy = 8 hexadecimal bytes representing the sensor's address
               e.g.  28 81 43 31 07 00 00 D9
               N.B. Sensors CANNOT be added.
  ?         - show this text again
Erasing EEPROM...
Done. Sketch will now restart using default config.
emonTx V3.4 EmonLibCM Continuous Monitoring V1.70
OpenEnergyMonitor.org
No EEPROM config
Settings:
Group 210, Node 15, Band 868 MHz

Calibration:
vCal = 268.97
i1Cal = 90.90
i1Lead = 4.20
i2Cal = 90.90
i2Lead = 4.20
i3Cal = 90.90
i3Lead = 4.20
i4Cal = 16.67
i4Lead = 6.00
datalog = 9.96
pulses = 1
pulse period = 100
temp_enable = 1
Temperature Sensors found = 0 of 1
Temperature measurement is NOT enabled.

RF on
RFM69CW only Node: 15 Freq: 868MHz Group: 210

<<< I wasn’t quick enough with “+++” - had to physically reset >>>

POST.....wait 10s
'+++' then [Enter] for config mode
NO CT's detected
Settings:
Group 210, Node 15, Band 868 MHz

Calibration:
vCal = 268.97
i1Cal = 90.90
i1Lead = 4.20
i2Cal = 90.90
i2Lead = 4.20
i3Cal = 90.90
i3Lead = 4.20
i4Cal = 16.67
i4Lead = 6.00
datalog = 9.96
pulses = 1
pulse period = 100
temp_enable = 1
Temperature Sensors found = 2 of 3, with addresses...
28 81 43 31 7 0 0 D9 
28 8D A5 C7 5 0 0 D5 

Temperature measurement is enabled.

RF on
AC missing 
emonTx V3.4 EmonLibCM Continuous Monitoring V1.70
OpenEnergyMonitor.org
No EEPROM config
Settings:
Group 210, Node 15, Band 868 MHz

Calibration:
vCal = 268.97
i1Cal = 90.90
i1Lead = 4.20
i2Cal = 90.90
i2Lead = 4.20
i3Cal = 90.90
i3Lead = 4.20
i4Cal = 16.67
i4Lead = 6.00
datalog = 9.96
pulses = 1
pulse period = 100
temp_enable = 1
Temperature Sensors found = 0 of 1
Temperature measurement is NOT enabled.

RF on
RFM69CW only Node: 15 Freq: 868MHz Group: 210
 
POST.....wait 10s
'+++' then [Enter] for config mode
Entering config mode...

Available commands for config during start-up:
  b<n>      - set r.f. band n = a single numeral: 4 = 433MHz, 8 = 868MHz, 9 = 915MHz (may require hardware change)
  g<nnn>    - set Network Group  nnn - an integer (OEM default = 210)
  i<nn>     - set node ID i= an integer (standard node ids are 1..30)
  r         - restore sketch defaults
  s         - save config to EEPROM
  v         - show firmware version
  w<x>      - turn RFM Wireless data on or off:
            - x = 0 for OFF, x = 1 for ON, x = 2 for ON with whitening
  x         - exit and continue
  ?         - show this text again

Available commands only when running:
  k<x> <yy.y> <zz.z>
            - Calibrate an analogue input channel:
            - x = a single numeral: 0 = voltage calibration, 1 = ct1 calibration, 2 = ct2 calibration, etc
            - yy.y = a floating point number for the voltage/current calibration constant
            - zz.z = a floating point number for the phase calibration for this c.t. (z is not needed, or ignored if supplied, when x = 0)
            -  e.g. k0 256.8
            -       k1 90.9 2.00
  l         - list the config values
  m<x> <yy> - meter pulse counting:
               x = 0 for OFF, x = 1 for ON, <yy> = an integer for the pulse minimum period in ms. (y is not needed, or ignored when x = 0)
  p<xx.x>   - xx.x = a floating point number for the datalogging period
  s         - save config to EEPROM
  t0 <y>    - turn temperature measurement on or off:
            - y = 0 for OFF, y = 1 for ON
  t<x> <yy> <yy> <yy> <yy> <yy> <yy> <yy> <yy>
            - change a temperature sensor's address or position:
            - x = a single numeral: the position of the sensor in the list (1-based)
            - yy = 8 hexadecimal bytes representing the sensor's address
               e.g.  28 81 43 31 07 00 00 D9
               N.B. Sensors CANNOT be added.
  ?         - show this text again
RF off

Continuing...
NO CT's detected
AC missing 
MSG:1,Vrms:3.24,T1:22.62,T2:22.12,pulse:0
MSG:2,Vrms:0.43,T1:22.62,T2:22.12,pulse:0
MSG:3,Vrms:0.43,T1:22.62,T2:22.12,pulse:0
MSG:4,Vrms:0.42,T1:22.62,T2:22.12,pulse:0

Powering down the emonTx, then restarting with no interaction, I see

OpenEnergyMonitor.org
No EEPROM config
Settings:
Group 210, Node 15, Band 868 MHz

Calibration:
vCal = 268.97
i1Cal = 90.90
i1Lead = 4.20
i2Cal = 90.90
i2Lead = 4.20
i3Cal = 90.90
i3Lead = 4.20
i4Cal = 16.67
i4Lead = 6.00
datalog = 9.96
pulses = 1
pulse period = 100
temp_enable = 1
Temperature Sensors found = 0 of 1
Temperature measurement is NOT enabled.

RF on
RFM69CW only Node: 15 Freq: 868MHz Group: 210
 
POST.....wait 10s
'+++' then [Enter] for config mode
NO CT's detected
AC missing 

and then nothing (as expected). But my trusty emonGLCD and debugging sketch shows two temperatures being measured and reported by radio:

DSCN1661.s

Sorry, I don’t understand what you are telling me.

I’d like the sketch to automatically find any sensors connected - is it not supposed to do that? Do I need to enter the config screen to do that? I thought it should find them automatically?

My query is also why it seems to know I have attached a sensor (as it returns a T pair), but no value.

Is the sketch working properly or not?

All I know is that I’ve tried to recreate your problem, and can’t. So the temperature measurement part of it seems to be working properly for me.

Yes it is, and it did it for me, but as I wrote

“option” means you have the choice: either you let it search for sensors, or you hard code the addresses into the sketch.

Are you actually trying to say that it was wrong to integrate temperature sensing into the library? The implications of that are two: as the documentation notes, you must not try to include temperature measurement into the sketch in the ways that it’s been done previously, and as temperature measurement is set up at the same time as the library is started, that means - as I’ve tried to explain three times already - details of the presence and number of sensors is not available at the point where the user - you - is seeing and setting the configuration options.

Temperature measurements had to be incorporated into the library because, due to the timing requirements of the One-wire bus, that’s the only way it would work. Which seemed to be a pretty good reason for doing it that way.

Of course not!!!

Are you sensors connected to the terminal block?

Could it be power? I am powering the RPi from the 5V as well?

One is, one is plugged in via the RJ45.

And where is the 5 V coming from?

Tried the old DS sketch (pr-ecompiled) - no change.

I was powering the EmonTX & Pi off the emonTX 5V - tried it with a better PS and no change.

Disconnected the power to the Pi from the TX and powered the Pi separately - no change.

Next re-enable the RF, disconnect the Pi and see what happens.

Then wire a different sensor direct (I’ve wired in a header and I am connecting to that) and remove the jumper inside.

That must mean an external 5 V USB supply?

You do have the correct power pin for the One-wire bus, specified in the sketch?

Expand. I just wired it as per the emonTX Wiki.

To limit self-heating of the sensors, emonLibCM turns the power on just before a reading is requested, and off just after the result has been retrieved. If the wrong pin is specified in the sketch, i.e. the default has been overridden with a wrong value, then the sensors connected via the terminal strip won’t be powered. This applies only to the screw terminals, the RJ45 socket is permanently powered.