Skip to content

Support to mip package manager #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,31 @@ A full example is provided in `/example` directory.

#### 1a - **network-enabled MicroPython ports**

> Warning: in latest MicroPython releases `upip` has been deprecated in favor of [`mip`](https://docs.micropython.org/en/latest/reference/packages.html#package-management). Please use the manual installation until I set up the driver to work with `mip`.
> Warning: in latest MicroPython releases `upip` has been deprecated in favor of [`mip`](https://docs.micropython.org/en/latest/reference/packages.html#package-management). This module is compatible with both of them. Please use the package manager included into your MicroPython version.

To include the library into a network-enabled MicroPython project, it's sufficient to install the package using `upip`:
If your MicroPython version supports `mip` package manager, put these lines **after** the setup of an Internet connection:

```python
import mip

mip.install("github:n-elia/MAX30102-MicroPython-driver")
```

If your MicroPython version supports `upip` package manager, put these lines **after** the setup of an Internet connection:

```python
import upip

upip.install("micropython-max30102")
```

Make sure that your firmware runs these lines **after** an Internet connection has been established.

To run the example in `./example` folder, please set your WiFi credentials in `boot.py` and then upload `./example`
content into your microcontroller. If you prefer, you can perform a manual install as explained below.

#### 1b - **manual way** (no Internet access required)

To directly include the library into a MicroPython project, it's sufficient to copy `max30102/circular_buffer.py`
and `max30102/max30102.py` next to your `main.py` file, into a `lib` directory.
and `max30102/__init__.py` next to your `main.py` file, into a `lib` directory.

The folder tree should look as follows:

Expand All @@ -73,7 +79,7 @@ The folder tree should look as follows:
┣ 📜 boot.py
┣ 📜 main.py
┗ 📂 lib
┣ 📜 max30102.py
┣ 📜 __init__.py
┗ 📜 circular_buffer.py
```

Expand All @@ -83,7 +89,7 @@ Then, import the constructor as follows:
from max30102 import MAX30102
```

To run the example in `./example` folder, copy `max30102/circular_buffer.py` and `max30102/max30102.py` into
To run the example in `./example` folder, copy `max30102/circular_buffer.py` and `max30102/__init__.py` into
the `./example/lib` directory. Then, upload the `./example` directory content into your microcontroller. After the
upload, press the reset button of your board are you're good to go.

Expand Down Expand Up @@ -273,6 +279,9 @@ resolution of 0.0625°C, but be aware that the accuracy is ±1°C.

## Changelog

- v0.4.1
- Changed the module files organization.
- Added support to `mip` package manager.
- v0.4.0
- According to some best practices discussed [here](https://forum.micropython.org/viewtopic.php?f=2&t=12508), some
changes have been made.
Expand Down
17 changes: 12 additions & 5 deletions example/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ def do_connect(ssid: str, password: str):
my_ssid = "my_ssid"
my_pass = "my_password"

# Check if the module is available in memory
try:
from max30102 import MAX30102
except:
print("'max30102' not found!")
except ImportError as e:
# Module not available. Try to connect to Internet to download it.
print(f"Import error: {e}")
print("Trying to connect to the Internet to download the module.")
do_connect(my_ssid, my_pass)
try:
# Try to leverage upip package manager to download the module.
import upip
do_connect(my_ssid, my_pass)
upip.install("micropython-max30102")
except:
print("Unable to get 'micropython-max30102' package!")
except ImportError:
# upip not available. Try to leverage mip package manager to download the module.
print("upip not available in this port. Trying with mip.")
import mip
mip.install("github:n-elia/MAX30102-MicroPython-driver")
Loading