Problem with looping in Processing

Hi there,

I´m working on a Energymonitor project to send Energy-data (explained here,51395.0.html)

Hardware: Energy sensing circuit+Arduino UNO
Software: Arduino 0022 with Firmata for UNO + Processing.

My problem is the following Processing code:
I want to calculate the average of the analog Values from A0-Pin over 3000 samples (draw-block), then calculate Current, and
Apparent Power (Scheinleistung S).
Checking the S- and w-Average values on the Serial COM, it seems like the Averaging isn´t working. I get w= 9,9,9,1,5,6,9… and so on. Almost the same code in Arduino IDE (other Post), gives a w= 8.0394,8.0239,8.2334…, so the averaging is working fine.
I´m a coding wrong? I believe it´s something simple, but I´m a mechanical engineer student trying to program :grin:


import processing.serial.*;
import cc.arduino.*;
import eeml.*;

// Definition der Variablen.................................
Arduino arduino;
float w; //analoge Wert (zw. 0 und 1023) aus die Sensorschaltung
int numberOfSamples=3000;// n=3000, Anzahl der Wiederholungen
float wquad;
float wsum;
float wqm;
float wkorr;// Bzw. gemittelte analoger Wert mit Korrekturfaktor
float U;// Analoge Wert entspricht eine Spannung U
float Uf=0.00488758; //Umwandlungsfaktor 5V/1023
float Uum=3.1; //Umw.faktor für Strom->Aus Datenblatt der Stromwandler CR 3110-3000
float I;// Effektive Strom
float Uleit=230;//Annahme für eff.Spannung
float S; //Scheinleistung
float lastUpdate;

DataOut dOut; 

void setup()
  arduino = new Arduino(this, Arduino.list()[2], 57600);
  dOut = new DataOut(this, "" , "dc0949c55775db92f74729df0696b555daf427ad966ef3ed3a4f7447c74d8941"); 
  dOut.addData(0,"Scheinleistung S");

void draw()
for (int i=0; i<numberOfSamples; i++)
  	w = arduino.analogRead(0)-680;
        wsum +=wquad;
        wkorr=wqm;// Hier konnte man um X-Faktor der Wert korrigieren 
        U= wkorr*Uf;
    if ((millis() - lastUpdate) > 180000){
        println("ready to PUT: ");
        int response = dOut.updatePachube(); 
        lastUpdate = millis();


void onReceiveRequest(DataOut d){ 
    d.update(0, S); 


w is the value read from the analog pin that the sensor is attached to. It is declared as a float, but the values being stored in it are integer values.

Almost the same code in Arduino IDE (other Post), gives a w= 8.0394,8.0239,8.2334..., so the averaging is working fine.

Not likely. The value read from the sensor is an integer. 8.0394 is not. There was obviously some different code on the Arduino that was converting the integer value to a float. That code needs to be copied into the Processing application.