Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    NeoPixel driver results

    Scheduled Pinned Locked Moved
    General Discussion
    3
    5
    129
    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.
    • DonStaufferundefined
      DonStauffer
      last edited by DonStauffer

      I've had good results so far with the NeoDriver.

      In order to get around the inability to use M150 to control NeoPixels during printer moves, I got the $7.50 Adafruit NeoDriver card, which receives instructions for the NeoPixels via I2C, and takes care of the critical timing issue for controlling the NeoPixels.

      I have it working now, using M260 to send I2C transactions. It seems to work fine, although I haven't yet had time to test it during printer moves. I think G29 will be my first attempt.

      Once I got the correct transactions, it works as easily as M150 did, though quite differently. As expected, it's slower, but perfectly adequate for progress bars and the like. I'd say an update takes about 100ms. So my chasers go kind of at a moderate speed, not like greased lightning. That's fine for my purposes.

      I'll update this when I have tested during moves. Hopefully the daemon will still operate during moves. That's my main concern.

      Initialization script (run once - maybe from config.g):

      ;   Initializes NeoDriver and turns off LEDs
      
      var FUNC_REGISTER_PIN = 0x01
      var FUNC_REGISTER_SPEED = 0x02
      var FUNC_REGISTER_BUF_LENGTH = 0x03
      ;var FUNC_REGISTER_BUF = 0x04
      ;var FUNC_REGISTER_SHOW = 0x05
      
      var BASE_ADDR_NEO_PIX = 0x0E
      
      ;   Parameters
      
      var I2CAddress = 0x60
      var NeoPixelPinNum = 0x0F
      var LEDCount = 28
      
      if exists(param.A)
          set var.I2CAddress = param.A
      
      if exists(param.N)
          set var.NeoPixelPinNum = param.N
      
      if exists(param.L)
          set var.LEDCount = param.L
      
      ;   Set NeoDriver pin #, speed = 800,000, Buffer size
      
      var BufferSize = 3 * var.LEDCount
      
      M260 A{var.I2CAddress} B{var.BASE_ADDR_NEO_PIX,var.FUNC_REGISTER_PIN,var.NeoPixelPinNum}
      M260 A{var.I2CAddress} B{var.BASE_ADDR_NEO_PIX,var.FUNC_REGISTER_SPEED,1}
      M260 A{var.I2CAddress} B{var.BASE_ADDR_NEO_PIX,var.FUNC_REGISTER_BUF_LENGTH,var.BufferSize,0}
      
      ;   Turn all LEDs off
      
      M98 P"/macros/Lights/NeoPixel/SetNeoPix"
      M98 P"/macros/Lights/NeoPixel/ShowNeoPix"
      
      DonStaufferundefined 1 Reply Last reply Reply Quote 2
      • DonStaufferundefined
        DonStauffer
        last edited by

        SetNeoPix macro:

        ;   Changes NeoPixel LED Color Values
        
        var FUNC_REGISTER_BUF = 0x04
        var FUNC_REGISTER_SHOW = 0x05
        
        var BASE_ADDR_NEO_PIX = 0x0E
        
        ;   Parameters
        
        var I2CAddress = 0x60
        var Red = 0
        var Green = 0
        var Blue = 0
        var StartLEDNum = 0
        var SetLEDCount = 1
        var LEDCount = 28
        
        if exists(param.A)
            set var.I2CAddress = param.A
        if exists(param.R)
            set var.Red = param.R
        if exists(param.U)
            set var.Green = param.U
        if exists(param.B)
            set var.Blue = param.B
        if exists(param.S)
            set var.StartLEDNum = param.S
        if exists(param.N)
            set var.SetLEDCount = param.N
        if exists(param.L)
            set var.LEDCount = param.L
        
        ;   Set LEDs
        
        var StartAddress = 3 * var.StartLEDNum
        
        var Data = vector(7, null)
        
        set var.Data[0] = var.BASE_ADDR_NEO_PIX
        set var.Data[1] = var.FUNC_REGISTER_BUF
        set var.Data[2] = 0
        set var.Data[4] = var.Green
        set var.Data[5] = var.Red
        set var.Data[6] = var.Blue
        
        while iterations < var.SetLEDCount
            set var.Data[3] = var.StartAddress + iterations * 3
            M260 A{var.I2CAddress} B{var.Data}
        
        
        1 Reply Last reply Reply Quote 0
        • DonStaufferundefined
          DonStauffer @DonStauffer
          last edited by

          @DonStauffer ShowNeoPix macro:

          ;   Makes NeoPixel LED Changes Visible
          
          var FUNC_REGISTER_SHOW = 0x05
          var BASE_ADDR_NEO_PIX = 0x0E
          
          ;   Parameters
          
          var I2CAddress = 0x60
          
          if exists(param.A)
              set var.I2CAddress = param.A
          
          M260 A{var.I2CAddress} B{var.BASE_ADDR_NEO_PIX,var.FUNC_REGISTER_SHOW}
          
          dc42undefined 1 Reply Last reply Reply Quote 1
          • dc42undefined
            dc42 administrators @DonStauffer
            last edited by

            Just to be clear, Duet 3 main boards provide a dedicated LED port that can be updated while movement is in progress. Older Duets do not, so they have to bit-bang the LEDs to meet the timing requirements, and that requires movement to be stopped.

            Duet WiFi hardware designer and firmware engineer
            Please do not ask me for Duet support via PM or email, use the forum
            http://www.escher3d.com, https://miscsolutions.wordpress.com

            1 Reply Last reply Reply Quote 0
            • oliofundefined
              oliof
              last edited by

              Still a great achievement to show how to handle I2C peripherals in a more integrated fashion without depending on firmware changes to make them work. Kudos @DonStauffer !

              <>RatRig V-Minion Fly Super5Pro RRF<> V-Core 3.1 IDEX k*****r <> RatRig V-Minion SKR 2 Marlin<>

              1 Reply Last reply Reply Quote 0
              • droftartsundefined droftarts referenced this topic
              • droftartsundefined droftarts referenced this topic
              • First post
                Last post
              Unless otherwise noted, all forum content is licensed under CC-BY-SA