To bring closure to my initial question on this thread, and what I have learnt along the way,… ie EmonTx reporting Strange Voltages…
My thanks to Robert and Trystan for their help and patience.
I have now as noted above installed new firmware to my emonTx4. using the Emontx4_DB_12CT_serial code as a base. Which can easily be used on the 6CT version if required, But note this has no radio function, as I use a direct USB-C connection to power and communicate with my EmonPi.
And following Robert advice, I have modified the ‘reported voltage’, in the main code, rather than the library cpp file, so anything less than 15volts is reported as a Zero voltage.
I installed the new HEX code from a compiled output HEX file, I created a UNIX virtual machine running 1.8.4 Arduino code, ( which run a complies perfectly,… just follow those instructions ).
-rw-r--r-- 1 pi pi 37536 Apr 20 17:17 EmonTx4.hex
Name is arbitrary, just as long as they match etc.
Using Roberts script as a bases,… I would execute an scp command to remote copy the file over to the emonPi. to the ‘compiled’ directory.
Stop the emonhub service as follows:-
sudo systemctl stop emonhub.service
them with the emonhub service not running,… AND making sure I was NOT using or viewing any serial comms on the emonPi,… ( as this would take control of the serial link and prevent serial comms update comminications ), sitting at the feeds display is fine.
then executing the following, NOTE: make sure to use correct USB port for EmonTx4, and NOT any other interface board, Modify ttyUSBX to suit your needs:-
avrdude -C/opt/openenergymonitor/EmonScripts/update/avrdude.conf -v -pavr128db48 -carduino -D -P/dev/ttyUSBX -b115200 -Uflash:w:EmonTx4.hex:i
which produced the following output as it updates the firmware
avrdude-original: Version 6.3-20171130
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "/opt/openenergymonitor/EmonScripts/update/avrdude.conf"
User configuration file is "/root/.avrduderc"
User configuration file does not exist or is not a regular file, skipping
Using Port : /dev/ttyUSB0
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude-original: Using autoreset DTR on GPIO Pin 7
avrdude-original: Using autoreset DTR on GPIO Pin 7
AVR Part : AVR128DB48
Chip Erase delay : 0 us
PAGEL : P00
BS2 : P00
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 0
StabDelay : 0
CmdexeDelay : 0
SyncLoops : 0
ByteDelay : 0
PollIndex : 0
PollValue : 0x00
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
prodsig 0 0 0 0 no 125 125 0 0 0 0x00 0x00
fuses 0 0 0 0 no 9 16 0 0 0 0x00 0x00
fuse0 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse1 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse2 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse4 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse5 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse6 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse7 0 0 0 0 no 1 0 0 0 0 0x00 0x00
fuse8 0 0 0 0 no 1 0 0 0 0 0x00 0x00
lock 0 0 0 0 no 4 1 0 0 0 0x00 0x00
data 0 0 0 0 no 0 0 0 0 0 0x00 0x00
flash 0 0 0 0 no 131072 512 0 0 0 0x00 0x00
eeprom 0 0 0 0 no 512 32 0 0 0 0x00 0x00
Programmer Type : Arduino
Description : Arduino
Hardware Version: 3
Firmware Version: 25.1
Vtarget : 0.3 V
Varef : 0.3 V
Oscillator : 28.800 kHz
SCK period : 3.3 us
avrdude-original: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude-original: Device signature = 0x1e970c (probably avr128db48)
avrdude-original: reading input file "EmonTx4.hex"
avrdude-original: writing flash (13842 bytes):
Writing | ################################################## | 100% 2.03s
avrdude-original: 13842 bytes of flash written
avrdude-original: verifying flash memory against EmonTx4.hex:
avrdude-original: load data flash data from input file EmonTx4.hex:
avrdude-original: input file EmonTx4.hex contains 13842 bytes
avrdude-original: reading on-chip flash data:
Reading | ################################################## | 100% 1.35s
avrdude-original: verifying ...
avrdude-original: 13842 bytes of flash verified
avrdude-original: safemode: Fuses OK (E:FF, H:FF, L:FF)
avrdude-original: Using autoreset DTR on GPIO Pin 7
avrdude-original done. Thank you.
then we need to restart the emonhub service,
sudo systemctl start emonhub.service
I did find a full power reset was required to sort things out again,… but system is now back up and running,… with the following modified base code,… use at one own risk.
// EmonTx4_DB_12CT_WiFi
// This default example prints 1 voltage and 12 power values to the serial port
// this is then either picked up by an EmonESP 8266 WiFi module or can be used
// for direct USB link to a emonBase/emonPi via emonHub.
#define Serial Serial3
#include <Arduino.h>
#include "emonLibDB.h"
#define EMONTX4 // Must be above "#include <RFM69_LPL.h>
#define DATALOG 9.8
#define EXPANSION_BOARD // Can be commented out for 6 CT only
const uint8_t LEDpin = PIN_PB2; // emonTx V4 LED
uint32_t counter = 0;
double VRMS_test; // variable added to allow for voltage test prior to printing
void setup()
{
pinMode(LEDpin, OUTPUT);
delay(10);
digitalWrite(LEDpin, HIGH);
Serial.begin(9600);
Serial.println("Set baud=115200");
Serial.end();
Serial.begin(115200);
Serial.println("\nEmonTx4_DB_12CT_WIFI");
/****************************************************************************
* *
Set the properties of the physical sensors
* *
****************************************************************************/
EmonLibDB_set_vInput(1, 100.0, 0.16); // emonVS Input channel 1, voltage calibration 100, phase error 0.16°
// EmonLibDB_set_vInput(2, 100.0, 0.16); // emonVS Input channel 2, voltage calibration 100, phase error 0.16°
// EmonLibDB_set_vInput(3, 100.0, 0.16); // emonVS Input channel 3, voltage calibration 100, phase error 0.16°
// (All 3 may be set, even if those inputs are unused)
EmonLibDB_set_cInput(1, 100.0, 0.3); // emonTx4 Current/power Input channel 1, 0.3° phase error for 100 A CT
// Main Porperty Supply
EmonLibDB_set_cInput(2, 50.0, 0.3); // emonTx4 Current/power Input channel 2, 0.3° phase error for 50 A CT
// Car Charger
EmonLibDB_set_cInput(3, 50.0, 0.3); // emonTx4 Current/power Input channel 3, 0.3° phase error for 20 A CT
// Salon
EmonLibDB_set_cInput(4, 20.0, 0.3); // (likewise for current/power Inputs 4 - 12)
// Cooker Ring
EmonLibDB_set_cInput(5, 20.0, 0.3); // Mains Ring 1
EmonLibDB_set_cInput(6, 20.0, 0.3); // Lighting Ring 1
// Second Line of CT inputs
EmonLibDB_set_cInput(7, 50.0, 0.3); // Extended Spare 1
EmonLibDB_set_cInput(8, 50.0, 0.3); // Extended Spare 2
EmonLibDB_set_cInput(9, 20.0, 0.3); // Lighting Ring 2
EmonLibDB_set_cInput(10, 20.0, 0.3); // Mains Ring 2
EmonLibDB_set_cInput(11, 20.0, 0.3);
EmonLibDB_set_cInput(12, 20.0, 0.3);
/****************************************************************************
* *
Link voltage and current sensors to define the power
& energy measurements
* *
For best precision and performance, include only the following lines
that apply to current/power inputs being used.
****************************************************************************/
EmonLibDB_set_pInput(1, 1); // CT1, V1
EmonLibDB_set_pInput(2, 1); // CT2, V2 (etc)
EmonLibDB_set_pInput(3, 1);
EmonLibDB_set_pInput(4, 1);
EmonLibDB_set_pInput(5, 1);
EmonLibDB_set_pInput(6, 1);
EmonLibDB_set_pInput(7, 1); // CT7, V1
EmonLibDB_set_pInput(8, 1); // CT8, V1
EmonLibDB_set_pInput(9, 1); // CT9, V1 (etc)
EmonLibDB_set_pInput(10, 1);
EmonLibDB_set_pInput(11, 1);
EmonLibDB_set_pInput(12, 1);
/* How to measure Line-Line loads: */
/*
EmonLibDB_set_pInput(3, 1, 2); // CT1 between V1 & V2
EmonLibDB_set_pInput(2, 2, 3); // CT2 between V2 & V3
EmonLibDB_set_pInput(3, 3, 1); // CT2 between V3 & V1 (etc)
EmonLibDB_set_pInput(4, 1, 2);
EmonLibDB_set_pInput(5, 2, 3);
EmonLibDB_set_pInput(6, 3, 1);
EmonLibDB_set_pInput(7, 1, 2);
EmonLibDB_set_pInput(8, 2, 3);
EmonLibDB_set_pInput(9, 3, 1);
EmonLibDB_set_pInput(10, 1, 2);
EmonLibDB_set_pInput(11, 2, 3);
EmonLibDB_set_pInput(12, 3, 1);
*/
/*
Pulse counting on any channel is only available if the appropriate solder link is made on the hardware,
and the related "TMP" link is broken.
*/
EmonLibDB_setPulseEnable(true); // Enable counting on the "Pulse" input
EmonLibDB_setPulseMinPeriod(20); // Contact bounce must not last longer than 20 ms
// EmonLibDB_setPulseEnable(Dig, true); // Enable counting on the "Pulse" input
// EmonLibDB_setPulseMinPeriod(Dig, 20); // Contact bounce must not last longer than 20 ms
EmonLibDB_datalogPeriod(DATALOG); // Report every 9.8 s (approx)
Serial.print("Starting ");
EmonLibDB_Init(); // Start continuous monitoring.
Serial.print("reports every ");
Serial.print(EmonLibDB_getDatalogPeriod());
Serial.println(" seconds approx");
for (int i = 0; i <= 20; i++) {
digitalWrite(LEDpin, HIGH);
delay(200);
digitalWrite(LEDpin, LOW);
}
}
void loop()
{
static uint32_t counter = 0;
if (EmonLibDB_Ready())
{
counter++;
Serial.print("MSG:"); Serial.print(counter);
// if mains input voltage is less than 15volts,.. it will be assumed to be zero
VRMS_test = EmonLibDB_getVrms(1);
if ( VRMS_test < 15 ) {
VRMS_test = 0;
}
// Serial.print(",Vrms:"); Serial.print(EmonLibDB_getVrms(1));
Serial.print(",Vrms:"); Serial.print(VRMS_test);
// Uncomment for further phases as required
// Serial.print(",V2:"); Serial.print(EmonLibDB_getVrms(2));
// Serial.print(",V3:"); Serial.print(EmonLibDB_getVrms(3));
// Serial.print(",FR:"); Serial.print(EmonLibDB_getLineFrequency());
#ifndef EXPANSION_BOARD
for (uint8_t ch = 1; ch <= 6; ch++)
#else
for (uint8_t ch = 1; ch <= 12; ch++)
#endif
{
Serial.print(",P"); Serial.print(ch); Serial.print(":"); Serial.print(EmonLibDB_getRealPower(ch));
// Uncomment for energy values
Serial.print(",E"); Serial.print(ch); Serial.print(":"); Serial.println(EmonLibDB_getWattHour(ch));
}
Serial.println();
// Now flash LED to show setup complete
digitalWrite(LEDpin, HIGH);
delay(200);
digitalWrite(LEDpin, LOW);
}
}
So now,… if I have a power cut,… my reported voltage is zero,… And as the system powers up and completes the ‘setup()’ function, the LED flashes 20 times.
And every time data is sent the LED flashes as well, which gives a warm feeling the system is active.