Probleme mit Arduino und 4 CT Sensoren

Hallo

Leider ist mein englisch nicht so gut als das ich es so erklären kann, ich hoffe es ist auch in Deutsch ok.

Ich bin neu hier und habe leider sofort eine frage zu einem Problem das ich bis jetzt nicht selber lösen konnte.

Zu meinem Problem, ich habe emoncms installiert und zum laufen gebracht. Ich habe 4 ct sensoren bis 100A die ich mit einem arduino auslesen wollte und via ethernet zum server senden wollte. ich habe mir dazu nach dieser Seite eine Platine gebastelt, mit eingängen für 4 sensoren. http://openenergymonitor.org/emon/buildingblocks/how-to-build-an-arduino-energy-monitor-measuring-current-only

​Der arduino wurde mit diesem sketch bespielt:

/*
  Arduino & OpenEnergyMonitor 
  
  This sketch connects to an emoncms server and makes a request using
  Arduino Ethernet shield (or other based on Wiznet W5100) or an 
  Arduino Wifi Shield
  
  author Mirco Piccin aka pitusso
  
  based on 
  http://arduino.cc/en/Tutorial/WebClientRepeating
*/

char foo;  //without a simple variable declaration, use of #ifdef at the top of your code raises an error!

//if using a W5100 based Ethernet shield, comment out the following line; 
//leave untouched if using Arduino Wifi Shield
//#define WIFI

#include <SPI.h>

/*#ifdef WIFI
  #include <WiFi.h>
  #include <WiFiClient.h>
#else */
  #include <Ethernet.h>
//#endif

// Include Emon Library
#include "EmonLib.h"                   

//network configuration, WIRED or WIFI
/*#ifdef WIFI
  //if using WIFI 
  char ssid[] = "ssid"; //  your network SSID (name) 
  char pass[] = "password";    // your network password (use for WPA, or use as key for WEP)

  int status = WL_IDLE_STATUS;
  int keyIndex = 0;            // your network key Index number (needed only for WEP)
  
  WiFiClient client;
#else*/
  //if using WIRED
  byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0x69, 0xD5};
  
  // fill in an available IP address on your network here,
  // for auto configuration:
  IPAddress ip(192, 168, 1, 300);
  IPAddress subnet(255, 255, 255, 0);
  IPAddress DNS(192, 168, 1, 300);
  IPAddress gw(192, 168, 1, 300);
  
  EthernetClient client;
//#endif

//Calibrations
const int volt = 230;
const float ct_calibration1 = 111.1;
const float ct_calibration2 = 111.1;
const float ct_calibration3 = 111.1;
const float ct_calibration4 = 111.1;
const float temp_offset = 0;

// Sensor pins
//const int tempSensorPin = A0;
//const int lightSensorPin = A1;
const int currentSensorPin1 = 0;
const int currentSensorPin2 = 1;
const int currentSensorPin3 = 2;
const int currentSensorPin4 = 3;

//float tempValue = 0;
float Irms1 = 0;
float Irms2 = 0;
float Irms3 = 0;
float Irms4 = 0;
//int lightValue = 0;

// Create an Emon instance
EnergyMonitor emon1; 
EnergyMonitor emon2; 
EnergyMonitor emon3;
EnergyMonitor emon4;

//Emoncms configurations
//char server[] = "emoncms.org";     // name address for emoncms.org
IPAddress server(192, 168, 1, 300);  // numeric IP for emoncms.org (no DNS)

String apikey = "MY-API";  //api key
int node = 1; //if 0, not used

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
boolean lastConnected = false;                 // state of the connection last time through the main loop
const unsigned long postingInterval = 10*1000;  // delay between updates, in milliseconds

void setup() {
  // start serial port:
  Serial.begin(9600);

  // Display a welcome message
  Serial.println("Emoncms client starting...");

  emon1.current(currentSensorPin1, ct_calibration1);
  emon2.current(currentSensorPin2, ct_calibration2);
  emon3.current(currentSensorPin3, ct_calibration3);
  emon4.current(currentSensorPin4, ct_calibration4);

/*#ifdef WIFI
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 
  
  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. 
    status = WiFi.begin(ssid, pass);
  
    // wait 10 seconds for connection:
    delay(10000);
  } 
  Serial.println("Connected to wifi");
#else*/
  //if (!Ethernet.begin(mac)) 
  {
    // if DHCP fails, start with a hard-coded address:
    //Serial.println("Failed to get an IP address using DHCP, forcing manually");
    Ethernet.begin(mac, ip, dns, gw, subnet);
  }
//#endif  

  printStatus();
}

void loop() {
  
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("Disconnecting...");
    client.stop();
  }
  
  // if you're not connected, and at least <postingInterval> milliseconds have
  // passed sinceyour last connection, then connect again and
  // send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
   
    //read sensors
    //lightValue = analogRead(lightSensorPin);
    //tempValue = getCelsius(analogRead(tempSensorPin));
    Irms1 = emon1.calcIrms(1480);
    Irms2 = emon2.calcIrms(1480);
    Irms3 = emon3.calcIrms(1480);
    Irms4 = emon3.calcIrms(1480);
    
    //Print values (debug)
    Serial.println();
    Serial.print(" ; Power L1 : ");
    Serial.println(Irms1*volt);
    Serial.print(" ; Power L2 : ");
    Serial.println(Irms2*volt);
    Serial.print(" ; Power L3 : ");
    Serial.println(Irms3*volt);
    Serial.print(" ; Power N : ");
    Serial.println(Irms4*volt);
      
    //send values
    sendData();
  }
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
}

// this method makes a HTTP connection to the server:
void sendData() {
  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("Connecting...");
    // send the HTTP GET request:
    client.print("GET /emoncms/input/post.json?");
    if (node > 0) {
      client.print("node=");
      client.print(node);
    }
    client.print("&json={");
    client.print("power-L1:");
    client.print(Irms1*volt);
    client.print(",power-L2:");
    client.print(Irms2*volt);
    client.print(",power-L3:");
    client.print(Irms3*volt);
    client.print(",power-N:");
    client.print(Irms4*volt); 
    client.print("}&apikey=");
    client.print(apikey); 
    client.println(" HTTP/1.1");
    client.println("Host:emoncms.org");
    client.println("User-Agent: Arduino-ethernet");
    client.println("Connection: close");
    client.println();

    // note the time that the connection was made:
    lastConnectionTime = millis();
  } 
  else {
    // if you couldn't make a connection:
    Serial.println("Connection failed");
    Serial.println("Disconnecting...");
    client.stop();
  }
}

void printStatus() {
 /* #ifdef WIFI
    // print the SSID of the network you're attached to:
    Serial.print("SSID: ");
    Serial.println(WiFi.SSID());

    // print your WiFi shield's IP address:
    IPAddress ip = WiFi.localIP();
    Serial.print("IP Address: ");
    Serial.println(ip);

    // print the received signal strength:
    long rssi = WiFi.RSSI();
    Serial.print("signal strength (RSSI):");
    Serial.print(rssi);
    Serial.print(" dBm");
  #else*/
    // print your local IP address:
    Serial.print("IP address: ");
    for (byte thisByte = 0; thisByte < 4; thisByte++) {
      // print the value of each byte of the IP address:
      Serial.print(Ethernet.localIP()[thisByte], DEC);
      Serial.print("."); 
    }  
 // #endif
  Serial.println();
}

float getCelsius(int sensorValue) {
/*
  created by Federico Vanzati for TinkerKit Thermistor Library
*/
  const static float ADCres = 1023.0;
  const static int Beta = 3950;            // Beta parameter
  const static float Kelvin = 273.15;    // 0°C = 273.15 K
  const static int Rb = 10000;            // 10 kOhm
  const static float Ginf = 120.6685;    // Ginf = 1/Rinf 
  
  float Rthermistor = Rb * (ADCres / sensorValue - 1);
  float _temperatureC = Beta / (log( Rthermistor * Ginf )) ;
  return _temperatureC - Kelvin;
}

 

Es arbeitet auch alles wie es soll, bis auf das die Daten an Pin 2 und 3 nicht koreckt ankommen. die daten von CT3 (Pin2) werden an den Server als Daten von CT3 und ct4 übergeben und die Daten von ct4 kommen garnicht erst an. Stecke ich die beiden Kabel um auf Pin 0 und 1 kommen die Daten ohne probleme an, ein hardware fehler wäre also aus zu schließen. Leider komme ich nicht dahinter warum es ab ct3 probleme gibt, an den pins kann es nicht liegen, da die seperat funktionieren. könnte es an der emonlib liegen, das diese nur mit 3 senoren funktioniert?

 

Englische Version mit übersetzer

 

Hello

 unfortunately is my English not so well thanwhich I it explain in such a way can, I hopes it isalso in German ok. I am again here and haveunfortunately immediately one ask to a problemwhich I not solve up to now could. To my problem, Iinstalled emoncms and to run brought. I have 4 ctsensors to 100A which I with one arduino to selectwanted and via ethernet to the server sendwanted. I tinkered myself in addition after this sidea plate, with entrances for 4 sensors.http://openenergymonitor.org/emon/buildingblocks/how-to-build-an-arduino-energy-monitor-measuring-current-only arduino was taped with this sketch: 

[2nd copy of sketch deleted - Moderator (RW)]

Itworks also everything like it is, up to which the datat pin 2 and 3 do not arrive koreckt. the data ofCT3 (Pin2) are handed over to the server as dataof CT3 and ct4 and the data of ct4 to come notonly on. I put the two cables over on pin 0 and 1arrive the data without problems, for a hardware anerror would be thus out to be closed. UnfortunatelyI do not come behind it why it starting from ct3 ofproblems give, at the pins cannot it lie, since thosefunction separately. could it lie to emonlib, this onlywith 3 senoren functioned?

Robert Wall's picture

Re: Probleme mit Arduino und 4 CT Sensoren

Hier ist ihr Problem:

    Irms3 = emon3.calcIrms(1480);
    Irms4 = emon3.calcIrms(1480);

Sie sind aus CT3 zweimal Senden des Stroms an emonCMS - einmal unter dem Namen Irms3, und noch einmal unter dem Namen Irms4.

Es Muss sein:

    Irms3 = emon3.calcIrms(1480);
    Irms4 = emon4.calcIrms(1480);

Beachten Sie, dass wir denken, dass ein besserer Wert für die Anzahl der Proben ist 1662. Dies ist wegen der kleinen Verbesserungen in emonLib.

aDm1N's picture

Re: Probleme mit Arduino und 4 CT Sensoren

Vielen dank.

 

ist mir nicht aufgefallen. jetzt funktioniert es, nur noch etwas ungenau. gibt es eine deutsche anleitung zum calibrieren? durch die englische bin ich noch nicht ganz durchgestiegen.

Robert Wall's picture

Re: Probleme mit Arduino und 4 CT Sensoren

Es tut mir leid, es gibt keine Fassung der Kalibrierungsanweisungen auf Deutsch. Wenn Sie eine genaue Amperemeter hat, ändern Sie die Zahl 111,1, damit der Wert von Irms, um die genauen Wert, dass Ihre Amperemeter liest.

Auch ändern sie
const int volt = 230;
dass es der durchschnittliche Wert Ihrer Spannung ist.

Comment viewing options

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