Jump to content
43oh

Ethernet and serial5 won't work together


Recommended Posts

I can't get Ethernet and Serial5 to work at the same time. If I run the ethernet the programs hangs when I write to serial5.

Anyone seen this before?

If I comment out ethernet.begin etc... the program runs fine. If I run as is the programs hangs at the first println to serial5.

If I comment out any println's to serial5 the program runs fine.

What could be the problem with ethernet and writing to serial port?

 

#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>

#include <Ethernet.h>

byte mac[] = {0x00, 0x1A, 0xB6, 0x02, 0xB8, 0xB2 };

//IPAddress ip(192,168,2,62);

EthernetServer server(8000);


const int Pump1Fault = PB_4;
const int Pump1SpeedThreshold = PC_4;
const int Pump1R2 = PC_5;
const int Pump1Current = A0;
const int Pump1Speed = A1;

const int Pump2Fault = PB_5;
const int Pump2SpeedThreshold = PK_0;
const int Pump2R2 = PK_1;
const int Pump2Current = A2;
const int Pump2Speed = A3;


const int Gate1 = PF_1;
const int Gate2 = PF_2;
const int Foreline1 = PL_0;
const int Foreline2 = PL_1;

String inData, outData;
String vesselPressure, scrollPump1Pressure;
String scrollPump2Pressure, vesselThermocouple;
String inputString = "";

volatile int State;

volatile int Pump1FaultStatus;
volatile int Pump1SpeedThresholdStatus;
volatile int Pump1R2Status;

volatile int Pump2FaultStatus;
volatile int Pump2SpeedThresholdStatus;
volatile int Pump2R2Status;

double Pump1CurrentValue;
double Pump1SpeedValue;

double Pump2CurrentValue;
double Pump2SpeedValue;

long currentTime = 0;
long waitTime = 1000;

boolean stringComplete = false;

void setup()
{
  pinMode(Pump1Fault, INPUT);
  pinMode(Pump1SpeedThreshold, INPUT);
  pinMode(Pump1R2, INPUT);
 
  pinMode(Pump2Fault, INPUT);
  pinMode(Pump2SpeedThreshold, INPUT);
  pinMode(Pump2R2, INPUT);
 
  pinMode(Gate1, OUTPUT);
  pinMode(Gate2, OUTPUT);
  pinMode(Foreline1, OUTPUT);
  pinMode(Foreline2, OUTPUT);
 
 
  Serial.begin(9600);  // Use for troubleshooting.
  Serial5.begin(9600);
 
  Serial.println("Starting Ethernet");
  Ethernet.begin(mac);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
 
 
  State = 1;
 
}

void loop()
{
   
   
 
  if(State == 1)
    { State = 2;
      getpump1inputs();
    }
    
  if(State == 2)
    { State = 3;
      getpump2inputs();
    }
    
  if(State == 3)
    { State = 4;
      getVesselPressure("#0002UVACVS");
      delay(10);
      vesselPressure = getSerial5data();
      vesselPressure.setCharAt(0,' ');
      vesselPressure.trim();
      Serial.print("Vac Vessel Pressure: ");
      Serial.println(vesselPressure);
    }
  if(State == 4)
    { State = 5;
      getVesselPressure("#0002USCR1");
      delay(10);
      scrollPump1Pressure = getSerial5data();
      scrollPump1Pressure.setCharAt(0,' ');
      scrollPump1Pressure.trim();
      Serial.print("Scroll Pump1 Pressure: ");
      Serial.println(scrollPump1Pressure);
    }
 
  if(State == 5)
    { State = 6;
      getVesselPressure("#0002USCR2");
      delay(10);
      scrollPump2Pressure = getSerial5data();
      scrollPump2Pressure.setCharAt(0,' ');
      scrollPump2Pressure.trim();
      Serial.print("Scroll Pump2 Pressure: ");
      Serial.println(scrollPump2Pressure);
    }
 
  if(State == 6)
    { State = 7;
      getVesselPressure("#0002UVACTC");
      delay(10);
      vesselThermocouple = getSerial5data();
      vesselThermocouple.setCharAt(0,' ');
      vesselThermocouple.trim();
      Serial.print("Vessel Thermocouple: ");
      Serial.println(vesselThermocouple);
    }
 
  if(State == 7)
    {
      State = 8;
      updateClient();
    }
    
  if(State == 8)
    { delay(1000);
      State = 1;
    }
}

void getpump1inputs()
  {
    Pump1FaultStatus = digitalRead(Pump1Fault);
      Serial.print("Pump1 Fault Status: ");
      Serial.println(Pump1FaultStatus);
    Pump1SpeedThresholdStatus = digitalRead(Pump1SpeedThreshold);
      Serial.print("Pump1 Speed Threshold Status: ");
      Serial.println(Pump1SpeedThresholdStatus);
    Pump1R2Status = digitalRead(Pump1R2);
      Serial.print("Pump1 R2 Status: ");
      Serial.println(Pump1R2Status);
    
      double Pump1CurrentValueInput = analogRead(Pump1Current);
      Pump1CurrentValue=((Pump1CurrentValueInput/4095) * 10);
      Serial.print("Pump1 Current Value: ");
      Serial.println(Pump1CurrentValue);
    double Pump1SpeedValueInput = analogRead(Pump1Speed);
      Pump1SpeedValue=((Pump1SpeedValueInput/4095) * 10);
      Serial.print("Pump1 Speed Value: ");
      Serial.println(Pump1SpeedValue);
    
  }
 
  void getpump2inputs()
  {
    Pump2FaultStatus = digitalRead(Pump2Fault);
      Serial.print("Pump2 Fault Status: ");
      Serial.println(Pump2FaultStatus);
    Pump2SpeedThresholdStatus = digitalRead(Pump2SpeedThreshold);
      Serial.print("Pump2 Speed Threshold Status: ");
      Serial.println(Pump2SpeedThresholdStatus);
    Pump2R2Status = digitalRead(Pump2R2);
      Serial.print("Pump2 R2 Status: ");
      Serial.println(Pump2R2Status);
    
    double Pump2CurrentValueInput = analogRead(Pump2Current);
      Pump2CurrentValue=((Pump2CurrentValueInput/4095) * 10);
      Serial.print("Pump2 Current Value: ");
      Serial.println(Pump2CurrentValue);
    double Pump2SpeedValueInput = analogRead(Pump2Speed);
      Pump2SpeedValue=((Pump2SpeedValueInput/4095) * 10);
      Serial.print("Pump2 Speed Value: ");
      Serial.println(Pump2SpeedValue);
    
  }
    
 String getVesselPressure(String command)
  {
    
   Serial5.println(command);
        
  }  
 
 
  String getSerial5data()
  {
    
    char received;
    inData = "";
    currentTime = millis();
    long time = currentTime + waitTime;
    do {
      long currentTime=millis();
      if(time < currentTime)
      {
        inData=" TimedOut";
        return inData;
        break;
      }
    if (Serial5.available())
     {
       
       received = Serial5.read();
       inData += received;
        
        }
         } while (received != 'r');     
          return inData;
         
      }    
    
  void updateClient()
  {
    EthernetClient client = server.available();
    if (client)
    {
     if (client.connected())
      {
       server.print("Pump1 Fault Status: ");
       server.println(Pump1FaultStatus);
       server.print("Pump1 Speed Threshold Status: ");
       server.println(Pump1SpeedThresholdStatus);
       server.print("Pump1 R2 Status: ");
       server.println(Pump1R2Status);
       server.print("Pump1 Current Value: ");
       server.println(Pump1CurrentValue);
       server.print("Pump1 Speed Value: ");
       server.println(Pump1SpeedValue);
       
       server.print("Pump2 Fault Status: ");
       server.println(Pump2FaultStatus);
       server.print("Pump2 Speed Threshold Status: ");
       server.println(Pump2SpeedThresholdStatus);
       server.print("Pump2 R2 Status: ");
       server.println(Pump2R2Status);
       server.print("Pump2 Current Value: ");
       server.println(Pump2CurrentValue);
       server.print("Pump2 Speed Value: ");
       server.println(Pump2SpeedValue);
      }
        
    }
 }



View the full article on Stellarisiti. 43oh pulls Stellarisiti Energia posts, so that members do not miss out questions. Please bear with this arrangement for now. Thanks!
Link to post
Share on other sites
Guest
This topic is now closed to further replies.
×
×
  • Create New...