read multiple 1-wire sensors from emonTx terminal

Hi, I've got two 1-wire sensors (DS18B20) connect to the emonTx v3 terminal block.

When I run tail -f /var/log/emonhub/emonhub.log I get the readings from only one sensor.

How can I read from multiple sensors connected to the terminal block?

Alex

glyn.hudson's picture

Re: read multiple 1-wire sensors from emonTx terminal

The latest firmware now includes auto detecting and reading from up to 5 temperature sensors. You can compile and upload from Arduino IDE using USB to UART cable 

https://github.com/openenergymonitor/emonTxFirmware/blob/master/emonTxV3...

Be sure to set the flag on the first line of the sketch to set what rf module your using. Probably rfm12b. 

alex88's picture

Re: read multiple 1-wire sensors from emonTx terminal

Hi, I uploaded that sketch with the flag set to rfm12b and the emonTx v3 stopped working. So I uploaded this sketch https://github.com/openenergymonitor/emonTxFirmware/blob/master/emonTxV3/RFM12B/emonTxV3_RFM12B_DiscreteSampling/emonTxV3_RFM12B_DiscreteSampling.ino and it works but it's still only reading one sensor.

 

Robert Wall's picture

Re: read multiple 1-wire sensors from emonTx terminal

What sort of emonTx V3 do you have? Is it a V3.2 with the RFM12B radio module surface-mounted on a RFμ328 module that is surface-mounted on the main PCB, or is it a V3.4 with a RJ45 connector?

I'm almost certain it's V3.2, but I'll wait for you to confirm that.

alex88's picture

Re: read multiple 1-wire sensors from emonTx terminal

It's V3.2.1 Feb 2014 with the rfm12b radio module surface-mounted on a RFμ328 module.

Robert Wall's picture

Re: read multiple 1-wire sensors from emonTx terminal

OK, the sketch Glyn pointed you at is for the V3.4. What you'll need to change:

The library: #include <JeeLib.h> becomes #include <RFu_JeeLib.h>

The radio module: #define RF69_COMPAT 0 -- always

Delete all references to the DIP Switches & Battery_voltage, and the code that goes with them

The Pulse input Dig 3 / IRQ 1 becomes Dig 2 / IRQ 0

I think that's all.

alex88's picture

Re: read multiple 1-wire sensors from emonTx terminal

Ok so I

Added the include <JeeLib.h>

set RF69_Compat to 0

commented out the DIP Switches & battery code

set pulse input to 2 !?

and the emonTx turns on but doesn't send anything and at one stage started blinking real fast.

I've atteched the modified sketch

Robert Wall's picture

Re: read multiple 1-wire sensors from emonTx terminal

You missed the "gotcha" that I missed for a while:

if (DS18B20_STATUS==0) attachInterrupt(1, onPulse, FALLING);

The 1 becomes a zero. It was a bit naughty of Glyn to use parameterised constants in most but not all of the places. I also changed emontx.pulseCount++; inside the ISR to get around a potential problem with timing. I'll attach my sketch, but I need to swap browsers to do it.

[After I wrote the post a few days ago, I 'back-converted' the sketch, and now I've attached it. It's untested from the temperature measurements angle as I don't have a spare DS18B20, let alone several. It recorded anything up to many tens of pulses when I dabbed a bit of wire onto the pulse input, so that aspect seems to work.]

[Edit: incorporated dBC's change - thanks for pointing that out]

[Edit 2: incorporated Glyn's change below.
emonTx V3.2 RFM12B DiscreteSampling sketch]

dBC's picture

Re: read multiple 1-wire sensors from emonTx terminal

I also changed emontx.pulseCount++; inside the ISR to get around a potential problem with timing.

I fear there's still a race condition there.


if (pulseCount)  
{
 emontx.pulseCount += pulseCount;
 pulseCount = 0;
}

If an interrupt occurs between those last two lines, you'll lose that pulse.   If you check the generated code you'll see there are a full six instructions between it reading pulseCount for the addition, and it eventually clearing it. The fix is pretty simple though:

if (pulseCount)
{
 cli();
 emontx.pulseCount += pulseCount;
 pulseCount = 0;
 sei();
}
glyn.hudson's picture

Re: read multiple 1-wire sensors from emonTx terminal

@dBC This has now been fixed, thanks: https://github.com/openenergymonitor/emonTxFirmware/blob/master/emonTxV3/RFM69CW/emonTxV3_RFM69CW_DiscreteSampling/emonTxV3_RFM69CW_DiscreteSampling.ino#L436

Robert Wall's picture

Re: read multiple 1-wire sensors from emonTx terminal

Er, no. But the attachment to my post above has been fixed.
http://openenergymonitor.org/emon/sites/default/files/emonTxV3_RFM12B_Di...

alex88's picture

Re: read multiple 1-wire sensors from emonTx terminal

This sketch works but only with some and not with others. I have like 10 ds18b20 temp sensors and I can only get reading from 3 of them the others always read 850 (raw data). They read 850 on their own or in any combination. However I know they all work fine if I connect them to my desktop.

Any ideas of what could be causing a constant 850 output on most of my sensors.

I am using them in parasite mode.

I've just tested the sensors with the same sketch which only allows for 1 connection on the terminal and the sensors that give 850 on the new sketch  work fine on it.

alex

 

Robert Wall's picture

Re: read multiple 1-wire sensors from emonTx terminal

Is "850" the temperature × 10 as printed to serial, i.e. 85°C? If so, that's the 'power-on' value of temperature and indicates that the device is not reading and converting the temperature.

It may be that 10 sensors are pulling the voltage on the bus down too far if they all do their thing at the same time - which they do. Page 5 of the data sheet gives some information. I think this is the likeliest given what you report. What is the topology of your wiring, the cable type & lengths?

alex88's picture

Re: read multiple 1-wire sensors from emonTx terminal

I get 850 (85 deg) even if I plug the one sensor straight into the terminal block using short wires.

But then if, without changing anything, I upload an older sketch to the tx, the same sensor connected the same way would work fine.

 

 

glyn.hudson's picture

Re: read multiple 1-wire sensors from emonTx terminal

Hi Alex,

That's strange. Try increasing the value of #define ASYNC_DELAY 375, there have been reports of a value of 750 working better for multiple sensors. 

By default the emonTx V3 is limited to maximum of 6 sensors. Make sure you are powering the emonTx via USB DC rather than AC-AC adapter when using so many sensors. 

You can also try increasing the sleepy delay on line 336 from 50ms to a higher value. 

https://github.com/openenergymonitor/emonTxFirmware/blob/master/emonTxV3...

​Let me know what your findings are. I could add code to disable sleep and increase delays when reading from many sensors as battery power is not practical. 

alex88's picture

Re: read multiple 1-wire sensors from emonTx terminal

Hi Glyn,

I just ran a test and found a way to make the sensors work.  I am using two sketch images:

sketch1:

https://github.com/openenergymonitor/emonTxFirmware/blob/master/emonTxV3...

sketch2:

http://openenergymonitor.org/emon/sites/default/files/emonTxV3_RFM12B_Di...

So first I connect one temperature sensor directly to the emonTx terminal block (ground and 1-wire data) where ground and power are tied together on the sensor.

I run the tx with sketch 2 on it and verify that the output is a constant 85 degrees.

then without unplugging or touching anything I upload sketch 1 and sensor will start working fine. Next I reload sketch 2 and now the sensor continues to work fine.  Sensor fixed?

I've tried these steps with 3  sensors and now the 3 work.

But I've no idea of what going on here!!

 

 

 

Robert Wall's picture

Re: read multiple 1-wire sensors from emonTx terminal

What you're doing there is maintaining the power to the sensor while moving from one sketch to the other?
That makes me think that Sketch 2 is not getting the address of the sensor correctly, or not initialising it correctly. To confirm this, can you get the address using the test sketch, then get Sketch 2 to display what it thinks is the address of the same sensor?

alex88's picture

Re: read multiple 1-wire sensors from emonTx terminal

Hi Robert,

I agree, I think you're on the right track there. Yes, I didn't remove the power and now I have all the sensors working except for one which I kept for testing purposes. The fix seems permanent so it might be an initialising issue as you pointed there.

I'll try to output what sketch 2 sees first .... I don't want to run a script that would fix the sensor. So as to be able to keep replicating the problem

Robert Wall's picture

Re: read multiple 1-wire sensors from emonTx terminal

"I have all the sensors working"

Is that working as in responding with what looks like a sensible temperature, or responding as in reporting accurately (after a bit of delay of course) changes in temperature?

alex88's picture

Re: read multiple 1-wire sensors from emonTx terminal

I think they look like sesilble temperature measurements in around the 22 degrees + or - 1 from eachother ... and they respond well if I blow on them or sink them in water. 

I don't know how to get the arduino to report on the address it sees but I'll look into that now.

glyn.hudson's picture

Re: read multiple 1-wire sensors from emonTx terminal

Ah! I think I've found the bug. The issue was in the new code the resolution of the sensor is not set every time after the sensors are powered up. Only once at startup. When the sensors are powered down in between readings they loose their resolution setting causing them to default back to 12 bit resolution. This then causes in issue since the async delay for the temperature conversion is only long enough to allow for 11 bit conversion (the emonTx / emonTH default). 

This has now been fixed. Resolution of each sensor is set every time they are read. Please try this new sketch now: 

https://github.com/openenergymonitor/emonTxFirmware/blob/master/emonTxV3/RFM69CW/emonTxV3_RFM69CW_DiscreteSampling/emonTxV3_RFM69CW_DiscreteSampling.ino

 

If reading from many sensors I would not recommend using sensors in parasitic power mode  or connection the 'pwr' pin from the sensors to digital 11 to enable powering does the sensors in between readings. I would recommend connecting DS18B20' 'pwr' pin to 5V terminal block / RJ45, GND to GND and data pin to Dig 5

alex88's picture

Re: read multiple 1-wire sensors from emonTx terminal

That did it, great!

I added the lines to set the resolution to the sketch that I was using (see attached) (since I have an emonTx V3.2 with an RFM12B) and it worked. I then changed the max to 11 and I got the 11 sensors working fine.

I'm aiming at getting about 20 DS18B20s connected to the tx so I will be connecting them non parasite mode next, thanks for pointing that out Glyn.

Thanks to everyone who helped me sort this out. Much appreciated.

Cheers,

Alex

 

glyn.hudson's picture

Re: read multiple 1-wire sensors from emonTx terminal

I would recommend you use the latest sketch I linked to above. The only change required for use with RFM12B is change flag to 0 at beginning of the sketch

Robert Wall's picture

Re: read multiple 1-wire sensors from emonTx terminal

Glyn, he needs RFu_JeeLib and to change the interrupt no. and pins etc as he's using a V3.2 with the RFμ328.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.