WordPress notes

Change the depth of the top menu in the header php file:
‘primary’, ‘menu_class’ => ‘nav-menu’, ‘depth’ => ‘2’ ) ); ?>

Add submenus with the Advanced Sidebar Menu.

Quad seven segment display with shift register

I wanted to control a seven segment display but still have enough pins left to work my ultrasonic distance sensor.  The next step was to make my quad display work.   I carefully worked through what each pin did using a spreadsheet and found I could display any number I liked at any one time, but they would all show the same number.  Clearly the display needed to be refreshed in sequence somehow.  My eureka moment was realising that this is exactly how it works – you just switch them on and off, one after the other really really fast.  The eye can’t tell this is happening so you see it all as one display.  PENNY D….R….O….P….S.

I found Pial’s Blog about using a shift register to control a 4 segment display and after much fiddling got it to work once I realised that his display worked on common anode (having a voltage made it work) whereas mine was common cathode (no voltage makes things work).  I realised I had to make everything down where his was up and up where his was down.  I then got a beautiful negative display of the numbers (the segments I wanted off were on and visa versa) which confused me for a while.  I’d spotted a weird tilde ~ on the start of some variables and after a little research found that this made the binary numbers the “negative” (01000100 becoming 10111011).  I removed the ~ and bingo, I could control the numbers.  I found a minor bug in his digits too – his 5 made a 3 so I fixed that.

This code just prints random numbers at a fast flicker to prove I can change things on the fly.

/*
  Shift Register Example
 for 74HC595 shift register

 This sketch turns reads serial input and uses it to set the pins
 of a 74HC595 shift register.

 Hardware:
 * 74HC595 shift register attached to pins 2, 3, and 4 of the Arduino,
 as detailed below.
 * LEDs attached to each of the outputs of the shift register

 Created 22 May 2009
 Created 23 Mar 2010
 by Tom Igoe

 */

//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;

//http://www.pial.net/post/Arduino-controlling-a-4-digit-seven-segment-display.aspx
const int digitPins[4] = {2,3,4,5}; //pins to control the 4 common anode pins of the display
const byte digit[10] = //seven segment digit bits
{
  B00111111, //0
  B00000110, //1
  B01011011, //2
  B01001111, //3
  B01100110, //4
  B01101101, //5
  B01111101, //6
  B00000111, //7
  B01111111, //8
  B01101111  //9
};
int digitScan = 0; //to interate through the digits in the display
int digitBuffer[4] = {0}; // to?

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
 
  for(int i=0;i < 4 br="" gt="" i="" nbsp="">    pinMode(digitPins[i],OUTPUT);
  }
 

}

void loop() {
 
  //if (Serial.available() > 0) {
    // ASCII ‘0’ through ‘9’ characters are
    // represented by the values 48 through 57.
    // so if the user types a number from 0 through 9 in ASCII,
    // you can subtract 48 to get the actual value:
    //int bitsToSend = Serial.parseInt();
    //Serial.println(“Wrote: ” + String(bitsToSend));
   
    //drop the latch
    //digitalWrite(latchPin, LOW);
   
    // shift the bits out:
    //shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
 
      // turn on the output so the LEDs can light up:
    //digitalWrite(latchPin, HIGH);
  //}
  // wait for a bit
  //delayMicroseconds(400);
  delay(1000);
  refreshDisplay();
}

// Going to change the display
void refreshDisplay()
{
  // make all the display segments LOW
  for(byte k=0;k < 4 br=”” k=””>  {
    digitalWrite(digitPins[k], HIGH);
  }

  // the numbers I am outputting, need to link to sensor next
    digitBuffer[0] = random(0, 9);
    digitBuffer[1] = random(0, 9);
    digitBuffer[2] = random(0, 9);
    digitBuffer[3] = random(0, 9);
  // open the latch
  digitalWrite(latchPin, LOW); 
 
  // clear all the pins
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
 
  // close the latch pin
  digitalWrite(latchPin, HIGH);
 
  // wait for a bit
  delayMicroseconds(400);
 
  // makes the right digit high
  digitalWrite(digitPins[digitScan], LOW);

  // open the latch
  digitalWrite(latchPin, LOW); 
  if(digitScan==0) // 0 is the first character – I want 3.123m
  {
    // write the number with the dp
    shiftOut(dataPin, clockPin, MSBFIRST, (digit[digitBuffer[digitScan]] | B10000000)); //inserting the dot
  }
  else
  {
    // write the number
    shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan]]);
  }
  digitalWrite(latchPin, HIGH);
  digitScan++;
  if(digitScan>3) digitScan=0;
 
}


Next step is to link up to the distance sensor, but I now need to make a bug hotel with youngest.

Ardhuino Shift Register – 74HC595 notes

So, I am still playing with Arduino, and want to understand the shift register better.  Notes as I go.

  • I used this official page to get up and running.  I set it up and got the “Hello World” sketch running.  It was all very deja vu and I realised that I’d been through all this before without really getting to grips with it (running before I could walk).  My eureka moment was realising that you address the 8 pins all at once by a binary number up to 255.  Suddenly it all makes sense (255 = 11111111 in binary so turns all 8 inputs HIGH, 129 is 10000001 which turns the first and last inputs HIGH.
  • function bitWrite appears to replace the bit in a binary number, so bitWrite(0,4,1) would change the number 0 to the number 1000 by placing a 1 4 digits in to the binary number.  bitWrite(16,2,1) would change 1000 to 1010.  The first parameter is the variable you are changing.
  • function ShiftOut fires out the bits in order then toggles the clock pin to tell the register the data is there.

Dell Inspiron 1210 (Mini 12), dead hdd meets Ubuntu 12.04

So, my dad’s Dell Inspiron 1210 (Mini 12) finally died after years of service.  I had moved it from Ubuntu to Windows a few years ago, but now it was properly dead.  Dad’s friend had diagnosed a dead hard disk.  And after much work I decided I agreed, though the BIOS was behaving badly.  I used Clonezilla to boot to DOS and refresh the BIOS, and this helped, but in the end it was the disk.

I dismantled the laptop using Dell’s own instructions and found a disk I’d not seen before, a ZIF (zero input force) 1.8″ drive.  I’d never met ZIF before and had no clue how to release it.  Eldest daughter suggested pull it out, so I did, but I later found on youtube that there is indeed a clamp you release.

Anyway, I tried a large variety of methods to make a functioning machine.  I wanted it to boot of an SD card and bought a 16GB in town.  But booting from USB or making an image on the SD card was endlessly frustrating.

In the end, I sought out (with wife’s help) an old USB DVD.  This got me moving forward, and I finally got Mandriva installed, though the display looked awful.  Ubuntu 10.10 then worked, and I then thought I would go the whole hog and go for the latest version of Ubuntu LTS (Long Term Support).

Installing was interesting.  Booting from a USB gave me weird display issues, but booting from the DVD was fine.  I installed to the SD card but the install failed at “install bootloader”.  I figured all the files would be in place and I just needed to get a bootloader working.  Thanks to it being an SD card it was easy to whack it in my main laptop.  Much searching got grub installed , I just had to find where it was mounting (/media/:

sudo grub-install –root-directory=/media/ /dev/sdb

This got the sd card in the 1210 to boot to the grub prompt.  More searching found three commands to get it booting:

grub> linux (hd0,1)/vmlinuz root=/dev/sda1 
grub> initrd (hd0,1)/initrd.img 
grub> boot

Then I was in and it booted fine – all the files were there.  Sadly the display was a complete disaster, a known problem.

So ctrl+alt+f1 got me a command prompt to get grub working properly, which was as simple as:

sudo grub-install /dev/sda
sudo update-grub 

Then I needed to work on the display issues (it was booting to a blank screen or half a screen of garbled nonsense, depending on its mood.  Back to ctrl+alt+f1 (the dist-upgrade took a while)

sudo apt-get dist-upgrade   # this takes a while
sudo shutdown now -r        # this reboots

The last stage was to follow the Ubuntu wiki for the problematic Intel gma 500 graphics card.

sudo service lightdm restart

I was just following the wiki by now:

Ubuntu 12.04

With the default settings, Ubuntu 12.04 boots to either a black screen or or top half screen.
There are several potential solutions: console=tty1, disable splash, or 915 Resolution

Option 1 – console=tty1

Perhaps the easiest method is to use “console=tty1” as a boot option.
  • gksudo gedit /etc/default/grub

Find the following line: GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”
Add console=tty1 in between the quotes, the end result looking as follows
  • GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash console=tty1″
save and exit, then update grub with

sudo update-grub

 And now it works perfectly and seems very smooth.

Raspberry Pi as squeezebox server (logitech media server) with Spotify

Please note that this is now obsolete – see

https://thomas.w-p.me.uk/blog/2013/10/adding-squeezelite-to-squeezboxserver-on-rpi/

For a better way.  The below is left for reference.

========================================================

I tried this once, but fell down when I got to the spotify bit because I had the wrong version of debian.   This post is just personal notes of how I progressed the second time.

  1. Downloaded and sent the armel version of Raspbian Wheez (torrent) to the SD CARD for my Raspberry Pi.
  2. It didn’t boot.  I did some research and found that I probably needed to change the start.elf file in /boot for the version in the non armel version.  I used this post to mount the img file I had used the time I got stuck and pulled the start.elf out of it.
  3. It then booted.  I left it running and did the rest using teraterm.  ALT+V to paste and TeraTerm copes nicely with multiple lines of commands.
  4. Followed this guide for installing, which was simply these commands in order, some (particularly the dist-upgrade in step 1) take a long time.  Thank you very much mystery poster (you may not need the commands in red, see later*):
  • sudo apt-get update && sudo apt-get dist-upgrade 
  • sudo apt-get install libjpeg8 libpng12-0 libgif4 libexif12 libswscale2 libavcodec53 
  • wget http://downloads.slimdevices.com/LogitechMediaServer_v7.7.2/logitechmediaserver_7.7.2_all.deb
  • sudo dpkg -i logitechmediaserver_7.7.2_all.deb  
  • sudo service logitechmediaserver stop
  • wget http://allthingspi.webspace.virginmedia.com/files/lms-rpi-raspbian.tar.gz
  • tar -zxvf lms-rpi-raspbian.tar.gz 
  • sudo mv arm-linux-gnueabihf-thread-multi-64int /usr/share/squeezeboxserver/CPAN/arch/5.14/ 
  • sudo mv libmediascan.so.0.0.0 libfaad.so.2.0.0 /usr/local/lib 
  • sudo mv /usr/share/squeezeboxserver/Bin/arm-linux/faad /usr/share/squeezeboxserver/Bin/arm-linux/faad.old 
  • sudo mv faad /usr/share/squeezeboxserver/Bin/arm-linux 
  • sudo ln -s /usr/local/lib/libmediascan.so.0.0.0 /usr/local/lib/libmediascan.so 
  • sudo ln -s /usr/local/lib/libmediascan.so.0.0.0 /usr/local/lib/libmediascan.so.0 
  • sudo ln -s /usr/local/lib/libfaad.so.2.0.0 /usr/local/lib/libfaad.so
  • sudo ln -s /usr/local/lib/libfaad.so.2.0.0 /usr/local/lib/libfaad.so.2
  • sudo ldconfig
  • The logitech media server was now up and running, but with no music.  I had to mount my music from a windows machine next.
  • sudo mkdir /mnt/music
  • sudo nano /etc/fstab
  • I then added the following to my /etc/fstab with my server IP.
  •  //192.168.0.6/music     /mnt/music      cifs    username=user,password=xxxxxx,workgroup=HOME,users,auto,user_xattr 0 0
  • (then CTRL-X followed by Y to save the file) 
  • It didn’t work.  It turns out that the windows server needed some registry tweaks and a reboot.
    • In HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management, set the LargeSystemCache key to 1 (hex).
    • In HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters, set the Size key to 3 (hex).’
  • It was all working now, I set up Logitech Media Server, it scanned the folder on the network and now music plays on my squeezebox.
  • I logged in to the settings and disabled nearly all the services since I hardly use any.  I left Extension Downloader and added the third party add on for Spotify in addition to the official spotify one (I also have a Squeezebox Radio). The 3rd party plugin took ages to appear.
  • Next I wanted to get the spotify to work.  This was where I had come to a halt last time, but it was as easy as installing the 3rd Party plugin and entering my username and password for spotify premium.  Easy.
  • Now I wanted to have my cake and eat it, and install the Pi as the squeezebox player too.  The All Things Pi blog has instructions for that too, but there are some small errors and one step I didn’t need to do.  I didn’t need
  • apt-get install alsa-base 
  • because the alsa-base was already installed.
  • All  the remaining commands worked fine but only if I prefaced them with “sudo”. But the player did not appear right away.  It turned out that I needed an armel version.  I used it to replace the one in /usr/local/sbin/ and it came up right away.
  • *The BBC iPlayer did not initally work.  With a nudge from “bpa” I tried replacing the new faad file with the faad.old, and BBC iPlayer worked right away.  I wonder how many of the steps I could take out.