Badger 2040 Tutorial

Hi All,

I notice on the product page it says the tutorial is coming soon. Any idea when?

I’d like to get started with my Badger, and I could do with a starter guide, as I have an open evening at school next week that it would be perfect for!

I know Python well, but haven’t done anything like this.

Thanks in advance,

andy

1 Like

Working on it now, sorry - last week was all a bit of a blur towards the end 😅

Should hopefully have it finished in the next couple of days!

3 Likes

Thanks Hel, much appreciated!
If you need a guinea pig to try it out - let me know!

Andy

Here is a little something to get you started. It covers the LED, text, rectangles, lines, fonts and updates,
Notice that slow updates provide a better image that fast ones. Hope it helps.

# Pimorini Badger 2040 Initial screen test
# Tony Goodhew 2 March 2022
import time
import badger2040

fonts = ["sans","gothic","cursive","serif","serif_italic"]
screen = badger2040.Badger2040()
screen.update_speed(badger2040.UPDATE_NORMAL)  # Slow but very clear
brightness = 255
screen.pen(15)
screen.clear()
screen.update()

screen.led(brightness)
for f in range(5):
    screen.font(fonts[f])

    for v in range (1,6):
        screen.pen(15)
        screen.clear()
        screen.pen(0)
        screen.thickness(1)
        screen.text(fonts[f],80,15,1.0)      # Font Name
        screen.text("Tony", 0, 45, 0.4*v)
        screen.thickness(v)
        screen.text("Goodhew", 0, 100, 1.0)
        screen.text(str(v), 250, 100, 1.0)
        screen.rectangle(180,50,50,50)        
        screen.line(150,120,250,120) 
        screen.pen(15)
        screen.rectangle(182+v,52+v,46-2*v,46-2*v)
        if v == 2 or v == 3:
            screen.update_speed(badger2040.UPDATE_TURBO) # Fast update - fuzzy?
        screen.update()
        if 2*int(v/2) == v:              # Even
            for ii in range(4):
                screen.led(255)
                time.sleep(0.25)         # Blink
                screen.led(0)
                time.sleep(0.25)
        else:                            # Odd
            for ii in range(255):
                screen.led(ii)           # Brightening
                time.sleep(0.01)
        screen.led(0)
        screen.update_speed(badger2040.UPDATE_NORMAL) # Slow but very clear

You can use Thonny to run the program without upsetting the installed demo softare.

Hope this helps.

Tony,
Thank you so much. That’s the first time there LED has lit up. It was mentioned in Kevin McAleer’s video and in a pitch black room mine didn’t light up.
Really appreciate this.
Q

Hi,

I’m hoping for some help connecting the Badger to my Raspberry Pi 4, I’m a bit of a noob when working with boards and such, though I have a bit more experience with actual coding.

I’ve installed Raspbian Bullseye from scratch and it’s running fine on the Pi, and I’ve connected the Badger with a USB cable.

I watched the introductory video on YouTube here First look at Badger 2040 - a super fast E Ink badge powered by RP2040 - YouTube and at 5:57 the presenter plugs the Badger into his Raspberry Pi. In Thonny he can see the device and files under MicroPython devices but when I do that I don’t see the MicroPython device section at all.

If it helps, I ran the command lsusb in Terminal and I can see this entry which suggests the Pi has detected the device:
Bus 001 Device7: ID 2e8a:0005 MicroPython Board in FS mode

Is there a step that I’m missing or do I need to change some settings somewhere? I apologise if it’s something really obvious!

Many thanks.
Michael

I was in the same boat a couple of days ago.
Ended up clicking the far bottom right corner where the version number is, clicked Pico and installed firmware which promptly made the Badger unusable. I’d already downloaded the pimoroni -pico-1.18.2.badger2040-micropython-v1.18.uf2 file from github and flashed it (hold down the boot button when you plug in the Badger) and copied the file across.
It’s probably a great guide on the worst thing to do, but I couldn’t find a guide for my level of experience.

1 Like

Hi FourQ,

Wow, thanks for the quick response!
I just tried changing the interpreter to MicroPython (local) and MicroPython (generic), none of which worked. I left the Pico option alone, thanks for the warning!

I also tried holding down the boot button when plugging it in but now I can’t see the device using lsusb. I’m going to have to read up on what uf2 is first I think.

I agree that we could use a user guide for absolute beginners as well as this device would certainly appeal to beginners but this first step is a stumbling block and could put beginners off. Unless it’s just me missing an instruction somewhere!

Thanks again for the prompt reply, I’d welcome other suggestions as well from other users with similar experiences.
Cheers.
Michael

Please try the following.

Just plug in the the USB cable, to provide power, and then press the reset button on the back. If it flashes the screen and shows “clock fonts ebook” the Badger is OK and you do not need to update the UF2 so keep away from the BOOT button.

Start Thonny, and make sure you see MicroPython (Raspberry Pi Pico) in the bottom right corner of the screen.

Type
print(“Hello Badger”)
onto line one of the editor

Press the STOP red icon
Press the GREEN icon
Save the file to Computer (NOT pico)
Check the message is printed in the bottom window.

If so, all is working

Please let me know what happens. Best of luck.

If you have access to a PC or Laptop try installing Thonny and use that.

Hi Tony,

Thanks for the helpful instructions, I’ll try them tonight and update here how I got on.👍🏼
Michael

Pretty sure it’s ‘Micropython (Raspberry Pi Pico)’ you’ll want to set it to (the confusion FourQ had was down to installing a different firmware, not changing the interpreter in Thonny).

(this is a quick start to talking to pico-ish things in Thonny, just don’t read the custom firmware bit above it!)

Here is a program using the buttons, thickness, size and fonts to try out while waiting for the tutorial.

# Pimoroni Badger 2040 Tutorial example
# How to use buttons, fonts and thickness
# Tony Goodhew (tonygo2) 3 March 2022

import badger2040
import machine
import time
fonts = ["sans","gothic","cursive","serif","serif_italic"]
display = badger2040.Badger2040()
display.update_speed(badger2040.UPDATE_TURBO)
display.pen(15)
display.clear()
display.update()

button_a = machine.Pin(badger2040.BUTTON_A, machine.Pin.IN, machine.Pin.PULL_DOWN)
button_b = machine.Pin(badger2040.BUTTON_B, machine.Pin.IN, machine.Pin.PULL_DOWN)
button_c = machine.Pin(badger2040.BUTTON_C, machine.Pin.IN, machine.Pin.PULL_DOWN)
button_up = machine.Pin(badger2040.BUTTON_UP, machine.Pin.IN, machine.Pin.PULL_DOWN)
button_down = machine.Pin(badger2040.BUTTON_DOWN, machine.Pin.IN, machine.Pin.PULL_DOWN)

message = None
message_y = 60
f = 2
t = 1
running = True

# Instruction page
display.pen(0)
display.font(fonts[3])
display.thickness(3)
display.text("Text & Buttons", 10, 30, 1.0)
display.thickness(2)
display.text("Press U & D = Font", 35, 67, 0.7)
display.text("Press B & C = Thickness", 3, 87, 0.7)
display.text("Press A to halt", 55, 110, 0.7)
for _ in range(2):
    display.update() 

def button(pin):      # This is the interrupt handle
    
    global message, f,t,running
    if message is not None:    
        return
        
    if pin == button_a:
        message = "A"
        display.pen(15)
        display.clear()
        display.update()
        display.font(fonts[3])
        display.thickness(2)
        display.text("Done", 100, 50, 1.0)
        for _ in range(2):
            display.update() 
        display.pen(15)
        display.clear()
        display.font(fonts[3])
        display.thickness(2)
        display.pen(0)
        display.text("Done", 100, 50, 1.0)
        for _ in range(2):
            display.update() 
        time.sleep(3)
        running = False
        display.pen(15)
        display.clear()
        for _ in range(2):
            display.update() 
        return
    if pin == button_b:
        message ="B"
        t = t - 1
        if t < 1:
            t = 1       
        return
    if pin == button_c:
        message = "C"
        t = t + 1
        if t > 6:
            t = 6        
        return
    if pin == button_up:
        message = "U"        
        f = f + 1
        if f > 4:
            f = 4
        return
    if pin == button_down:
        message = "D"
        f = f - 1
        if f < 0:
            f = 0
        return

button_a.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
button_b.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
button_c.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
button_up.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
button_down.irq(trigger=machine.Pin.IRQ_RISING, handler=button)

while running:
    if message is not None:
        display.pen(15)
        display.clear()
        display.pen(0)
        # Print top line in serif and thickness 2
        display.font(fonts[3])
        display.thickness(2)
        display.text(fonts[f], 10, 20, 1.0)
        display.text(" T: "+str(t), 210,20,1.0)
        # Update font and thickness
        display.font(fonts[f])
        display.thickness(t)
        display.text("Tony Goodhew", 5, 80, 1.1)
        for _ in range(2):
            display.update() 
        message = None
    time.sleep(0.1)

Badger 2040 coding documentation is here:

Have fun
Tony

1 Like

Here is an example of dithering:


# Badger 2040 graphics - colours
import badger2040
import machine
import time
fonts = ["sans","gothic","cursive","serif","serif_italic"]
display = badger2040.Badger2040()
display.update_speed(badger2040.UPDATE_NORMAL) # Slow but clearest
# Clear screen to white
display.pen(15)
display.clear()
display.update()
w = 18
# Set up text
display.font(fonts[3])
display.thickness(2)
display.pen(0)

# Centred text heading
space = (display.measure_text("Dither/Colour",0.8))
space = int((296-space)/2)
display.text("Dither/Colour",space,15,0.8)

# Hexadecimal dither colour values
hexa = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"]
w = 18 # Width of bars
for c in range(16):
    display.pen(c)
    display.rectangle(4+18*c,30,18,140)
    display.pen(15)
    if c > 7:
        display.pen(0)
    display.text(hexa[c],6+18*c,60+ c*3,0.6)
display.update()
time.sleep(5)

I hope this helps.

2 Likes

Hey folks,

Tutorial is now up, sorry for the wait 😅

Thanks very much, Hel! Just in time for the weekend! :-)

1 Like

Thank you, Hel. The image conversion in Thonny is a great help.

1 Like

Make sure to grab the new version of the firmware if you haven’t already, there’s some nice improvements in the version that we released yesterday :)

Hi Tony,

Thanks for the detailed instructions, I finally got some time to try these and it’s all working now, hurray!

I find that there’s sometimes just one missing step in some instructions which throws off beginners like me so your help was much appreciated.

Cheers!
Michael

Just tried 1.18.3 and can no longer get the built it demos to run.

With 1.18.2 I could run a script of my own from Thonny and press RESET and your demos would execute. Really great.

With 1.18.3 I cannot get the demos to run when I press RESET. - I can only run my own scripts via Thonny.

I’m going back to 1.18.2

In 1.18.3 the entry point must be a file called main.py.