├── I2C_Wiring.png ├── UARTS_Wiring.png ├── EasyTransfer ├── I2C_Wiring.png ├── UARTS_Wiring.png ├── keywords.txt ├── examples │ ├── EasyTransfer_TX_Example │ │ └── EasyTransfer_TX_Example.pde │ ├── EasyTransfer_RX_Example │ │ └── EasyTransfer_RX_Example.pde │ ├── EasyTransfer_2Way_wPot_Example │ │ └── EasyTransfer_2Way_wPot_Example.pde │ └── EasyTransfer_2Way_wServo_Example │ │ └── EasyTransfer_2Way_wServo_Example.pde ├── EasyTransfer.h ├── EasyTransfer.cpp └── README.txt ├── EasyTransferI2C ├── keywords.txt ├── examples │ ├── EasyTransfer_TX_Example │ │ └── EasyTransfer_TX_Example.pde │ └── EasyTransfer_RX_Example │ │ └── EasyTransfer_RX_Example.pde ├── EasyTransferI2C.h └── EasyTransferI2C.cpp ├── SoftEasyTransfer ├── keywords.txt ├── examples │ ├── SoftEasyTransfer_TX_Example │ │ └── SoftEasyTransfer_TX_Example.pde │ └── SoftEasyTransfer_RX_Example │ │ └── SoftEasyTransfer_RX_Example.pde ├── SoftEasyTransfer.h └── SoftEasyTransfer.cpp ├── EasyTransferVirtualWire ├── keywords.txt ├── examples │ ├── ETVirtualWireDemoTX │ │ └── ETVirtualWireDemoTX.pde │ └── ETVirtualWireDemoRX │ │ └── ETVirtualWireDemoRX.pde ├── EasyTransferVirtualWire.cpp └── EasyTransferVirtualWire.h └── README.txt /I2C_Wiring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madsci1016/Arduino-EasyTransfer/HEAD/I2C_Wiring.png -------------------------------------------------------------------------------- /UARTS_Wiring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madsci1016/Arduino-EasyTransfer/HEAD/UARTS_Wiring.png -------------------------------------------------------------------------------- /EasyTransfer/I2C_Wiring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madsci1016/Arduino-EasyTransfer/HEAD/EasyTransfer/I2C_Wiring.png -------------------------------------------------------------------------------- /EasyTransfer/UARTS_Wiring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madsci1016/Arduino-EasyTransfer/HEAD/EasyTransfer/UARTS_Wiring.png -------------------------------------------------------------------------------- /EasyTransfer/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map EasyTransfer 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | EasyTransfer KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | sendData KEYWORD2 15 | receiveData KEYWORD2 16 | begin KEYWORD2 17 | 18 | 19 | ####################################### 20 | # Constants (LITERAL1) 21 | ####################################### 22 | details LITERAL1 23 | -------------------------------------------------------------------------------- /EasyTransferI2C/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map EasyTransfer 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | EasyTransferI2C KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | sendData KEYWORD2 15 | receiveData KEYWORD2 16 | begin KEYWORD2 17 | 18 | 19 | ####################################### 20 | # Constants (LITERAL1) 21 | ####################################### 22 | details LITERAL1 23 | -------------------------------------------------------------------------------- /SoftEasyTransfer/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map EasyTransfer 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SoftEasyTransfer KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | sendData KEYWORD2 15 | receiveData KEYWORD2 16 | begin KEYWORD2 17 | 18 | 19 | ####################################### 20 | # Constants (LITERAL1) 21 | ####################################### 22 | details LITERAL1 23 | -------------------------------------------------------------------------------- /EasyTransferVirtualWire/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map EasyTransfer 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | EasyTransferVirtualWire KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | sendData KEYWORD2 15 | receiveData KEYWORD2 16 | begin KEYWORD2 17 | 18 | 19 | ####################################### 20 | # Constants (LITERAL1) 21 | ####################################### 22 | details LITERAL1 23 | -------------------------------------------------------------------------------- /EasyTransfer/examples/EasyTransfer_TX_Example/EasyTransfer_TX_Example.pde: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //create object 4 | EasyTransfer ET; 5 | 6 | struct SEND_DATA_STRUCTURE{ 7 | //put your variable definitions here for the data you want to send 8 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 9 | int16_t blinks; 10 | int16_t pause; 11 | }; 12 | 13 | //give a name to the group of data 14 | SEND_DATA_STRUCTURE mydata; 15 | 16 | void setup(){ 17 | Serial.begin(9600); 18 | //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. 19 | ET.begin(details(mydata), &Serial); 20 | 21 | pinMode(13, OUTPUT); 22 | 23 | randomSeed(analogRead(0)); 24 | 25 | } 26 | 27 | void loop(){ 28 | //this is how you access the variables. [name of the group].[variable name] 29 | mydata.blinks = random(5); 30 | mydata.pause = random(5); 31 | //send the data 32 | ET.sendData(); 33 | 34 | //Just for fun, we will blink it out too 35 | for(int i = mydata.blinks; i>0; i--){ 36 | digitalWrite(13, HIGH); 37 | delay(mydata.pause * 100); 38 | digitalWrite(13, LOW); 39 | delay(mydata.pause * 100); 40 | } 41 | 42 | delay(5000); 43 | } 44 | -------------------------------------------------------------------------------- /EasyTransfer/examples/EasyTransfer_RX_Example/EasyTransfer_RX_Example.pde: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //create object 4 | EasyTransfer ET; 5 | 6 | struct RECEIVE_DATA_STRUCTURE{ 7 | //put your variable definitions here for the data you want to receive 8 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 9 | int16_t blinks; 10 | int16_t pause; 11 | }; 12 | 13 | //give a name to the group of data 14 | RECEIVE_DATA_STRUCTURE mydata; 15 | 16 | void setup(){ 17 | Serial.begin(9600); 18 | //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. 19 | ET.begin(details(mydata), &Serial); 20 | 21 | pinMode(13, OUTPUT); 22 | 23 | } 24 | 25 | void loop(){ 26 | //check and see if a data packet has come in. 27 | if(ET.receiveData()){ 28 | //this is how you access the variables. [name of the group].[variable name] 29 | //since we have data, we will blink it out. 30 | for(int i = mydata.blinks; i>0; i--){ 31 | digitalWrite(13, HIGH); 32 | delay(mydata.pause * 100); 33 | digitalWrite(13, LOW); 34 | delay(mydata.pause * 100); 35 | } 36 | } 37 | 38 | //you should make this delay shorter then your transmit delay or else messages could be lost 39 | delay(250); 40 | } 41 | -------------------------------------------------------------------------------- /EasyTransferI2C/examples/EasyTransfer_TX_Example/EasyTransfer_TX_Example.pde: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | //create object 5 | EasyTransferI2C ET; 6 | 7 | struct SEND_DATA_STRUCTURE{ 8 | //put your variable definitions here for the data you want to send 9 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 10 | int16_t blinks; 11 | int16_t pause; 12 | }; 13 | 14 | //give a name to the group of data 15 | SEND_DATA_STRUCTURE mydata; 16 | 17 | //define slave i2c address 18 | #define I2C_SLAVE_ADDRESS 9 19 | 20 | void setup(){ 21 | Wire.begin(); 22 | //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. 23 | ET.begin(details(mydata), &Wire); 24 | 25 | pinMode(13, OUTPUT); 26 | 27 | randomSeed(analogRead(0)); 28 | 29 | } 30 | 31 | void loop(){ 32 | //this is how you access the variables. [name of the group].[variable name] 33 | mydata.blinks = random(5); 34 | mydata.pause = random(5); 35 | //send the data 36 | ET.sendData(I2C_SLAVE_ADDRESS); 37 | 38 | //Just for fun, we will blink it out too 39 | for(int i = mydata.blinks; i>0; i--){ 40 | digitalWrite(13, HIGH); 41 | delay(mydata.pause * 100); 42 | digitalWrite(13, LOW); 43 | delay(mydata.pause * 100); 44 | } 45 | 46 | delay(5000); 47 | } 48 | -------------------------------------------------------------------------------- /EasyTransferI2C/examples/EasyTransfer_RX_Example/EasyTransfer_RX_Example.pde: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | //create object 5 | EasyTransferI2C ET; 6 | 7 | struct RECEIVE_DATA_STRUCTURE{ 8 | //put your variable definitions here for the data you want to receive 9 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 10 | int16_t blinks; 11 | int16_t pause; 12 | }; 13 | 14 | //give a name to the group of data 15 | RECEIVE_DATA_STRUCTURE mydata; 16 | 17 | //define slave i2c address 18 | #define I2C_SLAVE_ADDRESS 9 19 | 20 | void setup(){ 21 | Wire.begin(I2C_SLAVE_ADDRESS); 22 | //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. 23 | ET.begin(details(mydata), &Wire); 24 | //define handler function on receiving data 25 | Wire.onReceive(receive); 26 | 27 | pinMode(13, OUTPUT); 28 | 29 | } 30 | 31 | void loop() { 32 | //check and see if a data packet has come in. 33 | if(ET.receiveData()){ 34 | //this is how you access the variables. [name of the group].[variable name] 35 | //since we have data, we will blink it out. 36 | for(int i = mydata.blinks; i>0; i--){ 37 | digitalWrite(13, HIGH); 38 | delay(mydata.pause * 100); 39 | digitalWrite(13, LOW); 40 | delay(mydata.pause * 100); 41 | } 42 | } 43 | } 44 | 45 | void receive(int numBytes) {} 46 | -------------------------------------------------------------------------------- /EasyTransferVirtualWire/examples/ETVirtualWireDemoTX/ETVirtualWireDemoTX.pde: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | //create object 6 | EasyTransferVirtualWire ET; 7 | 8 | struct SEND_DATA_STRUCTURE{ 9 | //put your variable definitions here for the data you want to send 10 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 11 | //Struct can'e be bigger then 26 bytes for VirtualWire version 12 | int16_t blinks; 13 | int16_t pause; 14 | }; 15 | 16 | //give a name to the group of data 17 | SEND_DATA_STRUCTURE mydata; 18 | 19 | void setup(){ 20 | //start the library, pass in the data details 21 | ET.begin(details(mydata)); 22 | 23 | // Initialise the IO and ISR 24 | vw_set_ptt_inverted(true); // Required for DR3100 25 | vw_setup(2000); // Bits per sec 26 | 27 | pinMode(13, OUTPUT); 28 | 29 | randomSeed(analogRead(0)); 30 | 31 | } 32 | 33 | void loop(){ 34 | //this is how you access the variables. [name of the group].[variable name] 35 | mydata.blinks = random(5); 36 | mydata.pause = random(5); 37 | //send the data 38 | ET.sendData(); 39 | 40 | //Just for fun, we will blink it out too 41 | for(int i = mydata.blinks; i>0; i--){ 42 | digitalWrite(13, HIGH); 43 | delay(mydata.pause * 100); 44 | digitalWrite(13, LOW); 45 | delay(mydata.pause * 100); 46 | } 47 | 48 | delay(5000); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /SoftEasyTransfer/examples/SoftEasyTransfer_TX_Example/SoftEasyTransfer_TX_Example.pde: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* For Arduino 1.0 and newer, do this: */ 4 | #include 5 | SoftwareSerial mySerial(2, 3); 6 | 7 | /* For Arduino 22 and older, do this: */ 8 | //#include 9 | //NewSoftSerial mySerial(2, 3); 10 | 11 | 12 | 13 | //create object 14 | SoftEasyTransfer ET; 15 | 16 | struct SEND_DATA_STRUCTURE{ 17 | //put your variable definitions here for the data you want to send 18 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 19 | int16_t blinks; 20 | int16_t pause; 21 | }; 22 | 23 | //give a name to the group of data 24 | SEND_DATA_STRUCTURE mydata; 25 | 26 | void setup(){ 27 | mySerial.begin(9600); 28 | //start the library, pass in the data details and the name of the serial port. 29 | ET.begin(details(mydata), &mySerial); 30 | 31 | pinMode(13, OUTPUT); 32 | 33 | randomSeed(analogRead(0)); 34 | 35 | } 36 | 37 | void loop(){ 38 | //this is how you access the variables. [name of the group].[variable name] 39 | mydata.blinks = random(5); 40 | mydata.pause = random(5); 41 | //send the data 42 | ET.sendData(); 43 | 44 | //Just for fun, we will blink it out too 45 | for(int i = mydata.blinks; i>0; i--){ 46 | digitalWrite(13, HIGH); 47 | delay(mydata.pause * 100); 48 | digitalWrite(13, LOW); 49 | delay(mydata.pause * 100); 50 | } 51 | 52 | delay(5000); 53 | } 54 | -------------------------------------------------------------------------------- /SoftEasyTransfer/examples/SoftEasyTransfer_RX_Example/SoftEasyTransfer_RX_Example.pde: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* For Arduino 1.0 and newer, do this: */ 4 | #include 5 | SoftwareSerial mySerial(2, 3); 6 | 7 | /* For Arduino 22 and older, do this: */ 8 | //#include 9 | //NewSoftSerial mySerial(2, 3); 10 | 11 | 12 | //create object 13 | SoftEasyTransfer ET; 14 | 15 | struct RECEIVE_DATA_STRUCTURE{ 16 | //put your variable definitions here for the data you want to receive 17 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 18 | int16_t blinks; 19 | int16_t pause; 20 | }; 21 | 22 | //give a name to the group of data 23 | RECEIVE_DATA_STRUCTURE mydata; 24 | 25 | void setup(){ 26 | mySerial.begin(9600); 27 | //start the library, pass in the data details and the name of the serial port. 28 | ET.begin(details(mydata), &mySerial); 29 | 30 | pinMode(13, OUTPUT); 31 | 32 | } 33 | 34 | void loop(){ 35 | //check and see if a data packet has come in. 36 | if(ET.receiveData()){ 37 | //this is how you access the variables. [name of the group].[variable name] 38 | //since we have data, we will blink it out. 39 | for(int i = mydata.blinks; i>0; i--){ 40 | digitalWrite(13, HIGH); 41 | delay(mydata.pause * 100); 42 | digitalWrite(13, LOW); 43 | delay(mydata.pause * 100); 44 | } 45 | } 46 | //you should make this delay shorter then your transmit delay or else messages could be lost 47 | delay(250); 48 | } 49 | -------------------------------------------------------------------------------- /EasyTransferVirtualWire/examples/ETVirtualWireDemoRX/ETVirtualWireDemoRX.pde: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | //create object 6 | EasyTransferVirtualWire ET; 7 | 8 | struct SEND_DATA_STRUCTURE{ 9 | //put your variable definitions here for the data you want to send 10 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 11 | //Struct can'e be bigger then 26 bytes for VirtualWire version 12 | int16_t blinks; 13 | int16_t pause; 14 | }; 15 | 16 | //give a name to the group of data 17 | SEND_DATA_STRUCTURE mydata; 18 | 19 | void setup(){ 20 | //start the library, pass in the data details 21 | ET.begin(details(mydata)); 22 | 23 | // Initialise the IO and ISR 24 | vw_set_ptt_inverted(true); // Required for DR3100 25 | vw_setup(2000); // Bits per sec 26 | 27 | vw_rx_start(); // Start the receiver PLL running 28 | 29 | pinMode(13, OUTPUT); 30 | 31 | randomSeed(analogRead(0)); 32 | 33 | } 34 | 35 | void loop(){ 36 | //check and see if a data packet has come in. 37 | if(ET.receiveData()){ 38 | //this is how you access the variables. [name of the group].[variable name] 39 | //since we have data, we will blink it out. 40 | for(int i = mydata.blinks; i>0; i--){ 41 | digitalWrite(13, HIGH); 42 | delay(mydata.pause * 100); 43 | digitalWrite(13, LOW); 44 | delay(mydata.pause * 100); 45 | } 46 | } 47 | 48 | //you should make this delay shorter then your transmit delay or else messages could be lost 49 | delay(250); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /EasyTransferVirtualWire/EasyTransferVirtualWire.cpp: -------------------------------------------------------------------------------- 1 | #include "EasyTransferVirtualWire.h" 2 | #include 3 | 4 | //so to make this easy, I'm just making my library be another data 5 | // layer on top of Virtual wire. 6 | 7 | 8 | //Captures address and size of struct 9 | void EasyTransferVirtualWire::begin(uint8_t * ptr, uint8_t length) { //HardwareSerial *theSerial){ 10 | address = ptr; 11 | size = length; 12 | //_serial = theSerial; 13 | } 14 | 15 | //Sends out struct in binary, with header, length info and checksum 16 | void EasyTransferVirtualWire::sendData(){ 17 | 18 | //temp storage place 19 | uint8_t temp_buffer[size+4]; 20 | 21 | uint8_t CS = size; 22 | temp_buffer[0] = 0x06; 23 | temp_buffer[1] = 0x85; 24 | temp_buffer[2] = size; 25 | 26 | for(int i = 0; i 19 | * 20 | *This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. 21 | *To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or 22 | *send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. 23 | ******************************************************************/ 24 | #ifndef EasyTransfer_h 25 | #define EasyTransfer_h 26 | 27 | 28 | //make it a little prettier on the front end. 29 | #define details(name) (byte*)&name,sizeof(name) 30 | 31 | //Not neccessary, but just in case. 32 | #if ARDUINO > 22 33 | #include "Arduino.h" 34 | #else 35 | #include "WProgram.h" 36 | #endif 37 | #include "Stream.h" 38 | //#include 39 | //#include 40 | //#include 41 | //#include 42 | //#include 43 | 44 | class EasyTransfer { 45 | public: 46 | void begin(uint8_t *, uint8_t, Stream *theStream); 47 | //void begin(uint8_t *, uint8_t, NewSoftSerial *theSerial); 48 | void sendData(); 49 | boolean receiveData(); 50 | private: 51 | Stream *_stream; 52 | //NewSoftSerial *_serial; 53 | uint8_t * address; //address of struct 54 | uint8_t size; //size of struct 55 | uint8_t * rx_buffer; //address for temporary storage and parsing buffer 56 | uint8_t rx_array_inx; //index for RX parsing buffer 57 | uint8_t rx_len; //RX packet length according to the packet 58 | uint8_t calc_CS; //calculated Chacksum 59 | }; 60 | 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /EasyTransferI2C/EasyTransferI2C.h: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | * EasyTransferI2C Arduino Library 3 | * details and example sketch: 4 | * http://www.billporter.info/easytransfer-arduino-library/ 5 | * 6 | * Brought to you by: 7 | * Mathieu Alorent 8 | * Forked from 9 | * Bill Porter 10 | * www.billporter.info 11 | * 12 | * See Readme for other info and version history 13 | * 14 | * 15 | *This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version. 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | * 22 | *This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. 23 | *To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or 24 | *send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. 25 | ******************************************************************/ 26 | #ifndef EasyTransferI2C_h 27 | #define EasyTransferI2C_h 28 | 29 | 30 | //make it a little prettier on the front end. 31 | #define details(name) (byte*)&name,sizeof(name) 32 | 33 | //Not neccessary, but just in case. 34 | #if ARDUINO > 22 35 | #include "Arduino.h" 36 | #else 37 | #include "WProgram.h" 38 | #endif 39 | #include "HardwareSerial.h" 40 | //#include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | class EasyTransferI2C { 48 | public: 49 | void begin(uint8_t *, uint8_t, TwoWire *theSerial); 50 | void sendData(uint8_t address); 51 | boolean receiveData(); 52 | private: 53 | TwoWire *_serial; 54 | //NewSoftSerial *_serial; 55 | uint8_t * address; //address of struct 56 | uint8_t size; //size of struct 57 | uint8_t * rx_buffer; //address for temporary storage and parsing buffer 58 | uint8_t rx_array_inx; //index for RX parsing buffer 59 | uint8_t rx_len; //RX packet length according to the packet 60 | uint8_t calc_CS; //calculated Chacksum 61 | }; 62 | 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /EasyTransferVirtualWire/EasyTransferVirtualWire.h: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | * EasyTransferVirtualWire Arduino Library 3 | * details and example sketch: 4 | * http://www.billporter.info/easytransfer-arduino-library/ 5 | * 6 | * Brought to you by: 7 | * Bill Porter 8 | * www.billporter.info 9 | * 10 | * See Readme for other info and version history 11 | * 12 | * 13 | *This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version. 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | * 20 | *This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. 21 | *To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or 22 | *send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. 23 | ******************************************************************/ 24 | #ifndef EasyTransferVirtualWire_h 25 | #define EasyTransferVirtualWire_h 26 | 27 | 28 | //make it a little prettier on the front end. 29 | #define details(name) (byte*)&name,sizeof(name) 30 | 31 | //Not neccessary, but just in case. 32 | #if ARDUINO > 22 33 | #include "Arduino.h" 34 | #else 35 | #include "WProgram.h" 36 | #endif 37 | #include 38 | //#include "HardwareSerial.h" 39 | //#include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | class EasyTransferVirtualWire { 46 | public: 47 | void begin(uint8_t *, uint8_t); 48 | //void begin(uint8_t *, uint8_t, NewSoftSerial *theSerial); 49 | void sendData(); 50 | boolean receiveData(); 51 | private: 52 | //HardwareSerial *_serial; 53 | //NewSoftSerial *_serial; 54 | uint8_t * address; //address of struct 55 | uint8_t size; //size of struct 56 | uint8_t rx_len; //RX packet length according to the packet 57 | uint8_t rx_array[255]; //RX packet parsing buffer 58 | uint8_t rx_array_inx; //index for RX parsing buffer 59 | uint8_t calc_CS; //calculated Chacksum 60 | }; 61 | 62 | 63 | 64 | #endif -------------------------------------------------------------------------------- /SoftEasyTransfer/SoftEasyTransfer.h: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | * EasyTransfer Arduino Library 3 | * details and example sketch: 4 | * http://www.billporter.info/easytransfer-arduino-library/ 5 | * 6 | * Brought to you by: 7 | * Bill Porter 8 | * www.billporter.info 9 | * 10 | * See Readme for other info and version history 11 | * 12 | * 13 | *This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version. 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | * 20 | *This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. 21 | *To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or 22 | *send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. 23 | ******************************************************************/ 24 | #ifndef SoftEasyTransfer_h 25 | #define SoftEasyTransfer_h 26 | 27 | 28 | //make it a little prettier on the front end. 29 | #define details(name) (byte*)&name,sizeof(name) 30 | 31 | //Not neccessary, but just in case. 32 | #if ARDUINO > 22 33 | #include "Arduino.h" 34 | #include 35 | #else 36 | #include "WProgram.h" 37 | #include 38 | #endif 39 | //#include "HardwareSerial.h" 40 | 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | class SoftEasyTransfer { 48 | public: 49 | //void begin(uint8_t *, uint8_t, HardwareSerial *theSerial); 50 | #if ARDUINO > 22 51 | void begin(uint8_t *, uint8_t, SoftwareSerial *theSerial); 52 | #else 53 | void begin(uint8_t *, uint8_t, NewSoftSerial *theSerial); 54 | #endif 55 | void sendData(); 56 | boolean receiveData(); 57 | private: 58 | //HardwareSerial *_serial; 59 | 60 | #if ARDUINO > 22 61 | SoftwareSerial *_serial; 62 | #else 63 | NewSoftSerial *_serial; 64 | #endif 65 | 66 | 67 | uint8_t * address; //address of struct 68 | uint8_t size; //size of struct 69 | uint8_t * rx_buffer; //address for temporary storage and parsing buffer 70 | uint8_t rx_array_inx; //index for RX parsing buffer 71 | uint8_t rx_len; //RX packet length according to the packet 72 | uint8_t calc_CS; //calculated Chacksum 73 | }; 74 | 75 | 76 | 77 | #endif -------------------------------------------------------------------------------- /EasyTransfer/EasyTransfer.cpp: -------------------------------------------------------------------------------- 1 | #include "EasyTransfer.h" 2 | 3 | 4 | 5 | 6 | //Captures address and size of struct 7 | void EasyTransfer::begin(uint8_t * ptr, uint8_t length, Stream *theStream){ 8 | rx_len = 0; 9 | rx_array_inx = 0; 10 | address = ptr; 11 | size = length; 12 | _stream = theStream; 13 | 14 | //dynamic creation of rx parsing buffer in RAM 15 | rx_buffer = (uint8_t*) malloc(size+1); 16 | } 17 | 18 | //Sends out struct in binary, with header, length info and checksum 19 | void EasyTransfer::sendData(){ 20 | uint8_t CS = size; 21 | _stream->write(0x06); 22 | _stream->write(0x85); 23 | _stream->write(size); 24 | for(int i = 0; iwrite(*(address+i)); 27 | } 28 | _stream->write(CS); 29 | 30 | } 31 | 32 | boolean EasyTransfer::receiveData(){ 33 | 34 | //start off by looking for the header bytes. If they were already found in a previous call, skip it. 35 | if(rx_len == 0){ 36 | //this size check may be redundant due to the size check below, but for now I'll leave it the way it is. 37 | if(_stream->available() >= 3){ 38 | //this will block until a 0x06 is found or buffer size becomes less then 3. 39 | while(_stream->read() != 0x06) { 40 | //This will trash any preamble junk in the serial buffer 41 | //but we need to make sure there is enough in the buffer to process while we trash the rest 42 | //if the buffer becomes too empty, we will escape and try again on the next call 43 | if(_stream->available() < 3) 44 | return false; 45 | } 46 | if (_stream->read() == 0x85){ 47 | rx_len = _stream->read(); 48 | //make sure the binary structs on both Arduinos are the same size. 49 | if(rx_len != size){ 50 | rx_len = 0; 51 | return false; 52 | } 53 | } 54 | } 55 | } 56 | 57 | //we get here if we already found the header bytes, the struct size matched what we know, and now we are byte aligned. 58 | if(rx_len != 0){ 59 | while(_stream->available() && rx_array_inx <= rx_len){ 60 | rx_buffer[rx_array_inx++] = _stream->read(); 61 | } 62 | 63 | if(rx_len == (rx_array_inx-1)){ 64 | //seem to have got whole message 65 | //last uint8_t is CS 66 | calc_CS = rx_len; 67 | for (int i = 0; i 19 | 20 | //create two objects 21 | EasyTransfer ETin, ETout; 22 | 23 | 24 | struct RECEIVE_DATA_STRUCTURE{ 25 | //put your variable definitions here for the data you want to receive 26 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 27 | int16_t buttonstate; 28 | }; 29 | 30 | struct SEND_DATA_STRUCTURE{ 31 | //put your variable definitions here for the data you want to receive 32 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 33 | int16_t buttonstate; 34 | int16_t servoval; 35 | }; 36 | 37 | //give a name to the group of data 38 | RECEIVE_DATA_STRUCTURE rxdata; 39 | SEND_DATA_STRUCTURE txdata; 40 | 41 | 42 | void setup(){ 43 | Serial.begin(9600); 44 | //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. 45 | ETin.begin(details(rxdata), &Serial); 46 | ETout.begin(details(txdata), &Serial); 47 | 48 | pinMode(13, OUTPUT); 49 | //enable pull-up 50 | pinMode(12, INPUT_PULLUP); 51 | 52 | } 53 | 54 | void loop(){ 55 | 56 | //first, lets read our potentiometer and button and store it in our data structure 57 | txdata.servoval = analogRead(0); 58 | 59 | if(!digitalRead(12)) 60 | txdata.buttonstate = HIGH; 61 | else 62 | txdata.buttonstate = LOW; 63 | 64 | //then we will go ahead and send that data out 65 | ETout.sendData(); 66 | 67 | //there's a loop here so that we run the recieve function more often then the 68 | //transmit function. This is important due to the slight differences in 69 | //the clock speed of different Arduinos. If we didn't do this, messages 70 | //would build up in the buffer and appear to cause a delay. 71 | for(int i=0; i<5; i++){ 72 | //remember, you could use an if() here to check for new data, this time it's not needed. 73 | ETin.receiveData(); 74 | 75 | //set our LED on or off based on what we received from the other Arduino 76 | digitalWrite(13, rxdata.buttonstate); 77 | 78 | //delay 79 | delay(10); 80 | } 81 | 82 | //delay for good measure 83 | delay(10); 84 | } 85 | -------------------------------------------------------------------------------- /EasyTransfer/README.txt: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | * EasyTransfer Arduino Library v1.7 3 | * details and example sketch: 4 | * http://www.billporter.info/easytransfer-arduino-library/ 5 | * 6 | * Brought to you by: 7 | * Bill Porter 8 | * www.billporter.info 9 | * 10 | * Lib version history 11 | * 1.0 Created 12 | * 1.1 Fixed dumb Copy-paste error in header file 13 | * Added a keyword file 14 | * 1.5 Forked lib into Software and Hardware Serial branches, I don't know a better way 15 | * added passing in of Serial port of different types 16 | * 1.6 Fixed bug where it wasn't clearing out the buffers if the CheckSum failed, 17 | * I'm good at dumb mistakes 18 | * 1.7 Fixed a bug where the receive function could block for too long and never process data correctly 19 | * Organized the examples to be Arduino IDE compatible 20 | * 1.8 21 | * Now Arduino 1.0 compatible! 22 | * 23 | * 24 | * Limits of the Library 25 | * You can change the Serial port, 26 | * but the Struct size must not pass 255 bytes 27 | * 28 | * The protcol is as follows: 29 | * Header(0x06,0x85),SizeofPayload,Payload,Checksum 30 | * 31 | * 32 | *This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version. 33 | This program is distributed in the hope that it will be useful, 34 | but WITHOUT ANY WARRANTY; without even the implied warranty of 35 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 36 | GNU General Public License for more details. 37 | 38 | * 39 | *This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. 40 | *To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or 41 | *send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. 42 | ******************************************************************/ 43 | 44 | 45 | ********************To Install************************************* 46 | 47 | To install, unzip and place 'EasyTransfer' folder into your 'C:\Users\{user name}\Documents\Arduino\libraries' folder or '{Arduino IDE path}\hardware\libraries" or {Arduino IDE path}\libraries" directory. 48 | 49 | Restart the Arduino IDE, look for the Library under "Sketch" -> "Import Library". You can also try the examples by finding them 50 | under "File" -> "Examples" -> "EasyTransfer". 51 | 52 | All uses of the library are in the example sketchs. 53 | 54 | 55 | ******************************************************************* 56 | 57 | 58 | Library now has two versions, one for regular hardware Serial, one for use with the NewSoftSerial library 59 | making any Arduino pin capable of transfering data back and forth easily. 60 | 61 | See the examples to find out how to use the library. -------------------------------------------------------------------------------- /EasyTransfer/examples/EasyTransfer_2Way_wServo_Example/EasyTransfer_2Way_wServo_Example.pde: -------------------------------------------------------------------------------- 1 | /*This is an example of the EasyTransfer Library 2way communications. 2 | 3 | This sketch is for the Arduino with the servo attached to pin 9. 4 | 5 | The other Arduino has a potentiometer attached to analog pin 0. 6 | Both have a putton attached to pin 12 and output a status using the LED on pin 13. 7 | 8 | The idea is each arduino will read the status of the button attached to it, and send it 9 | to the other Arduino, which will toggle it's LED based on the others button. The button 10 | should connect pin 12 to ground when pushed. 11 | 12 | And the Arduino with the potentiometer will send it's value to the one with the servo. 13 | The servo will move to the position based on the potentiometer. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | //create two objects 20 | EasyTransfer ETin, ETout; 21 | //create servo 22 | Servo myservo; 23 | 24 | struct RECEIVE_DATA_STRUCTURE{ 25 | //put your variable definitions here for the data you want to receive 26 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 27 | int16_t buttonstate; 28 | int16_t servoval; 29 | }; 30 | 31 | struct SEND_DATA_STRUCTURE{ 32 | //put your variable definitions here for the data you want to receive 33 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO 34 | int16_t buttonstate; 35 | }; 36 | 37 | 38 | //give a name to the group of data 39 | RECEIVE_DATA_STRUCTURE rxdata; 40 | SEND_DATA_STRUCTURE txdata; 41 | 42 | 43 | void setup(){ 44 | Serial.begin(9600); 45 | //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. 46 | ETin.begin(details(rxdata), &Serial); 47 | ETout.begin(details(txdata), &Serial); 48 | 49 | pinMode(13, OUTPUT); 50 | //enable pull-up 51 | pinMode(12, INPUT_PULLUP); 52 | 53 | myservo.attach(9); 54 | } 55 | 56 | void loop(){ 57 | 58 | //first, lets read our button and store it in our data structure 59 | if(!digitalRead(12)) 60 | txdata.buttonstate = HIGH; 61 | else 62 | txdata.buttonstate = LOW; 63 | 64 | //then we will go ahead and send that data out 65 | ETout.sendData(); 66 | 67 | //there's a loop here so that we run the recieve function more often then the 68 | //transmit function. This is important due to the slight differences in 69 | //the clock speed of different Arduinos. If we didn't do this, messages 70 | //would build up in the buffer and appear to cause a delay. 71 | 72 | for(int i=0; i<5; i++){ 73 | //remember, you could use an if() here to check for new data, this time it's not needed. 74 | ETin.receiveData(); 75 | 76 | //set our LED on or off based on what we received from the other Arduino 77 | digitalWrite(13, rxdata.buttonstate); 78 | 79 | //set our servo position based on what we received from the other Arduino 80 | //we will also map the ADC value to a servo value 81 | myservo.write(map(rxdata.servoval, 0, 1023, 0, 179)); 82 | 83 | //delay 84 | delay(10); 85 | } 86 | 87 | //delay for good measure 88 | delay(10); 89 | } 90 | -------------------------------------------------------------------------------- /EasyTransferI2C/EasyTransferI2C.cpp: -------------------------------------------------------------------------------- 1 | #include "EasyTransferI2C.h" 2 | 3 | 4 | 5 | 6 | //Captures address and size of struct 7 | void EasyTransferI2C::begin(uint8_t * ptr, uint8_t length, TwoWire *theSerial){ 8 | rx_len = 0; 9 | rx_array_inx = 0; 10 | address = ptr; 11 | size = length; 12 | _serial = theSerial; 13 | 14 | //dynamic creation of rx parsing buffer in RAM 15 | rx_buffer = (uint8_t*) malloc(size); 16 | } 17 | 18 | //Sends out struct in binary, with header, length info and checksum 19 | void EasyTransferI2C::sendData(uint8_t i2c_address){ 20 | uint8_t CS = size; 21 | _serial->beginTransmission(i2c_address); 22 | #if ARDUINO >= 100 23 | _serial->write(0x06); 24 | _serial->write(0x85); 25 | _serial->write(size); 26 | #else 27 | _serial->send(0x06); 28 | _serial->send(0x85); 29 | _serial->send(size); 30 | #endif 31 | for(int i = 0; i= 100 34 | _serial->write(*(address+i)); 35 | #else 36 | _serial->send(*(address+i)); 37 | #endif 38 | } 39 | #if ARDUINO >= 100 40 | _serial->write(CS); 41 | #else 42 | _serial->send(CS); 43 | #endif 44 | _serial->endTransmission(); 45 | } 46 | 47 | boolean EasyTransferI2C::receiveData(){ 48 | 49 | //start off by looking for the header bytes. If they were already found in a previous call, skip it. 50 | if(rx_len == 0){ 51 | //this size check may be redundant due to the size check below, but for now I'll leave it the way it is. 52 | if(_serial->available() >= 3){ 53 | //this will block until a 0x06 is found or buffer size becomes less then 3. 54 | #if ARDUINO >= 100 55 | while(_serial->read() != 0x06) { 56 | #else 57 | while(_serial->receive() != 0x06) { 58 | #endif 59 | //This will trash any preamble junk in the serial buffer 60 | //but we need to make sure there is enough in the buffer to process while we trash the rest 61 | //if the buffer becomes too empty, we will escape and try again on the next call 62 | if(_serial->available() < 3) 63 | return false; 64 | } 65 | #if ARDUINO >= 100 66 | if (_serial->read() == 0x85){ 67 | rx_len = _serial->read(); 68 | #else 69 | if (_serial->receive() == 0x85){ 70 | rx_len = _serial->receive(); 71 | #endif 72 | //make sure the binary structs on both Arduinos are the same size. 73 | if(rx_len != size){ 74 | rx_len = 0; 75 | return false; 76 | } 77 | } 78 | } 79 | } 80 | 81 | //we get here if we already found the header bytes, the struct size matched what we know, and now we are byte aligned. 82 | if(rx_len != 0){ 83 | while(_serial->available() && rx_array_inx <= rx_len){ 84 | #if ARDUINO >= 100 85 | rx_buffer[rx_array_inx++] = _serial->read(); 86 | #else 87 | rx_buffer[rx_array_inx++] = _serial->receive(); 88 | #endif 89 | } 90 | 91 | if(rx_len == (rx_array_inx-1)){ 92 | //seem to have got whole message 93 | //last uint8_t is CS 94 | calc_CS = rx_len; 95 | for (int i = 0; i 52 | * 53 | *This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. 54 | *To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or 55 | *send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. 56 | ******************************************************************/ 57 | 58 | 59 | ********************To Install************************************* 60 | 61 | To install, unzip and place 'EasyTransfer' folder into your 'C:\Users\{user name}\Documents\Arduino\libraries' folder or '{Arduino IDE path}\hardware\libraries" or {Arduino IDE path}\libraries" directory. 62 | 63 | Restart the Arduino IDE, look for the Library under "Sketch" -> "Import Library". You can also try the examples by finding them 64 | under "File" -> "Examples" -> "EasyTransfer". 65 | 66 | All uses of the library are in the example sketchs. 67 | 68 | 69 | ******************************************************************* 70 | 71 | 72 | Library now has two versions, one for regular hardware Serial, one for use with the NewSoftSerial library 73 | making any Arduino pin capable of transfering data back and forth easily. 74 | 75 | See the examples to find out how to use the library. -------------------------------------------------------------------------------- /SoftEasyTransfer/SoftEasyTransfer.cpp: -------------------------------------------------------------------------------- 1 | #include "SoftEasyTransfer.h" 2 | 3 | 4 | 5 | 6 | #if ARDUINO > 22 7 | //Captures address and size of struct 8 | void SoftEasyTransfer::begin(uint8_t * ptr, uint8_t length, SoftwareSerial *theSerial){ 9 | rx_len = 0; 10 | rx_array_inx = 0; 11 | address = ptr; 12 | size = length; 13 | _serial = theSerial; 14 | 15 | //dynamic creation of rx parsing buffer in RAM 16 | rx_buffer = (uint8_t*) malloc(size); 17 | } 18 | 19 | #else 20 | //Captures address and size of struct 21 | void SoftEasyTransfer::begin(uint8_t * ptr, uint8_t length, NewSoftSerial *theSerial){ 22 | rx_len = 0; 23 | rx_array_inx = 0; 24 | address = ptr; 25 | size = length; 26 | _serial = theSerial; 27 | 28 | //dynamic creation of rx parsing buffer in RAM 29 | rx_buffer = (uint8_t*) malloc(size); 30 | } 31 | 32 | #endif 33 | 34 | #if ARDUINO > 22 35 | //Sends out struct in binary, with header, length info and checksum 36 | void SoftEasyTransfer::sendData(){ 37 | uint8_t CS = size; 38 | _serial->write(0x06); 39 | _serial->write(0x85); 40 | _serial->write(size); 41 | for(int i = 0; iwrite(*(address+i)); 44 | } 45 | _serial->write(CS); 46 | 47 | } 48 | #else 49 | //Sends out struct in binary, with header, length info and checksum 50 | void SoftEasyTransfer::sendData(){ 51 | uint8_t CS = size; 52 | _serial->print(0x06, BYTE); 53 | _serial->print(0x85, BYTE); 54 | _serial->print(size, BYTE); 55 | for(int i = 0; iprint(*(address+i), BYTE); 58 | } 59 | _serial->print(CS, BYTE); 60 | 61 | } 62 | #endif 63 | 64 | boolean SoftEasyTransfer::receiveData(){ 65 | 66 | //start off by looking for the header bytes. If they were already found in a previous call, skip it. 67 | if(rx_len == 0){ 68 | //this size check may be redundant due to the size check below, but for now I'll leave it the way it is. 69 | if(_serial->available() >= 3){ 70 | //this will block until a 0x06 is found or buffer size becomes less then 3. 71 | while(_serial->read() != 0x06) { 72 | //This will trash any preamble junk in the serial buffer 73 | //but we need to make sure there is enough in the buffer to process while we trash the rest 74 | //if the buffer becomes too empty, we will escape and try again on the next call 75 | if(_serial->available() < 3) 76 | return false; 77 | } 78 | if (_serial->read() == 0x85){ 79 | rx_len = _serial->read(); 80 | //make sure the binary structs on both Arduinos are the same size. 81 | if(rx_len != size){ 82 | rx_len = 0; 83 | return false; 84 | } 85 | } 86 | } 87 | } 88 | 89 | 90 | 91 | if(rx_len != 0){ 92 | while(_serial->available() && rx_array_inx <= rx_len){ 93 | rx_buffer[rx_array_inx++] = _serial->read(); 94 | } 95 | 96 | if(rx_len == (rx_array_inx-1)){ 97 | //seem to have got whole message 98 | //last uint8_t is CS 99 | calc_CS = rx_len; 100 | for (int i = 0; i