Skip to content

Hub Built-in Sensors

The hub itself is a bundle of sensors: a 6-axis gyro and two buttons, plus two output devices - the light matrix and speaker. None of them use a port.

Gyro / IMU

A six-axis inertial measurement unit, the core of precise FLL navigation. Three angles:

AngleMeaningFLL use
YawRobot heading (horizontal rotation)Turns and straight driving - 90% of usage
PitchNose up/downDetect ramps / being lifted
RollLean left/rightRarely used

Word Blocks

(yaw angle)                    ← Sensors category reporter
reset yaw angle [0]
<hub [shaken]>
wait until <yaw angle > [88]>

Key behaviors

  • Yaw counts from the heading at start; turning right increases it (clockwise positive), range -180 to 180.
  • reset yaw angle 0 defines the current heading as 0; later readings are relative to it.
  • Gyros drift slightly: readings creep while standing still. Reset before every launch, and re-reset mid-program when you get a chance (while squared against a wall).

Example: gyro right turn 90°

reset yaw angle [0]
start moving [steering 100]
wait until <yaw angle > [88]>          ← stop 2° early; momentum covers the rest
stop moving

Why 88 and not 90: the robot coasts a little after the stop command. Measure your own lead value - details in Gyro Driving & Turns.

Hub buttons

Left and right buttons are programmable (the center button belongs to the system: start/stop programs):

when [left] button [pressed]
<[right] button [pressed]>

Uses: toggling debug modes, manual attachment zeroing, pit-side confirmation.

Light Matrix (output)

5x5 LEDs - your debugging display:

display image [SMILE]
write [Go]
turn off pixels
set pixel [x] [y] to [100] %

The most useful trick: display a live sensor value.

forever
  write (color sensor [C] reflected light)

Speaker (output)

play beep [60] for [0.2] seconds     ← 60 is pitch (MIDI note number), not frequency

Put different beeps at key points in the program: your eyes watch the robot, your ears track the program.

Python

python
import runloop, motor_pair
from hub import port, motion_sensor, light_matrix, button, sound

async def main():
    motion_sensor.reset_yaw(0)
    angles = motion_sensor.tilt_angles()   # (yaw, pitch, roll) in DECIdegrees!
    yaw = angles[0] / 10                   # convert to degrees

    await light_matrix.write("Hi")
    sound.beep(440, 200, 100)              # 440 Hz, 200 ms, volume 100

    if button.pressed(button.LEFT):        # returns ms held, 0 = not pressed
        pass

runloop.run(main())

Python angles are in 0.1-degree units

tilt_angles() returns yaw in decidegrees: a reading of 900 = 90°. Divide by 10 before using.

Sensors complete. Now put them to work: Advanced Word Blocks.