Introduction

The programmable IR remote controller is an IR remote control platform based on PIC32 that can record and resend the Infrared signal. To help users control programmable IR remote controller, an infrared wave server related to database and website is implemented in this project. Bluetooth module creates a bridge between PIC32 and server side for transmitting infrared data.

Highlevel Design

Rationale

There were several rationale behind the project. A member of the team presented it as a way of unifying all the infrared remote controllers that he had so he didn’t have to worry about keeping track of them anymore. We thought it would be a good idea to get rid off the need of batteries and also it should be plausible since the infrared signal are frequency range orders of magnitude slower than the clock speed of PIC32. Finally, making it available in a website, we thought it would be a good idea since the user would not depend on a laptop to run it. A great source of our project was the Arduino Universal IR remote ,which gave us the idea of unifying all the standards of infrared communication in one library.

Logic Structure

The system can be divided into 7 components as shown in figure 1. First the infrared module formed by an infrared receiver and LED as emitter. This module communicates directly to the PIC32 through SPI. The demodulated signal that comes from the receiver is sent through Bluetooth to a server. With a Python Script, our server gets the new signal information and records it into our database that is later used to create a new entry in the webpage for that signal. To send the infrared signal, the process is the opposite. The server collects the information from the database and send it through Bluetooth to the PIC32. Then it encodes the bits following the required standard and produce a PWM signal for the LED to blink appropriately.

Patents

The infrared field is a well developed field that has been around since 19th century, with the first infrared remote controls developed in the 1980s. There are dozens of patents named “universal remote control”, which is a synonym of programmable, all with a small tweak. Interestingly most of them where filed close to 2001-2004, as shows figure 2, taken from google patent search engine.


Figure 2 - Histogram of patents filed with names similar to Universal IR Remote Control over time
One of the most similar patents to our project is Controlling record/playback devices with a computer, that uses a server as well to store the signal information.

Hardware and Software Tradeoffs

As mentioned above, the main advantage of decoding and encoding infrared signals is that there carrier frequency, in the range of 40 kHz, is a lot slower than the clock speed of the PIC32 of 40 MHz. Therefore the cpu load was lighter than in other applications. In addition, the use of a database, enabled us prescind of additional memory hardware.

Standards

A major part of the design was accommodating to each of the standards that infrared manufacturers use: Philips RC6, Samsung, Sony, NEC, etc. Following the idea of , we built a library that contained the characteristics required to decode and encode the infrared bits for each standard. The essential characteristics were time interval for logic high and low for bit “1” and “0”, number of bits per signal and initial bit duration. An example of what this characteristics mean can be found in the appendix.

Hardware Design

The hardware Design contained three components apart from the PIC32 as shown in Figure 3. The receiver, TSOP382, demodulates the infrared signal and outputs an inverted logic signal, as shown in figure 3. When the infrared is in logic high, the receiver outputs a logic low and so on. It has an internal filter for PCM frequency, and only needs very low supply current. We implemented the application circuit suggested in its data sheet, connecting the output to RB9 of the MCU.

Figure 3 - Photograph of the hardware

Figure 4 - Inverted logic of IR receiver
The LED on the other hand is manufactured to amplify the brightness of the infrared signal. We controll it through PWM so we connected it to one of the PWM pins, RB14. Finally the Bluetooth module communicates via UART using pins RA1 and RB10. In order to test the receiver we put it directly in front of the LED, therefore the same information we are sending has to be received and it is easier to debug.

Software Design

Bluetooth Communication

HC-05 module is SPP(Serial Port Protocol) module, designed for transparent wireless serial connection setup. The communication between PIC32 and server is based on HC-05 module. After configuring the bluetooth module using AT commands. HC-05 acts as serial port on PIC32 side. On server side, we used python script to receive bluetooth information. Serial library was used to handle the communication via pySerial library.
def port_initialize():
	# Initialize serial port
	s_port=serial.Serial()
	s_port.port = "/dev/tty.hc09-DevB"
	s_port.baudrate = 38400
	s_port.bytesize = 8
	s_port.parity = "N"
	s_port.stopbits = 1
	s_port.timeout = 1
	s_port.open()
	return s_port

Server Side

Infrared Wave Database

Redis is an open source(BSD licensed), in-memory data structure store, used as a database, cache and message broker. In this project, we chose redis because of its lightweight feature. Expect using redis as database to store infrared wave, we also use it to communicate between server script, and web page framework.


Web Framework

In this project, a web page acts as Graphical User Interface. The web framework is python microframework library, flask. This framework can handle http request as python functions. When user trigger the input button on the site, the request can access to python script on server side. Sending wave and Recording Wave are the requests we defined. When sending button is triggered, the script fetches the infrared information in database, and send request and wave information to PIC32 through bluetooth module. When recording button is triggered, the script will send the record request to PIC32, and wait the feedback from PIC32. After finishes recording, PIC32 will send a request and the wave information to server. Then server will dump wave information into database, and plot and put the infrared wave on web page. Finally, we can use the browser on cell phone to access to this webpage, and send request to server. When server receives http request, serve will send specific infrared wave to PIC32 through bluetooth module according to the http request.

PIC32 Side

We basically followed an exist project IR-Remote, which is a project aimed at Arduino. This library is in c++ so we first translate the library into c to make it suitable for MPLab. We carefully go through the whole library and test it with some manually generate data to check both the correctness and our understanding.

unsigned int sony_raw[26] = {
    1000,
    //   value = 0b0010011 = 0x13 = 19
    48,12,    24,12,    24,12,    12,12,
    12,12,    24,12,    12,12,    12,12,
    // address =   0b00001 = 0x01 =  1
    24,12,    12,12,    12,12,    12,12,
    12
};
We found that this library didn't handle the address and value correctly. It also didn't deal with the LSB and MSB issues. But after discussion, we figured out that we don't have to know the exact meaning for each bit. On the contrary, we only have to focus on the correct sequence of bits and that's all. For IR encode and decode part, since the modulation is processed by the receiver, what we needed to do is to record and process the high and low information.

The configuration part of our code is the following piece. We enable Timer2 for our input. Since typical time period of the modulation would be 500us, we set the period for Timer2 to be 2000 to get a 50us interrupt. Function enableIRIn() is to set RB9 as input pin and get the state of our IR receiver from this pin. The interrupt was then act as a counter to measure the length of the high and low part of the square wave. We also enable the timer3 for output. We use PWM to generate precise square wave. As code indicates, we initially set the PWM period 1052, which 38KHz for the square wave. The PWM output is set to PB14. During the project, we found that if we use RB0 as PWM output according to the PPS group graph, PIC32 might not be able to boot nor recognized by the PC. We thought that this might be conflict while we are going to download the program to the chip. So we highly recommended to consider about pin conflict problem if some one gets stuck into some weird problem.

    ...
    OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_1, 2000);//timer_limit);
    // set up the timer interrupt with a priority of 2
    ConfigIntTimer2(T2_INT_ON | T2_INT_PRIOR_2);
    mT2ClearIntFlag(); // and clear the interrupt flag
    ...
    enableIRIn();

    OpenTimer3(T3_ON | T3_SOURCE_INT | T3_PS_1_1, 1052);
    OpenOC3(OC_ON | OC_TIMER3_SRC | OC_PWM_FAULT_PIN_DISABLE , 0, 0);
    PPSOutput(4, RPB14, OC3);

We tried nRF8001 for out bluetooth transmission procedure. It's a SPI bluetooth module so we have to communicate with it through SPI channel. According to the datasheet and manual, this module is quite an advanced one but it's complicated to use. The manufacturer provided a framework to wrap the operations to interact with the module. The framework also includes guidance document about how to migrate the library to other platform. We thought we were able to make the module running properly but finally we found it too hard for migration and debugging. So we turned to HC-05, which is an UART module, and make the new one working very soon.

The decode part of our IR station is driven by a state machine.

Results

The IR station is quite easy to use. The PIC32 starts working as soon as the power is on. Once you click the 'RECORD' on the web page, and press the button on you remote controller, we can see the wave and the name on the site. With different button, the wave is different. This is just as we expected. Then we can resend the exactly the same signal by click the 'SEND' button on the site. Each send button corresponds to one specific signal. Since the IR receiver and the sender are very close to each other, we grab and decode the signal just sent with the receiver and check if the data carried by them are the same. We tried several times and the bits are exactly the same. The TV act the same under the control of a real remote controller and our station, which means that our station can actually 'learn' from the controller and resend the command.

Our project didn't require realtime performance or operation speed. All we focused on was to reproduce the signal without error. The baudrate of the bluetooth module was running at 38400bps. To reduce the debug and storage difficulty, we transform the bits into an integer and send this value literally. The raw data look like the following piece of characters. The first number is the type of the protocal. 7 indicates that this package is actually a samsung one. The second number, which is pretty large is a integer represents 32bits array. The following several number is the raw time gap of each HIGH and LOW.

7 3772829743 81846 90 90 12 33 12 32 12 33 12 11 12 10
12 11 12 11 12 10 12 33 12 33 12 32 12 11 12 11 12 10 12 11 12 10 13 32 12
33 12 11 12 32 12 11 12 10 13 10 12 11 12 10 12 11 12 33 12 10 12 33 12 33
12 32 13 32 12
These number are in plain text, which makes it very easy to check if every thing was right on server side. Usually the remote controller will send the same signal several times in order to make sure the device can receive them. We just store the first one and ignore the other. From the oscilloscope we can get a better view on these numbers.

Actually the IR application does not require the frequency to be very accurate since the IR receiver usually will handle the drift of the signal. But it's a good idea to analyze the accuracy of the frequency. We use oscilloscope to monitor the PWM output and we see perfect square wave. The duty cycle of the PWM is 50%, which is a pretty trivial settings. With 50us period of the TIMER2 interrupt, it's obvious that we can't get the precise time duration of each square wave. The maximum error would be 2x50us so we add a tolerance in the decode procedure. This tolerance will help us scan the raw data, and attempt to decode the signal with one specific protocal.

IR signal is pretty easy to interference with each other. If there exist other IR signal in the environment with similar modulate frequency, the receiver won't get correct signal. So if several IR emitter is sending signal at the same time, maybe none of them can work properly.

Conclusion

Expectation vs Result

Our project proved that it’s potential method for using PIC32 to control the recording and transmission of infrared wave. We used the infrared library as reference wave. The result of this project met our early expectation. We can use website to control the PIC32 recording the infrared wave information via IR receiver, storing this information in the server via Bluetooth module, and sending infrared wave via IR transmitter.

Future Work

  1. The performance of infrared wave station is the limited distance of infrared control. The power of infrared LED is small, thus the maximum distance this infrared controller is less than 20cm. A better performance can be guaranteed after changing a high power IR emitters.
  2. In this project, we decoded the wave information on PIC side. We found that the data on server side is hard to manager when more infrared protocols from different companies get into this design. Decoding wave information in server side is a potential approach to solve this issue.
  3. The possibility for successfully recording was nearly 90% based on our tests. However, the infrared record may fail if there were at least two infrared signals. These overlap was hard to handle using software.

Ethical Consideration

We adhere to technical IEEE code of Ethics throughout all stages of the project. The whole programmer system uses a 5V power supply, and would not cause any harm to the player. The biggest ethical consideration is that in the event of someone using this program surveilling the infrared wave in the real world. But the infrared transmitter and receiver module we used in this project were limited within specific distance. All testing result, infrared wave and code are authentic and in agreement with the IEEE Code of Ethics. We are sure to be realistic in the statement and estimates the conclusion based on our testing data so we are able to help improve the understanding of infrared technology. We took this improvement in the understanding of technology upon ourselves as we are qualified to undertake the endeavor of the project. We made this device work safely and would maintain a clean and safe code.

Legal Consideration

There is no legal consideration that we are aware of. Infrared recorder and transmitter in our project can act as education use, which will not cause any harm to human.

Appendix

The group approves this report for inclusion on the course website.
The group approves the video for inclusion on the course youtube channel.

IR Standards

Philips RC5

  • Carrier frequency: 36kHz
  • Codec: BI-phase coding (Manchester Coding)
    • High bit: 0.899us High, 0.899us Low
    • Low bit: 0.899us Low, 0.899us High
  • Bit time: 1.778ms (64 Cycles of 36kHz)
  • 5bits address, 6bits command length (7bits for RC-5X)

Philips RC6

  • Carrier frequency: 36kHz
  • Codec: BI-phase coding (Manchester Coding)
    • High bit: 0.899us High, 0.899us Low
    • Low bit: 0.899us Low, 0.899us High
  • Bit time: 1.778ms (64 Cycles of 36kHz)
  • Start Bit: 2666us High, 899us Low, Mode Bit: 3 Bit, Data: 16 Bit

Samsung

  • Reference: http://elektrolab.wz.cz/katalog/samsung_protocol.pdf

Sony

  • Carrier frequency: 40kHz
  • Codec: Pulse Width modulation, 1.8ms for 1 and 1.2ms for 0
  • Start Code: 2.4ms High then 0.6ms Low
  • Command Bits: 7bit
  • Address Bits: 5 or 8bits
  • Repeat every 45ms if the key on the remote control is held down.

Schematic

Codes

Reference

Cost lists

Part Quantity Cost
PIC32MX250F128B 1 $5.00
MicroStick II 1 $10.00
IR Emiiter 1 $2.50
IR Receiver 1 $6.00
HC-05 Bluetooth 1 $8.00
Breadboard 1 $5.00
Total $36.50

Task List

  • Yuchao Jin: IR encode/decode software stack, putting software module together and debugging
  • Sichen Liu: Bluetooth module design ,website framework and debugging
  • Jaime Luengo: IR hardware design, test and IR software debugging