Labs / Board Reviews & Technical Insights

Designing your first electronic module

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

Contents

1. Development tools

We recommend EasyEDA Standard Edition; it makes simple two-layer boards very convenient.

2. How to design

In short, the steps are as follows:

3. Component selection

Consider the following aspects:

4. Useful websites and tools

5. Some design conventions

For PCB size and shape and connector pin order, refer to the Grove specification:

Grove Ecosystem Introduction

A standardized connection interface definition for embedded development kits: the Grove system

6. Writing the module driver

We recommend writing it in MicroPython. The driver code should be packaged as an easily reusable library file, e.g. sensor.py, providing a Sensor class. The folder structure is shown below:

my_sensor_module/
│── main.py   # Main program, example of how to use the module
│── sensor.py # Sensor driver

Taking the I2C temperature and humidity sensor SHT30 as an example:

import machine
import time

class SHT30:
    def __init__(self, i2c, addr=0x44):
        self.i2c = i2c
        self.addr = addr

    def read_temperature_humidity(self):
        """Read temperature and humidity data"""
        self.i2c.writeto(self.addr, b'\x2C\x06')
        time.sleep_ms(10)
        data = self.i2c.readfrom(self.addr, 6)
        temp = -45 + (175 * (data[0] << 8 | data[1]) / 65535.0)
        hum = 100 * (data[3] << 8 | data[4]) / 65535.0
        return temp, hum

# Usage example
i2c = machine.I2C(1, scl=machine.Pin(22), sda=machine.Pin(21))
sensor = SHT30(i2c)

while True:
    temp, hum = sensor.read_temperature_humidity()
    print(f"Temperature: {temp:.2f}°C, Humidity: {hum:.2f}%")
    time.sleep(1)

Consider pin changes, add error handling, make it non-blocking, handle changes in the communication protocol, and so on.