Pages: 1 2 [3] 4   Go Down
Author Topic: 350Mhz RF Remote. I know there is 315mhz and 433mhz.  (Read 6935 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm done for tonight.  Thanks for your help.

Instead of printing the code to the screen with serial.print.  Is there away to print the code to a pin? 

I think I'd like to hook the button board up to the transmitter though the arduino and play from there.  I dont know.  Picking at straws I suppose.
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sure, in the interrupt routine, you could just do this instead of serial.print:

Code:
byte value;
value = digitalRead(2);
digitalWrite(3,value);

There may be an error with digitalWrite taking value instead of HIGH or LOW. If so, try:

Code:
int value;

instead of byte.

That should relay whatever it reads on pin 2 out to pin 3. There will be a delay of course, but as long as the delay is consistent, the transmitter *shouldn't* care.

If you get a chance to measure that voltage, let me know. We may have to do something in-between to get it all nice and happy.

As a last resort, you could try to figure out which pins on the PT2262 that the buttons are connected to and which pins the address are set for from the circuit. That will tell you what commands are what instead of trying to read the remote output.

You could always go with your original plan to hook the buttons up directly on the remote and control it that way, but I think getting this sorted out will be more useful to you in the long run. I won't be able to mess with it much this weekend, but if you haven't figured it out by Monday, I will grab one of my remote outlets and attempt it myself to see if there are any gotchas.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I got home tonight and figured I'd look up all the values I've tried to use so far and come up with something.  It took a couple hours, but It's a nice course in simple programming!  

Code:

int inpin = 2; // makes the input pin pin 2
int outpin = 3;  // makes the output pin pin 3
int val = 0;  // sets the initial variable to 0

// 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
}

// the loop runs over and over forever
void loop() {
  int inpinState = digitalRead(inpin); //reads the state of the input pin
  digitalWrite(outpin, inpinState);  //writes the state of the input pin on the output pin
  Serial.println(inpinState); //displays the value of the input pin on the screen
  delay(0); // delay in between reads for testing
}

Results:
If I physically connect the transmitters signal line to the button boards signal line the remote works.  I can control the light.
If I run it though the arduino with the above code, I get nothing.  I can see the binary change happening as I push the button, but the lights don't respond.

What if there is a speed mismatch between what the arduino can process and what the button board and transmitter use?  So the binary doesnt get though right?  Like watching my arudino set at 9600 baud with a serial monitor set at 1200 baud?

Could it be an analog signal or a sign wave?  I dont know.  Scrapping for ideas.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SUCCESS!!!!  It works!  

I just had to get rid of the serialprint line.  I guess the extra little clock cycle that it took to print that line made the receiver not respond.  

Now I just need to capture some codes.  I guess I have two ways to do this.

1) capture the codes using serialprint and copy paste into notepad and tinker until it works.  Hardcoded codes do sound nice.

2) put some code in the setup section that will say "press the light toggle switch" then capture that code into a variable called lighttoggle.  Then prompt the user "press the fan on button" then capture that code into a variable called fanon.  
I know how to use serialprint and I know how to create variables now.  What I dont know is how to make it prompt, wait for input, then know when to move on to the next section.
Plus under option 2 I would have to store variables that were, 8, 16, however many bytes long and not just an instantaneous state change.
« Last Edit: March 09, 2013, 04:36:30 am by Mysticle31 » Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You just print the prompt out. Then you use this (in your loop):
Code:
if(Serial.available()){ //Someone entered something in the serial display

  byte c = Serial.read();

}

if(c > 0){ //We have a non-null value, so do something with it
  switch(c){
     case 'm': //'m' was sent
          //run some code meant for 'm'
         break; //always break after doing the command unless you want it to "fall through"
     case 'n': //'n' was sent...
         //do some code for 'n'
         break;
      //etc...
 }

If you have multiple steps, like multiple prompts, keep a state machine (keep a count of steps) so it knows what step it is at.
In your case, it might make more sense to increment the steps based on the interrupt. That way your code knows when the button was actually pressed.



Code:
byte state = 0;
byte light_toggle;
byte fan_toggle;
#define maxStates 6 //if there will be six steps total

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;
    case 2:
        Serial.print("Press the fan toggle switch")
        break;
    case 4:
        fan_toggle = value;
Serial.print("Fan toggle command is: ");
        Serial.println(fan_toggle, DEC);
        state++ //we have to increment the state here since no interrupt
        break;
     //etc... for all states
}

}



void interrupt(){
 state = state++ //increments the state counter
 
 //....do normal interrupt code here


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

If your value is 8 bits use
Code:
byte value
in your declaration, if it will be 16, use
Code:
unsinged int value
« Last Edit: March 09, 2013, 10:37:41 am by Retroplayer » Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There may be some minor errors in there. I always make stupid mistakes when writing code and only catch them when I go to compile. So, you may have to mess it, of course. It's just an example.

BTW, your address part of the command will (likely) always be the same for a particular device. So you really only need to capture that part once, then just store the command part for each button.
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am very interested in home automation myself. I even have all the X0 goodies including all the software that lets you program intelligent control and control from the web, but I am currently only renting a house so I am limited in what I can do. I have always thought it would be nice to tie all the various pieces together at some point. Maybe I should start playing with it a little so I have all the chunks ready when I move on.

I tend to stay at the girlfriends over the weekend, so something like an 'away' macro that turned off all the lights, set the thermostat down, ocassionally turned on lights to make it appear that I was home, set the security system, etc.. would be nice. Also checking on the cats and being able to feed and water them remotely would be nice. Hmm... I may have to start playing again.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh yeah.  I love this stuff.  I dreamed of working on one for awhile.  You need the arduino automatic cat feeder and sandbox scrapper with a little robot that will collect the doo doo and run it to the trash for you  smiley  I swear possibilities are only limited by a persons imagination and technical ablilty.

I tried this:
Code:
int inpin = 2; // makes the input pin pin 2
int outpin = 3;  // makes the output pin pin 3
byte state = 0;  //sets bytes vale to 0???
byte light_toggle; // creates byte light_toggle
byte value;  //creates byte value to display value
#define maxStates 6 //if there will be six steps total  (I'm not sure how this works.  There are 2 states on and off?)

// 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
}

// the loop runs over and over forever
void loop() {
   switch(state){ //like an if statement

    case 0:
Serial.print("Press the light toggle switch");
break;
    case 1:
light_toggle = value;  //what is this doing?  It's setting 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;

}

}

And it prints "Press the light toggle switch" over and over again.   
I'm not sure how #define maxStates 6 works.  Why do you need to know this?  Nothing ever references maxStates?

I think I need to somehow put the code together so that each state where we read a byte has it's own "if(c > 0)" section.  I'm not even close to understanding how that piece of code works yet.  It should just ignore all 0s so if it sees 0 then 0 then 0 then 0 then 0 it does nothing.  But if a 1 pops up it says "hey listen up write this down" for 8 bits and call that bit light_toggle and file it away.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just for fun I also tried playing with it with
int inpinState = digitalRead(inpin); //reads the state of the input pin
  byte onbyte  = digitalRead(inpinState) | (digitalRead(inpinState)<<1) | (digitalRead(inpinState)<<2) | (digitalRead(inpinState)<<3) | (digitalRead(inpinState)<<4) | (digitalRead(inpinState)<<5) | (digitalRead(inpinState)<<6) | (digitalRead(inpinState)<<7);
 

added

Code:
int inpin = 2; // makes the input pin pin 2
int outpin = 3;  // makes the output pin pin 3

// 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
}

// the loop runs over and over forever
void loop() {
  int inpinState = digitalRead(inpin); //reads the state of the input pin
  byte onbyte  = digitalRead(inpinState) | (digitalRead(inpinState)<<1) | (digitalRead(inpinState)<<2) | (digitalRead(inpinState)<<3) | (digitalRead(inpinState)<<4) | (digitalRead(inpinState)<<5) | (digitalRead(inpinState)<<6) | (digitalRead(inpinState)<<7);
  Serial.print(onbyte); //displays the value of the input pin on the screen
  //delay(0); // delay in between reads for testing
}
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It was repeating over and over again because the "state" is always going to be zero at least until an interrupt comes in. Hmm... sounds like we need another flag to tell whether it is the first time running so loop doesn't trigger every time. See, I told you I make stupid mistakes the first time around. lol

maxStates is the total number of states (no of prompts + number of entries.) So if there are three buttons to push, you have six states. Otherwise it would just keep counting forever. We want it to go back to the beginning when it has counts past the last state. I was doing that here:

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

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#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
  }
 
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 2 [3] 4   Go Up
Jump to: