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);
  }
}

33 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