Skip to content

Commit

Permalink
Support RPI 5 and fix various DoCommand args. Update to use hot reloa…
Browse files Browse the repository at this point in the history
…ding and upgrade meta.json
  • Loading branch information
michaellee1019 committed Dec 15, 2024
1 parent e860573 commit e7a1bee
Show file tree
Hide file tree
Showing 10 changed files with 406 additions and 195 deletions.
3 changes: 0 additions & 3 deletions .env

This file was deleted.

168 changes: 168 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# https://github.com/github/gitignore/blob/main/Python.gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
module.tar.gz

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.installed

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# MacOS Garbage
.DS_Store
77 changes: 63 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# michaellee1019:ht16k33
A Viam module that controls LED segment displays based on ht16k33/vk16k33 chips.
A Viam module that controls LED segment displays based on ht16k33/vk16k33 chips. This module is a Viam wrapper around the [Adafruit_CircuitPython_HT16K33](https://github.com/adafruit/Adafruit_CircuitPython_HT16K33/) library. The model has also been tested and works with the vk16k33 family of components which functionality is similar to the ht16k33.

### michaellee1019:ht16k33
The ht16k33 family of components is a Viam wrapper around the [Adafruit_CircuitPython_HT16K33](https://github.com/adafruit/Adafruit_CircuitPython_HT16K33/) library. The model has also been tested and works with the vk16k33 family of components which functionality is similar to the ht16k33.
## Supported Hardware
- [Adafruit 0.54" Quad Alphanumeric FeatherWing Display](https://www.adafruit.com/product/4261)
- [2Pcs Digital Tube Module Orange 0.54 Inch 4 Digit Tube Module LED Display 4 Digit Tube LED Segment Display Module I2C Tube Clock Display for Arduino](https://www.amazon.com/gp/product/B0BXDL1LFT/)

#### seg_14_x_4
Note: Other hardware may work, but may have different segment mappings to the ht16k33/vk16k33. You should be able to use the `set_digit_raw` command to set the segments for your specific display.

## Model: seg_14_x_4
This component supports 14-segment LED devices that have a four character display in each device. Depending on the device you can chain multiple displays together on the same channel, usually by soldering contacts that change the i2c address. Put each device address into the address array when wanting to string together the characters in each display, in the order that they are physically positioned from left to right.

This model implements the [adafruit_ht16k33.segments.Seg14x4 API](https://docs.circuitpython.org/projects/ht16k33/en/latest/api.html#adafruit_ht16k33.segments.Seg14x4)

Example Config
### Example Config
```
{
"model": "michaellee1019:ht16k33:seg_14_x_4",
Expand All @@ -22,29 +25,75 @@ Example Config
}
```

Example Do Commands:
### Example Do Commands:

#### Marquee
Marquee text across the display once. Repeating marquee is currently not supported.
```
{"marquee":{"text":"MICHAELLEE1019"}}
{
"marquee": {
"text": "MICHAELLEE1019"
}
}
```

Marquee text with a custom time between scrolls, in seconds
{"marquee":{"text":"MICHAELLEE1019","delay":0.1}}
```
{
"marquee": {
"text": "MICHAELLEE1019",
"delay": 0.1
}
}
```

#### Print
Print text onto the display. This method does not clear existing characters so it is recommended to pad the text with space chacters.
```
{"print":{"value":"ELLO POPPET"}}
{
"print": {
"value": "ELLO POPPET"
}
}
```

Print number. Optionally, provide `decimal` to round the number to a specific number of points.
```
{"print":{"value":3.14159265,"decimal":2}}
{
"print": {
"value": 3.14159265,
"decimal": 2
}
}
```

Not working:
{"scroll":{"count":2}}
Note: printing characters onto the display is pushed to the end of the display. If you send a single character, it will be placed in the right most digit, pushing any existing characters to the left. To clear the display, you can send space characters to `print`, or always send a string of characters matching the number of digits in the display.

#### Set Digit Raw
To get finer control over the display, you can set the raw bitmask for a specific digit. `index` is the index of the digit to set (0-3), and `bitmask` is a two byte integer from 0 to 65535 where each bit represents a segment of the display from 1-16.

The most logical way to pass in the `bitmask` is as a binary string. The bits in the string represent a single segment of the display. The bits are ordered depending on the specific wiring of the segments on the display. The usual order is reverse alphabetical such as`N-M-L-K-J-H-G-F-E-D-C-B-A`. You should check the datasheet of the display you are using to confirm the order. Seriously though, there is a ton of variation in how the segments are wired. Some displays will have two "A", and/or two "D" segments, and/or some with two "G" segments. The different display models will have different bit masks.

Using the [Adafruit 0.54" Quad Alphanumeric FeatherWing Display](https://www.adafruit.com/product/4261) for example, the following various bitmasks will light up the display in different ways:

| Bitmask | Result |
| --- | --- |
| `0b000000000000000` | Turn off all segments |
| `0b000000000000001` | Lights up segment A |
| `0b000000000000010` | Lights up segment B |
| ... | ... |
| `0b001000000000000` | Lights up segment M |
| `0b010000000000000` | Lights up segment N |
| `0b100000000000000` | Lights up segment Decimal Point (DP) |
| `0b111111111111111` | Lights up all segments |

Not working:
{"set_digit_raw":{"index":1,"bitmask":24}}
The DoCommand payload to display a 0 on the second digit of a 14x4 display would be:
```
{
"set_digit_raw": {
"index": 1,
"bitmask": "0b000000000111111"
}
}
```

20 changes: 13 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash
apt-get install -y python3.11-venv
python3 -m venv .venv
. .venv/bin/activate
pip3 install -r requirements.txt
python3 -m PyInstaller --onefile --hidden-import="googleapiclient" --hidden-import="viam-wrap" models.py
tar -czvf dist/archive.tar.gz dist/models
#!/bin/sh
cd `dirname $0`

# Create a virtual environment to run our code
VENV_NAME="venv"
PYTHON="$VENV_NAME/bin/python"

if ! $PYTHON -m pip install pyinstaller -Uqq; then
exit 1
fi

$PYTHON -m PyInstaller --onefile --hidden-import=googleapiclient src/main.py
tar -czvf dist/archive.tar.gz ./dist/main ./meta.json
17 changes: 11 additions & 6 deletions meta.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
{
"module_id": "michaelleetest:ht16k33",
"module_id": "michaellee1019:ht16k33",
"visibility": "public",
"url": "https://github.com/michaellee1019/ht16k33",
"description": "A Viam module that controls LED segment displays based on ht16k33/vk16k33 chips.",
"models": [
{
"api": "rdk:component:generic",
"model": "michaelleetest:ht16k33:seg_14_x_4"
"model": "michaellee1019:ht16k33:seg_14_x_4"
}
],
"entrypoint": "dist/main",
"first_run": "",
"build": {
"build": "sh build.sh",
"build": "./build.sh",
"setup": "./setup.sh",
"path": "dist/archive.tar.gz",
"arch" : ["linux/arm64", "linux/amd64"]
},
"entrypoint": "dist/models"
"arch": [
"linux/amd64",
"linux/arm64"
]
}
}
Loading

0 comments on commit e7a1bee

Please sign in to comment.