Monday 31 March 2014

Arduino UNO Tutorial Lessons – 1 to 3

OK, so I’ve gone through the first three tutorials and had a bit of a play with the UNO. It’s pretty easy for the first three lessons … and I anticipate that the remaining lessons will be similarly easy.

Lesson 1 – Blink..

Here we are hooking up the UNO to a 470 ohm resistor and LED and passing HIGH/LOW instructions to pin 13 through native functional loop.

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
  This example code is in the public domain.
*/
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);    
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1500);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1500);               // wait for a second
}

The code is pretty simple. Initialise the variable “led” as an integer and assign the value 13. This is the pin-out on the UNO that we connect the LED to.

setup then sets the pinMode of led (13) to be OUTPUT … that is, to receive signals.

The loop function sends a HIGH instruction to pin 13, waits 1500 milliseconds (1 and a half seconds) and then sends a LOW instruction to pin 13, waits another 1500 milliseconds and repeats.

Lesson 2 – Light Chaser

The breadboard is populated with 8 LED and 8 470 ohm resistors. The LED are connected to pins 6 through to 13 on the UNO and the ground rail of the breadboard is connected to the GND pin of the UNO.

The sketch simply creates an array containing the pin locations of each of the LED to be turned on and off in sequence within a for loop. Initially, the array contains each LED once and two for loops drive the sequence, one incrementing the pin, the second decrementing the pin.

The final version of the sketch has the array containing the entire increment/decrement sequence and a single for loop that does the driving.

int ledCount = 15;
int ledPins[] = {6, 7, 8, 9, 10, 11, 12, 13, 12, 11, 10, 9, 8, 7};
int ledDelay = 75;

void setup() {
  for(int thisLed = 0; thisLed < ledCount; thisLed++){
    pinMode(ledPins[thisLed], OUTPUT);
  }
}

void loop() {
  for (int thisLed = 0; thisLed < ledCount; thisLed++){
    digitalWrite(ledPins[thisLed], HIGH);
    delay(ledDelay);
    digitalWrite(ledPins[thisLed],LOW);
  }
  /*
  for (int thisLed = ledCount-1; thisLed > 0; thisLed--){
    digitalWrite(ledPins[thisLed], HIGH);
    delay(ledDelay);
    digitalWrite(ledPins[thisLed],LOW);
  }*/
}

Lesson 3 – Momentary Switch

Lesson 3 adds a momentary switch with a 10k ohm resistor into the breadboard and some instructions in the sketch to handle the button press.

int ledCount = 14;
int ledPins[] = {6, 7, 8, 9, 10, 11, 12, 13, 12, 11, 10, 9, 8, 7};
int ledDelay = 75;
int buttonPin = 2;

void setup() {
  for(int thisLed = 0; thisLed < ledCount; thisLed++){
    pinMode(ledPins[thisLed], OUTPUT);
  }
  pinMode(buttonPin, INPUT);
}

void loop() {
  for (int thisLed = 0; thisLed < ledCount; thisLed++){
    digitalWrite(ledPins[thisLed], HIGH);
    while(digitalRead(buttonPin) == HIGH) {
      delay(10);
    }
    delay(ledDelay);
    digitalWrite(ledPins[thisLed],LOW);
  }
  /*
  for (int thisLed = ledCount-1; thisLed > 0; thisLed--){
    digitalWrite(ledPins[thisLed], HIGH);
    delay(ledDelay);
    digitalWrite(ledPins[thisLed],LOW);
  }*/
}

Arduino Uno Clone – Freetronics 11

I have gone out and bought myself a Freetronics 11 kit from Jaycar (for the princely sum of just shy of $90AUD). I realise that this is a fairly high price for the Arduino with  a couple of peripherals, but I wanted to get something from a bricks and mortar store where I could get some support if needed. I’ve also just bought another clone from eBay for $10 with no peripheral bits and pieces … so I figure that I’m still doing OK.

Picture 26

The offering from Jaycar comes with some digital and analog input devices, some LED, diodes, resistors and jumper wires (and a little solderless breadboard) all of which I could have bought individually for much less … but there you go.

The first adventure was getting the device to be recognised on my 64 bit WIndows Home Premium machine. That was a little tedious, but when I downloaded the updated USB driver from Freetronics, I was up and running.

As the chip comes pre-loaded with the blink sketch, I made some small modifications, compiled and uploaded to the UNO and, presto … it worked.

Now, I’m reasonably familiar with programming, although I don’t have much experience with C++, but the structures and operators are all fairly consistent with what I know. I’m going to jump right in and do all of the tutorial builds to give me a refresher and some added experience with the UNO.

By the way, from here on, I’m going to refer to the development board as “the UNO” for simplicity sake. I’m not going to make any distinction between the “eleven”, the clone from top_electronics_au or any later clone purchases. The platform is open source … so I’m going to use the generic name.

There are a host of sites that offer, more or less, the same tutorials. When I post my results and comments about any of the tutorial projects, I’ll try to give a link to the tutorial where it is relevant.

As I mentioned in the previous article about my thinking and research into the UNO, there seem to be two schools of though about the application of the development board. On the one hand, there is the “build it on the development board and deploy it on the development board” camp and the “develop on the development board and deploy it on your own circuit” (I favour the latter camp, personally, but I don’t think that there is much value in arguing either side … so I wont. Do what you want! Me, I like the idea of building a circuit that is purpose made without any redundancy … but that also means that what I build won’t necessarily be extensible.

On with the show!

Tuesday 25 March 2014

Arduino Thinking

This is a new thread under the overarching Electronics thread.

I’ve been thinking about moving into the realms of microprocessors and I’ve had a look at a bunch of websites discussing a myriad of different microprocessor types and platforms.

The attractive thing about the Arduino platform is that it appears to be (more or less) all in one package. The microprocessor, PC interface and programmer all in one convenient package. This is compared with the alternatives of having a separate interface, separate programmer, etc.

One of my core philosophies is that it is more important to make a decision, rather than sweat on making the “right” decision. If you are wrong, then the wrong decision helps to inform your next decision. The complementary idea here is to not get too invested in being right, but, rather, accept that being wrong is part of the path to being right. Besides, it is much better than being paralysed by inaction. Whichever way it pans out, I’m falling down on the Arduino side of the argument.

One of the problems that I’ve had with the Arduino platform is that many of the projects that I’ve seen appear to be simply about plugging your Uno (or Due) into your project directly. That seems OK if all you are doing is making something that is going to be open and exposed. That kinda looks a bit inflexible.

So I read on more … It seems that the Arduino platform (and programming IDE) are open source. That means that I have more flexibility and I don’t have to use the Uno, or indeed any other 3rd party packages. My real limit here is the use of the microprocessor and a handful of parts to make it work (5 volt regulator circuit, 3.3 volt regulator circuit, 16MHz oscillator …). If I buy the base kit, then I have the development/prototyping hardware that I need to get me going. It would only be the supporting circuitry for the microprocessor and the microprocessor itself that I would “consume” in my project. At the moment, it looks like I can get the core chip for about $4.00 on the interweb.

I also found this tutorial on the Arduino website that describes how to eliminate the Arduino breadboard from your project (Arduino to Breadboard). So there are some instructions available for going “commando”.

I should then be able to program the microprocessor and drop it into a project without the Arduino periphery (although, obviously, I still need the supporting circuitry of the microprocessor). That seems to satisfy my basic needs for size and cost.

I will probably buy the basic Arduino kit and do the tutorial solderless projects in the box to give me some confidence in the platform and to learn more about the Arduino.

One of my basic wants is to build a simple circuit that will make a step motor sweep back and forth to drive a model radar dish (like K-9’s ears in Dr Who). I know … sounds simple!

Monday 24 March 2014

Beetlebot

A while back, I saw a cool little robot project by Jérôme Demers. I first encountered the Beetlebot on the Instructables website. The Beetlebot is a very simple (and cheap) design requiring only a handful of accessible electronics components (2 motors, 2 lever switches a battery clip and some wire).

I won’t bore you with a description of the build since his page (and several others including the Make! site) have done this. It would also appear that Jérôme’s design has made it into a couple of “Science Education” pages, tutorials, demos etcetera.

I present, however, my build of the Beetlebot …

Picture 22

Where Jérôme uses some shrink wire cover to act as the “wheels” of his Beetlebot, I’ve simply used two more wooden beads hot-glued to the shafts of the to motors.

I’ve been collecting the bits and pieces for this bot for a while (I had some of the parts, but I needed to buy a motor, a battery clip and some spade connectors) and I finally got around to building the project.

While I was soldering, I found it difficult to solder in the connecting wires. My old eyes are not what they used to be … I was using my reading glasses and a magnifying glass to be able to see the connections well enough.

Picture 23

I used solid core wire for the connections rather than multi-strand so that the wire “behaved” better while I was soldering … plus I had some leftover pieces from my last project.

Picture 24

The spade connectors had to be cut down so that the antennae didn’t interfere with each other too much when they activated. I simply used my side-cutters and then soldered the straightened paperclip into the socket before crimping.

Picture 25

The build went very well and I didn’t have very much rework to do. The only real hassle was when I was hot-gluing the trundle-wheel paperclip to the battery clip. It didn’t want to work all that well, so I am supporting the glue with some electrical tape. I also used both hot glue and electrical tape to hold the motors onto the brass strip.

Also, the hot glue blob for the passenger side antenna was a bit excessive and interfered with the operation of the antenna … so I did a little scalpel work.

Picture 26

Balance is important with the Beetlebot. Make sure that you follow Jérôme’s instructions about placement of the motors … if they are too far back, the Beetlebot will face-plant a lot.

The antennae come off very easily, the first time I let my Beetlebot free, it scuttled straight under my lounge chair and left one of it’s antennae under there.

All up, this build cost me about $12AUD and I bought all of the electronic components from eBay. The beads came from Spotlight and the paperclips came from my office.

The project took me about 1 ½ hours to complete … maybe I’ll make a carapace for my Beetlebot, but then again, I quite like the way it looks now. I wonder if I can get away with not giving this toy to my darling daughter?

Monday 10 March 2014

LED Lamp – Part 5

Today, I de-molded the lamp head from the plasticine.
Picture 20
There was some cleaning up to do as some of the resin leaked through the CD and made a mess on the under-side of the lamp. This would be visible, so I wanted to make it look better. It would also make it difficult to attach the disc to a riser. I picked the resin off with a sharp knife and an awl.
The cast wasn’t 100% successful as the mold was not sitting flat in the ice-cream container. The disc is about 13mm on one end and 10mm at the other side … meh.
Then … I connected it to the USB power supply (5.1V) and it looks pretty snazzy.
Picture 19
It throws a decent amount of light too.
With the disc turned over, so that the LED are facing downward, it looks pretty good too. The clear CD acts as a bit of a light-pipe, the cast blue light is pretty satisfying and the light coming through the resin looks nice too.
Picture 21
I need to figure out how to attach it to a riser and stand. I was originally thinking of casting a riser using the resin with the wires passing through the middle of the cast. That would involve pouring half of the mold, letting it set a little, laying a tube through the centre of the riser and then filling the mold with resin. I should end up with a riser that has a void in the middle where I can pass the wires through. Then I was thinking of making a base with a switch in it that would hold the disc and riser.
An alternative idea is to affix a clip onto the disc so that the light could be clipped on to a shelf over the bed. For that I’d need to make a small switch enclosure.
I dunno what to do … but I’m thinking about it.

Sunday 9 March 2014

LED Lamp – Part 4

The next thing to do is to invest the circuitry in some resin. I’m using Barnes Easy Cast Clear with a mixture of red and white dye and some glitter to add some pink glittery specialness for my daughter (the lamp is for my daughters bedroom).
First, I made a mold using plasticine.
Picture 16
I redid the plasticine base, pushing the LED lights through the CD and into the plasticine. That way, the LED plug up the holes in the CD and there shouldn’t be too much leaking underneath the disc.
The plasticine was rolled out into a couple of strips that were then wrapped around the CD to give me a vessel to pour the resin into. I made sure that I sealed the seams in the plasticine so that the resin doesn’t leak there either. The two wires (positive and negative) that power the circuit were cut in through the plasticine wall and sealed up.
I made up 100ml of 2 part resin. In the first 50ml, I added the white and red dyes and the glitter. The colours and glitter were added here so that I could mix them in without worrying about the pot-life of the mixed resin.
I put the plasticine reservoir into a plastic ice-cream tub to make sure that any spills or mishaps were contained.
When I had the colour mixed thoroughly, I then added 50ml of the resin part-B and poured it into the plasticine reservoir.
Picture 17
The mixture is curing in the mold.
You can see some of the glitter.
Picture 18
The resin is about 15mm thick and should cure to an almost opaque pink.. I’m not sure how much of the glitter will be visible, I’m hoping that the light from the LED will illuminate the resin disc.
Well … here’s hoping. The MSDS for the resin says that it is cured in @1 hour and takes about 7 days to fully cure (unless you want to bake it in the oven … not practical here, I’m afraid).

LED Lamp – Part 3

The next thing to do is to solder the anode (+) side of the circuit.
I cut the shielding off the solid core wire so that I would have more flexibility when soldering … also, cutting out little soldering windows is not so easy.
Picture 12
This was a bit of a pain as I had to mark out each solder point on the wire, take the LED and resistor out of the plasticine and position the wire and LED on my soldering stand. Each time, I had to put the circuit back into the plasticine and mark the next solder joint. Still, with a little patience, I got there.
Picture 13
You can see the termination on the right hand side of the loop and I’ve let the wire trail off.
More wire stripping for the negative side of the circuit. I also cut the long end of the resistor leg down to a more manageable (approx.) 5mm length. Then I was able to solder the outer wire in to the resistors in place. It wasn’t necessary to use the soldering stand for this side because I didn’t need to be too careful about heat-sinking the resistor.
Picture 14
Once the outer wire was soldered in, I took the plasticine off the back, cleaned the plasticine residue from the CD and presto … the CD is all wired up.
Next is a quick test of the circuit to make sure the LED all light up and we are pretty much done with the light end of the build.
Picture 15
I also drilled two more holes in the CD near the perimeter for the two solid core wires to go through to the under side of the CD.
Fiat Lux … let there be light.

LED Lamp – part 2

Today I got to work on soldering up the LED.
I made a bed of plasticine to sit the LED in, this was done by rolling out some plasticine about 10mm thick and sitting the CD on top, then I pressed the LED into the plasticine through the holes that I had drilled through the CD.
Picture 7
That gave me a stable surface to work on where the LED are spaced properly.
Then I took each LED in turn and shortened the cathode (-) leg and soldered it to the 100 ohm resistor.
Picture 8
I used my modified USB cable to test each of the LED as they were soldered, to make sure that the LED was still working (I’ve burned some LED out by being sloppy with my heat dissipation before).
Picture 9
As the LED/Resistors were completed, I put them back into the plasticine so that I could see how I’m going for space.
Picture 10
I’m still going to have to shorten the legs on the resistors, but here is the build so far with the cathode end pointing in to the middle of the CD.
Picture 11
And here it is with the cathode pointing to the edge of the CD. I need to run a wire between each of the resistors in series. I’ll also need to run a wire between the anodes in series. I think that I prefer the cathodes pointing out, but I’ll need to see how I go when I wire up the positive lead.
Anyway, that’s the progress so far. I’ll do some more later on today.

Thursday 6 March 2014

Create your own Order Tracking Excel

Here is a simplified version of my order tracking application. I’
image
Start out with columns…
  • Order Number – you increment this … it’s there for sorting
  • Date of Order – The date you placed the order (and paid)
  • Category – An arbitrary category used for column filtering
  • Item – A short description of the item
  • Description – A more detailed description of the item
  • Cost – The total cost for the order
  • # Items – the number of pieces
  • Cost Each – a calculated value of the cost per item
  • Vendor – the name of the vendor (sorting and filtering)
  • Sent Date – the date that the vendor tells you the order was sent
  • TTS Days – Time To Send days (calculated)
  • ETA – The date that the vendor estimates for delivery
  • ETA Days – the estimated number of days to deliver (calculated)
  • Arrived Date – the date that the item actually arrived
  • ETA/ATA Difference – the difference between estimated and actual (calculated)
  • Travel Time – the time that the order was in transit (calculated)
Now to put in some calculations … This is where the value is added. I’m using Excel 2010, so these formulae are using functions that I know are there in this version … don’t blame me if your spread-sheet doesn’t have the DATEDIF function!
Cell Reference Formula Purpose
H2 =F2/G2 calculates the cost per item
K2 =IF(J2<>"",DATEDIF(B2,J2,"D"),"") Calculates the number of days to send the order
M2 =IF(L2<>"",DATEDIF(B2,L2,"D"),"") Calculates the estimated number of days to arrive
O2 =IF(N2<>"",IF(N2>L2,DATEDIF(L2,N2,"D"),DATEDIF(N2,L2,"D")),"") Calculates the difference between the Estimated and Actual time to arrive days
P2 =IF(N2 <> "", IF(N2>J2,DATEDIF(J2,N2,"D"),DATEDIF(N2,J2,"D")),"") Calculates the number of days for the order to arrive
Copy the formulae down the columns in the spread-sheet and you should be good to go.
You can turn on Filtering in the spread-sheet so that you can track individual vendors and item categories.
When you don’t enter an ordered date, the item is, effectively, a wish-list item.
Well … that’s my piece for today. Hopefully, I’ll have some free time on the weekend to carry on with my LED bedside light.

Here is a copy of the spread-sheet for personal use.

Tuesday 4 March 2014

LED Desk/Bedside Lamp

I want to make a lamp for my flat.
The idea is a pretty simple one. I’ll use a CD protector disk (the clear ones that often come with a spindle of CD) this will be the basic platform for the light.
I want about 8 LED arranged around the CD so that it throws enough light and doesn’t look too sparse.
The electronic side of this project is very very simple. 8 LED in parallel and a switch (of course I need some resistors).
Parallel LED
Here’s the basic design for the circuit (of course it needs the switch added to the design, but that’ll do for now.
I’ve marked out the CD with 8 marks for 5mm holes to be drilled. This was done by first finding the centre and marking out a circle 4cm from the middle using a compass on a piece of paper.
Finding the centre of the CD was done by placing the CD against the inside of a T-Square, where the CD touches the T-Square is two angles of a right angle triangle. Draw a line 90 degrees from the two points toward the centre of the CD. Where these two lines intersect is the centre of the circle. Then I opened the compass up to 4cm and drew a parallel circle from the centre point. Next, I drew another two lines through the circle that are 45 degrees from the first set of lines that I drew.
Where the lines intersect with the 4cm compass line is where I’ve drilled the 5mm holes for the LED. 8 holes, evenly spaced around the circumference of the inner circle that I drew … what could be easier?
So far I have the light platform made … next I want to solder up the light circuit and test it.
Picture 7

Saturday 1 March 2014

Buying electronic components online

I’ve been buying electronic components from eBay for a while now. When I started, I had some concerns with the quality, the opportunity for being ripped off and the time that it takes to have the components that I want in my hot little hands.

There are some things that you need to think about when you go about buying electronic components on eBay. If, when you buy something from eBay, it doesn’t work … it can be a hassle to return the item(s) and get your money back, so I plan NOT to.

I guess that the easiest thing to do is to make sure that you are only buying cheap stuff that doesn’t really matter if it goes astray or if you have to buy a replacement if the quality isn’t good enough. I like to keep my risk low, so I really only buy stuff that is less than $10 AUD. That way, if it turns out to be a scam or a dud, I can write the loss off as a lesson.

I wrote a small database application that I use to track my eBay orders.

onlineOrders

The application uses the date of the order, type of component, item name, description, # items I’m buying, order cost, vendor and a bunch of other stuff. You could just as easily do this in a spread-sheet with a little jiggering around.

What I can do is, keep track of my orders and get some evidence of how the different vendors serve me. Then, when I place another order, I know what to expect.

I’ve also made another category for my orders for “Wish List” where I can record the stuff that I want to buy later on … all in once place. Handy for me.

What I can say from this experiment is that, in my experience, buying stuff on eBay is pretty safe (at least when you are buying stuff for a couple of bucks). I’ve had a couple of orders that simply never arrived (3 orders for a total loss of $6.69 AUD), but, compared to the orders that did arrive (103 at a total cost of $444.86) means that my overall risk is around 1.5%, so … not too bad.

I also have a couple of vendors who I would not use again (please don’t ask me who).

The other thing that I was worried about, the time it takes for the parcel to arrive, is also managed using my application. The vendors usually have some information on their item pages that tells you how long it usually takes for parcels to be delivered to your country, but you also want to know how long it takes when it arrives in your country. I’m currently living in what is lovingly referred to as a “Remote Location”, that’s right … Hobart Tasmania! So I need to factor the “Bass Triangle” into my estimations. With my application, I can work out the averages for each vendor in terms of:

  • Time to send the parcel;
  • The vendors estimated delivery timeframe (I usually take their pessimistic estimate);
  • The date that the parcel arrived.

So, armed with this data, I can get a fair idea of when I can expect to get my new toys. On average, the delivery of stuff from vendor to me is 15 days in transit. There are a bunch of variables … the vendors are not all in the same place, they don’t all use the same method of delivery … you get the picture, so I won’t die in a ditch if the parcel is +/- 5 days!

Finally, on the question of quality. Most of the stuff that I buy is fairly inexpensive, and that includes inexpensive to manufacture. Almost every component that I have received and tested falls within an acceptable tolerance range and that too is often stipulated on the vendors item page. I have been pretty pleased with the quality of the stuff that I’ve bought off the interweb … I don’t have particularly high expectations in this regard, no-ones life depends on the build quality of the components that I use, so that is an acceptable risk too. There has only been one time where I bought something, tested it and binned it, and to be fair … I hadn’t read the fine print on  the vendors item page (READ IT!).

There are some other benefits. Occasionally when you buy stuff from an eBay store, the parcel will arrive with a savings coupon for your next purchase. If you use these wisely, you can really save some money.

The main benefits that I was looking for when buying electronic components online were:

  • Cost; and
  • Availability

My experience has shown me that buying online exceeds my expectations there. When I started buying components from eBay, I would find a similar item from a local bricks and mortar vendor and compare the price. Often, I was saving up to 90% on the purchase. For example … a 5mm 20,000 mcd white LED cost me @ $6 when I bought it in-store … when buying 200 items from eBay, they work out at $0.02 each that is a saving of > 90%. Although it isn’t an apples and apples comparison, but for my purposes, the $0.02 LED is fit for purpose whereas the $6.00 LED is way overspecced for what I need. An LED with the same specifications as the $0.02 one was not available in store, so the comparison stands.

My advice is, if you can risk the small amount of money that you are spending buy online, track your orders and test the goods when they arrive.

Paypal Donations

Donations to help me to keep up the lunacy are greatly appreciated, but NOT mandatory.