Pages: 1 [2] 3   Go Down
Author Topic: HT12E library  (Read 14365 times)
0 Members and 1 Guest are viewing this topic.
Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1220
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Its working now,  some idiot typed   for ( int n =0; n>=3; n++ )   instead of  for ( int n =0; n<=3; n++ )   smiley-eek-blue

Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13917
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Yeah, we need a compiler that understands what we want, not what we write smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1220
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Right, but actually, would it not be possible for the compiler to spot that particular error quite easily?  and say " that ain't gonna get to 3 to start counting"

Or if you have the perennial   if ( a=0 )  instead of a==0  ,    it could nudged you and say "are you sure you want to make a be zero right now?"

Or perhaps us old farts should pay more attention to what we are typing, but I get carried away when I can see the code in my head, and just want to test it.
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13917
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


There is a tool called lint that detects some of the semantic bugs , I don't know if it is in the AVR kit , I used it in the days when compilers were really slow.

One thing that helps me a lot is a shortlist of my most common mistakes (5 or 6) and if code doesn't compile these are the things I check first. If it compiles and does not do what I want I start reading the code out loud. That gives another level of focus (your mind won't be 20 lines ahead) and that works quite well. Give it a try. OK, it looks a bit stupid to recite your "digital poetry" but code doesn't need to rhyme smiley-wink



Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1220
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset



Good tips, I will try them
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

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

Hi,

I'd like to know what is necessary to make this code works with Holtek HT6P20 or HT6026. Is there any library for this chip available to download?

I'll appreciate any kind of help.
« Last Edit: November 10, 2011, 08:32:27 pm by mfonte » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13917
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
to make this code works with Holtek HT6P20 or HT6026
You need to check datasheets to see what needs to be changed. If handshakes/formulas are identical you would have a headstart, otherwise it is often better to start from scratch.
Tip: define the interface first, how do you want to instantiate the class, what parameters (pins?); how to read the wanted value? timing? formulas. ets

If you have a link to the datasheets please post them, allways informative smiley-wink

Better make a new topic of this with a title that reflect the sensor type (get more focussed feedback)
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1220
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The datasheet for the HT6026    is  http://www.cikaeletronica.com/Produtos/Data%20Sheet/6026.PDF

It looks very similar, you could easliy write a sketch to send to these, but you need the extra pattern for the "open circuit" option for the trinary code  (  its either Vcc,  Ground, or open circuit - " floating" )
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

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

Hi Guys,

Thank you for the prompt response.

In fact I'd like decode the HT6P20 (learning code), but I know this chip is not so easy to unveil. As I'm still learning, I don't have advanced knowledge to create this decode.

The idea is to press learning button on Arduino that can store the code sent by the chip (HT6P20) .  After that, this remote control registered on Arduino is able to execute some actions.

I have this decode in ASM (http://www.asm51.eng.br/phpbb/viewtopic.php?p=51732&sid=8f5a880ce863a5d44303240c8b408f7a), but I can not translate to Arduino.

Datasheet:
http://www.datasheetcatalog.org/datasheets/120/170613_DS.pdf

Thanks in advance (again) :-)

BR,

Manoel





« Last Edit: November 16, 2011, 10:30:08 pm by mfonte » Logged

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1220
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The HT6P20  chip is more complicated, I don't know how you can decode that one.
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

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

/ *
ARDUINO HT6P20B DECODER WITH RESISTOR IN OSC 2M2.
THIS CODE NO TIMER USA, INTERRUPTION OR FOREIGN AND PIN SET INPUT.
IT MEASURES OF PILOT TIME PERIOD AND IF YOU COMPARE TO TRACK SET,
IF HE GOES TO CODE AND MAKE THE PERIOD OF TIME IN MEDIDÇÕES HIGH LEVEL
IF YOU HAVE INSIDE TRACK ACRECENTA 1 BIT 0 IN VARIABLE _DATA OR IF YOU DO NOT CLEAR THE MAIN AND RE-START
AFTER RECEIVING IT TAKES ALL THE BITS BITS OF ANTE 4 CODE AND TESTS TO KNOW IF THE CODE HAS BEEN RECEIVED
CORRECTLY, IF HE MAKES SURE TO RECEIVE A VARIABLE IN ANTCODE 1.

CREATED BY: DANIEL JACQUES MORESCO
DATE: 28/02/2012 USING ARDUINO 0022.
PHONES: 54 3324 2251 54 9206 7168
E-MAIL: ibisul@ibisul.com.br
Permitted public use, but should keep the name of the author.
* /

int x, startbit, ctr, dataok, t1, larpulso, larpulso1, larpulso2, larpulso3, larpulso4, bt1, bt2, antcode = 0;
unsigned long _data = 0, / / ​​DATA is the Code of recebio HT6p20 all 28 BITS where 22 of the buttons coodigo +2 +4 anti-code;
unsigned long _dur, _dur1 / / Pulse Duration
_pin byte / / Pin that will receive the digital RF signal.

void setup ()

{
  _pin = 2;
  Serial.begin (9600);
  pinMode (2, INPUT);
  pinMode (13, OUTPUT);
}

void loop ()

{
 
digitalWrite (13, digitalRead (2)) / / Blinks the LED as the value of digital input, interference testing.
if (startbit == 0)
 {/ / Test Pilot time until the start bit;
  _dur pulseIn = (_pin, LOW);
  if (_dur> 8000 && _dur <12000 && startbit == 0)
  {
    larpulso = _dur/23;
    = larpulso1 larpulso-50;
    larpulso2 larpulso = +50;
    = + larpulso3 larpulso larpulso-50;
    larpulso4 = larpulso larpulso + +50;
    startbit = 1;
        _dur = 0;
       _data = 0;
      dataok = 0;
         Ctr = 0;
  }
 }
 
/ / If the start bit THEN OK Starts measuring time high of signs, and tests whether the time is in the range.
if (startbit == 1 && dataok == 0 && ctr <28)
  {
      Ctr + +;
        _dur1 pulseIn = (_pin, HIGH);
if (_dur1> && larpulso1 _dur1 <larpulso2) / / If the pulse width is between 1/4000 and 1/3000 seconds
{
_data = (_data << 1) + 1 / / attach a * a * to the rightmost end of the buffer
}
else if (_dur1> && larpulso3 _dur1 <larpulso4) / / If the pulse width is between 2/4000 and 2/3000 seconds
{
_data = (_data << 1) / / attach a * 0 * for the rightmost end of the buffer
}
else
{
/ * Force loop termination * /
          startbit = 0;
}
       
   }
   
   
   

if (ctr == 28)
   {If (bitRead (_data, 0) == 1)
         {
           if (bitRead (_data, 1) == 0)
              {
                if (bitRead (_data, 2) == 1)
                   {
                     if (bitRead (_data, 3) == 0)
                        {
                          antcode = 1;
                        }
                   }
              }
         }

      if (antcode == 1)
         {/ / Have been received if all 28 bits, the value goes to _data variable and can be used as an example below.
           dataok = 1;
           Serial.println (_data, BIN);
           Ctr = 0;
           startbit = 0;
           antcode = 0;
           delay (100);
         }
   }
}


///////em português brasil ////////////////////////////////////////
/*
ARDUINO DECODIFICADOR HT6P20B COM RESISTOR DE 2M2 NO OSC.
ESTE CÓDIGO NÃO USA TIMER, INTERRUPÇÃO EXTERNA E NEM PINO DEFINIDO DE ENTRADA.
ELE MEDE O TEMPO DO PILOT PERIOD E COMPARA SE ESTÁ DENTRO DA FAIXA DEFINIDA,
SE TIVER ELE PASSA PARA CODE PERIOD E FAZ AS MEDIDÇÕES DE TEMPO EM NIVEL ALTO
SE TIVER DENTRO DA FAIXA ACRECENTA BIT 1 OU 0 NA VARIAVEL _DATA CASO NÃO ZERA AS VARIÁVEIS E RE-INICIA
APOS RECEBER TODOS OS BITS ELE PEGA OS 4 BITS DO ANTE CODE E TESTA PARA SABER SE O CÓDIGO FOI RECEBIDO
CORRETAMENTE, CASO RECEBIDO CERTO ELE COLOCA A VARIAVEL ANTCODE EM 1.

CRIADO POR: JACQUES DANIEL MORESCO
DATA: 28/02/2012 USANDO ARDUINO 0022.
FONES:54 3324 2251 54 9206 7168
E-MAIL: ibisul@ibisul.com.br
Permitido o uso público, mas deve-se manter o nome do autor.
*/

int x,startbit,ctr,dataok,t1,larpulso,larpulso1,larpulso2,larpulso3,larpulso4,bt1,bt2,antcode=0;
unsigned long _data=0;   // DATA é o Código recebio do HT6p20 todos os 28 BITS onde, 22 do coodigo+2 dos botões+4 do anti-codigo;
unsigned long _dur,_dur1;      // Duração do Pulso
byte          _pin;    // Pino que vai receber o sinal RF digital.

void setup()

{
  _pin=2;
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(13, OUTPUT);
}

void loop()

{
 
digitalWrite(13, digitalRead(2)); //Pisca o LED conforme o valor da entrada digital, testar interferencias.
if (startbit==0)
 {// Testa o tempo piloto até o Bit de inicio;
  _dur = pulseIn(_pin, LOW);
  if(_dur > 8000 && _dur < 12000 && startbit==0)
  {
    larpulso=_dur/23;
    larpulso1=larpulso-50;
    larpulso2=larpulso+50;
    larpulso3=larpulso+larpulso-50;
    larpulso4=larpulso+larpulso+50;
    startbit=1;
        _dur=0;
       _data=0;
      dataok=0;
         ctr=0;
  }
 }
 
// Se o Bit de inicio OK ENTÃO Inicia a medição do tempo em Nivel ALTO dos sinais, e testa se o tempo está na faixa.
if (startbit==1 && dataok==0 && ctr < 28)
  {
         ++ctr;
        _dur1 = pulseIn(_pin, HIGH);
   if(_dur1 > larpulso1 && _dur1 < larpulso2)     // Se a largura de pulso é entre 1/4000 e 1/3000 segundos
   {
     _data = (_data << 1) + 1;      // anexar um * 1 * para a extremidade mais à direita do buffer
   }
   else if(_dur1 > larpulso3 && _dur1 < larpulso4)   // Se a largura de pulso é entre 2/4000 e 2/3000 segundos
   {
     _data = (_data << 1);       // anexar um * 0 * para a extremidade mais à direita do buffer
   }
   else
   {
     /* força finalização do laço */
          startbit=0;
   }
       
   }
   
   
   

if (ctr==28)
   { if (bitRead(_data,0)==1)
         {
           if (bitRead(_data,1)==0)
              {
                if (bitRead(_data,2)==1)
                   {
                     if (bitRead(_data,3)==0)
                        {
                          antcode=1;
                        }
                   }
              }
         }   

      if (antcode==1)
         {// Se foram recebidos todos os 28 Bits, o valor vai para a variavel _data e pode ser usada como exemplo abaixo.
           dataok=1;
           Serial.println(_data,BIN);
           ctr=0;
           startbit=0;
           antcode=0;
           delay(100);
         }
   }
}
Logged

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1220
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well done Jaques,

All my new projects use Wirtualwire now, it is so versatile, and fast.

I used the HT12E code to drive my displays on an early board, because each number had already got its HT12D chip inside the display.
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

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

Jaques, thanks a lot.

It works for me even without the RESISTOR IN OSC.  Is it really needed?
I've used Arduino Mega 1280.

BR,

Manoel
Logged

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

Manuel, Thanks for the reply.
Resistor is required OSC in HT6P20, because it will set the clock.
My code allows a variation in clock that you can adjust according to the CSO.
Another thing that varies the clock and the battery voltage or battery that powers the remote, so you know when the battery is low.

hugs

Jacques Daniel Moresco.
Logged

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

Hi guys,


I have a remote that uses HT12E.
For domotic reasons, I would like to use my Arduino Uno to send RF frame.

Do I need specific library on Arduino to simulate HT12E ?
If yes, is it possible to get a link to download this lattest HT12E library ?


Thanks for your replies
Logged

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