Computer autopsy!

The GCSE computing class is well under way  and seem to be coping well with Python, but we decided that for the last lesson before half term we wanted to try something a little more practical as a treat.  My older computer was dragged back from the shed, where it was residing without a side panel or hard drive, and I took it into class. I also took in my pi and arduino to show them that computers come in different sizes, but it was the big computer that was the main attraction.  I have quite a small group, and they happily got stuck in dissecting the computer.  Those who didn’t want to get quite so hands-on documented the proceedings with a camera and video camera, or researched components on PC World.

We all marvelled at the weight of the CPU, felt the coolness of the heatsink, wondered at the tangle of cables, took the machine completely to pieces and spread it on the desks, then started the reassembly.  They even managed to get it almost back together!  We did discuss the need for earthing to avoid static, and that the components shouldn’t really be handled as much as we did, but I think by the end of the session all who were there were left with a deeper understanding of what’s inside the box on the desk, and while the boys showed no hesitation in dismantling things I learnt a lot too, and at least would feel a little braver in venturing inside should the need ever arise.

 

Advertisements

Electronic timer project

assembled timer - lots of LEDs!

assembled timer – all hand soldered in

Time for more soldering – delayed from the weekend due to real life commitments, but eventually I managed to get the soldering iron out, this time for the kitchen timer kit from Maplin.

A couple of hours’ work assembled all components, including a buzzer, 16 LEDs, an integrated chip, resistors and capacitors, the battery box was connected and the whole thing screwed together – so it was time for the moment of truth!

completed timer with LEDs showing

completed timer with LEDs showing

Yes, it all works, I’m pleased to say.  I now have a working kitchen timer that I made myself from components.  The push button sets the time, then the lights gradually go out until at the end they light up in a pattern.  The buzzer sounds when the timer is turned off.

This was a simpler kit than the radio (which I still haven’t found a power supply to test) but on the whole probably a little more fiddly, owing to the size of the LEDs and the sheer number of them.  I figured out how to make electronics easier – make the circuit boards bigger so that the soldering is less fiddly, but I suspect the experts would disagree and tell me it’s just experience! I’m currently using the 30 watt size soldering iron.  They do make smaller sizes, and I suspect that if I end up doing a lot more electronic soldering I’ll splash out for a smaller, more delicate one – and a proper soldering stand, as it’s nervewracking having a hot soldering iron sitting on the desk not properly secured.

What I don’t know yet is how to make a circuit board – I suspect it’s something to do with etching, and beyond both my capabilities and tools – but on the whole I’m a lot happier with the idea of assembling electronic components and programming them than I was at the start of the summer.

Soldering session

radio kit from Maplin

radio kit

After my cat knocked my radio flying – again – and trashed it completely, I decided to be more adventurous than just buying a new one.  It was time to make my own!

A kit from Maplins seemed the ideal solution, which meant it was time to learn how to solder.

partway through construction, some components assembled

partway through, front view

The instructions were inside the pack, and at first they seemed confusing, but I soon got the hang of matching parts to places.  It was interesting to note that I already recognised parts such as transistors and resistors from my work on the arduino, but of course with the breadboard it’s just pushing pegs in, whereas here I actually had to use a soldering iron.  Luckily we’re a fairly practical family so materials were to hand.

I soon learned that being shortsighted actually helps as I get my best view if I take my glasses off and peer really closely, and the whole project was completed in a couple of hours or so, with only a very slight mark on  my desk from a drop of hot solder and a tiny burn to the tip of one finger – although a cat got yelled at for trying to jump on my desk (different cat!) and once or twice I found myself being rather less than careful with the hot soldering iron than my husband would have approved of (shush don’t tell!).

finished project from the front

finished project – front view

I thoroughly enjoyed my afternoon of putting the radio together, and although I haven’t yet located a power supply to test it with so don’t know how successful my work has been, I will definitely get another kit and try a different project.  More importantly, I’m looking at the insides of the old shattered radio, recognising bits and realising that it really doesn’t take much to cross from user to creator.

finished project from the back, showing the speaker

My neat soldering!

In the end, it really doesn’t matter whether the final project works, because the learning experience has been well worth the cost of the kit (£15).  Now I know that soldering is not as scary as it always appeared to be to a complete novice, I’ve seen first-hand what components go into making a radio and I have a real sense of achievement.

One challenge still to come is building a cat-proof case!

Arduino – using a servo and shift register

servo connected to arduino

servo connected to arduino

The next project in the arduino kit, project 4, is to connect a servo.  In some ways, this is like a motor, but a servo provides much finer control – the arm on the top will rotate by a given angle.  This can then be attached to all sorts of things – servos are commonly used in radio controlled models, for example, to control steering.  The servo in the kit comes with different arms to put on top.  I used one with a double arm, but there is also a single arm and a cross-arm one.

servo arms

Servo arms

Wiring the servo to the arduino was simple with use of the breadboard circuit layout, and the program provided rotates the arm back and forth.  The code to move the arm is simple:

{ 
   for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees 
   {                       // in steps of 1 degree 
       myservo.write(pos); // tell servo to go to position in variable 'pos' 
       delay(15);          // waits 15ms for the servo to reach the position 
   }
}

This will rotate the arm from 0 degrees to 180 degrees (well technically 179 degrees!).

Obviously the real power of the servo will come when it will rotate in response to input.

8 lights with a shift register

8 LEDs with a shift register

I then worked on project 5 – using a shift register.  This is a little integrated circuit that in this case allows me to control 8 LEDs but only using 3 pins on the arduino instead of the 8 pins I used for project 2. The advantage of this is that it leaves more pins free for other devices.

I hit major problems with this project – the wiring is more complicated than others I’ve done, and at first I had a wire in the wrong place.  This wasn’t helped by the fact there was no explanation of what I should see when the program was running, so although some lights came on I wasn’t sure if it was working right or not.  A rewire sorted most of the problems, but there was still one light that refused to come on.  Closer inspection revealed that one of the pins on the shift register was bent rather than going into its hole.

Once that was sorted as well, the lights lit up in sequence to illustrate binary numbers from 0 to 255, then a poke round the arduino support site found an alternative function which lit the lights in sequence and then turned them off again, and which showed that the lights could be turned on and off by changing digitalWrite()’s in the original wiring without the shift register to changeLED()’s in the new version, so the code itself is very similar.

What I don’t understand at the moment is how the shift register works.  While I can see the new code in action, and it looks straightforward, I would like to feel I understand how it works.  This is where I feel the frustration of not having had anything like this at school.  Still, I have the power of the internet at hand, and I’m sure somewhere out there is a simple explanation.

I feel at the moment the arduino is fairly straightforward when it comes to following the projects and writing the code, but I really don’t have the understanding of the circuitry that I would like, and no idea of how things are connected as the breadboard looks after it all.

I’ve now got a build it yourself FM radio kit (nothing to do with the arduino), so maybe working through that and having a play at proper soldering will give me more of an idea of circuitry, and in the meantime it’s a case of hitting the research before I move on.

 

Arduino – further experiments

arduino set up with 8 LEDs

Arduino with 8 LEDs

While I had my arduino set up with eight LEDs, I thought it was the ideal opportunity to write my own function to take in a decimal number and display the binary equivalent.

This proved extremely straightforward to do, leaving me with a pleasant sense of having got the idea with output code and basic C structure.

void displayBinary(int number)
 {
   allOff();
   int delayTime=5000;
   int num=number;
   if (num>=128){
     digitalWrite(ledPins[7],HIGH);
     num=num-128;
   }
   if (num>=64){
     digitalWrite(ledPins[6],HIGH);
     num=num-64;
   }
   if (num>=32){
     digitalWrite(ledPins[5],HIGH);
     num=num-32;
   }
   if (num>=16){
     digitalWrite(ledPins[4],HIGH);
     num=num-16;
   }
   if (num>=8){
     digitalWrite(ledPins[3],HIGH);
     num=num-8;
   }
   if (num>=4){
     digitalWrite(ledPins[2],HIGH);
     num=num-4;
   }
   if (num>=2){
     digitalWrite(ledPins[1],HIGH);
     num=num-2;
   }
   if (num>=1){
     digitalWrite(ledPins[0],HIGH);
   }
   delay(delayTime);
 }

Then I just called the function in the loop section, with different integers.  Something to aim for in future is to input a number on the computer and have that number pass to the arduino, which then displays it!

all the assembled parts for testing the motor

The parts for testing the motor

Then it was time to test a different output device, so I collected the pieces for circuit 3, the motor test.  This introduced some new pieces: a transistor, a different resistor and a diode, as well as the motor itself.  I still don’t have much of an idea yet what they do, but it was still straightforward to clip the pieces together to build the circuit. In a way, though, I think the breadboard hinders learning, as although it makes it very easy to connect the pieces together, it’s not obvious what’s going on underneath, and where circuits are being completed.  I also need to learn how to read an electronic circuit diagram sometime!  It’s been years since the batteries, switch and bulb days of my childhood science.

Testing the motor

Testing the motor

Still, the motor and other parts were soon connected (about 10 minutes max), and I downloaded the program from the web and uploaded it to the arduino. There were three sample functions, one to run the motor, one to accelerate it slowly and one to decelerate it.  All seemed to run very smoothly, using the same principle as the code to dim the lights, of sending different values of i in a loop in turn to analogWrite(motorPin, i) .  Now I need to figure out what sort of things I could connect the motor to.  This is where something like lego or k’nex might come in handy, to build a housing and purpose for the circuit.  There is a 9v adapter supplied with the kit, so that it doesn’t have to run connected to the computer.

So I’ve seen some of the outputs in action so far, lights and motor.  Still to come are the servo for finer control of movement and using a shift register, which apparently will reveal how to control a group of LEDs with less than one pin each.  Then there’s sound to add, and then I’m on to the input options.  That’s when things should start getting really interesting as it will then be possible to write interactive programs.

I have now also bought a book on programming the arduino, so there will be plenty more to come on this topic.

 

Arduino project 2

8 green lights

The 8 lights can be programmed to turn on and off

Project 2 for the arduino board is a series of 8 flashing lights, that can be programmed to turn on and off in different sequences.  A program is available to produce three different sequences, and I was able to add my own function fairly easily to add another sequence.  While I’m not fluent in the language by any means, the code was simple enough, and an array meant it was easy to cycle through the lights.  The setup itself was straightforward, although I did clip the wires on the resistors this time so they fitted more neatly.  The colour of the wires used doesn’t matter at this stage, although I suspect it would be easier to use colour coding on more complicated projects.

int ledPins[] = {2,3,4,5,6,7,8,9}; //this produces an array of ledPins - arrays 
                                   //start from 0, so ledPins[0] is the first
                                   //and ledPins[7] is the last light.

This code sets up the LED pins so each can be referred to by its index in the array.

 

void setup(){
    for(int i = 0; i < 8; i++){ //this is a loop and will repeat eight times
    pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output
 }

This is the setup function, that sets each of the connected pins on the arduino in turn to output mode.

 

void oneAfterAnotherLoop(){
  int delayTime = 100; //the time (in milliseconds) to pause between LEDs
  for(int i = 0; i < 8; i++){
    digitalWrite(ledPins[i], HIGH); //Turns on LED #i each time this runs i
    delay(delayTime); //delay so you can see effect then increase i and loop 
  }
}

This is one of the functions that can be called in the loop() method.

I copied the structure of this function to write my own to turn the lights off in turn.  There were a few syntax errors (the beloved brackets and semi-colons!) but on the whole it was straightforward.

So I was left with a feeling of achievement, that was soon overwhelmed by a feeling that there’s still so much I can’t do.  However, I remind myself that people are using this quite confidently in a short amount of time, and of course if I don’t try I will never get anywhere.  I can at least see now how I could build simple flashing light sequences.

What would be interesting would be to get a large array of LEDs set up and write functions to draw different things with them.  This, of course, is how things like moving display signs are programmed – the end user will just type in the text they want, and the program will know how to display that text correctly, either still or moving.  So that’s something to head towards maybe.  An 8×8 bi-colour LED matrix is easily available from the same place I got the starter kit, at £3, and could be used as the basis for a project.  What I’m not sure about is how many pins it connects to.  It does cycle through each column of lights in turn, rather than controlling all 64 independently, which would be rather unwieldy.

I assume the limit for the arduino is the number of pins available to connect to – my uno has 14 digital input/output pins, 6 of which can be used as variable outputs (PWM) and 6 analogue inputs.  The arduino mega provides 54 digital I/O pins (14 provide PWM) and 16 analogue input.  Amazingly, I now understand what that all means, which is far more than I knew before I started, so I must be learning something!

Basically, the digital input/output can be used to turn something on or off (output) or receive an on or off signal (input).  Using one as PWM output means that the output load can be varied, rather than on/off, so can be used for dimming a light, for example.  The analogue input can be used to receive signals from sensors, which tend to be analogue (varying) rather than digital (on/off).

Arduino – first steps

arduino on base

Arduino bolted to its base

Time to get to grips with some technology!

First job was to set up the arduino and install the software.  The arduino bolted to the baseboard and the software was available from the arduino website.  The arduino connected to my computer via the USB port and I located and uploaded the first sample program, which flashes an LED on and off repeatedly.

I originally tried using a video to help me with my first project, but soon discovered the instructions from the arduino website and the experimenter’s guide were more than enough.

first program

This program turns the LED on and off repeatedly

The program seemed clear, although I haven’t tried writing my own yet – apparently it’s based on C.  It has two required functions, the setup function and the loop function.  The setup part tells the system what inputs and outputs to use, and then the loop function carries out the actual work.

Setting up the breadboard itself was rather fiddly at first, until I got the basic idea.  All the layouts for the starter experiments are included, and it’s a case of cutting one out, pinning it to the board and then pushing the right elements through the right holes.  The breadboard then joins to the arduino and sits neatly next to it on the base.

As soon as all the wires were connected, the red LED in the middle of the breadboard started obediently flashing on and off – a very satisfactory end to my first project, with no troubleshooting required.

flashing light project

This simple layout has a flashing LED

This is the project in action.  I need to clip the wires for the components, as at the moment they’re rather long, but I’ll save that for a day when I feel a little braver, as I feel it’s better at the moment to have them too long than too short.

flashing light layout

This shows the layout of the circuit

Instructions are provided for developing the project by connecting the LED to an analogue output instead, so that instead of on or off you can adjust the brightness of the light, and a program is provided to demonstrate this as well.

This shows a close up view of the circuit, including the breadboard with the printed template.  The LED is connected to pin 13 of the arduino, which corresponds to the code lines

int led = 13;
pinMode(led,OUTPUT);

This all seems very straightforward so far, and I’m looking forward to learning more.

(Click on any image to see a larger version)