top of page

Building a Data Logger with Adafruit Feather RP2040: Step-by-Step Guide

Aug 30

3 min read

Yong Yin

0

19

0

Introduction


In the world of IoT and embedded systems, data logging is a fundamental application. Whether you're tracking environmental data, monitoring sensor outputs, or simply experimenting with new sensors, having a reliable and easy-to-use data logger is essential. In this guide, we'll walk you through setting up a data logger using the Adafruit Feather RP2040 8MB Flash, a microSD card, and a STEMMA QT/Qwiic connector. By the end of this tutorial, you'll have a working data logger that can read sensor data and store it on a microSD card.


What You'll Need for the Feather RP2040 Data Logger


- Adafruit Feather RP2040 8MB Flash: A powerful microcontroller with ample flash memory and multiple I/O options.

- microSD Card Module: For storing data logs.

- STEMMA QT/Qwiic Sensor: For reading data. We’ll use an example sensor like the Adafruit BME280 for temperature, humidity, and pressure readings.

- Jumper Wires: For connecting components.

- Breadboard: For prototyping connections.

- Adafruit CircuitPython: Programming environment for writing the data logger code.

- microSD Card: A card to store the logged data.


Step 1: Setting Up the Hardware


1. Mount the Feather RP2040 on the Breadboard: Place the Feather board on the breadboard to make connections easier.


2. Connect the microSD Card Module


3. Connect the STEMMA QT/Qwiic Sensor:

- Use a STEMMA QT/Qwiic cable to connect the sensor directly to the Feather’s STEMMA QT port. This simplifies wiring, as the Feather RP2040 has a built-in STEMMA QT connector.


Step 2: Setting Up the Software


1. Install CircuitPython on the Feather RP2040:

- Download the latest CircuitPython UF2 file for the Feather RP2040 from [Adafruit's CircuitPython Downloads](https://circuitpython.org/board/adafruit_feather_rp2040/).

- Connect your Feather RP2040 to your computer via USB.

- Double-tap the reset button to enter bootloader mode.

- Drag and drop the UF2 file onto the "RPI-RP2" drive that appears.


2. Install Required Libraries:

- Download the [Adafruit CircuitPython Bundle](https://circuitpython.org/libraries) and copy the following libraries to the `lib` folder on the Feather:

- `adafruit_bme280.mpy`

- `adafruit_sdcard.mpy`

- `adafruit_bus_device`

- `adafruit_register`

- `adafruit_bitmap_font`

- `adafruit_display_text`

- `adafruit_sht31d.mpy` (if you are using a different sensor)


Step 3: Writing the Data Logger Code


Create a new file named `code.py` on the Feather RP2040. This will be your main program file. Below is a sample code in python to get you started:


import time

import board

import busio

import digitalio

import adafruit_sdcard

import storage

import adafruit_bme280


# SPI setup for microSD

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)

cs = digitalio.DigitalInOut(board.D22)

sdcard = adafruit_sdcard.SDCard(spi, cs)

vfs = storage.VfsFat(sdcard)

storage.mount(vfs, "/sd")


# I2C setup for BME280 sensor

i2c = busio.I2C(board.SCL, board.SDA)

bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)


# Sensor setup

bme280.sea_level_pressure = 1013.25


# Open the file on the microSD card

with open("/sd/data_log.txt", "a") as file:

while True:

temperature = bme280.temperature

humidity = bme280.humidity

pressure = bme280.pressure


# Prepare the data line

data_line = "{:.2f},{:.2f},{:.2f}\n".format(temperature, humidity, pressure)

# Write data to the file

file.write(data_line)

file.flush()


print("Logged:", data_line.strip())

# Wait 5 seconds before logging again

time.sleep(5)


Step 4: Testing the Data Logger


1. Power the Feather RP2040: Connect it to your computer or a battery pack.

2. Check the Serial Monitor: Open a serial monitor to see the data being logged in real-time.

3. Inspect the microSD Card: After running the logger for a while, remove the microSD card and open the `data_log.txt` file on your computer to see the logged data.


Conclusion


Congratulations! You've successfully set up a data logger using the Adafruit Feather RP2040, a microSD card, and a STEMMA QT/Qwiic sensor. This project can be expanded with additional sensors or modified to log data at different intervals, depending on your needs. Whether you're a hobbyist or a professional, this setup provides a flexible and powerful platform for all your data logging projects.


Happy logging!

Comments

Share Your ThoughtsBe the first to write a comment.
bottom of page