kopia lustrzana https://github.com/peterhinch/micropython-samples
udev rule fixed
rodzic
0b22d8c057
commit
13ee21580d
106
README.md
106
README.md
|
@ -1,17 +1,21 @@
|
||||||
# micropython-samples
|
# micropython-samples
|
||||||
A place for assorted code ideas for MicroPython. Most are targeted at the Pyboard variants.
|
A place for assorted code ideas for MicroPython. Most are targeted at the
|
||||||
|
Pyboard variants.
|
||||||
|
|
||||||
## fastbuild - Pull and build Pyboard firmware under Linux
|
# fastbuild - Pull and build Pyboard firmware under Linux
|
||||||
These scripts are intended to speed and simplify rebuilding firmware from
|
These scripts are intended to speed and simplify rebuilding firmware from
|
||||||
source notably where pyboards of different types are in use, or when
|
source notably where pyboards of different types are in use, or when
|
||||||
frozen bytecode necessitates repeated compilation and deployment. In
|
frozen bytecode necessitates repeated compilation and deployment. In
|
||||||
particular ``buildpyb`` will detect the attached Pyboard type, build the
|
particular ``buildpyb`` will detect the attached Pyboard type, build the
|
||||||
appropriate firmware, put the board into DFU mode and deploy it, before
|
appropriate firmware, put the board into DFU mode and deploy it, before
|
||||||
launching ``rshell``. The latter step may be removed if ``rshell`` is not
|
launching ``rshell``. The latter step may be removed if ``rshell`` is not in
|
||||||
in use.
|
use.
|
||||||
|
|
||||||
|
The scripts should be run as your normal user and can proceed without user
|
||||||
|
interaction.
|
||||||
|
|
||||||
Includes udev rules to avoid jumps from ``/dev/ttyACM0`` to ``/dev/ttyACM1``
|
Includes udev rules to avoid jumps from ``/dev/ttyACM0`` to ``/dev/ttyACM1``
|
||||||
by ensuring Pyboards of all types appear as ``/dev/pyboard``. Rules are also
|
and ensuring Pyboards of all types appear as ``/dev/pyboard``. Rules are also
|
||||||
offered for USB connected WiPy (V1.0) and FTDI USB/serial adaptors.
|
offered for USB connected WiPy (V1.0) and FTDI USB/serial adaptors.
|
||||||
|
|
||||||
These scripts use Python scripts ``pyb_boot`` to put the Pyboard into DFU mode
|
These scripts use Python scripts ``pyb_boot`` to put the Pyboard into DFU mode
|
||||||
|
@ -19,29 +23,60 @@ and ``pyb_check`` to determine the type of attached board. These use the
|
||||||
``pyboard.py`` module in the source tree to execute scripts on the attached
|
``pyboard.py`` module in the source tree to execute scripts on the attached
|
||||||
board.
|
board.
|
||||||
|
|
||||||
### Edits
|
### Optional Edits
|
||||||
|
|
||||||
``buildnew`` and ``buildpyb`` will need editing to point to your micropython
|
|
||||||
directory.
|
|
||||||
|
|
||||||
In the ``buildpyb`` script you may wish to edit the ``-j 8`` argument to ``make``.
|
In the ``buildpyb`` script you may wish to edit the ``-j 8`` argument to ``make``.
|
||||||
This radically speeds build on a multi core PC. Empirically 8 gave the fastest
|
This radically speeds build on a multi core PC. Empirically 8 gave the fastest
|
||||||
build on my core i7 4/8 core laptop: adjust to suit your PC. You may also want
|
build on my Core i7 4/8 core laptop: adjust to suit your PC. You may also want
|
||||||
to alter the call to ``rshell``.
|
to remove the call to ``rshell`` if you don't plan on using it.
|
||||||
|
|
||||||
The script assumes a frozen modules directory ``stmhal/modules``. You may wish
|
This script defaults to a frozen modules directory ``stmhal/modules``. This may
|
||||||
to change this. A recent update enabled the directory for frozen to be located
|
be overridden by creating an environment variable FROZEN_DIR: a recent update
|
||||||
anywhere in the filesystem.
|
enabled the directory for frozen to be located anywhere in the filesystem,
|
||||||
|
allowing project specific directories.
|
||||||
|
|
||||||
In ``buildpyb`` you may wish to delete the unix make commands.
|
In ``buildnew`` you may wish to delete the unix make commands.
|
||||||
|
|
||||||
### Dependencies
|
### Dependencies and setup (on PC)
|
||||||
|
|
||||||
Python3.x
|
Python3
|
||||||
pyserial ``apt-get install python3-serial``.
|
The following Bash code installs pyserial, copies ``49-micropython.rules`` to
|
||||||
Verify that ``pyboard.py`` in the tools directory of the source tree works
|
(on most distros) ``/etc/udev/rules.d``. It installs ``rshell`` if you plan to
|
||||||
(tests in comments at the start of the code).
|
use it (recommended).
|
||||||
Copy ``49-micropython.rules`` to (on most distros) ``/etc/udev/rules.d``.
|
|
||||||
|
As root:
|
||||||
|
```
|
||||||
|
apt-get install python3-serial
|
||||||
|
pip install pyserial
|
||||||
|
cp 49-micropython.rules /etc/udev/rules.d
|
||||||
|
pip3 install rshell
|
||||||
|
```
|
||||||
|
|
||||||
|
Verify that ``pyboard.py`` works: Close and restart the terminal session. Run
|
||||||
|
Python3 and paste the following:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import os
|
||||||
|
mp = os.getenv('MPDIR')
|
||||||
|
sys.path.append(''.join((mp, '/tools')))
|
||||||
|
import pyboard
|
||||||
|
pyb = pyboard.Pyboard('/dev/pyboard')
|
||||||
|
pyb.enter_raw_repl()
|
||||||
|
pyb.exec('pyb.LED(1).on()')
|
||||||
|
pyb.exit_raw_repl()
|
||||||
|
```
|
||||||
|
|
||||||
|
The build scripts expect an environment variable MPDIR holding the path to the
|
||||||
|
MicroPython source tree. To set this up, as normal user issue (edited for your
|
||||||
|
path to the MicroPython source tree):
|
||||||
|
|
||||||
|
```
|
||||||
|
cd ~
|
||||||
|
echo export MPDIR='/mnt/qnap2/data/Projects/MicroPython/micropython' >> .bashrc
|
||||||
|
echo >> .bashrc
|
||||||
|
```
|
||||||
|
|
||||||
|
Close and restart the terminal session before running the scripts.
|
||||||
|
|
||||||
### Build script: ``buildpyb``
|
### Build script: ``buildpyb``
|
||||||
This checks the attached pyboard. If it's a V1.0, V1.1 or Lite it builds the
|
This checks the attached pyboard. If it's a V1.0, V1.1 or Lite it builds the
|
||||||
|
@ -50,44 +85,45 @@ correct firmware and deploys it. Otherwise it produces an error message.
|
||||||
Optional argument ``--clean`` - if supplied does a ``make clean`` to delete
|
Optional argument ``--clean`` - if supplied does a ``make clean`` to delete
|
||||||
all files produced by the previous build before proceeding.
|
all files produced by the previous build before proceeding.
|
||||||
|
|
||||||
### Update source: ``buildnew``
|
### Update source: ``buildnew``/usr/local/bin
|
||||||
|
|
||||||
Report state of master branch, update sources and issue ``make clean`` for cross
|
Report state of master branch, update sources and issue ``make clean`` for
|
||||||
compiler, Pyboard variants, and ESP8266. Builds cross compiler and unix port.
|
Pyboard variants, and ESP8266. Builds cross compiler and unix port.
|
||||||
|
|
||||||
### ESP8266 Build
|
### ESP8266 Build
|
||||||
|
|
||||||
``buildesp`` A script to build and deploy ESP8266 firmware. Accepts optional
|
``buildesp`` A script to build and deploy ESP8266 firmware. Accepts optional
|
||||||
``--clean`` argument.
|
``--clean`` argument.
|
||||||
|
|
||||||
## ssd1306
|
# ssd1306
|
||||||
|
|
||||||
A means of rendering multiple larger fonts to the SSD1306 OLED display
|
A means of rendering multiple larger fonts to the SSD1306 OLED display
|
||||||
|
|
||||||
## mutex
|
# mutex
|
||||||
A class providing mutal exclusion enabling interrupt handlers and the main program to access shared
|
A class providing mutal exclusion enabling interrupt handlers and the main program to access shared
|
||||||
data in a manner which ensures data integrity.
|
data in a manner which ensures data integrity.
|
||||||
|
|
||||||
## watchdog
|
# watchdog
|
||||||
Access the simpler of the Pyboard's watchdog timers.
|
Access the simpler of the Pyboard's watchdog timers.
|
||||||
|
|
||||||
## reverse
|
# reverse
|
||||||
Fast reverse a bytearray.
|
Fast reverse a bytearray.
|
||||||
|
|
||||||
## font
|
# font
|
||||||
Convert a C file produced by GLCD Font Creator to Python for storage as persistent byte code.
|
Convert a C file produced by GLCD Font Creator to Python for storage as
|
||||||
|
persistent byte code. This is effectively obsolete: see [this solution](https://github.com/peterhinch/micropython-font-to-py.git).
|
||||||
|
|
||||||
## ds3231_pb
|
# ds3231_pb
|
||||||
Driver for the DS3231 low cost precison RTC, including a facility to calibrate the Pyboard's RTC
|
Driver for the DS3231 low cost precison RTC, including a facility to calibrate the Pyboard's RTC
|
||||||
from the DS3231.
|
from the DS3231.
|
||||||
|
|
||||||
## Buildcheck
|
# Buildcheck
|
||||||
Raise an exception if a firmware build is earlier than a given date.
|
Raise an exception if a firmware build is earlier than a given date.
|
||||||
|
|
||||||
## timed_function
|
# timed_function
|
||||||
Time a function's execution using a decorator
|
Time a function's execution using a decorator
|
||||||
|
|
||||||
## ESP8266
|
# ESP8266
|
||||||
benchmark.py Tests the performance of MQTT by periodically publishing while subscribed to
|
benchmark.py Tests the performance of MQTT by periodically publishing while subscribed to
|
||||||
the same topic. Measures the round-trip delay. Adapt to suit your server address and desired
|
the same topic. Measures the round-trip delay. Adapt to suit your server address and desired
|
||||||
QOS (quality of service, 0 and 1 are supported). After 100 messages reports maximum and
|
QOS (quality of service, 0 and 1 are supported). After 100 messages reports maximum and
|
||||||
|
@ -95,7 +131,7 @@ minimum delays.
|
||||||
|
|
||||||
conn.py Connect in station mode using saved connection details where possible
|
conn.py Connect in station mode using saved connection details where possible
|
||||||
|
|
||||||
## Rotary Incremental Encoder
|
# Rotary Incremental Encoder
|
||||||
|
|
||||||
Classes for handling incremental rotary position encoders. Note that the Pyboard timers can
|
Classes for handling incremental rotary position encoders. Note that the Pyboard timers can
|
||||||
do this in hardware. These samples cater for cases where that solution can't be used. The
|
do this in hardware. These samples cater for cases where that solution can't be used. The
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
ATTRS{idVendor}=="f055", ENV{MTP_NO_PROBE}="1"
|
ATTRS{idVendor}=="f055", ENV{MTP_NO_PROBE}="1"
|
||||||
ATTRS{idVendor}=="f055", ENV{ID_MM_DEVICE_IGNORE}="1"
|
ATTRS{idVendor}=="f055", ENV{ID_MM_DEVICE_IGNORE}="1"
|
||||||
SUBSYSTEMS=="usb", ATTRS{idVendor}=="f055", MODE:="0666"
|
SUBSYSTEMS=="usb", ATTRS{idVendor}=="f055", MODE:="0666"
|
||||||
KERNEL=="ttyACM*", ATTRS{idVendor}=="f055", SYMLINK+="pyboard", MODE:="0666", GROUP="adminpete"
|
KERNEL=="ttyACM*", ATTRS{idVendor}=="f055", SYMLINK+="pyboard", MODE:="0666"
|
||||||
KERNEL=="ttyUSB*", ATTRS{idVendor}=="f055", SYMLINK+="pyboard", MODE:="0666", GROUP="adminpete"
|
KERNEL=="ttyUSB*", ATTRS{idVendor}=="f055", SYMLINK+="pyboard", MODE:="0666"
|
||||||
|
# DFU mode
|
||||||
|
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE:="0666"
|
||||||
|
|
Ładowanie…
Reference in New Issue