Labs / MicroPython module projects

Adjustable Square Wave Signal Generator (Based on GraftPort-RP2040 Development Board)(Open Version)

Author: Li Zisheng · Source: FreakStudio open documentation · License: CC BY 4.0

Contents
GraftPort-RP2040 RP2040

Project Description

1. Introduction

1.1 Project Background

Traditional signal generator devices are usually bulky, complicated to operate and expensive.This project is based on the GraftPort-RP2040 development board, and integrates a clock signal generation module based on the SI5351 chip, a 5-way button module based on the PCF8574 and a 0.96-inch SSD1306-OLED module to realize an integrated programmable signal generator system featuring "frequency setting - channel selection - signal output", which addresses the issues of complex operation and poor portability of professional signal source equipment; meanwhile, it incorporates MicroPython lightweight task scheduling and menu interaction mechanisms to deliver a user-friendly operating experience.

1.2 Overview of the Main Functions of the Project

This project is developed based on MicroPython. Its core function is to generate programmable frequency signals via the SI5351 chip, and provide an interactive menu interface through the OLED display. Users can set the output frequency, select the output channel, and control the start/stop of signal output via a 5-way button; it also supports on-board button interrupt to switch task start/stop, has built-in automatic garbage collection to avoid memory leaks, and is equipped with exception capture and rate-limited printing for easier problem locating.

1.3 Applicable Scenarios or Application Area

2. Main Functions

3. Hardware Requirements

3.1 Hardware Required

The project is based on the GraftPort-RP2040 development board as the main controller:

v1.0 2020

The other required modules include:

5 SIS351 I2C PCF8574 SY7656 0.96 SSD1306-OLED

3.2 Hardware Connection

PCF8574 5-way key module: connect it via PH2.0 connecting cable to the I2C expansion module;

0.96-inch SSD1306-OLED module: connected to the PH2.0 connecting cable I2C expansion module;

6-channel 12C Direct Connection Expansion Module: Connect to the PH2.0 connection cable I2C0 interface

RP2040 I2C I2C0 I2C1 PCF8574 0.96 SSD1306-OLED PH2.0 6

GtaftSense-SI5351 Programmable Clock Generator Module: connected via PH2.0 connecting cable to I2C1 interface;

PH2.0 I2C0 PCF8574 0.96 SSD1306-OLED 6 12C

Lithium Battery Charge and Discharge Module: BAT interface connects to the lithium battery, and the OUT interface supplies power to the main control board via a PH2.0-2P connection cable.

PH2.0 2P
GraftPort-RP2040 M3
Adjustable Square Wave Signal Generator (Based on GraftPort-RP2040 Development Board)(Open Version)

3.3 Structural Assembly

First, use M3 plastic pillars to fix each module and the main control board to the bottom plate of the housing (M3 screw holes are pre-drilled on both the main control board and the housing):

GraftPort-RP2040 M3
GraftPort-RP2040 M3

Next, secure the periphery of the housing with M3 plastic pillars, then screw in M3 screws at the corresponding positions to complete the assembly:

GraftPort-RP2040 M3 3.3

3.4 Notes

When the main control board is not connected to an external watchdog module, the RUN DIP switch 2 must be turned on:

GraftPort-RP2040 2

The lithium battery charge-discharge module supports power level display, and you can charge it via the Type-C interface below:

2024-06 3000mAh 3.7V

4. Software Environment

5. File Structure

square_wave_generator
├─ .flake8
├─ LICENSE
├─ README.md
├─ tools
│  ├─ dependency_analyzer.py
│  ├─ mpy_compiler.py
│  ├─ mpy_uploader.py
│  └─ README.md
├─ firmware
│  ├─ board.py
│  ├─ boot.py
│  ├─ conf.py
│  ├─ main.py
│  ├─ tasks
│  │  ├─ maintenance.py
│  │  ├─ sensor_task.py
│  │  └─ __init__.py
│  ├─ libs
│  │  ├─ __init__.py
│  │  ├─ scheduler
│  │  └─ oledmenu
│  └─ drivers
│     ├─ __init__.py
│     ├─ ssd1306_driver
│     ├─ si5351_driver
│     └─ pcf8574keys_driver
└─ examples
   └─ README.md

6. Description of Key Documents

7. Core Ideas of Software Design

GraftPort-RP2040
GraftPort-RP2040 20ms 1 2 3 4 1000Hz

8. Instructions for Use

8.1 Hardware Connection

Connect the main control board, each sensor module and the battery according to the connection method specified in the "hardware requirements";

8.2 Run the Project (Using PyCharm + MicroPython Plugin)

Open PyCharm and install the corresponding MicroPython plugin.

1.45 2024.1

In the plugin, select Target Device (Target Device) as RP2040, and enable Auto-detect device path (Auto-detect device path).

RP2040

Set Project/firmware as the project root directory.

8.1

Modify the runtime configuration:

Adjustable Square Wave Signal Generator (Based on GraftPort-RP2040 Development Board)(Open Version)

Click the IDE green triangle button in the upper right corner to run, and you can start uploading the firmware and executing the project.

Adjustable Square Wave Signal Generator (Based on GraftPort-RP2040 Development Board)(Open Version)

8.3 Modification of Running Configuration

You can configure conf.py to modify or add parameters as needed, for example:

# conf.py example configuration
I2C_INIT_MAX_ATTEMPTS = 3      # Maximum number of sensor initialization retries
I2C_INIT_RETRY_DELAY_S = 0.5   # Interval between retries (seconds)
ENABLE_DEBUG = True            # Whether to enable debug printing
AUTO_START = True              # Whether to run tasks automatically at startup

8.4 Functional Testing

Turn on the VBAT battery power switch located below the main control board, and you will see the power indicators on the main control board and the module light up:

GraftPort-RP2040 DS1202Z-E 2 1 12.0MHz 1.200ns 12MHz

When conf.py is configured unchanged and the hardware connection is normal, the program can run properly.

The terminal output is as follows:

I2C 2 0x20 0x3c 1.0 output-1 output-2 11MHz 12MHz 8.4

8.5 Debugging and Troubleshooting

9. Sample Program

There are no other reference sample codes for this project, you can directly make modifications in the firmware folder.

10. Notes

11. Version Record

12. Contact the Developer

If you have any questions or need assistance, please contact the developer via the following channels :
📧 Email: 10696531183@qq.com
💻 GitHub: https://github.com/FreakStudioCN

13. Licensing Agreement

In this project, except for machine and other MicroPython official modules (MIT License), all driver and extension codes written by the author are released under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) Licensing Agreement.

You are free to:

Only the following conditions shall be complied with:

Copyright © FreakStudio. All rights reserved.

Appendix 1: Project Source Code Download

https://github.com/FreakStudioCN/GraftPort_MicroPython_Labs/tree/main/square_wave_generator

Appendix II: Reference Materials for hardware Modules

GraftSense-SI5351 Programmable Clock Generator Module

GraftSense-PCF8574 5-direction Button Module

GraftSense 0.96-inch SSD1306 OLED Module

GraftSense 6-Channel 12C Direct Connect Expansion Module

GraftSense-SY7656 Lithium Battery Charge-Discharge Module

GraftPort - Raspberry Pi Pico Expansion Board (Open Edition Template Files)

Version Record

Document Version

Date of Revision

Modifier

Revised Content

V1.0.0

2025-11-03

Hou Junhan

Draft the initial version of the document.

V1.1.0

2026-01-04

Li Zisheng

Final version.