Make It Last Build Series: “Hello, world” blinky light on a PIC

Technology
Make It Last Build Series: “Hello, world” blinky light on a PIC

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.

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Tagged
Discuss this article with the rest of the community on our Discord server!

ADVERTISEMENT

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 16th iteration!

Prices Increase in....

Days
Hours
Minutes
Seconds
FEEDBACK