Giter VIP home page Giter VIP logo

adafruit_neopixel_zerodma's Introduction

Adafruit_NeoPixel_ZeroDMA

DMA-based NeoPixel library for SAMD21 and SAMD51 microcontrollers (Feather M0, M4, etc.) Doesn't require stopping interrupts, so millis() and micros() don't lose time, soft PWM (for servos, etc.) still operate normally.

Requires LATEST Adafruit_NeoPixel and Adafruit_ZeroDMA libraries also be installed (Adafruit SAMD board support automatically includes Adafruit_ZeroDMA).

THIS ONLY WORKS ON CERTAIN PINS. THIS IS NORMAL. Library uses SERCOM peripherals for SPI output, and the hardware only supports this on specific pins (plus, some SERCOMs are in use for Serial, I2C, etc.).

AS OF VERSION 1.2.0: the selection of pins is more restrictive than before, to better avoid collisions with other peripherals (I2C, etc.)...with few exceptions, you can use DMA NeoPixels with impunity. And more boards are supported now.

COMPATIBLE BOARDS AND PINS:

  • Feather M0: pins 5, 6, 12 and MOSI*.
  • Feather M0 Express: pins 6, 12 and MOSI*.
  • Feather M4: pins 12, A2, A4 and MOSI*.
  • ItsyBitsy M0: pins 5, 12 and MOSI*.
  • ItsyBitsy M4: pins 2, 5, 12 and MOSI*.
  • Metro M0 or Arduino Zero: pins 5, 12 and MOSI*.
  • Metro M4: pins 6, 11, A3 and MOSI*.
  • Metro M4 AirLift: pins 6, 11 and MOSI*.
  • Grand Central: pins 11, 14, 23 and MOSI*.
  • HalloWing M0: pins 4 (NEOPIX), 6 and MOSI*.
  • HalloWing M4: pins 6, 8, A5 and MOSI*.
  • MONSTER M4SK: pin 2.
  • PyPortal, PyPortal Titano: pin 3 (SENSE connector).
  • PyGamer, PyGamer Advance: pins 12 and A4.
  • PyBadge, PyBadge AirLift: pins A4, MOSI*.
  • Crickit M0: pins 8, 11, A8 and A11.
  • Trellis M4: pin 10 (keypad NeoPixels).
  • Circuit Playground M0: pin A2.
  • Trinket M0: pin 4 (can't use simultaneously with I2C, SPI or Serial1).
  • Gemma M0: pin D0 (can't use simultaneously with I2C, SPI or Serial1).
  • QT Py: MOSI* and pin 16 (underside pad, can't use w/optional SPI flash).
  • Arduino NANO 33 IoT: pins 4, 6, 7, A2, A3, MOSI*.

* If using the MOSI pin on these boards, the corresponding SPI peripheral is not usable. A few add-ons (usually TFT display shields/wings) rely on SPI, so avoid NeoPixeling from this pin in such situations. MOSI is really only offered anymore to maintain partial compatibility with older projects that might've used the earlier library, which was less selective about such things.

OTHER THINGS TO KNOW:

DMA NeoPixels use a LOT of RAM: 12 bytes/pixel for RGB, 16 bytes/pixel for RGBW, about 4X as much as regular NeoPixel library (plus a little bit extra for structures & stuff).

0/1 bit timing does not precisely match NeoPixel/WS2812/SK6812 datasheet specs, but it seems to work well enough. Use at your own peril.

Have not tested this yet with multiple instances (DMA-driven NeoPixels on multiple pins), but in theory it should work. Should also be OK mixing DMA and non-DMA NeoPixels in same sketch (just use different constructor and pins for each).

Currently this only supports strip declaration with length & pin known at compile time, so it's not a 100% drop-in replacement for all NeoPixel code right now. But probably 99%+ of all sketches are written that way, so it's perfectly usable for most. The stock NeoPixel library has the option of setting the length & pin number at run-time (so these can be stored in a config file or in EEPROM)...but those functions are now considered deprecated, so we should be OK going forward.

adafruit_neopixel_zerodma's People

Contributors

adminius avatar apendley avatar deanm1278 avatar evaherrada avatar hathach avatar justinmbrock avatar ladyada avatar paintyourdragon avatar per1234 avatar siddacious avatar tyeth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_neopixel_zerodma's Issues

Free PIN selection

Hi,
first of all, i know what you mean with:

/*
This table contains the available pins and their corresponding SERCOMs and
DMA-related registers and such. M0 can actually handle SPI DMA on more
pins than are indicated here, but the code design INTENTIONALLY limits it
to specific pins. This is not a technical limit, but a documentation issue.
There are usually multiple pins available for each SERCOM, but each SERCOM
can have only one active MOSI pin. Rather than try to document "If you use
in X, then pins Y and Z can't be used" (and repeating this explanation for
up to four SERCOMs, and that the specific pins can vary for each board),
it's 10,000X SIMPLER to explain and use if one specific pin has been
preselected for each SERCOM. I tried to pick pins that are nicely spaced
around the board and don't knock out other vital peripherals. SERCOM pin
selection is NOT a fun process, believe me, it's much easier this way...
*/

SERCOM <> PIN-relations described here:
https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports/creating-a-new-spi

is it possible to add a new constructor(?) (for experienced user) with sercom and pin parameters, so user can define his own sercom/pin configuration?

e.g. instead of:

Adafruit_NeoPixel_ZeroDMA strip(NUM_PIXELS, PIN, NEO_GRB);
something like that:
Adafruit_NeoPixel_ZeroDMA strip(NUM_PIXELS, &sercom5, SERCOM5, SERCOM5_DMAC_ID_TX, A5, 6, 7, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_2, PIO_SERCOM_ALT, NEO_GRB);

another possibility to define sercomTable[] in a user sketch instead of library and use it (pointer ?) for sercom-definition.

Another question: for example user uses A5 for MOSI, pins 6 and 7 are used for MISO and SCK, that also means, that user can't use pins 6 and 7 for other stuff (like digitalWrite), right?

Library License

I looked through the available source, but I couldn't find a license.

Have I missed something obvious?

multiple DMA objects does not work

Hy

I am using an Arduino Nano 33 IoT with Adafruit neopixel side leds together with an RGBW neopixel stripe and some servos.
The servos trembled when using the "ordinary" neopixel library. Fortunately I found your solution with ZeroDMA. Unfortunately, it does not work with two objects of stripes. Even the pin asignement goes wrong.
I use pins 4 and 7.
If I only use one object, everything goes right for both pins. Only in combination with two objects it does not work.

The NeoPxl8 library I cannot use because I have two different types of neopixels.

Mixing one DMA object with objects from the "ordinary" neopixel library works. But makes no sense. Servo will tremble again.

I really like Adafruit products and bought already a lot of them. I kindly hope Adafruit/someone will find a solution, soon. Also because you wrote, that it theoreticaly should work.
I am also willing to test your solution as soon you have.

If you are doing some work here: My modifyable code plans to update the numbers of pixels, RGB type, etc. AFTER the initialisation of the objects. So the up to now missing update-functions would also be very helpful for me if someone implement them.

Thanks a lot and kind regards
Silvan

Arduino Nano 33 IOT question

So this uses DMA , using SPI , right ?
So can i use my WifiNina library next to it without weird conflicts ? (because i think it talks over SPI also)

And i am trying to find my pinout.
I have this data now :
-The SAMD21 MCU has 6 SERCOM based SPIs. SERCOM1 is available on pins 1, 14, and 15.
-Metro M0 or Arduino Zero: pins 5, 12 and MOSI*.
-the new Nanos have pin mapping similar to classic Nano. so SPI is on pins 10,11,12,13
PIN MKR PIN PIN DESCRIPTION
| 22 | 1 | PA12 | NINA_MOSI
| 23 | 2 | PA13 | NINA_MISO
| 24 | 4 | PA14 | NINA_CS
| 25 | 3 | PA15 | NINA_SCK
Which one , would be my pin , that i use ??

Add to Arduino Library Manager

I have had good success using this library with a Nano 33 IOT BLE, it solved the interrupt problem and works great, once again thank you for developing it.

mrkzero does not work

i used the this lib #include <Adafruit_NeoPixel.h> and used the simple example i managed to get an green led on pin 6.

when i switch to this lib#include <Adafruit_NeoPixel_ZeroDMA.h>
i start the strand example. on pin 5 - Serial.println(strip.begin())gives me 1.
but icant see a light

Compiler Warning

Thank you for this interface. Just started using this great library, really saved me a lot of time. I'm getting a compiler warning, all seems to be working but would like to see if it could be fixed.

Warning:

c:/users/dmyty/appdata/local/arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: changing start of section .bss by 8 bytes

Using:

Version: 2.2.2-nightly-20231224
Date: 2023-12-24T03:10:39.626Z
CLI Version: 0.35.0-rc.7

Copyright © 2024 Arduino SA

Includes are:

#include <ArduinoBLE.h>
#include <Adafruit_NeoPixel_ZeroDMA.h>

Thank you again for all you do.

Add Support For Seeeduino Xiao M0

Does not compile for Seeeduino Xiao M0 (SAMD21) due to this #ifdef not catching the Xiao type:

#ifdef ARDUINO_SAMD_ADAFRUIT
typedef SPIClass SPIClassSAMD;
#endif

The Xiao board library uses SPIClass and not SPIClassSAMD.

After commenting out the ifdef and endif to test, the Xiao crashes. I would love to use this library on the Xiao M0 but I'm not smart enough to modify it myself. Any help would be appreciated!

Adding QT-Py onboard neopixel to pins.h

I had to ditch the usual Adafruit_NeoPixel library for my project so I tweaked pins.h, adding for ADAFRUIT_QTPY_M0:

&sercom3, SERCOM3, SERCOM3_DMAC_ID_TX, 11, SPI_PAD_2_SCK_3, PIO_SERCOM_ALT,

to the sercomTable[] values. Now I can DMA drive the NeoPixel without interfering with my code (see context).

Not working with Metro M0 Express

Running Adafruit_NeoPixel_ZeroDMA on an Adafruit Metro M0 causes the board to crash (main loop stops, USB goes away).

Running versions:

v1.04 Adafruit DMA neopixel library
v1.1.6 Adafruit Neopixel library
v1.0.1 Adafruit Zero DMA library

The following causes the issue (using the on-board NeoPixel of the Metro M0 Express)

#include <Adafruit_NeoPixel_ZeroDMA.h>
Adafruit_NeoPixel_ZeroDMA strip(1, 40, NEO_GRB);

void setup() {
strip.begin();
strip.setBrightness(32);
strip.show();
}

void loop()
{
strip.setPixelColor(0,125,125,0);
strip.show();
delay(2000);
strip.setPixelColor(0,125,0,125);
strip.show();
delay(2000);
}

'class Adafruit_ZeroDMA' has no member named 'isActive'

I get this error when compilig the strandtest example with 1.0.8. I was trying to use the Metro M4 board and the on board neopixel. This error goes away if I roll back to lib version 1.0.7:

error: 'class Adafruit_ZeroDMA' has no member named 'isActive'

 while(dma.isActive()); // Wait for DMA callback, so pixel data isn't corrupted

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.