views:

832

answers:

15

How do I get started with programming PICs (or similar products)?

Preferably in C. What are some good beginner kits, tutorials, books, etc.? Maybe some little robotic project ideas.

+2  A: 

Couple of helpful links:

(community wiki, so please add more)

Greg Hewgill
+2  A: 

Pretty much every issue of Make Magazine has at least one robotics project. Their blog is also full of ideas.

Barry Brown
+7  A: 

One way to get started is using on the of the PIC starter kits offered by Microchip. They're usually one demonstration board that comes with one PIC included, which can be used to program the microcontroller and also perform some simple projects with the LEDs and such which comes on the board, along with an evaluation version of a C compiler.

There are multiple families of PICs, starting from 8-pin, 8-bit microcontrollers which only have 256 words of memory, up to 32-bit microcontrollers with hundreds of KB of RAM and flash based around an ARM core. Therefore, it would probably be a good idea to first find out what the requirements will be (from books and tutorials) before deciding which family of PIC microcontrollers to use.

Searching for something along the line of "PIC robotics" in an online bookstore like Amazon will yield many books on using PICs for robotics. However, it should be noted that many books may actually use a BASIC or other non-C language compilers for programming the microcontroller, so it would probably be a good idea to first look at the contents of the book to be sure that it provides C examples.

Also, it should be noted that there may be some incompatibilities between C compilers (available libraries and such), so it would be a good idea to also check that the C compiler you have and the code examples given in the book will actually work with each other. This part might be one of the more frustrating parts about getting started with embedding programming.

coobird
+10  A: 

Hopefully I won't get trashed for saying this but I find that assembler is far easier for the PIC than anything else. I am talking about the PIC not the PIC 32 which is a completely different thing.

I usually frequent SparkFun for both Olimex and non-Olimex (SparkFun) boards. Sometimes there are links to working examples, sometimes not, you have to shop around.

I cut my teeth on the PIC but have long since left them behind. The instruction set was horribly inefficient and they didn't "get it" when it came to development boards. It looks like they do "get it" now, there are a ton of boards in that $20 - $50 range with which one can get their feet wet, actually perhaps too many boards. Sadly a day late and ollar short for me personally.

You will want either something akin to the AVR Butterfly, a handful of different on board gadgets to learn to program, and/or an almost bare board, just the chip, clock/power preferably communications UART or UART over USB (That way you get power as well). Note SparkFun has a number of solutions for that, little boards that you plug on the end of a USB cable and the other side is UART and power and ground. With the simple board you can add your own LEDs and whatever without having to remove or disable the gee whiz gadgets that came with the evaluation board. At one point I used a SPI UART as bit banging SPI was easier than bit banging the UART bits themselves.

I would start by blinking LEDs, both by counting instructions and the number of clocks in a loop and by learning to use the on-chip timer. Then learn to scale the system clock or other clock divisors. Then I would get into the UART or bit bang a serial out so that your programs can communicate with you. Then try to receive serial/UART data, with a UART if it's there, but also by polling an I/O pin and using a timer or counting clocks, and also use interrupts, interrupting on a state change on the pin if that is possible. Learn how to use pull-ups, get a Dallas Semiconductor one wire temperature sensor or something like it and don't just download working code. Figure out how to communicate with it (you may very well melt down one or more parts doing this, both PICs and temperature sensors, buy extras of everything).

All and more of these basic skills are required to do robotics. Hmmm, stepping that motor is not unlike bit banging a UART or SPI bus, just a little different...

You say robotics in your post but either before you start or as you shop and look at the boards available and download and read the datasheets for the chips (before you buy one), you really need to find a simple project. For me it was an infrared receiver, point your television remote at the PIC plus a couple of parts from radio shack (well one part) and then either blink an LED to show what I received or later bit bang it out a UART. Eventually I was able to completely parse different IR protocols, and for fun still do that from time to time with different microcontrollers.

Finding a project that receives something, a sensor, etc. Is probably easier to do at home without a lot of special equipment. Basically it's just a matter of time, depending on the device. You just sample the input pin at some rate and somehow send that to yourself where you can graph it or examine it and realize that it is running like 4 times slower than I thought. I wonder why that is, and/or if I just change this code here to adapt for the slower rate then my receiver will work.

If you are trying to output something, you are likely going to want some sort of an oscilloscope or logic analyzer to "see" your output, and even with a scope the device may still just not accept your data. Eventually you will want to have a project that outputs something, sure so you will need to be prepared for that. Depending on what you want to interface with you could get two microcontroller boards and have one output the data as if it were talking to the device and have the other monitor and or receive the data as if it were a logic analyzer, giving you a way to "see" the data for $20 instead of $20,000.

Oh and when you go embedded, forget EVERYTHING, you were taught in programming class. PIC and rabbit semi and other compilers are not going to be true C compilers, but kind of C compilers (some may be compatible with some standard, but for embedded you don't NEED that). Rules like no gotos, no global variables, one return per function, functions should be less than X lines of code, etc. These may or may have a purpose on a computer but many of them will hurt you dearly in the embedded world. Make sure you can disassemble or basically see the instructions being created by your C code. With a sometimes very limited ROM and RAM, you don't want to be using 10 to 100 times more resources than you really needed to. Or have to buy a bigger part just because of your coding style. As with blinking LEDs to learn how to use the I/O pins, learning how to program for embedded is just as important before you get into a real project. The good thing about this is that you can probably get a free or demo compiler and start learning this stuff before you buy any hardware. There are probably PIC simulators out there as well that you can single step through the code with to understand what is going on.

My bottom line is that you shouldn't limit yourself to the PIC, shop sparkfun.com, buy a few different $20 evaluation boards with different chips (AVR, PIC, MSP430, and definitely some of the ARM based ones), fiddle with all of them. Determine their strengths and weaknesses and/or your favorites based on your personal coding style. Everyone has a little bit different way of implementing I/O and timers and interrupts, etc.

dwelch
++1. "Oh and when you go embedded, forget EVERYTHING, you were taught in programming class." right on the money. If I could upvote you a hundred times, I would.
Manuel Ferreria
-1 for suggesting assembler. To use that, you have to learn not only assembly language but also a lot of details about the PIC like how to initialize various things by setting bits in registers etc. When using C, all these options and initializations are easily done by compiler directives, which in turn can be created by settings in the IDE or even by a project wizard if the IDE has one. Then you can get right down to actually making the thing *do* something.
Jeanne Pindar
+2  A: 

I am currently playing with PIC processors as a hobby, with a very tight time and cash budget. I got the Microchip starter kit from Farnell (I paid £20, but it's still less than £30 now.)

An important thing to note is that while the kit comes with a 14 pin socket it will program bigger chips, I am currently using the 20 pin 16F690.

I use the HI-TECH C compiler which has a free version which is superb.

I also use the Velleman USB board, which I got from Maplin for £30. It is a bit slow, but it allows you to talk to the PIC from your PC.

PIC processors might not be the best, but they are simple to use, and cheap.

David Sykes
A: 

To be honest I wouldn't bother with PIC's these days instead look at IC's containing ARM7 cores. These are powerful , quite easy to use , can be programmed with free tools (GCC) and are now cheap. You don't say where you are located but if you are in Europe then look at buying a development board from this company ..

http://www.olimex.com/dev/

If you think an ARM7 core is to complex then take a look at the MSP430 family instead. I bought a MSP430 development kit made by Texas and sold by Farnell for about £12 and which included a slightly crippled C compiler as well.

IanW
There are ridiculously tiny 8-pin and 6-pin PIC packages that let you drop a small amount of computation exactly where you need it. Sometimes that is all that is needed. It will be a few more process generations before any ARM can do that...
RBerteig
Not that the small ARM chips and MSP430s don't have their place too, mind you. There are a LOT of embedded CPUs in the market to choose from, even if you stick to just one manufacturer's line card. The PIC is still a viable place to start.
RBerteig
I 2nd @Rberteig opinion PICs, with all there pain sometimes, are great.
kenny
A: 

You want to do the electronics as well as the embedded development. You could look at the Beginning Embedded Electronics tutorials at SparkFun. This project is ATmega168 based.

dmckee
A: 
kenny
A: 

You could take a look at the starter kits by Rabbit. They offer a variety of low-cost starter kits to try out a certain technology like wireless, bluetooth, sensors, etc. It would be fun to get into embedded programming by making a cool gadget.

My colleagues used some Rabbit kits a few years ago to get started on their development.

guzelo
A: 

Dwengo has some good tutorials and starters kits for starting with PICs in C, including some robotics projects.

Wim
A: 

Since I'm very used to Delphi, the products from mikroElektronika were very appealing to me. I've done a couple of projects using MikroPascal (very similar to Delphi syntax) using their EasyPIC development boards and programmers.

They are located somewhere in eastern europe, but I never had problems getting their products shipped to the US.

Here's a link to their website:

http://www.mikroe.com/

Padu Merloti
A: 

I'm looking at these kits now and again. Makes me smile and remember the good old days playing with a Sinclair ZX-81

http://www.xgamestation.com/

epatel
+1  A: 

I went for AVRs rather than PICs for my hobby microcontroller project and decided on a 'non trivial' project of a hexapod robot "from scratch" (no kits) with custom electronics and firmware in assembly... The blog's here, it's going well but slowly :)

I found the tutorials over at SparkFun were very good and it didn't take me long to get going.

There's a great AVR community over at AVRFreaks with lots of tutorial stuff, more for C than assembler to be honest.

Len Holgate
A: 

Although some time has passed over the question, I would like to share a good tutorial link for the ones who would search for this topic on StackOverflow.

Gooligum Electronics - PIC Tutorials

They explain things very well, I think.

sarimura
A: 

Getting Started With Programming PIC’s...

Since you've mentioned PICs, I will add two cents by recommending a thorough book Embedded C programming and the Microchip PIC by Barnett, O'Cull and Cox. Fragments on google books

The book uses CCS compiler.

Oh and when you go embedded, forget EVERYTHING, you were taught in programming class.

Yup. Also, documentation is more scarce. Also, IDEs for embedded development are noticeably more simplistic (yet seemingly more arcane) than IDEs for PC development.

Nick Alexeev