multiple ds18b20 emontx v3

I want to messure temp from 5 diffrent sensor. 

I can get one sensor temp.

I can also connect 5sensor and i se that the serial monitor see that 5 i connected.

 

But i can not get them printet to emoncms or in serial monitor with any temperatur. I just get temø from one sensor.

Anyone that can give me a hint og an example sketch for sensing and sending more than one ds18b20 sensor?

 

Robert Wall's picture

Re: multiple ds18b20 emontx v3

A quick look at the default sketch for the emonTx V3 tells me that it will send only one temperature. You must change the sketch so that it sends all 5 temperatures.

What to change:

In

typedef struct { int power1, power2, power3, power4, Vrms, temp; } PayloadTX;
  PayloadTX emontx;

add the extra temperatures  ... Vrms, temp0, temp1, temp2, temp3, temp4; }

In the conditional   if (DS18B20_STATUS==1) { .... }  where it reads the temperature sensor, you must do this 5 times:

float temp0=(sensors.getTempC(allAddress[0]));
float temp1=(sensors.getTempC(allAddress[1]));
float temp2=(sensors.getTempC(allAddress[2]));
float temp3=(sensors.getTempC(allAddress[3]));
float temp4=(sensors.getTempC(allAddress[4]));

then convert the temperatures 5 times and put them into the struct

if ((temp0<125.0) && (temp0>-40.0)) emontx.temp0=(temp0*10);  
if ((temp1<125.0) && (temp1>-40.0)) emontx.temp1=(temp1*10);
if ((temp2<125.0) && (temp2>-40.0)) emontx.temp2=(temp2*10);
if ((temp3<125.0) && (temp3>-40.0)) emontx.temp3=(temp3*10);
if ((tem4p<125.0) && (temp4>-40.0)) emontx.temp4=(temp4*10);

This is not the best way to do it but the simplest to explain, and it should work - I don't have 5 sensors to test with!

roedfjel's picture

Re: multiple ds18b20 emontx v3

tnx robert.

 

I tested your guide and it works ok with 4 sensor. but with 5sensor connected the debug serial output that its find 5 ds18b20 but only give me messurements on 4 sensor. the last one is 0in temp.

 

Is there anyting that wrong in this sketch that does not give me the last reading on the sensor.

 

the sketch i attached.

Robert Wall's picture

Re: multiple ds18b20 emontx v3

Ah! I missed this bit - sorry:

int numSensors;
//addresses of sensors, MAX 4!! 
byte allAddress [4][8];  // 8 bytes per address

That appears to be an artificial limit, the library indicates it is good to 64 devices on the same bus. I suggest you increase the array to 5 x 8.

But it may be a good idea to check the free memory - for that you need the "MemoryFree" library.

roedfjel's picture

Re: multiple ds18b20 emontx v3

tnx again for  the help Robert.

I had allready change that array, but the fault was that the serial console did not come  with any signal on that sensor. but the emoncms gets it :).

 

As you maybe know im not good in this but learning. tnx again for a good tips and guides.
im now searching info about that memoryfree and how to get that work. 

Robert Wall's picture

Re: multiple ds18b20 emontx v3

I cannot see a good reason why the serial monitor did not show the last temperature, unless it was low on memory. You could save some memory by doing this:

if (debug==1)
{
     Serial.print("temperature1: "); Serial.println(emontx.temp*0.1);
     Serial.print("temperature2: "); Serial.println(emontx.temp1*0.1);
     Serial.print("temperature3: "); Serial.println(emontx.temp2*0.1);
     Serial.print("temperature4: "); Serial.println(emontx.temp3*0.1);
     Serial.print("temperature5: "); Serial.println(emontx.temp4*0.1);
     delay(100);
}

You might also save some memory by using an array instead of 5 separate variables for the temperature, and then process them in loops:

typedef struct { int power1, power2, power3, power4, Vrms, temp[5]; } PayloadTX;

...

float temp[5];
for(int j=0; j<5; j++)
     temp[j] = sensors.getTempC(allAddress[j]);
digitalWrite(DS18B20_PWR, LOW);
for(int j=0; j<5; j++)
{
       //if reading is within range for the sensor convert float to int ready to send via RF
     if ((temp[j]<125.0) && (temp[j]>-40.0)) emontx.temp[j]=(temp[j]*10);           
     if (debug==1) 
     {
           Serial.print("temperature"); Serial.print(j+1); Serial.print(": "); 
           Serial.println(emontx.temp[j]*0.1); delay(20);
     }
}

 

Comment viewing options

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