element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Using Raspberry Pi to drive WS2812B LEDs
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 19 replies
  • Answers 2 answers
  • Subscribers 676 subscribers
  • Views 5379 views
  • Users 0 members are here
  • gpio
  • led
  • leds
Related

Using Raspberry Pi to drive WS2812B LEDs

Former Member
Former Member over 11 years ago

Hi there, I am pretty new to controlling hardware from the GPIO pins on the Raspberry Pi,

 

First I will give you a little background to what I am trying to achieve:

 

I have a 3D Printer which is controlled via my Raspberry Pi, running a distribution of wheezy containing OctoPrint. I have the Raspberry Pi Camera module connected up and a server accessible over the internet outside of my home network so I can see my prints progressing while away from home.

 

I am trying to use the above quoted LEDs which I purchased here:

 

20 RGB LED WS2812B Individually Addressable NeoPixel DC5V Arduino & Raspberry Pi | eBay

 

To illuminate my print bed. I chose these LED's due to them being RGB and (as the listing stated) them being compatible with the Raspberry Pi. I have thus far been unable to make them illuminate. The only light they emit is a quick purple flash when the ground and +5V supplies are first connected to the Raspberry Pi.

 

I have tried to use the Hyperion package on my Raspberry Pi but again no success. I ideally wanted to be able to be able to control them via the GPIO utilities already built in to the distribution to minimise CPU load (given the nature of 3D printer host software).

 

If anyone can advise me in this matter that would be fantastic.

 

Kindest regards,

 

Nathan

  • Sign in to reply
  • Cancel
Parents
  • rew
    0 rew over 11 years ago

    Those leds use a serial protocol to communicate their "color" with the host computer.

     

    The serial protocol uses a bit-time of 1.25 microseconds, or 800kbps. For each led you need to send 24 bits.

     

    If you would write a program that does the GPIO up-and-down things in the right cadence, then the Linux system will mess that up because there are interrupts and maybe other programs that want their slice of CPU-time.


    The only option I can think of is to write a kernel driver.

     

    HO STOP! HACKTIME!

     

    Connect the serial in of the WS2812 to the MOSI pin. Configure the SPI interface for 2.4MHz. Then send an SPI packet: a bunch of zeroes (*) (reset)  and then you encode:  0x1 0y1 0z1 .... the xyz are the bits you try to send, and the 0.1 (*) are the "protocol bits" that the WS2812 wants for synchronization.

     

    Anyway, then the raspberry pi will DMA the data to the SPI port and the signal will be nice and clean without interruptions.

     

     

    (*) I don't remember the polarity of the reset signal and the data bits. The way I've written it here, it can't work, so one or the other needs to be inverted.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • rew
    0 rew over 11 years ago in reply to rew

    Guys, consider me misguided: The raspberry pi SPI implementation skips a clock every byte. There is a gap between each byte. For a synchronous transfer that doesn't matter, but for a timed protocol as the WS2812 it ruins the whole thing.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to rew

    one of the reasons I am suggesting the use of an ATMega micro instead of the PI for the actual control of the LEDs, PI can be used as a Master sending commands to the ATMega to change light pattern etc

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Robert Peter Oakes

    Hi again,

     

    Thank you to all who have been replying to this thread, I feel like I am about to make a breakthrough.

     

    So, progress update:

     

    I have installed nanpy on my Raspberry Pi and I have it hooked up with my Arduino Uno (For now, I have ordered a Nano) and I have successfully been able to light a regular common anode RGB LED on pin 13 and gnd of the Uno.

     

    Now. My next question is how would I write a python script to control the WS2812B LEDs? I am guessing PWM signal would do it?

     

    Thanks again,

     

    Nathan

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 11 years ago in reply to Robert Peter Oakes

    Hi again,

     

    Thank you to all who have been replying to this thread, I feel like I am about to make a breakthrough.

     

    So, progress update:

     

    I have installed nanpy on my Raspberry Pi and I have it hooked up with my Arduino Uno (For now, I have ordered a Nano) and I have successfully been able to light a regular common anode RGB LED on pin 13 and gnd of the Uno.

     

    Now. My next question is how would I write a python script to control the WS2812B LEDs? I am guessing PWM signal would do it?

     

    Thanks again,

     

    Nathan

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to Former Member

    The WS2812B LEDs do not take PWM or even direct LED power, they have a chip built in that you talk to through a data line, serial in and a serial out to be precise

     

    each chip will take 24Bits of the serial data to represent RGB (8 bits each), once it has its 24bits, any more data is passed onto the next LED in the sequence. All this happens at a precise 800Khz

     

    so the code you write on the PI will simply have to decide what color and intensity you want for each LED and instruct the Uno to do that

     

    if you follow the Adafruit library examples your see what I am referring to, nice thing about these chips is you don't need power drivers for them, just give them 5V and then tell them what color you want. DONE.

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube