Smart Wooden Box

Way back in the 80s I built a circuit into a small carved Indian wooden box so that when the lid was opened it revealed a star shaped array of red leds that illuminated in a fast repeating pattern from the outside edge to the centre. It was in response to my children’s fascination with the Box of Delights televised at the time. I still have the box, and it still works and my grown up kids still love looking at it.
However, my grandchildren will expect something far more sophisticated. This is where I need help.
I am quite happy to build the box to whatever size is needed to accommodate the electronics but, although I can follow (good) instructions well and can solder quite well, I have absolutely zero skills in designing circuits and understanding components etc. I would like to build something with a micro RGB array so that when the box is opened it triggers a fascinating, hypnotic light show. Any advice or recommendations would be very gratefully accepted.
I will to attach a small clip of the original box in action. Very Heath Robinson!
Thanks all.
Jim
(Couldn’t see how to attach an mp4 file)

The Unicorn Hat HD is 16 x 16 RGB LED’s. It’s a nice square array.
Unicorn HAT HD - 256 * RGB LED Matrix on your Raspberry Pi – Pimoroni
And there is the mini with 17 x 7 RGB LED’s.
Unicorn HAT Mini – Pimoroni
This is 5 x 5
5x5 RGB Matrix Breakout – Pimoroni

And there is bigger
RGB LED Matrix Panel – Pimoroni

I think I may have jumper the gun a bit. I was thinking Raspberry Pi powered but a Micro Controller Like a PICO may be a better option. Power it up and let it do its thing when the door opens, kill the power and turn it off when its closed. You could go battery power and make it cordless, other than recharging it now and then.

If you upload your video to Youtube, or to online storage ( I use my Microsoft OneDrive) you can link to it in your post.

Thanks for the PICO suggestion, alphanumeric. It sounds like it will do the job but I really have no idea how to go about building such a thing (the electronics I mean). Could you point me in the right direction? I did find a project on Maker Pro in which you can control a 16x16 matrix with a smart phone but it’s overkill for what I want and probably a bit too challenging anyway. The same thing without the phone control would be perfect because it could be run from a power bank and therefore start with the opening of the box and stop with closing.
I have ordered a Unicorn Hat HD because it is such a neat package and, I think, pretty much ready to run. What I would like to know is could the raspberry pi be configured to run the Unicorn Hat straight from opening the box, i.e. power on. If it can, I think this is the way to go. What do you think?
Thanks for your interest.

That’s rub when going with an SBC instead of a Micro Controller, and why I had second thoughts. It’s doable, but having an OS in the mix complicates it a little bit.
If it’s completely powered down, you’ll have a delay while it boots up and then runs your python file. Then you have to do a proper shut down if you want to save the battery and not corrupt your SD card.

One way to do it is to use an on off shim
OnOff SHIM (micro-USB) – Pimoroni
Wire up a remote button. Closing the lid presses and holds the button down and initiates the shutdown.
You’d have to get creative with the opening part. You’d need to release the button and then press it again momentarily.

With a Micro Controller, you can just kill the power with no harm. And as soon as you power it back up it does its thing with only a very short pause.

Another way to do it, assuming you know they are coming over. Is a discreetly hidden switch to boot up the pi. Then run the python file when the lid is opened. Just have the lid button ground a GPIO pin. You can do a shutdown the same way with a second button.

I have a portable headless Pi build that’s setup as above. A momentary push button to do the shutdown, and a latching switch to kill the power.

I have several headless Pi builds that I am seriously considering converting to a Pi PICO, over a Pi Zero.

That sounds perfect. The box will only be brought out occasionally to keep the magic so yes, powering it on a little in advance certainly won’t be a problem.I’ll have to get my head round this (new to me) terminology! What’s a headless Pi?
Once again, I’m very grateful for your patient support.
Jim

Headless means no keyboard, mouse or monitor. I have several setups like this.
Pimoroni Pirate Radio, Pirate Radio - Pi Zero WH Project Kit – Pimoroni
Itty Bitty Beat Box, .Build an Itty Bitty Beat Box
Rovers, weather station like setups, the list goes on

An update! The Unicorn Hat Hd arrived this morning and is working beautifully. I can see how perfect it will be for the smart box. What I haven’t been able to discover is how to stop an example script before trying another. I tried control-C in terminal but that didn’t work. Any thoughts on that one? Nor could I find out how to set it up to boot straight into the script soon after power on in headless mode. Once more, your help and advice is needed! Sorry to be such a pain!

If you run the script from an IDE like Thonny, there is a stop option. The screen will freeze with what ever is being displayed, but it will stop running the script. Then just open and run another one to have a look see. There is a python command to stop it but I don’t know what it is?

I do the following to run my python file on boot up.
From terminal run crontab -e
select option 1 for nano
and add
@reboot python3 /home/pi/your_file.py &
ctrl x and y enter

My shutdown routine goes something like this, I call it up in my python file.

    def Shutdown(channel):
        unicornhathd.clear()
        unicornhathd.show()
        os.system("sudo shutdown now -P")
        time.sleep(30)    

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)  
GPIO.setwarnings(False)
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)  
GPIO.add_event_detect(5, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)

You can edit the 5 and make it what ever GPIO you want to use.

Thank you, once again!

Glad to help. With the above code, grounding GPIO 5 runs the shutdown routine. I often use a normally open, momentary contact switch. How its wired and where I put it depends on what I’m building.

I’ve been looking at the Pi Supply switch. It uses pins 7 and 11 with dupont connectors. Is there any reason why I shouldn’t solder the wires from the switch board to pins 7 and 11 on the underside of the Pi pcb? I was wondering if it might conflict with how the Unicorn Hat works. Any thoughts?

On Off Shim? There are two solder pads to solder wires to and use your own button. Over on the end by the BTN.

Pins 7 and 11 are used for monitoring and signaling what to do.

The Pi watches the state of BCM pin 17 and, when pulled low (button has been pressed), it initiates a clean shutdown. Last thing, just before your Pi shuts down, BCM pin 4 is pulled low to tell the On Off Shim to completely cut power to your Pi.

OnOff SHIM at Raspberry Pi GPIO Pinout
Unicorn HAT HD at Raspberry Pi GPIO Pinout
No conflicts that I can see.

The problem with the OnOff shim is that it would need to be mounted below the Unicorn, wouldn’t it? I don’t see how that could be done.
The Pi Supply on/off switch wouldn’t need that.
Am I missing something?

not excatually sure what you doing ,I have a Pi zero in a case with a Phat Dac - onoff shim solder flat to pizero pins ,on off shims button is acceable to me after cuttin a bit out of the case .

Link to the Pi Supply on/off please?

Momentarily grounding GPIO 3, physical pin 5, will have your Pi boot up. Assuming it was shut down and left powered up. And you can have it do a shut by momentarily grounding GPIO 3 with a config.txt edit.
You just add dtoverlay=gpio-shutdown to your config.txt file.
You can use any controllable pin you want for shutdown.
dtoverlay=gpio-shutdown,gpio_pin=17,active_low=1,gpio_pull=up
Uses GPIO 17 (BCM numbering not pin number), I use that with my fan shim to use its button for shutdown.

Pi-supply switch here: