Basics

Here you will find the basics of programming the Calliope mini

LED Matrix

RGB LED

Speaker

Button A

Button B

Pin -

Pin +

Pin P0

Pin P1

Pin P2

Pin P3

Motion Sensor

Light Sensor

Processor

Microphone

Radio

Outputs / Output
LED Matrix

The Calliope mini's LED matrix consists of 5 x 5 = 25 red LEDs, which can display not only numbers and texts but also images and animations. Larger screens work similarly, with the light points, also called pixels, being much denser.

Display Text

Individual letters or entire words and sentences can be displayed. In Open Roberta, it can be set whether the text is displayed as individual characters or scrolls through the screen as an animation. In MakeCode, the text automatically scrolls across the LED display if it is longer than one character.

MakeCode Python Scratch vertical_align_bottom ----

Display Numbers

Individual digits or larger numbers with decimal places can be displayed. In Open Roberta, it can be set whether larger numbers are displayed as individual digits or scroll through the screen as an animation. In MakeCode, numbers with more than one digit automatically scroll as an animation.

MakeCode Python Scratch vertical_align_bottom

Display Symbols

Predefined symbols and images can be selected and displayed on the LED matrix.

MakeCode Python

Display Custom Images

Individual light points can be turned on or off for custom symbols.

MakeCode Python Scratch vertical_align_bottom

RGB LED

The RGB LED can shine in various colors. Specifically, it can display 256^3 = 16.7 million colors, as the different colors are mixed additively from three primary colors, each with a range of 0-255 in programming. The additive color mixing is based on the concept that almost any color can be composed of the three colors red, green,

and blue. Black is displayed when the sum is 0, i.e., all LEDs are turned off, and white when all LEDs are at maximum brightness. The secondary colors yellow, cyan, and magenta are mixed from two colors each. For example, yellow is composed of green and red and has the RGB value (255, 255, 0). The Calliope mini V3 has three RGB LEDs built-in. They can all shine in one color or different colors.

MakeCode Python Scratch vertical_align_bottom

Speaker

The Calliope mini can play music and sounds with its built-in piezo speaker. A piezo speaker is based on the piezoelectric effect, derived from the ancient Greek piezein, meaning to press. When an electrical voltage is applied to the material, it deforms in the rhythm of the frequency. Thus, an audio signal composed of various frequencies can be converted into sound waves. The same principle works in reverse as a microphone.

MakeCode Python Scratch vertical_align_bottom
Inputs / Input
Buttons - A, B, AB

Everywhere in our lives we find buttons that we need to press to trigger actions and functions, e.g., a PC keyboard, a game controller, or the buttons on a vending machine. A button works similarly to a switch, except it closes the circuit as long as the button is pressed. The Calliope mini has two buttons: A and B. Pressing them simultaneously can also create a third input option: A + B.

MakeCode Python Scratch vertical_align_bottom


Touchpins - P0, P1, P2, P3

The touch pins are I/O input/output pins that are ideal for closing a circuit with your fingers or attaching alligator clips. The six-sided Calliope mini has a total of four touch pins, numbered from P0 to P3, as well as a plus and minus pin. Both the pins and the positive pole all supply a voltage of 3.3 volts. It is important to touch the minus pin to trigger a "pressing of the pins" (or you change the property programmatically, then it works without the minus pin). All pins are digital. Pins P1 and P2 are also analog, so they can be used to control servos or output the analog values of a potentiometer. The Calliope mini V3 has another touch pin on the back: the golden touch logo. This touch logo also works without touching the minus pin.

MakeCode Python Scratch vertical_align_bottom

Sensors
Motion and Position Sensor

The motion and position sensor contains an accelerometer, a gyroscope, and a magnetometer (compass). This allows the Calliope mini to measure, for example, its orientation and the direction and strength of its movement.

Gestures

The various gestures with which the Calliope is moved, shaken, etc., can be called up as events in the respective programming environment.

MakeCode Python Scratch vertical_align_bottom

Accelerometer

The accelerometer (accelerometer) can measure precise increases or decreases in speed. The values are given in thousandths of the Earth's acceleration (g-force) and can be retrieved for the 3 axes x, y, and z, as well as the total strength. The strength corresponds to the total length of all force vectors and can be calculated using the Pythagorean theorem: √(x²+y²+z²). Note that gravity always acts as an acceleration or attraction force on us and is also detected by the accelerometer.

MakeCode Python Scratch vertical_align_bottom

Gyroscope

The gyroscope or gyro sensor can measure the orientation or rotation of the two axes x and y in degrees (°). A rotation of the X-axis is called pitching and a rotation of the Y-axis is called rolling. If you place the Calliope mini on a table and draw a line between Pin 0 and Pin 3, that is the X-axis. The Y-axis lies between the USB port and the opposite edge between Pin 1 and 2.

MakeCode Python Scratch vertical_align_bottom

Compass

The integrated magnetometer can measure the magnetic force of the Earth's magnetic field and thus serve as a compass. The direction is given in degrees (°). North is at 0°, east at 90°, south at 180°, and west at 270°.

MakeCode Python Scratch vertical_align_bottom

Light Sensor

Light-emitting diodes (LEDs) can not only emit light but also capture light as photodiodes. The LED matrix on the Calliope mini is also the light sensor, which can measure the ambient light. This allows the Calliope mini to recognize brightness differences between indoors and outdoors or day and night. The brightness is output in a different value range in the respective editor. In Open Roberta in percent 0 - 100 and in MakeCode in 8-bit from 0 - 255.

MakeCode Python Scratch vertical_align_bottom


Processor

Temperature Sensor

A temperature sensor is built into the processor, which measures the temperature of the processor. With a small conversion, the approximate ambient temperature can also be measured with the Calliope mini. The temperature is output in degrees Celsius (°C).

MakeCode Python Scratch vertical_align_bottom

Runtime

The runtime gives us the time that has elapsed since the program started. When the Calliope mini's "reset" is pressed and the program restarts, the runtime is reset to 0. Unlike the pauses, the runtime allows you to work with intervals that do not block the processor's program flow. This is known as "non-blocking" code. Many functions in Makecode, like the forever loop, already take the principle of parallelism into account. The runtime is very precise and can be output in microseconds (μs), which is one millionth of a second, or milliseconds (ms), which is one-thousandth of a second.

MakeCode Python Scratch vertical_align_bottom


Microphone / Volume Sensor

With the MEMS microphone, the volume can be measured. It ranges from 0 - 100 percent in the Open Roberta Lab and from 0 - 255 in MakeCode.

MakeCode Python Scratch vertical_align_bottom


Radio

The Calliope mini has a small antenna with which electromagnetic waves can be transmitted and received. It supports two wireless transmission services: radio, which allows messages to be transmitted between different Calliope mini devices, and Bluetooth, which allows the Calliope mini to pair with other devices such as phones and tablets to transmit data or be programmed. Only one service can be activated at a time. Communication can take place over different radio groups/channels, which are set in the programming. Only Calliope mini devices in the same radio group can communicate with each other.
In the MakeCode editor, the radio extension must be loaded separately. Select the "radio" package under "Extensions".

Send Values

Numbers, texts, and logical values (Open Roberta) can be sent. In MakeCode, a pair of values consisting of a name and a number can also be sent.

MakeCode Python

Receive Values

The values can be received and retrieved when the Calliope mini devices are in the same radio group/channel.

MakeCode Python
Commands and Functions
Sequence

A sequence is the simplest form of instruction. The program follows your instructions from top to bottom.

Python

Start

The start function is included in many editors and defines what should be executed once at the program start. It is like the entry point and access to the program. Just like in a game or an event in real life, the rules and conditions for the program flow are defined in advance in variables.

MakeCode

Pause

Pauses are important when programming to allow the computer to wait briefly. This can be important so that, for example, a color display is visible longer before the program continues reading and executing. However, the pause also suspends the entire program for this period. If other tasks need to be performed during this time, such as playing a sound while the LED blinks at an interval, it is recommended to use the runtime.

MakeCode Python Scratch vertical_align_bottom

Loops

In programming, a loop is a control structure. It repeats instructions indefinitely or until a termination condition is met.

Forever / Repeat Indefinitely

The "forever" loop ensures that an instruction is executed repeatedly. This is important in programming so that certain sections of code are executed continuously. For programming continuous programs without termination conditions, such as games, interaction projects, or sensor measurements, this block is usually indispensable.

MakeCode Python Scratch vertical_align_bottom

Repeat x Times

The instructions within the loop are executed as many times as specified.

MakeCode Python Scratch vertical_align_bottom

Repeat Until / While

The "repeat until" loop executes an instruction as long as a termination condition is met. A termination condition must be a truth value or a logical statement that can be true or false. An example would be letting the LED blink until the temperature drops below 10 degrees. "While" is the counterpart to "repeat as long". The code is executed as long as the condition is true. "Repeat until" works the other way around. The code is executed repeatedly while a condition is still false, or has not occurred, and is aborted when it is true.

MakeCode Python Scratch vertical_align_bottom

Repeat for Index from to

This loop increments an index for a defined range of values and makes it available as a variable locally within the loop. The loop starts at the start value and breaks when the highest value is reached. It is suitable, for example, for counting up a countdown with the value of the index or for retrieving values from a list.

MakeCode Python Scratch vertical_align_bottom

Logic

With logic blocks, a program flow can be controlled and can lead to different outputs and results with different inputs. Logic is based on Boolean algebra, where two states/values of true and false or 1 and 0 are combined and lead to different outputs. Such logical combinations form the basis for transistor circuits in processors and digital electronics.

Logical/Boolean Operators

There are logical operators such as negation (not), conjunction (and), disjunction (or), and comparisons like greater than (>), less than (<), and equal to (=). With logical operators, truth values like true and false can be returned.

MakeCode Python Scratch vertical_align_bottom


Conditional Statement

The conditional statement, known as the "if, then" or "if, do" block, only executes a section if a condition is met. An example would be turning on the RGB LED only when the temperature rises above 20 degrees. The LED stays red even if the temperature drops below 20 degrees again. A branch provides an alternative program section with "otherwise" that is executed if the condition is not met or false. In the example of the LED, it could be turned off if it is below 20 degrees.

MakeCode Python

If, then / otherwise, if / otherwise

The second form of multiple branching can be imagined as a tree structure. The first condition is checked. If this is true, it goes to the next branch with the next condition. If this is false, the entire branching is aborted and the next conditions are not checked. The order is crucial here. In the programming editors, several conditions can be added by clicking on the "+".

MakeCode Python Scratch vertical_align_bottom

Mathematics

A processor processes only two states 0 and 1 / on and off, but with the help of an arithmetic-logical unit (ALU) based on transistor circuits, arithmetic operations are performed in no time. Thus, the Calliope mini can also be used as a calculator in the decimal system and solve complex mathematical and logical tasks.

Arithmetic Operators

With arithmetic operators such as addition (+), subtraction (-), multiplication (*), and division (/), numbers are returned that can be negative or positive and have decimal places.

MakeCode Python Scratch vertical_align_bottom

Modulo / Remainder of Division

The modulo operator (%) returns the remainder of a division of two numbers and can be helpful in finding even numbers (i%2), generating a repeating pattern of numbers, or retrieving the X values of the LEDs in the 5x5 grid (i%5).

MakeCode Python Scratch vertical_align_bottom

Random

A random number is chosen within a defined range of numbers. Randomness plays an important role in programming games and in data encryption. When a die is thrown in real life, the result is difficult to predict due to many physical influences, although it is theoretically possible. Since computers work predictably (deterministically), i.e., they always produce the desired result after input, randomness is generated in some cases by entering physical, arbitrary data, such as keystrokes, ambient noise, position, etc.

MakeCode Python Scratch vertical_align_bottom

Variables

Variables in programming are a kind of "container" where a program can store a data value, such as a number, a string, or a symbol. A variable can be queried and changed. For example, the score in a game is written to a variable and can thus be constantly queried and changed.

MakeCode Python Scratch vertical_align_bottom

Lists

Lists are a data type that can contain multiple numbers, texts, truth values, or even images. The values of a list can be processed and retrieved using loops as a stack.

Add Values

Values can be added to a list at the end, at the beginning, or at the position of the index.

MakeCode Python Scratch vertical_align_bottom

Retrieve Values

All values of a list can be retrieved and read using the index with a loop.

MakeCode Python Scratch vertical_align_bottom

Functions

Functions are like self-defined program modules that can be recycled and reused, allowing a more complex program to be structured into subprograms. They can also be thought of as a machine that performs a specific function, as the word suggests.

Function / Procedure

A procedure simply outsources the program code to another location and can be called as often as the function is called (e.g., in a loop).

MakeCode Python Scratch vertical_align_bottom

Function with Input Parameter

A function with an input parameter is more flexible because it can process different input values locally and generate an individual output. For example, a function can be written for the blinking heart, and the number of times the LED should blink can be specified as a parameter.

MakeCode Python Scratch vertical_align_bottom

Function with Return Value

A function with a return value can be thought of as a machine that produces a product or intermediate product. The return value is a data type, such as a number or a logical value, and can serve as an input again.

MakeCode Python