Capability of Tiny 2040

I have in the past successfully used a Plasma 2040 device to control an addressable LED strip. I have a potential application where space is at a premium and wondered if it were even possible to control a short length of addressable LEDs using a Tiny 2040 device to give the same measure of control via a Python programme as I had previously with the Plasma 2040. I am NOT an expert and don’t want to waste a lot of time if for some reason it is not technically feasible.

Thanks

With only a few LEDs, it should work. My success range is about 5-10. Feed the 5V to the LED power and use one of the digitial IO pins for data. If this does not work, try to feed the LEDs from 3V3. Be warned that both is out of specs, but did work for me.

Another option would be to use an Adafruit PixelShifter breakout. Small, and does the same level shifting as the Plasma does.

Thanks bablokb, you will notice from our previous interactions that I am an infrequent user but since the Tiny2040’s turned up yesterday I thought I would make a start. My aim is to embed a few LED’s into an example of my “other” Pastime which is wood turning, hence the need for a physically small device. I am afraid my advancing years mean that my memory is not what it was but I seem to recall that my first step is to download and install some firmware, namely a .uf2 file. Can you point me in the right direction as to which one to use (I assume I get it from Github). Also do I need to download a version of Micropython and same questions, which one and where from? Thanks for any help you can offer,

Mick Farmer

Your memory is correct. If you program in MicroPython, the first thing is to load the MicroPython firmware (in uf2-format) to the device. Not just any version, but a version provided by Pimoroni.

Best start is GitHub - pimoroni/pimoroni-pico: Libraries and examples to support Pimoroni Pico add-ons in C++ and MicroPython.

You will find a lot of links to Getting-Started-Guides, FAQs and other docs there. On the far left you will see a link to the official “Releases”. This is where you download the relevant UF2 file.

@Hel: for the Tiny2040, there is only an 8MB version. I assume the normal “pico”-version will be fine for the 2MB device?!

Yep, that’s correct - you only need the special build for the extra flash.

1 Like

Hi bablokb, thank you for your patience. I have “nuked” my Tiny 2040 and flashed “pico-v1.25.0-pimoroni-micropython.uf2” to it. I then verified that it was basically functional by running Tony Goodhew’s LED control programme to test the on-board LED functionality. I then connected a string of 10 3pin RGB LEDS to the 2040 with the LED 5V connected to Pin1 (VBUS), 0V connected to Pin 2 (Gnd) and the LED data line connected to Pin 6 (I2C bus 1 SDA). I wrote this programme scrap within Thonny with the intention of simply verifying that I could communicate via I2c with the LED strip:-

from machine import I2C, Pin

#Initialise I2C
i2c = I2C(1, scl=Pin(7), sda=Pin(6))
#devices = i2c.scan()
#print(devices)
data = [0,255,0,0]
address = 1
i2c.writeto(address, data)

This fails to run with an error message

Traceback (most recent call last):
File “”, line 9, in
TypeError: object with buffer protocol required

My searches so far lead me to believe that the problem lies with the formatting of the data list which I intended to be the LED index and the relevant RGB values.

Any pointers (even if it is only “stick to woodturning”!!!) would be gratefully received

Thanks

I think the first thing is to clarify the terminology. Since you were talking about the Plasma2040 in your original post, I was assuming that you are talking about addressable LED-strips that are of (one off) WS2812/Neopixel/SK6812/APA102/Dotstar/SK9822 type. These LED-strips have three pins: 5V, GND, data.

There are variants that have another pin, the clock pin. But chances are high you have one of the more common ones above.

These LED-strips are not controlled via I2C. They use their own protocol. You will find an example here: pimoroni-pico/micropython/examples/plasma2040/rainbow.py at main · pimoroni/pimoroni-pico · GitHub

But first read this: pimoroni-pico/micropython/modules/plasma at main · pimoroni/pimoroni-pico · GitHub

Thanks again bablokb, you have given me a lot to think about and absorb. You are correct in that the addressable LED strips are exactly what I am talking about so I take some comfort that what I want to achieve is at least feasible. Why I thought the control mechanism was I2C I really can’t recall. Perhaps I won’t have to sharpen up the bowl gouges and parting tools just yet !!! Thank you again for your perseverance and help.

1 Like

There are a bunch of Pimoroni i2c breakouts etc that that have strings of blinky lights / LED’s on them. Encoder Wheel for example. It’s not hard to get sidetracked and or confused when tinkering with something new. ;) Been there done that. =(

Hi bablokb, I have been busy for a while but have recently had a close look at the schematics for both the Plasma2040 and the Tiny 2040. As far as I can see (and I think you pointed this out) the only significant differences are that the Tiny2040 does not have the 3.3V to 5V level shifter (U3) for both the Data and Clock lines as used on the Plasma2040 and the control outputs for the latter device are taken from GPIO14 and GPIO15 pins of the 2040 chip. My thinking is that if I could access physical pin 18 (GPIO15) of the 2040 chip on the Tiny 2040 and load the Plasma2040 firmware (uf2 file), it ought to be possible to make the Tiny2040 mimic the Plasma2040 with the exception of the functionality associated with the additional buttons and the current sensing. Am I correct in these assumptions or am I missing something ? At present I only have the 2MB version of the Tiny2040 and wondered if this might be a limitation.

Thanks for any help you can offer.

I don’t think you have to go this route (replacing the firmware). As far as I can see, the normal Tiny2040 firmware also has the plasma-library integrated. With the links I gave you in my last post, you can drive the led-strip with almost any pin - you just have to feed in the number into the constructor.

So replace plasma2040.DAT in

led_strip = plasma.WS2812(LEDS, 0, 0, plasma2040.DAT)

with the pin-number you are using. Also note that you usually don’t have/need a clock line.

So take the example code and strip it down to led-strip driving (i.e. remove everything the Tiny2040 does not have like buttons, sensing and so on).

Once again, thank you bablokb for your prompt response, Thats my job for next week! I must confess I wasn’t looking forward to trying to access one of the pins of the 2040 chip with my Weller soldering iron !!!

This is very interesting, following along to see how things pan out. I have a Tiny2040, and a Tiny2350, sitting on my desk doing nothing. I am tinkering with some Tiny FX boards and LED’s. No RGB on those, not yet anyway. I do have a Plasma 2350 with an LED string setup as desktop lighting. Anyway, just tagging alone watching in the background. =)

I hope this is not a misunderstanding: you don’t have to solder one of the pins of the RP2040 chip. You should use one of the pins (throughholes) of the Tiny2040. They are connected to the RP2040 chip. See the pinout on the shop page.

Hi bablokb, I didn’t misunderstand you. If I had wanted to replicate the arrangement of the Plasma2040 I would have had to access one of the pins of the 2040 chip on the Tiny 2040 that is unused. That would have been VERY difficult !!! Thanks for the thought anyway.

Hi bablokb, success!!!

I used the “nuke” facility on the Tiny2040 and then downloaded tiny2040_8mb-v1.25.0-pimoroni-micropython.uf2. I then copied “rainbow.py” as you suggested and modified as the listing below (sorry but I can’t seem to create a listing that keeps the line numbers and correct indentation from Thonny):-

import plasma
#from plasma import plasma2040
import time

Import helpers for RGB LEDs, Buttons, and Analog

from pimoroni import RGBLED, Button, Analog

Press “B” to speed up the LED cycling effect.

Press “A” to slow it down again.

Press “Boot” to reset the speed back to default.

Set how many LEDs you have

NUM_LEDS = 60

The speed that the LEDs will start cycling at

DEFAULT_SPEED = 20

How many times the LEDs will be updated per second

UPDATES = 60

#Pick one LED type by uncommenting the relevant line below:

#APA102 / DotStar™ LEDs
#led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK)

#WS2812 / NeoPixel™ LEDs
led_strip = plasma.WS2812(NUM_LEDS, 0, 0, 6)

#user_sw = Button(plasma2040.USER_SW)
#button_a = Button(plasma2040.BUTTON_A)
#button_b = Button(plasma2040.BUTTON_B)
#led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B)
#sense = Analog(plasma2040.CURRENT_SENSE, plasma2040.ADC_GAIN, plasma2040.SHUNT_RESISTOR)

Start updating the LED strip

led_strip.start()

speed = DEFAULT_SPEED
offset = 0.0

count = 0

Make rainbows

while True:
#sw = user_sw.read()
#a = button_a.read()
#b = button_b.read()

#if sw:
    #speed = DEFAULT_SPEED
#else:
    #if a:
        #speed -= 1
    #if b:
        #speed += 1

speed = min(255, max(1, speed))

offset += float(speed) / 2000.0

for i in range(NUM_LEDS):
    hue = float(i) / NUM_LEDS
    led_strip.set_hsv(i, hue + offset, 1.0, 1.0)

#led.set_rgb(speed, 0, 255 - speed)

count += 1
if count >= UPDATES:
    #Display the current value once every second
    #print("Current =", sense.read_current(), "A")
    count = 0

time.sleep(1.0 / UPDATES)

As you can see, (I couldn’t transfer a video successfully as I couldn’t create it in an acceptable format) I do not use a clock line or external +3.3V to 5V level shifter.

Thanks again for all your help; just a load of programme cleaning up to do now but I have the functionality I want.

1 Like

If you use the Forums Preformatted Text </> option, it will retain the formatting indents etc. ;)

import plasma
#from plasma import plasma2040
import time

# Import helpers for RGB LEDs, Buttons, and Analog
from pimoroni import RGBLED, Button, Analog

# Press "B" to speed up the LED cycling effect.
# Press "A" to slow it down again.
# Press "Boot" to reset the speed back to default.

# Set how many LEDs you have
NUM_LEDS = 60

# The speed that the LEDs will start cycling at
DEFAULT_SPEED = 20

# How many times the LEDs will be updated per second
UPDATES = 60


 #Pick *one* LED type by uncommenting the relevant line below:

 #APA102 / DotStar™ LEDs
 #led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK)

 #WS2812 / NeoPixel™ LEDs
led_strip = plasma.WS2812(NUM_LEDS, 0, 0, 6)

#user_sw = Button(plasma2040.USER_SW)
#button_a = Button(plasma2040.BUTTON_A)
#button_b = Button(plasma2040.BUTTON_B)
#led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B)
#sense = Analog(plasma2040.CURRENT_SENSE, plasma2040.ADC_GAIN, plasma2040.SHUNT_RESISTOR)

# Start updating the LED strip
led_strip.start()

speed = DEFAULT_SPEED
offset = 0.0

count = 0
# Make rainbows
while True:
    #sw = user_sw.read()
    #a = button_a.read()
    #b = button_b.read()

    #if sw:
        #speed = DEFAULT_SPEED
    #else:
        #if a:
            #speed -= 1
        #if b:
            #speed += 1

    speed = min(255, max(1, speed))

    offset += float(speed) / 2000.0

    for i in range(NUM_LEDS):
        hue = float(i) / NUM_LEDS
        led_strip.set_hsv(i, hue + offset, 1.0, 1.0)

    #led.set_rgb(speed, 0, 255 - speed)

    count += 1
    if count >= UPDATES:
        #Display the current value once every second
        #print("Current =", sense.read_current(), "A")
        count = 0

    time.sleep(1.0 / UPDATES)

Hi alphanumeric, seem to have got the indenting OK but still can’t seem to include line numbers. Must be getting old !!!

The line numbers in Thonny don’t clip and past over with the code block. Not for me anyway on my Windows PC.