Show Posts
Pages: [1] 2 3
1  Using Arduino / Project Guidance / Re: 350Mhz RF Remote. I know there is 315mhz and 433mhz. on: March 12, 2013, 01:54:42 pm
Ohhh! See newbies doing dumb things.  There was more on the FCC website.  

I did some searching around and found a form member who made a library for the HT-12E.  
here http://arduino.cc/forum/index.php?PHPSESSID=2b8cea5a27a650c478c694e178b72f5a&topic=24424

I've been playing with it.  If I hook it up and try to read a code, it prints FFFF which is case 4 under "check if buffered data matches the address mask" in HT12E.cpp

HT12E.cpp
Code:
/*---
  HT12E.cpp
  HT12E Support for Arduino
  Author: Marcelo Shiniti Uchimura
  Date  : May '08
---*/

#include "Arduino.h"
#include "HT12E.h"

HT12E::HT12E(int pin, unsigned int addrMask)
{
  _pin = pin;
  pinMode(_pin, INPUT);
  _data = 0;
  _mask = addrMask << 4;  // the HT12E basic word is a stream with an 8-bit address
                          // followed by 4-bit data. I left shift the
                          // address mask 4 bits so I can match it to the entire word
}

int HT12E::read()
{
  byte ctr;            // for general error handling
  _tries = 0;
  do
  {
    /* look for HT12E basic word's pilot stream */
    for(ctr = 0; ctr < 13; ++ctr)
    {
      while(digitalRead(_pin) == LOW);                // wait for the signal to go HIGH
      _dur = pulseIn(_pin, LOW);

      if(_dur > 9000 && _dur < 12000) break;          // 36x(clock tick interval)
    }

    /* if error, skip everything */
    if(ctr == 13)
      {
        _tries = 4;
        break;
      }

    /* now wait until sync bit is gone */
    for(ctr = 0; ctr < 6; ++ctr)
      {
        if(digitalRead(_pin) == LOW) break;
        delayMicroseconds(80);
    }

      /* if error, skip everything */
      if(ctr == 6)
      {
        _tries = 5;
        break;
      }

    /* let's get the address+data bits now */
    for(_data = 0, ctr = 0; ctr < 12; ++ctr)
    {
      _dur = pulseIn(_pin, HIGH);
      if(_dur > 250 && _dur < 333)        // if pulse width is between 1/4000 and 1/3000 secs
      {
        _data = (_data << 1) + 1;         // attach a *1* to the rightmost end of the buffer
      }
      else if(_dur > 500 && _dur < 666)   // if pulse width is between 2/4000 and 2/3000 secs
      {
        _data = (_data << 1);             // attach a *0* to the rightmost end of the buffer
      }
      else
      {
        /* force loop termination */
        _data = 0;
            break;
      }
    }

    // check if buffered data matches the address mask
    if((_data & _mask) < _mask)
    {
      /* data error */
      _tries = 6;
    }
    else ++_tries;

  } while(_tries < 3);

  if(_tries > 3)
  {
    switch(_tries)
      {
        case 4: return 0xffff;
        case 5: return 0xfffe;
        case 6: return 0xfffd;
    }
  }
  return (_data ^ _mask);
}


HT12E.h
Code:
/*---

  HT12E.h
  HT12E Support for Arduino
  Author: Marcelo Shiniti Uchimura
  Date  : May '08

  Note  : make sure HT12E is operating at 3~4kHz clock range

---*/

#ifndef HT12E_h
#define HT12E_h
#include "Arduino.h"

class HT12E
{
  public:
                 HT12E(int pin, unsigned int addrMask); // this is the constructor
    int          read();                                // this is the main method
  private:
    byte         _pin;      // this is Arduino input pin
    unsigned int _data;     // this is data
    unsigned int _mask;     // this is the address mask
    byte         _tries;    // this is how many times Arduino could find
                            // valid HT12E words
    unsigned long _dur;     // pulse duration
};

#endif

Usage Example
Code:
#include <HT12E.h>

HT12E remote(7, B01111111); // pino 7, endere├žo 0111 1111b

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  unsigned int valor;
  valor = remote.read();
  if(valor > 0xFFF0) Serial.println(valor, HEX);
  else
  {
    Serial.print("DATA ");
    Serial.println(valor, BIN);
  }
  delay(1000);
}

He says it's a 12 bit encoder.  8 bits are the address, 4 bits are the code.  
My button board has 4 dip switches.  I dont know what it transmits.



How long is a word?  I seem to remember it being 2 bits, but maybe it varies?  I just barely understand enough here to be dangerous.
2  Using Arduino / Programming Questions / Re: Capture RF Codes to transmit later. RCSwitch / VirtualWire do not work!! on: March 12, 2013, 12:16:46 am
Ahh.. That makes scene.  I'm not sure what to do with it.  
I did play around with adding delay() and delayMicroseconds() at various values to see how the output changes.  It never worked though.

I even made the buffer as big as it could be and still run (about 800 byes) and it still never worked.

Lets say the button board outputs 11110001 for light on.  The Arudino is running really fast, what it sees is 111111,111111,111111,111111,000000,000000,000000,111111.  I separated the bits by commas for clarity.  
Well, if the arduino outputs that, the transmitter still sees and transmits 11110001, right?  Come to think of it, that would mean that I should see all of my binary in groups of 1 or 0 X number of times, and I do see things like 1101001 so that theory just got trashed. 
A quick read of wikipedias encoding articles makes me think that it is an issue I cant deal with,

Why does this work?
"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"
I can "forward" the signal though the arduino just fine.  Woudn't I encounter the same encoding problem?


3  Using Arduino / Project Guidance / Re: 350Mhz RF Remote. I know there is 315mhz and 433mhz. on: March 11, 2013, 08:08:24 pm
I dont know.  There is nothing in the FCC documents besides the engineers name and things

https://apps.fcc.gov/tcb/GetTcb731Report.do?applicationId=568629&fcc_id=IN2TX28

The back of the remote case does list
FCCID: IN2TX28  and  IC: 3558A-TX28

Not sure what the IC is, but I kind of doubt it's what we want.

Edit:
I popped open a receiver module and found that the receiver has an IC.  It's a PT4302-X

Then again, my other 433mhz has an IC too, so it probably wont tell us anything.
4  Using Arduino / Programming Questions / Re: Capture RF Codes to transmit later. RCSwitch / VirtualWire do not work!! on: March 11, 2013, 07:13:52 pm
OK I fixed it.  I verified that the pushbutton, countin and count out work as prescribed with serial mointor.

I added a pushbutton that I can press at the same time as the light toggle so It can get the code.

It still didn't work.  Maybe I just cant use arrays to do what I want?  Maybe I need an array with a variable size of how ever much it receives? 

Quote
int outpin = 3;           //connect the transmitter to pin 3
int inpin = 2;             //connect the button board to pin 2
int Array[500];          //create an array
int countin = 0;         //create a value to keep track of additions to the array
int countout = 0;       //create a value to keep track of read position in the array
int ArraySize = 500;   //total size of the array      
int readpin = 7;         //connect to a switch, connect the other side of the switch to ground

void setup()
        {
        //setup section
        Serial.begin(9600);
        pinMode(outpin, OUTPUT);
        pinMode(inpin, INPUT);
        pinMode(readpin, INPUT);
        digitalWrite(readpin, HIGH);
        Serial.println("Ready to Recieve");
      
        //press the button to continute
        while (digitalRead(readpin) == HIGH);
            {
            
            //read in bits received to the array
            while(countin <= ArraySize)
                {
                int inpinState = digitalRead(inpin);
                Array[countin] = inpinState;
                //Serial.println(ArraySize);
                //Serial.println(countin);
                countin++;
                }
            }
        Serial.println("Ready to Transmit");
        delay(5000);
        }

void loop()
        {
        //read out the array
        while(countout <= ArraySize)
            {
            digitalWrite(outpin, Array[countout]);
            //Serial.println(ArraySize);
            //Serial.println(countout);
            countout++;
            }
        delay(1000000);
        }
5  Using Arduino / Programming Questions / Re: Capture RF Codes to transmit later. RCSwitch / VirtualWire do not work!! on: March 11, 2013, 06:24:32 pm
Oh shoot! The array values in code isn't even being ran!.  I need to use while instead of if.  OK.  I'm going to go play and see what happens!
6  Using Arduino / Programming Questions / Re: Capture RF Codes to transmit later. RCSwitch / VirtualWire do not work!! on: March 11, 2013, 06:11:09 pm
Code:
if(countin <= ArraySize)  //if countin is less than or equal to ArraySize, and it should be if 0, do this.
            {
            int inpinState = digitalRead(inpin); //reads the value of inpin to veriable inpinState.
            Array[countin] = inpinState;          //adds inpinState to Array (an array called array) at position 0.
            countin++;                                 //add one to the count
            }

Well, that's what it is supposed to do anyway.  I want an array, string, whatever with the values received on inpin.  So I can then output the those values later.

If I go directly from one pin to another
Code:
int inpinState = digitalRead(inpin); //reads the state of the input pin
  digitalWrite(outpin, inpinState);  //writes the state of the input pin on the output

That works.  I want to read the codes into memory.  Store them for awhile.  Transmit them later when I want.
7  Using Arduino / Project Guidance / Re: 350Mhz RF Remote. I know there is 315mhz and 433mhz. on: March 11, 2013, 03:54:03 pm
Quote
The good news is that it looked like the code I posted would work if it picked up the data.
  I think so too.  I ran it just printing things to the console.

There are no ICs on the button board or the transmitter.




8  Using Arduino / Programming Questions / Re: Capture RF Codes to transmit later. RCSwitch / VirtualWire do not work!! on: March 11, 2013, 03:44:20 pm
Ohh.  Ok.  I understand most of that.  I need to go read what in interrupt is.

You would think that if my little "patchthough" worked.  The heart of it was
Code:
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


This should work?  It doesn't.
Code:
int outpin = 3;  //sets the tx pin to transmitter
int inpin = 2; //sets the rx pin from button board
int Array[500];
int countin = 0;
int countout = 0;  //keeps track of array values read
int ArraySize = 500;  //generates array size for max array values
int ledpin = 13;

void setup()
        {
        Serial.begin(9600);
        pinMode(outpin, OUTPUT);
        pinMode(inpin, INPUT);
        pinMode(logpin, OUTPUT);
        digitalWrite(ledpin, HIGH);  //turns on L Led while creating array
        if(countin <= ArraySize)
            {
            int inpinState = digitalRead(inpin); //reads the state of the input pin to inpinState
            Array[countin] = inpinState;
            countin++;
            }
        digitalWrite(ledpin, LOW);  //turns off L leg when done
        delay(1000);
        }

void loop()
        {
        if(countout <= ArraySize)
            {
            digitalWrite(outpin, Array[countout]);
            countout++;
            }
        delay(1000);
        }
9  Using Arduino / Project Guidance / Re: 350Mhz RF Remote. I know there is 315mhz and 433mhz. on: March 11, 2013, 12:01:06 pm
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
10  Using Arduino / Programming Questions / Re: Capture RF Codes to transmit later. RCSwitch / VirtualWire do not work!! on: March 11, 2013, 11:52:01 am
Great Idea.  I just tried it.  I tried his simple IRRecivDemo.

Code:
/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

I have no idea why nothing comes up in Serial Montitor when I use a library, but I can read some long binary when I use digitalRead or Serial.read().


Quote
Code:
int Array[155]={0,0
Using over 300 bytes to store 20 bytes-worth of information is not good use of a precious resource.

That is another thing I don't understand.  Why am I getting binary with 50-100 digits.  With just the remote by itself, 1/4 of a second of a button press is all it takes to turn on the light.  If I press it longer it will eventually dim the light.  It takes the arduino 2 seconds just to count to 155, much less output anything from an array.

The "button board" has 4 dip switches that select which receiver I'm talking to, and 5 buttons (Fan High, Fan Med, Fan Low, Fan Off, Light Toggle) 

Theoretically it should be something like (0000) Receiver Nibble if all dips are off + (some other nibble based on button pressed).  Maybe over and over and over again 5 times?  I dont know.
11  Using Arduino / Programming Questions / Capture RF Codes to transmit later. RCSwitch / VirtualWire do not work!! on: March 11, 2013, 02:16:34 am
I have several ceiling fans with lights controlled by hunter remote controls.  I've been trying to automate them with and arduino and a PC.  They run on 350mhz.

Big thanks to Retroplayer for his advice in another thread in the project guidance forum.  It was getting out of disorganized and this is more of a programming issue so I thought I'd create a new thread.

One of my remotes has a "button board" (the board with the pushbuttons) and a "transmitter" (the transmitter).  I desoldered the transmitter from the button board.  

Power and ground for the button board and the transmitter come from the arduino.

If I directly connect sig out on the button board to sig in on the transmitter - control works.  

If I forward the signal though the arduino with this bit of code - control works
Code:
int inpin = 2; // makes the input pin pin 2
int outpin = 3; // makes the output pin pin 3

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
}

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
  //Serial.print(inpinState); //swap comments out with digitalwrite to see output on screen.  they dont work together!!

}

If I connect the output of the button board to RX pin 0 and run this bit of code to look at whats happening - I receive data printed on the screen.  (I can even do the same thing with //digitalWrite(outpin, inpinState); in the previous example

Code:
int incomingByte = 0;   // for incoming serial data

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
               Serial.print(incomingByte, BIN);;
        }
}

Here is the interesting part.  If I use a library like RCSwitch, or VirtualWire and load their example receive examples, I get NOTHING.  No errors, no invalid data, no unknown coding, no result period.  Why?  I dont understand.  Serial.read and digitalread at least give me something.  

I even hooked a pushbutton up so that when I pressed the button it would start to write binary data to the screen.  If I didn't press the lighttoggle button, it would write 0s.  If I pushed the lighttoggle button, it would write some codes.

Without RCSwitch or VirtualWire is the project dead?

I've been trying to make a way to capture some of the data or replay it.  I've tried
digitalwrite  bit
digitalwrite  bit
digitalwrite  bit
etc.. (it never worked)
until I discovered arrays and started playing with those.
Code:
int inpin = 2; //sets the recieve pin from button board
int outpin = 3;  //sets the tx pin to transmitter
int logpin = 13;  //ground on this pin start code
int Array[]={};  //array.  I've tried it with precought values too.
int countin = 0;  //keeps track of array values read
int countout = 0;  //keeps track of array values sent
int ArraySize = sizeof(Array);  //generates array size for max array values

void setup()
        {
        Serial.begin(9600);
        pinMode(inpin, INPUT);
        pinMode(outpin, OUTPUT);
        pinMode(logpin, INPUT);
        digitalWrite(logpin, HIGH);
        if (digitalRead(logpin) == 0) //if I press the code-in button then the light toggle it will read code
            {
            Array[countin] = digitalRead(logpin);
            countin++;
            }
        }

void loop()
        {
        if(countout <= ArraySize)
            {
            digitalWrite(outpin, Array[countout]);
            countout++;
            }
        }
Hard coded Array
Code:
int outpin = 3;  //sets the tx pin to transmitter
int Array[155]={0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0,1,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0,0};  //array.  I've tried it with precought values too.
int countout = 0;  //keeps track of array values read
int ArraySize = 155;  //generates array size for max array values

void setup()
        {
        Serial.begin(9600);
        pinMode(outpin, OUTPUT);
        }

void loop()
        {
        if(countout <= ArraySize)
            {
            digitalWrite(outpin, Array[countout]);
            countout++;
            }
        }


Whats the deal here?
12  Using Arduino / Project Guidance / Re: 350Mhz RF Remote. I know there is 315mhz and 433mhz. on: March 10, 2013, 01:32:45 am
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.
13  Using Arduino / Project Guidance / Re: 350Mhz RF Remote. I know there is 315mhz and 433mhz. on: March 09, 2013, 02:48:32 pm
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
}
14  Using Arduino / Project Guidance / Re: 350Mhz RF Remote. I know there is 315mhz and 433mhz. on: March 09, 2013, 12:35:34 pm
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.
15  Using Arduino / Project Guidance / Re: 350Mhz RF Remote. I know there is 315mhz and 433mhz. on: March 09, 2013, 04:00:36 am
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.
Pages: [1] 2 3