Go Down

Topic: 350Mhz RF Remote. I know there is 315mhz and 433mhz. (Read 7 times) previous topic - next topic

Mysticle31

I tried your code again and recieve many Press the light toggle switch's still. 

Code: [Select]
int inpin = 2; // makes the input pin pin 2
int outpin = 3; // makes the output pin pin 3
int logpin = 13;  // makes the logpin pin 13
byte state = 0;
byte light_toggle;
byte fan_toggle;
byte value;
#define maxStates 6 //if there will be six steps total

// the setup routine runs once
void setup() {
  Serial.begin(9600);  // initialize serial communication at 9600 bits per second:
  pinMode(inpin, INPUT);  // makes inpin the input pin
  pinMode(outpin, OUTPUT);  // makes outpin the output pin
  pinMode(logpin, INPUT); //makes logpin input for button
  digitalWrite(logpin, HIGH); // turn on pullup resistors
}

void loop(){

  switch(state){

    case 0:
Serial.print("Press the light toggle switch");
break;
    case 1:
light_toggle = value;
Serial.print("Light toggle command is: ");
        Serial.println(light_toggle, DEC);
        state++; //we have to increment the state here since no interrupt
break;
}

}



void interrupt(){
state = state++; //increments the state counter

//....do normal interrupt code here


if(state > maxStates) state = 0; //reset the state counter
}


what is normal interrupt code?  is that what was in my void loop before?  I did have to add ;s on the end of all the state = state++ inorder to get it to compile.  Maybe that changed something? 

I hooked up a pushbutton to pin 13, so that it would print binary code to the serial monitor only when I pressed the button.  So if I press both buttons at the same time, it prints binary to the screen.  Otherwise it goes to the transmitter.  I tried then putting that code into multiple digital writes, but it didn't work.

digitalWrite(outpin, HIGH);
  digitalWrite(outpin, HIGH);
  digitalWrite(outpin, HIGH);
  digitalWrite(outpin, LOW);
  digitalWrite(outpin, LOW);
...etc.

Sadly, I'm coming to think that this project lies outside the realm of my abilities; even with the help of a more advanced, and kindhearted home automation enthusiast.  Time to take more programming classes.

Retroplayer

The missing ;'s were just another mistake. Again, I make a lot of them. I tend to program quickly and not worry about mistakes knowing (hoping) I will catch them later. Also, I am fairly new to C. I am more of a hardware guy.

The interrupt code is the function I named void interrupt(). You can name it whatever you want. You set what function to call on what type of interrupt with this statement in setup(): attachInterrupt(pin, function, mode.)

I apologize, my code was meant to be pseudo-code. The pieces were meant to be plugged into the example program not just run by themselves. I think that's why you were having trouble. I never set up the interrupts in my code. I will write something more complete for you to try. The 'normal interrupt code' part was suppose to be the stuff from the example.

Hang in there, I will post someting tonight for you.

Retroplayer

Unless I made a mistake, this should do what you want using the RCSwitch library:

Code: [Select]

#include <RCSwitch.h>
#define maxStates 3 //change this and the number of strings (char*) below to match the total number of codes you want to decipher.

byte state = 0; //variable to keep track of the states

char* prompts[]={"Press Light Toggle: ", "Press Fan Toggle: ", "Press next button name"}; //Serial strings for the various prompts
char* codes[]={"Light Toggle: ", "Fan Toggle: ", "Next button code: "}; //Serial strings for the names of the codes

RCSwitch mySwitch = RCSwitch(); //Make an instance of the RCSwitch library

void setup() {

  Serial.begin(9600);

  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2

  Serial.println(prompts[state]); //This will print the first prompt in the array of prompts to get things started
}

void loop() {

    if (mySwitch.available()) { //This code only runs when a button was decoded
    int value = mySwitch.getReceivedValue();
   
    if (value == 0) { //Something was seen, but the code couldn't decode it
   
      Serial.print("Unknown encoding");
     
    }
   
    else { //Or a valid code was found
   
      Serial.print(codes[state]); //Displays the name of the code based on the state
      Serial.print( mySwitch.getReceivedValue() );
      Serial.print(" / ");
      Serial.print( mySwitch.getReceivedBitlength() );
      Serial.print("bit ");
      Serial.print("Protocol: ");
      Serial.println( mySwitch.getReceivedProtocol() );
      Serial.println(" ");

      state++; //increment to the next state

      if(state > maxStates) state = 0; //reset the state counter if we reach the maximum step

      Serial.println(prompts[state]); //prints the next prompt. Starts back at the beginning if max was exceeded.
     
    }

    mySwitch.resetAvailable(); //reset the "available" flag after getting a code
  }
 
}

Mysticle31

You know.  I think the problem lies in how RCSwitch is used with my remote. 

Unmodified RCSWitch, VirtualWire and even some IRLibraryies do nothing with the input from the button board.  But I get something with digitalRead or Serial.read.  I cant even manually copy and paste some stuff into hardcoded tx examples.

I started a new thread in programming to see if I could pick some brains.  It's gone more than project guidance ha ha :)

Retroplayer

Your remote is using an SC2262 or PT2262, right?

I set up a quick configuration myself last night and tried it and had no success either. But when I looked inside the module it said 319Mhz on the TX module and I only have 315 and 434 modules. There is also AM and FM modulated modules (not sure which scheme the remote is using.) So I may not have the right modules for my remotes. I have a receiver outlet in my junk box somewhere. I will have to dig for it and try it again with that.

I ordered several PT2262 and PT2272 ICs a couple of years back and experimented with them over breadboards (without a micro) using my RF modules and that worked, so perhaps I can also set up my own "remote" on a breadboard to make sure the library is doing what it is suppose to be doing.

What's interesting is that I noticed the LED flickering like crazy on the Arduino while running the library and it would flicker faster when I pressed a button on the remote, so it is seeing something. It also mellowed out when I pulled it up with a 1K resistor and only flickered when I pressed a remote button. I don't see anything in the datasheet telling me I need to do that, though.

The good news is that it looked like the code I posted would work if it picked up the data.

Go Up