Solar PV power diversion with emonTx V3 using a PLL and temperature measurement

I have Martin's sketch up and running (with a few modifications to use different CT connections). However, I'm not getting a reading from my temperature sensor. My output looks like this:

514 511 510 239.41 811.56 4.36 0.00 49.99 0.00 0.00 PLL is locked

I have CT1 as my grid input (811.56), CT2 is my Solar PV (4.36). The voltage and frequency look fine, but I'm getting 0.00 for the temperature.

I know the sensor is working because the previous sketch (emonTxV3 Discrete Sampling) was displaying the temperature correctly. I changed the W1PIN define to 5 for the emonTx V3.

The pin changes I made are:

// Arduino I/O pin useage
#define VOLTSPIN 0
#define CT1PIN 2
#define CT2PIN 4
#define LEDPIN 6
//#define SYNCPIN 6 // this output will be a 50Hz square wave locked to the 50Hz input
//#define SAMPPIN 5 // this output goes high each time an ADC conversion starts or completes
#define RFMSELPIN 4
#define RFMIRQPIN 3
#define SDOPIN 12
#define W1PIN 5 // 1-Wire pin for temperature
#define TRIACPIN 2 // triac driver pin

Is there anything else I need to change in this sketch for the emonTX V3 ?

Thanks,

Allen

Robert Wall's picture

Re: Solar PV power diversion with emonTx V3 using a PLL and temperature measurement

Are you powering the temperature sensor with the output from DIO 19? If you are, have you turned that on? Remember, the emonTx V2 powered the temperature sensor all the time, and that is the version that Martin's code was written for.

(See in the default emonTx V3 sketch:

const byte DS18B20_PWR= 19;                              // DS18B20 Power

for a hint.)

AllenConquest's picture

Re: Solar PV power diversion with emonTx V3 using a PLL and temperature measurement

I had noticed the statements switching the power on in the emonTx V3 sketch, but having never had a V2 I didn't realise the difference.

However, I have tried putting the digitalWrite(DS18B20_PWR, HIGH) statement in the readTemperature() method of Martin's sketch, but I still get nothing back. So I now have (where I have defined DS18B20_PWR to be 19):

int readTemperature()
{
  byte buf[9];
  int result;
  digitalWrite(DS18B20_PWR, HIGH);
  oneWire.reset();
  oneWire.write(SKIP_ROM);
  oneWire.write(READ_SCRATCHPAD);
  for(int i=0; i<9; i++) buf[i]=oneWire.read();
  if(oneWire.crc8(buf,8)==buf[8])
  {
    result=(buf[1]<<8)|buf[0];
    // result is temperature x16, multiply by 6.25 to convert to temperature x100
    result=(result*6)+(result>>2);
  }
  else result=BAD_TEMPERATURE;
  digitalWrite(DS18B20_PWR, LOW);
  return result;
}

Can anyone help?

 

MartinR's picture

Re: Solar PV power diversion with emonTx V3 using a PLL and temperature measurement



 I used 2 functions to access the DS18B20 convertTemperature() starts the conversion and readTemperature() reads the result.

By turning the power off in readTemperature() you will have no power during the conversion process. Since you are using the PLL you presumably are running on mains power so there is no reason not to leave the DS18B20 power on all the time.

AllenConquest's picture

Re: Solar PV power diversion with emonTx V3 using a PLL and temperature measurement

I tried just switching it on in the setup(), but that didn't help. So I also added it to the convertTemperature() and readTermperature() method, but still no output.

void convertTemperature()
{
  oneWire.reset();
  digitalWrite(DS18B20_PWR, HIGH);
  oneWire.write(SKIP_ROM);
  oneWire.write(CONVERT_TEMPERATURE);
}

I tried the statement both before and after the oneWire.reset() call incase that was doing something. What was the reason for not using the DallasTemperature library?

MartinR's picture

Re: Solar PV power diversion with emonTx V3 using a PLL and temperature measurement

In the above the power will still be off for the oneWire reset command. Just turn the power on in setup() and remove all other references to DS18B20_PWR.

The Dallas library spends too much time waiting for things to happen so it can't be used with continuous monitoring.

AllenConquest's picture

Re: Solar PV power diversion with emonTx V3 using a PLL and temperature measurement

I solved the problem. I was forgetting the pinMode() command. So now these two lines are in my Setup() function and that is all.

pinMode(DS18B20_PWR, OUTPUT);
digitalWrite(DS18B20_PWR, HIGH);

AllenConquest's picture

Re: Solar PV power diversion with emonTx V3 using a PLL and temperature measurement

I now have one outstanding issue. I am driving an SSR to simplify the output stage, directly from the Dig2 (pin 4 on connector block) and GND (pin 3 on the connector block). This is giving me an switching voltage of around 3.3V, which hard switch the SSR. 

In fact it seems that there is a resistance between the output pins that varies depending on the switching voltage. If I use a 9V battery to switch the relay I get a lower output resistance that 3.3V.

Is there a way to use the 5V supply to switch the relay instead of the 3.3V ?

AllenConquest's picture

Re: Solar PV power diversion with emonTx V3 using a PLL and temperature measurement

I've hit a problem that I hope someone can help me with. My temperature sensor has suddenly started returning 300 Celsius. I can see from Martin's sketch that this is a default value when something is wrong. I'm not quiet able to understand what the oneWire code is doing and why this might be.

I loaded up the default emonTxV3 Discrete Sampling sketch and that is reporting the temperature correctly. So there is something in the code, but I don't know what.

Can anyone help?

Robert Wall's picture

Re: Solar PV power diversion with emonTx V3 using a PLL and temperature measurement

"So there is something in the code"  Not necessarily. It might also be a power supply issue - if the supply is dipping because you are drawing too much current from the 3.3 V rail, that could easily cause the DS18B20 to malfunction. The minimum supply voltage is only 3.0 V, so it doesn't have far to go. Does the DS18B20 work correctly with your code if you disconnect the SSR? If it does, I might be right, if not, I am probably wrong.

To understand the DS18B20 code, you need to study its data sheet. On page 10, the explanation starts with an overview and goes into increasing levels of detail, before giving examples on page 18.

AllenConquest's picture

Re: Solar PV power diversion with emonTx V3 using a PLL and temperature measurement

My setup has now been diverting to the hot water tank for a few days and it's looking good. I now have 2 temperature sensors connected (top and bottom of cylinder). 

Can anyone tell me where in Martin's sketch to put the logic to switch off diverting when a set temperature is reached?

Robert Wall's picture

Re: Solar PV power diversion with emonTx V3 using a PLL and temperature measurement

The actual comparison logic needs to be done infrequently, so immediately after you've got the temperature is a good place for that - set a logical flag and use that every cycle to determine whether to block setting the triac trigger.

Lines 328 or 331 look to be promising candidates, depending on whether you want to allow the manual triggering or not. "divertFlag" is used eventually to calculate the power diverted, so you need to make sure that is dealt with correctly too. I can't see any other traps that might catch you out.

 

Comment viewing options

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