Tiny 2040. Trouble getting started. (Win10)

Having a bit of trouble getting off the ground!

Got it into “uf2” mode by pressing the switches :-)
I see how that works.
Downloaded: “adafruit-circuitpython-pimoroni_tiny2040-en_GB-7.3.0.uf2” and copied to drive.
LED off. Solid off and then sometimes doing “2 red flashes”.
Copied Tony Goodhews’ variant of light flasher. Still no joy.
My “Lib” directory is empty, but I looked for libraries and did not find anything specific for Tiny 2040.
Using Mu1.1.1, using the “Check” facility there are lots of errors mostly:
“At least 2 spaces before online comment”, applied to lines with rpwm.

So I think (guess) it’s a missing library problem, but which libraries to use and where to get them (looked on Adafruit and it’s not clear to me) :-)

K

I tried this:

Tiny 2040 RBG LED control

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, GPIO.HIGH)
time.sleep(1)
GPIO.output(18, GPIO.LOW)

Every ~5.8 secs I get 2 red flashes.

K

That looks like MicroPython code that you’re trying to run there - try this CircuitPython code! It uses the pwmio library, but I think that should come built into to your CircuitPython image.

It is CircuitPython, and from what I have read that is what I expect, it certainly does not report any missing libraries. Mu Check clears the code too.

So…

What is wrong with me?

There is a custom Pimoroni Micro Python uf2 here.
Release Version 1.18.7 · pimoroni/pimoroni-pico (github.com)

Probably should be linked to from the product page.

Tried that, results in setting up as “UF Drive” and Tiny not being visible as a USB Drive.
Also tried “pimoroni-tiny2040-v1.18.7-micropython.uf2”. Same.

Reloaded with: adafruit-circuitpython-pimoroni_tiny2040-en_GB-7.3.0.uf2

And yes, starting to get to grips with this. So this program now in machine:

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18, GPIO.OUT)
while 1:
GPIO.output(20, GPIO.HIGH)
time.sleep(10)
GPIO.output(20, GPIO.LOW)
time.sleep(10)

Should be looping and flashing lamps. But still 2 red flashes every ~5.8 seconds. Any thoughts?

K

In this example GPIO 18 (red) is setup as an output, but then the loop is controlling GPIO 20 (blue), though since GPIO 20 wasn’t setup as an output it might be treated as a “no-op”.

Edit: some more stuff I thought of

Also python uses indention for scope, so if the code after the “while 1” is not indented (3 or 4 spaces) then it will be outside the scope of the loop.
And the pins for the LED are active low so driving the pin low turns it on, and vice-versa

With Circuit Python you should see a “CIRCUITPY” drive in file explorer.
With Micro Python it will only show up as PI-RP2 when in boot mode.
On the TINY 2040 its an RGB LED which is tied to
GPO 18 Red
GPO 19 Green
GPO 20 Blue
Putting a ground / low on the GPO pin will turn on that color LED on.
It doesn’t work the same way it does on a Pi PICO.
tiny2040.sch (shopify.com)

If you use PWM you can control the brightness and get just about any color you want.

Tony’s file should work with Pimoroni’s Micro Python file. It uses PWM to do the magic.
rpwm = PWM(Pin(18)) # RED
gpwm = PWM(Pin(19)) # GREEN
bpwm = PWM(Pin(20)) # BLUE

Yes I was trying out all pins 18,19 and 20 the paste is from during a change.
Indentation lost due to copy and paste.
Yes. I tried Tony’s file “exactly”. That did the same.
The code (certainly Tony’s should be functional).

So. Let’s try something else…
print(“Hello from Mu”)
MU has a serial console. But I cannot see the printout.
Now. We have a green flash every 5 seconds.

Hi Kerry,

Still struggling to get off the ground!

I would go on Discord, but the link is invalid!.

I’ll post again tomorrow. 🙂, or maybe in a mo.

K

OK. So. First thing. Am I loading the correct UF2 file?
These are my options:
“adafruit-circuitpython-pimoroni_tiny2040-en_GB-7.3.0.uf2” (Source Adafruit) [Seen as a USB drive]
“pimoroni-pico-v1.18.7-micropython.uf2” (Source Adafruit). [Not seen as a USB drive]
“pimoroni-tiny2040-v1.18.7-micropython.uf2” (Source Pimoroni) [Not Seen as a USB drive]
OR
Is there a better on?

If I get that right I may have a chance :-)

K

I have:
print(“I am sort of working”)

producing “I am sort of working” in the Mu serial part of the editor (under Ctrl-d).

The file I just used with my 8MB Tiny2040 is

pimoroni-tiny2040-v1.18.7-micropython.uf2

The LED lit up right after I flashed it, to a light green.

Thonny shows it as “MicroPython v1.18 on 2022-05-16; Pimoroni Tiny 2040 with RP2040”
Interpreter is set to “MicroPython(Rasberry Pi PICO)”
It’s not seen as a USB storage device, which is normal in Micro Python.

Running Tony’s file gets me
white
red
green
blue
flashing blue
and then green that fades to black.
Something like that anyway, it happens quickly.

So. Back to the LEDs.
Code:

Tiny 2040 RBG LED control

import RPi.GPIO as GPIO
import time

print(“Started”)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(20, GPIO.OUT)
while 1:
GPIO.output(20, GPIO.HIGH)
time.sleep(10)
GPIO.output(20, GPIO.LOW)
time.sleep(10)
print(“Looped”)

The runtime error is:
Traceback (most recent call last):
File “code.py”, line 2, in
ImportError: no module named ‘RPi’

Getting there, it is trying :-)

Circuit Python or Micro Python? It makes a difference code wise. Micro Python code will fail on Circuit Python and vise versa.
Plus, the Pimoroni Micro Python uf2 file has extra libraries in it for other Pimoroni Pico addons.

The “pimoroni-pico-v1.18.7-micropython.uf2” is for the 2mb Tiny2040.
And the “pimoroni-tiny2040-v1.18.7-micropython.uf2” is for the 8mb Tiny2049.
Just a FYI post.

Thanks! All helpful :-)

New microcontroller. Stupid old bloke :-)

K.

Anyone know where I can find the “simpleio” library?

If running CircuitPython simpleio should be in the standard library bundles

But I don’t see one for MicroPython