Skip to content

[PXCT-779] MicroPython Runtime Package tutorial #2457

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

karlsoderby
Copy link
Contributor

What This PR Changes

  • Tutorial covering installation and getting started with runtime
  • Common examples added (analogRead, digitalWrite etc.)
  • API added (summary table + detailed section)

Contribution Guidelines

- added all examples (and tested)
- added API
Copy link
Contributor

@pedromsousalima pedromsousalima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small detail but looks good!

Copy link
Contributor

@ubidefeo ubidefeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the great work, hope my suggestions come in handy :)


- `analog_read(pin)`

Analog read is a classic example where you read the voltage from an analog pin.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add: "[...] pin and print it to the console."


- `digital_read(pin)`

Reads a digital pin and returns a HIGH (1) or LOW (0) value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add: "We print this value in the console."


| Function | Description | Parameters | Returns | Alias |
| ------------------- | ---------------------------------------------- | ------------------------------------------------------------- | ------------------------ | ---------------- |
| `start` | Begins main loop with hooks | `preload`, `setup`, `loop`, `cleanup` | None | None |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preload is added to the end because it's only needed in very specific cases.
We want to allow the user to
start(setup, loop, cleanup) as a basic, friendly flow.

| `create_sketch` | Creates new sketch from template | `sketch_name`, `destination_path`, `overwrite`, `source_path` | Created sketch path | None |
| `copy_sketch` | Copies existing sketch to new location | `source_path`, `destination_path`, `name`, `overwrite` | Copied sketch path | None |

### start(setup=None, loop=None, cleanup=None, preload=None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per the last comment :)

Begins the main execution loop, calling user-defined hooks.

- **Parameters:**
- `preload`: Function run once before setup.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reorder placing this to the bottom of the list


The [Arduino Runtime Package](https://github.com/arduino/arduino-runtime-mpy/tree/main) is a MicroPython package that allows you to write and program your board using the classic `setup()` and `loop()` constructs.

The package was designed to make it easier to create programs, particularly for those familiar with the Arduino C++ environment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: "[...] environment, but it also adds a few interesting tricks to better help your program run and stop."

micropython_type: test
---

The [Arduino Runtime Package](https://github.com/arduino/arduino-runtime-mpy/tree/main) is a MicroPython package that allows you to write and program your board using the classic `setup()` and `loop()` constructs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change: "Arduino Runtime for MicroPython is a library that [...]"

suggestion: "[...] using the familiar [...]"

suggestion: "[...] construct. It also adds a few helpers along the way."

@@ -0,0 +1,367 @@
---
title: "Arduino MicroPython Runtime"
description: "Learn how to use the Arduino MicroPython runtime package, which allows you to write MicroPython code in a familiar Arduino style."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change: "Arduino Runtime for MicroPython"

suggestion: "[...] familiar Arduino style and adds a few helpers"

def loop():
value = digital_read(pin)
print(value)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always add a small delay not to flood the REPL and render the editor unresponsive

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

50ms is enough

- **Returns:** The interpolated value.
- **Alias:** None.

### pin_mode(pin, mode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move pin_mode etc above map(), constrain() and such commands, which should be under a section "helpers"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants