Tuesday, 27 December 2011

TP-Link WR703N, OpenWRT, MPD et al

Finally, a post....
I bought a TP-Link WR703N [1], it's a little router meant to be used in conjunction with a 3G Modem, it works as an access point broadcasting a wireless connection allowing multiple devices to utilize the modem at once (quite a clever idea, however, not one I'm interested in using), hence I decided to flash it with OpenWRT [2]


RAM - 32Mb
ROM - 4Mb
USB port (USB2)
CPU - Atheros AR7240 - 400Mhz
Wireless - Atheros AR9331 - b/g/n

Powered by a micro usb port, 5.7cm x 5.7cm, serial interface.
(These are just the basics, more here [3])

OpenWRT Install:
The device comes preinstalled with Chinese firmware, I connected the router via ethernet and configured Arch to have the IP (in /etc/rc.conf) but you could also easily use wifi to upload the new firmware.

After connecting to the router, keep hovering over the menu items, the page file names are in English, keep expanding the drop down menus until you find one with a page name similar to 'software upgrade', something along those lines (I do believe it's in one of the last sections). Go to the OpenWRT wiki and download the 'vanilla' firmware for the router, upload this, once the router has upgraded the firmware, it should reboot.

Having now installed the OpenWRT firmware, you can connect to the router via the ethernet port if you configure your computer's IP to be, telnet into the router using:
There you are presented with the CLI of the router where you can start manipulating things. Use opkg update to update the packages list and opkg install *package name* to install applications

These are simply the basics and much more informative instructions can be found on the OpenWRT forums and wiki.

OpenWRT Configuration:
I wanted to use the router as a wireless client (i.e. similar to a computer), I used the following network configurations


config 'interface' 'loopback'
option 'ifname' 'lo'
option 'proto' 'static'
option 'ipaddr' ''
option 'netmask' ''

config 'interface' 'lan'
option 'ifname' 'eth0'
option 'type' 'bridge'
option 'proto' 'static'
option 'ipaddr' ''
option 'netmask' ''

config 'interface' 'wan'
 option 'proto' 'dhcp'

config 'wifi-device' 'radio0'
option 'type' 'mac80211'
option 'channel' '11'
option 'macaddr' '38:83:45:a2:14:18'
option 'hwmode' '11ng'
option 'htmode' 'HT20'
list 'ht_capab' 'SHORT-GI-20'
list 'ht_capab' 'SHORT-GI-40'
list 'ht_capab' 'RX-STBC1'
list 'ht_capab' 'DSSS_CCK-40'

config 'wifi-iface'
option 'device' 'radio0'
option 'network' 'wan' #Set the adapter to act as a wide area network -- not sure why
option 'ssid' 'Price LAN'
option 'key' '*******'
option 'encryption' 'psk2' # My network uses psk2 security
option 'mode' 'sta' #Setup client mode

In the section 'config 'wifi-iface'' I've setup the router to act as a client by setting the 'mode' to 'sta' which sets the router to act as a client rather than an access point.

USB Support:
I needed USB support as the router only has a 4mb flash which isn't sufficient to install transmission, mpd, mpc etc. I updated
/etc/opkg.conf to remedy this (look at the wiki page on opkg, there is a section on how to do this).

Now I could install to my memory stick using the command
opkg -d usb install *package name*
This usually works fairly well, I had to update my PATH variable in /etc/profile to reflect the new install directories.

I've also played around in /etc/rc.local setting up some startup applications.
I've got mpd, transmission-daemon and mpc (adding playlists) on startup. 

[1] - $22/£15 - http://www.volumerates.com/product/genuine-tp-link-tl-wr703n-150m-11n-mini-wifi-wireless-router-for-instant-wifi-connection-99273
[2] - https://openwrt.org/
[3] - OpenWRT wiki page on WR703N - http://wiki.openwrt.org/toh/tp-link/tl-wr703n

I might continue to update this post as I progress with the project. I aim to use this router to act as a internet radio, I'll probably use an arduino to interface it with an LCD and rotary encoder.

Wednesday, 17 August 2011

A little bit about Arch Linux

I've recently switched from Ubuntu to Arch, which I have always wanted to do but time restrictions have been in the way, since it's summer I've been able to dedicate a good chunk of time to do this. I have a few things I'd like to note about it for myself as a historical record.

The installer did not work for me on the official download page. I downloaded multiple isos from the releng arch site which proved futile, again with installer problems, I finally downloaded 08.15 which worked flawlessly from a local-core install (I didn't want to download the packages from the internet - netinstall as I have a rubbish connection). After this install I had my arch installation up and running, command line only using the nouveau kernel module I do believe (The terminal was full screen, which isn't the case without nouveau, nvidia doesn't run it fullscreen either)

A few bits and pieces on config files:
Added net-profiles and net-cfg to start my wireless connection at boot up (init level 3) that way I wouldn't have to touch it when I launch X. I had to add a config file in /etc/network.d/ for netcfg to work, which was based on wireless-wpa in the examples folder, this was easy, added pricelan, the name of my netcfg profile to rc.conf in the NETWORKS=() section. Installed dbus and ntfs-3g, the latter I edited my fstab to automatically mount on startup. I had to add avahi-daemon to daemons in rc.conf for rhythmbox to start properly otherwise it would take ages to start up.

So now I wanted to setup my system, for the basics I Installed:
- Xorg & nvidia for a graphical interface
- Xmonad for window managing (wonderful!)
- Links to browse the internet from the command line so I could read the wiki as I installed xorg etc, highly recommended.
- Dmenu to launch programs in xmonad

Once I could launch X using the basic twm wm, I changed to xmonad, I did this by changing my ~/.xinitrc to launch xmonad, just placing 'xmonad' at the bottom of the file, nice and easy. When you launch X this time, you'll notice you just have a cross, press 'Alt-P' to launch d-menu and then some applications, 'man xmonad' has a good summary of the window tiling algorithm commands.

Now to install my essential applications:
- Chromium for web browsing
- Rhythmbox for music
- gnome-terminal
- Nautilus for file browsing

After installing these I couldn't get chromium to launch nautilus from the "Show in folder" dialog in downloads, I ammended this by installing 'perl-file-mimeinfo' which has the command 'mimeopen', it handles all the mimetypes so when you open files, it opens the proper program. After installing this chromium launched fine, however I had added the following lines to
~/.local/share/applications/defaults.list and ~/.local/share/applications/mimeapps.list
which may be needed, I don't know, I didn't try it without adding these lines.

Rhythmbox won't open .pls files in the radio section as some gnome services aren't running, I know it isn't gnome-settings-daemon, or obviously the keyring daemon. I'll have to look further into this to try and remedy the issue, I hope to find the right service to run rather than running xmonad ontop of gnome, I prefer xmonad neat, gnome3 is horrid. Anyway, I don't need a DE, WM will do me fine.

I'm still fiddling about with setting the wallpaper in xmonad, I'm using "xloadimage -onroot -fullscreen $path to image" at the moment which isn't stretching my 1980x1200 wallpapers to 1980x1080, A bit more exploration is required on my part to sort this out, once I have I'll be adding it to my ~/.xinitrc so when X starts my wallpaper will be set.

I have dipped my toes into xmonad configuration but the haskell syntax is a bit off-putting and I'm struggling with it at the moment but this holds your hand quite well and I'm currently going through it. The xmonad wiki is pretty handy as well, I think this will take a while to produce decent results though.

I'd finally like to say I only switched to arch based on it's philosophy and beautiful wiki.

P.s. man does jekyll look good...

Friday, 10 June 2011

The Blogs moved to wordpress!

I was a bit bored with blogger seeing as there are many limitations which I'd like to get rid of, so I've installed wordpress on some free hosting
Please tell me what you think, from an authors point of view, posting is now far more powerful and I can do lots more, e.g. use LaTeX to format equations, better support for embedding code etc. It makes my life easier.

I'm still in the process of sorting everything out, and moving the blog over, but it should be done pretty soon. I'll also be able to start blogging again quite soon (Exams are nearly over!)

Saturday, 14 May 2011

Boolean Logic in electronics

I stumbled across this great website in regards to basic electronics (for the AS Electronics course in the UK). Alas at the moment I don't have time to do much electronics or programming as I'm just about to start a month of exams, come the 20th June, I shall be back with hopefully some interesting posts!
See you then..

Tuesday, 10 May 2011


I just received a fountain pen through the post today. I was a bit put out due to it not being in any packaging and being loose in a jiffy bag, upon reflection it occurred to me, this is great - no waste, the pen survive fine, no damage at all. I then remembered when I bought some DIP sockets from rapid, they sent 1 tube (roughly 1cmx1cmx60cm) in a 1mx0.5mx0.2m and stuffed it full of paper, surely the could use tubes that they use to send posters in instead?! It's infuriating how much the electronics industry waste, I've seen a few posts on sparkfun's packaging, it looks quite minimalist yet sufficient for the job, why can't more suppliers be like this!
Rant over.

Friday, 6 May 2011

PCB etch tank

So I've got hold of some of the things I need, aquarium heater, bubbler and check valves, the chemicals are on there way and should be here soon, I'm looking forward to testing some things out. The immediate problem, being a student, I am somewhat poor and I have slightly broken my aquarium heater (more on that later in this post) so things progress slowly (I also have exams and should be focussing on them, but I'm not, because I like electronics more and I'm dedicated to my hobby...)

Here are a few pictures of the the parts:
From PCB etch tank
From PCB etch tank

I got the heater today, I thought "Great, this is exactly what I want" I even managed to slice the limit stopping you from turning the knob too far so I could reach higher temperatures (read: ~40 °C)

N.B. *Sigh* just looked at the cupric chloride guide:

Temperature (°C)040HCl fuming increases.
Etch speed increases. (see note 1)

Looks like I might not even need that heater... I think for the sake of simplicity and cost I shall eliminate it. Good, I feel like I have less things to limit my design now.

Coming back from my tangent, I had modded it and let it sit at ~45°C for a bit and went out for a run leaving it on, I came back to find it no longer working. I took it apart and found that the framework it was all attached to had melted and had pushed the magnet out stopping the lever from making contact with the contact. (best described with a picture)
From PCB etch tank
The lever on the bottom touches a contact when the blue knob is turned (this is how you set the temperature). When the temperature has reached a certain point, the lever expands and the magnet can no longer hold it touching the contact so it returns to the position in the picture breaking the circuit, I tried to remold the magnet hold and to some extent I had some sucess, I put it back in it's glass tube and turn it back on. *BANG* I have a nice set of sun spots and the breakers go; the heating element had shorted.

From PCB etch tank
From PCB etch tank

I took it all apart and tested all the components then fixed the heating element (shortening it due to a part blowing off it. I assumed the bulb had gone so took it out and replaced it with a jumper, it didn't work. After 30 minutes of troubleshooting I thought to check the fuse (I should have done this first) and low behold it had blown. After reassembling it this time I got a lovely red glow from the element so I'm assuming this is due to the loss of part of the element and the element's resistance has gone down.
From PCB etch tank
Because the circuit is setup as a potential divider the bulb was dimmer due to the lower resistance of the element & thus lower current through the bulb. The bulb is attached to a ~120k resistor which I think I'll replace with a lower value one to divert more current to the bulb and hopefully remedy the over powered element issue.
From PCB etch tank
My apologies if this is a little incoherent, It's getting a bit late here. Time for experiment 18 I think, I fancy some electronics to calm me down after such an eventful evening!

MAKE Electronics: Experiment 17: Emitting a tone (555)

This experiment sets the 555 up in astable mode (check out the previous post for an explanation). The 555 will emit pulses at a certain frequency which will drive the speaker. Changing the frequency of the pulses will then in turn change the frequency of the speaker's tone. To change the pulse frequency or rate, we adjust the external capacitor connected to pin 6, the threshold pin. (or the resistor between 6 & 7)
From MAKE: Electronics: Experiment 17 (555 in astable mode)
From MAKE: Electronics: Experiment 17 (555 in astable mode)

Here's the circuit, lets have a look at the schematic of the 555 in astable mode again:

So the THRESHOLD is connected to the TRIGGER, when the cap, C, is charged past 2/3 of the Vsupply the threshold is passed and the capacitor discharges through R2 into pin 7 (DISCHARGE) and a pulse is emitted from OUT. Once the cap has discharged and the IC is no longer triggered, the cap starts charging again, when it reaches 2/3 Vsupply it repeats the process, this results in a series of pulses, this is called a square wave oscillator, because it's producing a a series of square wave pulses. This is great for generating tones on speakers, flashing LEDs (albeit highly overkill!) etc.

Now we chain 2 chips together, both in astable mode, this produces a warbling tone.
The 555 on the left (IC2) is working in the same way as in part 1, however this time, a second 555 (IC1) is chained to the chip with it's output attached to pin 5 of the tone generator 555 (IC2). When IC1 produces a pulse it increases the voltage at pin 5 (2/3 Vsupply results in the chip emitting a pulse) so when IC1 emits a pulse and triggers the second chip to generate a pulse the capacitor attached to pin 5 of IC2 is less charged than it would have been if IC1 wasn't chained to IC2, this results in a higher pitch, because IC1 is oscillating far slower than IC2, IC2 isn't always triggered by a pulse from IC1 meaning it operates in its normal mode and produces a lower frequency tone.

This results in a warbling sound to be produced as some of the time IC2 is producing high frequency square waves (when IC1 is emitting a pulse) and some of the time IC2 is producing lower frequency square waves (when IC1 is not emitting a pulse)

(the video shows the circuit the other way round, sorry about that!)

There is a hell of a lot of info in this experiment so I think I'll spend some time playing around with the 555 trying to figure out how to get it to emit different pulses, an oscilloscope would be great to have around for this experiment!

Thursday, 5 May 2011

Custom etch tank: The start.

I've decided to have a bash at making an etch tank as I like making PCBs, however at the moment I've got no way to heat my etchant up and the whole affair is looking like a rather sorry state. After reading this instructable, I decided to build my own, I really like the etch tank design but would like to redesign it myself, purely for the practice in CAD and in-depth knowledge it will provide. I've bought an aquarium pump and heater to use in it and I will be using cupric chloride to etch.
I've found a wonderful website with a list of several materials and their resistances to specified chemicals, it's really invaluable to picking materials to use.
So far I have chosen a few materials:

Etch tank - Acrylic
Tubing - Ideally polypropylene (but I will settle for PVC) 1/4" ID (same as aquarium pump)
Fittings - Ideally polypropylene, but if PVC one are available I'd settle for them, they're expensive and hard to find.

It's a rather pitiful list but it's all I've decided on for the moment. I'm looking at buying chemicals, shipping is painfully expensive and I haven't really calculated how much I need to get, so that's on my to do list. It looks like higher concentration solutions of hydrogen peroxide cost the same as the lower concentration ones, obviously I'll go for the higher concentration as It's less to store, shipping will be cheaper and It's easy to dilute it.

I also need to get some methylene chloride for solvent welding acrylic, it's pretty cheap here, but I might buy it from ebay depending on delivery prices, this seller has most/all of the chemicals I need. Scratch that, the first seller mostly what I want at lower prices, excellent!
Hydrogen peroxide is the only thing that isn't stocked there, I thought I'd figure out how much I need, at 35% it's pretty concentrated, I used this handy calculator to find the concentration in mol/dm^3, so 500ml at 35% can be diluted to give 5 litres of 1.16mol/dm^3 looking at the equation on the cupric chloride link:
2H+ + Cu1+ + O{aq} → Cu2+ + H2O
This looks like it's probably going to be more than sufficient. Actually looking at the page again, it just occurred to me, I don't even need hydrogen peroxide after producing the etchant as I can regenerate the solution using air, I'm going to just get 250ml...
The acid gets used up so I'm buying a litre of that, the common mix to produce the starter etchant seems to be:
1 part HCl (35%)
2 parts H2O2 (3%)

Just bought:
1 Litre HCl
1 Litre Acetone
1 Litre methylene chloride
1 kg NaOH (just in case I want to do titration and analyze my etchant)
£9.50 for delivery
£11.50 for the chemicals

Now I can whip up some etchant, have a play around with it and see whether the check valves I've bought are or are not made from polycarbonate... hopefully they'll be OK.

On a side note: I've picked up a laser printer (from freecycle!) which I may play around modding to print on circuit boards. However, it looks like a fairly complicated endeavour which currently I'm not sure I need to embark on, one for the future perhaps.

Sunday, 1 May 2011

Learning Processing Chapter 5.6

Just a short post today, lots of work to get on with.
This little segment teaches you how to program a button in processing, a basic of UI design.
Boolean variables are either true or false, nothing in between.

mousePressed is a boolean variable, it is true when a mouse button is pressed and false when they are not. We use this in the button example, this is an emulation of a light switch in a dark room, when you press the switch the light comes on, when you let go, the light goes off and the room goes dark. This is implemented using similar code to the roll-over example:

 // Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 5-4: Hold down the button
boolean button = false;

int x = 50;
int y = 50;
int w = 100;
int h = 75;

void setup() {

void draw() {
// The button is pressed if (mouseX,mouseY) is inside the rectangle and mousePressed is true.
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h && mousePressed) {
button = true;
} else {
button = false;

if (button) {
} else {


(Taken from the learning processing site, all credit to Daniel Shiffman)

This code is fairly self-explanatory after the rollover exercises, the only thing I am a little unsure about it is this line:
if (button) {
I assume that (button) is the same as writing (button == true)
looking on this link it appears so, and (!button) would be the same as writing (button == false).

The next step on is to implement a switch feature so that when the button is pressed, it latches and stays on until you click it again. This makes use of putting code in the mousePressed function.
 void mousePressed() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h && mousePressed) {
button = !button;
We just add this to the end of the code and get rid of the first conditional in the draw() loop as it is no longer needed.

Shiffman's Code:
 // Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 5-5: Button as switch
boolean button = false;

int x = 50;
int y = 50;
int w = 100;
int h = 75;

void setup() {

void draw() {
if (button) {
} else {


// When the mouse is pressed, the state of the button is toggled.
// Try moving this code to draw() like in the rollover example. What goes wrong?
void mousePressed() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
button = !button;

So this time, when the mouse is pressed inside the rectangle, button is set to set to the opposite of what it was, if it was true then it would become false and vica versa.
I had to think about this for a bit to understand how it works, Draw is continually looping looking at button's value (true or false).The 'mousePressed' code is only initiated when (as you already knew) the button is pressed, (let's say the original value was false) clicking inside the rectangle changes the code to the opposite of what it was, so, it becomes true. Draw() loops and reads that button == true from the line "if(button) {" and then changes the background colour and stroke colour accordingly.

Here's what it produces:
(Taken from the learning processing site, all credit to Daniel Shiffman)

Wednesday, 27 April 2011

Learning Processing: Chapter 5.4-5.5

So, what on earth are "logical operators", wikipedia defines them as "A symbol or word used to connect to or more sentences in a grammatically valid way".
Not that I really understand that, for things I don't understand, I find it massively helpful to apply the mathematical paradigm of abstraction, instead of comprehending the (I'm pretty sure it's used in other fields as well, but this is where I first came upon it, just a warning to the pedants!).

So what properties do logical operators have, there are 3:

NOT - !
AND - &&
OR - ||

NOT is used to invert a boolean expression, so if we asked the question "Is the sky blue", NOT would return "false" thus having inverted "true"

AND is used to compare two boolean expressions and only return "true" if both of the 2 expressions are satisfied. For example if we were to ask the question "is the sky blue AND is the sea blue" processing would return "true" if we asked "is the sky blue AND the sea orange" processing would return "false", although one of the expressions is true, the other is false, AND only returns true when both expressions are true.

OR is like AND, however only one of the expressions has to be true to for it to return 'true', for example "is the sky blue OR is the sea orange", this returns 'true' because the first expression is true, even though the second is false.

Looking at what I've just written, that is an incredibly lengthy explanation for such simple concepts, I blame this on wikipedias overly wordy explanation of a 'logical operator' and it being quite late... now with the explanations dispensed, time to document the chapter.

In 5.4 we write a simple program to change a rectangles colour when the mouse is over it. I expanded on this code a bit and implemented a multiple rollover, when the mouse is not on the rectangle, the background is black and the rectangle white. When the mouse is on the rectangle, the background is white and the rectangle black. Hopefully the code is commented well enough for most people to understand!

 /* logical operators in use in a simple sketch, && is AND
|| is OR */

void setup() {
size(200,200); //200x200 canvas
smooth(); //set anti-aliasing

void draw() {
background(255); //set backgroudn white
if (mouseX > width/2 && mouseY > width/2) { //if mouse X coord is on the right AND the mouse Y coord is on the bottom half of the canvas
fill(0); //fill rect with black
rect(width/2,height/2,width/2,height/2); //draw rect at bottom right
else if (mouseX < width/2 || mouseY < height/2) { //else if the mouse X coord is less than half of the width OR the mouse Y coord is above the middle of the canvas
background(0); //fill background with black
fill(255); //fill rectangle with white
rect(width/2,height/2,width/2,height/2); //draw rect at bottom right

In 5.5 we learn to implement 'multiple rollovers' Shiffman has provided some pseudocode of his next example, however I decided to implement it myself before going ahead and reading his example, as usual my code is cruder, less well written and much harder to mod, but I'm proud of it, it accomplishes the same thing as Shiffman's code.


int w = 200; //width of canvas
int h = 200; //height of canvas
int c1 = 255; //colour1 = white
int c2 = 255; //colour2 = white
int c3 = 255; //colour3 = white
int c4 =255; //colour4 = white

void setup() {
size (w,h); //set canvas size
smooth(); //anti-aliasing

void draw() {
if (mouseX < width/2 && mouseY < height/2) {
c1 = 0;
c2 = 255;
c3 = 255;
c4 = 255;

} else if (mouseX < width/2 && mouseY > height/2){
c1 = 255;
c2 = 255;
c3 = 0;
c4 = 255;

} else if (mouseX > width/2 && mouseY < height/2) {
c1 = 255;
c2 = 0;
c3 = 255;
c4 = 255;

} else if (mouseX > width/2 && mouseY > height/2) {
c1 = 255;
c2 = 255;
c3 = 255;
c4 = 0;

background(255); //set white background

println("X = " + mouseX + " Y = " + mouseY);

 // Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 5-3: Rollovers
void setup() {

void draw() {

// Fill a black color

// Depending on the mouse location, a different rectangle is displayed.
if (mouseX < 100 && mouseY < 100) {
} else if (mouseX > 100 && mouseY < 100) {
} else if (mouseX < 100 && mouseY > 100) {
} else if (mouseX > 100 && mouseY > 100) {

Right, I think that's it for tonight...

Monday, 25 April 2011

Learning Processing: Chapter 5.1 - 5.3

So today I taught myself to use conditionals (haven't finished the chapter yet!). Boolean expressions are the foundation of conditionals, a boolean expression is a true/false question, these are the only types of questions computers can answer. An example of a boolean expression:
"15 > 20 false"
In processing there are 3 types of conditionals:

- if statements
e.g. "If x>y do something"

- else statements
e.g. "If x>y (do something), else (do this instead)"

- else if statements
e.g. "If x>y (do something), else if (do this instead), else (quit)"

You can only ever have 1 else and 1 if in a sketch,

Ex 5.1:
(check this out on the open processing website, it needs to be run multiple times to give different background colours and prints stuff in the command line, maybe just DL the code and paste it in processing and run it)

Ex 5.2 gave me a bit of trouble, I couldn't figure out what was wrong in the code on the 2nd problem. I didn't spot two if statements were used vs. 1 if and 1 else (which is what the second column of code uses).

Shiffman's website is pretty great, It's really handy to be able to check out whether you are wrong or right and you can just paste the code if you can't be bothered to write it out (which I don't usually do, I usually think about whats happening when I type it in, tonight I couldn't be bothered though!)


The first part of chapter 5.3 gives you some pseudo code, I wanted to test my coding skills so before turning the page I implemented the steps into code to see how my code compared to Shiffman's.

My Code:
 //set values and types of variable of RGB.

float r = mouseX;
float g = 100;
float b = 150;

// set window size and enable anti-aliasing
void setup() {

//start loop
void draw() {

if (r > 255) { //if 'r' is bigger than 255 set it to 255 (i.e. limit it)
r = 255;
else if(r < 0) { //if 'r' is smaller than 0 set it to 0 (limit it)
r = 0;
else {
println("r = " + r); //print line to debug to make sure 0<r<255

if (mouseX <= 100) { //if mouseX is on the left increase 'r' value by 5
r = r + 5;
else if (mouseX > 100) { // if mouseX is on the right decrease 'r' value by 5
r = r - 5;

// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 5-1: Conditionals

// Variables
float r = 150;
float g = 0;
float b = 0;

void setup() {

void draw() {
// Draw stuff

// If the mouse is on the right side of the screen is equivalent to
// "if mouseX is greater than width divided by 2."
if(mouseX > width/2) {
r = r + 1;
} else {
r = r - 1;

// If r is greater than 255, set it back to 255.
// If r is less than 0, set it back to 0.
if (r > 255) {
r = 255;
} else if (r < 0) {
r = 0;

Arghh! And then after all that we learn there is a function named "constrain()" which does this all for you e.g. r = constrain(r,0,255);
That would have been far easier, but it's nice to know I understand the concept of how to implement constraints without a specialised function.

Example 5.2 improves upon this last sketch by changing r,g and b. It also makes use of the constrain() function.

// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 5-2: More conditionals

// Three variables for the background color.
float r = 0;
float b = 0;
float g = 0;

void setup() {

void draw() {
// Color the background and draw lines to divide the window in quadrants.

// If the mouse is on the right hand side of the window, increase red.
// Otherwise, it is on the left hand side and decrease red.
if (mouseX > width/2) {
r = r + 1;
} else {
r = r - 1;

// If the mouse is on the bottom of the window, increase blue.
// Otherwise, it is on the top and decrease blue.
if (mouseY > height/2) {
b = b + 1;
} else {
b = b - 1;

// If the mouse is pressed (using the system variable mousePressed)
if (mousePressed) {
g = g + 1;
} else {
g = g - 1;

// Constrain all color values to between 0 and 255.
r = constrain(r,0,255);
g = constrain(g,0,255);
b = constrain(b,0,255);

In 5.4 I'll learn about Logical operator (AND, OR, NOT) which looks quite interesting and should hopefully be transferable to logic circuits when I get to them in MAKE: Electronics. This was quite a quite a long chapter so far, it's been hard but rewarding. I'm glad I've tried to implement the examples myself before looking at the code, it makes sure I understand the principles even if it is tough going!

MAKE: Electronics: Experiment 16: 555 timer


So, we finally get to play with some ICs now! I feel I have quite a good understanding of the basic components now, so in the coming weeks I shall have a go making some circuits up using transistors etc.

The 555 timer is perhaps the most ubiquitous IC on the planet, it is estimated that 1 billion per year are still produced, it has 3 modes:

- Monostable mode - This means that when the IC is triggered it produces one pulse, it can be used to trigger other ICs. A square waveform pulse is produced.

- Astable mode - This means that when triggered the IC acts as an oscillator, it is not stable, hence the astable name. This
is useful for flashing LEDs, producing tones on speakers etc. A square waveform is produced.

- Bistable mode - When triggered the IC acts as a flip flop, this is useful to remove the bounce (http://www.elexp.com/t_bounc.htm) from a switch. I don't really know much about flips flops, but I guess later on in the book when logic will have been covered I'll have a greater understanding of the concept.

(refer to the top diagram)
1 - (GND) Connected to GROUND
2 - (TRIG) Trigger, pull low when you want to trigger the chip (1/3 of Vs)
3 - (OUT) The pulses are delivered here (+V)
4 - (RESET) Pull low when you want to reset the chip
5 - (CTRL) Control, access to the internal voltage divider to change the threshold voltage (default > 2/3 Vs) which pulls pin 3 low (0V)
6 - (THR) Threshold, when pulled high (2/3 Vs) it sets pin 3 to 0V
7 - (DIS) Discharge, when a pulse is initiated, the capacitor attached to this pin discharges through it to ground, this is the timing capacitor, hence the larger the value, the longer it takes to discharge and the longer the pulse
8 - (Vcc) Positive supply voltage, from 3 - 15V

The Circuit : Monostable mode
This experiment uses the 555 timer in 'monostable' mode, when we trigger the chip, it will emit a pulse of a length determined by the capacitor attached to pin 6, the larger the capacitance, the longer the length of the pulse.

The circuit is wired up so when a button is pressed, it pulls pin 2 low, triggering the IC, a pulse is delivered on pin 3 thus powering the LED in the circuit. A potentiometer is connected in between the switch (connected to the trigger) and ground, by varying this pot, the pin is pulled to differing voltages, only if the pin is pulled below 1/3 of the supply voltage will the IC be triggered.

I plan on playing a bit with this chip and documenting my experiences further, I'm getting quite a good idea of how to use it.

Friday, 22 April 2011

MAKE: Electronics: Experiment 15 (Burglar Alarm)


(this video is showing how the relay is wired up, once the sensor circuit is broken (open) the relay energises, when the sensor circuit is closed, the relay stays energised)

Part 1: Stripboard Layout:
This experiment calls for a protoboard in the same layout of a breadboard, which does seem a great way to introduce beginners to transferring projects from solderless breadboard to permanent perfboard. However I found this nigh on impossible to find in the UK. I settled using a perfboard and arranging the layout in a somewhat similar manner to a breadboard.
The picture shows the top side and under side of the board, I have mirrored the photograph so the top right of the up side = the top right of the under side, basically, you can overlay the pictures over each other as they correspond (I'm not really sure how to say this more clearly!)

From MAKE Electronics: Experiment 15: Burglar Alarm

At the top of the board is the alarm circuit created back in experiment 11. At the bottom is a circuit that when triggered by an opening in the sensor circuit (i.e. opening a door) turns power on to the alarm circuit. If the sensor circuit is then closed again (door closed) power is still supplied to the alarm so it does not turn off. This is explained exceptionally well in the book however I think I only truly appreciated how the circuit worked when making my own (far less elegant) arrangement on a breadboard to see how it all worked from the schematic diagram.

I soldered everything on the stripboard first, then I took a dremel to it with a cutting wheel and trimmed it down and then sanded the sides, it fits in just between the slots in the project box so I don't have to screw it down (very convenient!).

Part 2: Project Box
The point of this experiment is to show how one goes from a fairly minimalist circuit on the breadboard to a fully-fledged project. This requires casing to maintain the longevity of the project and also somewhere to mount a user interface. The UI for this project is fairly simple, it consists of:
(i) An Arming button - arms the alarm (and lights green LED to indicate the alarm is armed)
(ii) A Test button - (un-armed) lights up LED when sensor circuit is close, (armed) tests alarm circuit/speaker
I added some banana plugs to my magnetic sensor, I currently don't have anywhere to put it, Platt says later in the book that I'll learn how to integrate an 'away from home' feature and add a keypad to it (Hopefully I can figure out how to use a matrix keypad instead of a common pin type keypad) So I might get round to using it pending on how well it turns out. When activated the alarm isn't exactly loud so I will build an amplifier circuit at some point (I tried driving it with an old amp and it goes fairly loud for its size, it can certainly be ear piercing)

Thursday, 21 April 2011

Why I hate textbooks

Just a quick reflection for now before I post about my new burglar alarm (courtesy of experiment 15 in MAKE: Electronics). One thing that I continually keep on doing is buying textbooks, putting them in my cupboard to read when the time comes that I need to seek help - however, I never do end up looking at them, I have the internet, with interactive information; videos, exercises all in one place, If I don't understand a term I'll look it up on wikipedia. Why do I continue to irrationally buy these textbooks when I know I have a very low chance of ever reading them? I like to think it's because once I've spent that amount of cash on a book, it will be presented exactly how I would like it to be, easily digestible, easily understood. It's almost as if when I buy it I expect to know the contents of it once owning it, sadly not the truth. I'm becoming more and more reliant on internet resources nowadays, Kahn Academy is playing a big role in my education now, well sorted, comprehensive videos on what I need to learn for college and more all in an easily accessible place, just a button click a way. I'm going to try and refrain from buying more textbooks, spending time looking for them and reading reviews, I'm going to try and find more online resources. I like that they're free (the majority) therefore I can't "own" it per-say which results in me putting time and effort in learning the content vs. "owning" it and assuming I can learn it when the time comes around.

Sunday, 17 April 2011

Learning Processing: Chapter 4

CHAPTER 4: Variables

Chapter 4 is the start of 'Lesson 2' focussing on the rest of the basics of programming: variables, conditionals and loops.

A variable is a pointer to a location in the computers memory where a value is stored. This value can vary hence the name. The chapter introduces the different types of variables; int, float, boolean, char, byte, short, long and double. Each should be used in a different circumstance depending on the need, the book explains where to use each one clearly and concisely. Variables can be named, and addressed in a sketch. for example mouseX is an integer storing the mouses X-coordinate - this is a system-wide variable, one already established in processing, these are mainly commonly used variables (e.g. frameCount) and so have been built into the language.

The exercise for using system variables gets you to create a little picture out of basic geometry that will scale itself accordingly when you change the size of the window. I thought that the large square was itself a square and not the bounds of the size therefore my code is somewhat different to the code posted on Shiffmans website as I shall ellaborate on.

Shiffman's Code:

is another function you learn how to use in this chapter. It focusses on using it in variables to create movement (e.g. Zoog the alien moving from side to side). The syntax is as follows random(low value bound,high value bound) - It's pretty easy to start implementing random values into your sketches after learning the basics.

Thursday, 14 April 2011

MAKE: Electronics: Experiment 14

This project takes your new found knowledge of soldering, breadboarding and PUTs to make a pulsing LED mounted on stripboard. I found this fairly easy, but it was a good practice of translating schematic to stripboard, the book does have a diagram of how the components should be arranged; but you can try and convert it yourself first before doing this - it is good practice!

The way the circuit works is that the capacitor connected to the anode charges, when it reaches a voltage high enough to pass through the gate the capacitor discharges passing current to the LED, the capacitor discharges resulting in the LED fading from bright to dim. However unlike the last LED oscillating circuit in the book there is a capacitor attached to the LED provide it with current, so it doesn't flash on and off, as instead of turning off the LED is provided with enough current to be lit dimly this creates a 'pulsing glow' as Platt puts it.

From MAKE Electronics: Videos

Wednesday, 13 April 2011

MAKE: Electronics: Experiment 13


This experiment demonstrates how heat affects components - in particular, the LED. One heats the LED with a soldering iron for a while with a copper aligator clip (which diverts heat from the LED, thus preventing it from damage). After you remove it and just use the soldering iron on its own, it's luminosity slowly decreases in intensity for a period of time before it burns out due to excessive heat.
OK, I have a little confession to make, I failed this experiment, the LED only got slightly dim after 5 minutes of my soldering iron at 450°C so I gave up!

The stop watch indicates how long the iron had been applied to the LED and the iron station shows the temperature the iron was at.

Learning Processing: Chapter 3

Chapter 3: 'Interaction'

Chapter 3 covers the 'flow' of a program; what setup() and draw() do and how to use them, mouse interaction, dynamic sketches and finally handling events (mouse clicks and key presses).

I've learnt that setup() is run only once when the sketch is run, it sets the 'initialization code' as Shiffman puts it. After setup(), draw() is run, this runs, then loops back to the start of the code:

void setup() {
//setup code

void draw() {
//code which loops

The { } host a 'block of code' allowing one to manage code as an individual part of a program.

mouseX - the current mouse x-coordinate
mouseY - the current mouse y-coordinate
pmouseX - the mouse x-coordinate in the previous run through draw()
pmouseY - the mouse y-coordinate in the previous run through draw()
void mousePressed() - function that runs code when a mouse button is pressed
void keyPressed() - function that runs code when a key on the keyboard is pressed

I feel I have a good understanding of all the above, I am starting to realise how one goes about programming and how hard it will be in future implementing features, it shall definitely improve my logic, something I have been looking forward to doing, it's not very often we get stretched in school!

This chapter completes 'Lesson 1' which covers the beginning of learning to program in processing. The end of lesson project is to create a dynamic sketch by interaction of the mouse and a static drawing. I have drawn a few things and added dynamics to them, currently I can't figure out how to export programs that actually display in webpages out, once I figure that out, they will be posted here.

Learning Processing: Chapter 2

Chapter 2 focusses on the topic of 'Processing':
- How to get the IDE
- Introducing the 'sketchbook'
- Interface
- The processing reference

Essentially it is quite a dull chapter if you have already used the Processing IDE before but to those new to it, it will prove a nice introduction as to how to use the IDE and the reference.

One problem I have found is with 'publishing' my programs, when I export them, and I have a folder containing the code and index.html, when I open index.html I don't see my program, the layout is how it should be but just a box where my program should display. I'm not sure what is causing this problem so I may have a browse on the processing forums to try and find a remedy to this problem!

Monday, 11 April 2011

Learning Processing: Chapter 1

I've picked up another book to delve into, I've always wanted to learn to program, 'Processing' seemed the logical choice Arduino (the programming language) is based on processing so I shall get a better understanding of syntax and how programs are written including the logic behind how they are structured (I've always been fascinated by this), thus giving me a step up when I go back to microcontrollers (after finishing this & Make: Electronics).

The book is called "Learning Processing" by Daniel Shiffman

A few things drew me to this book, I like how it really takes you from not knowing a thing about programming, to a decent foundation. I think it is very important to learn the theory so when it comes to learning different languages you still have a thorough understanding of the paradigm but you only have to pick up the new aspects of the language.

Processing is a language based on visual interaction vs text-based interaction. A program is written with text, displayed using visual then can be interacted with via mouse clicks (amongst other devices). Text-based languages operate by being written in text, producing text and then being interacted with by more text. Enough rambling, onto the first chapter...

CHAPTER 1: Pixels
This chapter focuses on 'Pixels', it describes how to draw some basic euclidean shapes (e.g. lines, circles and triangles etc), colour theory (grayscale, RGB, transparency) - that's about it. The book introduces different exercises to have a bash at to make sure you understand and can implement the theory - I personally find this the strong point on the book so far (Yes, I am only on chapter 2 at the moment!)

I've learnt that the grid the computer draws is different to the "Cartesian coordinate system" (The one you use in mathematics at school). The x-axis is drawn from left to right (lower -> higher value. This is the same as in the 'normal' graph system) however the y-axis is drawn from top to bottom, as you go down the y-value increases (not negatively).
I also have learnt how to draw - Rectangles, ellipses, triangles, lines and points, I know how to change line thickness, set the outline to be a different colour, set the inside to be a different colour etc. I don't quite understand how the colour mixing RGB system works yet, the mixing works like mixing lights; I've never really understood how that works thus I will check out a few tuts later on this week on the subject.

At the end of the chapter you have to draw your own 'character' in processing, mine is fairly appalling compared to Shiffman's but it is original and I feel proud to have accomplished something.

I tried to upload the code to openprocessing but it isn't displaying - not too sure why..
Here is the code.

Thursday, 7 April 2011

MAKE Electronics: Experiment 12

Joining 2 wires together:

I have already soldered quite a bit prior to this so it was more a chance to hone my skills than learning anything new, however I had never soldered low gauge wire, so this was a new experience for me, larger diameters do need more power and my Weller could just about handle the wire in the power chord, I'm not sure how I'd feel about using a 'soldering gun' they look rather unwieldy, I do have a low quality Weller hobby one in the garage which I might have a bash using at some point in the future.

The first 2 solder joints, the first joint joined the wires across each other in an 'x' shape, this went well. The second joint joined the wires parallel to each other, again, this proved to be successful, I heat shrinked the wires and was fairly happy with my hand work.

Next I chopped up a long power chord and made it much shorter, I joined each individual wire and heat shrinked all 3 individually, then used some electrical tape on the outside of this as I didn't have a larger enough diameter of heat shrink to use for this purpose. I tested this cable out on my soldering iron, it worked flawlessly, I was somewhat hesitant as I thought I might end up tripping the breakers with a short circuit - this did not happen fortunately!

Thursday, 31 March 2011

MAKE Electronics: Experiment 11

This is quite a long experiment so I will be writing it in steps.

Step 1: Flashing LED with a PUT:
A PUT, Programmable Unijunction Transistor is similar in function to a normal transistor in the sense that it acts as a switch. When voltage is applied to the anode it either is blocked or allowed to flow depending on the value that the gate is set at. The voltage at the gate determines how high the voltage at the anode has to be for current to flow.

The first part of the circuit is setup to explain this theory. The 2 resistors at the gate determine the voltage at the gate (and thus the voltage barrier at the anode). A resistor at the anode protects the PUT from excess current. When the circuit is set up, the capacitor attached to the anode charges and thus the voltage increases until it reaches the voltage set by the gate and current flows through and lights the LED between the cathode and ground.

Step 2: Making a metronome with a speaker:
This is very much the same circuit as above however the LED is replaced with a speaker, there is a resistor in series with the speaker, I assume this is to protect the speaker or to stop it from distorting. The sound is only faintly audible because of the very low current. A metronome can be produced by using a capacitor with a larger capacitance, this slows the oscillating of the speaker, whereas using a lower capacitance results in a faster oscillation. In this circuit a 0.0047 uf capacitor is used, therefore the speaker oscillates fairly frequently.

Step 3: Adding an amplifier:
In this step, a 2N222 transistor is added to amplify the current to the speaker so it makes a more audible tone. The collector of the transistor is protected by a resistor, the output of the PUT (cathode) is attached to the base of the transistor and then the speaker is put in series with the emitter and ground.
When the current flows through the PUT it reaches the base of the transistor which switches the current from the collector to the emitter. Because more current is flowing through the speaker it sounds louder.

Step 4: Adding another amplifier:
To give the speaker one final boost we add another 2N222, this time the speaker is hooked up between the positive voltage rail and anode, I assume it could also be placed in between the emitter and ground, the speaker only operates when the switch is open/the transistor is oscillating.

From MAKE Electronics: Videos
(at first the speaker is only going through 1 transistor, the second time it is being driven by 2, for some reason it is not much louder but at a slightly different pitch, I do not understand why this is!)

Step 5: Adding step 1 (the slow oscillator) to the fast oscillator driving the speaker:
The output from the cathode of the PUT in the top circuit is joined to the gate of the PUT driving the speaker, I assume this varies the gate voltage which means that when the PUT in the top circuit is passing current, the the capacitor in the speaker PUT circuit takes less time to charge and therefore the speaker oscillates more quickly, thus producing a higher tone, then when the slow oscillating PUT is not passing current the capacitor charges slower (as it is having to reach a higher voltage) in the speaker circuit producing a lower tone in the speaker.

Tuesday, 29 March 2011

ATX Bench-top Power Supply

I made this on the weekend. It's a converted ATX PSU, I cut the cables off and added binding posts to use as a bench-top power supply, I could have simply bought one of those cheap ones on ebay from china for ~£40 however I had this lying about and it cost me about £6 in parts.
First I took apart the PSU and took the PCB out after marking the top heights of the components on the case so I could figure out how to arrange the binding posts & fuses. I then drilled and sanded the holes (time to buy a hand reamer).

The wires colours correspond to the voltages:

Yellow - 12V
Yellow/Black - -12V
Orange - 3.3V
Red - 5V
Black - ground

I desoldered a bunch of these which I didn't need clogging up the case, and then cut the others down to a reasonable length and heat-shrinked them (so far no shorts). I then soldered the leads corresponding to the voltages I wanted; 3.3V, 5V, 12V and ground to their corresponding fuse holders and then from the fuse holder I soldered wire with crimped connectors on the end (to be used with the binding posts), hooked them up and voila, all I had left to do was to attach a switch from ground to the thin green wire which turns the power supply on and off when it is plugged in.

I mounted the fan the other way around as the binding post obstructed it from being in it's original position, I also put the fan guard on underneath as I didn't want the fan and the wires to hit each other. I used 5A quick blow fuses as these things can output ~20A and I'd rather not see my projects go up in flames if I can help it.

If you're looking for a 'how-to' vs. an 'account' I suggest looking at these links, which I used when making this power supply, I see no need to saturate the web with another set of instructions!

http://letsmakerobots.com/node/1355 (I'd like to note I do not use a load resistor, I didn't buy one and the supply seems to function ok without it)

One final note, if you do undertake this project, be very careful of the power caps inside, I left my supply off for a week before touching it, I'd rather be on the safe side!

Sunday, 27 March 2011

MAKE: Electronics: Project 7 - 10

I have been working through the book "Make: Electronics" By Charles Platt. I have been inspired to document my progress by James Floyd Kelly's blog regarding the book, It has been invaluable when carrying out the projects, check it out here - "http://handsonelectronics.blogspot.com/" I like the idea of documenting your troubles and how you overcome them, it seems most people just document their success rather than failure, I think the latter is far more important when it comes to learning.

I've written a bit about project 7 - 10 on Xournal and uploaded the PDFs to Google Docs so people can have a look at what I learnt, I find writing down what I did right/wrong helps me understand the circuits and theory better and improves my retention of the content.

Project 7 & 8:

Hello All

Hello everyone,
I am hoping to document some of the more interesting aspects of my life on this blog, probably ranging from interesting science articles to electronics projects. I want to improve my ability to describe things as currently I find that I'm hindered by my lack of ability to be concise in what I am saying, this should be a good exercise in improving my writing skills!