attiny radio

This commit is contained in:
Pascal Engélibert 2023-05-16 11:50:44 +02:00
parent 285669fef5
commit b3ebbf34b4
4 changed files with 101 additions and 4 deletions

View file

@ -20,7 +20,7 @@ Ce modèle utilise des composants beaucoup moins chers et moins sujets aux ruptu
## Licence
CopyLeft 2022-2023 Pascal Engélibert
CopyLeft 2022-2023 Pascal Engélibert [(pourquoi copyleft ?)](https://txmn.tk/fr/blog/why-copyleft/)
Ces instructions sont mises à disposition selon les termes de la licence [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/).

View file

@ -1,5 +1,9 @@
# Téléphone jukebox
Deux versions :
* `telephone`: joue le fichier correspondant au chiffre entré sur le cadran
* `radio`: joue tous les fichiers en boucle
## Prérequis
* 1 Attiny402
@ -9,7 +13,7 @@
* 1 résistance de 1kΩ
* de quoi fabriquer un PCB (précision SOIC requise pour le Attiny)
* ce qu'il faut pour programmer un Attiny (https://github.com/SpenceKonde/megaTinyCore)
* une Arduino suffit. Suivez de toute façon les instructions de megaTinyCore.
* une Arduino (Mega ou Nano) suffit. Suivez de toute façon les instructions de megaTinyCore.
* 1 carte micro-SD
## Électronique
@ -35,9 +39,37 @@ Si les fils sont cassants (monobrins), je conseille de les enrouler autour du ma
Placez les fichiers audio au format MP3 dans le dossier `mp3` de la carte SD. Ils doivent être nommés de `0001.mp3` à `0009.mp3`. Le fichier `0099.mp3` est lu en boucle quand aucun numéro n'est composé (on peut y mettre un BIP de quelques secondes par exemple).
Pour la version radio, tous les fichiers à la racine sont lus en boucle.
## Programmation
On utilise jtag2updi qui nécessite uniquement une carte de type Arduino (Mega ou Nano, mais pas Micro).
Après avoir installé MegaTinyCore et [jtag2updi](https://github.com/ElTangas/jtag2updi), téléversez le croquis jtag2updi dans la carte Arduino.
Connectez l'Attiny à l'Arduino :
* (Arduino) <-> Attiny
* +5V <-> +5V
* GND <-> GND
* **(tout modèle sauf Mega) D6 <-> UPDI
* **(Arduino Mega uniquement) D18 <-> UPDI
Choisissez les paramètres suivants :
* Type de carte : megaTinyCore/ATtiny402
* Chip : ATtiny402
* Clock : 20MHz internal
* Other settings: default
* Programmateur : jtag2updi (n'apparaît qu'après avoir choisi la carte)
Ne pas graver le bootloader. Graver le programme telephone ou radio avec le bouton classique (ne pas utiliser "graver avec un programmateur").
Si pendant le téléversement le message `avrdude: jtagmkII_getsync(): sign-on command: status -1` apparaît à répétition, il peut être nécessaire d'appuyer sur le bouton Reset de la carte Arduino. Le téléversement devrait démarrer juste après.
## Licence
CopyLeft 2023 Pascal Engélibert
CopyLeft 2023 Pascal Engélibert [(pourquoi copyleft&#8239;?)](https://txmn.tk/fr/blog/why-copyleft/)
Ces instructions sont mises à disposition selon les termes de la licence [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/).

65
attiny402/radio/radio.ino Normal file
View file

@ -0,0 +1,65 @@
#include <DFMiniMp3.h>
/*
* CopyLeft 2022-2023 Pascal Engélibert
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
*/
// Radio Jukebox
#define PIN_TX PIN_PA6
#define PIN_RX PIN_PA7
bool playing = false;
class Mp3Notify;
typedef DFMiniMp3<HardwareSerial, Mp3Notify> DfMp3;
DfMp3 dfmp3(Serial);
class Mp3Notify {
public:
static void PrintlnSourceAction(DfMp3_PlaySources source, const char* action)
{
}
static void OnError([[maybe_unused]] DfMp3& mp3, uint16_t errorCode)
{
}
static void OnPlayFinished([[maybe_unused]] DfMp3& mp3, [[maybe_unused]] DfMp3_PlaySources source, uint16_t track) {
playing = false;
}
static void OnPlaySourceOnline([[maybe_unused]] DfMp3& mp3, DfMp3_PlaySources source) {}
static void OnPlaySourceInserted([[maybe_unused]] DfMp3& mp3, DfMp3_PlaySources source) {}
static void OnPlaySourceRemoved([[maybe_unused]] DfMp3& mp3, DfMp3_PlaySources source) {}
};
void wait_ms(uint16_t msWait) {
uint32_t start = millis();
while((millis() - start) < msWait) {
// if you have loops with delays, its important to
// call dfmp3.loop() periodically so it allows for notifications
// to be handled without interrupts
dfmp3.loop();
delay(1);
}
}
void setup() {
delay(1000);
//Serial.begin(9600, SERIAL_8N1);
dfmp3.begin();
dfmp3.setVolume(24);
//dfmp3.setPlaybackSource(DfMp3_PlaySource_Sd);
wait_ms(1000);
//dfmp3.playMp3FolderTrack(0);
dfmp3.setRepeatPlayAllInRoot(true);
wait_ms(1000);
}
void loop() {
wait_ms(10);
}

View file

@ -64,7 +64,7 @@ Pistes d'amélioration qui n'ont pas encore été réalisées :
## Licence
CopyLeft 2022 Pascal Engélibert
CopyLeft 2022 Pascal Engélibert [(pourquoi copyleft&#8239;?)](https://txmn.tk/fr/blog/why-copyleft/)
Ces instructions sont mises à disposition selon les termes de la licence [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/).