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

    Using WS2812 with LoPy

    Scheduled Pinned Locked Moved LoPy
    lopyws2812github
    13 Posts 8 Posters 3.9k Views 9 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.
    • B Offline
      binux
      last edited by

      Hello everyone,

      I'm trying to drive a 10 leds ws2812 strip with my lopy and I'm kinda stuck. I was looking for a library which was taking the programming work of me. I came across this github project https://github.com/aureleq/wipy-lopy-WS2812 which sounds quiet promising. However I did not succed in getting the leds to show anything. My code looks like the following:

      import pycom
      import time
      from ws2812 import WS2812
      
      print("Disabling heartbeat")
      pycom.heartbeat(False)
      
      chain = WS2812( ledNumber=10, dataPin='P22' ) # connected to G9 on extension board
      data = [
          (255, 0, 0),
          (0, 0, 0),
          (0, 0, 0),
          (0, 0, 0),
          (0, 0, 0),
          (0, 0, 0),
          (0, 0, 0),
          (0, 0, 0),
          (0, 0, 0),
          (255, 0, 0),
      ]
      
      while True:
          chain.show(data)
          time.sleep(4)
      

      Does one already have some experience with this library? Is there a better alternative? Thanks for your help!

      1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino
        last edited by

        Try this one:

        https://github.com/johannesgaa/wipy-WS2812/tree/wipy2.0_support

        1 Reply Last reply Reply Quote 1
        • B Offline
          binux
          last edited by

          I tried. Nothing happened. I used the test.py from the github project.

          1 Reply Last reply Reply Quote 0
          • P Offline
            peekay123
            last edited by

            @jmarcelino, that library is not working for me. The LoPy SPI 0 port is on P11 I believe, not P22. Even with the change of pins, I have not been able to get an 8-led unit going.

            J 1 Reply Last reply Reply Quote 0
            • J Offline
              jmarcelino @peekay123
              last edited by

              @peekay123
              Yes something changed, I couldn't get that library to work for me yesterday. Seems that now when ports are set as SPI you can't do PULL_DOWN as the code is doing.

              I'm away from any WS2812s or test equipment until Wednesday so can't really help with this until then.

              B 1 Reply Last reply Reply Quote 0
              • B Offline
                binux @jmarcelino
                last edited by

                @jmarcelino I ask myself why the pycom led library does not offer the option to control a WS2812 strip. I mean they have one mounted on the PCB a change to support a led strip seems minor to me. Looking forward to know your results on Wednesday

                E 1 Reply Last reply Reply Quote 0
                • E Offline
                  Eric24 @binux
                  last edited by

                  @binux I had the same thought a while back. The code that drives the single status LED should be fairly easy to expand to support a string of LEDs. And doing it that way would save the SPI port for "real" SPI stuff. I think it would be a nice feature.

                  1 Reply Last reply Reply Quote 0
                  • gadgetoidG Offline
                    gadgetoid
                    last edited by

                    I'm not one to grave-dig old topics, but this one isn't that old and seems to turn up in Google for searches about using WS2812 pixels with WiPy/LoPy etc.

                    Upon looking into getting our WS2812-based products up and running with WiPy I came across the libraries listed here, but upon further testing I found some pretty severe problems with how they work.

                    Both of the linked "wipy-WS2812" codebases suffer the same issue; they claim to pack 2bits per byte, when they actually pack 1 bit every 2 bytes and discard half the bits. Running tests that sweep the full range of intensity for any colour channel pretty quickly showed this up.

                    Another example I found for generic MicroPython boards (uses import pyb and pyb.SPI which I believe is either an old paradigm, or one the Pycom does not follow) managed to get the bit packing correct, but failed to disable interrupts. It would update ~8 pixels before an interrupt fired and caused a delay in the SPI output long enough to count as a WS2812 reset.

                    I took the best of both of these examples and merged them into this: https://github.com/Gadgetoid/wipy-WS2812/commit/4288b4b782040053fcfec86fa7644dbec3ceab76#diff-62a17d14021710b4dc4370f193749d1f

                    Much kudos to whoever came up with the 2bits per byte packing optimisation- it's elegant, even if it makes the code ugly.

                    I have tested my code up to 32 pixels on a WiPy 2.0 board, using the SPI MOSI pin (labelled G22 on the breakout) and verified with an oscilloscope that the signal is consistent and uninterrupted.

                    Hopefully someone will find this useful.

                    P 1 Reply Last reply Reply Quote 3
                    • P Offline
                      peekay123 @gadgetoid
                      last edited by

                      @gadgetoid, you library was working very nicely with the previous version of system firmware. I wrote a simple rainbow effects which looked very nice. When I upgraded to 1.9.0.b1, the effect became eratic. I'm not sure where to begin figuring out what the latest update did! Any advice?

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        Devang Sharma
                        last edited by

                        Hello All, I've tried the same library as @binux did. I've used 3 WS2812B LEDs and got no output.

                        My Firmware is: (sysname='LoPy', nodename='LoPy', release='1.9.2.b2', version='v1.8.6-796-g489fafa0 on 2017-10-15', machine='LoPy with ESP32', lorawan='1.0.0')
                        Is this issue solved yet?
                        If not, then is there any way to route the onboard WS2812 LED to the IO?

                        Thanks.

                        B 1 Reply Last reply Reply Quote 1
                        • B Offline
                          binux @Devang Sharma
                          last edited by

                          @devang-sharma I fixed the issue. It looks like the firmware no more requires a "special" data pin for the LoPy.
                          Just use my fork of this library and connect your datapin to P11 (G22) and it should work as expected.

                          https://github.com/binloan/wipy-WS2812

                          1 Reply Last reply Reply Quote 3
                          • M Offline
                            MikeXu007
                            last edited by

                            will it be the same when deal with the ws2813b leds?
                            http://addressable-led.com/Products/WS2813-LED-Chip.html

                            L 1 Reply Last reply Reply Quote 0
                            • L Offline
                              livius @MikeXu007
                              last edited by

                              @mikexu007
                              You can work with same lib

                              think about people first, then computers

                              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