Referred to previous article “Learning-code remote controller and how to decode it” we discussed about it and its library for EV15xx. The source language is C for ATMega8, just explain how to decode remote’s code and you have to add extra parts; so we decided to build a practical 4 channel remote controller project.
Stay with sisoog.
Copyleft License
Depend on “Free software, software freedom”, we publish this project as GPL V3 license. All documents and resources are available to be freely used, modified, redistributed and sold by anyone but not allowed to remove creator’s name.
We used ATmega328p because it is Arduino’s micro. with 16 MHz frequency, but with a little change can be used for other microcontrollers and with other frequency.
It has been used GCC compiler and Eclipse development environment, but you can create a new Makefile and use it in Shell environment or Winavr compiler. It can be used in codevisionavr with a little change as easy as pie 🙂
Learning-remote library’s correction
Because this library has been written in 2009 with no change after that, some parts of library is rewritten such as decoding process as the main part. With the older one, maximum and minimum range of pulse width was micro seconds, that causes trouble when frequency was changed.
1 2 | #define Min_Pulse_Len 200 /* In us */ #define Max_Pulse_Len 15000 /* In us*/ |
1 2 3 | #define IS_Sync_Start_Pulse(T1,T2) (T2 > (T1*29) && T2 < (T1*32)) #define Bit_IS_Zero(T1,T2) (T2 > (T1*2) && T2 < (T1*4)) #define Bit_IS_One(T1,T2) (T1 > (T2*2) && T1 < (T2*4)) |
The other change is about storing receiving data from remote. The older library used an array for storing each bit that needed 24 bites of RAM memory.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | uint8_t Remode_Data[24]; . . . . if(Start_Sync==1) // Start Sended { if(Bit_Index < 24) { Remode_Data[Bit_Index] = !Bit_IS_Zero(Time_Rising,Time_Falling); Bit_Index++; } else { // All Bit Recive Bit_Index = 0; Start_Sync = 0; Revice_Flag = 1; } } // End of Start Sync Send . . . |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | volatile uint32_t EV_Code = 0; const uint32_t Bit_Shift[32] PROGMEM = { 0x00000001,0x00000002,0x00000004,0x00000008, 0x00000010,0x00000020,0x00000040,0x00000080, 0x00000100,0x00000200,0x00000400,0x00000800, 0x00001000,0x00002000,0x00004000,0x00008000, 0x00010000,0x00020000,0x00040000,0x00080000, 0x00100000,0x00200000,0x00400000,0x00800000, 0x01000000,0x02000000,0x04000000,0x08000000, 0x10000000,0x20000000,0x40000000,0x80000000, }; . . . . if(Start_Sync==1) // Start Sended { if(Bit_Index < 23) { if(Bit_IS_Zero(Time_Rising,Time_Falling)) { Bit_Index++; } else if(Bit_IS_One(Time_Rising,Time_Falling)) { Receive_Code |= pgm_read_dword(&Bit_Shift[(23-Bit_Index)]); Bit_Index++; } else { Start_Sync = 0; Bit_Index = 0; } } . . . |
It is recommended to use the corrected library for your projects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #define Key_Pin 3 #define Key_PORT PORTD #define Key_DDR DDRD #define Key_PIN PIND #define LED_Pin 4 #define LED_PORT PORTC #define LED_DDR DDRC #define CH0_Pin 0 #define CH1_Pin 1 #define CH2_Pin 2 #define CH3_Pin 3 #define CH_PORT PORTC #define CH_DDR DDRC RF_IN -> PORTD.2 Key -> PORTD.3 LED -> PORTC.4 CH0 ~ CH3 -> PORTC.0 ~ PORTC.3 |
Explain project
The program has three different modes:
- Normal Mode
After turning on the device, it is in normal mood; on-board LED is on for 1 second and off for 1 second, and pressing each button affects related output.
- Learn Mode
For using one or more remotes it’s needed to introduce the remotes to the device, so using learn mode.
By pressing device button for 1.5 second, learn mode starts and LED starts blinking fast, then for learning the remote’s code, press one button of the new remote, after learning, device mode is normal.
- Erasing Mode
For erasing saved remotes, press button for 10 seconds, LED turn on and off for 3 seconds, then all the remotes’ code is deleted from device memory.
Download Source Code
The source code of this project is uploaded at Github and is available to download.
———————————–
Author: Zeus
Translate: Golnoosh