Stap 4: TX SKETCH (zender)
#include <HX711.h>#include <JeeLib.h>#include <Manchester.h>ISR(WDT_vect) {Sleepy::watchdogEvent();}// HX711.DOUT - pin #A1 // HX711.PD_SCK - pin #A0 /* * How to Calibrate Your Scale1. Call set_scale() with no parameter. 2. Call tare() with no parameter. 3. Place a known weight on the scale and call get_units(10). 4. Divide the result in step 3 to your known weight. You should get about the parameter you need to pass to set_scale. 5. Adjust the parameter in step 4 until you get an accurate reading. */ // HX711 (Dout,Sck) HX711 scale(A1, A0); // parameter "gain" is ommited; the default value 128 is used by the library</p><p>#define TX_PIN 6 //pin where your transmitter is connected #define BUFFER_SIZE 50 #define LED_PIN 13 #define CELL_PIN A0//*********** SERIAL NUMBER *********** char SerialSens[ ]="SCZRE0364"; //*************************************int volt=0; char messaggio[32]; unsigned char data[BUFFER_SIZE]=""; char msg[BUFFER_SIZE]; char msg2[10]; char msg3[10]; char msg4[10]; float carica=0; char vuota[32]=""; int offset_scale=53;// How often do we do readings? long time = 0; // int timeBetweenReadings = 500; // We want a reading every 200 ms;void setup() { Serial.begin(9600); man.workAround1MhzTinyCore(); //add this in order for transmitter to work with 1Mhz Attiny85/84 man.setupTransmit(TX_PIN, MAN_600); pinMode ( LED_PIN, OUTPUT); pinMode ( TX_PIN, OUTPUT); Serial.println("HX711 Demo"); Serial.println("Before setting up the scale:"); Serial.print("read: \t\t"); Serial.println(scale.read()); // print a raw reading from the ADC</p><p> Serial.print("read average: \t\t"); Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC</p><p> Serial.print("get value: \t\t"); Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)</p><p> Serial.print("get units: \t\t"); Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided // by the SCALE parameter (not set yet) </p><p> scale.set_scale(291.00); // this value is obtained by calibrating the scale with known weights; see the README for details scale.tare(); // reset the scale to 0</p><p> Serial.println("After setting up the scale:");</p><p> Serial.print("read: \t\t"); Serial.println(scale.read()); // print a raw reading from the ADC</p><p> Serial.print("read average: \t\t"); Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC</p><p> Serial.print("get value: \t\t"); Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()</p><p> Serial.print("get units: \t\t"); Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided // by the SCALE parameter set with set_scale</p><p> Serial.println("Readings:"); }void loop() { Serial.print("\t| PESO:\t"); float peso=-scale.get_units(10); if (peso>-3 && peso<3) peso=0; Serial.print(peso, 0);Serial.println(" gr."); delay(50); dtostrf(peso, 4, 1,msg2); float risultato=readVcc(); dtostrf(risultato, 4, 0,msg4); carica=risultato/1000; dtostrf(carica, 1, 3,msg4); strcpy(msg,""); strcat(msg, "SN:"); strcat(msg, SerialSens); strcat(msg, "PE:"); strcat(msg, msg2); strcat(msg, "BT:"); strcat(msg, msg4); for (int i=0;i<=BUFFER_SIZE;i++) { data[i]=msg[i]; } digitalWrite(LED_PIN, true); //Lampeggia il led al ricevimento del messaggio delay(10); digitalWrite(LED_PIN, false); man.transmitArray(BUFFER_SIZE,data); scale.power_down(); // put the ADC in sleep mode Sleepy::loseSomeTime(30000); scale.power_up(); }float readVcc() { // Read 1.1V reference against AVcc // set the reference to Vcc and the measurement to the internal 1.1V reference #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = _BV(MUX5) | _BV(MUX0); #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) ADMUX = _BV(MUX3) | _BV(MUX2); #else ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #endif delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA,ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high<<8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts }
Uiteraard op regel Uwijzigtdewaarde 71 met wat je tijdens de kalibratie hebt.
De schets is gebaseerd op het SmartCityZen-project transmissieprotocol, en vervolgens vergeleken met de functies van de enkele afval control er sommige redundante informatie verzonden (voor bijvoorbeeld de sensor code of batterij volt zijn).
Op deze manier, echter kunnen de toegezonden gegevens worden gelezen SCZ Station en overgedragen via het Internet op SmartCityZen webserver en gedeeld via het portaal.
De schets stuurt naar de ontvanger om de 30 seconden van het gewicht van afval, deze waarde kan worden gewijzigd door simpelweg het veranderen van de waarde van deze opdracht
Sleepy :: loseSomeTime (30000);
Wijzigen van 30000 mS tot een max waarde van 60000 mS, waarmee een pauze van 1 minuut, te verhogen en bijvoorbeeld een te sturen om de 3 minuten met de volgende syntaxis:
Sleepy :: loseSomeTime (60000); Sleepy :: loseSomeTime (60000);<br>Sleepy :: loseSomeTime (60000);
Belt 3 keer de opdracht.