Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    ws2812 LED library working

    Scheduled Pinned Locked Moved Comments & Feedback
    8 Posts 3 Posters 56 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      johnmcdnz
      last edited by

      Just want to give some thanks to @robert-hh for the ws2812 library at
      https://github.com/robert-hh/WS2812

      I tried some other libraries for neopixel and micropython but couldn't get them to work with the Lopy. But this one works a charm.
      I connected an oscilloscope to the SPI pin and the issue seems to be signal timing. The faulty libraries are sending data with an equal high:low ratio, whereas the ws2812 documentation is clear that the ratio is something like 1:2 (low) or 2:1 (high).

      Anyway, I'm making progress now.

      J 1 Reply Last reply Reply Quote 1
      • J Offline
        johnmcdnz @johnmcdnz
        last edited by

        @robert-hh I have your library working, however I find that the memory buffer is used up quite quickly. This limits operation to about 20 LEDs in a string. This is with a Gpy device.

        Can you comment if you had similar experience? I'd like to know if there's a way to get the string upto 60 LEDs if possible.

        Also out of curiosity, can the LED string be wired onto the PIN P2, i.e in parallel to the RGBled on the board? Not yet tried this.

        Cheers, John McD.

        robert-hhR 1 Reply Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @johnmcdnz
          last edited by

          @johnmcdnz Indeed, the rmt version is quite memory hungry, due limitations of the rmt API. It should be possible to reduce that to a half, by not submitting the (1,0) tuple. I'll test that.
          You should be able to connect the WS2812 to P2. The the onboard LED and the first LED in the external chain will have the same color. You should disable heartbeat then. Otherwise, the first heartbeat pulse will clear your chain.

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @robert-hh
            last edited by robert-hh

            @robert-hh There is a new version on github now which almost halves the memory required by the driver. Reducing it more would require a change in the rmt module also accepting arrays as argument. At the moment it's tuples only, which use a lot of space.

            Edit: There is an SPI example of the driver, which uses way less space. But the timing is not very reliable. It disables the interrupt, which may cause a problem for long chains.

            1 Reply Last reply Reply Quote 2
            • L Offline
              livius
              last edited by livius

              @robert-hh
              I have looked at your good library and i have created immutable verison WS2812_immutable with less memory consumption.
              https://github.com/livius2/WS2812/blob/master/ws2812.py

              I do not have now leds to test but maybe it work without modification. Someone can test and send feedback
              I will test it when i back to place with leds.

              only difference is that you must say how many pixels you have at start:

              ws2812 = ws2812.WS2812_immutable(24, "P11")
              

              think about people first, then computers

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @livius
                last edited by robert-hh

                @livius Thank you for the change. It seems to have crossed with the change I made, dropping the usage of the (1,0)..... tuple totally. See:
                https://github.com/robert-hh/WS2812/blob/master/ws2812.py
                But you might have noticed that already.
                Edit: I see that you pre-allocate the intermediate bytearray too. That seems reasonable since most of the time this class is used with a single LED array.

                L 1 Reply Last reply Reply Quote 0
                • L Offline
                  livius @robert-hh
                  last edited by

                  @robert-hh said in ws2812 LED library working:

                  It seems to have crossed with the change I made,

                  he he :) i have forked your repo some time ago and i miss that you changed it ;-)

                  I have "merged" now your change and introduce resize method to my class to be more flexible
                  now the name immutable was removed and it become simply WS2812

                  think about people first, then computers

                  robert-hhR 1 Reply Last reply Reply Quote 1
                  • robert-hhR Offline
                    robert-hh @livius
                    last edited by

                    @livius Thanks. That looks fine. The biggest memory sinkhole is still this tuple(self.duration). It is four times the size of the initial bytearray, since every element is stored as 4 byte integer, plus 32 byte header.

                    1 Reply Last reply Reply Quote 0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • 1 / 1
                    • First post
                      Last post

                    Pycom on Twitter

                    Pycom