Compare commits

..
Author SHA1 Message Date
Laurens Valk 597b6d682f @pybricks/ide-docs v1.2.0 2021-04-09 12:31:37 +02:00
Laurens Valk 9c8d41efb8 doc/index: Update install note in IDE docs. 2021-04-09 12:21:47 +02:00
Laurens Valk a06e01c6de doc/start_pup/ev3: Drop installation guide.
These are now at https://pybricks.com/install/
2021-04-07 19:56:56 +02:00
David Lechner 186c46f52c api/pybricks/messaging: fix BluetoothMailboxServer close
As per standard Python socketserver, there is `server_close()` rather than `close()`.

Fixes #51
2021-04-07 19:42:33 +02:00
Laurens Valk 7679b8b47d examples/hubs/MoveHub: imu examples 2021-02-17 23:31:19 +01:00
Laurens Valk c14f1cf473 api/hubs/MoveHub: add basic imu
This is similar to the other hubs, but with reduced functionality.
2021-02-17 23:23:40 +01:00
Jerry Nicholls 6ce8336c26 doc/common/Motor: fix docstring for run_target
Changed "does" to "doesn't" for the target angle. The sign of the speed is irrelevant.
2021-02-15 19:12:41 +01:00
23 changed files with 120 additions and 966 deletions
+21
View File
@@ -19,6 +19,12 @@ Move Hub
.. automethod:: pybricks.hubs::MoveHub.light.animate
.. rubric:: Using the IMU
.. automethod:: pybricks.hubs::MoveHub.imu.up
.. automethod:: pybricks.hubs::MoveHub.imu.acceleration
.. rubric:: Using the battery
.. automethod:: pybricks.hubs::MoveHub.battery.voltage
@@ -39,3 +45,18 @@ Making the light blink
.. literalinclude::
../../../examples/pup/hub_movehub/light_blink.py
IMU examples
---------------
Testing which way is up
********************************
.. literalinclude::
../../../examples/pup/hub_movehub/imu_up.py
Reading acceleration
**************************************************
.. literalinclude::
../../../examples/pup/hub_movehub/imu_read_acceleration.py
+5 -17
View File
@@ -1,4 +1,4 @@
Welcome to Pybricks!
Pybricks API Documentation
==================================================================
This documentation has everything you need to install Pybricks and
@@ -18,13 +18,13 @@ the platforms below.
- **SPIKE / MINDSTORMS Inventor**
* - .. image:: ../api/images/ev3brick.png
:target: start_ev3/index.html
:target: https://pybricks.com/install/mindstorms-ev3/installation
- .. figure:: ../api/images/powereduphubs.png
:target: start_pup.html
:target: https://pybricks.com/install/technic-boost-city/
- .. figure:: ../api/images/primeinventorhub.png
:target: start_inventor.html
:target: https://pybricks.com/install/spike-mindstorms/
**Step 2: Start coding!**
@@ -53,19 +53,7 @@ findings on our `support page`_ so we can make Pybricks even better.
:hidden:
Home Page <https://pybricks.com>
Downloads <https://pybricks.com/downloads/>
Example Projects <https://github.com/pybricks/pybricks-projects>
Support <https://github.com/pybricks/support/issues/>
About Pybricks <https://pybricks.com/about/>
.. toctree::
:maxdepth: 1
:caption: Getting started
:hidden:
start_ev3/index
start_pup
start_inventor
Installation <https://pybricks.com/install/>
.. toctree::
:maxdepth: 1
+3 -1
View File
@@ -41,7 +41,7 @@ The connection will be made when you run your programs, as described below.
Pairing one EV3 Brick to another EV3 Brick.
When you scan for Bluetooth devices, you'll see a list of device names. By
default, all EV3 Bricks are named *ev3dev*. Click :ref:`here <hostname>` to
default, all EV3 Bricks are named *ev3dev*. Click `here`_ to
learn how to change that name. This makes it easy to tell them apart.
Repeat the steps in :numref:`fig_bluetooth_pair` if you want to pair more than
@@ -134,3 +134,5 @@ is shown in :numref:`fig_messaging_network`.
:align: center
An example network with one server and two clients.
.. _here: https://pybricks.com/install/mindstorms-ev3/beyond-micropython
-23
View File
@@ -1,23 +0,0 @@
MINDSTORMS EV3
########################
.. note::
This documentation is for EV3 MicroPython with Pybricks **3.0**.
Click `here`_ to view the documentation EV3 MicroPython **2.0**. This is
is the stable version officially supported by `LEGO Education`_.
.. rubric:: Table of contents
.. toctree::
:maxdepth: 1
start_ev3_install
start_ev3_brick
start_ev3_run
start_ev3_linux
start_ev3_upgrade
.. _here: https://pybricks.github.io/ev3-micropython/index.html
.. _LEGO Education: https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3
-81
View File
@@ -1,81 +0,0 @@
Using the EV3 Brick
===================
Make sure the EV3 Brick is turned off. Insert the microSD card you prepared
into the microSD card slot on the EV3 Brick, as shown in :numref:`fig_sd`.
.. _fig_sd:
.. figure:: ../../api/images/sd_label.png
:width: 75 %
:alt: sd
:align: center
Inserting the flashed microSD card into the EV3 Brick
Turning the EV3 Brick on and off
-----------------------------------------------------------
Turn on the EV3 Brick by pressing the dark gray center button.
The boot process may take several minutes. While booting, the EV3 Brick status
light turns orange and blinks intermittently, and you'll see a lot of text on
the EV3 screen. The EV3 Brick is ready for use when the status light turns
green.
To turn the EV3 Brick off, open the shutdown menu with the back button, and
then select *Power Off* using the center button, as shown
in :numref:`fig_onoff`.
.. _fig_onoff:
.. figure:: ../../api/images/onoff_label.png
:width: 65 %
:alt: onoff
:align: center
Turning the EV3 Brick off
Viewing motor and sensor values
-----------------------------------------------------------
When you're not running a program, you can view motor and sensor values using
the device browser, as shown in :numref:`fig_devicebrowser`.
.. _fig_devicebrowser:
.. figure:: ../../api/images/devicebrowser_label.png
:width: 100 %
:alt: devicebrowser
:align: center
Viewing motor and sensor values
Running a program without a computer
-----------------------------------------------------------
You can run previously downloaded programs directly from the EV3 Brick.
To do so, find the program using the *file browser* on the EV3 screen and press
the center button key to start the program as shown in :numref:`fig_manualrun`.
.. _fig_manualrun:
.. figure:: ../../api/images/manualrun_label.png
:width: 100 %
:alt: manualrun
:align: center
Starting a program using the buttons on the EV3 Brick
Going back to the original firmware
-----------------------------------------------------------
You can go back to the LEGO® firmware and your LEGO programs at any time. To
do so:
1. Turn the EV3 Brick off as shown above.
2. Wait for the screen and brick status light to turn off.
3. Remove the microSD card.
4. Turn the EV3 on.
-118
View File
@@ -1,118 +0,0 @@
Installation
===================
This page guides you through the steps to collect and install everything you
need to start programming.
What do you need?
-----------------------------------------------------------
To get started, you'll need:
- A Windows 10 or Mac OS computer
- Internet access and administrator access
This is required during the installation only. You will not need special
access to write and run programs later on.
- A microSD card
You'll need a card with a minimum capacity of 4GB and a maximum capacity
of 32GB. This type of microSD card is also known as microSDHC. We recommend
cards with Application Performance Class A1.
- A microSD card slot or card reader in your computer
If your computer does not have a (micro)SD card slot, you can use an
external USB (micro)SD card reader.
- A mini-USB cable, like the one included with your EV3 set
The typical configuration of this equipment is summarized
in :numref:`fig_overview`.
.. _fig_overview:
.. figure:: ../../api/images/overview_label.png
:width: 90 %
:alt: overview
:align: center
Setup overview
Preparing your computer
-----------------------------------------------------------
You'll write your MicroPython programs using Visual Studio Code. Follow the
steps below to download, install, and configure this application:
1. Download `Visual Studio Code <https://code.visualstudio.com/Download>`_.
2. Follow the on-screen instructions to install the application.
3. Launch Visual Studio Code.
4. Open the extensions tab.
5. Install the EV3 MicroPython extension as shown in :numref:`fig_store`.
.. _fig_store:
.. figure:: ../../api/images/store_label.png
:alt: store
:align: center
Installing the extension from the Visual Studio Code marketplace
.. _prepsdcard:
Preparing the microSD card
-----------------------------------------------------------
To make it possible to run MicroPython programs on your EV3 Brick, you'll now
learn how to install the required tools on your microSD card.
If the microSD card contains files you want to keep, make sure to create a
backup of its contents first.
See :ref:`managing files on the EV3 <managefiles>` to learn how to backup your
previous MicroPython programs if necessary.
*This process erases everything on your microSD card, including any previous
MicroPython programs on it.*
To install the MicroPython tools on your microSD card:
1. Download the `EV3 MicroPython microSD card image`_ and save it in a
convenient location. This file is approximately 360 MB. You do **not** need
to unzip the file.
2. Download and install a microSD card flashing tool
such as `Etcher <https://www.balena.io/etcher/>`_.
3. Insert the microSD card into your computer or card reader.
4. Launch the flashing tool and follow the steps on your screen to install
the file you have just downloaded. If you use Etcher, you can follow the
instructions below, as shown in :numref:`fig_etcher`.
a. Select the EV3 MicroPython microSD card image file you have just
downloaded.
b. Select your microSD card. Make sure that the device and size correspond
to your microSD card.
c. Start the flashing process. This may take several minutes. Do not remove
the card until the flashing process is complete.
.. _fig_etcher:
.. figure:: ../../api/images/etcher_label.png
:width: 85 %
:alt: etcher
:align: center
Using Etcher to flash the EV3 MicroPython microSD card image
Updating the microSD card
-----------------------------------------------------------
To update the microSD card, download a new image file using the link above and
flash it to the microSD card as described above. Be sure
to :ref:`back up any MicroPython programs you want to save <managefiles>`.
You do not need to erase the contents of the microSD card first. This is done
automatically when you flash the new image file.
.. _EV3 MicroPython microSD card image: https://education.lego.com/en-us/product-resources/mindstorms-ev3/teacher-resources/python-for-ev3
-101
View File
@@ -1,101 +0,0 @@
Accessing advanced EV3 features
===============================
MicroPython runs on top of `ev3dev`_, which is a specific version of Linux.
Linux is an *operating system*. (Other popular operating
systems are Microsoft Windows and Apple macOS.) This means that your EV3 is
almost like a real computer, just much smaller.
The Linux command line
-----------------------------------------
Although your EV3 Brick is quite like a real computer, you do not interact with
it using a big screen and a mouse. Instead, you can access files and programs
on it using the *command line*. It is also called the *terminal*.
Follow the steps in :numref:`fig_terminal` to access the command line. Now
you can enter commands by typing them in and pressing enter.
.. _fig_terminal:
.. figure:: ../../api/images/terminal_label.png
:width: 100 %
:alt: files
:align: center
Opening the Linux command line and running the ``ls`` command.
**Running basic commands**
For example, if you type the following command and press enter::
ls
then you will see the contents of the current folder. :numref:`fig_terminal`
shows the result: it listed the project folder of the ``getting_started``
project that we just ran.
If you type the following command and press enter::
exit
then the command line will be closed. Alternatively, click the garbage icon
shown in :numref:`fig_terminal`.
You can copy text from the command line by selecting it and
then pressing ``ctrl`` ``shift`` ``c``.
You can paste text into the command line
using ``ctrl`` ``shift`` ``v``.
**Running commands as an administrator**
Some commands require a password to run. This is similar to administrative
tasks on your computer or tablet, such as installing a new app. These commands
work like any other command, but you add ``sudo`` in front of
them.
As an exercise, you can run the following command to turn the EV3 Brick off::
sudo poweroff
You will be prompted for a password. Type ``maker`` and then press ``Enter``.
.. warning::
Only run commands with ``sudo`` if you know what you are doing.
**Learning more about the command line**
To learn more about the command line and many of the available commands, we
recommend reading the beginner-friendly free ebook
called `The Linux Command Line`_.
To learn more about ev3dev-specific tips and tricks, visit the `ev3dev`_
website.
.. _hostname:
Changing the EV3 Brick name
-----------------------------------------------------------
When you search for your EV3 using Visual Studio Code, you see all EV3 Bricks
listed by their name. By default, all EV3 Bricks are named *ev3dev*. Follow
these steps to change that name:
1. Open Visual Studio Code and connect to your EV3 as usual.
2. Read the steps above about running commands as an administrator.
3. Think of a good name. In this example, we'll
call it ``autonomous-vehicle2``
4. Enter the following command and press enter::
sudo hostnamectl set-hostname autonomous-vehicle2
5. Reboot the EV3 Brick for the change to take effect.
6. You may need to reboot your computer as well.
EV3 Brick names should only contain lowercase letters ``a`` through ``z``,
the digits ``0`` through ``9``, and the hyphen ``-``. It must start with a
letter or digit. It cannot include spaces or other symbols.
.. _ev3dev: https://www.ev3dev.org/
.. _The Linux Command Line: http://linuxcommand.org/tlcl.php
-166
View File
@@ -1,166 +0,0 @@
Creating and running programs
=============================
Now that you've set up your computer and EV3 Brick, you're ready to start
writing programs.
To make it easier to create and manage your programs, let's first have a quick
look at how MicroPython projects and programs for your EV3 robots are
organized.
Programs are organized into *project folders*, as shown in
:numref:`fig_projectstructure`. A project folder is a directory on your
computer that contains the main program (**main.py**) and other optional
scripts or files. This project folder and all of its contents will be copied
to the EV3 Brick, where the main program will be run.
This page shows you how to create such a project and how to transfer it to the
EV3 Brick.
.. _fig_projectstructure:
.. figure:: ../../api/images/projectstructure_label.png
:width: 100 %
:alt: projectstructure
:align: center
A project contains a program called **main.py** and optional resources like
sounds or MicroPython modules.
Creating a new project
-----------------------------------------------------------
To create a new project, open the EV3 MicroPython tab and
click *create a new project*, as shown in :numref:`fig_newproject`. Enter a
project name in the text field that appears and press *Enter*. When prompted,
choose a location for this program and confirm by clicking *choose folder*.
.. _fig_newproject:
.. figure:: ../../api/images/newproject_label.png
:width: 100 %
:alt: newproject
:align: center
Creating a new project. This example is called *getting_started*, but you
can choose any name.
When you create a new project, it already includes a file called *main.py*. To
see its contents and to modify it, open it from the file browser as shown in
:numref:`fig_projectoverview`. This is where you'll write your programs.
If you are new to MicroPython programming, we recommend that you keep the
existing code in place and add your code to it.
.. _fig_projectoverview:
.. figure:: ../../api/images/projectoverview_label.png
:width: 100 %
:alt: projectoverview
:align: center
Opening the default *main.py* program.
Opening an existing project
-----------------------------------------------------------
To open a project you created previously, click *File* and click
*Open Folder*, as shown in :numref:`fig_existingproject`. Next, navigate to
your previously created project folder and click *OK*. You can also open your
recently used projects using the *Open Recent* menu option.
.. _fig_existingproject:
.. figure:: ../../api/images/existingproject_label.png
:width: 75 %
:alt: existingproject
:align: center
Opening a previously created project.
Connecting to the EV3 Brick with Visual Studio Code
-----------------------------------------------------------
To be able to transfer your code to the EV3 Brick, you'll first need to
connect the EV3 Brick to your computer with the mini-USB cable and configure
the connection with Visual Studio Code. To do so:
- Turn the EV3 Brick on
- Connect the EV3 Brick to your computer with the mini-USB cable
- Configure the USB connection as shown in :numref:`fig_connecting`.
.. _fig_connecting:
.. figure:: ../../api/images/connecting_label.png
:width: 100 %
:alt: connecting
:align: center
Configuring the USB connection between the computer and the EV3 Brick
Downloading and running a program
-----------------------------------------------------------
You can press the F5 key to run the program. Alternatively, you can start it
manually by going to the *debug* tab and clicking the green start arrow, as
shown in :numref:`fig_running`.
When the program starts, a pop-up toolbar allows you to stop the program if
necessary. You can also stop the program at any time using the back button on
the EV3 Brick.
If your program produces any output with the ``print`` command, this is shown
in the output window.
.. _fig_running:
.. figure:: ../../api/images/running_label.png
:width: 100 %
:alt: running
:align: center
Running a program
Expanding the example program
-----------------------------------------------------------
Now that you've run the basic code template, you can expand the program to
make a motor move. First, attach a Large Motor to Port B on the EV3 Brick,
as shown in :numref:`fig_firstprogram`.
.. _fig_firstprogram:
.. figure:: ../../api/images/firstprogram_label.png
:width: 100 %
:alt: firstprogram
:align: center
The EV3 Brick with a Large Motor attached to port B.
Next, edit *main.py* to make it look like this:
.. literalinclude::
../../../examples/ev3/getting_started/main.py
This program makes your robot beep, rotate the motor, and beep again with a
higher pitched tone. Run the program to make sure that it works as expected.
.. _managefiles:
Managing files on the EV3 Brick
-----------------------------------------------------------
After you've downloaded a project to the EV3 Brick, you can run, delete, or
back up programs stored on it using the device browser as shown in
:numref:`fig_files`.
.. _fig_files:
.. figure:: ../../api/images/files_label.png
:width: 100 %
:alt: files
:align: center
Using the EV3 device browser to manage files on your EV3 Brick
-248
View File
@@ -1,248 +0,0 @@
Upgrading from v1.0 to v2.0
===============================
*EV3 MicroPython version 2.0 was released on May 18, 2020.*
This section is for users who have previously used LEGO MINDSTORMS EV3
MicroPython v1.0. We'll explain what's changed and how you can upgrade to
benefit from the latest improvements.
If you are a new user and you just got started using version 2.0, you can skip
this page.
Upgrading the microSD Card
-----------------------------------------
To upgrade, download the latest microSD card file and install it using the
standard :ref:`instructions <prepsdcard>`.
Note that this will erase all your existing files on the SD Card. Before you
upgrade, make sure that you still have all your projects on your computer.
If not, you can upload files back to your computer using
:ref:`these instructions <managefiles>`.
As with any software update, *be careful about when you update*. For example,
if you developed your code using version v1.0 and you are halfway into your
robotics competition season, you may want to stick with v1.0 for now.
Upgrading your existing programs
-----------------------------------------
Most changes in v2.0 are *new* features, like support for additional sensors.
Naturally, this will not affect your existing code.
However, some changes were made to existing features to improve performance.
All originally documented features in v1.0 will still work after you upgrade.
This means that most programs originally made for v1.0 will work with the v2.0
microSD card image without any changes.
To try this, simply download and run your original code as you did before.
However, it is recommended that you upgrade both the microSD card and your
programs at the same time to ensure everything works as expected.
The new EV3Brick() class replaces the ev3brick module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Version 2.0 introduces the :class:`EV3Brick() <pybricks.hubs.EV3Brick>` class.
You can use it instead of the old ``ev3brick`` module. The old ``ev3brick``
module can still be used, but it is no longer recommended or documented.
The :class:`EV3Brick() <pybricks.hubs.EV3Brick>` class improves the speed and
reliability of the EV3 screen and the EV3 speaker. It also adds functionality
like speech and drawing shapes. The default
font size is also bigger to make it easier to read text on the screen.
You can use
the following table as a starting point to upgrade your scripts. See the
:class:`EV3Brick() <pybricks.hubs.EV3Brick>` class documentation for
complete details of all methods and arguments.
.. list-table::
* - **Action**
- **v1.0**
- **v2.0**
* - | Initialize
| your EV3
- ::
from pybricks import ev3brick as brick
- ::
from pybricks.hubs import EV3Brick
ev3 = EV3Brick()
* - | Light on
- ::
brick.light(Color.RED)
- ::
ev3.light.on(Color.RED)
* - | Light off
- ::
brick.light(None)
- ::
ev3.light.off()
* - | Read
| Buttons
- ::
if Button.LEFT in brick.buttons():
print("Left is pressed.")
- ::
if Button.LEFT in ev3.buttons.pressed():
print("Left is pressed.")
* - | Play a
| beep
- ::
brick.sound.beep()
- ::
ev3.speaker.beep()
* - | Play a
| sound file
- ::
brick.sound.file(SoundFile.HELLO)
- ::
ev3.speaker.play_file(SoundFile.HELLO)
* - | Text to
| speech
-
- ::
ev3.speaker.say("I can say anything!")
* - | Play
| notes
-
- ::
ev3.speaker.play_notes(['C4/4', 'G4/4'])
* - | Write text
| at a given
| position
- ::
brick.display.text("Hello!", (50, 60))
- ::
ev3.screen.draw_text(50, 60, "Hello!")
* - | Write text
| and scroll
| automatically
- ::
brick.display.text("Hello")
brick.display.text("world!")
- ::
ev3.screen.print("Hello")
ev3.screen.print("world!")
* - | Change font
| size
-
- ::
from pybricks.media.ev3dev import Font
big_font = Font(size=24)
ev3.screen.set_font(big_font)
* - | Display an
| image on
| the screen
- ::
from pybricks.parameters import ImageFile
brick.display.image(ImageFile.QUESTION_MARK)
- ::
from pybricks.media.ev3dev import ImageFile
ev3.screen.load_image(ImageFile.Question_MARK)
* - | Draw shapes
| on the screen
-
- ::
ev3.screen.draw_line(30, 30, 30, 100)
ev3.screen.draw_box(50, 30, 90, 60)
ev3.screen.draw_circle(70, 90, 20, fill=True)
* - | Read
| battery
| voltage
- ::
brick.battery.voltage()
- ::
ev3.battery.voltage()
Other internal changes to existing features
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Most methods of the ``Motor`` class now
have ``Stop.HOLD`` as the default instead of ``Stop.COAST``. This improves
accuracy in most applications. You can still select ``Stop.COAST`` if you
like.
- The internal PID controllers for the motors are more accurate than before.
If you give a motor command when it is already running, it smoothly adjusts
the speed to the newly given command. This works even if you keep
adjusting the speed in a fast loop.
- Methods to configure motor settings have changed. You can change settings
using the ``control`` attribute now. The old settings setters
continue to exist in the implementation, but they are no longer documented.
- So-called Python *keyword arguments* are now supported. Previously, you
could only enter the argument *values*. For example:
::
my_motor.run_angle(500, 90, Stop.HOLD, False)
This is still possible. But you can now choose to omit optional arguments
and specify others with *keywords*. This can make your code easier to read.
For example:
::
my_motor.run_angle(500, 90, wait=False)
- It is no longer necessary to import ``pybricks.tools.print``. The ``print``
function is now built-in. It works just like Python or MicroPython.
- Most parameters in the :mod:`parameters <pybricks.parameters>` now have a
specific type and representation. For example, suppose you measure a color
and print the result. If you do ``print(Color.RED)``, you will see the
parameter instead of a technical number.
- Sound and image files have moved to a dedicated ``media`` module.
Importing them from the old location will continue to work in this release,
to make sure existing scripts will still work.
**Installing an older version of the Visual Studio Code extension**
The Visual Studio Code extension and this documentation are updated
automatically. You can still use your existing scripts with the updated
extension. If you absolutely wish to keep the old version, look for the EV3
extension on the extension tab, click the gear icon, and
click *install another version*.
-4
View File
@@ -1,4 +0,0 @@
SPIKE Prime / Robot Inventor
########################################################
Coming soon!
-176
View File
@@ -1,176 +0,0 @@
.. _pupguide:
Powered Up
########################
.. figure:: ../api/images/powereduphubs.png
:height: 15 em
:align: center
This page shows how you can install Pybricks on the BOOST Move Hub, the City
Hub, and the Technic Hub using the `Pybricks Code`_ interface.
You can reinstall the :ref:`original firmware <restoring>` at any time
using the official Powered Up app.
1. Requirements
--------------------------------------
* A BOOST Move Hub, City Hub, or Technic Hub.
* A Windows, Mac, Linux, or Android device.
* Bluetooth Low Energy (BLE). Make sure that Bluetooth is switched on.
If you don't have BLE, the coding interface will inform you during the
installation step. In that case, you can try using a low-cost USB Bluetooth
Dongle thats support Bluetooth Low Energy.
2. Installing a compatible browser
---------------------------------------------------
Writing Pybricks programs requires a web browser with web Bluetooth
functionality, such as:
* `Google Chrome`_
* `Microsoft Edge`_
* Chromium
If you use Linux, enable *Experimental Web Platform features* on
the ``chrome://flags/`` page. On Windows and Mac, this is already enabled.
3. Installing the Pybricks firmware
-----------------------------------
Before you begin, turn the hub off. The update works best with fresh batteries.
If you use the City Hub, you must unplug all motors and sensors. Follow these
steps:
1. Go to `Pybricks Code`_.
2. Press and hold the green button, and wait for the light to start blinking.
3. While you hold it, click the firmware update button.
4. Select the ``LEGO Bootloader`` and click *Pair*.
5. Wait until the light goes off and until it blinks red/green/blue again.
6. You may now release the button and wait for the installation to finish.
These steps are summarized in this video:
.. raw:: html
<video controls src="https://pybricks.com/wp-content/uploads/2020/06/install.mp4" width="100%"></video>
<br /><br />
4. Running programs
--------------------------------
Once the firmware is installed, you can start coding! Use the *Bluetooth*
button to connect to your *Pybricks Hub*. Then press run to
start your program.
.. figure:: ../api/images/pybrickscode.png
To get started, just copy and paste this snippet::
from pybricks.pupdevices import Motor
from pybricks.parameters import Port, Stop
from pybricks.tools import wait
# We'll use two motors. One is a dial
# to set the speed of the other motor.
motor = Motor(Port.B)
dial = Motor(Port.A)
# Say hello :)
print("Hello, Pybricks!")
# First, we'll move the dial to zero.
dial.run_target(500, 0, Stop.COAST)
while True:
# Set the speed based on dial angle
speed = dial.angle()*3
if abs(speed) < 100:
speed = 0
# Run motor at desired speed
motor.run(speed)
# Wait briefly, then repeat
wait(10)
5. Next steps
-----------------------------------------
Now that you've learned how to install Pybricks and run programs, check out
the steps below to make Pybricks coding even easier. We'll also show you how
you can restore the original firmware.
Saving a program on the hub
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The Move Hub, City Hub, and Technic Hub do not have separate storage space
for user programs. This means your program is erased after it is done running.
Fortunately, you can still save one program on the hub, by including it in the
firmware. To do so:
1. Open the settings tab with the ⚙ icon.
2. Activate the *Include current program* switch.
3. Update the firmware as you did before. Now, your current program will be
included.
4. Now can start and stop your program with the green button.
No connection required!
5. You can still download and run new programs with the run button as usual.
This is a bit of a slow process to do each time. We recommend to
use the run button to run your code most of the time. When you are
happy with your final program, follow the steps above to save it on the hub.
Using Pybricks offline
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Instead of working in your browser, you can install Pybricks locally:
1. Open the settings tab with the ⚙ icon.
2. Click on *Install as App* and follow the on-screen instructions.
To uninstall, click the ⋮ menu in the top and
click *Uninstall*. Note that this only removes the app from your computer.
To restore the original firmware on the hub, see the next section.
.. _restoring:
Restoring the original firmware
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Pybricks uses the same update procedure as the LEGO apps. The only difference
is which firmware file we upload. This means you can go back to the original
firmware any time. As shown in the video below, just put the hub in update mode
and connect using a LEGO app.
.. raw:: html
<video controls src="https://pybricks.com/wp-content/uploads/2020/06/restore.mp4" width="100%"></video>
This video shows the Powered Up app in *create* mode. It has firmware for all
hubs. As usual, you may need to restart the app to detect the hub. If it fails,
try again with fresh batteries.
Installing the latest build
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. warning::
This section is only intended for developers who want to try the
latest features. Some features may not work when you do this. To revert
to a stable version, just install the firmware as you normally would.
Pybricks Code automatically provides the latest stable and tested firmware.
To get a more recent version, log in to GitHub and go to our `latest builds`_.
Click on the desired build and go to `Artifacts`.
Download the firmware ZIP archive for your hub. To install it, drag this file
*onto* the firmware update button in Pybricks Code. The update now proceeds as
usual.
.. _latest builds: https://github.com/pybricks/pybricks-micropython/actions?query=is%3Asuccess+branch%3Amaster+workflow%3ABuild
.. _support page: https://github.com/pybricks/support/issues/
.. _Pybricks Code: http://code.pybricks.com/
.. _Google Chrome: https://www.google.com/chrome/
.. _Microsoft Edge: https://www.microsoft.com/en-us/edge
+3 -1
View File
@@ -13,7 +13,7 @@ At the moment, this class is only available on EV3.
use this class on 13 February 2020 on 10:07 and 44.431260
seconds, the file is called ``log_2020_02_13_10_07_44_431260.csv``.
See :ref:`managing files on the EV3 <managefiles>` to learn how to upload
See `managing files on the EV3`_ to learn how to upload
the log file back to your computer.
@@ -71,3 +71,5 @@ name will always be the same. However, this means that the contents of
``my_file.txt`` will be overwritten every time you run this script.
.. literalinclude:: ../../../examples/ev3/datalog_extra/main.py
.. _managing files on the EV3: https://pybricks.com/install/mindstorms-ev3/running-programs#managing-files-on-the-ev3-brick
+5
View File
@@ -1,3 +1,8 @@
# 1.2.0 - 2021-04-09
## Changed:
- Moved installation guide to external site.
# 1.1.1 - 2021-02-14
## Added:
+5 -11
View File
@@ -1,13 +1,6 @@
Pybricks Documentation
==================================================================
.. toctree::
:maxdepth: 1
:caption: Getting started
:hidden:
start_pup
.. toctree::
:maxdepth: 1
:caption: Pybricks Modules
@@ -29,13 +22,12 @@ Pybricks Documentation
signaltypes
motors
To begin, install the Pybricks firmware on your hub. Check
`pybricks.com/install`_ to learn how.
Use the ☰ menu to navigate all available classes, methods, and tools. A few
commonly used devices and classes are listed below for quick reference.
.. rubric:: Installation
Click :ref:`to jump to the installation guide <pupguide>`.
.. rubric:: Programmable Hubs
.. figure:: ../api/images/hubsoverview.png
@@ -47,3 +39,5 @@ Click :ref:`to jump to the installation guide <pupguide>`.
.. figure:: ../api/images/pupdevicesoverview.png
:width: 100 %
:target: pupdevices/index.html
.. _pybricks.com/install: https://pybricks.com/install/
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@pybricks/ide-docs",
"version": "1.1.1",
"version": "1.2.0",
"description": "Special build of Pybricks API docs for embedding in an IDE.",
"repository": {
"type": "git",
-1
View File
@@ -1 +0,0 @@
.. include:: ../api/start_pup.rst
@@ -0,0 +1,16 @@
from pybricks.hubs import MoveHub
from pybricks.tools import wait
# Initialize the hub.
hub = MoveHub()
# Get the acceleration tuple.
print(hub.imu.acceleration())
while True:
# Get individual acceleration values.
x, y, z = hub.imu.acceleration()
print(x, y, z)
# Wait so we can see what we printed.
wait(100)
+29
View File
@@ -0,0 +1,29 @@
from pybricks.hubs import MoveHub
from pybricks.parameters import Color, Side
from pybricks.tools import wait
# Initialize the hub.
hub = MoveHub()
# Define colors for each side in a dictionary.
SIDE_COLORS = {
Side.TOP: Color.RED,
Side.BOTTOM: Color.BLUE,
Side.LEFT: Color.GREEN,
Side.RIGHT: Color.YELLOW,
Side.FRONT: Color.MAGENTA,
Side.BACK: Color.BLACK,
}
# Keep updating the color based on detected up side.
while True:
# Check which side of the hub is up.
up_side = hub.imu.up()
# Change the color based on the side.
hub.light.on(SIDE_COLORS[up_side])
# Also print the result.
print(up_side)
wait(50)
+1 -1
View File
@@ -1,4 +1,4 @@
# ExampleHub = TechnicHub PrimeHub
# ExampleHub = TechnicHub PrimeHub MoveHub
from pybricks.hubs import ExampleHub
from pybricks.parameters import Color, Side
from pybricks.tools import wait
+26 -13
View File
@@ -267,7 +267,7 @@ class Motor(DCMotor):
given target angle.
The direction of rotation is automatically selected based on the target
angle. It does matter if ``speed`` is positive or negative.
angle. It does not matter if ``speed`` is positive or negative.
Arguments:
speed (:ref:`speed`): Speed of the motor.
@@ -715,7 +715,31 @@ class Battery:
pass
class Accelerometer:
class SimpleAccelerometer:
"""Get measurements from an accelerometer."""
def acceleration(self):
"""Gets the acceleration of the device.
Returns:
tuple of :ref:`linacceleration_m`: Acceleration along all three
axes.
"""
pass
def up(self):
"""Checks which side of the hub currently faces upward.
:returns:
``Side.TOP``, ``Side.BOTTOM``, ``Side.LEFT``, ``Side.RIGHT``,
``Side.FRONT`` or ``Side.BACK``.
:rtype: :class:`Side`
"""
pass
class Accelerometer(SimpleAccelerometer):
"""Get measurements from an accelerometer."""
def neutral(self, top, front):
@@ -786,17 +810,6 @@ class Accelerometer:
"""
pass
def up(self):
"""Checks which side of the device or hub currently faces upward.
:returns:
``Side.TOP``, ``Side.BOTTOM``, ``Side.LEFT``, ``Side.RIGHT``,
``Side.FRONT`` or ``Side.BACK``.
:rtype: :class:`Side`
"""
pass
class IMU(Accelerometer):
+3 -1
View File
@@ -4,7 +4,8 @@
"""LEGO® Programmable Hubs."""
from ._common import (Speaker as _Speaker, Battery as _Battery,
ColorLight as _ColorLight, Keypad as _Keypad,
LightMatrix as _LightMatrix, IMU as _IMU)
LightMatrix as _LightMatrix, IMU as _IMU,
SimpleAccelerometer as _SimpleAccelerometer)
from .media.ev3dev import Image as _Image
from .parameters import Button as _Button
from .geometry import Axis as _Axis
@@ -35,6 +36,7 @@ class MoveHub:
# In reality, they are instance attributes created by __init__.
battery = _Battery()
light = _ColorLight()
imu = _SimpleAccelerometer()
class CityHub:
+1 -1
View File
@@ -180,5 +180,5 @@ class BluetoothMailboxClient:
There was a problem establishing the connection.
"""
def close(self):
def server_close(self):
"""Closes all connections."""
+1 -1
View File
@@ -40,7 +40,7 @@ class BluetoothMailboxServer(Connection):
def __enter__(self) -> BluetoothMailboxServer: ...
def __exit__(self, type, value, traceback) -> None: ...
def wait_for_connection(self, count: int = 1) -> None: ...
def close(self) -> None: ...
def server_close(self) -> None: ...
class BluetoothMailboxClient(Connection):
def __enter__(self) -> BluetoothMailboxClient: ...