powered by TinkerSpace.in
Join free
TinkerPy Tutorial ๐Ÿ“˜ Part 1 ยท Starter ยท Chapter 12 of 24

Fixed-Pin and Special Modules

Some modules always sit on the same pins, some can go on any pin, and some need no wires at all because they are built into the board! Learn how to switch on ultrasonic, robot motors, joystick, TV remote, GPS, GSM, Bluetooth, IoT, Wireless, Counter and Clock โ€” and plan your own big project.

๐Ÿ“–Key words

Fixed-pin module

A module that always uses the same pins, like the ultrasonic sensor (i3 + i4 on Mega) or the robot motors (o3โ€“o6). Its setup lines say โ€œcannot be changedโ€.

Special components

The part of Circuit Connections where you switch fixed-pin modules on and off: I2C parts, Ultrasonic, Right motor and Left motor.

Board feature

Something built into the board that needs no wires: Bluetooth, IoT, Wireless, Wireless IoT, Counter and Clock.

Device ID

Every TinkerKit boardโ€™s own name, like TP00000002 (Menu โ†’ Device info). Wireless uses it to find the other board.

P and N

The two pins of a robot motor. If a wheel turns the wrong way, Circuit Connections can swap P and N for you.

๐ŸŽฌSee it work

Which pins does it take?

Sort each module: fixed pins, a pin you pick, or no pins at all.

Mini or Mega?

Tap each board to see which special modules it can use.

๐Ÿง How it works

Fixed-pin modules (Special components)

  • Ultrasonic ๐Ÿ“ก โ€” measures distance with an echo: distance() in cm. Mega: i3 TRIG + i4 ECHO. Mini: i2 TRIG + i1 ECHO โ€” thatโ€™s both Mini inputs.
  • Right motor โš™๏ธ โ€” o3 (P) + o4 (N). Left motor โ€” o5 (P) + o6 (N). Switch on one or both; drive them with robot_control(), not with o3 = ON.
  • A wheel turns the wrong way? Tap โ‡„ swap to swap its P and N pins.
  • I2C parts (OLED, LCD, sensors) take o7 + o8 โ€” chapter 11.
  • If a fixed pin is already used, Circuit Connections warns you and offers Remove & add.

Special modules you put on a pin

  • DHT11 ๐Ÿ’ฆ โ€” temperature (ยฐC) and humidity (%). Only on an input pin; it has its own wiring, so no mode. Adds import dht11.
  • Joystick ๐Ÿ•น๏ธ โ€” TinkerPy Mega only. X and Y need input pins (i1โ€“i4); the push switch can be any pin. Ticking Joystick adds all three lines on free pins.
  • TV remote ๐Ÿ“บ โ€” an IR receiver on any free pin. Teach the board your remote first: Menu โ†’ TV Remote โ†’ Learn Remote.
  • GPS ๐Ÿ›ฐ๏ธ โ€” location, speed and time from satellites: one pin. GSM ๐Ÿ“ฑ (SIM800L) โ€” SMS and calls: a receive pin plus a send output pin. Both need board firmware 2.28+, one of each per board. SMS cost money โ€” use with an adult.

Board features: no wires needed

  • Tap them in Circuit Connections โ†’ Board features. They add an import line and take no pins.
  • Bluetooth ๐Ÿ“ถ โ€” talk to the TinkerPy App on a phone nearby. Mega only; it adds bluetooth_begin() to setup.
  • IoT ๐ŸŒ โ€” talk to the app over the internet. The board needs WiFi (the Board WiFi box in Circuit Connections).
  • Wireless ๐Ÿ“ก โ€” board to board, nearby, using each boardโ€™s Device ID (up to 6 boards). Wireless IoT ๐Ÿ›ฐ๏ธ โ€” board to board through the internet. Both Mega only.
  • Counter ๐Ÿ”ข โ€” counters c1 to c8 that can count by themselves. Clock โฐ โ€” clock_start(7, 0, 0), then read HH, MM and SS.

Plan a big project

  • Write the problem first, then list every input, output and feature it needs.
  • Mark the fixed pins first (ultrasonic, motors, I2C), then give the rest to free pins.
  • Check the board: Bluetooth, joystick and Wireless need a TinkerPy Mega.
  • Code each module in depth in TinkerPy Coder: ultrasonic, DHT11 and joystick (ch 3), robots (ch 4), Bluetooth and IoT (ch 6), Wireless and TV remote (ch 7), Counter and Clock (ch 8), GSM and GPS (ch 12).

๐Ÿ’ปCode

Text
Module            Switch it on in               Pins it takes                      Board
----------------  ----------------------------  ---------------------------------  ---------
Ultrasonic        Special components            Mega: i3 TRIG + i4 ECHO             Mini, Mega
                                                Mini: i2 TRIG + i1 ECHO
Right motor       Special components            o3 (P) + o4 (N)                    Mini, Mega
Left motor        Special components            o5 (P) + o6 (N)                    Mini, Mega
I2C parts         Special components            o7 (SDA) + o8 (SCL)                Mini, Mega
DHT11             a pin: Special                one input pin                      Mini, Mega
Joystick          a pin: Special / Libraries    X, Y: input pins; switch: any pin  Mega
TV remote         a pin: Special / Libraries    any one free pin                   Mini, Mega
GPS               a pin: GPS & GSM              any one pin (firmware 2.28+)       Mini, Mega
GSM               a pin: GPS & GSM              any pin + one output pin (2.28+)   Mini, Mega
Bluetooth         Board features                none                               Mega
IoT               Board features (+ WiFi)       none                               Mini, Mega
Wireless          Board features                none                               Mega
Wireless IoT      Board features (+ WiFi)       none                               Mega
Counter           Board features                none (c1 - c8)                     Mini, Mega
Clock             Board features                none (HH, MM, SS)                  Mini, Mega

Every fixed-pin module, special module and board feature: where you switch it on in Circuit Connections, which pins it takes and which board it works on.

# Add the libraries you need
import ultrasonic

# Give your pins easy-to-remember names
o1 = set_name("warning")

# ===== Parking sensor =====

# This code block executes only once
setup:
    i3 = set_input(ultrasonic_trig)  # cannot be changed
    i4 = set_input(ultrasonic_echo)  # cannot be changed
    warning = set_output(led)

# This code block executes forever
loop:
    distance_cm = distance()  # how far it is, in cm
    if distance_cm > 0 and distance_cm < 20:  # closer than 20 cm?
        warning = ON  # turn warning ON
    else:  # otherwise
        warning = OFF  # turn warning OFF

A parking sensor on the TinkerPy Mega: switching on Ultrasonic wrote import ultrasonic and the two โ€œcannot be changedโ€ lines for i3 and i4. On a Mini, Circuit Connections writes i2 (TRIG) and i1 (ECHO) instead.

# Add the libraries you need
import tv_remote
import motor

# ===== TV remote robot =====

# This code block executes only once
setup:
    i1 = set_function(tv_remote)  # TV remote receiver (TSOP1838) โ€” learn the keys on the board: Menu > TV Remote
    o3 = set_output(right_motor_P)
    o4 = set_output(right_motor_N)
    o5 = set_output(left_motor_P)
    o6 = set_output(left_motor_N)

# This code block executes forever
loop:
    key = remote_read()  # the TV remote key pressed (1-9, 0, a-d, up, ok, ch+ โ€ฆ) into key โ€” None if no key
    if key == "up":  # when key == "up"
        robot_control("F", 80, "F", 80)  # Left 80% Forward, Right 80% Forward : Robot - Moving Forward
    elif key == "ok":  # otherwise, when key == "ok"
        robot_control("S", 0, "S", 0)  # stop both motors

A TV-remote robot: ticking TV Remote put the receiver on a free pin (i1), and switching on both motors took o3โ€“o6. The up key drives forward, ok stops. Learn your remoteโ€™s keys on the board first.

# Add the libraries you need
import bluetooth

# Give your pins easy-to-remember names
o1 = set_name("lamp")

# ===== Phone lamp =====

# This code block executes only once
setup:
    lamp = set_output(led)
    bluetooth_begin()  # switches Bluetooth on when the board starts

# This code block executes forever
loop:
    letter = bluetooth_read_char()  # the letter the app sent (Bluetooth) into letter โ€” None if nothing new
    if letter == "S":  # when letter == "S"
        lamp = ON  # turn lamp ON
    elif letter == "s":  # otherwise, when letter == "s"
        lamp = OFF  # turn lamp OFF

A phone-controlled lamp for the TinkerPy Mega: switching on Bluetooth added import bluetooth and bluetooth_begin() โ€” no pins at all. The app sends S for on and s for off.

# Add the libraries you need
import clock
import counter
import buzzer

# Give your pins easy-to-remember names
o1 = set_name("bell")

# ===== Morning bell =====

# This code block executes only once
setup:
    bell = set_output(buzzer)
    clock_start(6, 59, 50)  # start the clock at 6:59:50 and let it start ticking
    c1.set(0)  # set c1 straight to 0

# This code block executes forever
loop:
    if HH == 7 and MM == 0 and SS == 0:  # when HH == 7 and MM == 0 and SS == 0
        bell = ON  # turn bell ON
        c1.increment()  # one more morning rung
        wait(1000)  # pause here for 1000 milliseconds before continuing
        bell = OFF  # turn bell OFF

A morning bell with two board features: Clock (starts at 6:59:50, so the bell rings after 10 seconds) and Counter (c1 counts how many times it has rung). Neither takes a pin.

Open TinkerPy Code

๐ŸŽ‰Fun examples

๐Ÿฆ‡Bat sonar

Bats find insects in the dark by sending out sounds too high for us to hear and listening for the echo โ€” just like the ultrasonic sensor.

๐Ÿ“บOld remote, new life

An old TV remote lying at home can become the controller for your robot car once the board has learnt its keys.

๐Ÿ›ฐ๏ธSatellites above you

A GPS module listens to signals from satellites high above the Earth and works out where you are from their timing.

๐ŸŒWhere itโ€™s used

๐Ÿ› ๏ธProject ideas

Plan a robot car

Plan a robot with two motors, an ultrasonic sensor and an OLED. Write down the pins they take (o3โ€“o6, i3/i4, o7/o8), then choose free pins for a headlight LED and a horn buzzer. Check it in Circuit Connections.

๐Ÿงฐ You need: notebook, TinkerPy Mega board or Simulator
Big project planning sheet

Pick a problem (forgotten plants, a noisy classroom, a dark staircase). Fill a sheet: inputs, outputs, features, pins, board (Mini or Mega) and the logic in plain words. Swap sheets with a friend to check for pin clashes.

๐Ÿงฐ You need: A4 sheet, pencil

โญPoints to remember

  1. Fixed-pin modules always use the same pins.
  2. Ultrasonic: Mega i3 TRIG + i4 ECHO; Mini i2 TRIG + i1 ECHO.
  3. Right motor o3 + o4; left motor o5 + o6.
  4. Drive motors with robot_control(), not o3 = ON.
  5. Swap P and N if a wheel turns the wrong way.
  6. DHT11 goes on an input pin only.
  7. Joystick, Bluetooth and Wireless need a TinkerPy Mega.
  8. TV remote: any free pin; learn the keys on the board.
  9. GPS and GSM need board firmware 2.28 or newer.
  10. Board features take no pins.
  11. IoT and Wireless IoT need the boardโ€™s WiFi.
  12. Counters are c1 to c8.
  13. Clock: clock_start(h, m, s), then HH, MM, SS.
  14. Plan fixed pins first, then the free pins.
๐Ÿคฏ
Did you know?

Sound travels about 343 metres every second in air, so the echo from a wall 1 metre away comes back to the ultrasonic sensor in less than one hundredth of a second.

โ“Mini quiz

๐Ÿ”‘
Log in to try the mini quiz

5 quick questions to check yourself โ€” free with your TinkerPy account.

Log in