Wiki

Reso-nance numérique | Arts et cultures libres

Outils du site


projets:le_miracle_dans_le_magasin:accueil

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
projets:le_miracle_dans_le_magasin:accueil [2018/02/19 14:32]
jerzon Créé depuis le formulaire projets:creer
projets:le_miracle_dans_le_magasin:accueil [2018/02/21 09:59] (Version actuelle)
resonance [Final code miracle]
Ligne 3: Ligne 3:
   * Date : 19/02/2018/ - ...   * Date : 19/02/2018/ - ...
   * Licence : [[http://creativecommons.org/licenses/by-sa/3.0/legalcode|CC-by-sa-3.0]]   * Licence : [[http://creativecommons.org/licenses/by-sa/3.0/legalcode|CC-by-sa-3.0]]
-  * Description : synchronisation le son au mouvement +  * Description : synchroniser le son au mouvement 
-  * Fichiers sources : //mettre un lien// +  * Fichiers sources : {{ :projets:le_miracle_dans_le_magasin:miracle.zip |}} 
-  * Lien //mettre un lien//+
  
 {{tag>bluetooth moteur lecteur mp3 synchronisation}} {{tag>bluetooth moteur lecteur mp3 synchronisation}}
Ligne 14: Ligne 14:
 {{projets:le_miracle_dans_le_magasin:accueil:img_7668.jpg?800|le miracle dans le magasin}} {{projets:le_miracle_dans_le_magasin:accueil:img_7668.jpg?800|le miracle dans le magasin}}
  
-===== Matériaux ===== 
-Liste de matériel et composants nécessaires. 
  
-===== Tutoriel ===== +===== Matériel =====
-Guide pas à pas pour la réalisation du projet.+
  
 +<WRAP group>
 +<WRAP half column>
 +{{:projets:le_miracle_dans_le_magasin:20180129_180010.jpg?600|}}
 +</WRAP>
 +
 +<WRAP half column>
 +  * Android avec application "Arduino Bluetooth Controller" : Se connecter au module bluetooth HC-05, choisir "switch mode" et mettre "a" pour on et "b" pour off
 +  * 1 ARDUINO NANO 3.0
 +  * 1 UART Série mp3 LECTEUR MODULE BORD 3W OPEN-SMART
 +  * 1 CARTE MICRO SD
 +  * 1 HC-05 BLUETOOTH  maitre-esclave
 +  * 2 Batteries 3,7 V 720 mAh 25C V931 F949
 +  * 1 ULN 
 +  * 1 MOTEUR RS445PA14233R 
 +  * 1 ENCEINTE 
 +  * 1 CÂBLE mini JACK/ mini JACK
 +  * 1 BREADBOARD
 +</WRAP>
 +</WRAP>
 +
 +
 +===== Codes Arduino =====
 +==== Tests ====
 +  * {{ :projets:le_miracle_dans_le_magasin:test_hc05_slave.zip |}}
 +  * {{ :projets:le_miracle_dans_le_magasin:test_serial_mp3.zip |}}
 +  * {{ :projets:le_miracle_dans_le_magasin:test_uln2003_dc.zip |}}
 +
 +==== Final code "miracle" ====
 +  * {{ :projets:le_miracle_dans_le_magasin:miracle.zip |}}
 +
 +
 +<code cpp>
 +/* Projet Miracle - Jérôme Kdiajanian
 + * Code : Reso-nance numérique (+ Open-Smart Demo)
 + * 29/01/2018
 + * System : Android with "Arduino Bluetooth Controller App" > send "A" or "B" caracter > HC-05 Bluetooth > Arduino UNO > Open Smart Serial MP3 player + ULN2003 driver > DC motor
 + *
 + * Wiring :
 + * Serial MP3 Player A    | Arduino UNO R3//
 + * RX                     | 7
 + * TX                     | 8
 + * VCC                    | 5V
 + * GND                    | GND
 + * Bluetooth HC-05        
 + * TX                     | 11
 + * RX                     | 10
 + * Driver ULN2003         | 5
 +*/
 +
 +#include <SoftwareSerial.h>
 +
 +// MP3 pins
 +#define ARDUINO_RX 8 //should connect to TX of the Serial MP3 Player module
 +#define ARDUINO_TX 7 //connect to RX of the module
 +SoftwareSerial myMP3(ARDUINO_RX, ARDUINO_TX);
 +
 +// HC-05 pins
 +#define rxPin 11 // Broche 11 Arduino en tant que RX --- TX du HC-05
 +#define txPin 10 // Broche 10 Arduino en tant que TX --- RX du HC-05
 +SoftwareSerial BTserial(rxPin, txPin); // RX | TX
 +
 +// ULN 2003 (dc motor) pin
 +int motorpin = 5;
 +
 +// Command Strings to "Arduino Bluetooth Controller App"
 +String state;
 +String A = "128"; // nothing (test)
 +String B = "120";
 +
 +static int8_t Send_buf[6] = {0} ;
 +/************Command byte**************************/
 +/*basic commands*/
 +#define CMD_PLAY  0X01
 +#define CMD_PAUSE 0X02
 +#define CMD_NEXT_SONG 0X03
 +#define CMD_PREV_SONG 0X04
 +#define CMD_VOLUME_UP   0X05
 +#define CMD_VOLUME_DOWN 0X06
 +#define CMD_FORWARD 0X0A // >>
 +#define CMD_REWIND  0X0B // <<
 +#define CMD_STOP 0X0E
 +#define CMD_STOP_INJECT 0X0F//stop interruptting with a song, just stop the interlude
 +
 +/*5 bytes commands*/
 +#define CMD_SEL_DEV 0X35
 +#define DEV_TF 0X01
 +#define CMD_IC_MODE 0X35
 +#define CMD_SLEEP   0X03
 +#define CMD_WAKE_UP 0X02
 +#define CMD_RESET   0X05
 +
 +/*6 bytes commands*/  
 +#define CMD_PLAY_W_INDEX   0X41
 +#define CMD_PLAY_FILE_NAME 0X42
 +#define CMD_INJECT_W_INDEX 0X43
 +
 +/*Special commands*/
 +#define CMD_SET_VOLUME 0X31
 +#define CMD_PLAY_W_VOL 0X31
 +#define CMD_SET_PLAY_MODE 0X33
 +#define ALL_CYCLE 0X00
 +#define SINGLE_CYCLE 0X01
 +#define CMD_PLAY_COMBINE 0X45//can play combination up to 15 songs
 +
 +void sendCommand(int8_t command, int16_t dat );
 +
 +void setup() 
 +{
 +  myMP3.begin(9600);
 +  delay(500);//Wait chip initialization is complete
 +
 +  // HC05
 +  pinMode(rxPin, INPUT);
 +  pinMode(txPin, OUTPUT);
 +  BTserial.begin(38400); // serial bluetooth
 +
 + sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card  
 + delay(200);//wait for 200ms
 +
 + pinMode(motorpin, OUTPUT);    
 +}
 +
 +void loop() 
 +{
 +   while(BTserial.available()) {
 +    state = BTserial.read();
 +      if(state == B) {
 +        playWithVolume(0XFF01); //play the first song with volume
 +        accel_motor();
 +        delay(1000); //wait
 +      }
 +      else if(state == A) {
 +       // nothing
 +      }
 +   }
 +}
 +
 +void setVolume(int8_t vol)
 +{
 +  mp3_5bytes(CMD_SET_VOLUME, vol);
 +}
 +void playWithVolume(int16_t dat)
 +{
 +  mp3_6bytes(CMD_PLAY_W_VOL, dat);
 +}
 +
 +/*cycle play with an index*/
 +void cyclePlay(int16_t index)
 +{
 +  mp3_6bytes(CMD_SET_PLAY_MODE,index);
 +}
 +
 +void setCyleMode(int8_t AllSingle)
 +{
 +  mp3_5bytes(CMD_SET_PLAY_MODE,AllSingle);
 +}
 +
 +void playCombine(int8_t song[][2], int8_t number)
 +{
 +  if(number > 15) return;//number of songs combined can not be more than 15
 +  uint8_t nbytes;//the number of bytes of the command with starting byte and ending byte
 +  nbytes = 2*number + 4;
 +  int8_t Send_buf[nbytes];
 +  Send_buf[0] = 0x7e; //starting byte
 +  Send_buf[1] = nbytes - 2; //the number of bytes of the command without starting byte and ending byte
 +  Send_buf[2] = CMD_PLAY_COMBINE; 
 +  for(uint8_t i=0; i < number; i++)//
 +  {
 +    Send_buf[i*2+3] = song[i][0];
 +  Send_buf[i*2+4] = song[i][1];
 +  }
 +  Send_buf[nbytes - 1] = 0xef;
 +  sendBytes(nbytes);
 +}
 +
 +void sendCommand(int8_t command, int16_t dat = 0)
 +{
 +  delay(20);
 +  if((command == CMD_PLAY_W_VOL)||(command == CMD_SET_PLAY_MODE)||(command == CMD_PLAY_COMBINE))
 +    return;
 +  else if(command < 0x10) 
 +  {
 +  mp3Basic(command);
 +  }
 +  else if(command < 0x40)
 +  { 
 +  mp3_5bytes(command, dat);
 +  }
 +  else if(command < 0x50)
 +  { 
 +  mp3_6bytes(command, dat);
 +  }
 +  else return;
 +}
 +
 +void mp3Basic(int8_t command)
 +{
 +  Send_buf[0] = 0x7e; //starting byte
 +  Send_buf[1] = 0x02; //the number of bytes of the command without starting byte and ending byte
 +  Send_buf[2] = command; 
 +  Send_buf[3] = 0xef; //
 +  sendBytes(4);
 +}
 +void mp3_5bytes(int8_t command, uint8_t dat)
 +{
 +  Send_buf[0] = 0x7e; //starting byte
 +  Send_buf[1] = 0x03; //the number of bytes of the command without starting byte and ending byte
 +  Send_buf[2] = command; 
 +  Send_buf[3] = dat; //
 +  Send_buf[4] = 0xef; //
 +  sendBytes(5);
 +}
 +void mp3_6bytes(int8_t command, int16_t dat)
 +{
 +  Send_buf[0] = 0x7e; //starting byte
 +  Send_buf[1] = 0x04; //the number of bytes of the command without starting byte and ending byte
 +  Send_buf[2] = command; 
 +  Send_buf[3] = (int8_t)(dat >> 8);//datah
 +  Send_buf[4] = (int8_t)(dat); //datal
 +  Send_buf[5] = 0xef; //
 +  sendBytes(6);
 +}
 +void sendBytes(uint8_t nbytes)
 +{
 +  for(uint8_t i=0; i < nbytes; i++)//
 +  {
 +    myMP3.write(Send_buf[i]) ;
 +  }
 +}
 +
 +// fonction motor a retravailler en fonction du résultat voulu avec le moteur ....
 +void accel_motor() {
 +   for (int pwm=0; pwm <= 150; pwm++){ // 1ere acceleration vitesse moyenne
 +        analogWrite(motorpin,pwm);
 +        delay(10);
 +   }
 +   delay(2000);  // pause : reste 2 sec en vitesse moyenne 
 +   for (int pwm=150; pwm <= 255; pwm++){ // 2eme acceleration vitesse max
 +     analogWrite(motorpin,pwm);
 +     delay(5);
 +    }
 +   delay(3000);   // pause : reste 3 sec  vitesse max  
 +   digitalWrite(motorpin, LOW);   // vitesse zero 
 +   delay(300);  // eteint pendant 300 msec
 +}
 +</code>
 +
 +
 +  
 + 
 ===== Photos ===== ===== Photos =====
-Code pour afficher les images du projet : + 
-<code>{{gallery>?&crop&lightbox}}</code>+{{gallery>?&crop&lightbox}}
  
  
  
/home/resonancg/www/wiki/data/attic/projets/le_miracle_dans_le_magasin/accueil.1519047123.txt.gz · Dernière modification: 2018/02/19 14:32 de jerzon