Find all your DIY electronics in the MakerShed. 3D Printing, Kits, Arduino, Raspberry Pi, Books & more!

MZ_MakeItLast.gif

hello_world_final.jpg

If you haven’t already heard, we’re excited to be running the Make It Last, a project build series and contest, sponsored by Microchip and Energizer. Throughout the course of this series, we’re going to cover three project builds, each demonstrating an example of low-power design using microcontrollers.

Just getting started? We suggest you take a look at the announcement post for an introduction to the series, then follow along with these instructions to build the first stage of our first project, a data logger, and learn how to say ‘hello, world’ with a blinking light!

If you haven’t signed up for the newsletter, you should do that, too. We’re about to send out the second issue.

Step 0: Collect supplies

DSC_4398.JPG

Parts list:

  • Microhip18LF25K22 microcontroller
  • Solderlesss breadboard
  • 100k resistor
  • 1x3mm red LED
  • 1uF capacitor
  • .1″ male header (6 pins long)
  • Breadboard jumper wires

Tools:

  • PICkit 3 programmer, for programming the processor
  • Pliers (optional, for bending wires)

Note: You will need to download and install a couple pieces of software (MPLAB and MPLAB C for PIC18) to be able to program the microcontroller used in this project. For full instructions, see the second project newsletter.

Step 1: Mod the header to make a PIC programmer connector

DSC_4406.JPG

To program the microcontroller, we need a way to connect the PICkit 3 programmer to the breadboard. Since they are both female connectors, we can use a standard .1″ header. Because the headers are normally used with soldered protoboards, we’ll need to modify them to work with the breadboard. Use a pliers to push each pin down so that it is centered in the plastic, with an equal amount of metal on each side of the plastic connector. That way, the header will be able to make a good connection with both the breadboard and the programmer.

Step 2: Examine the breadboard

breadboard.jpg

The breadboard acts as as a big interconnect for the electrical parts, allowing you to easily hook up power and other control signals without running too many wires. It is divided up into three sections: two side rails for power, and one main section for connecting things up.

In the photo above, we’ve highlighted how the holes are connected together. Each shaded area represents a separate circuit, and all of the holes in that circuit are shorted together. Each one of these sections can be used to make a single connection, or “node” in a circuit diagram. The two side sections are reserved for power — anything plugged into the black areas becomes connected to ground, and anything plugged into the red areas becomes connected to power. For a more in-depth discussion about breadboards, see Tom Igoe’s breadboard page.

Step 3: Place the processor and programming header on the board

hello_world_processor_programmer.jpg

The first thing to do is to place the main components so that we can start to wire around them. For this project, this means the microcontroller and the programming header. Place them in the same locations as shown in the above photo — we’ll be adding more parts as we go, and will need the extra space on the breadboard for future additions.

Step 4: Add wires for the power and ground connections

hello_world_power.jpg

Next, we need to run wires to connect the power rails on each side of the board. Run a wire from the red (positive) row on the bottom rail to the red on the top rail, and repeat for the blue (ground) rows. These are the red wires in the above photo. Next, hook up the power and ground connections to the processor and the header. The processor needs to have pins 8 and 19 connected to ground, and pin 20 to power. The header should have pin 2 connected to power, and 3 to ground. In the above photo, the green wires are for the ground connections, and the yellow ones are for power.

Step 5: Connect the programming header to the processor

hello_world_programmer.jpg

The programming header is used to connect the programmer to the microcontroller. It needs to have 3 wires connected: pin 1 goes to the reset input on the microcontroller (white wire), and pins 4 and 5 go to microcontroller pins 28 and 27, respectively. In addition, a 100k resistor should be connected between power and microcontroller pin 1 (note: the value of this resistor isn’t critical; I’m using a 10k resistor in the above photo). The resistors acts as a ‘pull-up’, keeping the reset line input to the microcontroller high when the programmer isn’t connected.

Step 6: Add the decoupling capacitor and LED

hello_world_final.jpg

The final parts to add are the 1uF capacitor and LED. The long lead (positive) on the capacitor should be connected to pin 20 (power) on the microcontroller, and the short lead (negative) should be connected to the ground rail. The capacitor acts as a reserve energy source for the microcontroller, protecting it from any quick fluctuations in the power supply. Similarly, the long lead (positive) on the LED should be connected to pin 2 on the microcontroller, and the short lead (negative) should be connected to the ground rail.

Double-check your setup with the above photo — if everything looks the same, you are good to go!

Step 7: Download and open the example program

program.jpg

Download and unzip the

example project

. Fire up your copy of MPLAB, click File->Open Workspace, navigate to where you unzipped the project, and double-click on “hello_world.” If all goes well, you should see a screen similar to the one above.

Step 8: Configure the PICkit 3 programmer

Note: Don’t plug the PICkit programmer into your breadboard yet, if it is configured incorrectly it could damage your chip!
Once the software is set up, the next step is to configure your PICkit 3 programmer for the board. If you haven’t already done so, plug it into the USB port on you computer.

configure_programmer.jpg

Next, select it as the active programmer in MPLAB by clicking Programmer->Select Programmer->PICkit 3. Next, configure the programmer to supply 3.3v to the board by clicking on Programmer->Settings, then navigating to the “Power” menu. Drag the slider until the voltage reads 3.3V, then click OK to apply the changes.

Step 9: Program the project

DSC_4423.JPG

At this point, you should be able to plug the PICkit 3 programmer into the programming header, as shown above. Click Project->Build All to make sure that the example program is compiled, then click Programmer->Program to download it to the microcontroller. If all went well, you should now be the proud build of a blinky light circuit!

Conclusion

This might seem like a lot of work for just a blinking light, however what we have done is to set up everything we need to progress to more complex projects. So relax, pat yourself on the back for a job well done, and get ready for the next steps!

If you have any problems with this initial set-up and breadboard build, talk to us on the MAKE Forums.


Related

Comments

  1. migpics says:

    Can you recommend a kit for doing this? I’m not sure where to get these parts in Norway!

    1. Addidis says:

      Im not from there , but MicrochipDirect.com should be able to provide the PIC, temp sensor, and memory and programmer. (your looking for the DIP form factor chip)
      The other components are pretty common.

  2. migpics says:

    Thanks so much. I’ll look into it.
    I found a place called ELFA and it’s in Oslo about an hour away from where I live.
    No radio shacks around here!
    On another note, how feasible is it to tear apart existing electronics to scavange the parts?

  3. Addidis says:

    You will probably land up purchasing the EEPROM and PIC and the cost of the other parts is low enough that you probably want to avoid the hassle for the cost. . . Just buy em.

  4. gwagner says:

    I think it would be a good idea to include a current limiting resistor in series with the LED. Something on the order of:

    (3.3V – 1.2V)/10 mA = 210 ohm

    220 ohm is a standard value
    3.3V is Vcc
    1.2V is typical red LED forward voltage
    10 mA is typical LED current

  5. makeit says:

    I used the program shown at step 7 but the mplab is complaining that the p18lf25k22_g.lkr and 18lf25k22.h files are not found.

    I tried windows-search tool but I can’t find them anywhere.

    Do I need to download them from somewhere or install HI-TECH C Compiler for PIC18 as this might provide the necessary additions?

    1. Matt Mets says:

      Oh, yes! you will need both MPLAB at MPLAB C for PIC18 (version 3.36+) to use the provided software. Installation instructions are in the second newsletter:

      http://makermedia.cmail1.com/T/ViewEmail/r/9B86A59D0AD8D346

      1. makeit says:

        Thanks very much for your fast solution. I managed to build thanks to you :)

        later I figured out that in addition I had to configure the library-search-path and include-search-path because it couldn’t find the file ‘c018i.o’. I found this instruction in the documentaion.

  6. Edward says:

    Hi, the LED only blinks when PICKIT3 is connected. I tried using another 5v power source after programming the LED only stays on all the time. Any idea? Could it be the Oscillator configurations?

  7. Fernando says:

    Very useful information Matt, Thanks!!!
    I am newbie about this, and I would like to ask you if with PICKIT3 we could feed our breadboard (+5V), instead of use external source?
    I saw that you included 1 LED in the part list, but I don’t understand why did you included, because as far I understand, all the procedure was to explain how to program (download), the code to PIC.

    My best regards
    Fernando Romo

In the Maker Shed