Skip to content

Commit 92241ff

Browse files
committed
Improved readme
1 parent 420e785 commit 92241ff

File tree

1 file changed

+78
-51
lines changed

1 file changed

+78
-51
lines changed

README.md

Lines changed: 78 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,24 @@ A MicroPython Bluetooth library for controlling LEGO hubs and creating custom Bl
1414

1515
## Installation
1616

17-
```bash
18-
pip install btbricks
17+
### On LMS-ESP32
18+
19+
The module should be included in the latest Micropython firmware from <https://wwww.antonsmindstorms.com>. If not, use ViperIDE or Thonny and create a new file called rcservo.py.
20+
Copy the contents from the same file in this repository inside.
21+
22+
### On MicroPython device using `micropip` from PyPI
23+
24+
```python
25+
import micropip
26+
await micropip.install("btbricks")
1927
```
2028

29+
Note: `micropip` must be available on the target board and may require an internet connection from the device.
30+
31+
### On SPIKE Legacy or MINDSTORMS Robot Inventor
32+
33+
Use the installer script in mpy-robot-tools: <https://github.com/antonvh/mpy-robot-tools/blob/master/Installer/install_mpy_robot_tools.py>
34+
2135
## Quick Start
2236

2337
### Connect to a LEGO Hub
@@ -47,67 +61,83 @@ if hub.is_connected():
4761
```
4862

4963
### Create an RC Receiver (Hub-side)
50-
RCReceiver, R_STICK_HOR, R_STICK_VER
51-
52-
# Create RC receiver
53-
receiver = RCReceiver(name="robot")
54-
55-
# Wait for transmitter connection
56-
while not receiver.is_connected():
57-
pass
64+
Use the examples in the `examples/` folder for full, runnable code. Minimal receiver/transmitter snippets:
5865

59-
print("Transmitter connected!")
66+
```python
67+
from btbricks import RCReceiver, R_STICK_HOR, R_STICK_VER
68+
from time import sleep_ms
69+
70+
# Create RC receiver (advertises as "robot" by default)
71+
rcv = RCReceiver(name="robot")
72+
73+
print("Waiting for RC transmitter to connect...")
74+
try:
75+
while True:
76+
if rcv.is_connected():
77+
steering = rcv.controller_state(R_STICK_HOR)
78+
throttle = rcv.controller_state(R_STICK_VER)
79+
print(f"Steering: {steering}, Throttle: {throttle}")
80+
sleep_ms(100)
81+
else:
82+
sleep_ms(500)
83+
except KeyboardInterrupt:
84+
rcv.disconnect()
85+
```
6086

61-
# Read control values in a loop
62-
while receiver.is_connected():
63-
steering = receiver.get_value(R_STICK_HOR)
64-
throttle = receiver.get_value(R_STICK_VER)
65-
print(f"Steering: {steering}, Throttle: {throttle}"
66-
receiver.on_data = on_rc_data
67-
receiver.start()
68-
```RCTransmitter, R_STICK_HOR, R_STICK_VER
87+
```python
88+
from btbricks import RCTransmitter, L_STICK_HOR, R_STICK_VER
6989
from time import sleep
7090

71-
# Create transmitter
91+
# Create RC transmitter (central)
7292
tx = RCTransmitter()
7393

74-
# Connect to receiver
7594
if tx.connect(name="robot"):
76-
while tx.is_connected():
77-
# Set stick values
78-
tx.set_stick(R_STICK_HOR, 50) # Steering at 50%
79-
tx.set_stick(R_STICK_VER, 75) # Throttle at 75%
80-
81-
# Send to receiver
82-
tx.transmit()
83-
sleep(0.1ransmitter = RCTransmitter(ble)
84-
85-
# Connect and send RC commands
86-
transmitter.connect_and_send(b'LEGO Hub', {
87-
R_STICK_HOR: 50, MidiController
88-
from time import sleep
95+
try:
96+
while tx.is_connected():
97+
# Set stick values in range [-100, 100]
98+
tx.set_stick(L_STICK_HOR, 0)
99+
tx.set_stick(R_STICK_VER, 50)
100+
tx.transmit()
101+
sleep(0.1)
102+
except KeyboardInterrupt:
103+
tx.disconnect()
104+
```
89105

90-
# Create MIDI controller
91-
midi = MidiController()
106+
### Create a MIDI Controller
92107

93-
# Send MIDI note on
94-
midi.send_note_on(60, 100) # Middle C, velocity 100
95-
sleep(0.5)
108+
```python
109+
from btbricks import MidiController
110+
from time import sleep
96111

97-
# Send MIDI note off
112+
# Create MIDI controller (advertises as "amh-midi" by default)
113+
midi = MidiController(name="amh-midi")
98114

99-
ble = BLEHandler()
100-
midi = MidiController(ble)
115+
print("MIDI controller started, connect from your DAW...")
101116

102-
# Connect to MIDI device and send note on
103-
midi.connect_to_hub(b'LEGO Hub')
104-
midi.send_note_on(60, 100) # Middle C, velocity 100
105-
midi.send_note_off(60)
117+
try:
118+
while True:
119+
# Send MIDI note on: middle C (note 60), velocity 100
120+
midi.note_on(60, 100)
121+
sleep(0.5)
122+
123+
# Send MIDI note off
124+
midi.note_off(60)
125+
sleep(0.5)
126+
127+
# Or send a chord
128+
midi.chord_on("C4", velocity=100, style="M") # C major chord
129+
sleep(1)
130+
midi.note_off(60) # Stop the chord
131+
132+
except KeyboardInterrupt:
133+
print("MIDI controller stopped")
106134
```
107135

108-
## API Reference
136+
## Documentation and API reference
109137

110-
See the [documentation](docs/api.rst) for detailed API reference.
138+
See the full documentation and API reference at:
139+
140+
https://docs.antonsmindstorms.com/en/latest/Software/btbricks/docs/index.html
111141

112142
### Core Classes
113143

@@ -134,9 +164,6 @@ See the [documentation](docs/api.rst) for detailed API reference.
134164
- **ESP32** with MicroPython
135165
- Other MicroPython boards with `ubluetooth` support
136166

137-
## Firmware Notes
138-
139-
SPIKE Prime requires the MINDSTORMS firmware for Bluetooth support. See [Anton's Mindstorms documentation](https://docs.antonsmindstorms.com) for detailed setup instructions.
140167

141168
## License
142169

0 commit comments

Comments
 (0)