Friday, May 23, 2014

Arduino IR Blaster

My IR blaster is built on a LeoStick which is an arduino compatible USB stick. I must be a sucker for punishment because I thought it would be easy to make one of the many IR libraries work on here and control my Samsung TV.

There were two problems with my plan. First, the defacto IR libraries don't allow me to use the necessary IO pins and second, Samsung IR codes are not supported.

Rather than detail what when wrong, I will present my solutions.

The first problem arises because the LeoStick has a green LED attached to Digital IO pin 9 which is the default PWM Timer used by Ken Shirriff's IR library. The solution is an updated fork of this library Chris Young which implements more Timer chips and enables selecting Digital IO pin 5. Do to that, edit IRLibTimer.h and find the section with the heading 'it's probably Leonardo' (the LeoStick is apparently compatible with the Leonardo). Comment out the default #define and uncomment the IR_USE_TIMER3. (I wonder why we can't select this at run time?). Based on the IRLib manual, I also installed my IR LED with whatever resistors I had on hand (470 ohm I think).

So, thanks to the hard work of these guys, I have got my LED working. Now, to make it talk Samsung protocol.

There were a few snippits of code in various forums but I had to piece that together into the format for IRLib. I have only added sending as I already have a list of codes from SamyGO and LIRC. The only code I wanted to use is TV_POWER 0xE0E040BF because once the TV is on, I can talk to it via the network.

I have submitted my changes as a GitHub pull request. If they are not accepted in the upstream library you can find them here https://github.com/jnewbigin/IRLib

The final piece to the puzzle is making the IR code send when I want it to. To keep this generic, I made my sketch read a hexadecimal code from the serial port. When it receives a code it just send it, thus allowing control over the time and the code. This could probably be integrated with LIRC but I am just using a simple shell command
echo 0xE0E040BF > /dev/ttyACM0

So here is my sketch. There is not much error detection in the serial reading but what is the worst that can go wrong?

/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
 * Version 1.3   January 2014
 * Copyright 2014 by Chris Young http://cyborg5.com
 * Based on original example sketch for IRremote library
 * Version 0.11 September, 2009
 * Copyright 2009 Ken Shirriff
 * http://www.righto.com/
 *
 * Modified by John Newbigin to support Samsung and USB control May 2014
 */
#include <IRLib.h>

IRsend My_Sender;

void setup()
{
  Serial.begin(9600);
}

void p(char *fmt, ... ){
        char buf[128]; // resulting string limited to 128 chars
        va_list args;
        va_start (args, fmt );
        vsnprintf(buf, 128, fmt, args);
        va_end (args);
        Serial.print(buf);
}

// 0xE0E040BF = Power
void sendCode(unsigned long code)
{
   p("Sending SAMSUNG 0x%08lx\n", code);

  for (int i = 0; i < 3; i++)
  {
    My_Sender.send(SAMSUNG, code, 0);
    delay(30);
  }
}

unsigned long ir_code = 0;
void loop() {
  while(Serial.available() <= 0)
  {
    delay(10);
  }
  int incomingByte = Serial.read();

  int nibble = -1;
  if(incomingByte == 10)
  {
    p("Got newline\n");
    sendCode(ir_code);
    ir_code = 0;
  } 
  else if(incomingByte == 13)
  {
    // ignore
  }
  else if(incomingByte >= '0' && incomingByte <= '9')
  {
    nibble = incomingByte - '0';
    p("Got digit %d\n", nibble);
  }
  else if(incomingByte >= 'a' && incomingByte <= 'f')
  {
    nibble = incomingByte - 'a' + 10;
    p("Got hex digit %d\n", nibble);
  }
  else if(incomingByte >= 'A' && incomingByte <= 'F')
  {
    nibble = incomingByte - 'A' + 10;
    p("Got hex digit %d\n", nibble);
  }
  else if(incomingByte = 'x')
  {
    p("Starting number\n");
    ir_code = 0;
  }
  else
  {
    p("Got %d\n", incomingByte);
  }
 
  if(nibble >= 0)
  {
    ir_code<<= 4;
    ir_code+= nibble;
    p("Code is 0x%08lx\n", ir_code);
  }
}

44 comments:

  1. Thank you for your sharing. Thanks to this article I can learn more things. Expand your knowledge and abilities. Actually the article is very practical gmail login

    ReplyDelete
  2. great post. i like it. feeling great when reading your post

    Mutilate A Doll 2

    ReplyDelete
  3. Very helpful advice in this particular post! It’s the little changes that make the largest changes. Thanks for sharing!
    vex 3

    ReplyDelete
  4. Really i am getting inspired and i hope you will be awesome activity you have! but i want to learn this i am using Mass Texting and i have to get many learn and received activities messages you must to check it’s very helpful service and this is really informative blog well sharing more and keep it up your success

    ReplyDelete
  5. I think this webpage is a standout amongst the best I have seen so far on the web. You examine probably the most recent technique on split testing in a compelling way. The article is talked about in a brilliant way and I am happy that it has helped me to such an extent. Now every things are colorful because colorful thing always attract user and Color is also a key element in custom logo design and plays an important role in brand identification. design colorful and meaningful logos by world best designers.

    ReplyDelete
  6. This was an awesome article! If you want to know the History and Facts of Tarot Cards, please refer yourtarotlife.com.

    ReplyDelete

  7. I like your article very much, thanks for sharing the good information we have read.
    hotmail login email
    gmail sign up

    ReplyDelete
  8. Along these lines, you are an administration worker AND a Linux nerd. Join the club. best cleaning companies in dubai It is conceivable to utilize your savvy card to get to DOD CAC Card empowered destinations.

    ReplyDelete
  9. Spectrum Internet offers amazing deals on its service, no matter what speed you require. According to speedtest.net, they deliver the fastest internet in the US. Plus, they delivery these internet speeds at affordable prices along with providers all across the US which you can search based on your location.

    ReplyDelete
  10. Speedily this excellent website may possibly without doubt always be well-known amidst virtually all blogs folks, to the thoughtful articles or blog posts or maybe testimonials. VIn number

    ReplyDelete
  11. I really treasure your piece of work, Great post. Oscar Awards 2020

    ReplyDelete
  12. I simply wanted to thank you a lot more for your amazing website you have developed here. allegheny county real estate It can be full of useful tips for those who are actually interested in this specific subject, primarily this very post.

    ReplyDelete
  13. You know your projects stand out of the herd. There is something special about them. Room addition

    ReplyDelete
  14. Sometimes it is on top of that an awesome posting garage repair

    ReplyDelete
  15. I liked your blog and the detailing you have provided about IR blaster, Can I share it on Geek Squad tech support

    ReplyDelete
  16. I would love to use some experts of this for a report I am doing I hope that would be okay. Eyal Nachum

    ReplyDelete
  17. Our team of trusted dissertation writers works on your task with thorough concentration. This results in the completion of work even before the deadline.
    someone write my essay for me | dissertation writing services

    ReplyDelete
  18. The next time I learn a weblog, I hope that it doesnt disappoint me as much as this one. hazard perception test qld practice

    ReplyDelete
  19. It is really an extraordinary and obliging piece of data. Federal Pacific panel

    ReplyDelete
  20. Speedily this excellent website may possibly without doubt always be well-known amidst virtually all blogs folks, to the thoughtful articles or blog posts or maybe testimonials. Albagora

    ReplyDelete
  21. Great post! I like your blog because of its content which is very helpful to many. federalprocessingregistry.com

    ReplyDelete
  22. I have perused every one of the remarks and proposals posted by the guests for this article are very fine Skip hire bristol

    ReplyDelete
  23. ITach WiFi devices provide a new level of control flexibility, for ... compatibility with control-based computer software

    click

    ReplyDelete
  24. I am very happy to read this. Appreciate your sharing play gem swap 2

    ReplyDelete
  25. I am usually to blogging and i genuinely appreciate your content regularly. mp3juices

    ReplyDelete
  26. Thank you very much for this great post.satta king

    ReplyDelete
  27. https://medium.com/@sadik8877/watch-joker-full-2020-streaming-online-7024315dfbd6
    https://medium.com/@sadik8877/watch-joker-2020-full-online-free-streaming-da82fab37755
    https://medium.com/@sadik8877/putlockers-hd-watch-joker-2019-online-full-for-free-15da8ef3d519
    https://medium.com/@sesbikel2/123movies-watch-joker-2020-hd-full-movie-online-free-32ecd293196b
    https://medium.com/@sesbikel2/hd-joker-2020-4k-full-movie-watch-online-download-38e629a8a482
    https://medium.com/@sesbikel2/download-and-watch-joker-full-movie-hd-2020-e4e76ff53063

    ReplyDelete
  28. Good Subway Surfers download. I think I may be a little to late to vote though.

    ReplyDelete
  29. https://wrestlemanianfo.com/wwe Wrestlemania 2020

    ReplyDelete
  30. Your opinion is great, it is exactly what I think. If we go in that direction, everything will become much more perfect potty racers 4

    ReplyDelete
  31. IR Transmitter and Receiver Using Arduino: Tv ir remote uses InfraRed NEC Protocol for communication between infraRed remote and Tv itself.

    click on here

    ReplyDelete
  32. This post is good enough to get someone to understand this great thing, and I'm sure people will appreciate these interesting things play

    ReplyDelete
  33. It seems like the major phone manufacturers are moving away from built in IR blasters so I'm looking for a way to future-proof my "dumb" devices that don't currently integrate with my IoT infrastructure. I have a mesh-networked smart home, but I need to find a physical remote to turn on my TV? There has to be a better way.
    about us

    ReplyDelete
  34. ABC Assignment Help is an ethical place where students can get Chinese Assignment Help services at the best price. Our professional academic experts consistently help students in assignment which is free of plagiarism.
    Chinese Assignment Help

    ReplyDelete
  35. hp printer won't print black can happen due to multiple reasons such as dry or empty black ink cartridge, Printed clogging, or software related issues. For early diagnosis, you should always check and verify if you are the ink cartridges are full and not empty. The next step should be to confirm for the Clean printhead; your HP printer is equipped with an automatic printhead cleaning tool, which can be run through Control Panel. There might also be a chance of a blocked nozzle, and it can be cleaned with the help of a cotton swab. Additionally, you should always ensure to use the genuine ink cartridges and routine maintenance of your printers. I hope you will now get rid of the HP printer won’t print black

    ReplyDelete
  36. On a regular basis, many users are using canon printer for the excellent printing services. Users prefer canon printers for their personal or official usages. It is certain that user can face minor or major technical issues while printing procedure. If your canon printer is not printing the documents, you can get connected with live printer experts to get full technical support to sort out canon printer not printing issue immediately. Our canon printer troubleshooting team is highly skilled and rich experienced to recognize the major reasons of canon printer not printing and apply the best technical resolutions to resolve this error within a few seconds.
    canon printer troubleshooting

    ReplyDelete
  37. When QuickBooks desktop is unable to launch properly, QuickBooks Error 80029c4a arises which signifies the some of the necessary files are either missing or corrupt. QuickBooks Error 80029c4a signifies that the dynamic link library file got corrupted somehow. Sometimes this also indicates that your system might be at risk to the virus. You better check your antivirus and firewall configuration to rule out that possibility. If the process seems complicated to you and you need assistance. We are happy to help you with this simple process. Our technical support team can resolve this issue within a few minutes. Get in touch today!

    ReplyDelete
  38. Assignment Help Hong Kong is the best option to complete academic papers without any stress. If you don’t want to degrade your academic performance, make sure to connect with the professional service provider of assignment writing help.
    Assignment Help Online
    Online Assignment Help

    ReplyDelete
  39. I am applying my technical skills to resolve this technical problem, but I am facing a lot of problems. Hence, it has become a critical situation for me. I don’t have complete technical knowledge to find out the major reasons of this technical error. So I look for the permanent resolutions to resolve AOL Gold Icon not responding problem as soon as possible.

    ReplyDelete
  40. McAfee is one of the best and powerful antivirus software, if you’re finding for an antivirus program for your computer system. You can install, and activate McAfee antivirus software at mcafee.com/activate. This antivirus program provides the safe and secure online browsing and safeguards all your important and valuable data. If you get stuck to install McAfee antivirus software, you can take specialized help from our certified antivirus experts.

    ReplyDelete
  41. MkvPoker Adalah Situs Judi Poker Terbaik Dengan Taruhan Uang Asli Yang Menjaminkan Kemenangan Yang Tinggi

    Wa : +855 9637 31855

    ReplyDelete