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:
- First, define the module's purpose (e.g. sensor acquisition, motor driving, communication). Then search online for similar modules, make a spreadsheet listing their links, and ask the sellers directly for reference schematics. After choosing the core functional chip based on the reference designs, read the reference circuit section of its datasheet; some also provide layout guidance;
- Second, think through the usage scenario: indoor or outdoor, contact or non-contact. The power interface uniformly uses +5V; if 3V3 is needed, add a 5V-to-3V3 circuit;
- Technical parameters that need to be pinned down must be checked in the datasheet, e.g.: input voltage range, maximum current consumption, sensor accuracy (e.g. ±1°C, ±3%RH) and communication method
3. Component selection
Consider the following aspects:
- Cost: both time cost and money cost. If a cheap chip has no ready-made driver while a slightly more expensive one does, choose the more expensive one; if the price difference is large, choose the cheap one.
- Package: whether to use DIP (through-hole, suited to hand soldering) or SMD (surface-mount, suited to volume production). 0805/0603 packages are recommended for passive components.
- Voltage and current ratings: the input voltage rating of the LDO (e.g. AMS1117-3.3) must be higher than the maximum supply voltage; some drive circuits require a MOSFET/transistor driver stage on the MCU's IO pins.
- Communication: if too many IO pins are used, consider adding an IO expander chip communicating over the IIC bus.
4. Useful websites and tools
- LCSC (LCSC.com): filter by parameters and buy directly.
- LCSC open-source hardware platform (oshwhub.com): reference mature designs and find ones that have been verified.
- GitHub, CSDN, Elecfans forum.
5. Some design conventions
For PCB size and shape and connector pin order, refer to the Grove specification:
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 driverTaking 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.