![]() |
Forum Index : Microcontroller and PC projects : CMM2: Has anyone done anything with the IR reciver.
Author | Message | ||||
mclout999 Guru ![]() Joined: 05/07/2020 Location: United StatesPosts: 490 |
I was wondering what people had done with the IR that is just sitting there on all of our systems. I need some help getting started on using it. I think I can just get an NEC or Sony remote or a universal and set it to either right? Then I need to record the IR input for the buttons I want(from the manual witch I have read on this). Then I create a input rutine to use those codes. NOT sure how to do that but I would like to develop a INC file to use IR input. Maybe It is simplers than I think it is but I would like to know what others may have done with the IR receiver. I did search for IR here but try that for yourself. Thanks all. |
||||
CircuitGizmos![]() Guru ![]() Joined: 08/09/2011 Location: United StatesPosts: 1427 |
The manual shows a really simple example of the IR function making a interrupt happen where the codes are then PRINTed. Micromites and Maximites! - Beginning Maximite |
||||
Sasquatch![]() Guru ![]() Joined: 08/05/2020 Location: United StatesPosts: 377 |
Also, nearly all of the remotes that I have tried work (TV, DVD etc.) what changes are the "Device code" and "Key Code" are different depending on the brand of remote. If you do buy a remote, your CMM2 likely has a 38kHz receiver as that is what is specified in the documentation. Edited 2020-10-11 05:19 by Sasquatch -Carl |
||||
CircuitGizmos![]() Guru ![]() Joined: 08/09/2011 Location: United StatesPosts: 1427 |
38 kHz receivers have enough slop that they usually pick up 36-40kHz. Micromites and Maximites! - Beginning Maximite |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
I tend to only use Sony remotes and they seem to have standardized on 40kHz, so I use the 4840 IRX IC, but as CG says - the 4838's do tend to be good enough for the 40kHz remotes also. I used remotes like this semi regularly. An expansion of the demo code in the manual, is a bit of this code from my latest call-bell system: The above code sample sets up all the remote control key values, and DEV is the device code, which never changes for any one specific remote control. ...and that bit of code starts the background interrupt... ...and this bit of code is the actual interrupt that is executed whenever a button press is detected. Note the application of one of the ten commandments of writing interrupts: 'Thou shalt not hang around in interrupts.' - keep interrupts very short, and process the results inside your main loop NOT inside the interrupt. ...and I use that simple one-dimension array to store the remote key-codes for lookup later on. The GET_SLOT sub, which accepts two remote control keypresses for the two-digit input between 01 and 99 in the menus: These bits of code are just some examples of how you can process remote-control keypresses. There are many ways to do it, and each programmer tends to have their own way of coding, so you may well come up with something else. I'm just using a simple FOR/NEXT loop for each digit, looking for a match between the code received, and one of the values in the NUMS array. After you enter the two digits, the result is saved in a global variable(DIG) for analysis by the main loop. IR remote controls are very useful in your project, and they are easy to code for once you get the hang of how interrupts need to work, and how you process codes received by the interrupt in the background, inside your main loop. EDIT: One last little bit of code, showing you how I check the value of DIG, as returned by the sub above, for valid numbers: So, we have the situation where the main loop is calling the GET_SLOT sub, which is then using the IR interrupt for each keypress, updating the global variable DIG and then exiting back to the main loop - where DIG is analysed to see if it is valid or not and taking action based on that. Edited 2020-10-11 15:47 by Grogster Smoke makes things work. When the smoke gets out, it stops! |
||||
mclout999 Guru ![]() Joined: 05/07/2020 Location: United StatesPosts: 490 |
Grogster: Thanks your responce is like a master series in IR. It will take some time to figure it out but thanks for the information and examples. |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
My examples are perhaps a bit advanced, but they do show you how you handle IR key presses. Would you like a really simple example code(complete, not bits like above) that just waits for keypresses and shows your choice on the console? You might be able to more easily learn from that then from my code extracts above where I was doing quite specific things. Smoke makes things work. When the smoke gets out, it stops! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
This is what I used when I was repairing my TV remote and needed to test all keys ' recieve NEC IR codes dim integer IRdev, IRkey, revIRkey IR IRdev, IRkey , IRint do if IRrec = 1 then revIRkey = bitReverse(IRkey, 8) print hex$(IRdev,4);" ";hex$(IRkey,2);" ";hex$(revIRkey,2) IRrec = 0 endif loop until inkey$ <>"" end sub IRint if ((IRdev>>8)and &hFF) = (inv(IRdev) and &hFF) then ' we have an 8 bit device code. IRdev = IRdev>>8 and &hFF endif IRrec = 1 ' set a flag to indicate reception of code end sub function bitReverse(x!, k!) as integer local integer n for n = 1 to k! bitReverse = (bitReverse << 1) + ((x! >> n) and 1) next n end function The code works but the TV remote is starting to play up again... Jim VK7JH MMedit |
||||
CircuitGizmos![]() Guru ![]() Joined: 08/09/2011 Location: United StatesPosts: 1427 |
"The above code sample sets up all the remote control key values, and DEV is the device code, which never changes for any one specific remote control." True mostly. I have remotes that break that rule. This type of remote has TV keys with one device code and DVR keys that emit a different device code. Micromites and Maximites! - Beginning Maximite |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |