2026 remote: wiring as found on the real remote, IMU reset fix
- Nextion is on Serial2 (pins 7/8) - already in the last commit; docs updated. - MPU6050 on Wire (18/19) so everything is on the edge headers (owner's choice); the two stick wires from 18/19 move to A7/A8 (21/22). - Stick mapping checked on the real remote: left stick X/Y/twist on A3/A7/A8, right on A0/A1/A2, all inverted but the right twist. - RemoteIMU: full device reset before waking. The remote's MPU6050 (likely a clone) answers and wakes without it but every data register reads 0. Axis defaults confirmed (+pitch nose down, +roll right side down). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0b836af8de
commit
aeccba3be7
4 files changed
+41
-39
No files matched your search
@@ -31,16 +31,18 @@ constexpr uint32_t LINK_LOST_MS = 300;
|
||||
// Logical axis order used everywhere in the remote code.
|
||||
enum StickAxis : uint8_t { L_X = 0, L_Y, L_TWIST, R_X, R_Y, R_TWIST, NUM_AXES };
|
||||
|
||||
// A0-A5 in a row, as wired for the old remote (2019-teensy-nrf24/remote/Joysticks.h).
|
||||
// A4/A5 are also Wire's SDA/SCL - that's why the MPU6050 is on Wire2 below.
|
||||
// BENCH: which physical axis is on which pin wasn't recoverable from the old
|
||||
// code; reorder these so each lands on the right logical axis ('p' dump).
|
||||
constexpr uint8_t STICK_PINS[NUM_AXES] = { A0, A1, A2, A3, A4, A5 };
|
||||
// The old remote had A0-A5 in a row (2019-teensy-nrf24/remote/Joysticks.h).
|
||||
// The two wires on A4/A5 (pins 18/19) move to A7/A8 (pins 21/22), because
|
||||
// 18/19 are Wire's SDA/SCL for the MPU6050 (owner's choice 2026-11-17: edge
|
||||
// headers only, no pads underneath). A6 (20) stays free for the battery.
|
||||
// Checked on the real remote (2026-11-17): the left stick is on A3/A7/A8, the
|
||||
// right stick on A0/A1/A2.
|
||||
constexpr uint8_t STICK_PINS[NUM_AXES] = { A3, A7, A8, A0, A1, A2 };
|
||||
|
||||
// Each logical axis must end up: X + = pushed RIGHT, Y + = pushed FORWARD
|
||||
// (away from you), TWIST + = rotated COUNTERCLOCKWISE seen from above.
|
||||
// BENCH: flip any axis that reads the wrong way on the serial 'p' status dump.
|
||||
constexpr bool STICK_INVERT[NUM_AXES] = { false, false, false, false, false, false };
|
||||
// Checked on the real remote (2026-11-17): every axis but the right twist reads inverted.
|
||||
constexpr bool STICK_INVERT[NUM_AXES] = { true, true, true, true, true, false };
|
||||
|
||||
constexpr int ADC_BITS = 12; // 0..4095
|
||||
constexpr int ADC_AVERAGING = 8; // hardware averaging per analogRead()
|
||||
@@ -69,17 +71,14 @@ constexpr float STICK_EXPO[NUM_AXES] = { 0.25f, 0.25f, 0.30f, 0.20f, 0.20f,
|
||||
// One-pole low-pass on raw ADC counts (1 = no filtering). Pots are noisy.
|
||||
constexpr float STICK_FILTER_ALPHA = 0.5f;
|
||||
|
||||
// ---- Remote IMU: MPU6050 on the third I2C bus (Wire2: SDA2 = 25, SCL2 = 24) ----
|
||||
// On the Teensy 4.0, 24/25 are solder pads on the underside, not edge pins.
|
||||
// Not Wire (18/19): those pins are stick axes A4/A5. Not Wire1 (17/16) either:
|
||||
// those are stick axes A3/A2.
|
||||
#define IMU_WIRE Wire2
|
||||
// ---- Remote IMU: MPU6050 on Wire (SDA = 18, SCL = 19) ----
|
||||
// Edge-header pins; the stick axes that used to be there moved to A7/A8.
|
||||
#define IMU_WIRE Wire
|
||||
constexpr uint8_t IMU_ADDR = 0x68; // 0x69 if AD0 is pulled high
|
||||
// Mounting remap: which chip axis (0=X,1=Y,2=Z) and sign gives each handset
|
||||
// axis. Handset frame: +X = away from you, +Y = your left, +Z = up.
|
||||
// BENCH: with the defaults the chip is assumed flat, component side up, its
|
||||
// X arrow pointing away from you. Verify with the serial 'p' dump: tipping
|
||||
// the far edge down must read +pitch, dipping the right side must read +roll.
|
||||
// Checked on the real remote (2026-11-17): the defaults are right - tipping
|
||||
// the far edge down reads +pitch, dipping the right side reads +roll.
|
||||
constexpr uint8_t IMU_AXIS_FROM_CHIP[3] = { 0, 1, 2 };
|
||||
constexpr int8_t IMU_AXIS_SIGN[3] = { +1, +1, +1 };
|
||||
constexpr float IMU_ALPHA = 0.98f; // complementary filter, same as the robot
|
||||
|
||||
@@ -16,34 +16,27 @@ at 100 Hz.
|
||||
`BATTERY_SENSE_PIN = A6` in `Config.h` once it's wired. A low-battery
|
||||
warning is still to do.
|
||||
|
||||
- **IMU on the normal pin headers** (suggestion, not done): with the GY-521 on
|
||||
the main board, wire it to Wire (SDA 18 / SCL 19) instead of Wire2 (the
|
||||
24/25 pads under the Teensy 4.0). 18/19 are A4/A5, used by two stick axes
|
||||
now, so move those two axes to A7 (pin 21) and A8 (pin 22): all on the
|
||||
edge headers. A6 (pin 20) stays free for the battery divider, A9 (23) is
|
||||
spare. Firmware: in `Config.h` `STICK_PINS = { A0, A1, A2, A3, A7, A8 }`
|
||||
and `#define IMU_WIRE Wire`; `Sticks.cpp` reads through `STICK_PINS`, so
|
||||
nothing else changes. Redo the stick axis check (`p` dump) and calibration
|
||||
afterwards. (Wire1 is no way out: its 16/17 are stick pins A2/A3 too.)
|
||||
|
||||
## Building
|
||||
|
||||
From the `2026-current` folder: `pio run -e remote`, flash with
|
||||
`pio run -e remote -t upload`, monitor with `pio device monitor -e remote`.
|
||||
|
||||
## Wiring (from the old remote sketch in `../../2019-teensy-nrf24/remote/`; edit `Config.h` if yours differs)
|
||||
## Wiring (edge headers only; edit `Config.h` if yours differs)
|
||||
|
||||
| Part | Signal | Teensy 4.0 pin |
|
||||
|------|--------|----------------|
|
||||
| nRF24L01 | MOSI / MISO / SCK | 11 / 12 / 13 (SPI0) |
|
||||
| nRF24L01 | CE / CSN | 9 / 10 |
|
||||
| nRF24L01 | VCC | 3.3 V, with a 10–100 µF cap right at the module |
|
||||
| MPU6050 | SDA / SCL | **25 / 24 (Wire2)**, solder pads on the underside of the 4.0: not 18/19, those are stick pins A4/A5 |
|
||||
| MPU6050 | SDA / SCL | **18 / 19 (Wire)** |
|
||||
| Nextion | TX → RX2, RX ← TX2 | 7 / 8 (Serial2), 5 V supply (found on the real remote) |
|
||||
| Sticks | 6 axes | A0–A5. Which axis is on which pin isn't known yet: reorder `STICK_PINS` until the `p` dump reads right |
|
||||
| Sticks | 6 axes | left stick X / Y / twist on **A3 / A7 / A8** (17 / 21 / 22), right stick on **A0 / A1 / A2** (14 / 15 / 16). A7/A8 hold the two wires that were on A4/A5 (18/19). All but the right twist read inverted (`STICK_INVERT`). Checked on the real remote |
|
||||
| Battery (planned) | divider | A6 (20) |
|
||||
|
||||
**MPU6050 rewiring:** the old remote had its MPU code switched off, probably
|
||||
because A4/A5 double as Wire's pins. Move the MPU's SDA/SCL to pins 25/24 (the pads under the board).
|
||||
**Rewiring from the old remote:** move the two stick wires from 18/19 to
|
||||
21/22, then put the MPU on 18/19 (Wire). The old remote had its MPU code
|
||||
switched off, probably because A4/A5 double as Wire's pins. Redo the stick
|
||||
axis check (`p` dump) and the sweep calibration afterwards.
|
||||
|
||||
Stick pots are wired 3.3 V – wiper – GND. **Never feed 5 V into a Teensy
|
||||
4.x analog pin.**
|
||||
|
||||
@@ -18,8 +18,15 @@ static bool writeReg(uint8_t reg, uint8_t val) {
|
||||
bool RemoteIMU::begin() {
|
||||
IMU_WIRE.begin();
|
||||
IMU_WIRE.setClock(400000);
|
||||
ok_ = writeReg(REG_PWR_MGMT_1, 0x00); // wake out of sleep
|
||||
// Full device reset first: the remote's MPU6050 (likely a clone) answers
|
||||
// and wakes without it, but every data register reads 0 until it has been
|
||||
// reset (found on the real remote, 2026-11-17).
|
||||
ok_ = writeReg(REG_PWR_MGMT_1, 0x80);
|
||||
if (!ok_) return false;
|
||||
delay(100);
|
||||
ok_ = writeReg(REG_PWR_MGMT_1, 0x01); // wake, clocked from the X gyro PLL
|
||||
if (!ok_) return false;
|
||||
delay(50);
|
||||
writeReg(REG_CONFIG, 0x03); // 44 Hz DLPF: a handheld remote doesn't need more bandwidth
|
||||
delay(50);
|
||||
|
||||
|
||||
Reference in new issue
Block a user