Monday 23 December 2013

A note about random()

I have seen quite a few people struggling with the Arduino random() function. The problem lies in creating a simple random '1' or '0'. It is tempting to write
random(0,1);
But this doesn't work as it returns '0' every time. What random() does is to generate a random number from START to FINISH - 1.
random(START, FINISH);
So to get a random '0' and '1' returned you have to do this:

#define START 0
#define FINISH 1

random(START, FINISH + 1);
so it outputs from START '0' to FINISH '1'

Saturday 21 December 2013

Send Morse code over Bluetooth

Here's the code to send morse over Bluetooth

// morse sender - flash LED on 7
/*
connections
Arduino       BT
5V            PIN 2 (VCC)
GND           PIN 3 (GND)
10 (RXPIN)    PIN 4 (TXD) - data transmitted from remote
11 (TXPIN)    PIN 5 (RXD) - remote to receive this data
*/

#include "avr/pgmspace.h"
#include "MorseEnDecoder.h"
#include "SoftwareSerial.h"

#define WPM 5

#define LEDPIN 7
#define RXPIN 10
#define TXPIN 11

morseEncoder morseOut(LEDPIN);

SoftwareSerial GanymedeBT(RXPIN, TXPIN); // GanymedeBT class object in Arduino

long lastTrans;
long current;
boolean ended = true;

void setup() {
  
  pinMode(LEDPIN, OUTPUT);
  
  GanymedeBT.begin(9600);
  
  morseOut.setspeed(WPM);
  
  lastTrans = millis();
}

void loop() {
  
  current = millis();
  
  morseOut.encode();
  
  if(GanymedeBT.available() && morseOut.available()) {
    char text = GanymedeBT.read();
    GanymedeBT.write(text); // echo
    if(text == '\r') GanymedeBT.write('\n'); // when CR received addcq cq cq m6kwh NL
    morseOut.write(text);
  }
  
  if(!morseOut.available()) {
    lastTrans = current;
    ended = false;
  }
}



To use this pair the module, then use the terminal"screen device" command to talk to it, or use the CoolTerm program.

Resetting the Bluetooth module with AT commands

BT modules ceom with strange names and PIN codes. To pair with a Mac give your BT module a sensible name and the PIN 0000.

Like this

BT module configuration

Do not pair before this sketch, in order to send AT commands BT red LED must be flashing.

Set name to whatever_you_want, PIN to 0000, baud rate to 9600 using AT commands below:

/* BT module configure
BT flashing
send AT+NAMEWhatever_you_want
send AT+PIN0000
send AT+BAUD4
connections
Arduino       BT
5V            PIN 2 (VCC)
GND           PIN 3 (GND)
10            PIN 4 (TXD)
11            PIN 5 (RXD)
*/

#include "SoftwareSerial.h"

#define RXPIN 10 
#define TXPIN 11

SoftwareSerial BT(RXPIN, TXPIN); // create class BT

void setup()  
{
  Serial.begin(9600); // start USB
  BT.begin(9600); // start BT
}

void loop()
{
  if (BT.available())
  {
    Serial.write(BT.read()); // echo from BT
  }
 
  if (Serial.available())
  {
    BT.write(Serial.read()); // write AT command to BT
  }
}

Getting Started with Arduino

Made these note for my grandson...

Starting with Arduino
Blink a light (LED)

Start the IDE software, click on its icon in the dock

Programming

1 Programs have two parts called 

void setup()
{
  put what we want to do here
}

and

void loop()
{
  put what we want to repeat here
}

2 setup() and loop() are functions. 

Functions are like this

return_this function(input_this)
{
... do something
return this;
}

 what they do is in the { ... } brackets. They don’t return anything back so they are void.

3 the Pins have to be told what they are, mode = INPUT or OUTPUT. 

pinMode(pin, mode);

End each line with ‘;’

4 Give a name to the PIN number and a waiting TIME between flashes

#define NAME VALUE,  for example like this

#define LEDPIN 7
5 Code now looks like this

// pin number 7 and delay time of 1sec = 1000msec
#define LEDPIN 7
#define TIME 1000

// setup pin 7 as an output
void setup() 
{                
  pinMode(LEDPIN, OUTPUT);     
}

any line starting “//“ is just a comment, not part of your program code

5 Now for the loop(), which gets repeated

This is what we have to do

- turn the LED on
- wait for 1 sec
- turn the LED off
- wait for 1 sec
... repeat...

To turn the LED on and off, we have to OUTPUT a HIIGH or LOW signal on the pin.

digitalWrite(pin, value);

and we have to create a delay

delay(1000); 

1000 is in milliseconds, 1000 msec = 1 sec.

6 The code now looks like this

// pin number 7 and delay time of 1sec = 1000msec
#define LEDPIN 7
#define TIME 1000

// setup pin 7 as an output
void setup() 
{                
  pinMode(LEDPIN, OUTPUT);     
}

// repeat the following code to flash the light
void loop() 
{
  digitalWrite(LEDPIN, HIGH);
  delay(TIME);
  digitalWrite(LEDPIN, LOW);
  delay(TIME);
}

7 Type all this in.

Then press the “tick” button to check it is right. If so press the “arrow” button to send your program to the Arduino. 

The LED will start to flash!

Wednesday 18 December 2013

A binary clock

I know clocks are cheap, you can get a watch these days for less than £1! But how about a binary clock?

This one tells the time in four columns, from right to left:

- minutes (yellow LEDs) 1 2 4 8

- minutes (green LEDs) 10 20 40

- hours (red LEDs) 1 2 4 8

- hours (blue LEDs) 10 20

Just add up the binary digits to get the time. the display is like this:

2013 12 18 13 35 27

The time shown above is

10 +3 hours, 30 + 3 minutes or 13:33

The program for this is:

// binary clock

#define LED1M 2
#define LED2M 3
#define LED4M 4
#define LED8M 5

#define LED10M 6
#define LED20M 7
#define LED40M 8

#define LED1H 9
#define LED2H 10
#define LED4H 11
#define LED8H 12

#define LED10H A0
#define LED20H A1

#define MBUTTON A4
#define HBUTTON A5

static unsigned long tick;
int sec = 0;
int minu = 0;
int hr = 0;
int munit;
int hunit;
   
void setup()
{  
  pinMode(LED1M, OUTPUT);
  pinMode(LED2M, OUTPUT);
  pinMode(LED4M, OUTPUT);
  pinMode(LED8M, OUTPUT);
  
  pinMode(LED10M, OUTPUT);
  pinMode(LED20M, OUTPUT);
  pinMode(LED40M, OUTPUT);
                
  pinMode(LED1H, OUTPUT);
  pinMode(LED2H, OUTPUT);
  pinMode(LED4H, OUTPUT);
  pinMode(LED8H, OUTPUT);
  
  pinMode(LED10H, OUTPUT);
  pinMode(LED20H, OUTPUT);
  
  pinMode(MBUTTON, INPUT_PULLUP); // set minutes button
  pinMode(HBUTTON, INPUT_PULLUP); // set hours button
  
  tick = millis(); // start clock
  
}

void loop()
{
   
   if(millis() - tick >= 1000) // basic timing
   {
     tick = millis();
     sec++; // count seconds

   }
   
   if(sec >= 60)
   {
     minu++; // count minus
     sec = 0;

   }
   
   if(minu >= 60)
   {
     hr++; // count hrs
     minu = 0;
   }
   
   if(hr >= 24)
   {
     hr = 0; // reset hrs
     minu = 0; // and min
   }
   
   munit = minu%10; // get min units
   hunit = hr%10; // get hr units

   // convert 1st column to binary
   if(munit == 1 || munit == 3 || munit == 5 || munit == 7 || munit == 9) 
   {  
     digitalWrite(LED1M, HIGH);
   }
   else 
   {
     digitalWrite(LED1M,LOW);
   }
   if(munit == 2 || munit == 3 || munit == 6 || munit == 7) 
   {
     digitalWrite(LED2M, HIGH);
   }
   else 
   {
     digitalWrite(LED2M,LOW);
   }
   if(munit == 4 || munit == 5 || munit == 6 || munit == 7) 
   {
     digitalWrite(LED4M, HIGH);
   }
   else 
   {
     digitalWrite(LED4M,LOW);
   }
   if(munit == 8 || munit == 9)
   {
     digitalWrite(LED8M, HIGH);
   }
   else 
   {
     digitalWrite(LED8M,LOW);
   }
   
   // convert 2nd column to binary
   if((minu >= 10 && minu < 20) || (minu >= 30 && minu < 40) || (minu >= 50 && minu < 60))  
   {
     digitalWrite(LED10M, HIGH);
   } 
   else 
   {
     digitalWrite(LED10M,LOW);
   }
   if(minu >= 20 && minu < 40)  
   {
     digitalWrite(LED20M, HIGH);
   }
   else 
   {
     digitalWrite(LED20M,LOW);
   }
   if(minu >= 40 && minu < 60) 
   {
     digitalWrite(LED40M, HIGH);
   }
   else 
   {
     digitalWrite(LED40M,LOW);
   }

   // convert 3rd column to binary
   if(hunit == 1 || hunit == 3 || hunit == 5 || hunit == 7 || hunit == 9) 
   {
     digitalWrite(LED1H, HIGH);} 
   else 
   {
     digitalWrite(LED1H,LOW);
   }
   if(hunit == 2 || hunit == 3 || hunit == 6 || hunit == 7) 
   { 
     digitalWrite(LED2H, HIGH);
   } 
   else 
   {
     digitalWrite(LED2H,LOW);
   }
   if(hunit == 4 || hunit == 5 || hunit == 6 || hunit == 7) 
   {digitalWrite(LED4H, HIGH);
   } 
   else
   {
     digitalWrite(LED4H,LOW);
   }
   if(hunit == 8 || hunit == 9) 
   {
     digitalWrite(LED8H, HIGH);
   }
   else 
   {
     digitalWrite(LED8H,LOW);
   }

   // convert 4th column to binary
   if(hr >= 10 && hr < 20) 
   {
     digitalWrite(LED10H, HIGH);
   } 
   else 
   {
     digitalWrite(LED10H, LOW);
   }
   if(hr >= 20 && hr < 24)  
   {
     digitalWrite(LED20H, HIGH);
   } 
   else
   {
     digitalWrite(LED20H,LOW);
   }
   
   if(digitalRead(MBUTTON) == LOW)
   {
     minu++;
     sec = 0;
     delay(250); // allow for contact bounce?
   }
   
   if(digitalRead(HBUTTON) == LOW)
   {
     hr++;
     sec = 0;
     delay(250);
   }
}
   

Thursday 12 December 2013

LCD Temperature & Humidity

Next step, display the Temperature and Humidity on an LCD display. Like this:

2013 12 12 15 23 18

The circuit for this is:

2013 12 12 15 21 15

And the board layout is:

2013 12 12 15 23 04

The code has no error checking at this time::

#include "dht11.h"
#include "LiquidCrystal.h"



// LCD connections
#define RS 0
#define EN 1
#define D4 5
#define D5 4
#define D6 3
#define D7 2

// LCD mode
#define cols 16
#define rows 2

dht11 DHT11;
// sensor pin
#define DHT11PIN 12

LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);

void setup()
{
  lcd.begin(cols, rows);
  delay(2000);
}

void loop()
{
  DHT11.read(DHT11PIN); // make a read to refresh the temp & humid
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Humid (%) ");
  lcd.print((float)DHT11.humidity, 2); // humid 2 dec places


  
  lcd.setCursor(0, 1);
  lcd.print("Temp (C) ");
  lcd.print((float)DHT11.temperature, 2); // temp 2 dec places
   
  delay(2000);
}

Temperature & Humidity

Now here's a very neat device. A small unit that measures Temperature (degC) and Humidity (%) directly.

2013 12 12 13 07 36
Communication with the device is tricky, but there is an Arduino Library "dht11.h" which make the whole thing very simple. See Here. You have to copy the ".h" and ".cpp" files one by one to a text editor and save them. Then put them in your Arduino library folder in a sub folder called "dht11"

The connections are (S = Signal, Centre Pin = +5V, - = GND):

2013 12 12 13 09 50
The pull up resistor is essential, otherwise you get wrong readings...

Here's my test bed:

2013 12 12 13 08 12

And the display on the Serial Monoitor of the Arduino IDE:

Screen Shot 2013 12 12 at 13 05 34 The code

#include "dht11.h"

dht11 DHT11;

#define DHT11PIN 2

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  delay(2000);
}

void loop()
{
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK: 
		Serial.println("OK"); 
		break;
    case DHTLIB_ERROR_CHECKSUM: 
		Serial.println("Checksum error"); 
		break;
    case DHTLIB_ERROR_TIMEOUT: 
		Serial.println("Time out error"); 
		break;
    default: 
		Serial.println("Unknown error"); 
		break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (C): ");
  Serial.println((float)DHT11.temperature, 2);

  delay(2000);
}

Thursday 28 November 2013

Bluetooth communications for the Arduino

I have never seen such confusing garbage on various web sites as when I searched for Bluetooth use on the Arduino.

I found there are two modules common on the market, the HC-05 and HC-06. There is also a JY-MCU with two versions for "slave" only or "master - slave" applications.

The JY-MCU provides only a "slave" connection if you buy the one that uses the HC-06 module. This is the one described here.

These are the connections for a simple system:

Screen Shot 2013 11 28 at 16 45 54

Take care the Bluetooth BTX goes to the Arduino ARX (0) and BRX to ATX (1).

The Bluetooth name of this module is set by some AT commands you give. The password or PIN for pairing is changed to 0000. The default baud rate is 9600bps.

Two ways to program

If the module is simply connected as above to the Arduino serial RX & TX pins (0 and 1), which are also used by the USB connection, then the Serial.h library can be used. Like this:

#include "Serial.h"

#define LEDPIN 8

void setup() {

  pinMode(LEDPIN, OUTPUT);
  
  Serial.begin(9600); // start serial comms on default pins 0 & 1
}

void loop() {

  char v;

  if(Serial.available() > 0) // if data in the serial buffer, read it
    v = Serial.read();

  if(v == ‘H’) {
    digitalWrite(LEDPIN, HIGH); // turn LED on
  {
  else if(v == ‘L’) {
    digitalWrite(LEDPIN, LOW); // turn LED off
  }

  delay(100);
}


These steps must be followed as the USB must be inactive when the BT is connected as they use the same signals on pins 0 & 1.

1 Connect USB to power BT module, only +5 and GND connected

2 Pair MAC to BT module

3 Run this simple sketch to find the BT device port

void setup() {

    Serial.begin);
    println(Serial.list());
  }


4 Load the BT sketch above via USB and then go to IDE > Tool > Serial Port and click on the device for the BT module

5 Disconnect USB, wire up the BT module RX and TX signals, connect battery supply

6 Reset Arduino to run the BT sketch above

7 Open IDE Serial Monitor which should now be talking to the BT

8 Enter H or L to control LED via Bluetooth

To stop using BT remove the connections to pin 0 RX and pin 1 TX and chose the IDE Serial Port device for USB.

Arduino SoftwareSerial library

The second way is by using the SoftwareSerial.h library, using any other pins, but not RX 0 & TX 1.

You find the BT device port as in 3 above to be able to connect in the IDE.

#include "SoftwareSerial.h"

// BT TX to pin 10 ARX, RX to pin 11 ATX
#define ARX 10
#define ATX 11

SoftwareSerial myBT(ARX, ATX); // create BT object

// can use both USB and BT ports
void setup() {

  Serial.begin(9600); // open comms via USB device port, chose in IDE
  myBT.begin(9600); // open comms via BT device port, chose in IDE 

}

void loop() {

  if(myBT.available()) {

   // do something, e.g. char x = myBT.read();
  }


  if(Serial.available()) {
    // do something e.g. char x = Serial.read();
  }
}


Nothing here has yet been tested as I have not yet received my BT module, but when it arrives I will try it out and update this post.

Monday 25 November 2013

Send morse messages from KB

There is an Arduino library called MorseEnDecoder.h which can be used for encoding characters and send them as morse code at a fixed WPM. It can also be used for decoding received morse (but at a fixed WPM...).

The output of the program is a TTL signal an Arduino pin. This must be used to drive an external oscillator if audio is required, it can drive a relay directly to key a transmitter if no local audio is required - or it could do both!

The oscillator circuit uses a TTL 74LS00:

2013 11 25 17 56 33

Here's the code:

// sends TTL signal on OSCPIN to a TTL external osillator
// input from Serial Monitor, "string_to_send CR"

#include "avr/pgmspace.h"
#include "MorseEnDecoder.h"

#define WPM 5

#define OSCPIN 7

// morseOut class
morseEncoder morseOut(OSCPIN);

// timing
long lastTrans;
long current;
boolean ended = true;

void setup() {
  
  pinMode(OSCPIN, OUTPUT);
  
  Serial.begin(9600);
  
  morseOut.setspeed(WPM);
  
  lastTrans = millis();
}

void loop() {
  
  current = millis();
  
  morseOut.encode(); // must call once per loop
  
  if(Serial.available() && morseOut.available()) {
    char letter = Serial.read(); // read the next letter
    morseOut.write(letter); // send the letter
  }
  
  if(!morseOut.available()) {
    lastTrans = current;
    ended = false;
  }
}

Send morse code with an Arduino

Here is a very simple morse code sender, with at the moment hard wired text words to send. I hope to develop this to accept keyboard input and send it...

The circuit is very simple, a Piezo transducer is connected to pin 2, a LED to pin 7 and a push button to pin 8. Pushing the button sends the text "CQ CD DE M6KWH".

2013 11 25 15 25 31

// Morse sender

// pins
#define PIEZOPIN 2
#define BUTTONPIN 8
#define LEDPIN 7

// text array codes
#define DOT 0
#define DASH 1
#define SPACE 2
#define WORD 3

// text words
int CQ[] = {1,0,1,0,2,1,1,0,1,3};
int DE[] = {1,0,0,2,0,3};
int M6KWH[] = {1,1,2,0,1,1,1,1,2,1,0,1,2,1,1,0,2,0,0,0,0,3};

// sound frequency 1000Hz
// cycle time = 1000000/frequency(Hz) usec
#define CYCLE 1000

// dash = 3 dots, space = 3 dots, word = 7 dots
#define DOTTIME 150

void setup() {

  pinMode(BUTTONPIN, INPUT);
  pinMode(PIEZOPIN, OUTPUT);
  pinMode(LEDPIN, OUTPUT);
}

void loop() {

// wait for button pressed 
  while(digitalRead(BUTTONPIN) != LOW);

// send message words
  sender(CQ);
  sender(CQ);
  sender(DE);
  sender(M6KWH);

// finger still on button?
  while(digitalRead(BUTTONPIN) != HIGH);
  delay(100); // avoid button bounce
}

// send a word
void sender(int dida[]) {

  int x = 0; // array index

// send characters up to end of word
  while(dida[x] != WORD) {
   switch (dida[x]) {
    case DOT:
       sound(DOTTIME);
       delay(DOTTIME); // add after dot
       break;
    case DASH:
        sound(3 * DOTTIME);
        delay(DOTTIME); // add after dash
        break;
    case SPACE:
         delay(2 * DOTTIME);  // add for space
         break;
    }
    x++;
  }
  delay(6 * DOTTIME); // add   for word
}

// make sound at FREQ for time (msec)
void sound(long time) {

  long start;

// make the sound for time msec
  start = millis(); // read current time
  digitalWrite(LEDPIN, HIGH); // turn on LED

// loop until time has passed making sound
  while(millis() < start + time) {
    digitalWrite(PIEZOPIN, HIGH);
    delayMicroseconds(CYCLE/2);
    digitalWrite(PIEZOPIN, LOW);
    delayMicroseconds(CYCLE/2);
  }
  digitalWrite(LEDPIN, LOW); // turn off LED
}

Monday 18 November 2013

Update on One Wheel Robot

I have made soms updates to both the hardware and the code, so here they are.

Hardware wiring:

2013 11 18 10 26 12 There are now four I/Os, the steering servo, a light detector under the from of the robot, two LEDs (red and green) which show the steering direction and the sonar detector for obstacle detection.

The latest code is:

// This is my second go at the one wheel robot. Sigificant program parts are: 
// 1 lots of defines to set parameters, hope to make the code easier to understand later
// 2 LED show the chosen steering direction, for no particular reason other than pretty
// 3 servo angles set it to centre, and R or L
// 4 when a random direction is chosen for forward or reverse, it is biased to the centre
// differently for fwd or rev. bigger number = more bias towards chosing centre direction
// 5 velocity is set, but in reverse it is reduced
// 6 the robot goes forward for a time, then choses a random direction, so as to "roam" around
// 7 if the sonar detects a crash then it backs out either R or L but not C
// 8 a couple of settle times are used to stabilise the operation against hardware glitches
// 9 if it comes across a white place then it stops (parking place!), waits for 10sec then gos off straight

#include "Servo.h"
#include "NewPing.h"

// piezo pin
#define PIEZOPIN A3

// LED pins
#define GREENPIN 2
#define REDPIN 1

// light detector pin
#define LIGHTPIN A4
#define DARK 500

// sonar pins & max distance (above this returns 0)
#define TRIGPIN 5
#define ECHOPIN 4
#define MAXDIST 100

// RobotShield driver pins for motor A
#define MOTORADIRPIN 8
#define MOTORASPEEDPIN 6

// servo pin
#define SERVOPIN A5

// steering positions
#define STEERCENTRE 85
#define STEERLEFT 115
#define STEERRIGHT 55

// random direction bias towards straight(0), 1-3 = left(1), 4-7 = right(2)
#define BIAS 15
#define REVBIAS 10
#define CENTRE 0
#define LEFT 1
#define RIGHT 2

// crash detect distance (cm)
#define CRASH 15

// drive speeds (0 - 255) and directions
#define FWDSPEED 130
#define REVSPEED 130
#define STOP 0
#define FWD 1
#define REV 2

// various timings (msec)
#define FWDTIME 500
#define REVTIME 2000
#define SETTLE 50
#define PARKTIME 10000

Servo steering;  // create servo object
NewPing sonar(TRIGPIN, ECHOPIN, 100); // create NewPing object, max 100 cm away

unsigned long ms, pms;

// =================SETUP================
void setup() {

  // define I/Os
  
  pinMode(GREENPIN, OUTPUT); // LED pins
  pinMode(REDPIN, OUTPUT);
  
  pinMode(LIGHTPIN, INPUT);
  
  pinMode(TRIGPIN, OUTPUT); // sonar pins
  pinMode(ECHOPIN, INPUT);
  
  pinMode(MOTORADIRPIN, OUTPUT); // motor pins for direction and speed
  pinMode(MOTORASPEEDPIN, OUTPUT);
  
  pinMode(SERVOPIN, OUTPUT); // servo pin
  
  // connect servo
  
  steering.attach(SERVOPIN);
  
  // seed random generator
  
  randomSeed(analogRead(A0));
}
  
// =================LOOP================
void loop() {
  
  // wander about
    
  long cm;
  unsigned int dir;
  
  // if find white parking place then stop
  
  if(analogRead(LIGHTPIN) < DARK) {
    drive(STOP, STOP);
    delay(PARKTIME);
    steering.write(STEERCENTRE); // go off straight
    while(analogRead(LIGHTPIN) < DARK) {  // go until off white area
     drive(FWD, FWDSPEED);
    }
  }  
  
  // check for obstacles, if none go forward
  

  cm = sonar.ping_cm(); // get distance (cm), convert us to cm, 60us/cm is roundtrip speed of sound
  delay(50); // at least 50usec between sonar pings
  
  if(cm  == 0 || cm > CRASH) { // no obstacle in CRASH distance out to MAXDIST (returns 0)
  
    drive(FWD, FWDSPEED); // go forward
    
    ms = millis(); // change direction if more than FWDTIME has passed
    if(ms > pms + FWDTIME) {
      dir = randir(BIAS); // save direction chosen, based on BIAS, for use in choice of reverse direction below
      pms = ms;
    }

  }
  
  // obstacle found, reverse away
  
  else {
    
    if(dir == LEFT) steering.write(STEERRIGHT); // if dir was L then R
    else if(dir == RIGHT) steering.write(STEERLEFT); // if dir was R then L
    else while(randir(BIAS) == CENTRE); // if was centre set to only L or R
    drive(REV, REVSPEED);
    delay(REVTIME); // for a time
  }
  
  // loop stabilisation settle time
  
  delay(SETTLE);

}

// chose a random direction, returns direction chosen, lights LEDs
int randir(int limit) {
  
              int x, result;
        
              digitalWrite(REDPIN, LOW); // LEDs off
              digitalWrite(GREENPIN, LOW);
              
              x = random(1, limit); // random direction
              if(x < 4) {
                  steering.write(STEERLEFT);
                  digitalWrite(REDPIN, HIGH); // red LED on
                  result = LEFT;
              }        
              else if(x > 3 && x < 7) {
                  steering.write(STEERRIGHT);
                  digitalWrite(GREENPIN, HIGH); // green LED on
                  result = RIGHT;
              }
              else {
                steering.write(STEERCENTRE);
                result = CENTRE;
              }
              
              delay(SETTLE);
              return result;
}

// drive forward at vel 0-255, cmd = 0 STOP, cmd = 1 FWD, cmd = 2 REV
void drive(int cmd, int vel) {
  
    switch (cmd) {
      case 0: // stop
        analogWrite(MOTORASPEEDPIN, STOP);
        break;
      case 1: // fwd
        digitalWrite(MOTORADIRPIN, HIGH);
        break;
       case 2: // rev
        digitalWrite(MOTORADIRPIN, LOW);
        break;
    }
    analogWrite(MOTORASPEEDPIN, vel);  // set speed
}  
I have the thought to put in some sound generation, maybe the pip, pip, pip when reversing. This would be done by connecting a piezo transducer to A3 output and using the "pitches.h" library and tone() function.

Wednesday 13 November 2013

Been quiet around here, for a good reason

I have just immersed myself in the microcomputer called the Arduino. This is a very flexible single board computer with an excellent program development system running on my Mac.

The Arduino has lots of input/outputs, six of which can be used as analog inputs for measuring voltages of 0-5V. All I/Os can be used for digital input or output. Six of the digital outputs can output PWM signals to emulate an analog output. This is the board:

Screen Shot 2013 11 13 at 16 21 03

Along side this I have purchased a "Starter Kit", looks like this:

Kit box

Inside is everything you need, and more, to do a series of practical experiments, complete with a book giving full and simple instructions.

Inside box

Anyone could grasp microcomputer programming with this kit. But to help Arduino has an excellent web site at arduino.cc.

My robot

After I had done all the exercises and learnt how to program, I then purchased a one wheel robot chassis and a RobotMotor driver board which plugs on top of the Arduino. I wired this up to the drive motor, steering servo, an ultrasonic range detector and a couple of LEDs which show the steering direction. The robot looks like this:

One Wheel Robot

Programming

Now comes the tough bit! Writing a program to make the robot do something. A simple robot like this with only one sensor, for range, capable of measuring from about 2 - 200 cm. Based on this input I wanted the robot to roam around the room, and avoid crashing by backing up when it got closer than 20 cm to anything. It should roam around in a random pattern and back up in a sensible way.

The latest code is in the post above.

Sunday 13 October 2013

Watching her

We went to dinner at our son's house last night. He has a son and a daughter. The daughter is what used to be called a handful. But not in a disgusting way, she is very clever, sometimes irresistibly naughty and sometime as sweet as … well good.

Like this:

Screen Shot 2013 10 13 at 11 48 56

She drifts out to one extreme or another but finds it difficult to get back, she gets stuck in naughty quite often and needs a quiet talk to get her back to good, then again she demonstrates a sudden clever remark or skill or knowledge. Last night she showed a wonderful spanish accent, she has been doing spanish at school. I don't know whether is is mimicry or genuine mental switch to the language, but it sounded very clever to me.

And then another day I loaded a Mandarin Chinese learning program on my iPad and she got going writing the Chinese characters and the English words. She sure has a way with languages.

Thursday 3 October 2013

Climate change - ACTION

It is now without doubt that climate change is underway, and will continue unless we stop (yes stop) using more CO2 producing fossil fuels! They have to be left in the ground - whereas the industry is spending £600B yr trying to extract more… and the capital of these companies makes up a lot of the investments in your pension fund…

Global Climate Change3

The recent IPCC report uses four scenarios they call RCPs. (RCP2.6, 4.5, 6.0 & 8.5). These are named according to the "forcing" scenarios, i.e. how much of the agents that cause warming actually come about. The positive forcing agents are CO2 emissions, CH4 (methane) emissions, Halo-carbons and NO2; of which CO2 is the biggest, closely followed by CH4. Overall the total radiative forcing upwards has gone like this by 1950, 1980 & 2011:

Screen Shot 2013 10 03 at 13 41 16

So things are going from bad to worse, quickly. Putting it another way these are the contributors:

Climate Change Attribution

Here's what is happening:

1 Arctic sea ice melting, adding to sea level rise

Artic summer ice 1900 2012

2 Increase in CO2 due to fossil fuel emissions:

CO2 1960 2012

3 Land and ocean surface temperature rise as a result of forcing

Land and Ocean surface temp 1850 2012

4 Ocean CO2 & pH fall, killing off all sea life from corals to fish:

Ocean CO2  pH 1990 2012

5 Sea level change due to thermal expansion and ice melting (poles and glaciers):

Sea level change 1900 2012

6 Heating of the oceans - much more energy is stored in oceans than in the air, so it is much more important to look at sea heat content than air temperature (the 2C story…). This is hell of a lot of Joules of energy:

Upper ocean heat content 1950 2012

7 Finally here are the main effects depending on the RCP scenarios:

Table C  mm vs RCP

YOU HAVE GOT TO BELIEVE THIS STUFF. WE NEED TO ACT, OR DROWN, OR STARVE, OR START BLOODY WARS, or…

This is all a very slow process, but it is going on. We can expect by 2100 - warmer days (certainty), hot days (certainty), heat waves (very likely), heavy rain (very likely), droughts (likely), cyclones (likely) and high sea levels (London and New york under water? Likely).

Thursday 29 August 2013

A question / Syria

I have just one question about getting involved in the internal war in Syria.

WHAT IS IN IT FOR US?

My conclusion is, nothing.

WE must stop being moralistic and tub thumping. Our job is not to rule the world (maybe it's a colonial hangover, but all the same…).

So lets stop being coerced by the USA into foolish military actions, we must insist on a political solution among the people of the Middle East themselves. It's called self-determination.

Leave them to it. If they want to shoot themselves, gas themselves or whatever. Just be smug and glad it doesn't happen here - any more. We have grown out of it.

Tim! Get a grip

The expected announcement of new iPhone models by Apple, has been completely ruined by leaks.

Many of which are probably true and show the exact models that will be announced.

We have seen both internal electronics, screen shots - probably inevitable since beta versions of iOS7 have been widely circulated to help iron out bugs by developers - and worst of all finished products that the public are supposed to be surprised by.

After all that is the centre of Apple marketing, is it not? To bring a new surprise to the market!

Screen Shot 2013 08 29 at 10 01 08

In past times Apple has always kept very tight secrets about new developments, but somehow Tim Cook seems to have lost control, or is not exerting enough control, over manufacturers and their employees who have photographed many of the secret developments, both internal circuits, cases and finished products.

Enough to completely ruin the anticipation of the event.

Come on Tim. Get a grip! Get cross!

This IS pollution!

Whatever people may say, the criss cross tracks of planes IS pollution. It pollutes my air space, prevents the sun shining and spoils my enjoyment of a summer's day.

Media Pollution

Sunday 25 August 2013

Why are we constructing a society like this?

A couple of issues are:

Housing in the UK

We are desperately short of houses, and a lot of the stock we have is poor, energy wasteful and decrepit.

But houses are not being built.

Current government proposes to increase house building by relaxing the rules, and at the same time as pushing a “localism” agenda for communities to manage their own environment, has legalised land grabs by speculating developers.

Two aspects of this which are the most damaging are

- Councils receive from central government money for every new house built, effectively this amount is a bonus of the council tax value of the next 6 years. This encourages them to freely give planning permissions t to the most housing they can get away with, with little or no consultation with communities that elect them.

- Planning policy says quite clearly that permission cannot be refused if the development is “sustainable”. The definition of sustainability is wide open to abuse, and developers are very good at filling gaps by “mitigation” arguments. Thus councils can not refuse approvals, or developers will go to law and sue them to reverse decisions - at tax payer’s cost.

The result of all this is that councils are giving more and more approvals, but houses are not being built, because land assets are inflated (as developers buy land cheap and get planning permissions which increases the value), This looks good on the developers balance sheet, but means that they cannot build houses at a cost (= land + house build cost + council costs for serves + profit) that people can afford.

Government initiatives to tempt people into taking unaffordable loans (75% from banks and 20% short term from government) are a false stimulus. They still cannot afford the repayments, even if the government part is interest free, and they will get into uncontrolled debt.

So planning approvals are given, without community support or consultation, land assets go up, and NO houses get built.

HS2

HS2 proposals beggar a big question about what kind of society we want to build. The sums are so great (£50bn / 25M tax payers = £2000 each) that one can truly question the advantages of transporting thousands of people at very high cost between city centres and gaining just 1/2 hour to do so.

The way our society is organised today is increasing and increasing “run about”, more and more people are travelling to work, traveling to meet each other, traveling... yet 90% of businesses in UK have less than 10 employees.

To serve communities and those 90% of small businesses we have to find a way to cut traveling and invest to grow locally.

That is what we need to spend £50bn on:

- Housing and business planning

- Business premises and tax reductions

- Local transport infrastructure

- Communications, or broadband to give “virtual office” capability across the UK.

- Electric, autonomous delivery vans, and other automated infrastructure

- More beautiful places to live

Politics and government

We have to accept the state of humanity. Just chose how do we want to live with it? Living in UK is very different to living in the Sahara or in Syria.

We have to accept that the a lot of humanity is, in western eyes, in-humane in many ways. Not to accept this, and leave people to evolve by themselves, has created social upheavals, law making, wars etc etc as those, you could almost call them “do gooders” push to construct a society in which ”decent” people can live.

And even here in UK we have inverted politics. Today politicians do not consult with the people they represent, then take these views to parliament, but conversely they make up policies, publish manifestos, ask for a vote then pass laws, dictating back to the public what should happen. And in many cases law making outside the very manifesto they were elected on, with no community input, except from lobby groups. And even these are coming under attack.

Friday 23 August 2013

Finding components for my SSTV receiver

I am building a simple SSTV receiver for reception on 14230 kHz, this is based on the RSGB Centenary Receiver for PSK31 published in Sept Radcom magazine. My circuit diagram is in a previous post.

I have managed to get most of the components - resistors, coils, capacitors, ICs - from Spectrum Communications. But had difficulty finding a source for the 14230kHz crystals. Now I have made a contact through ICM-Crystals with Chris Emmerson who is able to source them from China, at a cost of 20GBP for 6. Compare that to quotes in the EU & UK of 120-160GBP!!

Let's see how delivery goes...

In the mean time, here's the board with most components mounted:

2013 10 02 15 42 08

I have left off two resistors that were connected from the LM386 inputs to ground because this IC has internal bias resistors and they are unnecessary. I have also substituted the input MOSFET for a BF245A, and lowered the load resistor to 1K to maintain the drain at 4-4.5V with zero source resistor.

Monday 19 August 2013

Looking at the SA612

The SA612 is a wonderful circuit! It combines a balanced mixer with an oscillator. Its internal circuits is this:

Screen Shot 2013 08 19 at 11 05 09

Internally the circuit has three Bias circuits which set it up in the right conditions. It has an oscillator at pins 6 & 7, inputs at pins 1 & 2, and outputs at pins 4 & 5. The inputs are grounded through 1k5 resistors and the outputs are loaded by 1k5 resistors also. This makes the whole circuit extremely easy to use with minimal external components.

First the oscillator. This has two pins, 6 & 7. To use this as an oscillator external components have to be connected like this:

2013 08 19 11 32 14

The inputs are on pins 1 & 2, and are balanced, but can be used a single end inputs by connecting the unused one to ground via a small capacitor, like this:

2013 08 19 11 35 37

The outputs on pins 4 & 5 are also balanced, but may be used unbalanced like this:

2013 08 19 11 38 19

To complete the circuit just add power and ground, pins 8 & 3:

2013 08 19 12 47 11

Now to connect some external circuits, for example to make an RF mixer. Here the input comes from a crystal filter and the output is audio frequency, this would be suitable for a PSK32, SSTV or SSB detector.

2013 08 19 12 56 23

The crystals "X" have the same frequency, e.g. 14070 kHz for PSK31 or 14230 kHz for SSTV reception. The oscillator is pulled to the upper sideband by the 30pF trimmer. The RF input would typically come from a preamplifier which we will add next, and the Af output would go to an AF amplifier (see previous posting for an AGC controlled amplifier).

2013 08 19 13 01 48

CORRECTION: The 2K2 resistor in the collector of the BF245A should be 1K

The SA612 needs a 5V supply, so a 7805 regulator (TO92 size is OK) is used. So there we have it, correct use of the SA612 to make simple 14MHz, fixed frequency, receiver. Here's the complete circuit, now to get the veto board wired and try it...

2013 08 19 13 30 41

Note on the LM386

There are some common mistakes in circuits using the LM386

The amplifier internal circuit is:

Screen Shot 2013 08 19 at 10 16 18

Which shows several things:

1 The inputs have internal resistors to ground - so external resistors are NOT needed. The inputs are ground referenced. Inputs can be on either terminal, with the unused one grounded, or using a balanced input to both.

2 There is an internal feedback tapped at pins 1 & 8. Leaving these pins open give the smallest gain of about 20, while connecting a capacitor from 1 to 8 increases the gain to 200.

3 An output stabilising network of a series 47nF to 100nF capacitor and a 10 - 22R resistor is highly recommended.

4 To prevent supply line noise or hum reaching the input stages a decoupling capacitor can be connected from pin 7 to ground. 47-100uF would be suitable.

LM386 Amp with AGC

As part of a developing receiver for SSTV, based on the RSGB Centenary Receiver project in the September Radcom , I have developed an alternative AF amplifier for the set providing AGC to give a constant output for differing inputs from the RF stage.

The amplifier is the ubiquitous LM386, used by just about everybody - hell its a very good design, well done National Semiconductor! The amplifier is set to maximum gain by the 10uF capacitor across pin 1 and 8. The input goes to the -ve side at pin 2, the positive input at pin 3 is grounded. The input is via a series 6K8 resistor and a 10uF decoupling capacitor.

The AGC circuit uses a diode bridge. On +ve and -ve cycles the output charges the two 100uF capacitors until the top two diodes start to conduct, when they do they reduce the input so providing an AGC action.

Here's the circuit:

2013 08 19 09 57 24

The amplifier give a constant output tot around 0.7V rms, i.e. the forward conduction voltage of the two diode in the +/- control loop.

A bigger output can be obtained by using a potential divider at the output before driving the diode bridge, a potentiometer could be used (suggested value 1k log), to provide a volume control if directly driving a loudspeaker. The output of 0.7V is good for the line input of the USB DAC iMic connected to the iPad for SSTV decoding.
The front end is now in breadboard stage but I am waiting to find the 14230kHz crystals from somewhere...

Thursday 15 August 2013

Just an idea for SSTV

There was an interesting circuit in the latest Radcom from the RSGB for a receiver for 14MHz PSK31 digital signals. This got me thinking that something similar could be used for SSTV.

The receiver is an RF amplifier, followed by a crystal filter and balanced mixer, whose output goes directly to an AF amplifier.

The transmitter is a balanced mixer driving an output stage.

Here it is:

2013 08 15 18 05 39

The AF input and AF output are connected to an iPad using a Griffin iMic interface. The iPad is running Blackcat systems SSTV software which can both receive and transmit.

I have not yet worked out the RX/TX switching, and it occurs to me that I don't need two 14230kHz oscillators, one would do. So the TX oscillator could feed the RX mixer…

Tuesday 6 August 2013

Digital Audio - Lossy compression

Lossy codecs save space on storage and speed download times, MP3 reduces files to 1/12th, WMA to 1/24th of their uncompressed size. Subjectively and very often, people say they cannot hear the difference between a CD, a 128kbps MP3 or a 64kbps WMA stream. But this is when they are listening on pitifully small speakers, for example on a laptop, or on poor earphones plugged into an MP3 player. But play the same tracks on a better hifi system and the differences are clear. Play the same track from a CD and the difference is very striking. Play the same tracks from an HD Audio download (24bit/96kHz) studio master and the differences are dazzling.

The problems with lossy compression are many, and mostly based on dubious psycho-acoustic assumptions:

1. The removal of all audio information above a certain frequency - “can’t hear it anyway”

2. Stereo to mono conversion completely or above a certain frequency - “stereo is only heard at mid frequencies”

3. Phase collapse, the elimination of phase differences between channels, completely or above a certain frequency - “blurred instrument positioning in the sound stage does not contribute to musical appreciation”

4. Frequency masking, loud tones masking lower volume information in nearby frequencies - “just lets the main music come through”

5. Temporal masking, loud tones that mask lower volume information that precedes or follows the masking content - “just lets the main music come through”

6. Echo, the insertion of unwanted information before and after sharps transients - “the ear doesn’t hear this small change”

Subjectively people find that WMA is better than MP3 is better than Real Audio lossy compression. But technically they are all bad. This can be seen by looking at the spectra of various test sounds before and after compression.

The first spectra show a sound clip original (in WAV uncompressed format) versus the same clip of pink noise in MP3, Real Audio and WMA reproductions.

Screen Shot 2013 08 06 at 13 51 06

Here's another example:
Screen Shot 2013 08 06 at 13 51 50

The MP3 output looks ugly, with low pass filtering above 10kHz, but look at the added noise round the low level tones! The Real Audio has better channel separation and frequency response up to above 13kHz, but the noise floor is up to just -60dB, close to the right channel levels. WMA compression delivers clean stereo separation and high frequencies above 18kHz, but a slightly increased noise floor.

Sorting out the bits

One of the ambitions I have had for a long time is to get all the binary bits from a musical recording through my chain to the loudspeakers. No matter what they make of them when they get there, which is another matter.

What do I mean? Well these days you can start with a CD, or a downloaded file which can be CD 16 bit/44.1kHz or upwards - my limit today is 24bit/96kHz as this the highest supported by my iMac and iTunes. A 24bit/96kHz file will carry a 120dB dynamic range and DC to 48kHz bandwidth. Not so good as an orchestra but a lot better than CDs.

But to throw in another difficulty in the way I insist on sending my music over my WiFi system, to avoid all those ugly wires and allow me to have the computer in one room and the system in another. So what I have is an iMac running iTunes, an Apple TV, and a spare Macbook also running iTunes. The Apple TV or the Macbook can be connected by an optical link to my DAC and the line out audio to my amplifiers.

A word about the DAC. I hate, if that is not too strong a word, all these DACs advertised as the best in sliced bread, but costing $1000s. This is ridiculous. The basic guts of a DAC are a couple of semiconductor chips, one to receive the SPDIF optical input and pass it to a decoder as a serial I2S signal. The decoder is the guts of the system and many semiconductor makers offer products for this function. However sorting the men from the boys there is only one company, English, that leads the field, this is Wolfson. The make both chips required, the WM8805 SPDIF and the WM8740 DAC. Together they cost $10! So why $1000? The problem is to find someone who makes a DAC with these chips. Fortunately a company in Hong Kong, HA INFO Audio Electronics, has seen the light and makes a rather neat DAC with these chips. It has digital SPDIF and Coax input up to 24bit/192kHz, and line and headphone output for under £100. Which is a great improvement over $1000-2000!!!

Then the amplifiers. Here again prices of equipment are ridiculous at anything up to the $5000 range. I am a great fan of class D amplifiers as I believe they can give excellent quality and performance, including transient rise times, and have high efficiency so they run cool. However looking again round the industry there are few amplifiers that quote a DC to 50kHz bandwidth. I believe we have to maintain the bandwidth all the way from the computer file to the loudspeaker terminals. And this means DC to 50kHz for a 24bit/96kHz source file. One company that makes such amplifiers is Hypex with modules up to quite high powers - 400W or so. I use their 180W models in a small case with a conventional power supply, the only requirement being to use massive capacitors of 10,000uF for both positive and negative rails. The result is a low cost amplifier (total about £200) which has excellent performance and DC - 50kHz bandwidth.

Getting the audio from the computer to the DAC SPDIF optical input can be done in three ways:

1. iMac > Apple Airplay > Apple TV > DAC. But this compromises the bandwidth as Airplay down-samples files to 16bit/44.1kHz. And this is what comes out of the Apple TV. So that is no good.

2. iMac > file copy > MacBook > DAC. Copy the 24bit/96kHz files to the MacBook and output SPDIF optical from there to the DAC, in this case the system does support DC-50kHz bandwidth all the way though. But files have to be copied.

3. Register both iMac and Macbook with Apple for “Home Sharing”. This allows the MacBook to see and retrieve the music from the remote iMac. And, wonder of wonders, it can retrieve 24bit/96kHz files over WiFi with NO down-sampling. This means that in this way high quality music files can be played over my WiFi system. (I Wonder why Airplay and the Apple TV down-samples? WiFi can easily carry the bit rates of the 24bit/96kHz music (2Mbps or so). Its probably because the Apple TV has a rather slow processor built-in??? Anyway Apple’s iTunes preferred music delivery system is sadly only 16bit/44.1kHz AAC compressed music...).

So now the problem is solved. If you are a newbie then I strongly suggest to use a setup of:

- Music Centre, either remote iMac or local Mac Mini - or both

- Itunes with Home Sharing enabled, HD tracks downloaded from the many on-line stores (Linn, 2L etc)

- The DAC and Amplifiers I mentioned above (Google them).

- Finally an iPhone or iPad with Apple Remote to control iTunes running on one or both of the Macs.

Don’t forget to enable 24bit/96kHz sound output using the utility Audio MIDI Setup on both Macs. And restart iTunes after you have done it.

A headless system can be created by using a Mac Mini as your music centre and controlling it by Screen Sharing / VNC Viewer from a remote iMac or iPad. In this way you can configure iTunes, buy HD track music and have a totally integrated low cost HiFi system.

Now about those loudspeakers which I want to drive from DC to 50kHz, what about those? Suggestions welcome.

Tuesday 30 July 2013

Multiple audio outputs on iMac

I have been using my iPad with the Blackcat Systems SSTV program to view SSTV pictures. The output of the iMac was connected to a A/D converter, the Griffin iMic, which was then plugged into the iPad. [I have used the same I/O device to listen to an SDR radio…]

This all ran well but the problem was that when I plugged the iMic in to the iMac headphone jack, I lost the audio output from the internal loudspeakers, and so could not monitor the audio signals or tune around the band without unplugging the iMic…

So how to output audio to multiple devices? Well there is a way. Open the utility Audio MIDI Setup, and chose to add a device (+ sign). Then chose Multiple Output Device, now select the outputs you want to receive the signals. Here's a screen shot:

Screen Shot 2013 07 30 at 11 53 48

In my case I was outputting the signals from Web based SDR radio at http://websdr.ewi.utwente.nl:8901.

Screen Shot 2013 07 30 at 12 00 00

and tuning to the SSTV frequency of 14230kHz - you can see a signal coming in.

I can now drive the iMic/iPad and listen via an Firewire audio interface, the FCA202, with a small battery powered loudspeaker plugged into the headphone jack. Or I can plug the iMic into the FCA202 headphone output to pick up the audio at the same time as it plays through the internal iMac loudspeaker.

LATER

I have had two or three crashes of Safari when listening to the radio I mentioned above, I have no idea why. To cure the problem I was forced to remake and select (Alt-Speaker Icon) the Multiple Output device and then restart Safari. Bug reports sent to Apple.

Friday 26 July 2013

Putting a bigger HDD in Maggie's computer

My wife, Maggie, has run out of disk space - mainly from having over 12,000 picture in iPhoto!

So I plan to install a spare 500GB HDD that I have lying around. The problem is that I don't have the original OS X installation disk that came with the computer. But Apple to the rescue, as the computer, an old 13" white Macbook, has been upgraded to OS X Lion (10.7) and this can be installed over the internet from Apple.

How?

IMPORTANT!!!

BACK UP TO TIME MACHINE EXTERNAL DRIVE!!!

Then first you need a copy of a program called Recovery Data Assistant. This has to be down-loaded from the Apple web site.

You then need a USB stick which has to be (*) formatted using Disk Utility, as Mac OS Extended (Journaled) and selected and partitioned as one partition with the Option of GUID. This makes it suitable for a bootable drive. The Recovery Data Assistant app is copied onto this USB drive - needs above 1GB, I have an 8GB drive so that's OK.

HARDWARE

Next you replace the physical HDD in the computer - this is fairly easy and there are instructions on the Apple web site.

INSTALL

Now restart the computer an hold down the Alt key.This will bring up a picture of all the drives on the machine, one of which will be the USB "Recovery" stick. Chose it.

Now you must erase the new HDD and format it correctly, from the Recovery Data Assistant chose the menu option of Disk Utility. Then, as above for the USB stick (*), format and partition the drive as bootable.

Nearly there.

Now quit Disk Utility and still in the Recovery Assistant select to Install OS X from the internet. Join your local WiFi network and follow the on screen instructions - you will need the Apple ID you used to purchase the original OS X Lion and the password.

After about an hour you will have a brand new computer, running OS X Lion. You can transfer the old HDD files back from the External Backup Drive using the Utility Migration Assistant.

Tuesday 9 July 2013

Graduation

Charlie graduated today from Stafford Uni with a BEng (Hons) degree. Well done!!!

Charlie Graduation Stafford UK

Monday 1 July 2013

New DAC

For some time I have been mightily disappointed in the DAC that I had in my music system. I built an amplifier using the excellent Hypex modules; chosen for two reasons, bandwidth (up to 50kHz) and low distortion. But I couldn't find a low cost DAC and had to fall back on what I thought was the best from HK, since I object to paying the ridiculous prices asked for by most audio companies. (I should explain. Wolfson in UK make the best ICs for building a DAC, there WM8805 SPDIF interface and WM8740 DAC are by far the best in the industry. And they cost less than 10$, so why should I pay 1000$ for a DAC?).

But then I found that some sensible HK supplier had taken the application note for the Wolfson chips and made a DAC, for £80! Complete in a nice box, with headphone amplifier also, and with an AC power supply. This DAC covers all bit depths (16 & 24) and all sample rates from 44.1 to 96kHz. So I bought one.

I coupled this DAC up in one of two ways:

1 Optical input from my Apple TV, and streaming music over from my iMac by WiFi. This was the response:

Screen Shot 2013 06 30 at 09 53 06

As you can see it cuts off sharply at 19kHz, this is due to the way Apple's Airplay handles the transfer, any file in iTunes is down sampled to 44.1kHz before being sent over the WiFi, and at the Apple TV end there is a low pass filter at around 20kHz. The idea being that music only needs a 20Hz - 20kHz bandwidth, an idea which I find ridiculous - for a violin to sound like a violin you have to pass all the frequencies it generates, and these stretch up beyond 50kHz.

2 Optical input from my MacBook with Audio MIDI setting to output 96kHz. This was the DACs response:

Screen Shot 2013 06 30 at 09 51 06

Well now isn't that better? A response out to nearly 45kHz - against the maximum you could expect from a 96kHz rate of half that or 48kHz. And note that the response goes down to DC, as do my amplifiers.

What is very exciting is that with "Home Sharing" turned on, so that I can access music on my iMac (some of which is 24/96) then playing a track through the MacBook gives the wide bandwidth, the same as playing directly from the MacBook!

Now I am sure that I am sending all the possible frequencies from the music files to my speakers. What they do with it is another question… but it sound much better.

Thursday 27 June 2013

Cherwell District Council - woefully wrong

Since ever Cherwell District council have been ignoring the huge changes that the government has brought in about house building and district planning.

Up until 2010 planning targets, for the number of new houses to get built, were handed out by central government under the Regional Spacial Strategies. For us this meant the number in what is called the SE Plan. The figure in this plan was to build 13400 houses in Cherwell from 2006 to 2026.

The changes to planning policy brought in by the coalition government meant four things

- the RSS was revoked, and the SE Plan 13400 target no longer valid

- a completely new National Planning Policy Framework (NPPF) was introduced

- under the NPPF councils had to replace the SE Plan number with a market based, factual forecast of housing need in the next 5 years, and a vision of needs in years 6-10 and 11-15. Updated annually and rolled forward.

- make a definitive Local Plan to describe the vision and strategy for their district

But what Cherwell did was lazy and to argue that the SE Plan was still valid, and they did not make any new market based forecast (they are not alone, neither have many other councils either…). They then extended it our to 2031 to a project a figure of 16750 houses to be built in a fixed 25 years.

They have never met the rate of building that the SE Plan defined, 670 houses per year. From 2006 to 2012 just 3744 houses were built, or 535 per year, against a "SE Plan" of 5360. The number built was however not restricted by the provision of land or planning approvals, with huge developments approved in Banbury and Bicester. It is however a realistic number which correctly reflects the growth in population plus the financial limitations of people to buy the houses.

Here are the numbers plotted out:

Cherwell

Ignore the lines at to bottom , they are the data from Banbury alone.
The top green line is the Cherwell SE Plan, under this the red line is the actual built up to 2013 and the trajectory (developer forecast) out to 2018 (5 year need). This neatly bring us back to the old Plan and Cherwell pat themselves on the back. But it is wrong.

The growth of need, based on population growth, not taking into account any financial limitations, is shown by the dotted red line. This is based on data from the ONS and DCLG and a study from Cambridge University (howmanyhomes.org) that gathered the data together - so it is national and reliable.

The net effect of this is that Cherwell is planning to overbuild houses that people won't or can't by. By 2018 developers have told Cherwell they are forecasting to build 2076 more houses than the population growth indicates.

To achieve this Cherwell Council have given new planning permission on huge swaths of green field land. Developers are very happy to have this, they gain asset value on land they have bought once planning permission is given and the land value rises. It is all a land grab, they have no intention of building...

The reality is that sufficient previously approved sites are simply not being built at Bankside in Banbury and the large Eco Town in Bicester because there is not the demand and the house prices are too high for people to afford a mortgage. The house prices are high because developers are greedy for profits (on top of the scurrilous growth in asset values they are getting) as the speculation cost they paid for the land in the housing boom times forced up prices. This was all well and good in the housing boom, but in the current climate the value of the land has fallen, the developers should take a hit on asset values, stop grabbing even more new land and sell houses at prices people can afford.

For completeness here is the data for Banbury:

Banbury