Skip to main content

Thymio plug-in for Thonny

The Python module tdmclient_ty is a plug-in for Thonny, the Python IDE for beginners. Based on the module tdmclient, it lets you run Python programs on the Thymio II mobile robot.

Like tdmclient, the plug-in relies on Thymio Suite and its Thymio Device Manager component (tdm) to communicate with the robot.

Installation

In Thonny, select the menu Tools>Manage Packages, type tdmclient_ty in the search box, and click the button Search on PyPI. Click the link tdmclient_ty in the result list (normally the only result), then the Install button below.

Make sure you also have Thymio Suite installed on your computer.

Usage

Connect a robot to your computer via a USB cable or the RF dongle and launch Thymio Suite. In Thymio Suite, you can click the Aseba Studio icon to check that the Thymio is recognized, and, also optionally, start Aseba Studio (select the robot and click the button "Program with Aseba Studio"). Only one client can control the robot at the same time to change a variable or run a program. Either don't start Aseba Studio or unlock the robot by clicking the little lock icon in the tab title near the top left corner of the Aseba Studio window.

In Thonny, the plug-in adds a menu Thymio with four commands:

  • Run on Thymio: run the program in the editor panel on the Thymio. First the program is converted (transpiled) to Aseba, the programming language of the Thymio. Then this Aseba program is loaded on the robot and started. Because of the limitations of the Thymio hardware and firmware, only a subset of Python is supported. Please see below for examples and refer to tdmclient for complete documentation.
  • Transpile Program: transpile the program in the editor panel from Python to Aseba and display the result in the Shell panel. This can be useful to understand exactly what the transpiler does, especially if you already know the Aseba language, or just to check that your program is accepted by the transpiler.
  • Stop Thymio: stop the program which runs on the robot and the robot itself.
  • Unlock Thymio: release control of the robot. The first time you execute Run on Thymio or Stop Thymio, an exclusive connection is established with the robot and no other program can control it. Unlock Thymio ends this connection until the next time you execute Run on Thymio or Stop Thymio. It can be useful to control the robot alternatively from Thonny and other applications, such as Aseba Studio or Scratch in Thymio Suite or tdmclient in Jupyter.

Program examples

blue.py

This program sets the color of the top color led to blue. Variables described in the Thymio documentation must have names with underscores (_) instead of dots (.) and are defined in the global scope.

leds_top = [0, 0, 32]

blink.py

This program illustrates the use of a timer. Event handlers are defined as functions with a @onevent decorator. To assign values to global variables (yours as well as those predefined for the Thymio), variables must be declared with global statements like in normal Python functions.

on = False

timer_period[0] = 500

@onevent
def timer0():
    global on, leds_top
    on = not on
    if on:
        leds_top = [32, 32, 0]
    else:
        leds_top = [0, 0, 0]

print.py

This program illustrates the use of functions print and exit. print accepts any number of constant strings and numeric or boolean expressions as arguments.

i = 0

timer_period[0] = 1000

@onevent
def timer0():
    global i, leds_top
    i += 1
    is_odd = i % 2 == 1
    if is_odd:
        print(i, "odd")
        leds_top = [0, 32, 32]
    else:
        print(i, "even")
        leds_top = [0, 0, 0]

@onevent
def button_center():
    exit()

clock.py

This program illustrates the use of the clock module. The time origin (time zero) is when the program starts and every time the function clock.reset() is called. Two other functions are defined: clock.ticks_50Hz() which gets the value of a number incremented 50 times per second, and clock.seconds() which gets the number of seconds (i.e. clock.ticks_50Ht()//50).

import clock

@onevent
def button_left():
    print("clock.seconds()", clock.seconds())

@onevent
def button_right():
    print("clock.ticks_50Hz()", clock.ticks_50Hz())

@onevent
def button_backward():
    print("clock.reset()")
    clock.reset()

@onevent
def button_center():
    exit()

Metadata

Release files for tdmclient-ty 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tdmclient-ty 0.1.9
File Size Uploaded
tdmclient-ty-0.1.9.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tdmclient-ty 0.1.9
File Interpreter ABI Platform
tdmclient_ty-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 27.7 kB

Release files / tdmclient-ty-0.1.9.tar.gz

Download URL tdmclient-ty-0.1.9.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
75d284d2bbe491ce80eda4b4e89e565d3b72e7c9d864ec4fcd841aa9f4134a0b
BLAKE2b-256 checksum
How to use checksums
5658149dd91b16bc00744516db5cfd372abe98dc3aed5ea897b5626e2d8e4241
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / tdmclient_ty-0.1.9-py3-none-any.whl

Download URL tdmclient_ty-0.1.9-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e744c2c5bc83556ff9057a73c0853f37d7a3cb17ee3a551bb578d6ea97e86c5
BLAKE2b-256 checksum
How to use checksums
4991594f4ac7905407015ec69c76ad1864fc159b806ff02d0988192e019cf5ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page