Stap 5:-Receiversysteem
Het systeem van de ontvanger vereist dat de Arduino aangesloten met de 1602-display en de 433 MHz RF ontvanger volgens het bedradingsschema.
En dit is de schets te laden:
/* ------------------------------------------------------------------------------- // Monitoraggio produzione rifiuti casalinghi con SCZRE con display LCD 16x2 1602 con registrazione in EPROM del totrifiuti e dell'ultima pesata// */ #include <LiquidCrystal.h> #include <SPI.h> #include <SD.h> #include <Manchester.h> #include <string.h> #include <EEPROMex.h> // Connections: // rs (LCD pin 4) to Arduino pin 12 // rw (LCD pin 5) to Arduino pin 11 // enable (LCD pin 6) to Arduino pin 10 // LCD pin 15 to Arduino pin 13 // LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2 // Ricevitore RF connesso a pin 7 arduino LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); int backLight = 13; // pin 13 will control the backlight</p><p>//Configurazione Libreria Manchester per trasmissione #define RX_PIN 7 #define BUFFER_SIZE 50 uint8_t buffer[BUFFER_SIZE]; unsigned char message[BUFFER_SIZE]; #define LED_PIN 13 char SensMessage[] = "SCZXX"; // Memorizzazione totale rifiuti String dataInizio = "02/01/2016"; int addressFloat = 0; int addressFloatPeso=5; boolean scarico=HIGH; float totRifiuti = 0.0; float precPeso = 0; float nowPeso = 0; void setup() { Serial.begin(9600); //EEPROM.writeFloat(addressFloat,totRifiuti); //EEPROM.writeFloat(addressFloatPeso,precPeso); pinMode(backLight, OUTPUT); digitalWrite(backLight, LOW); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off. lcd.begin(16, 2); // columns, rows. use 16,2 for a 16x2 LCD, etc. lcd.clear(); // start with a blank screen lcd.setCursor(0, 0); // set cursor to column 0, row 0 (the first row) lcd.print("SCZ Recycle"); // change this text to whatever you like. keep it clean. lcd.setCursor(0, 1); // set cursor to column 0, row 1 lcd.print("smartcityzen.it"); totRifiuti = EEPROM.readFloat(0); precPeso=EEPROM.readFloat(5); //Configurazione Manchester man.setupReceive(RX_PIN, MAN_600); man.beginReceiveArray(BUFFER_SIZE, buffer); delay(500); lcd.clear(); // start with a blank screen lcd.setCursor(0, 0); // set cursor to column 0, row 0 (the first row) lcd.print("Attendi"); }void loop() {if (man.receiveComplete()) { uint8_t receivedSize = 0; Serial.println("Ricevuto: "); digitalWrite(LED_PIN, HIGH); delay(100); digitalWrite(LED_PIN, LOW); for (int i = 0; i < BUFFER_SIZE; i++) {message[i] = char(buffer[i]); Serial.print(char(message[i])); } Serial.println(); Serial.print("SENSORE: "); for (int t = 0; t < 5; t++) { SensMessage[t] = message[t + 3]; } String messstr = String(SensMessage); Serial.println(messstr);if (messstr == "SCZRE") { Serial.println("Ricevuto un SCZ RECYCLING"); gestioneSCZRE(); } man.beginReceiveArray(BUFFER_SIZE, buffer); } else { lcd.setCursor(0, 0); lcd.print("TOT: "); lcd.print(totRifiuti+nowPeso); lcd.print(" KG"); Serial.print("totRifiuti:");Serial.println(totRifiuti); lcd.setCursor(0, 1); lcd.print("NOW: "); lcd.print(nowPeso); lcd.print(" KG"); Serial.print("nowPeso:");Serial.println(nowPeso); } } //---------------------------------SCZRE-------------------------- void gestioneSCZRE() { Serial.print("IN FUNZIONE: "); for (int i = 0; i < BUFFER_SIZE; i++) { Serial.print(char(message[i])); } String nowRifiuti = ""; Serial.print("nowRifiuti:");Serial.println(nowRifiuti); for (int i = 0; i < 5; i++) { nowRifiuti = nowRifiuti + char(message[i + 15]); Serial.print(char(message[i + 15])); } Serial.print("nowRifiuti:");Serial.println(nowRifiuti); nowPeso = nowRifiuti.toFloat(); if (precPeso==0) { precPeso=nowPeso; } if (nowPeso<0.1 && scarico==LOW) { totRifiuti=totRifiuti+precPeso; EEPROM.writeFloat(addressFloat,totRifiuti); EEPROM.writeFloat(addressFloatPeso,precPeso); scarico=HIGH; } if (nowPeso>1) { scarico=LOW; } Serial.print("nowPeso:");Serial.println(nowPeso); }