Monday, October 01, 2018

Revitalising an Audiotron - Part 1

- New life to an old device

///THIS IS A FIRST DRAFT TO GIVE SOME POINTERS SO THAT SOMEONE ELSE CAN TRY IT OUT .. it might have mistakes and sections that are not clear because this started simply as a scribble pad as I experimented.
So - if you are going to try it out then let me know and we can go through things slowly together and improve the guide.
Sorry - no pictures yet///


Long ago I wrote about my first experiences with Internet radio devices. It was the Audiotron that I started with. It still works fine but I wanted to have a go at converting it so that it can have a new lease of life.
My efforts of a while ago to get the "TurtleRadio" function within it live again and then to keep it alive plus the likelihood that keeping the old SMB client within the embedded Windows operating system working against changing household infrastructure would become more difficult in the future so I speculated to others about reusing much of the hardware but putting a Raspberry Pi inside the case to do most of the work.
This resulted in a quick response from Sam Zantos to say that it he had already done it - although his approach used a combination of Raspberry Pi and Arduino.
So I thought that I would try to do it myself and see how far I could get with only a Raspberry Pi and document the steps.

I have had this working on a Rev 1 Raspberrry Pi and the Raspberry Pi 2 that was released in February 2015.

In my case, I want it to become a "Squeezebox" client (and possibly a LMS server) so that it works with the other main components dotted around the house.
The hardware parts (display, infra-red remote, keys, rotary encoder) would be largely the same solution regardless of the software - so I will cover that first.

But before we get into that, it is important to note that if you follow the steps described here then you would be opening up your Audiotron and taking things apart and then putting them back together in a different way.
Clearly any such actions need to be taken with great care since you are working with a device that connects to an electricity supply. At no time during these steps do you need the Audiotron power to be switched on - so disconnect that first of all. But if you do reconnect it then be very careful to ensure that everything is safe and you have done nothing silly like leaving a bare wires or some jumper wires lying around inside the case.

Everything described here is undertaken at your own risk.

The detailed description of using a compatible display controller and rotary encoder at http://www.bobrathbone.com/raspberrypi_radio.htm (the PDF in particular) was the ideal starting point.

I wanted to do this in a way that would be easily reversible and something that could be tackled by someone with almost no electronics skills - so I have avoided cutting wires or soldering.

This Part 1 goes through the steps to get the LCD and infra-red remote control working with a Raspberry Pi (RPi).

So - here we go ...

Disconnect the Audiotron and open up the case - 5 screws on the back and 3 on each side. The 2 screws on each side towards the front are longer than the other. The case slides out backwards - nothing else is attached to it.
Then use Dupont/jumper cables to join up various parts of the Audiotron to the RPi.

Disconnect the ribbon cable at JP4 - by carefully pulling it upwards using the edges of the connector - not the cable. There is a red line on the cable to denote pin 1.
You can then plug in your jumper cables into the end of the cable - male in this cable and female onto the RPi GPIO connector.
Following the numbering guide below.

The Audiotron infra-red and rotary controller connects to JP3 on the Audiotron board.
My Audiotron did not have ZIF a socket for this cable. If your is the same then simply pull the cable straight up and out of the socket - do not wiggle it.
If yours has a ZIF socket then release the lock (typically by pulling up the sides) and the cable comes out very easily.

This cable is more difficult to get connected to the RPi. I managed to find a supplier of an adapter that can take this 1mm pitch FFC/FPC cable and connect it to a breadboard. They even modified their standard product to make all new shipments use ZIF sockets. So top marks to Technological Arts, Inc of Toronto Canada. I bought 2 of their ADIMMFLEX24 connectors. These are for 24-way FPC cables but we do not need that many for the Audiotron. So take care when putting the cable in to make sure that you have pin 1 lined up exactly. They were contemplating making some adapters for different numbers of pins - so if you get the choice then you need a 10 way (rotary and IR) and a 22 way (keys).
Now plug the adapter into the breadboard and then run cables to hook up the IR device.
NOTE: I could not get the IR device to work at 3.3v (3v3) so I connected it up to a 5v pin on the RPi GPIO connector. This then brings the danger of feeding 5V back into the GPIO data pin and causing damage because it cannot take that much. So it is essential to put a resistor into the circuit.

Note - shows how long ago I was working on this ... the RPi pin numbers below are for the very first Raspberry Pi model that had only 26 GPIO pins. Devices after that have 40 and that should make it much easier to connect up more of the Audiotron buttons. However, check carefully that the pins described below do remain the same for 40 pins versions (for example some might have dual purpose and need to be configured at boot time).

RPi
Pin Number
RPi
Pin Name
Audiotron
LCD
JP4
Audiotron
Rotary knob  and IR
JP3
Audiotron
Keypad
JP2
13V3


25V2 (+5V)1 (+5V) IR ***
3GPIO2
45V
5GPIO3
6GND5 (RW)6 (GND)
7GPIO4
8GPIO14
9GND1 (GND)
10GPIO15
11GPIO17
12GPIO1814 (D7)
13GPIO21 (GPIO27)
14GND3 (Contrast)
15GPIO222 (DATA) ***
16GPIO2313 (D6)
173V3
18GPIO2412 (D5)
19GPIO10
20GND
21GPIO9
22GPIO2511 (D4)
23GPIO11
24GPIO86 (EN)
25GND
26GPIO74 (RS)
Unused:
3 (Contrast adjustment)
7,8,9,10 (D1,D2,D3,D4)

*** Take care with the IR voltage. Mine would not work at 3.3V but Sam said that his did.
If you go with 5V then you need to protect the GPIO pin with a resistor.
So try 3.3V first (pin 1 on RPi) and if the IR tests do not work then try 5V but fit a resistor first (certainly if using an old RPi like I was). I put a 4k7 resistor in series between the data pin and the GPIO pin.

The software starting point of these instructions is Squeezeplug - http://www.squeezeplug.eu
At the time of writing the version of Squeezeplug was 7.5 (released December 2014).
However, the instructions are likely to work with other releases but it might miss some of the prerequisites and you would have to resolve them yourself.

The commands below assume that you are logged into your Raspberry Pi as user "pi".


Bringing the LCD to life:

Install LCDproc

sudo apt-get install lcdproc

Then check the version that was installed with the following command
lcdproc -v

This should respond with something like:
LCDproc 0.5.5


If the version is lower than 0.5.7 then this version does not include the built-in support for Raspberry Pi GPIO driven support of the HD44780-compatible LCD controller.

Also - if you are using a "Raspberry Pi 2" then there might be a problem - depending on whether or not the version that you have recognises the RPi. I made a change to my version to handle this but at the time of writing this that update had not been made in the official source. If that is still a problem then I'll put my version somewhere for download or contact me if I have not yet done that.


# If you need to make and install the CVS version of LCDproc:   

  sudo apt-get install cvs autoconf automake

  # download the CVS source, then make and install
  cvs -z3 -d:pserver:anonymous@lcdproc.cvs.sourceforge.net:/cvsroot/lcdproc \
      checkout -P lcdproc

  # make and install the CVS source
  cd lcdproc
  sh ./autogen.sh
  ./configure --prefix=/usr --sysconfdir=/etc  --localstatedir=/var \
              --enable-drivers=hd44780
  make

  # do a sanity check on LCDd before installing it
  sudo invoke-rc.d LCDd stop
  server/LCDd -f    # a curses LCD emulation window should show.
           # terminates LCDd

  # install the new version over the old version
  sudo make install



Configure LCDproc:

Then edit the LCDproc configuration file to use the hd44780 compatible LCD
locate:
sudo nano /etc/LCDd.conf

Locate the section that starts
## Server section with all kinds of settings for the LCDd server ##
[server]

In there you will see
DriverPath=
If the full line is
DriverPath=server/drivers/
then it has been set to that via the installation of the special lcdproc
but since the installation has been done then change it to the usual value
DriverPath=/usr/lib/lcdproc/
If you do not do this then the process will not start properly

Then look for
Driver=
and above that are a list of supported devices.

Probably it shows:
Driver=curses
Change to
Driver=hd44780

Then look for
## Hitachi HD44780 driver ## [hd44780] # Select what type of connectiDriverPath=server/drivers/on. See documentation for types. ConnectionType=4bit

and change to
ConnectionType=raspberrypi

The scroll down to find Size=
and change from
Size=20x4
to
Size=40x2


You can also change the lcdproc startup and exit message to personalise things.
These appear on the LCD screen
# Hello message: each entry represents a display line; default: builtin #Hello=" Welcome to" #Hello=" LCDproc!" # GoodBye message: each entry represents a display line; default: builtin #GoodBye="Thanks for using" #GoodBye=" LCDproc!"

You could change these to something like:
# Hello message: each entry represents a display line; default: builtin Hello=" Welcome to" Hello=" rpitron" # GoodBye message: each entry represents a display line; default: builtin GoodBye="Thanks for using" GoodBye=" rpitron"


Next is to get the audio player installed.

Squeezelite with LCD support

sudo apt-get install libasound2-dev libflac-dev libmad0-dev libvorbis-dev libfaad-dev libmpg123-dev liblircclient-dev libncurses5-dev


git clone https://github.com/fpasteau/squeezelite.git

cd squeezelite
OPTS=-DINTERACTIVE make

Assuming all goes well - it should look something like this:
pi@rpitron ~/squeezelite $ OPTS=-DINTERACTIVE make cc -Wall -fPIC -O2 -DINTERACTIVE main.c -c -o main.o cc -Wall -fPIC -O2 -DINTERACTIVE slimproto.c -c -o slimproto.o cc -Wall -fPIC -O2 -DINTERACTIVE buffer.c -c -o buffer.o cc -Wall -fPIC -O2 -DINTERACTIVE stream.c -c -o stream.o cc -Wall -fPIC -O2 -DINTERACTIVE utils.c -c -o utils.o cc -Wall -fPIC -O2 -DINTERACTIVE output.c -c -o output.o cc -Wall -fPIC -O2 -DINTERACTIVE output_alsa.c -c -o output_alsa.o cc -Wall -fPIC -O2 -DINTERACTIVE output_pa.c -c -o output_pa.o cc -Wall -fPIC -O2 -DINTERACTIVE output_stdout.c -c -o output_stdout.o cc -Wall -fPIC -O2 -DINTERACTIVE output_pack.c -c -o output_pack.o cc -Wall -fPIC -O2 -DINTERACTIVE decode.c -c -o decode.o cc -Wall -fPIC -O2 -DINTERACTIVE flac.c -c -o flac.o cc -Wall -fPIC -O2 -DINTERACTIVE pcm.c -c -o pcm.o cc -Wall -fPIC -O2 -DINTERACTIVE mad.c -c -o mad.o cc -Wall -fPIC -O2 -DINTERACTIVE vorbis.c -c -o vorbis.o cc -Wall -fPIC -O2 -DINTERACTIVE faad.c -c -o faad.o cc -Wall -fPIC -O2 -DINTERACTIVE mpg.c -c -o mpg.o cc -Wall -fPIC -O2 -DINTERACTIVE interactive.c -c -o interactive.o cc main.o slimproto.o buffer.o stream.o utils.o output.o output_alsa.o output_pa.o output_stdout.o output_pack.o decode.o flac.o pcm.o mad.o vorbis.o faad.o mpg.o interactive.o -lasound -lpthread -lm -lrt -ldl -lcurses -llirc_client -o squeezelite


Then make a backup of the original Squeezelite and copy the newly built one into place

Edit /etc/default/squeezelite to add a -L option
(in this special version of Squeezelite ... -L means use LCDproc)

Probably will find that the Squeezelite output is being alternated with information about the state of the Raspberry Pi.
This is useful when checking that things are working - but is a distraction when in normal use.
To disable this you can edit /etc/LCD.conf and change
#AutoRotate=off
to
AutoRotate=off

and
#ServerScreen=off
to
ServerScreen=off


Using infrared remote control:

To get the infrared remote control working:

sudo apt-get install lirc
Then get lirc working with your remote control ...

Edit /etc/modules to add:
# Load RPi lirc support for GPIO driven IR device
lirc_dev
lirc_rpi gpio_in_pin=22

e.g. using
sudo nano /etc/modules
Note - the number shown is GPIO22 which is pin 15 on the GPIO connector


Edit /etc/lirc/hardware.conf (for example by using nano) and make it look like this:

# /etc/lirc/hardware.conf
#
# Arguments which will be used when launching lircd
LIRCD_ARGS=""

#Don't start lircmd even if there seems to be a good config file
#START_LIRCMD=false

#Don't start irexec, even if a good config file seems to exist.
#START_IREXEC=false

#Try to load appropriate kernel modules
LOAD_MODULES=true

# Run "lircd --driver=help" for a list of supported drivers.
DRIVER="default"
# usually /dev/lirc0 is the correct setting for systems using udev
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"

# Default configuration files for your hardware if any
LIRCD_CONF=""
LIRCMD_CONF=""


create a new directory to hold the lirc configuration files

cd $HOME
mkdir rpitron
cd rpitron

Now create the configuration file for the remote control that you are going to use.
In my case I want to use the remote control that came with the Audiotron.
I have made some configuration files for that - which you should then download and copy to the default for lirc.

wget ... (info to be added in here)...

cp /etc/lirc/lircrc ./lircrc.backup
cp audiotron.lircrc /etc/lirc/lircrc

cp /etc/lirc/lircd.conf ./lircd.conf.backup
cp audiotron.lircd.conf /etc/lirc/lircd.conf


Then modify the startup parameters for the modified Squeezelite to include
-i -F /etc/lirc/lircrc
The "-i" means use Infrared via lirc - and the -F gives the location of the lirc remote control configuration file that maps the various key presses into Squeezelite commands.


In theory ... if you now reboot then things should work!
If they do not then you will have to go back through the steps one at a time to work out what went wrong.
Most likely if that cables were connected to the wrong pins. Hopefully that did not break anything!

You will probably find that the scroll rate on the display is too fast when long track names are being shown.

In LMS (via web browser to port 9000 on your LMS server) you can change the scroll rate - via
Settings/Player/Display - and change the scroll rate from 0.033 to 0.8 or some other value that suits.
It does not look good when scrolling through - so probably best to set the title format (in Settings/Player/Basic) to something that is less likely to need scrolling.


To be done:
Add some pictures to show the inside of the Audiotron and the mass of cables.
Clear up the various sections and provide breakpoints and test methods so that steps can be verified
Upload the Audiotron remote control configuration files
Add links
Add list of parts

Useful tools:
To check or set GPIO pins
WiringPi -

While working on this I submitted updates to the modified Squeezelite (to make the -F parameter work) and to LCDproc to add support for Raspberry Pi 2 B.



No comments: