Example Programs

Some simple example code programs and utilities are found in the examples subfolder.

examples.console

A terminal-based console that provides feedback on sensor information and allows keyboard based control of actuators. The console.py example uses the curses library to allow console over-writing. It uses line-drawing characters, which may not render correctly on default settings on Windows, kitty (a fork of putty) has an Allow ACS line drawing in UTF setting which allows the correct rendering.

It provides a useful quick test for hardware and also a useful example of how to do many low-level API calls. The console should be run without any other code (include core.py) running. It can be run as follows:

cd ~/yrk/examples
python console.py
Screen shot of console.py python program

Screen shot of console.py

The cursor keys on the keyboard can be used to move between the different motor, LED and servo options (the console sets the PWM driver up for 1.5mS analogue servos). As the console can enable and motors and servos it should be used with caution.

examples.potmotor

An simple script showing how to set the speed of motor 0, and the brightness of the LEDs, proportional to the potentiometer setting. Attach a motor to motor port 0 and set pot roughly to middle position before running!

To run:

python potmotor.py

Use Ctrl-C to exit, then run:

python stop.py

to reset motors and leds.

examples.potservo

An simple script showing how to set PWM duty cycle (on-time) of one of the servo outputs, proportional to the potentiometer setting. Attach a small analog servo to port 0. The on-time will be vary between 1.0 mS and 2.0 mS as the potentiometer is rotated, which is a typical range for most analog servos. The PWM frequency is set to about 50Hz, again typical for most servo motors.

To run:

python potservo.py

Use Ctrl-C to exit

examples.stop

An example script showing how to stop and reset everything. The following sequence takes place:

  • Call motors.stop_all_motors() to stop motors

  • Call led.set_colour_solid(0) to turn off RGB LEDs

  • Call display.clear() to clear OLED display

To run:

python stop.py
examples.stop.stop_all()

Stops and resets all actuators