I’ve been experimenting with a range of PiicoDev products and as suggested programming them through Thonny and using a BBC Micro:Bit V2 as my microcontroller.
I have been having a heap of fun with the distance sensor/ musical instrument and have a few questions…
I was wondering if I can rejig the code to play other musical notes such as A, G, C, B, D, E and F? If so, do I just modify the code?
Before I started playing with the distance sensor, I had the atmospheric sensor programmed in Thonny…
a) do I need to upload the main.py and unified files from each video tutorial or are they the same files for every PiicoDev program?
b) Is it possible to add another motion sensor to the program to eliminate the need to continually hold down button A on the micro:bit and to make this a hands free instrument?
Is there a way to save each project individually in Thonny?
The PiicoDev_Unified.py file handles setting up the I2C communications bus for each of the 3 microcontrollers that PiicoDev is designed to work with, in your case the micro:bit. This is the same file in every PiicoDev tutorial, so you can just leave it in place.
Main.py is a special case as this is a reserved name that your micro:bit will try to run whenever it is powered on. Main.py is different for each of our PiicoDev tutorials so if you wanted to use two different sensors you’ll need to graft bits and pieces from both of the main.py files from the tutorials to make a new main.py that handles the initialisation and logic for both.
Since most of your programs are going to have a main.py in them it’s best to setup a folder for each project on your computer then just keep all the files associated with that project in the same location.
Absolutely, if you’re adding another PiicoDev sensor you’ll just need the driver file for it (eg. PiicoDev_VL53L1X.py is the driver for the distance sensor). Then each sensor will usually have some intialisation that happens once before the main program loop, and a piece of code that is called continuously as your program runs which sits inside the main loop.
That’s right, the example program has some notes defined in the initialisation section, then the number in the code chooses which note should play.
Appreciate you taking the time to respond with such great advice. I’ll be looking into every glue you’ve shared. It’ll keep me busy over the next couple of days. Stay tuned please.
And you can get our latest projects and tips straight away by following us on: