Saturday 6 April 2019

Raspberry Pi - Setting up Energenie IR Blaster Board for Alexa control (Part 1 - getting the remote working on the PI)

Please note I am not an expert on this so please don't mail me questions, the information here is a mixture of tips and instructions I have found on the web.
Some were old and contained incorrect commands and some were new but missed other steps.

I'll assume people reading this are OK installing versions of linux and using editors such as nano.

  • Install the Energenie board into your Pi (in my example I'm using a Pi version A) and the board  just plugs into the Pi.
  • Install Raspbian Sketch - I'm using the lite version because I don't need a graphics interface, I created my SD card using Etcher.
  • I've set my Pi up for a fixed IP (so I can ssh into it easily)
  • As it's a Pi Version A I've configured a USB dongle to connect to Wi-Fi.
  • SSH is configured so I can remote into the Pi
  • I've changed the root password for security.
  • The Pi is configured so it boots into the operating system without requiring the password (for automatic operation).
Most of the items above such as IP address, SSH and auto boot are configured through the raspi-config tool from command line.
Using SSH means I can run the Pi "headless" without a monitor connected and any changes or commands can be done from a remote computer - for example rebooting or changing configuration.


At this point you should have a Raspberry Pi, configured with Raspbian Sketch and ready to go.


Check all updates are installed

sudo apt-get update
sudo apt-get upgrade

Now install lirc

sudo apt-get install lirc
sudo apt-get install lirc-x

The Energenie uses pin 12 - GPIO18 for Input and Pin 11 - GPIO17 for output.

edit /etc/modules and add the following lines

lirc_dev
lirc_rpi gpio_in_pin=18 gpio_out_pin17

edit /boot/config.txt and add the following line

dtoverlay=lirc-rpi,gpio_in_pin=18,gpio_out_pin=17

Edit /etc/lirc/hardware.conf and add the lines below

LOAD_MODULES=true
DRIVER="default"
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"LIRCD_CONF=""
LIRCD_ARGS="--uinput --listen"
LIRCMD_CONF=""

If /etc/lirc/hardware.conf does not exist you can create it with the "touch" command i.e. touch /etc/lirc/hardware.conf


(If you get permission errors you might need to precede your command with sudo so you've got higher level permissions).

Edit /etc/lirc/lirc_options.conf and change the entries for device and driver to the ones below.

device = /dev/lirc0
driver = default


I had issues getting the service to start, the reason is most guides contain old command references for the service

Instead of the service being called lirc it's now called lircd

stop and start the service with the following commands

sudo /etc/init.d/lircd stop
sudo /etc/init.d/lircd start

You can check if the service is running with the following command.

sudo /etc/init.d/lircd status

At this point you should be able to test the IR is working.

You might want to reboot so everything is running and all files are in sync.

Stop the service

sudo /etc/init.d/lircd stop

Run this command

mode2 -d /dev/lirc0

Point a remote control at your pi and press some buttons, you should see output similar to this.

Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
space 16777215
pulse 15319054
space 3441
pulse 1772
space 395
pulse 485
space 385
pulse 1341
space 392
pulse 473
space 485
pulse 397

At this point the IR interface is receiving commands, the next step is to program it up to store commands and transmit them.
The following command will create a custom remote control configuration file in your home directory, the filename is specified when you are running the irrecord program.

sudo irrecord -d /dev/lirc0 ~/lircd.conf
You will see output similar to the text below (not all the output is shown).












In this example I'm creating a remote control file for "Soundbar"

Running as regular user pi
Using driver default on device /dev/lirc0

irrecord -  application for recording IR-codes for usage with lirc
Copyright (C) 1998,1999 Christoph Bartelmus(lirc@bartelmus.de)

This program will record the signals from your remote control
and create a config file for lircd.

A proper config file for lircd is maybe the most vital part of this
package, so you should invest some time to create a working config
file. Although I put a good deal of effort in this program it is often
not possible to automatically recognize all features of a remote
control. Often short-comings of the receiver hardware make it nearly
impossible. If you have problems to create a config file READ THE
DOCUMENTATION at https://sf.net/p/lirc-remotes/wiki

If there already is a remote control of the same brand available at
http://sf.net/p/lirc-remotes you might want to try using such a
remote as a template. The config files already contains all
parameters of the protocol used by remotes of a certain brand and
knowing these parameters makes the job of this program much
easier. There are also template files for the most common protocols
available. Templates can be downloaded using irdb-get(1). You use a
template file by providing the path of the file as a command line
parameter.

Please take the time to finish the file as described in
https://sourceforge.net/p/lirc-remotes/wiki/Checklist/ an send it
to  so it can be made available to others.

Press RETURN to continue.

Checking for ambient light  creating too much disturbances.
Please don't press any buttons, just wait a few seconds...

No significant noise (received 0 bytes)

Enter name of remote (only ascii, no spaces) :Soundbar
Using Soundbar.lircd.conf as output filename

Now start pressing buttons on your remote control.




It will guide you through pressing buttons randomly and then create the custom keys.

For a list of valid lirc command keys type

irrecord --list

To test the functionality I programmed keys for

KEY_VOLUMEUP
KEY_VOLUMEDOWN
KEY_POWER
KEY_MUTE

The file "Soundbar.lircd.conf" was created in the home folder.

From lirc version 0.9.2 you don't need to merge configuration files into one, you just copy the conf file to a folder and they are automatically included in the list of commands.

In this case I'll copy "Soundbar.lircd.conf" to the correct folder (/etc/lirc/lirc.conf.d)

The first command will make sure I'm in my home directory.


cd ~/

You could list the files in the directory to check the file is there.

ls

Soundbar.lircd.conf

Now copy the file, be careful typing in the command, the file is filename.lircd.conf but the directory it's going into is under /etc/lirc - i.e. it doesn't have the "d" at the end.
If you use the command below as reference just replace "Soundbar" with whatever you called your file.

sudo cp Soundbar.lircd.conf /etc/lirc/lircd.conf.d/

The original file will still be in your home directory should you need it.
At this point we should be at the point we can test the transmission.

I would restart the lircd service so it reloads any configuration files.

sudo /etc/init.d/lircd restart

The command to send an IR function is "irsend" and the syntax is

irsend SEND_ONCE Remote_Name Remote_Button

For my test file I'll see if the Soundbar turns on, then I'll send Volume UP and DOWN etc.

irsend SEND_ONCE Soundbar  KEY_POWER

The Soundbar should turn on (as long as the Pi is pointing reasonably in the right direction).

To test the other keys just repeat the command with the key name

irsend SEND_ONCE Soundbar KEY_VOLUMEUP


irsend SEND_ONCE Soundbar KEY_VOLUMEDOWN


irsend SEND_ONCE Soundbar KEY_MUTE

You can use a command "irw" to confirm your programmed buttons, type irw and then press your remote buttons, you'll see confirmation of the ones you've programmed  with their command value.

irw
0000400405000401 00 KEY_VOLUMEUP Soundbar
0000400405008481 00 KEY_VOLUMEDOWN Soundbar
0000400405004c49 00 KEY_MUTE Soundbar


Press Ctrl + C to exit the irw program.

At this point you should
1)  Have lirc working on a Pi
2) Be able to stop and start the lircd service
3) Be able to create a custom remote control key file
4) Be able to copy this file from your home directory to the correct lirc folder.

My next step is to get Alexa skill and see how to control it - the ultimate aim is to get the remote downstairs and for my wife to issue a macro such as "Alexa, Media ON" to turn the TV, Cable and Soundbar on.



Monday 19 March 2018

Yamaha Keyboard Community



What a strange couple of weeks I've just had.

I was in a forum for quite a few years (https://yamaha-keyboard-community.com), I'm not one of those who has a lot of spare time so I would go on sometimes a bit more than others.

As time went on I built up some great friendships and even got involved helping people with computer problems and such, it was a good place to have a chill out here and there.

Over the last six months I've been training to take over the roles of a colleague who was retiring, then I've taken this role over on top of my other tasks. This reduced my spare time and my keyboard playing/forum/Xbox time.

It was quite a surprise when I went onto the forum recently and found messages telling me I wasn't authorized to view content (such as the image below)




To cut a long story short (after sending a couple of mails to the admins) I'm told the founder of the forum Kxxxx had decided to "leave the forum and have nothing more to do with it", He did this before then had a change of mind and spent ages putting all his deleted posts back.

In the same mail I'm given a reason/excuse why my account has been demoted to make it non functional - one of the quotes is below.

Kxxxx dropped you down to "Guest". Why? It had been noticed that you had been rather selective on which other members posts / songs you would respond to with some receiving no response from you at all. I and Kxxxx stopped responding to your music to give you the hint that you couldn't expect people to respond to you if you didn't reciprocate. An occasional "Sounds good" just didn't cut it. When you responded to one of mine and a couple of others I reciprocated - again to show that joining in has its rewards.


Surely the purpose of a forum like this is to come and go as I please, I agree I might not listen to every song but I have a work life and simply not much time outside of it.

But, If I choose to comment or not then surely that's my choice, If I choose to comment what should I put or not put?
Clearly there are some unwritten rules here that I'm not aware of, when I ran a forum in the past I let people come and go as they pleased and write whatever they wanted as long as it's not offensive or similar.

Anyway, my account was reinstated but I felt I wanted to take some time out as I'm pretty pissed that someone who's thrown their toys out the pram (for the umpteenth time and abandoned his forum) has decided to vent his childish and immature attitude on me, I make no mention of what's going on on in the forum posts, someone actually posted a comment asking where I was and another member, I responded that I'm taking some time out and nothing more.

I'm in a couple of other forums so I joined another to see what's happening on that, I complete my profile and post a song into a challenge section.

I then found my account demoted again.

I then get this amazing response (this is part of the email but it's perhaps the best bit)

I am really sorry that things have turned out this way. As you know I wasn’t best pleased that most of my posts seemed to be ignored but I have a different way of looking at things and (maybe childishly) ignored yours for a while to see if you would get the message. Perhaps I should have just asked you why you were ignoring my posts but that wouldn’t have been right either. I know that Kxxxx was miffed as you had not responded to any of his songs for a while and maybe he thought that you didn’t think our music was up to your standard.

When you said you were taking time out I said to Kieth that he should leave yours and Mxx’s accounts open to see what happened. Mxx on joining YKF said that he thought that YKC had ground to a standstill and it was a pity as Kxxxx and Bxxxxx had done so much hard work. – A bit annoying that as Mxx poured his back catalogue and later songs on to the forum and rarely responded to anyone else’s work so it was no wonder that not only Kxxxx and I stopped responding to him. When you made your big intro on YKF it looked as if you had made up your mind and Kxxxx saw it as such.

Kxxxx has started to get back into the forum and is replacing all the posts he deleted.

So - the forum admin who left (deleted all his posts,all his YouTube content, all his Google+ content and everything else) is back on the forum and posting all his deleted material back on.

I would be cautious if you join this forum, it says it's the friendliest forum on the web yet I find myself barred from participating because I might have missed one or two songs posted by the two administrators (or not commented at the correct/unknown level), I'm not sure what the comment means that I might feel other peoples playing is not up to my standard? Everyone is different, who am I to judge others and say they shouldn't be playing or other negative comments - I wouldn't be pretentious enough to consider myself above others, anyone who plays an instrument is unique to others, much as an artist or sports person is, it's the unique quality that makes us who we are.

I invite you to make your own mind up if you join this forum, I can't advise you on how often you should post, what songs you should and shouldn't post, what you should/shouldn't put in any comments or how you should interact.
From my perspective I assumed everything was going along swimmingly but clearly not - it's like a marriage to someone who won't tell you what's wrong but insists you fix the problems immediately.

I'm sure If the admins want to sue me for posting this or log a complaint then I'll produce the emails to prove that everything above is exactly as it happened - there can't be a complaint if I'm not rude and am producing the facts?

If however they want to apologise then I'm sure we'll all like to hear it, I'm big enough to apologise if I offend someone or screw up so I expect others to as well.

At the moment I'm so gobsmacked at the petty and childish actions that I don't actually know what to say other than some very choice swear words, you think you have made some great friends and are enjoying interaction but I suppose you don't know people as much as you think.

I almost feel that I'm back at school, my friend is no longer my friend because I spoke to someone else or didn't do something they wanted, their feet are stamping and their arms are folded tightly to their chest while they look at the ground.

It's hard to think they are grown men and have the nerve to tell others how, why and when I should interact with others - it's a disgrace and HOW DARE YOU!

Since writing this the Admin had yet another tantrum and put an amazing message on the site "due to a boycott by most members the forum is now closed".

As before, he's blaming others for his own shortcomings but at least others won't experience his childish actions.

Kev