maandag 9 november 2009

Electronic component: The Arduino board

Besides the PICAXE, another popular PIC exists for the electronic hobbyist: the Arduino. Actually, the PICs in use are Atmegas, Arduino is the platform making it easy for people to use the PIC.




The Arduino family consits of a few different boards. I'll be using the Duemilanove, as displayed above, but many more are available for different needs. The Duemilanove has 13 digital input/output pins, 5 analog and an USB connector. Today we'll cover the process of programming an Arduino.

What I like the most about the Arduino platform is that it's all open-source. Except for the PIC that is. The software to program the chip is written in C++ and runs on most platforms. Here is a screenshot:



The proces of programming the Arduino is very simple actually. You write the software and press upload to upload it to the Arduino. The Arduino Duemilanove can be connected to your PC by USB with a USB connector cable.

We are going to built a blink LED, as always ;) The following circuit will show nothing really. It's nothing more than connecting the Arduino to your PC an a LED between digital 13 and the ground. The shopping list for the circuit is:

1 x USB connector cable
1 x Arduino Duemilanove (check Sparkfun.com, it seems to be the cheapest)
1 x red LED


You can open the default Blink example from the file menu (file > examples > digital > blink). Every program has at least a setup function (this code is run as initialization) and a loop function (which is repeated between power up and power down of the board). In the setup function the digital pin 13 is enabled as output. In the loop the output on 13 is set to HIGH, wait for a second, set to LOW and again wait for a second. Nothing really fancy. Upload the program and enjoy the coolness.


vrijdag 6 november 2009

Project: The light-o-meter

Ok, this is the final chapter in the project. We are going to build the actual meter. In the previous postings we've learned to program the PICAXE and use the LDR. Up next is to combine these into one circuit.

One nice feature of the PICAXE 18X is to be able to read analog components, by connecting them to an input pin. This will have to be either input0 (pin 17) or input1 (pin 18) as they have ADC support.

This is how the meter is going to work. The LDR will be used by the PICAXE to determine the amount of light. Based on the amount of light LEDs will be lit or unlit. The more light, the more LEDs will be lit.

For the following circuit we will require these items:
1 x 9V Battery
1 x LDR
1 x 10 kOhm resistor (brrown, black, orange)
1 x 4.7 kOhm resistor (I still use three)
8 x 1 kOhm resistor (brown, black, red)
8 x  C547B transistor
3 x green LED
3 x yellow LED
2 x red LED




Ok, here we go. Step by step:

1. Place the PICAXE on the board, like the last time.





2. Put the 8 LEDs on the board


 
3. For each LED, put a resistor between the LED and ground.
 

4. For each LED add a transistor to the board. Whatch carefully how to connect them.
 

5. Connect each transistor to the appropriate pin on the PICAXE. See the pin layout in the previous post for more details.

 
6. Connect an LDR to the + pole, and the 10kOhm resistor. The resistor should be connected to the - pole. Connect input 1 of the PICAXE to the LDR and resistor.

 
7. Review the result before you blow anything up ;)


8. upload the following code into the PICAXE:

main:
readadc 1, b0 'Read the amount of light 0=dark 255=very much

'Is it very bright? put led 7 on
if b0 > 230 then
    high  7
else
    low 7
end if

'Is it less very bright? put led 6 on
if b0 > 200 then
    high  6
else
    low 6
end if

'Is it bright? put led 5 on
if b0 > 180 then
    high  5
else
    low 5
end if

'Is it medium bright? put led 4 on
if b0 > 150 then
    high 4 
else
    low 4
end if

'Is it below medium? put led 3 on
if b0 > 120 then
    high  3
else
    low 3
end if

'Is it between dark and medium bright? put led 2 on
if b0 > 90 then
    high  2
else
    low 2
end if

'Is it less dark? put led 1 on
if b0 > 60 then
    high  1
else
    low 1
end if

'Is it quite dark? put led 0 on
if b0 > 30 then
    high  0
else
    low 0
end if

goto main


This is the result:


woensdag 4 november 2009

Electronic component: The PICAXE

For our project we are going to use a PICAXE, today we are going to learn what the PICAXE is and how to program it. This we will be doing by building a circuit which is sending out an SOS signal in Morse code.

The PIXAXE is a PIC. IC stands for integrated circuit, as we already have learned. PIC stands for programmable integrated circuit. This means that you can write code and upload it onto the chip. Based on input you can set a different output.

For the project I've used an PICAXE 18X, but there are many different types of PICAXE chips. Also different PICs exist, for example the Atmel chips which we will meet later on.

As we are about to program a PIXAXE, we do require some items. I bought them at SparkFun, which seem to be nice guys. For today's circuit, this is what we need:
1 x PICAXE 18X (Some other PICAXEs will be ok too, but you are on your own ;))
1 x PICAXE Serial programmer cable


1 x PICAXE Bread board adapter (instead you might want to get the PICAXE 18 pin power project board, but I found this to be more flexible, although you will have to solder it)


1 x USBtoRS232 converter, as my PC doesn't have a serial port.
 
1 x USB connector cable
 
1 x 9V battery
1 x 4,7 kOhm (I used 2 x 2.2 kOhm + 1 x 330 Ohm in series, as I didn't have one)
1 x green LED

Well, that's about it. Here is the circuit we are going to build:


To imitate the PICAXE Bread board adapter, I've used three signal input symbols. It's pretty straightforward I guess. Note that this is the actual pin layout for the PICAXE 18X:


Ok, once you have connected everything, including the serial and USB cable, we can start programming the PICAXE. As I use Linux I'll be using AXEpad, which is really easy to use. For Windows you will probably have to set up some drivers and download another program. The code for the PICAXE will be the same anyway, so here we go:

main: ' start here
    gosub short ' jump to short
    gosub short ' jump to short
    gosub short ' jump to short
    pause 200 ' wait 200 msec
    gosub long ' jump to long
    gosub long ' jump to long
    gosub long ' jump to long
    pause 200 ' wait 200 msec
    gosub short ' jump to short
    gosub short ' jump to short
    gosub short ' jump to short        
    pause 3000 ' wait 3 sec
    goto main ' jump back to main

short: 
    high 4   ' Set output 4 to ON     

   pause 100 ' wait 100 msec
    low 4   ' Set output 4 to OFF
    pause 100 ' wait 100 msec
    return  ' Jump back to main
     
long:
    high 4  ' Set output 4 to ON
    pause 300 ' wait 300 msec     

    low 4  ' Set output 4 to OFF
    pause 300 ' wait 300 msec
    return  ' Jump back to main


The code is pretty human readable. It looks a bit like BASIC. Just put the code in the editor and upload it the PICAXE. If everything goes OK, you will be seeing a LED that's blinking short-short-shot-long-long-long-short-short-short.

That's it for now. Till next time.