From 3a8b34d8a09b3091dc1675f0287bc46533739497 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 28 Aug 2020 14:44:10 +0100 Subject: lego piano --- additions/modelli/lego-piano/board-full.jpg | Bin 0 -> 3083826 bytes additions/modelli/lego-piano/board-populated.jpg | Bin 0 -> 1170164 bytes additions/modelli/lego-piano/board-wired.jpg | Bin 0 -> 988414 bytes additions/modelli/lego-piano/board.jpg | Bin 0 -> 2139616 bytes additions/modelli/lego-piano/keys-hammers.mp4 | Bin 0 -> 9378106 bytes additions/modelli/lego-piano/keys-in-place.jpg | Bin 0 -> 1482801 bytes additions/modelli/lego-piano/keys.jpg | Bin 0 -> 1185543 bytes additions/modelli/lego-piano/led-matrix-test.jpg | Bin 0 -> 1748652 bytes additions/modelli/lego-piano/lego-electronics.jpg | Bin 0 -> 1737450 bytes .../lego-piano/lego-piano-scanner-schematic.svg | 2515 ++++++++++++++++++++ additions/modelli/lego-piano/piano-disassemble.jpg | Bin 0 -> 2048096 bytes .../modelli/lego-piano/sensor-matrix-test.jpg | Bin 0 -> 2323403 bytes .../modelli/lego-piano/sensor-mount-size-check.jpg | Bin 0 -> 2022954 bytes additions/modelli/lego-piano/sensor-mount-test.jpg | Bin 0 -> 709173 bytes .../modelli/lego-piano/sensor-position-test-1.jpg | Bin 0 -> 957706 bytes .../modelli/lego-piano/sensor-position-test-2.jpg | Bin 0 -> 986262 bytes .../modelli/lego-piano/sensors-mount-wiring.jpg | Bin 0 -> 1628446 bytes additions/modelli/lego-piano/sensors.jpg | Bin 0 -> 1099667 bytes additions/modelli/lego-piano/sound-test-1.mp4 | Bin 0 -> 25171908 bytes additions/modelli/lego-piano/sound-test-2.mp4 | Bin 0 -> 4786660 bytes additions/modelli/lego-piano/sound-test-3.mp4 | Bin 0 -> 10024798 bytes src/modelli/lego-piano/.gitignore | 2 + src/modelli/lego-piano/document.en.rest.txt | 258 ++ src/modelli/lego-piano/document.it.rest.txt | 257 ++ src/modelli/lego-piano/du2html.xsl | 1 + 25 files changed, 3033 insertions(+) create mode 100644 additions/modelli/lego-piano/board-full.jpg create mode 100644 additions/modelli/lego-piano/board-populated.jpg create mode 100644 additions/modelli/lego-piano/board-wired.jpg create mode 100644 additions/modelli/lego-piano/board.jpg create mode 100644 additions/modelli/lego-piano/keys-hammers.mp4 create mode 100644 additions/modelli/lego-piano/keys-in-place.jpg create mode 100644 additions/modelli/lego-piano/keys.jpg create mode 100644 additions/modelli/lego-piano/led-matrix-test.jpg create mode 100644 additions/modelli/lego-piano/lego-electronics.jpg create mode 100644 additions/modelli/lego-piano/lego-piano-scanner-schematic.svg create mode 100644 additions/modelli/lego-piano/piano-disassemble.jpg create mode 100644 additions/modelli/lego-piano/sensor-matrix-test.jpg create mode 100644 additions/modelli/lego-piano/sensor-mount-size-check.jpg create mode 100644 additions/modelli/lego-piano/sensor-mount-test.jpg create mode 100644 additions/modelli/lego-piano/sensor-position-test-1.jpg create mode 100644 additions/modelli/lego-piano/sensor-position-test-2.jpg create mode 100644 additions/modelli/lego-piano/sensors-mount-wiring.jpg create mode 100644 additions/modelli/lego-piano/sensors.jpg create mode 100644 additions/modelli/lego-piano/sound-test-1.mp4 create mode 100644 additions/modelli/lego-piano/sound-test-2.mp4 create mode 100644 additions/modelli/lego-piano/sound-test-3.mp4 create mode 100644 src/modelli/lego-piano/.gitignore create mode 100644 src/modelli/lego-piano/document.en.rest.txt create mode 100644 src/modelli/lego-piano/document.it.rest.txt create mode 120000 src/modelli/lego-piano/du2html.xsl diff --git a/additions/modelli/lego-piano/board-full.jpg b/additions/modelli/lego-piano/board-full.jpg new file mode 100644 index 0000000..3a18a44 Binary files /dev/null and b/additions/modelli/lego-piano/board-full.jpg differ diff --git a/additions/modelli/lego-piano/board-populated.jpg b/additions/modelli/lego-piano/board-populated.jpg new file mode 100644 index 0000000..f6b54e4 Binary files /dev/null and b/additions/modelli/lego-piano/board-populated.jpg differ diff --git a/additions/modelli/lego-piano/board-wired.jpg b/additions/modelli/lego-piano/board-wired.jpg new file mode 100644 index 0000000..a635d1e Binary files /dev/null and b/additions/modelli/lego-piano/board-wired.jpg differ diff --git a/additions/modelli/lego-piano/board.jpg b/additions/modelli/lego-piano/board.jpg new file mode 100644 index 0000000..e4227ff Binary files /dev/null and b/additions/modelli/lego-piano/board.jpg differ diff --git a/additions/modelli/lego-piano/keys-hammers.mp4 b/additions/modelli/lego-piano/keys-hammers.mp4 new file mode 100644 index 0000000..293e684 Binary files /dev/null and b/additions/modelli/lego-piano/keys-hammers.mp4 differ diff --git a/additions/modelli/lego-piano/keys-in-place.jpg b/additions/modelli/lego-piano/keys-in-place.jpg new file mode 100644 index 0000000..716ae41 Binary files /dev/null and b/additions/modelli/lego-piano/keys-in-place.jpg differ diff --git a/additions/modelli/lego-piano/keys.jpg b/additions/modelli/lego-piano/keys.jpg new file mode 100644 index 0000000..e03ad9c Binary files /dev/null and b/additions/modelli/lego-piano/keys.jpg differ diff --git a/additions/modelli/lego-piano/led-matrix-test.jpg b/additions/modelli/lego-piano/led-matrix-test.jpg new file mode 100644 index 0000000..6e176b3 Binary files /dev/null and b/additions/modelli/lego-piano/led-matrix-test.jpg differ diff --git a/additions/modelli/lego-piano/lego-electronics.jpg b/additions/modelli/lego-piano/lego-electronics.jpg new file mode 100644 index 0000000..2e7d007 Binary files /dev/null and b/additions/modelli/lego-piano/lego-electronics.jpg differ diff --git a/additions/modelli/lego-piano/lego-piano-scanner-schematic.svg b/additions/modelli/lego-piano/lego-piano-scanner-schematic.svg new file mode 100644 index 0000000..63c1895 --- /dev/null +++ b/additions/modelli/lego-piano/lego-piano-scanner-schematic.svg @@ -0,0 +1,2515 @@ + + + + + + image/svg+xml + + SVG Picture created as lego-piano.svg date 2020/08/28 12:25:04 + + + + + + + + + + + + + + + + SVG Picture created as lego-piano.svg date 2020/08/28 12:25:04 + Picture generated by Eeschema-SVG + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + 2 + + + 3 + + + 4 + + + + + U2 + + + QRE1113 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + 2 + + + 3 + + + 4 + + + + + U3 + + + QRE1113 + + + + + + + + + + + + + + + + + + + + + + + + + + + R1 + + + + + 330 + + + + + + + + + + + + + + + + + R3 + + + + 330 + + + + + + + + + + + + + + + + + R2 + + + + 10k + + + + + + + + + + + + + + + + + + + + R4 + + + + + 10k + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + 2 + + + 3 + + + 4 + + + + + U4 + + + + QRE1113 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + 2 + + + 3 + + + 4 + + + + + U1 + + + + QRE1113 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + 2 + + + 3 + + + 4 + + + + 5 + + + 6 + + + + J1 + + + + Conn_01x06_Male + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sense2 + + + + + + + + sense1 + + + + + + + + + row2 + + + + + + row1 + + + + + + + col2 + + + + + col1 + + + + + + sense2 + + + + + + + + sense1 + + + + + + + + + row2 + + + + + + row1 + + + + + + + col1 + + + + + + col2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/additions/modelli/lego-piano/piano-disassemble.jpg b/additions/modelli/lego-piano/piano-disassemble.jpg new file mode 100644 index 0000000..c63f673 Binary files /dev/null and b/additions/modelli/lego-piano/piano-disassemble.jpg differ diff --git a/additions/modelli/lego-piano/sensor-matrix-test.jpg b/additions/modelli/lego-piano/sensor-matrix-test.jpg new file mode 100644 index 0000000..544d7b5 Binary files /dev/null and b/additions/modelli/lego-piano/sensor-matrix-test.jpg differ diff --git a/additions/modelli/lego-piano/sensor-mount-size-check.jpg b/additions/modelli/lego-piano/sensor-mount-size-check.jpg new file mode 100644 index 0000000..76fd643 Binary files /dev/null and b/additions/modelli/lego-piano/sensor-mount-size-check.jpg differ diff --git a/additions/modelli/lego-piano/sensor-mount-test.jpg b/additions/modelli/lego-piano/sensor-mount-test.jpg new file mode 100644 index 0000000..6a3b512 Binary files /dev/null and b/additions/modelli/lego-piano/sensor-mount-test.jpg differ diff --git a/additions/modelli/lego-piano/sensor-position-test-1.jpg b/additions/modelli/lego-piano/sensor-position-test-1.jpg new file mode 100644 index 0000000..da1dde8 Binary files /dev/null and b/additions/modelli/lego-piano/sensor-position-test-1.jpg differ diff --git a/additions/modelli/lego-piano/sensor-position-test-2.jpg b/additions/modelli/lego-piano/sensor-position-test-2.jpg new file mode 100644 index 0000000..bbda47f Binary files /dev/null and b/additions/modelli/lego-piano/sensor-position-test-2.jpg differ diff --git a/additions/modelli/lego-piano/sensors-mount-wiring.jpg b/additions/modelli/lego-piano/sensors-mount-wiring.jpg new file mode 100644 index 0000000..4a084d3 Binary files /dev/null and b/additions/modelli/lego-piano/sensors-mount-wiring.jpg differ diff --git a/additions/modelli/lego-piano/sensors.jpg b/additions/modelli/lego-piano/sensors.jpg new file mode 100644 index 0000000..905ea9f Binary files /dev/null and b/additions/modelli/lego-piano/sensors.jpg differ diff --git a/additions/modelli/lego-piano/sound-test-1.mp4 b/additions/modelli/lego-piano/sound-test-1.mp4 new file mode 100644 index 0000000..52333ef Binary files /dev/null and b/additions/modelli/lego-piano/sound-test-1.mp4 differ diff --git a/additions/modelli/lego-piano/sound-test-2.mp4 b/additions/modelli/lego-piano/sound-test-2.mp4 new file mode 100644 index 0000000..2fada27 Binary files /dev/null and b/additions/modelli/lego-piano/sound-test-2.mp4 differ diff --git a/additions/modelli/lego-piano/sound-test-3.mp4 b/additions/modelli/lego-piano/sound-test-3.mp4 new file mode 100644 index 0000000..fabeefc Binary files /dev/null and b/additions/modelli/lego-piano/sound-test-3.mp4 differ diff --git a/src/modelli/lego-piano/.gitignore b/src/modelli/lego-piano/.gitignore new file mode 100644 index 0000000..08d33d4 --- /dev/null +++ b/src/modelli/lego-piano/.gitignore @@ -0,0 +1,2 @@ +/document.en.du.xml +/document.it.du.xml diff --git a/src/modelli/lego-piano/document.en.rest.txt b/src/modelli/lego-piano/document.en.rest.txt new file mode 100644 index 0000000..309d5c6 --- /dev/null +++ b/src/modelli/lego-piano/document.en.rest.txt @@ -0,0 +1,258 @@ +====================================== +Making the LEGO Grand Piano play music +====================================== +:CreationDate: 2020-08-28 10:39:28 +:Id: modelli/lego-piano +:tags: - 3dPrint + - hardware + - software + - models + +The `LEGO Grand Piano 21323 +`_ is a great +model, full of clever details and impressive engineering. + +It contains a bit of electronics, that allow it to talk with a phone +app via Bluetooth. + +.. image:: lego-electronics.jpg + :width: 100% + :alt: a Lego optical sensor, motor, power&control brick, mounted on + a wide base of sideways pieces; the motor moves a long axle + with many pegs at right angles to each other + +The app can play a few built-in tunes while running the motor inside +the piano, which pulls some keys down in a regular pattern, so you can +pretend to have a "player piano". The app can also wait for you to +press any key on the piano (they all move a little flag in front of +the optical sensor) before playing the next note, so you can pretend +to be playing. + +That's fun, but not really enough: there are 25 independent keys, +surely we can make them play the right note! + +.. image:: keys.jpg + :width: 100% + :alt: the full keyboard of the Lego piano, 2 octaves + 1, with + correctly-alternating white and black keys, each key has a + matching hammer + +.. video:: keys-hammers.mp4 + :width: 100% + :type: video/mp4 + +After some research, I decided to use optical sensors and a big +microcontroller. How hard can it be? ☺ + +As sensor I picked the `QRD1114 +`_, +which is dead easy to use: infrared LED plus phototransistor, with a +very narrow and short area of sensitivity, so there's very little +chance of nearby keys setting off the wrong sensor. + +The controller I used is a `Lilygo TTGO-T7 v1.3 +`_, +just because I had bought a bunch of them. It's a very small ESP32 +board, with 40 pins broken out, and support for charging a lithium +battery from USB. + +.. note:: + + The v1.3 is a ``d1_mini32`` board as far as the `esp32-arduino + `_ libraries are + concerned, v1.4 is a ``esp32wrover``. There are probably other + variants, so you may need to adjust something if you want to + replicate my build + + +First step was figuring out how to connect the sensors to the +controller. The LED in the QRD1114 can easily work with about 20mA, +so I can drive one directly from the ESP32, whose GPIO pins can drive +up to about 30mA. 25 sensors fit nicely in a 5×5 matrix, so something +like this should work: + +.. image:: lego-piano-scanner-schematic.svg + :width: 100% + :alt: schematic drawing of an electronic circuit; four QRD1114 are + arranged in a 2×2 grid; a pin labelled "row1" is connected to + 2 LED anodes via a 330Ω resistor and to 2 phototransistor + collectors via a 10kΩ resistor; a pin labelled "row2" is + similarly connected to the other pair; a pin labelled "col1" + is connected to the LED cathode and phototransistor emitter + of two sensors, one per "row"; a pin labelled "col2" is + similarly connected to the other pair; between each 10kΩ + resistor and the phototransistor collectors are pins labelled + "sense1" and "sense2" + +Pulling a "row" pin high (with the others low) and a "col" pin low +(with the others in high-impedance / tristate), we can turn on one +sensor at a time, so we can scan the matrix. When the phototransistor +sense light reflecting from an object in front of it, it will pull +down the "sense" pin, which we can read via the ADC in the controller. + +Testing that design on a breadboard proved that it can work! + +.. image:: sensor-matrix-test.jpg + :width: 100% + :alt: breadboard with a ESP32 dev board, 4 QRD1114 sensors, four + resistors, and a bunch of wires. One QRD1114's LED is shining + a weak pink, the others are off + +How are we going to keep the sensors in the right place inside the +piano, though? We're going to print a support that's compatible with +Lego pieces! + +.. image:: sensor-mount-test.jpg + :width: 100% + :alt: white plastic 3D-printed rectangle, 6×2 Lego studs in size, + with standard-sized studs only along one long side; 5 QRD1114 + sensors occupy one long side, and 2 Lego 1×1 plates with C + clip are on the other side + +My printer (a `Prusa i3 MK3S +`_) +can print holes of the right size for standard vias, and can print the +whole sensor support in one go (29 studs long). The sensors need to be +aligned with the hammers (there's no space behind the stems of the +keys, also the hammers are white so more visible to the +phototransistor, and move more, so it's less probable we'll have false +positives). I used `OpenSCAD `_ to `model +the support +`_. + +.. image:: sensor-mount-size-check.jpg + :width: 100% + :alt: white plastic 3D-printer rectangle, 29×2 Lego studs in size, + with 25 groups of 4 small holes to hold the sensors, placed + on top of the "strings" on the piano, showing how the holes + for the sensors align with the hammers + +We also must check positioning on the other two axes, of course. + +.. image:: sensor-position-test-1.jpg + :width: 100% + :alt: one QRD1114 mounted on the 3D-printer plastic holder, + suspended below one of the "strings" with a Lego clip piece; + the sensor sits just above and behind the rightmost hammer on + the keyboard; the hammer is in its resting position + +.. image:: sensor-position-test-2.jpg + :width: 100% + :alt: same pieces as before; the hammer is in its raised position, + precisely in front of the sensor + +At this point someone must be asking: how are we going to solder those +sensors on a *plastic* board? And the answer is, we're not going to! I +decided to go with `wire-wrapping +`_! + +.. image:: sensors-mount-wiring.jpg + :width: 100% + :alt: reverse side of the 29×2 rectangle, with 10 sensors inserted + into their holes from the front, and many thin electrical + wires, insulated in yellow plastic, connecting some of their + pins + +The sensors have 4 pins, numbered counter-clockwise looking at the LED +/ phototransistor faces: + +1. phototransistor collector, to connect to pull-up resistor and to + "row" pin +2. phototransistor emitter, to connect to "column" pin +3. LED anode, to connect to current-limiter resistor and to "row" pin +4. LED cathode, to connect to "column" pin + +so the whole wiring looks like this:: + + aM aN aO aP aQ cM cN cO cP cQ + 14 14 14 14 14 14 14 14 14 14 … + 23 23 23 23 23 23 23 23 23 23 … + Mb Nb Ob Pb Qb Md Nd Od Pd Qd + +where ``a``, ``c`` go to the pull-up resistors; ``b``, ``d`` go to the +limiter resistors, and ``M``, ``N``, ``O``, ``P``, ``Q`` go to the +column pins. + +The controller board is built in a similar way: 3D-printed and +wire-wrapped (see `the model +`_). + +.. image:: board.jpg + :width: 100% + :alt: white plastic 3D-printed rectangle, with two groups of 10x2 + holes around a label "esp", two groups of 5×2 holes around + labels "220Ω" and "10kΩ", three groups of 5 holes beside + labels "led", "gnd", "pht", and one group of 9 holes beside a + label "amp"; there is a notch in the rectangle near the "esp" + label, and a small raised block near the "amp" label + +The notch in the board corresponds to the battery connector, and the +raised block is to hold up the small `AdaFruit audio amplifier +`_ + +.. image:: board-populated.jpg + :width: 100% + :alt: same board, with all the components placed on it. The "led", + "gnd" and "pht" holes hold connectors + +.. image:: board-wired.jpg + :width: 100% + :alt: reverse of the populated board, many electrical wires + insulated in yellow plastic connect various pins + +.. image:: board-full.jpg + :width: 100% + :alt: same populated board, with a small naked speaker connected to + the amplifier + +I had some problems with the row / column connections, because not all the +GPIO pins can actually be used. After some trial and error, I settled +on: + +- row pins: 05 23 19 18 26 +- colums pins: 17 33 16 21 22 +- ADC pins: 02 04 12 27 14 +- DAC pin: 25 +- amp enable: 32 + +The program was a bit fiddly to get right, but not particularly +complicated, `you can see it in my Git repository +`_. + +.. note:: + + The TTGO board gave me some problems with uploading the compiled + image, with errors like ``A fatal error occurred: Timed out waiting + for packet content`` or ``Invalid head of packet (0xE0)``. To fix + those, I had to `set the upload speed by hand + `_ + in the ``Makefile``. + +First test with a few sensors on a breadboard: + +.. video:: sound-test-1.mp4 + :width: 100% + :type: video/mp4 + +and with all the sensors, mounted inside the piano: + +.. video:: sound-test-2.mp4 + :width: 100% + :type: video/mp4 + +I removed the Lego electronics to make space for the wires and the +controller board. + +And, finally, the whole assembled set: + +.. video:: sound-test-3.mp4 + :width: 100% + :type: video/mp4 + +At the moment the program can't really deal with more than one key +pressed at a time, as you may have noticed at the end of that last +video. The next step is to use a soundfont library, probably +`TinySoundFount `_ or `the +ESP-optimised version +`_, +which should have no problems mixing multiple notes. diff --git a/src/modelli/lego-piano/document.it.rest.txt b/src/modelli/lego-piano/document.it.rest.txt new file mode 100644 index 0000000..a6c0ea9 --- /dev/null +++ b/src/modelli/lego-piano/document.it.rest.txt @@ -0,0 +1,257 @@ +=================================== +Come far suonare in Pianoforte LEGO +=================================== +:CreationDate: 2020-08-28 10:39:28 +:Id: modelli/lego-piano +:tags: - 3dPrint + - hardware + - software + - models + +Il `Pianoforte a coda LEGO 21323 +`_ è un gran bel +modello, con un sacco di dettagli interessanti e un livello di +ingegneria veramente notevole. + +Ci sono un po' di componenti elettronici, che parlano via Bluetooth +con una app per telefono. + +.. image:: lego-electronics.jpg + :width: 100% + :alt: un sensore ottico Lego, motore, e scatola di controllo, + su una larga base di pezzi montati di lato; il motore fa girare + un lungo asse con camme ortogonali + +La app può suonare alcuni motivi predefiniti mentre fa girare il +motore dentro al pianoforte, cosa che fa abbassare un po' dei tasti in +una sequenza costante, per far finta che il pianoforte stia suonando +la musica. Oppure, la app può aspettare che premiate un tasto +qualsiasi (tutti i tasti muovono un pezzo di fronte al sensore ottico) +per suonare ciascuna nota, per far finta che stiate suonando voi. + +Carino, ma un po' tanto limitato: abbiamo 25 tasti indipendenti, ci +deve essere un modo di fargli suonare la nota giusta! + +.. image:: keys.jpg + :width: 100% + :alt: la tastiera del pianoforte Lego piano, 2 ottave + 1, con + tasti bianchi e neri in sequenza corretta; ciascun tasto ha + il suo martelletto + +.. video:: keys-hammers.mp4 + :width: 100% + :type: video/mp4 + +Dopo un po' di ricerca, ho deciso di usare sensori ottici e un +microcontroller potente. Non può essere tanto difficile, vero? ☺ + +Ho usato come sensore il `QRD1114 +`_, +che è molto semplice da usare: LED infrarosso più fototransistor, con +campo visivo molto stretto e corto, per cui è difficile che tasti +adiacenti producano falsi positivi. + +Come controller ho usato un `Lilygo TTGO-T7 v1.3 +`_, +principalmente perché ne avevo una manciata. È un ESP32, espone 40 +piedini, e può caricare una batteria al litio da USB. + +.. note:: + + La versione 1.3 è un ``d1_mini32`` per quanto riguarda le librerie `esp32-arduino + `_, la 1.4 è un + ``esp32wrover``. Son sicuro che ci siano altre versioni in giro, + potreste dover fare qualche aggiustamento su volete riprodurre quel + che ho fatto + +Per cominciare ho dovuto trovare il sistema di collegare i sensori al +controller. Il LED del QRD1114 si accontenta di 20mA, per cui posso +alimentarlo direttamente dai GPIO del ESP32, che reggono fino a circa +30mA. 25 sensori fanno una matrice 5×5, per cui qualcosa di simile a +questo circuito dovrebbe funzionare: + +.. image:: lego-piano-scanner-schematic.svg + :width: 100% + :alt: schema elettrico; quattro QRD1114 sono disposti a quadrato; + un filo etichettato "row1" è collegato agli anodi di due LED + tramite una resistenza di 330Ω e ai collettori di due + fototransistor tramite una resistenza di 10kΩ; un filo "row2" + è collegato in maniera simile agli altri due sensori; un filo + "col1" è collegato al catodo del LED e all'emettitore del + fototransistor di un sensore per riga; un filo "col2" è + collegato in maniera simile agli altri due; tra ciascuna + resistenza da 10kΩ e i fototransistor ci sono fili + etichettati "sense1" e "sense2" + +Mettendo "alto" un piedino di riga (con gli altri "bassi") e "basso" +un piedino di colonna (con gli altri ad alta impedenza / tristate), +possiamo accendere un sensore alla volta. Quando un fototransistor +vede la luce riflessa da un oggetto che gli sta davanti, abbassa il +piedino "sense", che possiamo leggere con l'ADC del controller. + +Testiamo il circuito su una breadboard per dimostrare che funziona! + +.. image:: sensor-matrix-test.jpg + :width: 100% + :alt: breadboard con un ESP32, 4 sensori QRD1114, quattro + resistenze, e un po' di fili. Un LED fa una debole luce rosa, + gli altri sono spenti + +Come facciamo a tenere i sensori al loro posto dentro il pianoforte? +Stampiamo un supporto compatibile coi pezzi Lego! + +.. image:: sensor-mount-test.jpg + :width: 100% + :alt: rettangolo di plastica bianca prodotto da una stampante 3D, + di dimensioni pari a 6×2 pezzi Lego; ci sono pispoli di + dimensione standard su uno dei lati lunghi, con 2 manine 1×1 + attaccate; cinque sensori QRD1114 sull'altro lato + +La mia stampante (una `Prusa i3 MK3S +`_) +riesce a stampare fori della dimensione giusta per i componenti +elettronici, e l'intero supporto (lungo 29 unità Lego) in una passata +sola. I sensori devono essere allineati ai martelletti (non c'è posto +dietro le stecche dei tasti, inoltre i martelletti sono bianchi per +cui più visibili ai sensori, e si muovono di più per cui riducono la +probabilità di letture sbagliate). Ho usato `OpenSCAD +`_ per `costruire il modello del supporto +`_. + +.. image:: sensor-mount-size-check.jpg + :width: 100% + :alt: rettangolo di plastica bianca prodotto da una stampante 3D, + di dimensioni pari a 29×2 pezzi Lego, con 25 gruppi di 4 fori + ciascuno per reggere i sensori, appoggiato sopra le "corde" + del pianoforte; i fori sono allineati coi martelletti + +Dobbiamo anche controllare l'allineamento sugli altri due assi, +ovviamente. + +.. image:: sensor-position-test-1.jpg + :width: 100% + :alt: un sensore QRD1114 inserito nel supporto stampato, appeso a + una delle "corde" con una manina Lego; il sensore è appena + sopra e dietro l'ultimo martelletto a destra; il martelletto + è a riposo + +.. image:: sensor-position-test-2.jpg + :width: 100% + :alt: stessi pezzi di prima; il martelletto è sollevato, proprio + davanti al sensore + +A questo punto qualcuno si starà domandando: come si fa a saldare +componenti elettronici su una basetta di *plastica*? E la risposta è +che non saldiamo nulla! Ho usato la tecnica del `wire-wrapping +`_! + +.. image:: sensors-mount-wiring.jpg + :width: 100% + :alt: retro del rettangolo 29×2, con 10 sensori montati dal davanti + nei loro fori, e tanti fili elettrici isolati in giallo che + collegano alcuni dei piedini + +Ciascun sensore ha 4 piedini, numerati in senso antiorario guardando +dalla faccia del LED / fototransistor: + +1. collettore del fototransistor, da collegare a una resistenza di + pull-up e a un piedino "riga" +2. emettitore del fototransistor, da collegare a un piedino "colonna" +3. anodo del LED, da collegare a una resistenza di limitazione e a un + piedino "riga" +4. catodo del LED, da collegare a un piedino "colonna" + +per cui i collegamenti vengono più o meno così:: + + aM aN aO aP aQ cM cN cO cP cQ + 14 14 14 14 14 14 14 14 14 14 … + 23 23 23 23 23 23 23 23 23 23 … + Mb Nb Ob Pb Qb Md Nd Od Pd Qd + +dove ``a``, ``c`` vanno alle resistenze pull-up; ``b``, ``d`` vanno +alle resistenze di limitazione, e ``M``, ``N``, ``O``, ``P``, ``Q`` +vanno ai piedini colonna. + +Ho costruito la basetta del controller nella stessa maniera: stampa e +wire-wrap (`modello +`_). + +.. image:: board.jpg + :width: 100% + :alt: rettangolo di plastica bianca prodotto da una stampante 3D, + con due gruppi di fori 10×2 intorno a una scritta "esp", due + gruppi di fori 5×2 intorno a scritte "220Ω" e "10kΩ", tre + gruppi di 5 fori ciascuno accanto a scritte "led", "gnd", + "pht", e un gruppo di 9 fori accanto a una scritta "amp"; c'è + uno svaso vicino alla scritta "esp" e un rettangolo rialzato + vicino alla scritta "amp" + +La svasatura serve a far spazio per il connettore della batteria, e il +blocchetto rialzato regge l'`amplificatore AdaFruit +`_ + +.. image:: board-populated.jpg + :width: 100% + :alt: stessa basetta, con tutti i componenti al loro posto; i fori + "led", "gnd" e "pht" hanno dei connettori + +.. image:: board-wired.jpg + :width: 100% + :alt: retro della basetta, un sacco di fili elettrici isolati in + giallo collegano i piedini + +.. image:: board-full.jpg + :width: 100% + :alt: stessa basetta, con un piccolo altoparlante collegato + all'amplificatore + +Ho avuto un po' di problemi con i piedini per righe e colonne, perché +non tutti i GPIO sono davvero usabili. Alla fine ho usato questi: + +- righe: 05 23 19 18 26 +- colonne: 17 33 16 21 22 +- ADC: 02 04 12 27 14 +- DAC: 25 +- abilitazione dell'amplificatore: 32 + +Il programma ha richiesto un po' di attenzione, ma non è +particolarmente complicato, `potete leggerlo nel mio repository Git +`_. + +.. note:: + + La circuiteria del TTGO mi ha dato un po' di problemi nel caricare + il programma compilato, producendo errori tipo ``A fatal error + occurred: Timed out waiting for packet content`` o ``Invalid head + of packet (0xE0)``. Per evitarli, ho dovuto `impostare + esplicitamente la velocità di trasferimento + `_ + nel ``Makefile``. + +Primo test con pochi sensori su una breadboard: + +.. video:: sound-test-1.mp4 + :width: 100% + :type: video/mp4 + +e con tutti i sensori, montati al loro posto nel pianoforte: + +.. video:: sound-test-2.mp4 + :width: 100% + :type: video/mp4 + +Ho rimosso i componenti elettronici Lego per far posto ai fili e al controller. + +E, finalmente, il risultato assemblato: + +.. video:: sound-test-3.mp4 + :width: 100% + :type: video/mp4 + +Al momento il programma non sa gestire più di un tasto premuto alla +volta, come probabilmente avete notato alla fine dell'ultimo filmato. +Il passo successivo è di usare una libreria soundfont, probabilmente +`TinySoundFount `_ o `la +versione ottimizzata per ESP +`_, +che dovrebbe riuscire a mixare note multiple. diff --git a/src/modelli/lego-piano/du2html.xsl b/src/modelli/lego-piano/du2html.xsl new file mode 120000 index 0000000..e2487e0 --- /dev/null +++ b/src/modelli/lego-piano/du2html.xsl @@ -0,0 +1 @@ +../../../templates/du2html.xsl \ No newline at end of file -- cgit v1.2.3