ADE7758
ADE7758 copied to clipboard
schematic ade7758
Thank you for sharing... where can ı find any schematic or wiring about ade7758 for using with arduino ?
Hi I think this code is outdated. I will recheck and push the new codes later. I will also check the pinnings.
Hey, i´m working on a project using the ADE7758 and an Arduino UNO. I tried your code but it won´t work properly... Did you worked further on this project? If yes, can you share your new code and a schematic maybe.
Thank you!
Yes I have worked further on it but I was not able to push it because I forgot. I'll look for it next week.
On Thu, Jan 8, 2015 at 9:47 PM, EnergyChris [email protected] wrote:
Hey, i´m working on a project using the ADE7758 and an Arduino UNO. I tried your code but it won´t work properly... Did you worked further on this project? If yes, can you share your new code and a schematic maybe.
Thank you!
— Reply to this email directly or view it on GitHub https://github.com/engkan2kit/ADE7758/issues/1#issuecomment-69180627.
Hey,
thank you for your soon reply.
I´m looking intent for your updated code :)
Kind regards!
I pushed newer codes. However, these were from March 2014. I am not sure if this works for you directly, you might need to modify something and to solve the scaling of voltages and current. Read the Readme for further info. I will be working on this again in the near future.
On Wed, Jan 14, 2015 at 9:10 PM, EnergyChris [email protected] wrote:
Hey,
thank you for your soon reply.
I´m looking intent for your updated code :)
Kind regards!
— Reply to this email directly or view it on GitHub https://github.com/engkan2kit/ADE7758/issues/1#issuecomment-69913559.
Hi, Can you please share your code for arduino UNO?
I´m looking intent for your updated code too.
thanks very much!
Hi, I am trying to measure voltage and current with an arduino uno, but i can´t get it to work right. First i notice that the pins for the SPI bus are different, apparently they are defined for an arduino mega in your code. Is that correct?
Thanks a lot!
Sorry about the source codes. They got mixed-up with my other versions of this library. I initially used the SPI library but later converted it to use software SPI because my project needed the hardware SPI for a more sensitive communication and changing modes added delays.
Hi, I am trying with arduino uno to. ¿Someone could do it? I have the other question. ¿Can the ADE7758 measure DC (direct corrent)?
Thanks you
This was tested before with arduino Uno and Mega. I don't think it can measure DC correctly. if you want DC power correctly. But if you are handling DC, you can just use voltage divider and use the ADC of your arduino for the voltage and use a sense resistor for the current.
Thank you for your answer. I don't understand my situation but I have this problem (see the image) (unknown command) When I push some letter (a, b, c, d) the same thing happens.
(copy and paste for see the image) https://www.dropbox.com/s/gn680q5mrt4azhb/problema.JPG?dl=0 Do you know why?
Thank you
Can you post your code? Especially the switch/case part.
Hi, I'm trying to metering the AC and the temperature but no run. this is the code (is the same like your code)
ADE7758: ` #include "Arduino.h" #include <SPI.h> #include "ADE7758Lib.h"
char inputChar; // a string to hold incoming data boolean rx = false; // whether the string is complete ADE7758 myADE(&SPI,3); void setup() { Serial.begin(9600);
myADE.begin(); Serial.println("ADE7758 begins operating"); delay(1000); }
void loop() {
if (rx) { switch(inputChar){
//////////////////////////
case 't':
Serial.println("Temperature: ");
for(int k=0; k<=9; k++) //I don't know wihs is the Bit Location for temperature
{
Serial.println(myADE.getTemperature(k),HEX);
}
/////////////////////////
case 'a':
Serial.println("ENERGY readings for each phase:");
Serial.println(myADE.getWattHR(PHASE_A), HEX);
Serial.println(myADE.getWattHR(PHASE_B), HEX);
Serial.println(myADE.getWattHR(PHASE_C), HEX);
break;
case 'b':
Serial.println("CURRENT RMS readings for each phase:");
Serial.println(myADE.IRMS(PHASE_A), HEX);
Serial.println(myADE.IRMS(PHASE_B), HEX);
Serial.println(myADE.IRMS(PHASE_C), HEX);
break;
case 'c':
Serial.println("VOLTAGE RMS readings for each phase:");
Serial.println(myADE.VRMS(PHASE_A), HEX);
Serial.println(myADE.VRMS(PHASE_B), HEX);
Serial.println(myADE.VRMS(PHASE_C), HEX);
break;
case 'd':
Serial.println("Complex Energy readings for each phase:");
Serial.println(myADE.getVAHR(PHASE_A), HEX);
Serial.println(myADE.getVAHR(PHASE_B), HEX);
Serial.println(myADE.getVAHR(PHASE_C), HEX);
break;
default:
Serial.println("unknown command");
}
rx = false;
} }
void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); rx = true; } } `
ADE7758Lib.cpp
` #include <SPI.h> #include "ADE7758Lib.h" #include <avr/wdt.h>
extern void isrGDO0event(void); SPISettings ADESETTINGS(125000, MSBFIRST, SPI_MODE1); //public ADE7758::ADE7758(SPIClass *ADESPI, int SSpin) { _ADE7758SPI=ADESPI; _SSpin=SSpin; digitalWrite(_SSpin, HIGH); //Ensure Chip select pin is output pinMode(_SSpin, OUTPUT);
}
void ADE7758::begin() { //normal mode //write8bits(OPMODE, 0x44); //spi_setup(); //write8bits(OPMODE, 0x05); }
////////////////////////////////// int ADE7758::getTemperature(char phase) { return read8bits(TEMP+phase); } //////////////////////////////////
int ADE7758::getWattHR(char phase) { return read16bits(AWATTHR+phase); }
int ADE7758::getVARHR(char phase) { return read16bits(AVARHR+phase); }
int ADE7758::getVAHR(char phase) { return read16bits(AVAHR+phase); }
long ADE7758::VRMS(char phase) { char i=0; long volts=0; getVRMS(phase);//Ignore first reading for(i=0;i<10;++i){ volts+=getVRMS(phase); delayMicroseconds(50); } //average return volts/10; }
long ADE7758::IRMS(char phase) { char i=0; long current=0; getIRMS(phase);//Ignore first reading for(i=0;i<10;++i){ current+=getIRMS(phase); delayMicroseconds(50); } //average return current/10; }
void accumulateEnergy() {
}
long ADE7758::waveform(char phase,char source) {
}
void ADE7758::powerOff() {
}
void ADE7758::powerON() {
}
void ADE7758::sleep() {
}
void ADE7758::wakeUp() {
}
long ADE7758::getInterruptStatus(void){ return read24bits(STATUS); }
long ADE7758::getResetInterruptStatus(void){ return read24bits(RSTATUS); }
int ADE7758::lineFreq(char phase){ uint8_t mmode; mmode = read8bits(MMODE); write8bits(MMODE,(mmode&0x11111100 )| phase); delay(10); return read16bits(FREQ); } //private
void ADE7758::enableChip() {
digitalWrite(_SSpin, LOW);
}
void ADE7758::disableChip() { digitalWrite(_SSpin, HIGH); }
void ADE7758::write8bits(char reg, unsigned char data) { _ADE7758SPI->beginTransaction(ADESETTINGS); enableChip();
delay(10); _ADE7758SPI->transfer(REG_WRITE(reg)); delay(2);
_ADE7758SPI->transfer(data);
delay(1);
disableChip(); _ADE7758SPI->endTransaction(); }
void ADE7758::write16bits(char reg, unsigned int data) { _ADE7758SPI->beginTransaction(ADESETTINGS); enableChip();
delay(10); _ADE7758SPI->transfer(REG_WRITE(reg)); delay(2); _ADE7758SPI->transfer((unsigned char)((data>>8)&0xFF)); delay(2); _ADE7758SPI->transfer((unsigned char)(data&0xFF)); delay(1);
disableChip(); _ADE7758SPI->endTransaction(); }
unsigned char ADE7758::read8bits(char reg) { _ADE7758SPI->beginTransaction(ADESETTINGS); enableChip();
unsigned char ret; delay(10); _ADE7758SPI->transfer(REG_READ(reg)); delay(2); ret=_ADE7758SPI->transfer(0x00); delay(1);
disableChip(); _ADE7758SPI->endTransaction(); return ret; }
unsigned int ADE7758::read16bits(char reg) { _ADE7758SPI->beginTransaction(ADESETTINGS); enableChip(); unsigned int ret=0; unsigned char ret0=0; delay(10); _ADE7758SPI->transfer(REG_READ(reg)); delay(2); ret=_ADE7758SPI->transfer(0x00); delay(2); ret0=_ADE7758SPI->transfer(0x00); delay(1);
disableChip(); _ADE7758SPI->endTransaction(); ret= (ret<<8)|ret0; return ret; }
unsigned long ADE7758::read24bits(char reg) { _ADE7758SPI->beginTransaction(ADESETTINGS); enableChip(); unsigned long ret=0; unsigned int ret1=0; unsigned char ret0=0; delay(10); _ADE7758SPI->transfer(REG_READ(reg)); delay(2); ret=_ADE7758SPI->transfer(0x00); delay(2); ret1=_ADE7758SPI->transfer(0x00); delay(2); ret0=_ADE7758SPI->transfer(0x00); delay(1);
disableChip();
_ADE7758SPI->endTransaction();
ret= (ret<<16)|(ret1<<8)|ret0;
return ret;
}
long ADE7758::getIRMS(char phase) { return read24bits(AIRMS+phase); }
long ADE7758::getVRMS(char phase)
{
return read24bits(AVRMS+phase);
}
`
ADE7758Lib.h
` #ifndef _ADE7758LIB_h #define _ADE7758LIB_h
#include <SPI.h>
#define AWATTHR 0x01 #define BWATTHR 0x02 #define CWATTHR 0x03 #define AVARHR 0x04 #define BVARHR 0x05 #define CVARHR 0x06 #define AVAHR 0x07 #define BVAHR 0x08 #define CVAHR 0x09 #define AIRMS 0x0A #define BIRMS 0x0B #define CIRMS 0x0C #define AVRMS 0x0D #define BVRMS 0x0E #define CVRMS 0x0F #define FREQ 0x10 #define TEMP 0x11 #define WFORM 0x12 #define OPMODE 0x13 #define MMODE 0x14 #define WAVMODE 0x15 #define COMPMODE 0x16 #define LCYCMODE 0x17 #define MASK 0x18 #define STATUS 0x19 #define RSTATUS 0x1A #define ZXTOUT 0x1B #define LINECYC 0x1C #define SAGCYC 0x1D #define SAGLVL 0x1E #define VPINTLVL 0x1F #define IPINTLVL 0x20 #define VPEAK 0x21 #define IPEAK 0x22 #define GAIN 0x23 #define AVRMSGAIN 0x24 #define BVRMSGAIN 0x25 #define CVRMSGAIN 0x26 #define AIGAIN 0x27 #define BIGAIN 0x28 #define CIGAIN 0x29 #define AWG 0x2A #define BWG 0x2B #define CWG 0x2C #define AVARG 0x2D #define BVARG 0x2E #define CVARG 0x2F #define AVAG 0x30 #define BVAG 0x31 #define CVAG 0x32 #define AVRMSOS 0x33 #define BVRMSOS 0x34 #define CVRMSOS 0x35 #define AIRMSOS 0x36 #define BIRMSOS 0x37 #define CIRMSOS 0x38 #define AWAITOS 0x39 #define BWAITOS 0x3A #define CWAITOS 0x3B #define AVAROS 0x3C #define BVAROS 0x3D #define CVAROS 0x3E #define APHCAL 0x3F #define BPHCAL 0x40 #define CPHCAL 0x41 #define WDIV 0x42 #define VADIV 0x44 #define VARDIV 0x43 #define APCFNUM 0x45 #define APCFDEN 0x46 #define VARCFNUM 0x47 #define VARCFDEN 0x48 #define CHKSUM 0x7E #define VERSION 0x7F
#define REG_READ(reg) reg #define REG_WRITE(reg) (unsigned char)((reg) | 0x80)
//PHASE_SEL #define PHASE_A 0 #define PHASE_B 1 #define PHASE_C 2
//WAV_SEL #define CURRENT 0 #define VOLTAGE 1 #define ACT_PWR 2 #define REACT_PWR 3 #define APP_PWR 4
//interrupt mask/status bit #define AEHF 0 #define REHF 1 #define VAEHF 2 #define SAGA 3 #define SAGB 4 #define SAGC 5 #define ZXTOA 6 #define ZXTOB 7 #define ZXTOC 8 #define ZXA 9 #define ZXB 10 #define ZXC 11 #define LENERGY 12 #define RESET 13 #define PKV 14 #define PKI 15 #define WFSM 16 #define REVPAP 17 #define REVPRP 18 #define SEQERR 19
#define WAVMODE_VALUE(phase, wave) (((wave)<<2)|(phase))
class ADE7758 { public: ADE7758 (SPIClass *,int ); void begin(); int WattHR(char ); int VARHR(char ); int VAHR(char ); long VRMS(char ); long IRMS(char ); long waveform(char ,char ); int lineFreq(char );
void accumulateEnergy();
void powerOff();
void powerON();
void sleep();
void wakeUp();
long getInterruptStatus(void);
long getResetInterruptStatus(void);
void enableChip();
void disableChip();
void write8bits(char , unsigned char );
void write16bits(char , unsigned int );
unsigned char read8bits(char );
unsigned int read16bits(char );
unsigned long read24bits(char );
//////////////////
int getTemperature(char);
/////////////////
long getIRMS(char );
long getVRMS(char );
int getWattHR(char );
int getVARHR(char );
int getVAHR(char );
private:
SPIClass *_ADE7758SPI;
int _SSpin;
long accuWattHRA;
long accuWattHRB;
long accuVARHRA;
long accuVARHRB;
long accuVAHRA;
long accuVAHRB;
};
#endif `
Thank you so much for your help
They way I see it in you switch statement, if you enter a 't', it goes to the case 't'. However, since you did not put a break, it will still check for the next cases which will not match 't'. Therefore, it goes to the default: Serial.println("unknown command"); Also, I forgot to implement the TEMP(0x11) register temperature computation. But it is in the datasheet. The function should not accept a second argument. We are supposed to add a temperature sensor inside a transformer per phase that is why we put that function like that but we never had time to implement it. Therefor, the getTemperature(0) just put zero in it. Itshould return the content of the TEMP register. Just use the computation in datasheet.
Thank you for your help. I did that, but I coninue with the problem.
I dowloand your code and I have the same problem (unknown command) Do you have any other ideas? Thank you.
You should check your code again. Inside the serial event, you had char inChar, but you are using inputChar in your loop. change it to this:
void serialEvent() { while (Serial.available()) { // get the new byte: inputChar = (char)Serial.read(); rx = true; } }
On Mon, Jul 17, 2017 at 3:35 AM, 2Peter [email protected] wrote:
Thank you for your help. I did that, but I coninue with the problem.
I dowloand your code and I have the same problem (unknown command) Do you have any other ideas? Thank you.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/engkan2kit/ADE7758/issues/1#issuecomment-315631653, or mute the thread https://github.com/notifications/unsubscribe-auth/AFTqU1qRHSUY8Ur_eN8kjqc2eugx_SF9ks5sOmYDgaJpZM4B7IWV .
Hi, I tried it and this is the result: https://www.dropbox.com/s/239l2mqnrdwg8wj/void%20changer.JPG?dl=0 (not meter the temperature, for example)
I think that the problem is in the circuit diagram. Can you check this picture please? https://www.dropbox.com/s/qxpozynnyq6l99q/circuito%20temperatura.jpeg?dl=0
I used the SPI connection, only for meter temperature. This is correct ?
Thank you.
Wiring seems fine. How is the "-" and the gnd of the ade7758 connected the gnd of arduino?
On Jul 20, 2017 3:31 AM, "2Peter" [email protected] wrote:
Hi, I tried it and this is the result: https://www.dropbox.com/s/ 239l2mqnrdwg8wj/void%20changer.JPG?dl=0 http://url (not meter the temperature, for example)
I think that the problem is in the circuit diagram. Can you check this picture please? https://www.dropbox.com/s/qxpozynnyq6l99q/circuito% 20temperatura.jpeg?dl=0 http://url
I used the SPI conection, This is correct ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/engkan2kit/ADE7758/issues/1#issuecomment-316492410, or mute the thread https://github.com/notifications/unsubscribe-auth/AFTqU4Pq7oT2z1voc6MYT7faEIhOyx8dks5sPlmDgaJpZM4B7IWV .
Sorry, the "-" is the GND of arduino. I did a modification to know if arduino take the temperature's data, but not (check the picture) https://www.dropbox.com/s/xzs71xl4cj03j8y/temperatura_he_pedido_dato.JPG?dl=0 With the voltage happen the same
engkan2kit
HI.,., Can you please share the updated code for ADE7758., the old code is not working.,.
engkan2kit
HI.,., Can you please share the updated code for ADE7758., the old code is not working.,.
Hi Sorry, I don't have the hardware for this anymore. If you can send me the eval board for ADE7758, I can update the code and ensure it works.
Hi.,. the ADE7758 library works well for the arduino UNO.,., but not responding good for esp8266 series.,. can you help us??
it is giving wrong data.,., any spi settings to be changed??
On Fri, Sep 1, 2023 at 4:24 PM Kister Genesis Jimenez < @.***> wrote:
engkan2kit
HI.,., Can you please share the updated code for ADE7758., the old code is not working.,.
Hi Sorry, I don't have the hardware for this anymore. If you can send me the eval board for ADE7758, I can update the code and ensure it works.
— Reply to this email directly, view it on GitHub https://github.com/engkan2kit/ADE7758/issues/1#issuecomment-1702561891, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKHRYCWJUKFTDJ7L7GKJ73LXYG5IFANCNFSM4APMQWKQ . You are receiving this because you commented.Message ID: @.***>
-- With thanks and Regards G.R.Kanagachidambaresan, eee1.blogspot.com +91-9994120988.
Hi, I have made the SPI between ADE7758 and arduino to measure Vrms but it starts to count instead of measuring the voltage, can anyone help me with this problem?