Example programs
The same examples the VS Code extension lists under Examples: for every part of the robot a
minimal and a complete program, in Python and, where there are blocks for it, in blocks. Download one and open it
in the extension (a .evnblocks file opens in the blocks editor). Needs says what to
plug in, and how to set the robot up, before you run it.
Board, button, LED and timing battery, button, LED, wait, StopWatch
-
Board: minimalboard_minimal.py · board_minimal.evnblocksNeeds: nothing but the board; you press the user button when it asks
-
Board: the whole APIboard_complete.py · board_complete.evnblocksNeeds: nothing but the board (a battery pack for the battery readings); you press the user button when it asks.
Motor EV3 / NXT motors on ports 1-4
-
Motor: minimalmotor_minimal.py · motor_minimal.evnblocksNeeds: a motor on port 1, wheel off the ground
-
Motor: the whole APImotor_complete.py · motor_complete.evnblocksNeeds: motors on ports 1 and 2, wheels off the ground (the calibration turns each shaft for about twelve seconds, up to about a turn and a half each way); when the program asks, you hold the wheel on port 1 until it stops (stall detection).
Robot (DriveBase) two wheel motors driven together
-
Robot: minimalrobot_minimal.py · robot_minimal.evnblocksNeeds: a robot: left wheel motor on port 4 (mounted mirrored), right on port 3, 62.4 mm wheels 170 mm apart, and 40 cm of clear floor ahead
-
Robot: the whole DriveBase APIrobot_complete.py · robot_complete.evnblocksNeeds: a robot: left wheel motor on port 4 (mounted mirrored), right on port 3, 62.4 mm wheels 170 mm apart, an EVN IMU on I2C port 3 fixed flat to the chassis, and 40 cm of clear floor ahead and 20 cm to each side (the robot also pivots about 45 degrees on its right wheel and back). Keep the robot still while the program starts: the IMU calibrates its gyro 8 to 25 s into stillness.
Pose (where the robot is) position and heading from the wheels, an IMU and a compass
-
Pose: minimalpose_minimal.py · pose_minimal.evnblocksNeeds: a robot: left wheel motor on port 4 (mounted mirrored), right on port 3, 62.4 mm wheels 170 mm apart; you push it along the floor while the program runs.
-
Pose: the whole APIpose_complete.py · pose_complete.evnblocksNeeds: a robot: left wheel motor on port 4 (mounted mirrored), right on port 3, 62.4 mm wheels 170 mm apart, an EVN IMU on I2C port 3 fixed flat to the chassis, and 40 cm of clear floor ahead and to the right. A compass on I2C port 14, calibrated on the robot (Compass.calibrate()), is used when it is there. Keep the robot still while the program starts: the IMU calibrates its gyro 8 to 25 s into stillness.
Colour sensor TCS34725 on an I2C port
-
Colour sensor: minimalcolour_sensor_minimal.py · colour_sensor_minimal.evnblocksNeeds: the colour sensor on I2C port 1, and something coloured to hold under it
-
Colour sensor: the whole APIcolour_sensor_complete.py · colour_sensor_complete.evnblocksNeeds: the colour sensor on I2C port 1, a white sheet, and something coloured.
Distance sensor VL53L0X time of flight on an I2C port
-
Distance sensor: minimaldistance_sensor_minimal.py · distance_sensor_minimal.evnblocksNeeds: the distance sensor on I2C port 1
-
Distance sensor: the whole APIdistance_sensor_complete.py · distance_sensor_complete.evnblocksNeeds: the distance sensor on I2C port 1, and a hand or a box to move in front of it.
Gesture sensor APDS-9960 on an I2C port
-
Gesture sensor: minimalgesture_sensor_minimal.py · gesture_sensor_minimal.evnblocksNeeds: the gesture sensor on I2C port 1, and a hand to swipe a few cm above it
-
Gesture sensor: the whole APIgesture_sensor_complete.py · gesture_sensor_complete.evnblocksNeeds: the gesture sensor on I2C port 1 (nothing over it at the start), a hand, a white sheet, and something coloured.
Environment sensor BME280: temperature, humidity, pressure
-
Environment sensor: minimalenvironment_sensor_minimal.py · environment_sensor_minimal.evnblocksNeeds: the environment sensor (BME280) on I2C port 1
-
Environment sensor: the whole APIenvironment_sensor_complete.py · environment_sensor_complete.evnblocksNeeds: the environment sensor (BME280) on I2C port 1, with its small vent hole left uncovered.
Compass magnetometer on an I2C port, with its calibration
-
Compass: minimalcompass_minimal.py · compass_minimal.evnblocksNeeds: an EVN compass module on I2C port 2, away from the motors
-
Compass: the whole APIcompass_complete.py · compass_complete.evnblocksNeeds: an EVN compass module (HMC5883L or QMC5883L) on I2C port 2, fixed flat to the robot away from the motors; room to turn the robot on the floor and to pick it up and tumble it.
Touch pads MPR121, 12 pads
-
Touch pads: minimaltouch_pads_minimal.py · touch_pads_minimal.evnblocksNeeds: the touch pads (MPR121) on I2C port 1
-
Touch pads: the whole APItouch_pads_complete.py · touch_pads_complete.evnblocksNeeds: the touch pads (MPR121) on I2C port 1, and bare fingers.
IMU gyro and accelerometer, with its calibration
-
IMU: minimalimu_minimal.py · imu_minimal.evnblocksNeeds: an EVN IMU module on I2C port 1, fixed flat to the robot; keep it still for the first seconds
-
IMU: the whole APIimu_complete.py · imu_complete.evnblocksNeeds: an EVN IMU module (MPU-6500) on I2C port 1, fixed flat to the robot with the x axis of its silkscreen pointing forward (else set axes()); a table and a book; you tilt, tap and turn the robot when the program asks.
ADC ADS1115: four analogue inputs
-
ADC: minimaladc_minimal.py · adc_minimal.evnblocksNeeds: the ADC module on I2C port 1, and a voltage of 0 to 3.3 V on A0 (for example a potentiometer between the board's 3.3 V and GND pins, its middle pin on A0); never more than 3.3 V on a pin
-
ADC: the whole APIadc_complete.py · adc_complete.evnblocksNeeds: the ADC module on I2C port 1, and a voltage of 0 to 3.3 V on A0 (for example a potentiometer between the board's 3.3 V and GND pins, its middle pin on A0; A1..A3 may stay open). Never more than 3.3 V on a pin, whatever the range.
Display 128x64 OLED
-
Display: minimaldisplay_minimal.py · display_minimal.evnblocksNeeds: the OLED display on I2C port 1
-
Display: the whole APIdisplay_complete.py · display_complete.evnblocksNeeds: the OLED display on I2C port 1.
LED matrix 8x8 matrix (HT16K33)
-
LED matrix: minimalled_matrix_minimal.py · led_matrix_minimal.evnblocksNeeds: the 8x8 LED matrix on I2C port 1
-
LED matrix: the whole APIled_matrix_complete.py · led_matrix_complete.evnblocksNeeds: the 8x8 LED matrix on I2C port 1.
7-segment display four digits (HT16K33)
-
7-segment display: minimalseven_segment_minimal.py · seven_segment_minimal.evnblocksNeeds: the 7-segment display on I2C port 1
-
7-segment display: the whole APIseven_segment_complete.py · seven_segment_complete.evnblocksNeeds: the 7-segment display on I2C port 1.
RGB LEDs WS2812B strip on a servo port
-
RGB LEDs: minimalrgb_leds_minimal.py · rgb_leds_minimal.evnblocksNeeds: the RGB LED module (8 LEDs) on servo port 1
-
RGB LEDs: the whole APIrgb_leds_complete.py · rgb_leds_complete.evnblocksNeeds: the RGB LED module (8 LEDs) on servo port 1.
Servo hobby servos on ports 1-4
-
Servo: minimalservo_minimal.py · servo_minimal.evnblocksNeeds: a Geekservo 270-degree servo on servo port 1, horn free to turn
-
Servo: the whole APIservo_complete.py · servo_complete.evnblocksNeeds: a Geekservo 270-degree servo on servo port 1 and a Geekservo continuous-rotation servo on servo port 2, both with nothing in the way of the horn.
Bluetooth HC-05 module on a serial port
-
Bluetooth: minimalbluetooth_minimal.py · bluetooth_minimal.evnblocksNeeds: the Bluetooth module on serial port 2, and a phone (Android) or PC paired with it (PIN 1234) running a Bluetooth serial terminal app that ends each line it sends with a newline
-
Bluetooth: the whole APIbluetooth_complete.py · bluetooth_complete.evnblocksNeeds: the Bluetooth module on serial port 2, and a phone (Android) or PC paired with it (PIN 1234) running a Bluetooth serial terminal app that ends each line it sends with a newline.
UART (serial ports) Serial 1 and 2 as plain UARTs (MicroPython's machine.UART)
-
UART: minimaluart_minimal.py · uart_minimal.evnblocksNeeds: a jumper wire from TX to RX on Serial 1 (or a device talking 115200 baud lines there)
-
UART: the whole APIuart_complete.py · uart_complete.evnblocksNeeds: a jumper wire from TX to RX on Serial 1 (the board hears what it sends). Without the wire the program still runs and says nothing came back.
I2C (any device) raw I2C on ports 1-16, for devices without a class
-
I2C: minimali2c_minimal.py · i2c_minimal.evnblocksNeeds: an EVN IMU module (MPU-6500) on I2C port 1
-
I2C: the whole APIi2c_complete.py · i2c_complete.evnblocksNeeds: an EVN IMU module (MPU-6500) on I2C port 1. Other EVN modules on that port are named when they have an ID register; the rest (display 0x3C, LED matrix 0x71, seven-segment 0x74, touch pads 0x5A, ADC 0x48) are listed by address only, not identified.
Files on the board open(), os and the flash file system
-
Files: minimalfiles_minimal.py · files_minimal.evnblocksNeeds: nothing but the board
-
Files: the whole tourfiles_complete.py · files_complete.evnblocksNeeds: the board, and a motor on port 1 with its wheel off the ground (for the last part: a log recorded while the motor runs, written once it has stopped).
Data log (recorded on the board) motors, sensors, the battery and your own rows, saved to a CSV file
-
Data log: minimaldatalog_minimal.py · datalog_minimal.evnblocksNeeds: a motor on port 1, free to turn; an EVN IMU module on I2C port 1, kept still
-
Data log: completedatalog_complete.py · datalog_complete.evnblocksNeeds: a motor on port 1, free to turn; an EVN IMU module on I2C port 1, kept still; a battery pack.
Controllers (PID and ADRC) your own control loops: a line follower, a heading hold
-
Controllers: minimalcontrollers_minimal.py · controllers_minimal.evnblocksNeeds: a robot: left wheel motor on port 4 (mounted mirrored), right on port 3, 62.4 mm wheels 170 mm apart; an EVN colour sensor on I2C port 2 facing the floor a few mm up, over the edge of a dark line on a light floor
-
Controllers: completecontrollers_complete.py · controllers_complete.evnblocksNeeds: a robot: left wheel motor on port 4 (mounted mirrored), right on port 3, 62.4 mm wheels 170 mm apart; an EVN colour sensor on I2C port 2 facing the floor a few mm up, over the edge of a dark line on a light floor; an EVN IMU on I2C port 1
Extended Peripherals HiTechnic NXT colour sensor and compass, HuskyLens, VL53L1X, TCS3430
HiTechnic colour sensor HiTechnic NXT Color Sensor V1 / V2 (NXT cable adapter, 100 kHz)
-
HiTechnic colour sensor: minimalhitechnic_color_minimal.py · hitechnic_color_minimal.evnblocksNeeds: a HiTechnic NXT Color Sensor (V1 or V2) on I2C port 8, through an NXT cable adapter
-
HiTechnic colour sensor: the whole APIhitechnic_color_complete.py · hitechnic_color_complete.evnblocksNeeds: a HiTechnic NXT Color Sensor (V1 or V2) on I2C port 8, through an NXT cable adapter, a white sheet of paper
HiTechnic compass HiTechnic NXT Compass Sensor (NXT cable adapter, 100 kHz)
-
HiTechnic compass: minimalhitechnic_compass_minimal.py · hitechnic_compass_minimal.evnblocksNeeds: a HiTechnic NXT Compass Sensor on I2C port 5, through an NXT cable adapter; room to turn the robot on the floor
-
HiTechnic compass: the whole APIhitechnic_compass_complete.py · hitechnic_compass_complete.evnblocksNeeds: a HiTechnic NXT Compass Sensor on I2C port 5, through an NXT cable adapter; room to turn the robot on the floor
HuskyLens DFRobot HuskyLens AI camera (I2C mode)
-
HuskyLens: minimalhuskylens_minimal.py · huskylens_minimal.evnblocksNeeds: a DFRobot HuskyLens set to Protocol Type I2C on I2C port 11
-
HuskyLens: the whole APIhuskylens_complete.py · huskylens_complete.evnblocksNeeds: a DFRobot HuskyLens set to Protocol Type I2C on I2C port 11
VL53L1X distance sensor ST VL53L1X time-of-flight distance sensor, up to 4 m
-
VL53L1X distance sensor: minimalvl53l1x_minimal.py · vl53l1x_minimal.evnblocksNeeds: an ST VL53L1X distance sensor on I2C port 1
-
VL53L1X distance sensor: the whole APIvl53l1x_complete.py · vl53l1x_complete.evnblocksNeeds: an ST VL53L1X distance sensor on I2C port 1, a flat grey or white card and a ruler
TCS3430 colour sensor ams-OSRAM TCS3430 XYZ colour and light sensor
-
TCS3430 colour sensor: minimaltcs3430_minimal.py · tcs3430_minimal.evnblocksNeeds: an ams-OSRAM TCS3430 colour sensor on I2C port 16
-
TCS3430 colour sensor: the whole APItcs3430_complete.py · tcs3430_complete.evnblocksNeeds: an ams-OSRAM TCS3430 colour sensor on I2C port 16, a white sheet of paper