PIC Up a NeoPixel Ring and C What You Can Do Using This Tutorial

lit ringAs [Shahriar] points out in the introductory matter to his latest video at The Signal Path, Arduinos are a great way for a beginner to dig into all kinds of electronic excitement, but they do so at the cost of isolating that beginner from the nitty gritty of microcontrollers. Here, [Shahriar] gives a very thorough walkthrough of a 60-neopixel ring starting with the guts and glory of a single RGB LED. He then shows how that ring can easily be programmed using a PIC and some C.

[Shahriar]’s eval board is a simple setup that he’s used for other projects. It’s based on the PIC18F4550 which he’s programming with an ICD-U64. The PIC is powered through USB, but he’s using a separate switching supply to power the ring itself since he would need ~60mA per RGB to make them burn white at full brightness.

He’s written a simple header file that pulls in the 18F4550 library, sets the fuses, and defines some constants specific to the ring size. As he explains in the video, the PIC can create a 48MHz internal clock from a 20Mhz crystal and he sets up this delay in the header as well. The main code deals with waveform generation, and [Shahriar] does a great job explaining how this is handled with a single pin. Before he lights up the ring, he puts his scope on the assigned GPIO pin to show that although the datasheet is wrong about the un-delayed width of the low period for a zero bit, it still works to program the LEDs.

[Shahriar] has the code available on his site. He is also holding a giveaway open to US residents: simply comment on his blog post or on the video at YouTube and you could win either a TPI Scope Plus 440 with probes and a manual or a Tektronix TDS2232 with GPIB. He’ll even pay the shipping.

18 thoughts on “PIC Up a NeoPixel Ring and C What You Can Do Using This Tutorial

  1. This looks interesting. I’ve been working on porting the Adafruit Neo-Pixel libs to work with PIC18, my ‘weapon-of-choice’ when it comes to micros. This looks like a much cleaner, fresh implementation than porting bloated Arduino libs.

  2. I don’t understand one thing, why do americans use 120V@60Hz instead of normal 230V@50Hz like us Europeans, it’s just better.

    1. Oh if only your internet had a search-engine, I also live in europe and I have several available, this took almost no time to find – and it shows in quality, but you spend even less time on your research so i dont really care.

      http://wiki.answers.com Q/Why_does_the_US_run_at_120V_when_some_of_the_world_runs_at_240V

      saying “use X instead of Y like us, its better” is flamebait

      — another european

    2. I assume for the same reason we don’t use the metric system… we are egocentric and if it wasn’t invented here, we tend to scoff at it… NIH you know…

    1. The point of this tutorial is to make you realise that comments like that are a bit silly (if you’ll forgive me). An understanding of how micro-controllers do things generally means that you can move between different types fairly easily. Like how you learn to drive a car rather than learn to drive a, say, Honda.

      1. You miss my point. If you have a look on the internet 99.999% of all results are for using the Arduino + libraries with no examples of how to drive them purely with bit-banging the pins.

    2. Although it is nice to have code ready made for something, all methods used to drive these leds should be transferable between controllers.
      Bit banging in particular is not preferred as the timings are rather tight when programming in C and asm is needed.

      I find the perfect method (halfway between complexity and ease of use) to be PWM based with a bit of DMA ocasionally.

  3. The new CLC peripherals on the PIC16’s make driving WS2811’s pretty trivial. I wrote AN1606 to demonstrate using a PIC16F1509 to drive the LED’s. This appnote will be revised shortly to also show driving the LED’s from the PIC16F1719 which has more memory so it can buffer a larger image.
    Essentially, the CLC allows the SPI clock and PWM to be mixed with the SPI data. The SPI clock provides a 50% modulation and the PWM provides the 25% modulation to make the WS2811 waveform. The SPi must be driven from TMR2 to synchronize the PWM and SPI Clock edge. Then writes to the SPI produce 8 proper WS2811 bits.

  4. Very nice, this one is going on my watch later list. He’s right about the Arduinos, for me they lowered the barrier for entry to the point i could just started making stuff and having a lot of fun doing it. I do feel i’m now ready to delve a bit further into microcontrollers and this looks like a good place to start

    Thanks

  5. I just got my neopixel ring sat and ported his code this weekend to stellaris/tiva. Works nicely, ditto on the bloated arduino libs. I did have to tweak the T0L and T1L times (could not just leave them as he did). On the scope it worked out to 2.6usec total for high + low for 0&1. It can pull a bit of curr, I saw 1.7A or so on the 5v line (all on), but for his rainbow code ~0.4A.

  6. As an amusing factoid, the 18F4550’s PLL has a 4Mhz input only, so it can run the core at 48Mhz with a 4Mhz crystal/clock as well. I usually use 12Mhz because that’s the clock other pic18s with USB modules need for low or high speed operation (they only have X4 PLLs, not the fancy X96 unit the 18F4550-series does). I’ve never been clear why everyone seems to prefer using 20Mhz crystals, maybe its just because its a common upper limit for other micro-controllers so they have them around? (and they DO work just as well as anything else)

    1. For hobbyists (and other people who can’t just pour money on their projects to make them bloom – and dont have a lot of pesky certifications to pass) i think there is a lot to be said for using “good enough and available” over “better but need to buy”.

      tl;dr: I think you hit the nail.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s