Arduino - Projekte der 3AHET
Würden Sie gerne auf diese Nachricht reagieren? Erstellen Sie einen Account in wenigen Klicks oder loggen Sie sich ein, um fortzufahren.

Übertragungsprotkoll

Nach unten

Übertragungsprotkoll Empty Übertragungsprotkoll

Beitrag von Dylan Baumann Di Mai 24, 2016 2:49 pm

Erläuterung:
Die Umgebung in der wir unser Übertragungsprotkoll verwendet haben, bestand aus vier Arduino Megas. Einer diente als zentraler Empfänger und war für den Output der Daten zuständig, welche die anderen drei Arduinos mit Sensoren gemessen haben. Die Sensoren waren ein Fotowiderstand, eine IR-Empfänger sowie ein Temperatursensor.

Funktion:
Wenn der Taster für den Output-Arduino betätigt wird sendet dieser die Zahl 255. Die Sensorstationen wissen jeweils, dass sie bei einer empfangenen 255 ihre Messdaten erheben und senden sollen. Jede Sensorstation besitzt des Weiteren eine eigene Zahl, mit welcher nachher vom Output-Arduino die Daten zugeordnet werden können. Wenn eine Sensorstation etwas anderes als eine 255 empfängt, sendet sie die Daten einfach weiter. Die Zahl 255 ist in den Datenpaketen jeweils zum Schluss.

Anmerkung:
Wie im Code ersichtlich wird, verwendet der Output-Arduino zum Kommunizieren TX3 und RX3, da TX1 und RX1 für den Serial Monitor, in welchem die Daten ausgegeben werden, verwendet werden. Es könnte aber auch problemlos ein LCD-Display verwendet werden.

Code des Output-Arduinos:
Code:
int receivedbyte;         //receivedbyte will contain the received data


void setup() {
  Serial.begin(9600);
  Serial3.begin(9600);
  pinMode(7, INPUT);

}

void loop() {

  if(digitalRead(7) == HIGH){     //if the button is pushed the master arduino starts the measure-cycle
    Serial3.write(255);           //the 255 will say the sensor arduinos that they have to measure their data
    delay(500);                   //is necessary, beacuse else the arduino will trigger the button often
  }
  
  if(Serial3.available() > 0){    //if data is incoming
    receivedbyte = Serial3.read();  //the incomig daat will be saved as receivedbyte
    
    if(receivedbyte == 254){      //if the received data is 254, which is the temperaturesign, the master knows that the next incoming data will be the temerpature and starts the outputvoid of the temperature
      outputtemp();
    }
    if(receivedbyte == 253){      //same as above but for the resistence of the foto resistor
      outputres();
    }
    if(receivedbyte == 252){      //again the same but for the infrared receiver
      outputflame();
    }
  }
}



void outputtemp(){                //in this void the temperature will be output
    receivedbyte = Serial3.read();  //again the incoing daat is saved as receivedbyte
    Serial.println("");             //create an ampty line so that the output doesn't look too cramped
    Serial.println("The Temperature is: ");  //writes the text for the temperature
    if(receivedbyte != 255){              //checks if the incoming data is the sign of the master or not
      Serial.print(receivedbyte);
    }
}



void outputres(){         //does the same as outputtemp() but for the fotoresistor

  if(Serial3.available() > 0){
    receivedbyte = Serial3.read();
    Serial.println("");
    Serial.println("The resistance is: ");
    if(receivedbyte != 255){
      Serial.print(receivedbyte);
    }
  }
}



void outputflame(){       //does the same as outputtemp() but for the infraredreceiver

  if(Serial3.available() > 0){
    receivedbyte = Serial3.read();
    Serial.println("");
    Serial.println("Does something burn? ");
    if(receivedbyte == 50){
      Serial.print("Yes");
    }
    else if(receivedbyte == 100){
      Serial.print("No");
    }
  }
}

Code die Sensorstationen:
Code:
int receivedbyte;            //received byte shall be the received data
int sensorvalue;             //sensorvalue is the value the sensor measures
#define sensorsign  254      //the sensorsign is send that the master arduino knows whichs sensor data it is, 254 for temperature, 253 for photoresistor, 252 for infraredsensor


void setup() {
  Serial.begin(9600);
}

void loop() {
  
  if(Serial.available() > 0){           //data is incoming
    receivedbyte = Serial.read();       //receivedbyte contains the received data

    if(receivedbyte == 255){            //if the received data is the sign of the master arduino, the value of this sensor is measured end send with its sensorspecificsign end the regular the 255 to say the next sensor to measure its value

      Getyourvalue();                   //in this void you sensor measured the value
      Serial.write(sensorsign);         //writes the sensorspecific sign
      Serial.write(sensorvalue);        //writes the sensorvalue
      delay(1);
      Serial.write(255);                //writes the 255 to say the next sensor that it has to emasure its data
    }

    else if(receivedbyte != 255){     //if the received data is not the sensorsign, it must be the data of an other sensor and is send to the next station
      Serial.write(receivedbyte);     //sends the received data forward to the next station of the network
    }
  }
}



void Getyourvalue(){            //in this void the sensor-specific data is measured

    

}

Schaltung:
Übertragungsprotkoll Schalt10

Dylan Baumann
Admin

Anzahl der Beiträge : 4
Anmeldedatum : 23.02.16
Alter : 25
Ort : 3AHET

Nach oben Nach unten

Nach oben


 
Befugnisse in diesem Forum
Sie können in diesem Forum nicht antworten