Because I have no pins available on my Wemos D1 mini, I want to drive my Neopixel ring from a MCP23008 I/O expander.

I'm trying to run the 'simple' example from the Adafruit_neopixel library. How do I declare the Neopixel pin number when using say pin 0 on the MCP23008 - or is this impossible?


2 Answers 2


I don't think that will be an option. The NeoPixel parts need very tight control of the timing in order to work, if the pin timing is wrong by 100 us the wrong data will get latched in.

Can you move some other functions / pins onto the IO expander and then drive the neopixels directly from the processor?

  • Thanks Andrew. I thought all chained rgb leds with processors were called neopixels. What I have is 10 x 'WS2812B WS2811 Mini board IC 10mm*3mm DC5V SMD 5050 RGB Leds'. My mistake. Not sure if that makes a difference. Appreciate your thoughts re moving other functions to expander though am using i2c, SPI and need RX/TX for nextion display
    – BobJ
    Commented Jun 26, 2017 at 20:22
  • NeoPixel is the Adafruit marketing name for WS2812 LEDs. You only need 1 pin, exactly what you can move I can't answer without a lot more detail on your system but your best bet would be something slow, a chip select pin or something like that. If your SPI device has a select that would be the obvious choice (or if it's the only SPI device you may be able to wire the select low all the time and save a pin, some devices let you do that, some don't)
    – Andrew
    Commented Jun 27, 2017 at 8:29

I think you will need to write your own library. This isn't as bad as it seems. If the library uses analog write then it won't work, because I don't think you can do PWM with that expander.

The library writes directly to pins. You need to intercept this behaviour and tell the library to tell the MCP230008 to write to the pin. I haven't seen the library I question, but this should be straight forward.

If you take the existing Adafruit library and find where it writes to a pin. Rather than calling digitalWrite it needs to call expanderWrite(pin, state). Every instance of pinMode() needs replacing with explanderPinMode(pin, mode) Then write yourself those two functions that use I2C/SPI to set the IOX's registers to implement what you need.

The IO Expander is not going to be a good idea if the library requires critical accurate timing, because of the lag of telling the IOX to do things. An alternative is to use another D1 as the IO expander.

  • 4
    look at the code for Neopixels: github.com/adafruit/Adafruit_NeoPixel/blob/master/… Both the Adafruit Neopixel and the FASTled libraries are highly optimized for the timing specific RGB leds. Leds with a PWM signal would be no problem, there are many modules that can do PWM. Leds with a clock signal are no problem, they don't use specific timing. It's the timing specific protocol of Neopixels that is a problem.
    – Jot
    Commented Jun 26, 2017 at 14:27
  • Thanks Code Gorilla. I thought all chained rgb leds with processors were called neopixels. What I have is 10 x 'WS2812B WS2811 Mini board IC 10mm*3mm DC5V SMD 5050 RGB Leds'. My mistake. Not sure if that makes a difference re timing issue. ! don't have enough knowledge to amend the library - but many thanks for your suggestions
    – BobJ
    Commented Jun 26, 2017 at 20:34
  • What library are you using to control the LEDs? Commented Jun 27, 2017 at 7:26
  • library is 'Adafruit_NeoPixel' - simple working ide sketch below: #include <Adafruit_NeoPixel.h> #define PIN 2 // pin used for Neopixel #define NUMPIXELS 1 // No. of NeoPixels attached Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); void setup() { pixels.begin(); // Initializes the NeoPixel library. } void loop() { pixels.setPixelColor(0, pixels.Color(255,0,0)); pixels.show();delay(500); pixels.setPixelColor(0, pixels.Color(0,255,0)); pixels.show();delay(500); }
    – BobJ
    Commented Jun 27, 2017 at 8:49
  • Ooops - ide looks a mess - can't see how to include file as an attachment. Can you read it?
    – BobJ
    Commented Jun 27, 2017 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.