### Clone and Install ev3dev-lang-python Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/CONTRIBUTING.rst Clone the repository, navigate into the directory, and install the library on an EV3 with internet access. The default sudo password is 'maker'. ```shell git clone https://github.com/ev3dev/ev3dev-lang-python.git cd ev3dev-lang-python sudo make install ``` -------------------------------- ### Build Documentation with Sphinx Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/tests/README.md Install Sphinx and its dependencies, then use sphinx-build to generate HTML documentation from the docs directory. ```bash $ sudo apt-get install python3-sphinx python3-sphinx-bootstrap-theme python3-recommonmark $ cd ev3dev-lang-python/ $ sudo sphinx-build -nW -b html ./docs/ ./docs/_build/html ``` -------------------------------- ### Install RPyC Classic Service on ev3dev Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/rpyc.md These commands install and enable the RPyC classic service to run on an ev3dev device at boot. This is necessary for remote connections. ```shell echo "[Unit]\nDescription=RPyC Classic Service\nAfter=multi-user.target\n\n[Service]\nType=simple\nExecStart=/usr/bin/rpyc_classic.py\n\n[Install]\nWantedBy=multi-user.target" > rpyc-classic.service sudo cp rpyc-classic.service /lib/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable rpyc-classic.service sudo systemctl start rpyc-classic.service ``` -------------------------------- ### Install RPyC on Linux Desktop Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/rpyc.md Installs the RPyC package on a Linux system using apt-get. This is required if controlling an ev3dev device from a desktop PC. ```shell sudo apt-get install python3-rpyc ``` -------------------------------- ### Run API Tests with MicroPython Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/tests/README.md After installing MicroPython and necessary libraries, navigate to the project directory and run the API tests using the micropython interpreter. ```bash $ cd ev3dev-lang-python/ $ micropython tests/api_tests.py ``` -------------------------------- ### Specify Touch Sensor Port Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/index.md This example shows how to explicitly assign a touch sensor to a specific input port (e.g., INPUT_1). This is useful when you have multiple sensors connected. ```python ts = TouchSensor(INPUT_1) ``` -------------------------------- ### Update to Latest Release Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/CONTRIBUTING.rst Update your current ev3dev2 installation to the latest available release by updating the package list and then installing or upgrading the micropython-ev3dev2 package. ```shell sudo apt update sudo apt install --only-upgrade micropython-ev3dev2 ``` -------------------------------- ### Motor and Sensor Initialization with Port Names Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/port-names.md Demonstrates how to initialize a LargeMotor and a TouchSensor using predefined port name constants. Ensure the respective modules and constants are imported. ```python from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B from ev3dev2.sensor import INPUT_1 from ev3dev2.sensor.lego import TouchSensor m = LargeMotor(OUTPUT_A) s = TouchSensor(INPUT_1) ``` -------------------------------- ### Run API Tests with CPython Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/tests/README.md Navigate to the project directory and execute the API tests using Python 3. Ensure the fake-sys directory has the correct permissions. ```bash $ cd ev3dev-lang-python/ $ chmod -R g+rw ./tests/fake-sys/devices/**/* $ python3 -W ignore::ResourceWarning tests/api_tests.py ``` -------------------------------- ### Build and Deploy MicroPython Files Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/CONTRIBUTING.rst If developing micropython support, this command provides a shortcut to build and deploy only the micropython files. ```shell cd ev3dev-lang-python sudo make micropython-install ``` -------------------------------- ### Release Script Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/CONTRIBUTING.rst Execute the release script to build and prepare the package for distribution. This is a key step in the release process. ```shell ./debian/release.sh ``` -------------------------------- ### Use Text-to-Speech Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/README.rst Make the robot speak using the Sound.speak method. Ensure the Sound class is imported. ```python from ev3dev2.sound import Sound sound = Sound() sound.speak('Welcome to the E V 3 dev project!') ``` -------------------------------- ### Update pbuilder Environment Source: https://github.com/ev3dev/ev3dev-lang-python/wiki/Packaging Sets up the pbuilder environment for building packages for Debian (amd64) and Raspbian (armhf) on Jessie. Ensure these commands are run before building. ```sh OS=debian ARCH=amd64 DIST=jessie pbuilder-ev3dev base OS=raspbian ARCH=armhf DIST=jessie pbuilder-ev3dev base ``` -------------------------------- ### Initialize and Reset Console Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/console.md Initializes a Console instance with the default font and resets the console to clear the screen and hide the cursor. ```python #!/usr/bin/env micropython from ev3dev2.console import Console # create a Console instance, which uses the default font console = Console() # reset the console to clear it, home the cursor at 1,1, and then turn off the cursor console.reset_console() ``` -------------------------------- ### Build pbuilder Base Images Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/CONTRIBUTING.rst Build the pbuilder base images for Debian stretch and Raspbian stretch. These commands are part of the release process. ```shell OS=debian DIST=stretch ARCH=amd64 pbuilder-ev3dev base OS=raspbian DIST=stretch ARCH=armhf pbuilder-ev3dev base ``` -------------------------------- ### Initialize MoveTank for Dual Motor Control Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/README.rst Instantiate the MoveTank class to control two motors simultaneously. Specify the output ports for each motor. ```python from ev3dev2.motor import MoveTank, SpeedPercent, OUTPUT_A, OUTPUT_B tank_drive = MoveTank(OUTPUT_A, OUTPUT_B) ``` -------------------------------- ### Reinstall Latest Release Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/CONTRIBUTING.rst Use this command to reinstall the latest stable release of the ev3dev2 library on the EV3. ```shell sudo apt-get --reinstall install python3-ev3dev2 ``` -------------------------------- ### Build Debian and Raspbian Packages Source: https://github.com/ev3dev/ev3dev-lang-python/wiki/Packaging Builds the python-ev3dev packages for both Debian (amd64) and Raspbian (armhf) distributions using the pbuilder environment. ```sh OS=debian ARCH=amd64 DIST=jessie pbuilder-ev3dev build OS=raspbian ARCH=armhf DIST=jessie pbuilder-ev3dev build ``` -------------------------------- ### Upload Debian Packages Source: https://github.com/ev3dev/ev3dev-lang-python/wiki/Packaging Uploads the signed Debian and Raspbian packages to the ev3dev package archive using the dput command. ```sh dput ev3dev-deb pbuilder-ev3dev/debian/jessie-amd64/python-ev3dev_1.0.0_amd64.changes dput ev3dev-rpi pbuilder-ev3dev/raspbian/jessie-armhf/python-ev3dev_1.0.0_armhf.changes ``` -------------------------------- ### Create PyPi Release Tag Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/CONTRIBUTING.rst Create an annotated tag for a specific release version, intended for PyPi. This tag is used to mark the official release point. ```shell git tag -a 2.1.0 -m "python-ev3dev2 PyPi release 2.1.0" ``` -------------------------------- ### Clone ev3dev-lang-python Repository Recursively Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/tests/README.md Use this command to clone the repository and its submodules, including the fake-sys directory, in one step. ```bash $ git clone --recursive https://github.com/ev3dev/ev3dev-lang-python.git ``` -------------------------------- ### Basic Python Script Template for ev3dev Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/index.md This template includes the necessary shebang line and import statements for ev3dev Python programs. Ensure your editor uses LF line endings to avoid 'No such file or directory' errors. ```python #!/usr/bin/env python3 from time import sleep from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, SpeedPercent, MoveTank from ev3dev2.sensor import INPUT_1 from ev3dev2.sensor.lego import TouchSensor from ev3dev2.led import Leds # TODO: Add code here ``` -------------------------------- ### Using SpeedRPM Unit for Motor Control Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/motors.md Demonstrates how to use the SpeedRPM class to specify motor speed in rotations per minute. This is useful for precise speed control over a set duration. ```python from ev3dev2.motor import SpeedRPM # later... # rotates the motor at 200 RPM (rotations-per-minute) for five seconds. my_motor.on_for_seconds(SpeedRPM(200), 5) ``` -------------------------------- ### Running Python Scripts with Brickman Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/micropython.md Use 'brickrun' to execute Python programs via an SSH shell to prevent Brickman from interfering. ```shell brickrun -- ./program.py ``` -------------------------------- ### Drive with MoveTank for Seconds Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/index.md This snippet shows how to drive two motors using MoveTank for a specific duration in seconds. Speed parameters accept unit classes or percentages. ```python from ev3dev2.motor import MoveTank, SpeedPercent, OUTPUT_A, OUTPUT_B tank_drive = MoveTank(OUTPUT_A, OUTPUT_B) # drive in a different turn for 3 seconds tank_drive.on_for_seconds(SpeedPercent(60), SpeedPercent(30), 3) ``` -------------------------------- ### Run a Single Motor for Rotations Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/index.md This snippet demonstrates how to run a LEGO Large Motor at a specified speed for a given number of rotations. Ensure the LargeMotor class and SpeedPercent are imported. ```python from ev3dev2.motor import LargeMotor, SpeedPercent, OUTPUT_A m = LargeMotor(OUTPUT_A) m.on_for_rotations(SpeedPercent(75), 5) ``` -------------------------------- ### Basic Python Script Template for ev3dev Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/README.rst This template includes essential imports and the shebang line required for ev3dev Python scripts. Ensure your editor uses LF line endings. ```python #!/usr/bin/env python3 from time import sleep from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, SpeedPercent, MoveTank from ev3dev2.sensor import INPUT_1 from ev3dev2.sensor.lego import TouchSensor from ev3dev2.led import Leds # TODO: Add code here ``` -------------------------------- ### Update ev3dev-lang-python Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/CONTRIBUTING.rst Navigate to the project directory, pull the latest changes, and reinstall the library. This command updates the module to the newest version. ```shell cd ev3dev-lang-python git pull sudo make install ``` -------------------------------- ### Update Import Statements for ev3dev-Stretch Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/upgrading-to-stretch.md Replace old import statements with new ones that import specific modules for motors and sensors. The platform is now automatically determined. ```python from ev3dev2.motor import Motor, OUTPUT_A from ev3dev2.sensor.lego import TouchSensor, UltrasonicSensor ``` -------------------------------- ### Upgrade ev3dev2 Python Libraries Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/faq.md Upgrade the python3-ev3dev2 and micropython-ev3dev2 libraries on an internet-connected EV3. You will be prompted for the SSH password. ```bash sudo apt-get update sudo apt-get install --only-upgrade python3-ev3dev2 micropython-ev3dev2 ``` -------------------------------- ### Control LEDs with Touch Sensor Input Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/index.md This snippet demonstrates how to use a touch sensor to change the color of the ev3dev LEDs. The LEDs turn green when the sensor is pressed and red when released. A small sleep interval prevents the loop from consuming excessive CPU. ```python ts = TouchSensor() leds = Leds() print("Press the touch sensor to change the LED color!") while True: if ts.is_pressed: leds.set_color("LEFT", "GREEN") leds.set_color("RIGHT", "GREEN") else: leds.set_color("LEFT", "RED") leds.set_color("RIGHT", "RED") # don't let this loop use 100% CPU sleep(0.01) ``` -------------------------------- ### Update Changelog and Tag Release Source: https://github.com/ev3dev/ev3dev-lang-python/wiki/Packaging Updates the debian/changelog file with the new version, commits the changes, and creates a Git tag for the release. This is a prerequisite for building the package. ```sh git checkout master git merge develop git tag -a 1.0.0 ``` -------------------------------- ### Real-time Sensor Data Display Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/console.md Continuously displays gyroscope angle and color sensor readings on the console, updating inverse coloring based on specific conditions. ```python #!/usr/bin/env micropython from time import sleep from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3 from ev3dev2.console import Console from ev3dev2.sensor.lego import GyroSensor, ColorSensor console = Console() gyro = GyroSensor(INPUT_1) gyro.mode = GyroSensor.MODE_GYRO_ANG color_sensor_left = ColorSensor(INPUT_2) color_sensor_right = ColorSensor(INPUT_3) # show the gyro angle and reflected light intensity for both of our color sensors while True: angle = gyro.angle left = color_sensor_left.reflected_light_intensity right = color_sensor_right.reflected_light_intensity # show angle; in inverse color when pointing at 0 console.text_at("G: %03d" % (angle), column=5, row=1, reset_console=True, inverse=(angle == 0)) # show light intensity values; in inverse when 'dark' console.text_at("L: %02d" % (left), column=0, row=3, reset_console=False, inverse=(left < 10)) console.text_at("R: %02d" % (right), column=10, row=3, reset_console=False, inverse=(right < 10)) sleep(0.5) ``` -------------------------------- ### Sign Debian Packages Source: https://github.com/ev3dev/ev3dev-lang-python/wiki/Packaging Signs the generated .changes files for both Debian and Raspbian packages using the debsign command. This is necessary before uploading. ```sh debsign pbuilder-ev3dev/debian/jessie-amd64/python-ev3dev_1.0.0_amd64.changes debsign pbuilder-ev3dev/raspbian/jessie-armhf/python-ev3dev_1.0.0_armhf.changes ``` -------------------------------- ### Drive MoveTank for Seconds Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/README.rst Control the MoveTank for a specified duration in seconds. Speed can be set using SpeedPercent or other unit classes. ```python # drive in a different turn for 3 seconds tank_drive.on_for_seconds(SpeedPercent(60), SpeedPercent(30), 3) ``` -------------------------------- ### Run a Single Motor Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/README.rst Operates a LEGO Large Motor at 75% speed for 5 rotations. Ensure the motor is connected to the specified output port. ```python m = LargeMotor(OUTPUT_A) m.on_for_rotations(SpeedPercent(75), 5) ``` -------------------------------- ### Write Text with a Bitmap Font Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/display.md Use this snippet to display text on the EV3 screen. Ensure you have imported the necessary modules and have a display object initialized. The `fonts.load()` function selects the desired bitmap font. ```python import ev3dev2.fonts as fonts display.draw.text((10,10), 'Hello World!', font=fonts.load('luBS14')) ``` -------------------------------- ### Drive with MoveTank for Rotations Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/index.md Use the MoveTank class to drive two motors in a turn for a specified number of rotations. Speed can be defined using unit classes or percentages. ```python from ev3dev2.motor import MoveTank, SpeedPercent, OUTPUT_A, OUTPUT_B tank_drive = MoveTank(OUTPUT_A, OUTPUT_B) # drive in a turn for 5 rotations of the outer motor # the first two parameters can be unit classes or percentages. tank_drive.on_for_rotations(SpeedPercent(50), SpeedPercent(75), 10) ``` -------------------------------- ### Display Text at Specific Location Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/console.md Displays text at a specified row and column, with options to reset the console and use inverse coloring. ```python #!/usr/bin/env micropython from ev3dev2.console import Console # create a Console instance, which uses the default font console = Console() # reset the console to clear it, home the cursor at 1,1, and then turn off the cursor console.reset_console() # display 'Hello World!' at row 5, column 1 in inverse, but reset the EV3 LCD console first console.text_at('Hello World!', column=1, row=5, reset_console=True, inverse=True) ``` -------------------------------- ### Control LEDs with Touch Sensor Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/README.rst Changes LED colors based on touch sensor input. The LEDs turn green when pressed and red when released. Specify the sensor port if not using the default. ```python ts = TouchSensor() leds = Leds() print("Press the touch sensor to change the LED color!") while True: if ts.is_pressed: leds.set_color("LEFT", "GREEN") leds.set_color("RIGHT", "GREEN") else: leds.set_color("LEFT", "RED") leds.set_color("RIGHT", "RED") # don't let this loop use 100% CPU sleep(0.01) ``` ```python ts = TouchSensor(INPUT_1) ``` -------------------------------- ### Drive MoveTank for Rotations Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/README.rst Control the MoveTank for a specified number of rotations. Speed can be set using SpeedPercent or other unit classes. ```python # drive in a turn for 5 rotations of the outer motor # the first two parameters can be unit classes or percentages. tank_drive.on_for_rotations(SpeedPercent(50), SpeedPercent(75), 10) ``` -------------------------------- ### Change Console Font and Display Centered Text Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/console.md Changes the console font to 'Lat15-TerminusBold16.psf.gz', resets the console, and displays text centered on the LCD. ```python #!/usr/bin/env micropython from ev3dev2.console import Console # create a Console instance, which uses the default font console = Console() # change the console font and reset the console to clear it and turn off the cursor console.set_font('Lat15-TerminusBold16.psf.gz', True) # compute the middle of the console mid_col = console.columns // 2 mid_row = console.rows // 2 # display 'Hello World!' in the center of the LCD console console.text_at('Hello World!', column=mid_col, row=mid_row, alignment="C") ``` -------------------------------- ### Tag Stable Branch Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/CONTRIBUTING.rst Force push tags to the stable branch. This is done to ensure the remote repository reflects the local stable tag, which is important for CI/CD pipelines. ```shell git tag -d stable git tag stable git push --tags --force ``` -------------------------------- ### Control ev3dev Motor Remotely with RPyC Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/rpyc.md Connects to a remote ev3dev device using RPyC and controls a LargeMotor based on the state of a TouchSensor. Ensure IP connectivity and that the RPyC service is running on the ev3dev device. ```python import rpyc # Create a RPyC connection to the remote ev3dev device. # Use the hostname or IP address of the ev3dev device. # If this fails, verify your IP connectivty via ``ping X.X.X.X`` conn = rpyc.classic.connect('X.X.X.X') # import ev3dev2 on the remote ev3dev device evc3dev2_motor = conn.modules['ev3dev2.motor'] evc3dev2_sensor = conn.modules['ev3dev2.sensor'] evc3dev2_sensor_lego = conn.modules['ev3dev2.sensor.lego'] # Use the LargeMotor and TouchSensor on the remote ev3dev device motor = ev3dev2_motor.LargeMotor(ev3dev2_motor.OUTPUT_A) ts = ev3dev2_sensor_lego.TouchSensor(ev3dev2_sensor.INPUT_1) # If the TouchSensor is pressed, run the motor while True: ts.wait_for_pressed() motor.run_forever(speed_sp=200) ts.wait_for_released() motor.stop() ``` -------------------------------- ### MicroPython Shebang Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/micropython.md Modify the shebang line in your scripts to use 'micropython' instead of 'python3' when running with MicroPython. ```python #!/usr/bin/env micropython ``` -------------------------------- ### Fix Windows Line Endings in Python File Source: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/docs/faq.md Use this command to remove Windows-style line endings (CRLF) from a Python file on the EV3 brick. Ensure your editor is configured for Unix-style line endings (LF) when editing files on Windows. ```shell sed -i 's/\r//g' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.