Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pilotak/python-mcp2221
Python driver for MCP2221A
https://github.com/pilotak/python-mcp2221
adc dac gpio hid library mcp2221 mcp2221a python usb
Last synced: about 1 month ago
JSON representation
Python driver for MCP2221A
- Host: GitHub
- URL: https://github.com/pilotak/python-mcp2221
- Owner: pilotak
- License: mit
- Created: 2021-04-04T09:43:50.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-11-04T06:29:55.000Z (about 2 months ago)
- Last Synced: 2024-11-04T07:25:51.438Z (about 2 months ago)
- Topics: adc, dac, gpio, hid, library, mcp2221, mcp2221a, python, usb
- Language: Python
- Homepage:
- Size: 40 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Python driver for MCP2221/A
[![Build](https://github.com/pilotak/python-mcp2221/actions/workflows/validate.yaml/badge.svg)](https://github.com/pilotak/python-mcp2221/actions/workflows/validate.yaml)
[![PyPI](https://img.shields.io/pypi/v/mcp2221)](https://pypi.org/project/mcp2221/)## Examples
Read GP0
```python
from MCP2221 import MCP2221mcp2221 = MCP2221.MCP2221()
mcp2221.InitGP(0, MCP2221.TYPE.INPUT)
print(mcp2221.ReadGP(0))
```Write GP0
```python
from MCP2221 import MCP2221mcp2221 = MCP2221.MCP2221()
mcp2221.InitGP(0, MCP2221.TYPE.OUTPUT)
print(mcp2221.WriteGP(0, 1))
```Read ADC on GP1
```python
from MCP2221 import MCP2221mcp2221 = MCP2221.MCP2221()
mcp2221.InitGP(1, MCP2221.TYPE.ADC)
mcp2221.SetADCVoltageReference(MCP2221.VRM.VDD)
print(mcp2221.ReadADC(1))
```Write DAC on GP2
```python
from MCP2221 import MCP2221mcp2221 = MCP2221.MCP2221()
mcp2221.InitGP(2, MCP2221.TYPE.DAC)
mcp2221.SetDACVoltageReference(MCP2221.VRM.REF_2_048V)
mcp2221.WriteDAC(12)
```## Tests
```sh
pip install pytest pytest-cov
pytest tests/ --doctest-modules --cov=MCP2221
```