Monthly Archives: February 2018

PIC 16F62X programming tools

I have used the PIC 16F628 chip in a variety of projects. It is a small self-contained micro-controller that only requires a 3.5V supply to operate. It has it’s own internal clock circuitry. The PIC is an 18 pin package with several IO pins that can be programmed as input or output. It also has an internal serial UART and internal non-volatile memory.

I use the MikroElectronika PASCAL (https://www.mikroe.com) compiler to develop software. This is free for hobbyists and there are also C compilers available.

I use an adaption of the Windows PC serial port to program it. The following circuit is what I use. A photo is also shown of my programmer. This is an inexpensive lash-up on a piece of vero board. This is connected using a standard comms cable to the PC comms port and the PIC is inserted into the 18 pin socket for programming.

 

The compile tools create an image in Intel Hex format. I have written a Windows PC programmer tool that loads the Hex file and programs the PIC. The software is free to use, just drop me a line if you want a copy.

 

 

Music players for the Pi Zero W

I have been investigating music players for the Pi Zero. I wanted to be able to control them using a mobile phone or tablet. I intended to put a couple around the house and re-cycle some old sound systems and computer speakers. The player also needs to connect to my fileserver that has my entire CD library on it.

I looked at “pi musicbox” first of all, it seemed to satisfy my requirements, but when I tested it I found some problems. These are my findings:-

  1. The image can be downloaded direct from their website. It has a small footprint and it works straight away.
  2. The configuration file is visible on a partition for windows users, so the wifi details can be plugged in before booting up while the sd card is still connected to a PC. This works great.
  3. Once the system was booted up, I could connect to the web server and control it from a PC and mobile. Additional configuration can be done from here. I tried to set up a link to my file server, but it didn’t work. I had to enable SSH and connect to the command terminal and hack the configuration file at /opt/musicbox/startup.sh. The line to mount a network server had to be changed to: mount -t cifs -o user=pi,password=pi //FILESERVER/pi-music /music/Network
  4. The system scans all the network files by default on boot up. This takes a lot of time and I am not sure why it is necessary.
  5. The web user interface was very slow to operate and got stuck a few times.
  6. There was an annoying spinning disk when waiting that didn’t go away on some browsers.

So I was not very impressed…….

I have not yet tried “Volumnio”.

The next product I tried was VLC which I have used on my PC for audio and video and it is quite robust and useful. It happens to have its on internal web server that can be switched on so I installed it on a headless pi with a GUI. (VLC can run without a GUI, but it is easier to configure with a GUI).

The setup to be done is as follows:

  1. Run VLC and go to the control page TOOLS / / PREFERENCES / / INTERFACE from the main menu bar. Click to check the box “All”, then select “main interfaces” from the left hand list and click to check the box “Web”.
  2. Select lua on the expanded “main interfaces” option and add a password for http access.
  3. Add the following file (with sudo) /usr/share/vlc/lua/http/.hosts and add entries to allow access to the web server. e.g. ::1 192.168.1.123 or just use 1:0 0.0.0.0 for everybody.
  4. I also added an entry to start the invisible VLC (called CVLC) on boot by adding @cvlc to the file /home/pi/.config/lxsession/LXDE-pi/autostart
  5. Once the server has started it can be accessed from any web browser. Note that it is on port 8080. (use http://my pi IP address whatever:8080 on the URL line of the browser)
  6. Mount the fileserver music library in the /home/pi folder as this is where browsing starts from. i.e.
 mkdir /home/pi/MusicLibrary 

 add a mount command to /etc/fstab

 //FILESERVER/pi-music /home/pi/MusicLibrary cifs user=pi,password=pi,uid=pi,gid=pi,x-systemd.automount 0 0

I found that the response was snappy and it worked well.  There is a separate interface for mobiles and tablets with less functionality. VLC is quite useful in that playlists can be setup and access to other music streams can be setup.

I am currently using a USB to Audio widgit that plugs into the pi USB port. You can see this in the photo above. This cost less than a pound and took three weeks to arrive all the way from China. The pi recognises it without any fuss.

I decided that the mobile interface needed a function to select and play all files listed on the browse window, i.e. play a full CD rather than play a single file. I was able to hack the http server files and add some jquery/javascript to achieve this. The server html files are located at /usr/share/vlc/lua/http.

I hacked the file “mobile_browse.html” to add an extra button to play all the files. A copy is attached here :

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
< mobile_browse.html: VLC media player web interface - VLM
< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
< Copyright (C) 2005-2014 VLC authors and VideoLAN
< $Id$
<
< Authors: Brandon Brooks <bwbrooks -at- archmageinc -dot- com>
<
< This program is free software; you can redistribute it and/or modify
< it under the terms of the GNU General Public License as published by
< the Free Software Foundation; either version 2 of the License, or
< (at your option) any later version.
<
< This program is distributed in the hope that it will be useful,
< but WITHOUT ANY WARRANTY; without even the implied warranty of
< MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
< GNU General Public License for more details.
<
< You should have received a copy of the GNU General Public License
< along with this program; if not, write to the Free Software
< Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<html>
 <head>
 <title><?vlc gettext("VLC media player - Web Interface") ?></title>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <meta name="viewport" content="width=device-width" />
 <link href="favicon.ico" type="image/x-icon" rel="shortcut icon" />
 <script type="text/javascript" src="js/common.js"></script>
 <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.13.custom.css" rel="stylesheet" />
 <link type="text/css" href="css/main.css" rel="stylesheet" />
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>
 <script type="text/javascript" src="js/jquery.jstree.js"></script>
 <script type="text/javascript" src="js/controllers.js"></script>
 <script type="text/javascript">
 var pollStatus = false;
 var browse_target = '#mobile';
 $(function(){
 browse(); 
 
 })

function clearit()
 {
 sendCommand({'command':'pl_empty'})
 updatePlayList(true);
 }

function queueit ()
 {
 clearit();
 var $children = $('#browse_elements').children('li');
 var first=true;
 var play=false;

$children.each(function()
 { 
 var path = this.getAttribute('opendir') ? this.getAttribute('opendir') : this.getAttribute('openfile');

if (!first) {
 sendCommand('command=in_enqueue&input='+encodeURI(path));
 if (!play) {
 sendCommand('command=in_play&input='+encodeURI(path));
 }
 play = true;
 }
 first=false; 
 });
 
 setTimeout(function(){updatePlayList(true);window.location = "mobile.html";},2000);
 
 }
 </script>

<style>
 .buttonx {
 background-color: #FF0000; 
 border-style: solid;
 border-width: 4px;
 border-color: black;
 color: white;
 padding: 15px 32px;
 text-align: center;
 text-decoration: none;
 display: inline-block;
 font-size: 24px;
 }
 </style>
 </head>
 <body>
 <div id="window_browse" title="<?vlc gettext("Media Browser") ?>">
 <div>
 <ol id='browse_elements' selectable="selectable">
 <li><?vlc gettext("Play List") ?></li>
 </ol>
 </div>
 </div>
 <br/>
 
 <button id="qbutt" type="button" value="Q" class=buttonx onclick="queueit();">Play</button>


</body>
</html>

Don’t ever trust a washing machine engineer

I usually do all the handyman maintenance on my wife’s house rental. She has an estate agent that handles the rental and contacts me first if there are any problems. Sod’s law ensures that the tenants washing machine goes wrong when we are on holiday, so the agent called his engineer to look at it and emailed us with the update.

“Well guv, the controller pcb is broken, you might as well get a new machine and i’ll guarantee it for 10 years.” He managed to convince my wife to get a new machine.

When I got back, I went to sort out the mess as the “engineer” plumbed it into where the dishwasher was and left the dishwasher in the middle of the kitchen. So I thought to myself, this “engineer” is too damn lazy to move the washing machine because the cooker was in the way and that needed to be moved first. Then I thought if he hasn’t moved the machine, how can he really had a look at the insides.

Of course he hadn’t. He used the oldest excuse for washing machine engineers as he is lazy and incompetent.

I took the machine away and plugged in the services. Switched it on. Mnnn all the lights come on and the pump is working, it even lets water in; that is not a broken pcb to me. Of course I knew what was wrong… 99% of breakdowns are due to worn out brushes on the main motor. I tried a spin cycle and I could hear some arcing from the motor and it was turning erratically.

So, I put it on it’s side and removed the old brushes from the motor without even having to remove a cover. The brushes are in a plastic assembly and held by two screws, very simple to remove.

Sure enough the brushes were worn. I identified the part and ordered it on-line £10 for the pair.

The next photo shows the old (black) and the new(red).

 

The assembly is located with two lugs that locate with two holes on the motor. The replacements were fixed in position with the two screws and re-connected using the push on connectors.

Job’s a goodun !!

And that’s it, the machine is working again, ready for action when the 10 year guarantee runs out. Now, mr useless, lazy, incompetent Washing Machine Engineer, is there anything else you want to know about fixing washing machines ????

 

Cheap and cheerful Windows file server

This is my cheap and cheerful Windows file server on my home wifi network. It has a 1TByte hard drive accessible to my windows PC and any other device on my home network. It also has a Subversion server running that I can use Tortoise SVN on my PC.

The picture shows a Raspberry Pi Zero W strapped to a USB removable hard drive. The drive is connected by USB to the Pi Zero and the whole thing is powered by a USB cable plugged into the Wifi router. It is permanently available. It is very easy to set up.

I initially set up the raspberry pi to run headless so I can use VNC on my windows PC to control it using the pi graphical user interface. I have stored this basic image as a .img file on my PC so that I can burn the image to a micro SD card when needed.

On the raspberry pi command window :

sudo apt-get install samba samba-common-bin

sudo leafpad /etc/samba/smb.conf

(or use sudo nano)

Edit the smb.conf :-

set

workgroup =

wins support = yes

Add the following entries for each file source folder required:

[pi-hard-disk]

comment=


path = /media/hdisk


browseable = Yes


writeable = Yes


onlyguest = no


create mask = 0777


directory mask = 0777


public = no

I setup three entries :-

One for the local pi folder /home/pi (pi)

One folder for the entire external drive /media/hdisk (pi-hard-disk)

One readonly folder for my CD library /media/hdisk/MUSIC (pi-music)

Set the samba pass word for user pi (user “pi” password “pi”)

I am keeping it simple with no special access/authentication considerations.

sudo smbpasswd -a pi


>> enter pi as password

Next automatically mount the external usb drive on boot up. My external drive is formatted as windows NTFS older models are FAT32. Ensure the pi can handle ntfs.

sudo apt-get install ntfs-3g

Add an entry to the fstab table to mount the drive on boot up. The mount point is the folder:

/media/hdisk. You can use any folder, but it must agree with the path specified previously.

mkdir /media/hdisk

sudo leafpad /etc/fstab

Add this entry to the fstab config file :

/dev/sda1 /media/hdisk ntfs-3g vmask=000 0 0

To avoid using IP network addresses (eg 192.168.1.123), ensure the pi has a suitable network name. The wifi router should be able to resolve the name to the actual IP address used. I am using the name FILESERVER for my pi computer. This can be set using raspbian config program. There is an option to change the name under the network menu.

sudo raspi-config

Reboot the pi and everything should work !!

 

On the windows PC go to file explorer and type the following into the top URL bar:

\\FILESERVER

Windows will ask for a user and password to connect. Enter user pi and password pi as setup previously.

You will then see the file shares to the file server:

 

On other raspberry Pi s on the network :-

You need to set up a samba client to connect to the samba server on the file server….

at the command window:

sudo apt-get install samba-common smbclient samba-common-bin cifs-utils

Ensure a mount point is created. This can be anywhere:

mkdir /media/fileserver

Update the fstab table to auto connect to the fileserver on boot.

sudo leafpad /etc/fstab

Add the entry

//FILESERVER/pi-hard-disk   /media/fileserver   cifs   user pi,password pi,uid=pi,gid=pi,x-systemd.automount 0 0

Reboot the pi and access to the file server can be made from /media/fileserver.

 

On other android tablets or phones on the network :-

Find a samba client app on the play store. e.g. AndSMB.

Enter the server name e.g. FILESERVER and the user and password e.g. pi/pi