Skip to content

Commit 1d35ef1

Browse files
authored
Merge pull request #16 from arduino/development
merge development into main
2 parents cfaecf9 + 3d39d9b commit 1d35ef1

File tree

8 files changed

+35
-18
lines changed

8 files changed

+35
-18
lines changed

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This module also wraps machine functions in easy-to-use methods.
77
## Installation
88

99
### mip (MicroPython Package Manager)
10+
1011
This is the recommended method for boards which can connect to Internet.
1112
Run the following MicroPython script using your favourite editor:
1213

@@ -43,7 +44,9 @@ connect(SSID, PWD)
4344
mip.install('github:arduino/arduino-runtime-mpy')
4445

4546
```
47+
4648
### mpremote mip
49+
4750
You will need to have Python and `mpremote` installed on your system, [follow these instructions](https://docs.micropython.org/en/latest/reference/mpremote.html) to do so.
4851

4952
Open a shell and run the following command:
@@ -53,8 +56,8 @@ mpremote mip install "github:arduino/arduino-runtime-mpy"
5356
```
5457

5558
### Manual Installation
56-
Copy the folder `arduino` and its content into your board's `lib` folder using your preferred method.
5759

60+
Copy the folder `arduino` and its content into your board's `lib` folder using your preferred method.
5861

5962
## Usage
6063

@@ -219,10 +222,10 @@ delay(1000) # Delay the execution for 1 second
219222

220223
Some utility methods are provided and are still in development:
221224

222-
* `map(x, in_min, in_max, out_min, out_max)`
223-
Remaps the value `x` from its input range to an output range
224-
* `mapi(x, in_min, in_max, out_min, out_max)`
225-
same as `map` but always returns an integer
225+
* `map_float(x, in_min, in_max, out_min, out_max)`
226+
Remaps the value `x` from its input range to an output range as a float
227+
* `map_int(x, in_min, in_max, out_min, out_max)`
228+
same as `map_float` but always returns an integer
226229
* `random(low, high=None)`
227230
Returns a random number between `0` and `low` - 1 if no `high` is provided, otherwise a value between `low` and `high` - 1
228231
* `constrain(val, min_val, max_val)`
@@ -248,6 +251,6 @@ create_sketch('main')
248251

249252
The method returns the Python file's full path.
250253

251-
### copy_sketch(source_path = '', destination_path = '.', name = None, overwrite = False):
254+
### copy_sketch(source_path = '', destination_path = '.', name = None, overwrite = False)
252255

253-
Wraps `create_sketch()` and provides a shortcut to copy a file to another path.
256+
Wraps `create_sketch()` and provides a shortcut to copy a file to another path.

arduino/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
__author__ = "Murilo Polese"
2-
__credits__ = ["Murilo Polese", "Ubi de Feo", "Sebastian Romero"]
1+
__author__ = "Ubi de Feo"
2+
__credits__ = ["Ubi de Feo", "Sebastian Romero"]
33
__license__ = "MPL 2.0"
4-
__version__ = "0.1.0"
4+
__version__ = "0.4.0"
55
__maintainer__ = "Arduino"
66

77
from .arduino import *

arduino/arduino.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
LOW = 0 # Voltage level LOW
1616

1717
# UTILITY
18-
def map(x, in_min, in_max, out_min, out_max) -> int | float:
18+
def map_float(x, in_min, in_max, out_min, out_max) -> int | float:
1919
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
2020

21-
def mapi(x, in_min, in_max, out_min, out_max) -> int:
22-
return int(map(x, in_min, in_max, out_min, out_max))
21+
def map_int(x, in_min, in_max, out_min, out_max) -> int:
22+
return int(map_float(x, in_min, in_max, out_min, out_max))
2323

2424
def random(low, high=None) -> int:
2525
if high == None:
@@ -63,7 +63,7 @@ def analogRead(_pin) -> int:
6363

6464
def analog_write(_pin, _duty_cycle) -> None:
6565
p = PWM(Pin(_pin))
66-
duty = mapi(_duty_cycle, 0, 255, 0, 65535)
66+
duty = map_int(_duty_cycle, 0, 255, 0, 65535)
6767
p.duty_u16(floor(duty))
6868

6969
if(_duty_cycle == 0):
@@ -82,7 +82,6 @@ def get_template_path():
8282
return '/'.join(__file__.split('/')[:-1]) + '/template.tpl'
8383

8484
def create_sketch(sketch_name = None, destination_path = '.', overwrite = False, source_path = None):
85-
8685
if sketch_name is None:
8786
sketch_name = 'main'
8887
new_sketch_path = f'{destination_path}/{sketch_name}.py'
@@ -112,6 +111,8 @@ def copy_sketch(source_path = '', destination_path = '.', name = None, overwrite
112111

113112
# RUNTIME
114113
def start(setup=None, loop=None, cleanup = None, preload = None):
114+
if preload is not None:
115+
preload()
115116
if setup is not None:
116117
setup()
117118
try:
File renamed without changes.
File renamed without changes.

install.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
#!/bin/bash
22
#
3-
# Install Arduino Runtime to a MicroPython board using mpremote.
3+
# MicroPython Package Installer
4+
# Created by: Ubi de Feo and Sebastian Romero
5+
#
6+
# Installs a MicroPython Package to a board using mpremote.
7+
#
48
# This script accepts an optional argument to compile .py files to .mpy.
59
# Simply run the script with the optional argument:
610
#
711
# ./install.sh mpy
812

13+
# Name to display during installation
914
PKGNAME="Arduino Runtime for MicroPython"
15+
# Destination directory for the package on the board inside the library directory
1016
PKGDIR="arduino"
17+
# Source directory for the package on the host
1118
SRCDIR=$PKGDIR
19+
# Board library directory
1220
LIBDIR="lib"
1321

1422
# File system operations such as "mpremote mkdir" or "mpremote rm"
@@ -86,6 +94,8 @@ for filename in $SRCDIR/*; do
8694
source_extension="${f_name##*.}"
8795
destination_extension=$source_extension
8896

97+
# If examples are distributed within the package
98+
# ensures they are copied but not compiled to .mpy
8999
if [[ -d $filename && "$f_name" == "examples" ]]; then
90100
if ! directory_exists "/${LIBDIR}/${PKGDIR}/examples"; then
91101
echo "Creating $LIBDIR/$PKGDIR/examples on board"

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
"urls": [
33
["arduino/__init__.py", "github:arduino/arduino-runtime-mpy/arduino/__init__.py"],
44
["arduino/arduino.py", "github:arduino/arduino-runtime-mpy/arduino/arduino.py"],
5-
["arduino/template.tpl", "github:arduino/arduino-runtime-mpy/arduino/template.tpl"]
5+
["arduino/template.tpl", "github:arduino/arduino-runtime-mpy/arduino/template.tpl"],
6+
["arduino/examples/00_basic.py", "github:arduino/arduino-runtime-mpy/arduino/examples/00_basic.py"],
7+
["arduino/examples/01_arduino_blink.py", "github:arduino/arduino-runtime-mpy/arduino/examples/01_arduino_blink.py"],
8+
["arduino/examples/02_nano_esp32_advanced.py", "github:arduino/arduino-runtime-mpy/arduino/examples/02_nano_esp32_advanced.py"]
69
],
710
"deps": [],
8-
"version": "0.1.0"
11+
"version": "0.4.0"
912
}

0 commit comments

Comments
 (0)