SPI for Dotstar on Metro M4 Express with Circuitpython

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jmroadman
 
Posts: 11
Joined: Sat Nov 27, 2010 1:55 pm

SPI for Dotstar on Metro M4 Express with Circuitpython

Post by jmroadman »

Hello,

I'm having trouble getting SPI to drive Dotstars using the Metro M4 Express and Circuitpython. I can get them to work on D5 and D6 using the bitbanging code, but not the SPI code (nothing happens at all). The only changes I'm making are the data/clock wires between D5/D6 and MOSI/SCK and uncommenting the appropriate definition. Can anyone suggest some troubleshooting to try or see what I'm doing wrong? Thanks! P.S. I'm using a level shifter.

I have an external power supply for the strip and am getting the clock from the SCK pin and data from the MOSI pin on the 6 pin header according to the pinout of: https://learn.adafruit.com/adafruit-met ... 51/pinouts I'm using the circuitpython code from the dotstar tutorial found at https://learn.adafruit.com/adafruit-dot ... ibrary-use

Code: Select all

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import random
import board
import adafruit_dotstar as dotstar

# On-board DotStar for boards including Gemma, Trinket, and ItsyBitsy
# dots = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)

# Using a DotStar Digital LED Strip with 30 LEDs connected to hardware SPI
dots = dotstar.DotStar(board.SCK, board.MOSI, 30, brightness=0.2)

# Using a DotStar Digital LED Strip with 30 LEDs connected to digital pins
# dots = dotstar.DotStar(board.D6, board.D5, 30, brightness=0.2)


# HELPERS
# a random color 0 -> 192
def random_color():
    return random.randrange(0, 7) * 32


# MAIN LOOP
n_dots = len(dots)
while True:
    # Fill each dot with a random color
    for dot in range(n_dots):
        dots[dot] = (random_color(), random_color(), random_color())

    #time.sleep(0.001)

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: SPI for Dotstar on Metro M4 Express with Circuitpython

Post by mikeysklar »

Can you post a photo of your setup so we can verify the MOSI/SCK connections?

Are you using a 30 LED strand?

What version of CircuitPython are you running and is the dotstar library the current release?

Level shifters are not critical so it might be helpful to remove that from the mix.

User avatar
jmroadman
 
Posts: 11
Joined: Sat Nov 27, 2010 1:55 pm

Re: SPI for Dotstar on Metro M4 Express with Circuitpython

Post by jmroadman »

Photos attached, one for SPI and one for bitbanging. In both cases, green goes to the clock of the Dotstar and white goes to the data line of the Dotstar.

I'm using a 60 LED/m strip of LEDs that's 4 m long, but only illuminating the first 30 LEDs. This works fine when bitbanging.

I'm running the stable version 8.0.4 for Circuitpython and the 8.x bundle of libraries.

I've removed the level shifter. It still works for bitbanging but not for SPI.
Attachments
Photo Mar 27, 1 16 43 PM (Small).jpg
Photo Mar 27, 1 16 43 PM (Small).jpg (174.48 KiB) Viewed 92 times
Photo Mar 27, 1 11 59 PM (Small).jpg
Photo Mar 27, 1 11 59 PM (Small).jpg (158.01 KiB) Viewed 92 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: SPI for Dotstar on Metro M4 Express with Circuitpython

Post by mikeysklar »

My guess is that the SCK and MOSI pins could be reversed as the pinout diagram for this board is a little confusing. Can you show wires connected to the DotStar strip?

Note the orientation of the white triangle.
Screenshot from 2023-03-28 14-14-25.png
Screenshot from 2023-03-28 14-14-25.png (31.88 KiB) Viewed 86 times

User avatar
jmroadman
 
Posts: 11
Joined: Sat Nov 27, 2010 1:55 pm

Re: SPI for Dotstar on Metro M4 Express with Circuitpython

Post by jmroadman »

Thanks for the suggestion. I have quadruple checked my connections and I've got data connected to MOSI and clock connected to SCK on the 6 pin header. I even swapped the two to be sure. The data line is the white line in my picture and the clock is the green line.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: SPI for Dotstar on Metro M4 Express with Circuitpython

Post by mikeysklar »

Okay, you have the connections on the Metro M4 correct.

Can you show how the external power supply and dotstars are hooked up?

What dotstar product are you working with from Adafruit? If they are not a model we carry this can happen.

User avatar
jmroadman
 
Posts: 11
Joined: Sat Nov 27, 2010 1:55 pm

Re: SPI for Dotstar on Metro M4 Express with Circuitpython

Post by jmroadman »

Thanks for everyone's help. I found my problem (I think). The problem is with a 8' extension cable I had between the arduino and the Dotstar strip. It worked on the low frequency bitbanging, but wouldn't work on the high frequency SPI signal. Shortening the cable solved the problem.

Now, a follow up question. My setup requires that the arduino be 8' away from the LED (long story), so I need to find a way to extend the cable in the final setup. Right now I'm using 4 conductor strain gauge wire (all 4 are twisted together). Does anyone have experience extending the dotstar cable? What cable topology (twisted pair, coax, etc) worked for you?

Thanks!

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: SPI for Dotstar on Metro M4 Express with Circuitpython

Post by mikeysklar »

Probably worth mentioning there was an 8' cable. High speed SPI is not going to like that.

Is it possible to put the Metro closer and extend the power to it? That can easily run 8'.

You can set the baudrate for SPI hardware with the DotStars. It defaults 4MHz which is 1000x what you had with with the bit-bang SPI 3KHz. Try lowering the speed to 500KHz and see if it can do the 8' run.

Code: Select all

class DotStar(_pixelbuf.PixelBuf):
    """
    A sequence of dotstars.

    :param ~microcontroller.Pin clock: The pin to output dotstar clock on.
    :param ~microcontroller.Pin data: The pin to output dotstar data on.
    :param int n: The number of dotstars in the chain
    :param float brightness: Brightness of the pixels between 0.0 and 1.0
    :param bool auto_write: True if the dotstars should immediately change when
        set. If False, `show` must be called explicitly.
    :param str pixel_order: Set the pixel order on the strip - different
         strips implement this differently. If you send red, and it looks blue
         or green on the strip, modify this! It should be one of the values above.
    :param int baudrate: Desired clock rate if using hardware SPI (ignored if
        using 'soft' SPI). This is only a recommendation; the actual clock
        rate may be slightly different depending on what the system hardware
        can provide.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”