powered by TinkerSpace.in
Join free
TinkerPy Projects lessons
📲
Lesson 10 of 10 · Maker · 12 min

Talk to your App

Receive data from your phone app over Bluetooth, and send some back.

Your TinkerPy App sends data (one character) when you tap a widget — for example a Switch sends S for ON and s for OFF. The board reads it with bluetooth_read_char().

TinkerPy
import bluetooth

setup:
    bluetooth_begin()  # switches Bluetooth on when the board starts

loop:
    bt = bluetooth_read_char()
    if bt == 'S':
        o1 = pwm(100)
    elif bt == 's':
        o1 = 0
Tap the Switch in your app → the LED turns on and off.

Sending to the app

bluetooth_write("A") sends data to the app. An output widget — like Fire — changes when its data arrives.

TinkerPy
import bluetooth

setup:
    bluetooth_begin()  # switches Bluetooth on when the board starts

loop:
    if i2 == ON:
        bluetooth_write("A")
        o1 = pwm(100)
    else:
        bluetooth_write("a")
        o1 = 0
    wait(500)
A flame sensor on i2 makes the Fire widget burn in the app.
💡 Tip

Open the App lessons to build the app for this code!