Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A ctachup after a long time off-air.
- Loading branch information
Showing
48 changed files
with
7,527 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
/* | ||
Manchester Decoding, reading by delay rather than interrupt | ||
Rob Ward August 2014 | ||
This example code is in the public domain. | ||
Use at your own risk, I will take no responsibility for any loss whatsoever its deployment. | ||
Visit https://github.com/robwlakes/433MHz_Tx_Rx | ||
for the latest version and documentation. | ||
Filename: Receiver1.ino (receives the broadcast) | ||
Filename: Transmitter5.ino (makes the broadcast) | ||
*/ | ||
|
||
//Interface Definitions | ||
int RxPin = 8; //The number of signal from the Rx | ||
int ledPin = 13; //The number of the onboard LED pin | ||
|
||
// Variables for Manchester Receiver Logic: | ||
word sDelay = 250; //Small Delay about 1/4 of bit duration try like 250 to 500 | ||
word lDelay = 500; //Long Delay about 1/2 of bit duration try like 500 to 1000, 1/4 + 1/2 = 3/4 | ||
byte polarity = 0; //0 for lo->hi==1 or 1 for hi->lo==1 for Polarity, sets tempBit at start | ||
byte tempBit = 1; //Reflects the required transition polarity | ||
byte discards = 1; //how many leading "bits" need to be dumped, usually just a zero if anything eg discards=1 | ||
byte discNos = 0; //counter of how many discarded | ||
boolean firstZero = false;//has it processed the first zero yet? This a "sync" bit. | ||
boolean noErrors = true; //flags if signal does not follow Manchester conventions | ||
//variables for Header detection | ||
byte headerBits = 10; //The number of ones expected to make a valid header | ||
byte headerHits = 0; //Counts the number of "1"s to determine a header | ||
//Variables for Byte storage | ||
byte dataByte = 0; //Accumulates the bit information | ||
byte nosBits = 0; //Counts to 8 bits within a dataByte | ||
byte maxBytes = 9; //Set the bytes collected after each header. NB if set too high, any end noise will cause an error | ||
byte nosBytes = 0; //Counter stays within 0 -> maxBytes | ||
//Variables for multiple packets | ||
byte bank = 0; //Points to the array of 0 to 3 banks of results from up to 4 last data downloads | ||
byte nosRepeats = 0; //Number of times the header/data is fetched at least once or up to 4 times | ||
//Banks for multiple packets if required (at least one will be needed) | ||
byte manchester[4][20]; //Stores 4 banks of manchester pattern decoded on the fly | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
pinMode(RxPin, INPUT); | ||
pinMode(ledPin, OUTPUT); | ||
Serial.println("Debug Manchester Rx+Tx"); | ||
lDelay=2*sDelay; | ||
Serial.print("Using a delay of 1/4 bitWaveform "); | ||
Serial.print(sDelay,DEC); | ||
Serial.print(" uSecs 1/2 bitWaveform "); | ||
Serial.print(lDelay,DEC); | ||
Serial.println(" uSecs "); | ||
if (polarity){ | ||
Serial.println("Negative Polarity hi->lo=1"); | ||
} | ||
else{ | ||
Serial.println("Positive Polarity lo->hi=1"); | ||
} | ||
Serial.print(headerBits,DEC); | ||
Serial.println(" bits expected for a valid header"); | ||
if (discards){ | ||
Serial.print(discards,DEC); | ||
Serial.println(" leading bits discarded from Packet"); | ||
} | ||
else{ | ||
Serial.println("All bits inside the Packet"); | ||
} | ||
Serial.println("D 00 00001111 01 22223333 02 44445555 03 66667777 04 88889999 05 AAAABBBB 06 CCCCDDDD 07 EEEEFFFF 08 00001111 90 22223333"); | ||
eraseManchester(); | ||
} | ||
|
||
// Main routines, find header, then sync in with it, get a packet, and decode data in it, plus report any errors. | ||
void loop(){ | ||
tempBit =polarity^1; | ||
noErrors =true; | ||
firstZero =false; | ||
headerHits =0; | ||
nosBits =0; | ||
nosBytes =0; | ||
discNos =discards; | ||
|
||
while (noErrors && (nosBytes<maxBytes)){ | ||
while(digitalRead(RxPin)!=tempBit){ | ||
} | ||
delayMicroseconds(sDelay); | ||
digitalWrite(ledPin,0); | ||
if (digitalRead(RxPin)!=tempBit){ | ||
noErrors=false; | ||
} | ||
else{ | ||
byte bitState = tempBit ^ polarity; | ||
delayMicroseconds(lDelay); | ||
if(digitalRead(RxPin)==tempBit){ | ||
tempBit = tempBit^1; | ||
} | ||
if(bitState==1){ | ||
if(!firstZero){ | ||
headerHits++; | ||
if (headerHits==headerBits){ | ||
digitalWrite(ledPin,1); | ||
} | ||
} | ||
else{ | ||
add(bitState); | ||
} | ||
} | ||
else{ | ||
if(headerHits<headerBits){ | ||
noErrors=false; | ||
} | ||
else{ | ||
if ((!firstZero)&&(headerHits>=headerBits)){ | ||
firstZero=true; | ||
} | ||
add(bitState); | ||
} | ||
} | ||
} | ||
} | ||
digitalWrite(ledPin,0); | ||
} | ||
|
||
void analyseData(){ | ||
} | ||
|
||
void add(byte bitData){ | ||
if (discNos>0){ | ||
discNos--; | ||
} | ||
else{ //add bit into byte | ||
dataByte=(dataByte<<1)|bitData; | ||
nosBits++; | ||
if (nosBits==8){ //add byte into bank | ||
nosBits=0; | ||
manchester[bank][nosBytes]=dataByte; | ||
nosBytes++; | ||
} | ||
if(nosBytes==maxBytes){ | ||
if (checkBanks()){ | ||
hexBinDump();//show the data | ||
nosBytes=0; | ||
bank=0; | ||
eraseManchester(); //"jumble it up" | ||
} | ||
bank=(bank+1)%4; //modulo 4 bank pointer | ||
} | ||
} | ||
} | ||
|
||
//Properly dump the banks in formatted hex and Binary with leading zeroes | ||
void hexBinDump(){ | ||
Serial.print("D "); | ||
for( int i=0; i < maxBytes; i++){ | ||
byte mask = B10000000; | ||
if (manchester[bank][i]<16){ | ||
Serial.print("0"); | ||
} | ||
Serial.print(manchester[bank][i],HEX); | ||
Serial.print(" "); | ||
for (int k=0; k<8; k++){ | ||
if (manchester[bank][i] & mask){ | ||
Serial.print("1"); | ||
} | ||
else{ | ||
Serial.print("0"); | ||
} | ||
mask = mask >> 1; | ||
} | ||
Serial.print(" "); | ||
} | ||
Serial.println(); | ||
} | ||
|
||
void eraseManchester(){ | ||
for( int j=0; j < 4; j++){ | ||
for( int i=0; i < 20; i++){ | ||
manchester[j][i]=j+i;//make each byte in each bank different | ||
} | ||
} | ||
} | ||
|
||
|
||
boolean checkBanks(){ //checks one bank against the other three | ||
//check the four versions are the same, best quality data, maybe too high? | ||
boolean valid = true; | ||
for( int i=1; i < 4; i++){ //Checking all four banks | ||
for (int j=0; j<maxBytes; j++){ //NB we are checking up to maxBytes | ||
if (manchester[0][j] != manchester[i][j]){ | ||
valid = false; | ||
} | ||
} | ||
} | ||
return valid; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
Manchester Decoding, reading by delay rather than interrupt | ||
Rob Ward August 2014 | ||
This example code is in the public domain. | ||
Use at your own risk, I will take no responsibility for any loss whatsoever its deployment. | ||
Visit https://github.com/robwlakes/433MHz_Tx_Rx | ||
for the latest version and documentation. | ||
Filename: Receiver1.ino (receives the broadcast) | ||
Filename: Transmitter5.ino (makes the broadcast) | ||
*/ | ||
|
||
const int TxPin = 8; // the TxPin applied to the 433MHz modulator pin | ||
const int ledPin = 13; // the number of the onboard LED pin | ||
|
||
byte thisBit; //reflects the current data bit polarity, | ||
|
||
byte manchester[16]; //stores a bank of data to be manchester encoded on the fly, say first 8 bytes | ||
byte bytePointer = 0; //increments through manchester[data] | ||
byte maxBytes = 9; //number of bytes transmitted | ||
|
||
word sDelay = 500; //1/2 of bit pattern duration, begin with 500uS (a common choice, data bit length = 1ms) | ||
|
||
void setup(){ | ||
pinMode(TxPin, OUTPUT); | ||
pinMode(ledPin, OUTPUT); | ||
//The following format relates to the Weather stations, mainly because I wanted to incorporate | ||
//extra data from other remote RF sensors into my WWW server's weather pages. | ||
//This would work with the now legacy Bios or Thermor series (They repeat data 4 times to detect errors). | ||
//Hence I need to be able to make the Tx use a compatible protocol to simplify the receiver program logic | ||
//that decodes the protocol. As the Tx mimics a sensor it would need to alert the receiver to be able to | ||
//distinguish multiple transmitters/sensors apart. ie different ID number's etc so they don't clash with | ||
// the existing transmitters. | ||
//Obviously other users may like to determine their own format or adapt it to their own weather station protocols. | ||
// | ||
//Dummy data in the Manchester Byte Array (just to test it out). | ||
manchester[0] = B01110001; //eg Brand/Sensor ID, can be from 0 to 255 | ||
manchester[1] = B00000111; //eg Packet type (wind, rain, solar, UV etc) | ||
manchester[2] = 2; //dummy data | ||
manchester[3] = B10101010; //dummy data | ||
manchester[4] = B11110000; //dummy data | ||
manchester[5] = 5; //dummy data, incremented | ||
manchester[6] = 6; //dummy data, decremented | ||
manchester[7] = 7; //dummy data | ||
manchester[8] = B00110011; //dummy data | ||
Serial.begin(115200); | ||
Serial.println("Transmitter On Air....");//Just to check if you like | ||
} | ||
|
||
void loop(){ | ||
digitalWrite(ledPin,HIGH); | ||
manchester[5]++;//just tickle over the bits in the number to show it can change | ||
manchester[6]--;//as above | ||
//repeat 4 times over as a simple, but very effective, "checksum" system to validate data | ||
for (int packet=0;packet<4;packet++){ | ||
digitalWrite(TxPin,0); //begin on Signal Off | ||
for (int j=0;j<30;j++){ //header 30 of 1's, probably excessive, 20 could be enough | ||
Tx1(); //Send 1's as it stabilises the Rx's AGC the quickest | ||
} | ||
Tx0(); //put in a single 0 as the first "Start Bit", indicates end of Header bit stream of 1's | ||
bytePointer = 0; //Point to start of manchester array | ||
for (bytePointer =0;bytePointer<maxBytes;bytePointer++){ | ||
byte mask = B10000000; //MSB -> LSB | ||
for (int k=0;k<8;k++){ | ||
thisBit = mask & manchester[bytePointer]; //thisBit!=0 means the bit in that spot is a 1 | ||
if (thisBit == 0){ | ||
Tx0(); //Send a 0 | ||
} | ||
else{ | ||
Tx1(); //Send a 1 | ||
} | ||
mask = mask >> 1;//move to the next bit in manchester[bytePointer] | ||
}//end of checking a byte, 1 bit a a time MSB to LSB | ||
}//end of the machester[bytePointer] | ||
digitalWrite(TxPin,0); //End packet on Signal Off | ||
delay(20); //break between repeating packets | ||
}//end of 4 repeats of packet data burst | ||
digitalWrite(ledPin,LOW); //just for debugging | ||
//Wait for 30 Seconds before next transmission | ||
for (int second=0;second<30;second++){ | ||
delay(1000); //a Second | ||
} | ||
} | ||
|
||
//The definitions that follow are used by numerous authors (e.g., Stallings) | ||
//See www.wikipedia.com | ||
void Tx1(){ | ||
digitalWrite(TxPin,0);//put in a 'low' here so the next transition makes sense | ||
delayMicroseconds(sDelay); | ||
digitalWrite(TxPin,1);//transition from low to a high indicates a 1 sent | ||
delayMicroseconds(sDelay); | ||
} | ||
|
||
void Tx0(){ | ||
digitalWrite(TxPin,1);//put in a 'high' here so the next transition makes sense | ||
delayMicroseconds(sDelay); | ||
digitalWrite(TxPin,0);//transition from high to a low indicates a 0 sent | ||
delayMicroseconds(sDelay); | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
|
||
# Temp files | ||
*~ |
Oops, something went wrong.