Last update: 2018-02-25 15:30 (See the note at end)
Once again a project realized in the B&B during my free time, far from home. The circuit described here will be capable to drive almost any device that currently uses an IR remote control, by means of WiFi connection, as to say: with your smartphone. This time I want to show all the route from the idea to the running device. I had the idea some years ago (look at my previous articles regarding IR and WiFi), but I completely forgot it until today.
When I start a new project, there is the first step that I call: “sofa time”. I spend such time lying down on the sofa, without any computer, pen, document or tool. I just think about how to realize the project with the minimal effort.
After this time, I take a block-notes and draw with a pencil (or a pen) a very minimal schematic. In practice, it’s just a brief list of essential connections for the various components that I’m going to use. Here is such minimal schematic:
I don’t need a full schematic, at this time. I will draw it “seriously” with a CAD in the final steps. Well, now I can start building the prototype. First of all I search in my “junk box” what components are available and eventually I change the schematic in order to make it possible to be realized with available components. Usually my laboratory is very complete, but currently I have only few parts, being far from home. This is the prototype, wired on a proto board :
Note the presence of some SMD components. Sometimes I put such components mixed with the through-hole parts for space saving or just to substitute missing parts of the required value. It’s a simple circuit, but requires soldering skills to be built !
Did you noticed that I used a 16MHz crystal? Did you also noticed that I used a linear 3.3V regulator for powering the microcontroller ATmega88 and the WiFi module ESP-01? Well, there is a mistake ! A 16 MHz crystal is out of specs at 3.3V as you can see in the next picture:
The diagram is taken from the ATmega88 datasheet and says that the maximum crystal frequency at 3.3V is about 13.3MHz, evaluated with dF=(20-10)MHz and dV=(4.5-2.7)V. The nearest value that I have in my junk box is 12.288MHz, then I’m going to replace the component onto the circuit (it will be an easy job).
I plan to power my circuit with a 5V wall adapter, probably a phone charger, but during the tests I will use a Li-Ion battery, just to limit the number of cables on my unfair working place. Note that the LM1117-3.3 IC does NOT stabilize very well with the power supply taken from a Li-Ion battery. Look at this picture taken from the component’s datasheet :
A fully charged battery has 4.2V voltage, so it’s under the minimal dropout at 100mA to have a stable 3.3V output. Consider that the ESP-01 can have current peaks greater than 250mA, so the regulator output may be unstable. This situation will degrade more when the battery discharges to 3.7V (its nominal voltage) and the residual charge is about 10% of the nominal capacity. I used a 100uF capacitor connected to the ESP-01 power lines in order to absorb part of the current spikes in WiFi transmission and if necessary I will increase such capacity. In the “real life” the circuit, powered with a 5V-700mA wall adapter, will work fine ; for this test version I can accept some limitations.
Here is the first version of the circuit schematic (still subject to change):
For a better view, you can download the drawing in PDF format from this link. The pinout for the wifi module ESP-01 in the schematic diagram corresponds to this figure:
Note: if you want to replicate this project, you must program the ESP-01 module to use a 9600 BPS communication speed. There is an AT version created with such default speed on this website: http://wiki.aprbrother.com/wiki/Firmware_For_ESP8266 ; go there and look for ai-thinker-0.9.5.2-9600.bin. You can also alter (in a permanent way) the current communication speed of your ESP-01 module using AT commands. There are two, that works depending upon the version of firmware installed. Try both of them; the first that gives answer “OK” is the right one.
For additional information and useful SW tools, take a look at my previous articles here:
Interfacciare il modulo ESP-01 con una porta USB
The firmware – Part 1
At this moment I don’t want to write an App to test the device, so the first version of the firmware contains a very basic webserver, just to check if I can connect to the device with my smartphone using the default browser. The first release of the firmware (about 3 KBytes) is available at this link. The file is zipped with password. Use the program 7Z with password: eficara to expand it. The zip contains the .hex file to program the micro and the following image for the fuses map:
When the microcontroller has been programmed, you can try to check if it works. First of all, connect your smartphone to the AP that is presented by the Esp-01 module. You will be informed, obviously, that you are NOT connected to the Internet:
Note that the last 6 characters of the AP SSID will differ from the ones showed in the image, being the representation of last 3 bytes of the MAC address of the module and also the ESP_ part can differ if there is another release of the AT firmware in the module.
After connecting your smartphone to the Esp-01 AP, you can open the default browser and navigate to the single page available on this minimal webserver implementation. Here is an example:The page is always located at 192.168.4.1 (the Esp-01 IP) /cmd.htm (the single implemented web page) and the command ?k= followed by 4 hexadecimal digits. You will receive an html page with the same hex digits. This is just for test purposes. Please note that the hex digits that you will use in your requests must be in capital letters, or you will receive wrong answers:IR protocols – Tools
Now I must indagate the IR protocols that I want to use in this device. Many, many years ago, I realized an IR protocol analyzer under MS-DOS using Borland C and some subroutines in Asm 8086. It worked with direct I/O control of the pins of a COM port. Here is the hardware I used for IR protocol analysis:
Well, I will NOT present here such old MS-DOS programs because I have found on the internet a great page published by Ondřej Staněk at this link: http://www.ostan.cz/IR_protocol_analyzer/ that has a freely downloadable tool that is much more complete and powerful than mine. It works under Windows and the involved hardware is very simple to build. Here is a screenshot of the program running on my PC:
Or, if you can’t find the photodiode, you can try with a normal IR emitter (LED) using this circuit. I made it ‘cause I haven’t any photodiode in my “mobile laboratory”, but I have an IR emitter (LED) mounted on a small proto-board. I tested this unconventional circuit on my notebook and after a couple of tries it worked (the previous screenshot was taken with this interface).
Here are some audio settings I used on my notebook in order to make it work:
WM8650 tablet as remote control for Sony TV
Using Android tablet as SIRC remote control (#2)
General purpose infrared remote control receiver with RS232 output
Usare lo smartphone come telecomando TV
Un altro telecomando TV per smartphone Android
The firmware – Part 2
Well, I finished this project or, better, this “proof of concept”. It works, I can control my TV using the browser of my smartphone. The IR protocols used here are NEC and RC5. Due to the low power of IR led, driven directly by uC Port with a single resistor, the distance from the device to the TV (or other apparatus) will be 1 meter max. Add a transistor interface if you want long distance.
Note (Feb, 25 2018): I tested the circuit in the picture below and the distance now is over 3.5 meters. I can’t test if it works over 3.5 meters ‘cause my B&B room is very small !
One reader from Hackaday proposed to use multiple output pins in parallel to drive the IR LED with more power. It’s a good idea, but the software needs to be modified ‘cause I used the SBI I/O,#bit and CBI I/O,#bit instructions respectively to turn OFF (remember, negative logic for LED) and ON the port bit.
Controlling multiple port bits at the same time needs the OUT I/O,R instruction. Using the OUT instruction also involves to get the port status (in order to save other bits not used for IR led) and save it to 2 different registers, one to be used when you want low level on the IR outputs and the other when you want high level, without affecting the “non IR led” bits. Such approach changes the number of clock cycles needed to generate the 38KHz (Nec) and 36KHz (RC5) frequencies. This is absolutely not difficult to realize, but at this moment I closed my test firmware, so the transistor solution is simpler.
At power-on (reset) the microcontroller automatically sends one command for testing the NEC and RC5 protocol as you can see in the Main procedure.
After sending the test commands, the main procedure loops in the wifi section (function: Parameters) waiting for commands from any browser. The same IR code used in the test procedure can be sent with the smartphone, with the same effect.
Note that in order to send RC5 protocol IR commands, you must use another string in the browser. In place of: cmd.htm?k= you must use: cmd.htm?r= . This informs the firmware that the following 4 characters (hex) must be used as address and command for RC5 protocol, not for NEC. Please, remember that the standard RC5 protocol has 5 bits address (0x00..0x1F) and 6 bits command (0x00..0x3F). Codes out of the limits will be cut out with a simple “and” operation.
Finally, the new release of the firmware. It’s only 3034 bytes long. In the zip file you can find the .hex to burn the micro and a picture of the fuses configuration. Download the file from here and use the program 7Z to expand it. The password is “eficara”.
Have fun !
Note (Feb,21 2018): this article was linked by Hackaday and then I’ve seen many comments there about the “unuseful” ATmega88 micro used in my circuit. Someone assumed (wrongly) that I used the Arduino IDE to create this project ! Well, there is a big misunderstanding. May be that someone leaves his opinion before reading the article or simply thinks that reading the article is just an option. Ok, I just want to make clear that I wrote all the firmware in C language (some ASM code was optimized to C) and without using any “pre-cooked” library for ESP-01 or IR functions. All the webserver via AT commands and the IR RC5 and NEC protocols are mine, not copied from other people’s works. I know that the Esp8266 itself is a fully programmable device, but my target was to use a preprogrammed part (Ai-Thinker ESP-01 module with AT firmware) and just control that part how it comes “out-of-the-box”, without any modification, to create my “proof of concept”. I also know that there is a Lubuntu virtual machine (VirtualBox) with the complete environment to develop C language applications for the ESP8266. I have such VM enabled and working on my desktop computer, at home.