Arduino and Processing Project

Hello everyone,

I am creating (as a school project) a home automation greenhouse which must be programmed to objects both in Arduino and in Processing and everything must be controlled on processing.

In practice I have 3 sensors, which values ​​I have to read on processing and 1 water motor and a fan that can be activated both automatically based on the parameters given by the sensors, and with buttons on the processing interface.

In hardware I have no problems, but I have problems with the software, in particular in sending data and reading them on processing. I am able to establish interaction with the COM, but then I cannot pass all this data.

How could I do?

What have you tried ?
How are you sending the data and in which format ?

Code, posted in code tags, would be nice to see.

What does that mean?

What is "Processing"?

From Arduino - Wikipedia.

the Arduino language , originated from the Processing language.

but I can't help feeling that you already knew that

I have a similar task to do, and a search on Google for;

'Arduino to Processing example using serial port'

or

'Arduino to Processing example using com port'

Revealed a few tutorials worth looking at.

Thanks at all.

Anyway I went ahead but I have a problem: now I have both a water motor and an air fan. When I load the sketch and go to the serial monitor the water motor works while the air fan does not, how could I fix this problem?

//Di seguito si richiamano le classi utilizzate
#include "levelwater.h"
#include "pumpwater.h"
#include "moisturesoil.h"
#include "airtemperature.h"
#include "airfan.h"

//Dichiarazione delle variabili per il passaggio dei dati dalle classi
int valueLevel;
int valueSoilMoisture;
int valuePumpWater;
int valueAirFan;
int valueAirTemperature;
int valueAirMoisture;

//Istanziamento degli oggetti dalle classi
LevelWater WLS = LevelWater(A1); //Water level Sensor
PumpWater WPM = PumpWater(2); //Water Pump Module
MoistureSoil MSS = MoistureSoil(A0); //Moisture Soil Sensor
AirFan AFM = AirFan(3, 4); //Air Fan Module
AirTemperature ATM = AirTemperature(5);//Air Temperature and Moisture Sensor

void setup() {

  //Inizializzazione della seriale
  Serial.begin(9600);
  //Funzioni per far comunicare la seriale con le classi interessate
  WPM.setSerial(&Serial);
  AFM.setSerial(&Serial);
  
}

void loop() {

  //Sensore Livello Acqua
  valueLevel = WLS.readwriteValue();
  
  //Sensore Umidità del Suolo
  valueSoilMoisture = MSS.readwriteValue();

  //Sensore Temperatura e Umidità
  valueAirTemperature = ATM.temperatureValue();
  valueAirMoisture = ATM.moistureValue();
  
  //Passaggio valori di azionamento o spegnimento
  valuePumpWater = WPM.readValue();
  valueAirFan = AFM.readValue();
  
  //Motorino Acqua
  if(valuePumpWater == 1){
    WPM.turnON();
  }
  else if(valuePumpWater == 2){
    WPM.turnOFF();
  }

  //Ventola Aria
  else if(valueAirFan == 3){
    AFM.turnON();
  }
  else if(valueAirFan == 4){
    AFM.turnOFF();
  }

  //Passaggio valori nella seriale verso Processing
  Serial.print('H');
  Serial.print(",");
  Serial.print(valueLevel, DEC);
  Serial.print(",");
  Serial.print(valueSoilMoisture, DEC);
  Serial.print(",");
  Serial.print(valueAirTemperature, DEC);
  Serial.print(",");
  Serial.print(valueAirMoisture, DEC);
  Serial.println();
  delay(100);
}
#ifndef module_airfan
#define module_airfan

class AirFan{

  private:
  
  int A_modulePin;
  int B_modulePin;
  int moduleState;
  int serialValue;

  Stream *_streamRef;

  public:

  AirFan(int, int);

  void turnON();
  void turnOFF();

  int readValue();

  setSerial(Stream *myStream){
    _streamRef = myStream;
  }
  
};

AirFan::AirFan(int n, int m){

  A_modulePin = n;
  B_modulePin = m;
  pinMode(n, OUTPUT);
  pinMode(m, OUTPUT);
  digitalWrite(n, LOW);
  digitalWrite(m, LOW);
  
}

void AirFan::turnON(){

  analogWrite(4, 255);
  digitalWrite(3, LOW);
  
}

void AirFan::turnOFF(){

  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  
}

int AirFan::readValue(){

  int result = -99;
  
  if(_streamRef->available()){

  result = -1;
      
    int value = _streamRef->parseInt();

    if(value == 3 || value == 4 && value != 0){

      result = value;
    }
  }
  return result;
}

#endif
#ifndef module_pumpwater
#define module_pumpwater

class PumpWater{

  private:
  
  int modulePin;
  int moduleState;
  int serialValue;

  Stream *_streamRef;

  public:

  PumpWater(int);

  void turnON();
  void turnOFF();

  int readValue();

  setSerial(Stream *myStream){
    _streamRef = myStream;
  }
  
};

PumpWater::PumpWater(int n){

  modulePin = n;
  pinMode(n, OUTPUT);
  digitalWrite(n, HIGH);
  
}

void PumpWater::turnON(){

  digitalWrite (2, LOW);
  
}

void PumpWater::turnOFF(){

  digitalWrite(2, HIGH);
  
}

int PumpWater::readValue(){

  int result = -99;
  
  if(_streamRef->available()){

  result = -1;
      
    int value = _streamRef->parseInt();

    if(value == 1 || value == 2 && value != 0){

      result = value;
    }
  }
  return result;
}

#endif

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.