|
1 |
| -# MicroPython Log to a SD Card Example |
| 1 | +# MicroPython - Logging to a SD Card |
| 2 | + |
| 3 | +Leveraging the flexibility of MicroPython, this example demonstrates how to access a SD Card, collect (simulated) sensor data efficiently and write the information in a JSON format to a file on the the system SD Card as well as print out the results to a connected serial console. |
| 4 | + |
| 5 | +The key elements shown in this example include: |
| 6 | + |
| 7 | +- Mounting the on-board SDCard and determining if a SD Card is inserted on the device |
| 8 | +- Opening a file for writing on the SD Card |
| 9 | +- Implementing a logging loop that orchestrates the recording and output of sensed information. |
| 10 | +- Gathering sensor data in a python dictionary and writing this information in a JSON format. |
| 11 | +- Detecting a board type at runtime. |
| 12 | + |
| 13 | +## Requirements and Setup |
| 14 | + |
| 15 | +### Supported Development Boards |
| 16 | + |
| 17 | +Currently this example is setup to run on the following development boards running MicroPython: |
| 18 | + |
| 19 | +- [SparkFun IoT RedBoard - RP2350](https://www.sparkfun.com/sparkfun-iot-redboard-rp2350.html) |
| 20 | +- [SparkFun IoT RedBoard - ESP32 MicroPython](https://www.sparkfun.com/sparkfun-iot-redboard-esp32-micropython-development-board.html) |
| 21 | +- [Teensy 4.1](https://www.sparkfun.com/teensy-4-1.html) |
| 22 | + |
| 23 | +### SD Card |
| 24 | + |
| 25 | +A FAT formatted SD card inserted into the Development Board. |
| 26 | + |
| 27 | +A great option for this is the [1GB SD Card](https://www.sparkfun.com/microsd-card-1gb-class-4.html) at SparkFun. |
| 28 | + |
| 29 | +## Install the Demo |
| 30 | + |
| 31 | +The demo Python source code must be installed on the development board. This is either peformed using a MicroPython enabled IDE (such as [Thonny](https://thonny.org) or [PyCharm](https://www.jetbrains.com/pycharm/download/?section=mac)). |
| 32 | + |
| 33 | +> [!NOTE] |
| 34 | +> For development boards that access the SDCard via a SPI connection (such as the SparkFun Line of IoT RedBaords), the MicroPython `sdcard` library must be available. If not included in the MicroPython firmware, this library is easily installed using the MicroPython tool [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html). |
| 35 | +> |
| 36 | +> To install the library, connect your MicroPython development board to your computer and issue the following command in a terminal window: |
| 37 | +> ```mpremote mip install sdcard``` |
| 38 | +
|
| 39 | +## Running the Demo |
0 commit comments