It's now time to put it all together and test it. Unplug the power USB cables from both the Raspberry Pi Zero W and the QT Py Hat. Carefully connect the two boards together making sure that the 40 pins line up exactly. It could be easy to get off by one set of pins or to bend a pin so be careful.

Connect a USB power cable to the Raspberry Pi and connect the QT Py Hat to your PC using a USB C cable for uploading programs. NOTE: Under normal operation, it is not necessary to have the USB C cable connected to the QT Py. The entire system can be powered through the Raspberry Pi. However, for now we do need it connected to upload software.

Find the program arduino_files/echo and upload it to the QT Py board. This program will monitor data coming from your Raspberry Pi over the UART and echo it to your serial monitor. Upload the program and open your serial monitor. Make sure that you set the baud rate to 19200.

Again on your PC use a browser and navigate to the IP address of your Raspberry Pi. As we mentioned earlier on my system the IP address was 

You should see the simulated remote control buttons pop up just like we did in the test earlier. This time try clicking on one of the buttons. Here's what we saw when we clicked on the "Mute" button.

This tells us the row and column of the button that we clicked (the numbering system starts with zero) then it also tells us the data that was sent to the REST API that we have created. The "7" means protocol number 7 which is the NECx protocol if you remember from our previous test. The number "3772837903" is the decimal representation of that 32-bit hexadecimal value that we found when we tested the mute button on my TV which was E0E0F00F. (Don't worry we are not going to make you convert 32-bit hex numbers into decimal numbers.) The third item is "0" because the NECx protocol doesn't need any additional data. This string of digits and slashes is the string of data that was sent over the UART channel from the Raspberry Pi to the QT Py board attached to your hat.

Look at the serial monitor on your Arduino IDE. It should be echoing that same stream of data that is receiving from your Raspberry Pi. Ours looks like this:

Echoing serial port

If you happen to have a Samsung TV or a cable box from Spectrum Cable especially if it was a Spectrum system that was formerly owned by Bright House Cable, then you might be lucky enough to have your system already configured because that's what I have. But the likelihood of that is pretty slim. If you want to try it out, find a program arduino_files/qtpy_ir_remote and upload it to the QT Py. Then when you click on one of the buttons of your webpage remote, it should transmit the proper signals to your TV or cable DVR box.

Chances are that's not the case. We're going to have to customize things to your particular TV and cable system. Unfortunately, our software is not yet sophisticated enough to simply record the IR signals from your existing remote control. We are working on it, but it's not yet ready. Were going to have to do this the hard way.

Programming Custom IR Codes

Upload the program arduino_files/dumpFreq to the QT Py and open a serial monitor with a baud rate of 9600. We are going to test each of the buttons on your remote control and write down the protocol number, the IR code, and any additional information about that function. Then we will modify a JavaScript file to put these new codes into the system. Let's look at the JavaScript file first. On your Raspberry Pi, we need to edit the /home/pi/qtpyir/static/codes.js file. No need to use the Linux editors if you have set up a samba server. You can simply go to \\raspberrypi\userpi\qtpyir\static\codes.js and edit it using your favorite text editor such as Notepad or Notepad++. Here are the first few lines of that file.

var PageTitle="QtPy Cable Remote Demo";
var Button= [//object containing all buttons
	[//object containing row 0
		[7,0xe0e0e01f,0, "V+",187],//Object containing button 1
		[5,0x37c906,0, "|◄◄",74],//jump back "J"
		[5,0x37291a,0, "◄◄",36],//rewind
		[5,0x37990c,0, "►",32],//play
		[5,0x36293a,0, "►►",35],//fast-forward
		[5,0x36113d,0, "1",49],
		[5,0x37111d,0, "2",50],
		[5,0x36912d,0, "3",51]
	[//row 1
		[7,0xe0e0d02f,0, "V-",189],
		[5,0x36b129,0, "►►|",78],//live "N"
		[5,0x375914,0, "<span class='Red Big'>●</span>",82],//record "R"
		[5,0x374117,0, "||",80],
		[5,0x365934,0, "<span class='Big'>■</span>",83],//Stop
		[5,0x37910d,0, "4",52],
		[5,0x365135,0, "5",53],
		[5,0x375115,0, "6",54]
	[//row 2

The first line defines the text that appears at the top of your webpage.

Then we define all of the necessary information for each of the buttons displayed. Square brackets enclose the entire button array definition. There are also brackets enclosing each row. And then each button is defined within a set of brackets containing five values. The first button that appears in the leftmost position of the top row is the "Volume Up" button. Let's talk about each of the data items.

The first one is the protocol number which is 7. The second item is the hexadecimal code for that particular function. Notice that we prefix the value with "0x" to let it know that this is a hex number. There is a third value which is in this case 0. We will talk more about when that might be a different value. The fourth item is the text that will be displayed on the button. In this case, it is the "Volume Up" button so we simply chose the text "V+" as you can see for some of the other buttons we used special characters.

The final value is the keyboard scan code number for that particular button. In addition to being able to click on the buttons to activate the remote, you can also use keypresses. The code 187 is the code for the "+" key. Actually is the code for the "=" key and a "+" is the shifted version of that. But the program ignores the shift key and when you press + it returns code 187. Here is a reference for keyboard scan codes in JavaScript and it allows you to test different keys to see what the code is.

You should now upload arduino_files/dumpFreq to the QT Py and open the serial monitor at 9600 baud. Point your remote at the receiver chips on the Hat and write down the protocol number, the code, and the address for each function of your remote. Then edit those values into the codes.js file.

The file we have provided you is just a template. You can add and remove buttons and rearrange them however you want. You can label them however you want. Note that the text displayed on each button can be any HTML information including tags like &lt;span>, CSS information, or any other HTML tags. Some of the special characters that we use are a bit undersized so we created a special class called "Big" which makes the text bigger. We also included a class called "Red" which turns the text red. We use both "Red" and "Big" classes on the record button to make a bigger red button.

Some protocols have more than just a protocol number and a 32-bit code. For example, there is something called a Pioneer protocol which is the same as the NEC protocol #1 except that it uses a 40 kHz modulation instead of the standard 38 kHz modulation so in that case, you might encode your data something like this.

[1,0x1234abcd,40, "V+",187]

By the way that's just a made-up code. It doesn't really do anything that we know of. Another example is the Samsung36 protocol that is used by some Samsung Blu-ray players. It is a 36 protocol consisting of a 20-bit code followed by a 16-bit address. The code to stop my Blu-ray player would look like this.

[8,0xc837,0x0400, "<span class='Big'>&#9632;</span>",83],//Stop

We realize all of this is very confusing and complicated but we just don't have the software ready for a traditional "learning remote" kind of function where you simply press the button on your existing remote to record the data. We are working on it but it is very complicated.

Complete details of all of the protocols used by IRLib2 can be found in the extensive documentation in your arduino/libraries/IRLib2/manuals folder. The documentation is available in .docx, PDF, and EPUB format. Check out section "1.4 Protocol Details" for more information about the protocols supported by IRLib2.

What If It Does Not Decode?

Sometimes the dumpFreq program doesn't recognize your code. If it happens to be about 56-57 kHz frequency there's a good chance it is the "Panasonic Old" protocol. The codes of protocol 5 that we've already included might work.

The arduino_files folder also contains programs called dump and freq which separate the regular decoding and frequency detection into two different parts. It also provides more detailed information which might be useful for reverse-engineering the protocol.

There is an extensive appendix to the IRLib2 on how to implement your own protocols. It may be that we just cannot support your particular device.

Final Steps

When you've recorded all the codes for your devices and edited codes.js then load the program arduino_files/qtpy_ir_remote. You can test out your newly programmed codes. Note that after editing codes.js, reloading the webpage doesn't always cause a new copy of codes.js to be reloaded. You may need to clear your browser cache and reload the page. Using Google Chrome press CTRL-SHIFT-DELETE and then make sure that only "Cached images and files" is checked. Then click on "Clear Data" and refresh the webpage. That will ensure the latest copy of all of your codes gets loaded.

Once you have all of your codes programmed and working, you can disconnect the USB C cable from the QT Py and power the device solely through the Raspberry Pi.

Operating the Device

Place your device in a convenient location with the IR LED's pointed at your TV and cable box or other devices. Call up the webpage at your IP address for your Raspberry Pi.

Not only can you click on the buttons on the webpage, you can also use keypresses. For example, we have assigned "G" for "Guide" and "L" for "List". To see which keypresses activate which buttons you can press the "Escape" key on your keyboard. The labels on the buttons will display what keypresses you have assigned to each function. By pressing "Escape" again it will toggle back to the normal labels.

This keyboard function capability is especially useful as an assistive technology device. For example you can use speech recognition software such as Dragon NaturallySpeaking or Windows 10 built in voice control to use keypresses and arrow keys to navigate your cable or Blu-ray menus easily. If you've not already done so, see the demonstration video on the first page of this tutorial.

This guide was first published on Apr 17, 2021. It was last updated on Mar 08, 2024.

This page (Final Configuration Steps) was last updated on Mar 08, 2024.

Text editor powered by tinymce.