ESP IR Remote (for Kenwood Hi-Fi But Fully Customisable)(Updated 29/05/2017)

by AndyS127 in Circuits > Remote Control

3250 Views, 11 Favorites, 0 Comments

ESP IR Remote (for Kenwood Hi-Fi But Fully Customisable)(Updated 29/05/2017)

kenwood_m-85x_midi_system.jpg
IMG_20170203_183234.jpg
RemoteHomePage.PNG

A quick bit of history before I begin.

I have always been interested in gadgets & music and if I was asked where the split is, I'd say 50-50. I've tinkered and hacked things together since I could hold a screwdriver; some successfully and others not so but I have never been put off by the challenge of creating something 'better suited' to my needs. I'm also lucky enough to have a wife that 'understands' me and allows me to tinker & hack, provided I do my fair share of the housework, etc.

Back in the very early 90's, we 'invested', in a very expensive (for us), Kenwood M-85, Midi Hi-Fi system. It had Dolby surround, a CD, Graphic Equaliser and more inputs than I really needed at the time I could have bought a much cheaper system but I knew that if I spent the money on a good system to start with, it would last a few years. And after over 25 years on, it still works perfectly apart from the 'record deck', (which was just too tempting for my 2 young sons but has now been replaced by a Rega RP1) and the Graphic Equaliser, which just takes a while to warm up the display. I have done my best to keep it looking good too. For a few years I had it packed in the loft and substituted by a Panasonic Home Theatre System but as good as that was, it didn't have enough inputs for my musical/audio gadgetry. So last year I dug it back out of boxes and after building a custom shelving system for it, set it all up along with the RP1. But the remote had suffered a bit over the years and didn't want to play. I 'popped' it's shell and after a bit of cleaning with a fibre brush I noticed that one of the battery contacts had broken off the PCB and some of the internal plastic support had suffered too. I carefully replaced the battery contact with one from an old remote I had kicking around and plastic-welded a few new supports in place. Huzzah, it worked but it made me realise that this may be the weakest part of the system and getting a replacement was almost impossible unless I wanted to spend over £100 on a 2nd hand one from ebay or somewhere. So I needed to keep this one as safe as possible whilst I found a way to replicate the main controls. Which brings me to this Instructable.

But before we start; I know there are many Instructables already for similar projects. However, I wasn't able to find one that gave full instructions on the coding or how exactly you are supposed to send them from the web page to the ESP and translate that code to an IR signal that will do what I wanted it to. Most references I have been able to find were either written or explained in terms that required a higher level of expertise than I have or just didn't go into enough detail for my comprehension. So after many hours of 'Googling', I finally managed to pull all of the info I could find and using a little bit of educated guessing, found a way to do what I wanted. I should also make it clear that I am quite lazy when it comes to engaging the grey matter and tend to only learn the bits that are important to what I am doing at the time. If some of the steps seem a bit disjointed, I apologise. It wasn't until a friend told me I should post this that I started making notes. I'm no expert at any of the following but have learned what I have from many better informed sources. If you need to ask questions, I will try to answer them as best I can or point you to a better source of information. I will try to include links where they're necessary and some images too. I will also try to include all of those who are due a credit, if I can still find the correct source. If I do miss a credit, please forgive me as I never started out to create an Instructable and in my laziness, didn't make notes of some of the sources. Enough of the preamble and on with the project.

Sources and Prebuild

KENWOOD X94-1000-11-2.jpg
RemoteHomePage.PNG

I purchased an ESP8266 from ebay for a different but related project and then found that I would be better off with a RPi. So it sat around for a few weeks, with nothing to do but gather some dust... until now!

To use the ESP as an IR Blaster, I first needed to find out how to 'do' the code and see what was possible on the web. I googled ESP8266 IR-remote and found many many sites but many either involved in-depth learning or a masters degree in electronic engineering, until I found an instructable that looked like a ready made solution; Easiest ESP8266 Learning IR Remote Control Via WIFI by mmiscool. This allowed me to prove that it was indeed possible to create a Wi-Fi controlled IR remote. It worked and after some 'tinkering' with the code to add more buttons and style, I found that it was quite limited by the amount of buttons I could have. (I got to 11 before it became unstable). But what it did do was display the code for each button I pressed. (This bit came in handy when I couldn't find the exact remote listed in LIRC's remote listings for my Kenwood, we will return to this later).

So I started thinking that I would need some kind of server-side database of codes and pull them from there when needed. My head started throbbing at this point as I had never attempted this before and didn't know where to begin. I also realised that I was going to need about 20 - 30 buttons to run the day-to-day commands that I wanted. So my next task was to design a front page for these controls; I wanted something fairly fancy but usable (making it as easy and eye-pleasing as possible also helps where my wife is concerned) and didn't want to overload the web pages with images. So it would need to be a 'flat' page but with buttons rather than just links. For this I turned to a fantastic site I found a few weeks before W3Schools.com. (If you ever want to create any form of website, you would benefit from their site.)

I opted for a mix of Bootstrap and W3.CSS, with some Google and Bootstrap Icons to help with the aesthetics. After that some trial and error padding and font-sizing got me to something I liked the look of and had the requisite buttons for daily use. I've now updated the code to use tables for better looks/spacing. You can see that it's, not the same layout as the Kenwood remote but probably more usable. The HTML file is 'WiFi-Remote-html.txt and feel free to do what you need to to make your own style remote page.

Code Rewrites and How-to

Now I could see what my remote was going to look like, it was time to learn what I could about setting up a backend system for sending the IR codes to the ESP. Hmm, the 'Google Force', was not with me and although I could find some threads for it, I needed something I could get my teeth into and just chew off the bits I needed.So I changed tack again and searched for similar projects on Github and the like. Success, I found a project by 'witnessmenow', that looked promising, so I downloaded the repository and spent a couple of nights understanding the principals behind his project. It made sense and after a little experimentation, mostly in the styling dept', I found I could generate my html using his code. It worked for a few of the lines, so I quickly 'knocked-up' an Excel sheet to manipulate the code for the remaining buttons and copied the results back to the .ino file and flashed it onto the ESP. It looked just as I wanted but wasn't working other than displaying my Remote layout. I then examined the Ajax section of the .ino file and found where each of the button elements should be and where the IR code needed to go.

At this point, I didn't have any of the IR codes from my remote jotted down, so I reflashed the 'Easiest ESP8266 Learning IR Remote Control Via WIFI', image back onto the ESP and did some copying and pasting into another Excel sheet. I then opened the .ino code for witnessmenow's project in Notepad++ and added the Ajax code along with the button ID's and some text formulas into the spreadsheet, to give me what I needed. I then pasted the output back into the .ino file so that I had all of the HTML generation and Ajax instructions for each button. Time to reflash the ESP with the new .ino file. It flashed and I opened up the page in IE. Nada, nope, one flash when I hit the power button but nothing else. I re-opened the .ino file in Notepad++ and could see no reason why it wouldn't work. The original .ino file worked fine in IE. Hmm, more digging to be done. But it was gone midnight and my eyes were sore... I'll revisit tomorrow evening.

Finished Product and Further Credits

IMG_20170327_231232.jpg
IMG_20170327_231331.jpg
RemoteHomePage.PNG

Whilst chatting to the guy I work with, about some of his web creations and tools he uses, I came to the conclusion that it wasn't the code but the version of IE I am using. I'm running Windows 10 and whilst I use Opera as my default browser, I wanted to make it easy to flick between code and my remote page so stupidly chose IE instead of Edge or Opera as I (also stupidly) thought it would work with Bootstrap, W3.css and Ajax too. But when I got home, I fired up Opera and browsed to my ESP and 'Woo hoo', it worked for each and every button. Every delighted press gave me a flash on the LED. So now the acid test. Connect up the IR LED and point it at the Kenwood. It worked and I sat back with a beer and played with my new toy for a few minutes.

All I needed to do now was mount it in a spare box I had lying on my desk. This I did with the aid of a £5 hot glue gun from Geek and some Sugru from Amazon. The IR LED came from an old Sony remote and I fully expect it to burn out sooner or later but by that time, I may have found a way to integrate the ESP into the Amp using an opto-coupler or similar. But for now I am a happy bunny and have a working Wi-Fi remote for my good old Kenwood Hi-Fi.

Credits:

Mark Szabo: If you've done any searching for ESP8266 and IR Remote, you will already know the name;

https://github.com/markszabo/IRremoteESP8266: Great IR library for the ESP8266 and further info.

mmiscool: For the initial insights and the IR Receiver routine.

https://www.instructables.com/id/Easiest-ESP8266-Learning-IR-Remote-Control-Via-WIF/: Simple IR sender and receiver and diagram for connections.

W3Schools.com: For a fantastic site dedicated to learning web coding languages and techniques.

https://www.w3schools.com/: You'll love this great site.

LIRC: For plenty of info on different remote codes, etc.

http://lirc.sourceforge.net/remotes/: You may be able to find all the codes for your project here. If not refer to mmiscool's project and use the receiver function to get them.

witnessmenow: For a fantastic sketch and info that I have modified to suit my needs.

https://github.com/witnessmenow/ESP8266-IR-Remote-Example: A great project that taught me a lot about my humble ESP8266. (in the context of this project at least.)

Last but by no means least:

Sarah: My wife, friend and backup.