This project is a comprehensive micropython supported board GPIO control system, featuring functionalities for controlling GPIO pins, interacting with I2C and SPI devices, and handling events with power management options. The system is designed to be highly extensible, allowing users to easily add new functionalities or modify existing ones. It supports both digital and analog I/O operations, I2C device communication, and SPI data transfer.
- Digital I/O Control: Read from and write to GPIO pins configured as digital inputs or outputs.
- Analog I/O Control: Read analog values from ADC pins and write analog values to DAC pins.
- I2C Communication: Scan for devices on the I2C bus, read from and write to I2C devices with configurable retries.
- SPI Communication: Perform data transfer with SPI devices, including error handling and retries.
- Command Parsing: Execute commands via a built-in command parser for easy interaction with the system.
- Event Handling: Schedule events and handle them efficiently, with integrated power management features.
- Power Management: Support for light and deep sleep modes to conserve power during inactivity.
- Extensibility: Easily extend the system with new features or modifications.
- Micropython supported Development Board
- Micro-USB Cable for power and programming
- I2C Devices (optional)
- SPI Devices (optional)
- Breadboard and Jumper Wires for prototyping
- Python 3.x installed on your machine
- Thonny IDE or any other MicroPython-compatible IDE
- MicroPython Firmware installed on your Micropython supported Development Board board
-
Install MicroPython on Micropython supported Development Board:
- Download the latest MicroPython firmware for Micropython supported Development Board from here.
- Flash the firmware to your Micropython supported Development Board using esptool or the Thonny IDE.
-
Upload the Project Code:
- Open the provided
.py
file in Thonny or your preferred IDE. - Connect the Micropython supported Development Board to your computer.
- Upload the code to the board.
- Open the provided
-
Power on the Micropython supported Development Board:
- Connect your Micropython supported Development Board to a power source using the Micro-USB cable.
-
Open a Serial Monitor:
- Use the Thonny IDE or a serial terminal (e.g., PuTTY) to connect to the Micropython supported Development Board's serial port.
-
Interact with the System:
- Once connected, you'll be greeted with a GPIO table and a list of available commands.
- You can now begin executing commands as described in the "Command Reference" section below.
digital_write(pin, value)
: Write a digital value (0/1) to the specified GPIO pin.>>> digital_write(2, 1)
digital_read(pin)
: Read a digital value (0/1) from the specified GPIO pin.>>> digital_read(2)
analog_read(pin)
: Read an analog value (0-4095) from the specified ADC pin.>>> analog_read(34)
analog_write(pin, value)
: Write an analog value (0-255) to the specified DAC pin.>>> analog_write(25, 128)
i2c_scan()
: Scan the I2C bus and return the detected device addresses.>>> i2c_scan()
i2c_read(addr, nbytes, timeout=1000, retries=3)
: Read a specified number of bytes from an I2C device at the given address, with optional timeout and retries.>>> i2c_read(0x3C, 4)
i2c_write(addr, data, timeout=1000, retries=3)
: Write data to an I2C device at the given address, with optional timeout and retries.>>> i2c_write(0x3C, b'\x00\x01')
spi_transfer(mosi_pin, miso_pin, sck_pin, data, timeout=1000, retries=3)
: Perform SPI data transfer with specified pins, data, and optional timeout and retries.>>> spi_transfer(18, 19, 23, b'\x01\x02\x03')
sleep_mode(mode)
: Enter either light or deep sleep mode. Valid modes are"light"
and"deep"
.>>> sleep_mode("light")
schedule_event(callback, delay_ms)
: Schedule an event to be executed after the specified delay in milliseconds.>>> schedule_event(callback_function, 1000)
gpio_table()
: Print the GPIO table, showing available pins and their functions.>>> gpio_table()
help()
: Display the list of available commands and their usage.>>> help()
This project is designed to be extensible, allowing you to add new features or modify existing ones. To add a new command:
- Define a new method in the appropriate class (e.g.,
GPIOControl
,I2CControl
,SPIControl
). - Register the new command in the
CommandParser
class by adding it to theself.commands
dictionary. - Test the new functionality using the serial monitor.
To conserve power, the system supports both light and deep sleep modes. Use the sleep_mode
command to put the Micropython supported Development Board into sleep mode. The system will automatically wake up after the specified duration or based on external interrupts.
The system includes basic error handling for I2C and SPI communications, with retries to ensure reliability. If an error occurs during command execution, an error message will be displayed in the serial monitor. Use these messages to debug issues or refine command logic.
Contributions to this project are welcome. If you find a bug or have a feature request, feel free to open an issue or submit a pull request. Please ensure that your code follows the style and conventions used in the project.
This project is licensed under the MIT License. See the LICENSE
file for more details.
This project was developed with inspiration from various open-source MicroPython projects. Special thanks to the MicroPython community for their continuous support and contributions.