Ranger 2-Way (TOF2) × SPIKE Prime / Robot Inventor
Using the Ranger 2-Way (TOF2) with SPIKE Prime / Robot Inventor: check the edition and the wiring, then pick your software; its page covers that software only.

Which edition
Get the SPIKE edition (LEGO LPF2 plug) and plug it into any hub port A~F; no battery needed. Works with SPIKE Prime (yellow hub) and Robot Inventor (teal hub).
Wiring
② Pick your software
Official LEGO AppWhat most schools use; no firmware change, read with the colour-sensor blocksMBC Blocks websiteBlock coding with every value available; hub runs Pybricks firmware
PybricksType Python: fastest and most complete; the pick of competition teamsInteractive tutorialSPIKE
No hub needed: click through it in your browser. Pick a function on the left, watch the code or blocks build up on the right, and drag the simulated sensor to see the values.
MicroPython (Pybricks)Pybricks blocksPybricks built-in blocks (no library)MBC Blocks websiteLEGO SPIKE AppLEGO SPIKE App Python