Commits

Alessio Caiazza committed 9597e91

VirtualWire experiment

Comments (0)

Files changed (4)

+syntax: glob
+termostato_rx/build
+termostato_tx/build
+termostato_rx/build.sh
+termostato_rx/makefile
+termostato_tx/build.sh
+termostato_tx/makefile

termostato/protocol.h

+#ifndef TERMOSTATO_PROTOCOL_H
+#define TERMOSTATO_PROTOCOL_H
+
+struct HOTSPOT_MSG{
+  //put your variable definitions here for the data you want to receive
+  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
+  short cmd;
+  int args;
+};
+
+const short PING = 0;
+const short SWITCH_ON = 1;
+const short SWITCH_OFF = 2; 
+
+#endif

termostato_rx/termostato_rx.ino

-#include <SoftEasyTransfer.h>
+#include <VirtualWire.h>
+#include <EasyTransferVirtualWire.h>
+#include "../termostato/protocol.h"
 
-#include <SoftwareSerial.h>
 
 #define STATUS_LED 13
 #define RELE 12
 #define LOST_SIGNAL_TRASHOLD 30 * 1000
 #define LOOP_DELAY 250
 
-SoftwareSerial mySerial(RADIO_IN, 3);
-
-
-//create object
-SoftEasyTransfer ET; 
-
-struct RECEIVE_DATA_STRUCTURE{
-  //put your variable definitions here for the data you want to receive
-  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
-  short cmd;
-  int args;
-};
+EasyTransferVirtualWire ET; 
 
 //give a name to the group of data
-RECEIVE_DATA_STRUCTURE mydata;
-
-const short PING = 0;
-const short SWITCH_ON = 1;
-const short SWITCH_OFF = 2; 
+HOTSPOT_MSG mydata;
 
 unsigned long time;
 bool connectionLost;
 bool status;
 
 void setup(){
-  mySerial.begin(9600);
-  //start the library, pass in the data details and the name of the serial port.
-  ET.begin(details(mydata), &mySerial);
+  ET.begin(details(mydata));
+
+  // Initialise the IO and ISR
+  //vw_set_ptt_inverted(true); // Required for DR3100
+  vw_setup(2000);  // Bits per sec
+
+  vw_rx_start();       // Start the receiver PLL running
   
   pinMode(STATUS_LED, OUTPUT);
   pinMode(RELE, OUTPUT);
+
   time = millis();
   connectionLost = true;
   status = false;
       digitalWrite(STATUS_LED, status);
     }
   }
-  //you should make this delay shorter then your transmit delay or else messages could be lost
+  
   delay(LOOP_DELAY);
 }

termostato_tx/termostato_tx.ino

-#include <SoftEasyTransfer.h>
-#include <SoftwareSerial.h>
+#include <VirtualWire.h>
+#include <EasyTransferVirtualWire.h>
+#include "../termostato/protocol.h"
 
 #define GENERAl_SWITCH 7
 #define POT A5
 #define TEMP A2
-#define RADIO_OUT 3
+#define RADIO_OUT 2
 #define STATUS_LED 13
 
 // we tie 3.3V to ARef and measure it with a multimeter!
-#define aref_voltage 3.3    
+#define aref_voltage 5.0    
 #define TEMP_MIN 12
 #define TEMP_MAX 33
 
 
 
 
-SoftwareSerial mySerial(2, RADIO_OUT);
-SoftEasyTransfer ET; 
+EasyTransferVirtualWire ET; 
 
-struct SEND_DATA_STRUCTURE{
-  //put your variable definitions here for the data you want to receive
-  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
-  short cmd;
-  int args;
-};
+
 
 //give a name to the group of data
-SEND_DATA_STRUCTURE mydata;
+HOTSPOT_MSG mydata;
 
-const short PING = 0;
-const short SWITCH_ON = 1;
-const short SWITCH_OFF = 2; 
 
 long lastPing;
 bool status;
 
-void setup(){
-	Serial.begin(9600);
-  mySerial.begin(9600);
-  //start the library, pass in the data details and the name of the serial port.
-  ET.begin(details(mydata), &mySerial);
+void setup(){  
+  ET.begin(details(mydata));
+
+  // Initialise the IO and ISR
+  //vw_set_ptt_inverted(true); // Required for DR3100
+  vw_setup(2000);  // Bits per sec
   
   pinMode(STATUS_LED, OUTPUT);
   pinMode(GENERAl_SWITCH, INPUT);
   pinMode(POT, INPUT);
   pinMode(TEMP, INPUT);
    
-  analogReference(EXTERNAL);
- 	lastPing = 0;
- 	status = false;
- 	digitalWrite(STATUS_LED, status);
+  Serial.begin(9600);
+  //analogReference(EXTERNAL);
+  lastPing = 0;
+  status = false;
+  digitalWrite(STATUS_LED, status);
 }
 
 int getTemp() {
 void loop(){
 	long now = millis();
 	if(now - lastPing > PING_FREQ) {
+    lastPing = now;
 		mydata.cmd = PING;
 		mydata.args = (int)status;
 		ET.sendData();
 	if(status && temp > trashold) {
 		mydata.cmd = SWITCH_OFF;
 		mydata.args = 0;
+    status = false;
 		mustSend = true;
 	} else if (!status && temp < trashold) {
 		mydata.cmd = SWITCH_ON;
 		mydata.args = 0;
+    status = true;
 		mustSend = true;
 	}
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.