Projet IMA3 P1, 2017/2018, TD1 : Différence entre versions

De Wiki de Projets IMA
(Partie informatique)
(Partie informatique)
Ligne 138 : Ligne 138 :
 
  #define DATAOUT 11 //MOSI
 
  #define DATAOUT 11 //MOSI
 
  #define DATAIN  12 //MISO  
 
  #define DATAIN  12 //MISO  
  #define SPICLOCK  13 //sck
+
  #define SPICLOCK  13 //sck
  #define SLAVESELECT 10 //ss
+
  #define SLAVESELECT 10 //ss
 
   
 
   
 
  #define NUM_ROWS 8
 
  #define NUM_ROWS 8
Ligne 145 : Ligne 145 :
 
  #define NUM_PIXELS 64
 
  #define NUM_PIXELS 64
  
 +
//A screen struct contains a character array of size 64. Each position in the array corresponds to the color of ann LED on the matrix.
 
  typedef struct{
 
  typedef struct{
 
  char pixel[NUM_PIXELS];
 
  char pixel[NUM_PIXELS];
 
  } screen;
 
  } screen;
+
  screen myscreen;
screen myscreen;
 
 
 
//A screen struct contains a character array of size 64. Each position in the array
 
//corresponds to the color of ann LED on the matrix.
 
 
 
 
 
 
 
  
 
  cRGBMatrix RGBMatrix; //Create an instance of the class for use in the library
 
  cRGBMatrix RGBMatrix; //Create an instance of the class for use in the library
  
  /*
+
  //Configures SPI and I/O for communication with an RGB Matrix.  
Configures SPI and I/O for communication with an RGB Matrix.
 
Note: Pinout should reflect the pin assignments in the cRGBMatrix.h file
 
*/
 
 
  void cRGBMatrix::begin(void)
 
  void cRGBMatrix::begin(void)
 
  {  //SPI Bus setup
 
  {  //SPI Bus setup
 
     SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0); //Enable SPI HW, Master Mode, divide clock by 16    //SPI Bus setup
 
     SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0); //Enable SPI HW, Master Mode, divide clock by 16    //SPI Bus setup
 
  //SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1); //Enable SPI HW, Master Mode, divide clock by 16    //SPI Bus setup
 
  //SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1); //Enable SPI HW, Master Mode, divide clock by 16    //SPI Bus setup
   
 
 
     //Set the pin modes for the RGB matrix
 
     //Set the pin modes for the RGB matrix
 
     pinMode(DATAOUT, OUTPUT);
 
     pinMode(DATAOUT, OUTPUT);
Ligne 173 : Ligne 163 :
 
     pinMode(SPICLOCK,OUTPUT);
 
     pinMode(SPICLOCK,OUTPUT);
 
     pinMode(SLAVESELECT,OUTPUT);
 
     pinMode(SLAVESELECT,OUTPUT);
+
    //Make sure the RGB matrix is deactivated
//Make sure the RGB matrix is deactivated
 
 
     digitalWrite(SLAVESELECT,HIGH);
 
     digitalWrite(SLAVESELECT,HIGH);
//Send the command mode character
+
    //Send the command mode character
    digitalWrite(SLAVESELECT, LOW);
+
    digitalWrite(SLAVESELECT, LOW);
    spiTransfer('%');
+
    spiTransfer('%');
    digitalWrite(SLAVESELECT, HIGH);
+
    digitalWrite(SLAVESELECT, HIGH);
    delay(100);
+
    delay(100);}
  
}
 
  
/*
+
//Sends/receives a single byte to the SPI port. Inputs: char value - The value to be sent to the SPI port. Returns: Value received from the SPI port
Sends/receives a single byte to the SPI port.
+
char cRGBMatrix::spiTransfer(char value)
Inputs: char value - The value to be sent to the SPI port
+
{ SPDR = value;                    // Start the transmission
Returns: Value received from the SPI port
 
*/
 
char cRGBMatrix::spiTransfer(char value)
 
{
 
    SPDR = value;                    // Start the transmission
 
 
     while (!(SPSR & (1<<SPIF)))    // Wait for the end of the transmission
 
     while (!(SPSR & (1<<SPIF)))    // Wait for the end of the transmission
     {
+
     {};
    };
 
 
     return SPDR;                    // return the received byte
 
     return SPDR;                    // return the received byte
 
}
 
}
  
/*
+
/*Sets the color of a pixel on a given matrix. Note: display won't be updated until display() function is called.
Sets the color of a pixel on a given matrix
 
Note: display won't be updated until display() function is called
 
 
Inputs: int screen - The specific matrix to have a pixel set
 
Inputs: int screen - The specific matrix to have a pixel set
int row - The row of the pixel to be set
+
int row - The row of the pixel to be set
int column - The column of the pixel to be set
+
int column - The column of the pixel to be set
char color - The color to be used for the pixel fill.
+
char color - The color to be used for the pixel fill.
 
Returns: 1 - Success
 
Returns: 1 - Success
0 - Failure (invalid screen, row or column)
+
0 - Failure (invalid screen, row or column)*/
*/
 
 
char cRGBMatrix::fillPixel(int row, int column, char color)
 
char cRGBMatrix::fillPixel(int row, int column, char color)
 
{
 
{
Ligne 218 : Ligne 197 :
  
  
/* Fills a screen in the screenBuffer
+
/* Fills a screen in the screenBuffer. Note: display won't be updated until the display() function is called.
Note: display won't be updated until the display() function is called.
 
 
Inputs: int screen - The screen to be filled
 
Inputs: int screen - The screen to be filled
char color - The color to be used for the fill.
+
char color - The color to be used for the fill.
 
Returns: 1 - Success
 
Returns: 1 - Success
0 - Failure (invalid board) */
+
0 - Failure (invalid board) */
 
char cRGBMatrix::fillScreen(char color)
 
char cRGBMatrix::fillScreen(char color)
 
{
 
{
Ligne 235 : Ligne 213 :
 
         }
 
         }
 
     }
 
     }
return 1;
+
return 1;
}
+
}
  
  
Ligne 248 : Ligne 226 :
 
  }
 
  }
  
/* Sends the frame of data determined by the screen parameter
+
/* Sends the frame of data determined by the screen parameter
Inputs: char * screen - The 64 byte buffer to send over SPI*/
+
    Inputs: char * screen - The 64 byte buffer to send over SPI*/
void cRGBMatrix::sendScreen(char * screen)
+
void cRGBMatrix::sendScreen(char * screen)
{
+
{
 
     for(int row=0; row<NUM_ROWS; row++)
 
     for(int row=0; row<NUM_ROWS; row++)
    {
 
 
         for(int column=0; column<NUM_COLUMNS; column++)
 
         for(int column=0; column<NUM_COLUMNS; column++)
        {
+
             spiTransfer(screen[(row*8)+column])
             spiTransfer(screen[(row*8)+column]);
+
}
        }
 
    }
 
}
 
  
  
Ligne 265 : Ligne 239 :
 
  void cRGBMatrix::clear(void)
 
  void cRGBMatrix::clear(void)
 
  { fillScreen(BLACK);
 
  { fillScreen(BLACK);
  display();
+
  display();}
  }
 
  
 
=== Bilan ===
 
=== Bilan ===

Version du 18 mai 2018 à 11:09

Projet IMA3-SC 2017-2018 : Puissance 4

Puissance 4

Description du Projet

Notre projet est un jeu de Puissance 4 à partir d'une matrice LED RGB de taille 8x8. Chaque colonne de la matrice est associée à un bouton poussoir. Les joueurs jouent à tour de rôle en appuyant sur les boutons pour placer leur pion. Sur une page Web, les joueurs peuvent configurer leur pseudonymes et leur couleur. La page internet permettra d'annoncer les scores et de rejouer plusieurs parties.

Cahier des charges

TO DO

Matériel nécessaire

Pour ce projet nous utiliserons:

  • Raspberry-Pi et son module WIFI "WI-PI"
  • Arduino UNO
  • Matrice LED RGB et son contrôleur
  • 8 boutons poussoirs
  • Un shield (PCB crée à partir du logiciel Fritzing)
  • Une page Web HTML pour pouvoir modifier les paramètres du jeu.

Séance 1

Cette première séance nous a permis de définir notre sujet et la liste du matériel nécessaire.

Partie informatique

Raspberry

Nous avons commencé la configuration du Raspberry afin qu'il réponde à nos besoins : connesion série avec l'Arduino, création d'un serveur Websocket... Pour cela, nous avons utilisé ce tutoriel : [1].

Ainsi, nous avons configuré la connexion série, mis à jour la distribution, et configuré la connexion via ssh qui est fonctionnelle.






Partie électronique

Découverte du logiciel Fritzing et début de création d'un shield (PCB) pour connecter la matrice LED RGB et l'Arduino.

Schéma du shield

Le shield se placera entre la matrice LED RGB et l'arduino. Il permettra tout d'abord de relier les 8 boutons aux pins 2 à 9 de l'Arduino.

Lors de la réalisation du shield nous avons fait attention à ne pas avoir de connexions qui se croisent ainsi que des angles droit. Nous avons réalisé un plan de masse et nous avons essayé de réduire au maximum la taille du shield. Néanmoins il nécessite une taille conséquente afin de pouvoir souder les boutons en face de chaque colonne de la matrice LED RGB.







Séance 2

Partie informatique

Nous avons terminé la configuration de la Raspberry. Nous avons ainsi configuré le point d'accès, les IP des clients WiFi, le nom du réseau et le serveur Web. La Raspberry est donc fonctionnelle pour notre projet.

Partie électronique

Finalisation du shield sur Fritzing, gravure de la carte et soudure.

Shield Puissance4.gif









Séance 3

Partie électronique

Nous avons terminé la partie électronique. Nous avons réalisé les dernières soudures entre la Matrice et le shield.

Partie informatique

La partie électronique terminée, nous avons cherché à faire fonctionner la matrice LED. Il nous a été difficile de comprendre le fonctionnement de la matrice et de son contrôleur.

Nous avons donc cherché sur internet des librairies Arduino faisant fonctionner ce type de matrice. Après plusieurs essais infructueux avec différentes librairies, nous avons réaliser à faire fonctionner notre matrice grâce à la librairie de ce tuto : [2]. Dans cette librairie, nous avons du remplacer

#include "WProgram.h"

par

#include "Arduino.h"

Cette librairie étant réalisée dans l'objectif de faire fonctionner plusieurs matrices connectées entre elles à la suite, nous l'avons modifié afin qu'elle soit plus adaptée à nos besoins. Ainsi, cette librairie contient les fonctions de base que nous utiliserons dans notre programme : allumer un pixel de la coueleur de notre choix, allumer/éteindre tous les pixels de la matrice, allumer une ligne/une colonne de la matrice...

Séance supplémentaire 1

Partie informatique

Nous avons commencé notre programme Arduino. Afin de faire fonctionner notre matrice LED, nous avons cherché sur internet une bibliothèque Arduino contenant des fonctions qui seraient utiles pour notre projet. Après de multiples recherches peu fructueuses, nous avons trouvé la bibliothèque "RGBMatrix" sur ce site [3]. Cependant, cette bibliothèque était créée pour faire fonctionner plusieurs Matrices LED les unes à coté des autres. Nous l'avons donc modifié et simplifiée afin de pouvoir l'utiliser dans notre projet.

Voici une aperçu du contenu de notre bibliothèque "myRGBMatrix"

//Define the "Normal" 8 bit colors
#define BLACK		0
#define RED		0xE0
#define GREEN		0x1C
#define BLUE		0x03
#define ORANGE		RED|GREEN
#define MAGENTA	RED|BLUE
#define TEAL		BLUE|GREEN
#define WHITE		(RED|GREEN|BLUE)-0x60
#include <avr/pgmspace.h>
#include <ctype.h>
#include "myRGBMatrix.h"
#include "Arduino.h"
#include "myRGB.h"
//Define the SPI Pin Numbers
#define DATAOUT 11		//MOSI
#define DATAIN  12		//MISO 
#define SPICLOCK  13		//sck
#define SLAVESELECT 10		//ss

#define NUM_ROWS	8
#define NUM_COLUMNS	8
#define NUM_PIXELS	64
//A screen struct contains a character array of size 64. Each position in the array corresponds to the color of ann LED on the matrix.
typedef struct{
	char pixel[NUM_PIXELS];
} screen;
 screen myscreen;
cRGBMatrix RGBMatrix;	//Create an instance of the class for use in the library
//Configures SPI and I/O for communication with an RGB Matrix. 
void cRGBMatrix::begin(void)
{  //SPI Bus setup
    SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0);	//Enable SPI HW, Master Mode, divide clock by 16    //SPI Bus setup
	//SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1);	//Enable SPI HW, Master Mode, divide clock by 16    //SPI Bus setup
    //Set the pin modes for the RGB matrix
    pinMode(DATAOUT, OUTPUT);
    pinMode(DATAIN, INPUT);
    pinMode(SPICLOCK,OUTPUT);
    pinMode(SLAVESELECT,OUTPUT);	
    //Make sure the RGB matrix is deactivated
    digitalWrite(SLAVESELECT,HIGH); 		
    //Send the command mode character
    digitalWrite(SLAVESELECT, LOW);
    spiTransfer('%');
    digitalWrite(SLAVESELECT, HIGH);
    delay(100);}


//Sends/receives a single byte to the SPI port. Inputs: char value - The value to be sent to the SPI port. Returns: Value received from the SPI port
char cRGBMatrix::spiTransfer(char value)
{  SPDR = value;                    // Start the transmission
   while (!(SPSR & (1<<SPIF)))     // Wait for the end of the transmission
   {};
   return SPDR;                    // return the received byte

}

/*Sets the color of a pixel on a given matrix.	Note: display won't be updated until display() function is called.

Inputs: int screen - The specific matrix to have a pixel set int row - The row of the pixel to be set int column - The column of the pixel to be set char color - The color to be used for the pixel fill. Returns: 1 - Success 0 - Failure (invalid screen, row or column)*/ char cRGBMatrix::fillPixel(int row, int column, char color) { if((column < 0) || column > NUM_COLUMNS)return 0; if((row < 0) || row > NUM_ROWS)return 0; if(color == 0x25 || color == 0x26)return 0;

myscreen.pixel[row*8+column]=color; }


/* Fills a screen in the screenBuffer. Note: display won't be updated until the display() function is called. Inputs: int screen - The screen to be filled char color - The color to be used for the fill. Returns: 1 - Success 0 - Failure (invalid board) */ char cRGBMatrix::fillScreen(char color) { if(color == 0x25 || color == 0x26)return 0;

   for(int row=0; row<NUM_ROWS; row++)
   {
       for(int column=0; column<NUM_COLUMNS; column++)
       {
           myscreen.pixel[row*NUM_ROWS+column]=color;
       }
   }
	return 1;
}


//Sends the data in screenBuffer to the matrices.
void cRGBMatrix::display(void)
{
	digitalWrite(SLAVESELECT, LOW);	//Select the LED matrices
	spiTransfer(0x26);				//SEnd the Start of frame character
	sendScreen(myscreen.pixel);	//Send frame data over SPI.
	digitalWrite(SLAVESELECT, HIGH);	//Unselect the LED matrices
}
/* Sends the frame of data determined by the screen parameter
   Inputs: char * screen - The 64 byte buffer to send over SPI*/
void cRGBMatrix::sendScreen(char * screen)
{
   for(int row=0; row<NUM_ROWS; row++)
       for(int column=0; column<NUM_COLUMNS; column++)
           spiTransfer(screen[(row*8)+column])
}


//Clears the entire frame by filling all the screens with Black
void cRGBMatrix::clear(void)
{ 	fillScreen(BLACK);
	display();}

Bilan