Integrate EMONLIB to ESP

886 views
Skip to first unread message

Domenico Carvetta

unread,
Oct 25, 2015, 10:56:41 AM10/25/15
to souliss
Hi Juan,
I tried to run T57 into a ESP sketch using the Emonlib.h library, unsuccessfully.
I got a lot of compilation errors.
Question is: what is the status of the integration of Emonlib library to ESP? I know, by your wiki page, that the other option is read the CT with an Arduino and send the data to the ESP.



Domenico Carvetta

unread,
Oct 25, 2015, 12:26:37 PM10/25/15
to souliss
Is there someone able to explain what is the meaning for this compilation errors????
If I remove the Emonlib.h from the sketch, the errors disappered!




c
:/users/carvetta/appdata/roaming/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib\libm.a(lib_a-w_sqrt.o):(.literal+0x8): undefined reference to `__ieee754_sqrt'
c:/users/carvetta/appdata/roaming/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib\libm.a(lib_a-w_sqrt.o): In function `
sqrt':
d:\ivan\projects\arduinoesp\toolchain\dl\esp-newlib\build\xtensa-lx106-elf\newlib\libm\math/../../../../../newlib/libm/math/w_sqrt.c:63: undefined reference to `__ieee754_sqrt'

collect2
.exe: error: ld returned 1 exit status

Juan Pinto

unread,
Oct 25, 2015, 3:07:57 PM10/25/15
to souliss
Overwrite the file attached on this path:

C:\Users\carvetta\AppData\Roaming\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\lib

Related to this issues:

Regards
libm.a

Domenico Carvetta

unread,
Oct 25, 2015, 3:34:06 PM10/25/15
to souliss
Dear Juan,
thanks. What about integration of Emonlib library to ESP ?
Have you any input for me ?



Juan Pinto

unread,
Oct 25, 2015, 3:49:27 PM10/25/15
to sou...@googlegroups.com
Not yet, I opened a post on ESP forum, but for now I have emonlib working on arduino connected to a ESP for communications, here the post with some hints on the last page:

Regards

--
You received this message because you are subscribed to a topic in the Google Groups "souliss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/souliss/fYII0H9RXOE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/souliss/c40f9076-7038-4006-882c-59409d733494%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Domenico Carvetta

unread,
Oct 25, 2015, 3:51:19 PM10/25/15
to souliss
ok, thanks !!

Domenico Carvetta

unread,
Oct 26, 2015, 7:46:45 AM10/26/15
to souliss
HI Dario,
one question about the ADC pin on the ESP8266.

In order to read external voltage applied to ADC pin, do I need to "declare" "A0" or "A1", or am I wrong ?
  emon1.current(0, 29.01);                  // Current: ADC input pin, calibration (1800/62ohm)
 
I found that to read external voltage applied to ADC pin, we have to use analogRead(A0).
Can you double confirm me ? Thanks!!


Di Maio, Dario

unread,
Oct 26, 2015, 7:58:20 AM10/26/15
to sou...@googlegroups.com
I don't know much about.

Dario.

--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+u...@googlegroups.com.

To post to this group, send email to sou...@googlegroups.com.

Domenico Carvetta

unread,
Oct 26, 2015, 1:52:18 PM10/26/15
to souliss
Hi Juan, back to you :-)

I am trying to upload the sketch "E06_ATTINY_EMONLIB.ino" into a ATtiny85.
First compilation error, should be that SoftwareSerial support only 20,16 and 8Mhz processors.
Did you use to upload using ATtiny85 @8Mhz internal oscillator, BOD disabled core ?

Thanks !!

Juan Pinto

unread,
Oct 26, 2015, 2:08:21 PM10/26/15
to sou...@googlegroups.com
You can do with an Arduino and I think will be more easy to get it working for you :P
 
I used an attiny85 without external clock and runing at 8mhz with internal oscillator.
 
Regards

--
You received this message because you are subscribed to a topic in the Google Groups "souliss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/souliss/fYII0H9RXOE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to souliss+u...@googlegroups.com.

To post to this group, send email to sou...@googlegroups.com.

Domenico Carvetta

unread,
Oct 26, 2015, 2:11:41 PM10/26/15
to souliss
Yes, you are right; I will use first a Arduino :-)

BTW, can you send me the SoftwareSerial.h library you used to upload the attiny85 without external clock and running at 8mhz with internal oscillator ?
I want to double check where is the problem , thanks.

Domenico Carvetta

unread,
Oct 26, 2015, 2:15:58 PM10/26/15
to souliss
Can I run this code for a Arduino-UNO or need I change something, Juan ?

#include <SoftwareSerial.h>
#include "EmonLib.h"             // Include Emon Library
EnergyMonitor emon1;             // Create an instance




SoftwareSerial TinySerial(3, 4); // RX, TX
#define LED 1
#define CT  A1




void setup()  
{
 
// Open serial communications and let us know we are connected
 
TinySerial.begin(9600);  // SET TO 1200 ON RECEIVER, I DONT KNOW WHY
 pinMode
(LED, OUTPUT);
 emon1
.current(CT, 10);       // Current: input pin, calibration.
}




void loop()
{
 
float current = emon1.calcIrms(1480);
 
TinySerial.print(current);
  delay
(100);
  digitalWrite
(LED,!digitalRead(LED));
}

Juan Pinto

unread,
Oct 26, 2015, 2:22:14 PM10/26/15
to sou...@googlegroups.com
Yes, you can use it, but take care where the pins are defined, (example: pin1 on Arduino is TX so change the led to the pin 13)
 
And you don't need to use SoftwareSerial on Arduino, you can use standard Serial, but this is an option.
 
Regards

--
You received this message because you are subscribed to a topic in the Google Groups "souliss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/souliss/fYII0H9RXOE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.

Domenico Carvetta

unread,
Oct 26, 2015, 2:29:27 PM10/26/15
to souliss
So that the new code for Arduino-Uno looks like, can you double confirm me just to make sure, Juan?


//#include <SoftwareSerial.h>



#include "EmonLib.h"             // Include Emon Library
EnergyMonitor emon1;             // Create an instance




//SoftwareSerial TinySerial(3, 4); // RX, TX


#define LED 13

#define CT  A1




void setup()  
{
 
// Open serial communications

 
Serial.begin(9600);  
 pinMode
(LED, OUTPUT);

 emon1
.current(CT, 10);       // Current: input pin, calibration.
}




void loop()
{
 
float current = emon1.calcIrms(1480);

 
Serial.print(current);
  delay
(100);
  digitalWrite
(LED,!digitalRead(LED));
}

Juan Pinto

unread,
Oct 26, 2015, 2:39:48 PM10/26/15
to sou...@googlegroups.com
It's ok
 
Regards.

--
You received this message because you are subscribed to a topic in the Google Groups "souliss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/souliss/fYII0H9RXOE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.

domenico carvetta

unread,
Oct 26, 2015, 2:45:03 PM10/26/15
to sou...@googlegroups.com
Last question, I apologize ....

And from the E06_ESP_EMONLIB.ino sketch side, I found as follows line 20, but I didn't understand the meaning.
I know that I must connect directly Arduino-Uno Pin1 (TX) to ESP (RX pin), right Juan or am I wrong?

#define Debug Serial1 //Change to Serial1 if you want to use the GPIO2 to TX

Juan Pinto

unread,
Oct 26, 2015, 3:14:43 PM10/26/15
to sou...@googlegroups.com
Yes, you'll connect from Arduino TX to ESP RX, this is mandatory.
 
And if you want to use the GPIO2 on ESP to see the debug you will use Serial1 instead Serial.
 
Regards

--
You received this message because you are subscribed to a topic in the Google Groups "souliss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/souliss/fYII0H9RXOE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.

Domenico Carvetta

unread,
Oct 31, 2015, 9:47:45 AM10/31/15
to souliss
Hi Juan,
finally I was able to run correctly the T57 for power meter.
I used, as you suggested, a Arduino-Uno, where the TX pin is connected directly to ESP RX.
I didn't used any resistors to match the 5V from the Arduino to the 3.3v for the ESP.
I attached a pictures for your reference.

Next step has been to use a Arduino-Nano in order to minimize the dimensions.
But, although, I used exactly the same configuration, it didn't work and the readings for the T56 and T57 have been nAnn and nWnn.
Do you have any ideas ?
Thanks !!
Screenshot_2015-10-31-12-23-35.png

Juan Pinto

unread,
Nov 2, 2015, 10:59:54 AM11/2/15
to souliss
It's strange, both Arduino Uno and nano are virtually the same :S
 
Regards

domenico carvetta

unread,
Nov 2, 2015, 11:12:49 AM11/2/15
to sou...@googlegroups.com
My opinion is the same; it looks like a bit strange.
I tried to compare both schematics Arduino_uno vs. Arduino-Nano and I found none differences.
BTW, using Arduino-nano it doesn't work.


Juan Pinto

unread,
Nov 2, 2015, 11:16:36 AM11/2/15
to sou...@googlegroups.com
You use this example to use the arduino as an usart node.
 
Regards

--
You received this message because you are subscribed to a topic in the Google Groups "souliss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/souliss/fYII0H9RXOE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.

Domenico Carvetta

unread,
Nov 2, 2015, 11:55:44 AM11/2/15
to souliss
I used a your sketch to connect the Arduino-Uno (TX) to the ESP (RX). Am I wrong, perphaps ?


#include "EmonLib.h"                   // Include Emon Library
EnergyMonitor emon1;                   // Create an instance

#define LED 13
#define CT  A1

void setup()  
{
 
// Open serial communications
 
Serial.begin(9600);  
 pinMode
(LED, OUTPUT);

 
//emon1.current(CT, 10);          // Current: input pin, calibration.
   emon1
.current(CT, 29.01);       // Current: input pin, calibration.

}




void loop()
{
   
float current = emon1.calcIrms(1480);

    current
= current - 0.04;            // valore di offset per la calibrazione
   
if (current < 0) current=0 ;                
   
 
Serial.println(current);
  delay
(1000);
  digitalWrite
(LED,!digitalRead(LED));
}

Juan Pinto

unread,
Nov 3, 2015, 12:40:07 PM11/3/15
to souliss
It's ok
 
Regards

Domenico Carvetta

unread,
Nov 12, 2015, 10:37:17 AM11/12/15
to souliss
Hi Juan,
can I disturb you again about this topic ?

I want to monitor, from power meter point of view, two different points into my home.  
So that, I have to handle two analog pins ie. A0 and A1 connected to different TA devices.

But I don't know how to assign A0 to the first T57 and A1 to the second T57 using a same serial connection from Arduino to ESP.
Or do I need a second Serial connection?

The original sketch is below:

Arduino sketch:
#include "EmonLib.h"                   // Include Emon Library
EnergyMonitor emon1;                   // Create an instance

#define LED 13
#define CT  A1

void setup()  
{
 
// Open serial communications
 
Serial.begin(9600);  
 pinMode
(LED, OUTPUT);

    emon1
.current(CT, 29.01);       // Current: input pin, calibration.
}

void loop()
{
   
float current = emon1.calcIrms(1480);
    current
= current - 0.04;            // valore di offset per la calibrazione
   
if (current < 0) current=0 ;                
   
 
Serial.println(current);
  delay
(1000);
  digitalWrite
(LED,!digitalRead(LED));
}

ESP8266 sketch:
     FAST_710ms()   {
           
float current = 0;
           
if(Serial.available()){
               
float current = Serial.parseFloat();
                           
               
Souliss_ImportAnalog(memory_map, CURRENT, &current);
               
float watt = current*230;
               
Souliss_ImportAnalog(memory_map, WATTS, &watt);
           
}
       
}

Juan Pinto

unread,
Nov 12, 2015, 11:04:59 AM11/12/15
to sou...@googlegroups.com
In this case I suggest you configure your Arduino as peer of  the ESP via USART.
 
Regards

--
You received this message because you are subscribed to a topic in the Google Groups "souliss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/souliss/fYII0H9RXOE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.

domenico carvetta

unread,
Nov 12, 2015, 11:08:44 AM11/12/15
to sou...@googlegroups.com
Good idea ! 
I had not thought of before, I will try and just in case ....I come back to You!


Julio Rosquete

unread,
Feb 14, 2016, 5:53:46 PM2/14/16
to souliss
Hi, i trying to place a power monitor in my system, but i get too many fluctuating reading on the souliss app, i am using a nano and a esp, does somebody know if i'got something wrong? thanks

arduino code

#include "EmonLib.h"                   // Include Emon Library 
EnergyMonitor emon1;                   // Create an instance 

#define LED 13
#define CT  A1

void setup()  
{
 // Open serial communications
 Serial.begin(9600);  
 pinMode(LED, OUTPUT);

 //emon1.current(CT, 10);          // Current: input pin, calibration.
   emon1.current(CT, 185.01);       // Current: input pin, calibration.

}




void loop()
{
    float current=0;
   for (int thisPin = 1; thisPin < 11; thisPin++) {
  current =(current + (emon1.calcIrms(1480)));
     }
   current=current/10;
    current = current - 0.04;            // valore di offset per la calibrazione
    if (current < 0.15) current=0.12 ;                
    
  Serial.println(current);
  delay(100);
  digitalWrite(LED,!digitalRead(LED));
}

 esp code

// Configure the framework
#include "bconf/MCU_ESP8266.h"              // Load the code directly on the ESP8266
//#include "conf/Gateway.h"                   // The main node is the Gateway, we have just one node
#include "conf/IPBroadcast.h"

// Define the WiFi name and password
#define WIFICONF_INSKETCH
#define WiFi_SSID               "villa_rosquete"
#define WiFi_Password           "1234567890"    

// Include framework code and libraries
#include <ESP8266WiFi.h>
#include <EEPROM.h>
#include "Souliss.h"

// This identify the number of the LED logic
#define CURRENT             0
#define WATTS               2
#define MYLEDLOGIC          4               
//#define MYLEDLOGIC1          5 

//#define Debug Serial        //Change to Serial1 if you want to use the GPIO2 to TX

 #define  OUTPUTPIN     2
// #define  OUTPUTPIN1     5
 
void setup()
{   
    Initialize();
   
    
    Serial.begin(9600); 
    //Debug.begin(115200);
    Serial.println("inicio");

    // Connect to the WiFi network and get an address from DHCP
    GetIPAddress();     
   // SetAsGateway(myvNet_dhcp);
    // This node will serve all the others in the network providing an address
    
    // This is the vNet address for this node, used to communicate with other
    // nodes in your Souliss network
    SetAddress(0xAB06, 0xFF00, 0xAB01);  // 
    //Example of Peer Definition
    //SetAsPeerNode(0xAB02, 1);
    
    Set_Current(CURRENT);
    Set_Power(WATTS);
    Set_SimpleLight(MYLEDLOGIC);        // Define a simple LED light logic

//  Set_SimpleLight(MYLEDLOGIC1);       
    pinMode(OUTPUTPIN, OUTPUT);         // Use pin as output 
    // pinMode(OUTPUTPIN1, OUTPUT);         // Use pin as output 
        //  pinMode(16, INPUT); 
}

void loop()
    
    EXECUTEFAST() {                     
        UPDATEFAST();   
        FAST_50ms() {   // We process the logic and relevant input and output every 50 milliseconds
            Logic_SimpleLight(MYLEDLOGIC);
            DigOut(OUTPUTPIN, Souliss_T1n_Coil,MYLEDLOGIC);
            //Logic_SimpleLight(MYLEDLOGIC1);
          //  DigOut(OUTPUTPIN1, Souliss_T1n_Coil,MYLEDLOGIC1);
          //  DigIn(16, Souliss_T1n_ToggleCmd,MYLEDLOGIC);
            //LowDigIn2State
            //DigIn2State(16, 0,0,MYLEDLOGIC);
        } 
        FAST_510ms()    {
           Logic_Current(CURRENT);
           Logic_Power(WATTS);
        }
        FAST_710ms()    {
           float current = 0;
           if(Serial.available()){
            DigOut(OUTPUTPIN, Souliss_T1n_ToggleCmd,MYLEDLOGIC);
               float current = Serial.parseFloat();
              // Debug.println(current);
               
               Souliss_ImportAnalog(memory_map, CURRENT, &current); 
               float watt = current*230; 
               Souliss_ImportAnalog(memory_map, WATTS, &watt);
           }
        }
        // Here we handle here the communication with Android
       FAST_PeerComms();                                       
    }
}    
As you see per screenshoots i got reading as 0A and others perfect at 0,12a cause i am using the clamp at a 60w bulb. another estrange behavior is the power in watts show infinite power ¿¿??? 
screenshot.jpg
screenshot (1).jpg

Domenico Carvetta

unread,
Feb 15, 2016, 4:51:55 AM2/15/16
to souliss
I don't know why, but it works fine!

Screenshot_2015-11-11-08-49-49.png

Domenico Carvetta

unread,
Feb 15, 2016, 4:54:05 AM2/15/16
to souliss
Screenshot_2015-10-28-11-35-24.png

Julio Rosquete

unread,
Feb 15, 2016, 1:57:52 PM2/15/16
to souliss
buongiorno Domenico, could you please post your files to check if i got something wrong, thanks

El lunes, 15 de febrero de 2016, 9:54:05 (UTC), Domenico Carvetta escribió:


Julio Rosquete

unread,
Feb 16, 2016, 7:58:14 AM2/16/16
to souliss
does somebody knows or have this circuit working to help me out?, thanks

Juan Pinto

unread,
Feb 16, 2016, 2:10:09 PM2/16/16
to sou...@googlegroups.com

--
You received this message because you are subscribed to a topic in the Google Groups "souliss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/souliss/fYII0H9RXOE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages