i would like to receive data from my 433 mhz weather station, the protocol does work correctly, but the way of sampling pulses doesn't work, The code is orginally written for arduino. below the code. the problem is that it does not pick up the signal and put it in the rawsignal variable. the signal coming from the 433mhz receiver is inverted.
- #define MIN_RAW_PULSES 20 // =8 bits. Minimal number of bits*2 that need to have been received before we spend CPU time on decoding the signal.
- #define RAWSIGNAL_SAMPLE_RATE 30 // Sample width / resolution in uSec for raw RF pulses.
- #define MIN_PULSE_LENGTH 40 // Pulses shorter than this value in uSec. will be seen as garbage and not taken as actual pulses.
- #define SIGNAL_TIMEOUT 5 // Timeout, after this time in mSec. the RF signal will be considered to have stopped.
- #define SIGNAL_REPEAT_TIME 250 // Time in mSec. in which the same RF signal should not be accepted again. Filters out retransmits.
- #define BAUD 9600 // Baudrate for serial communication.
- #define RAW_BUFFER_SIZE 256 // Maximum number of pulses that is received in one go.
- #define SCAN_HIGH_TIME 50 // tijdsinterval in ms. voor achtergrondtaken snelle verwerking
- #define FOCUS_TIME 50 // Duration in mSec. that, after receiving serial data from USB only the serial port is checked.
- #define PRINT_BUFFER_SIZE 60 // Maximum number of characters that a command should print in one go via the print buffer.
- const unsigned long LoopsPerMilli=345;
- const unsigned long Overhead=0;
- int RawCodeLength=0;
- unsigned long PulseLength=0L;
- unsigned long numloops=0L;
- unsigned long maxloops=0L;
- boolean Ftoggle=false;
- uint8_t Fbit=0;
- uint8_t Fport=0;
- uint8_t FstateMask=0;
- #define WS1100_PULSECOUNT 94
- #define WS1200_PULSECOUNT 126
- #define ALECTOV3_PULSEMID 300/RAWSIGNAL_SAMPLE_RATE
- #define PIN_RF_RX_DATA 15
- struct RawSignalStruct // Raw signal variabelen places in a struct
- {
- int Number;
- byte Repeats;
- byte Delay;
- byte Multiply;
- unsigned long Time;
- byte Pulses[RAW_BUFFER_SIZE+2];
- } RawSignal={0,0,0,0,0,0L};
- void FetchSignal() {
- DataPin = PIN_RF_RX_DATA;
- Fbit = !digitalPinToBitMask(DataPin);
- Fport = digitalPinToPort(DataPin);
- FstateMask = (StateSignal ? Fbit : 0);
- //Serial.println("Pass1");
- unsigned long Timer=millis()+SCAN_HIGH_TIME;
- while(Timer>millis() || RepeatingTimer>millis()) {
- //Fbit = !digitalRead(PIN_RF_RX_DATA);
- //Serial.println("Pass2");
- if(Fbit == true){
- //Serial.println("Pass3");
- if (RawSignal.Time) {
- if (RawSignal.Repeats && (RawSignal.Time+SIGNAL_REPEAT_TIME)>millis()) {
- PulseLength=micros()+SIGNAL_TIMEOUT*1000;
- //Serial.println("Pass4");// delay
- while ((RawSignal.Time+SIGNAL_REPEAT_TIME)>millis() && PulseLength>micros())
- if ((*portInputRegister(Fport) & Fbit) == FstateMask)
- //Serial.println("Pass5");
- PulseLength=micros()+SIGNAL_TIMEOUT*1000;
- while((RawSignal.Time+SIGNAL_REPEAT_TIME)>millis() && ((*portInputRegister(Fport) & Fbit) != FstateMask));
- }
- }
- //Serial.println("Pass6");
- RawCodeLength=1; // Start at 1 for legacy reasons. Element 0 can be used to pass special i formation like plugin number etc.
- Ftoggle=false;
- //Serial.println("Pass7");
- maxloops = (SIGNAL_TIMEOUT * LoopsPerMilli);
- do{
- //Serial.println("Pass8"); // read the pulses in microseconds and place them in temporay buffer RawSignal
- numloops = 0;
- while ((Fbit == true) ^ Ftoggle) // while() loop *A*
- if (numloops++ == maxloops) break;
- //Serial.println("Pass9"); // timeout
- PulseLength=((numloops + Overhead)* 1000) / LoopsPerMilli; // Contains pulslength in microseconds
- if (PulseLength<MIN_PULSE_LENGTH) break; // Pulse length too short
- Ftoggle=!Ftoggle;
- RawSignal.Pulses[RawCodeLength++]=PulseLength/(unsigned long)(RAWSIGNAL_SAMPLE_RATE); // store in RawSignal !!!!
- }
- while (RawCodeLength<RAW_BUFFER_SIZE && numloops<=maxloops);
- //Serial.println("Pass10"); // For as long as there is space in the buffer, no timeout etc.
- if (RawCodeLength>=MIN_RAW_PULSES) {
- RawSignal.Repeats=0; // no repeats
- RawSignal.Multiply=RAWSIGNAL_SAMPLE_RATE; // sample size.
- RawSignal.Number=RawCodeLength-1; // Number of received pulse times (pulsen *2)
- RawSignal.Pulses[RawSignal.Number+1]=0; // Last element contains the timeout.
- RawSignal.Time=millis(); // Time the RF packet was received (to keep track of retransmits
- Serial.println("Pass11");
- }
- else {
- RawSignal.Number=0;
- //Serial.println("Pass12");
- }
- RepeatingTimer=millis()+SIGNAL_REPEAT_TIME;
- //Serial.println("Pass4");
- }
- }
- }