The ESP32 acts as an IR tower. Install the driver once, then import whichever modules you need in each script.
rcx_driver.py and all module files to the ESP32.# Import only what you need from motion_rcx import move, stop from sound_rcx import beep move(speed=6, duration=2.0) beep()
High-level two-motor movement. Controls motors A and B together. All duration values are in seconds; omit to run until stop().
Drive forward on motors A and B.
move(speed=5, duration=2.0)
Drive in reverse on motors A and B.
backward(speed=4, duration=1.5)
Pivot left: motor A forward, motor B reverse.
turn_left(duration=0.5)
Pivot right: motor A reverse, motor B forward.
turn_right(duration=0.5)
Spin left in place.
spin_left(speed=5, duration=1.0)
Spin right in place.
spin_right(speed=5, duration=1.0)
Coast all three motors to a stop.
stop()
Hard-brake all three motors immediately.
brake()
Pause the script for the given number of seconds.
wait(1.5)
Fine-grained control of motors A, B, and C individually.
Use the constants MOTOR_A, MOTOR_B, MOTOR_C
and FORWARD, REVERSE for readable code.
Turn on a single motor.
from motors_rcx import on, power, MOTOR_A, FORWARD, REVERSE power(MOTOR_A, 5) on(MOTOR_A, FORWARD)
Coast a single motor to a stop.
off(MOTOR_A)
Hard-brake a single motor.
brake(MOTOR_B)
Set power level 0–7 before calling on().
power(MOTOR_C, 3)
Coast all three motors at once.
all_off()
Hard-brake all three motors at once.
all_brake()
Preset sounds and arbitrary tones. play_tone duration is in 1/100ths of a second.
Play one of the RCX's five built-in sounds.
| BLIP | short blip |
| BEEP | standard beep (default) |
| SWEEP | frequency sweep |
| PLING | high pling |
| BUZZ | low buzz |
from sound_rcx import beep, SWEEP beep() # default beep beep(SWEEP) # sweep sound
Play a tone at any frequency.
frequency: Hz | duration: 1/100ths second
from sound_rcx import play_tone play_tone(440, 50) # concert A, 0.5 s play_tone(880, 25) # one octave up, 0.25 s
Configure the three RCX sensor ports before reading them.
Always call configure() (or set_type + set_mode)
once at the start of your script.
Set both type and mode in one call. Use this first.
from sensors_rcx import configure, SENSOR_1, TYPE_LIGHT, MODE_PERCENT configure(SENSOR_1, TYPE_LIGHT, MODE_PERCENT)
Set the hardware type attached to a sensor port.
| TYPE_NONE | no sensor |
| TYPE_SWITCH | touch sensor |
| TYPE_TEMPERATURE | temp sensor |
| TYPE_LIGHT | light sensor |
| TYPE_ROTATION | rotation sensor |
Set how the RCX interprets the sensor reading.
| MODE_RAW | 0–1023 raw A/D |
| MODE_BOOLEAN | 0 or 1 |
| MODE_EDGE | count transitions |
| MODE_PULSE | count half-transitions |
| MODE_PERCENT | 0–100 scaled |
| MODE_CELSIUS | °C (temperature) |
| MODE_FAHRENHEIT | °F (temperature) |
| MODE_ROTATION | rotation ticks |
Reset the sensor counter or accumulator to zero. Useful for edge/pulse counting modes.
from sensors_rcx import clear, SENSOR_2 clear(SENSOR_2)
Control what the RCX LCD shows. Only one value is displayed at a time.
Display a sensor reading. sensor_id: 0, 1, or 2.
from display_rcx import show_sensor show_sensor(0) # show sensor 1 value
Display a timer value. timer_id: 0–3.
show_timer(0)
Display an RCX variable. var_id: 0–31.
show_variable(0)
Display minutes since the RCX was powered on.
show_clock()
Low-level display control using any RCX source constant.
from display_rcx import show, SOURCE_SENSOR_RAW show(SOURCE_SENSOR_RAW, 0)
RCX system control: alive check, power, IR range, messaging between bricks, and timers.
Send an alive check to the RCX. Use this to verify IR is working.
from system_rcx import ping ping()
Stop all running tasks on the RCX immediately.
stop_all()
Turn off the RCX.
power_off()
Set the RCX internal clock.
set_time(0, 0) # reset clock
Switch IR transmitter range. Use long_range=True for distance; False (default) for nearby reliable operation.
set_range(long_range=True)
Set the auto power-off delay. Pass 0 to disable.
set_power_down(0) # disable auto-off
Broadcast an IR message (0–255) to nearby RCX bricks.
set_message(42)
Reset a timer to zero. timer_id: 0–3.
clear_timer(0)
from motion_rcx import move, turn_right, stop
from sound_rcx import beep
for _ in range(4):
move(speed=6, duration=1.5)
turn_right(speed=5, duration=0.6)
stop()
beep()
from sound_rcx import play_tone
notes = [262, 294, 330, 349, 392, 440, 494, 523] # C4 to C5
for freq in notes:
play_tone(freq, 30) # 0.3 s each
from sensors_rcx import configure, SENSOR_1, TYPE_LIGHT, MODE_PERCENT from display_rcx import show_sensor from motion_rcx import move, stop configure(SENSOR_1, TYPE_LIGHT, MODE_PERCENT) show_sensor(0) # Drive while light is on, stop when dark move(speed=5)
from system_rcx import set_message
from sound_rcx import beep
import time
# Send three signals, one second apart
for i in range(3):
set_message(i + 1)
beep()
time.sleep(1)
All modules at a glance.
# motion_rcx
from motion_rcx import *
move(speed, duration)
backward(speed, duration)
turn_left(speed, duration)
turn_right(speed, duration)
spin_left / spin_right
stop() / brake() / wait(s)
# motors_rcx
from motors_rcx import *
power(motor, 0–7)
on(motor, direction)
off(motor) / brake(motor)
all_off() / all_brake()
MOTOR_A/B/C FORWARD/REVERSE
# sound_rcx
from sound_rcx import *
beep(sound)
play_tone(hz, duration)
BLIP BEEP SWEEP PLING BUZZ
# sensors_rcx
from sensors_rcx import *
configure(sensor, type, mode)
set_type(sensor, type)
set_mode(sensor, mode)
clear(sensor)
SENSOR_1/2/3
TYPE_SWITCH/LIGHT/TEMP/ROT
MODE_BOOLEAN/PERCENT/RAW...
# display_rcx
from display_rcx import *
show_sensor(id)
show_timer(id)
show_variable(id)
show_clock()
# system_rcx
from system_rcx import *
ping() / power_off()
stop_all()
set_time(h, m)
set_range(long_range)
set_power_down(minutes)
set_message(value)
clear_timer(id)
Open App
RCX.__init__() if needed.