G'day and welcome to the guide video for the Makerverse microSD Card Module. In this video, we'll be connecting the microSD Card Module to a Raspberry Pi Pico and making a simple data logger.
Let's get started. The first thing we're going to need to do is to insert a FAT32 formatted microSD Card into the module.
Next, we're going to get the Megaverse microSD Card Module and plug it into a breadboard. If you open up the guide to this video, you'll see that there are six connections that you need to make. A power and a ground, and then four connections which make up what's called an SPI bus for the microSD Card Adapter.
We'll start by plugging in the power connections. We'll take a red wire and plug this into either the 5 volts or the 3.3 volts of the microSD Card Module. We'll just go with the 5 volt input and connect that to the 5 volt output on the VBUS pin of the Raspberry Pi Pico. Next, we'll get a black wire and connect that to the ground pin on the microSD Card Module and then the ground pin on a Raspberry Pi Pico. For our ground pin, we'll take this pin here, which is the third one in from the top left.
Next come the four wires which make up the SPI bus for the microSD Card. Looking at the guide, there's one sentence at the bottom of the connections section that says we're going to be using pins 12, 13, 14 and 15. We'll take our next wire and connect that to the CS or chip select line of the microSD Module and connect that to the fourth pin from the right on the bottom row on the Raspberry Pi Pico. One, two, three, four.
Next we'll connect the MOSI or Master Outslave In connection from the microSD Card. We'll plug in a wire there into the MOSI pin and this goes to GP15 on the Raspberry Pi Pico. This happens to be in the bottom right hand corner here.
Next we're going to make the clock connection. The clock pin is
It's now time to plug in the Raspberry Pi Pico into your PC and open up Thonny. With the power connected, you'll be able to see a faint green glow coming from underneath the microSD Card Module. This is the power LED. In order to use a microSD Card in MicroPython on the Raspberry Pi Pico, you're going to need to download one file. Scrolling down to the guide where it says Downloading MicroPython Modules, right click on the sdcard.py link and click Save Link As. Then copy that file onto your Raspberry Pi Pico.
If you haven't used the Raspberry Pi Pico with Thonny before, you can check out our guide. With sdcard.py downloaded to the Raspberry Pi Thonny, it's time to scroll down in the guide. Find the section that says Initializing an SD Card, scroll down a little bit more and then copy the first example from that section into Thonny. With the code copy pasted, you can then save it as main.py on the Raspberry Pi Pico. Pressing CTRL R to run this code will then mount the microSD Card's file system so it can be accessed from the Python code running on the Pico.
If everything's being connected correctly, you'll then see a file listing of what's on the microSD Card printed to the console. In this case, we just have System Volume Information, which is a Windows specific folder, and ADCData.txt, which is a file left over from the example we're going to run later. In order to see this on the Raspberry Pi Pico's file list, you need to click the three horizontal lines here and click Refresh.
Let's go over the connections. We have labelled CLK on the microSD Module and this goes to pin 14 on the Raspberry Pi Pico which just happens to be the second one in on the bottom right there. The last connection is the MISO or Master In Slave Out. We'll connect a wire there to the microSD Card and this goes to GP12 on the Raspberry Pi Pico which happens to be this one right there.
We have a quick look at what this code is doing. First, we define an SPI variable. This is just going to be the SPI bus that we're going to be using to talk to the microSD Card. This comes from the SPI part of the machine package. We're going to be using SPI number one, and then we define what pins we're going to be using for this SPI bus. The next line defines a CS or chip select pin, and then below that, we create our SD object from the SDCard.sdcard function. It gets passed the SPI peripheral we're using and the chip select pin.
Next, we call the mount function from the UOS module. This tries to mount the SD card that we've just initialized to the path slash SD. Then we do a listing of what's in the slash SD folder, and that will list all the files that are on the microSD Card.
Now that we know that the microSD Card is working, it's time to make our simple data logger. Opening up the guide, scroll down a little bit further to the section that says Data Logging, and then copy the code example from there into Thonny just as we did before. The first part of this code example is very similar. It's almost exactly the same as what we had before. Below this, we define the ADC object because we're going to be reading values from the analog to digital converter and logging them to a text file on the microSD Card.
Next, we have this big section here that starts with with open. This defines the file on the SD Card that we're going to be writing to, and then below that, we have an infinite loop that reads values from the ADC, calculates a timestamp, and then writes a single line per sample. These lines are made up of the time converted to a string, then a space, then our ADC value converted to a string, and then a new line. Last, we call flush because this forces writing of the data that's in the internal buffer to the physical SD Card.
We are going to use a potentiometer as a source of test data and wire it up to one of the ADC inputs on the Raspberry Pi Pico. To do this, we will connect the red wire to one side of the potentiometer and the other end to the 3.3 volt output on the Raspberry Pi Pico (the fifth pin in from the top left corner). We will then take another cable and connect it to the other side of the potentiometer and to a ground pin. Lastly, we will connect the middle of the potentiometer to GP26 on the Raspberry Pi Pico.
Once the potentiometer is connected, we can press Control-R in Thonny and the code will start running. We will see timestamps and sample numbers printed to the console and written to the file on the microSD card. Turning the potentiometer knob will cause the ADC values in the debug output to vary. When we are done, we can press Control-C and double-click ADCdata.txt in the SD folder to compare the data written to the file to the data printed to the console. We can then remove the microSD card and plug it into a PC to do our own data analysis.
A print of the time and the ADC value is just made to the console purely for debugging purposes. Lastly, we sleep for 500 milliseconds just so it's not hammering the SD Card with data.
We hope this has given you some good ideas for your own projects. If you make something cool, or just have a question, leave a comment on the article for this video.
Makers love reviews as much as you do, please follow this link to review the products you have purchased.