Project

General

Profile

Mysterious jeenode difficulty - need loads of help.

Added by grajmahal about 6 years ago

Hi All. I am trying to get a couple of jee-nodes to remotely control the operation of a sliding mirror. I have written the following sketch to do the trick, but it is only half working. When the trigger events happen for the clickstate=HIGH half of things, the radio transmits the “99999999” value. But when the opposite action is called for, the LED lights and the serial monitor on the sending unit returns the right value, but the receiving unit doesn’t see any transmission. I have reversed the order of things, tried stripping the sketch down, even changed the LED pins around in case there was some kind of a conflict. Nothing. Please - what am I doing wrong?

Thanks
John

#include 
#include 

int switchpin = 14; // pin that detects input
int ledpin = 5; //  red LED
int greenpin = 17; // Green LED
int clickstate = HIGH; 
int secondread = LOW;
int lastclick = HIGH;
int state = 0; //0 for closed, 1 for open - always starts closed
uint32_t payload;

void setup() {
  rf12_initialize(2,RF12_915MHZ,212);
  pinMode (ledpin, OUTPUT);
  pinMode (switchpin, INPUT);
  pinMode (greenpin, OUTPUT);
  digitalWrite (greenpin, HIGH);// just to test and make sure that the green and red leds are properly wired 
  delay (500);
  digitalWrite (greenpin, LOW);
  Serial.begin(57600);
  Serial.println(57600);
  Serial.println("Monitoring Sending Node");// just so I know that Serial Monitoring is working
}

void loop () {
clickstate = digitalRead (switchpin); // read the pin once 
 delay (500);// teeny delay to mitigate bounce
secondread = digitalRead (switchpin);// read the pin again 
   if (clickstate == secondread){ // make sure that the two reads are the same
       if (clickstate == !lastclick){ //make sure that this is new action and not a repeat of something already responded to



          if (clickstate == LOW) { // if the chess piece has been replaced
                 if (state == 1) { // and if the mirror is open
                      state = 0; // we reset the mirror to closed
                      payload = 444444444;// set the value of the radio payload 
                      digitalWrite (greenpin, HIGH);// light up the green LED to let the user know that the input has been receievd
                 }
          }

         if (clickstate == HIGH) { // If the chess piece is removed 
                 if (state == 0) { // and if the mirror is closed
                      state = 1; // we reset the mirror to open
                      payload = 99999999;// set the value of the radio payload
                      digitalWrite (ledpin, HIGH);// light up red LED for user
                 } 

         }

     rf12_sendStart(rf12_hdr, &payload, sizeof payload);// passes the "go up" or "go down" signal to the receiver
     delay (500);// small wait
     rf12_sendStart(rf12_hdr, &payload, sizeof payload);// passes the "go up" or "go down" signal to the receiver again to minimize false positives
     Serial.print (payload);// allows me to monitor the value of "payload"   
     delay (10000);// waits for the mirror to finish moving before taking any more action
       }}// closes loop where we need to do something
 digitalWrite (ledpin, LOW); //once the leds go dark, user knows that more input is ok 
 digitalWrite (greenpin, LOW); 
 lastclick = clickstate; // assigns lastclick to the state of the current click to make sure that there is only an action on a change

} // loop close 

Replies (4)

RE: Mysterious jeenode difficulty - need loads of help. - Added by JohnO about 6 years ago

Your RF section looks a little light:

     rf12_sendStart(rf12_hdr, &payload, sizeof payload);// passes the "go up" or "go down" signal to the receiver
     delay (500);// small wait
     rf12_sendStart(rf12_hdr, &payload, sizeof payload);// passes the "go up" or "go down" signal to the receiver again to minimize false positives
     Serial.print (payload);// allows me to monitor the value of "payload"   

I am no expert but I have used the sequence below with success. It may be worth taking a look at http://jeelabs.org/2011/12/12/inside-the-rf12-driver-part-3/ and possibly the two earlier blogs.

               rf12_sleep(RF12_WAKEUP);
               while (!rf12_canSend())
               rf12_recvDone();
               rf12_sendStart(0, &payload, sizeof payload);
               rf12_sendWait(0);
               rf12_sleep(RF12_SLEEP);

RE: Mysterious jeenode difficulty - need loads of help. - Added by grajmahal about 6 years ago

Thanks JohnO. I tried putting that extra code in there, and now it transmits the first packet, but just freezes up when the second one would be going out. I take it that somehow, the radio is not ready to send, and it sits in that little loop forever. The odd thing is that it seems to always be “ready” to send the other packet - I can get it to do that over and over again. I even tried placing the rf12_initialize in the loop, just to re-start the radio every time - no difference. Sends one kind, won’t send the other. I am stumped. red LED = transmit, every time. green LED = no transmit, every time.

John

RE: Mysterious jeenode difficulty - need loads of help. - Added by JohnO about 6 years ago

Can you post your updated sketch as an attachment?

RE: Mysterious jeenode difficulty - need loads of help. - Added by hve about 6 years ago

Hmm - that didn’t work. Try as an attached file. Or cut&paste with < pre > ….. < /pre > == around it - martynj

    (1-4/4)