Problème d'affichage du moniteur série

Bonjour, je suis en pleine réalisation d'un projet, mais j'ai un problème !
Mon projet est de fabriquer une manette de gaz pour un simulateur d'avion .
Je ne connais pas le langage arduino, je sais juste faire des jeux de lumière, mais pas plus .
J'ai trouvé sur un site internet un programme avec toutes les commandes que je veux, mais il manque les valeurs à attribuer pour le joystick.
Le joystick est brancher sur les pins: 6 (dapdUpOn), le pin 7 (dapdDownOn), le pin 8 (dapdLeftOn), et sur le pin 9 (dapdRightOn) .
Le gros problème, c'est qu'il n'y a rien d'afficher dans le moniteur série! Et moi, je dois prendre les relever du joystick pour qu'ils puissent fonctionner !

si une personne peut m'aider sur ce projet, ce serait vraiment cool

#include "UnoJoy.h"

void setup(){
  setupPins();
  setupUnoJoy();
}

void loop(){
  // Always be getting fresh data
  dataForController_t controllerData = getControllerData();
  setControllerData(controllerData);
}

void setupPins(void){
  // Set all the digital pins as inputs
  // with the pull-up enabled, except for the 
  // two serial line pins
  for (int i = 2; i <= 12; i++){
    pinMode(i, INPUT);
    digitalWrite(i, HIGH);
  }
  pinMode(A4, INPUT);
  digitalWrite(A4, HIGH);
  pinMode(A5, INPUT);
  digitalWrite(A5, HIGH);
}

dataForController_t getControllerData(void){
  
  // Set up a place for our controller data
  //  Use the getBlankDataForController() function, since
  //  just declaring a fresh dataForController_t tends
  //  to get you one filled with junk from other, random
  //  values that were in those memory locations before
  dataForController_t controllerData = getBlankDataForController();
  // Since our buttons are all held high and
  //  pulled low when pressed, we use the "!"
  //  operator to invert the readings from the pins
  controllerData.triangleOn = !digitalRead(2);
  controllerData.circleOn = !digitalRead(3);
  controllerData.squareOn = !digitalRead(4);
  controllerData.crossOn = !digitalRead(5);
  controllerData.dpadUpOn = !digitalRead(6);
  controllerData.dpadDownOn = !digitalRead(7);
  controllerData.dpadLeftOn = !digitalRead(8);
  controllerData.dpadRightOn = !digitalRead(9);
  controllerData.l1On = !digitalRead(10);
  controllerData.r1On = !digitalRead(11);
  controllerData.selectOn = !digitalRead(12);
  controllerData.startOn = !digitalRead(A4);
  controllerData.homeOn = !digitalRead(A5);
  
  // Set the analog sticks
  //  Since analogRead(pin) returns a 10 bit value,
  //  we need to perform a bit shift operation to
  //  lose the 2 least significant bits and get an
  //  8 bit number that we can use  
  controllerData.rightStickX = analogRead(A2) >> 2;
  // And return the data!
  return controllerData;
}

UnoJoyArduinoSample.ino (2.03 KB)

UnoJoy.h (9.62 KB)

met ton code entre balises.. tu auras plus de gens qui le liront
et Lit les regles du forum ici

voici ton code

#include "UnoJoy.h"

void setup(){
  setupPins();
  setupUnoJoy();
}

void loop(){
  // Always be getting fresh data
  dataForController_t controllerData = getControllerData();
  setControllerData(controllerData);

  Serial.begin(115200);
}

void setupPins(void){
  // Set all the digital pins as inputs
  // with the pull-up enabled, except for the 
  // two serial line pins
  for (int i = 2; i <= 12; i++){
    pinMode(i, INPUT);
    digitalWrite(i, HIGH);
  }
  pinMode(A4, INPUT);
  digitalWrite(A4, HIGH);
  pinMode(A5, INPUT);
  digitalWrite(A5, HIGH);
}

dataForController_t getControllerData(void){
  
  // Set up a place for our controller data
  //  Use the getBlankDataForController() function, since
  //  just declaring a fresh dataForController_t tends
  //  to get you one filled with junk from other, random
  //  values that were in those memory locations before
  dataForController_t controllerData = getBlankDataForController();
  // Since our buttons are all held high and
  //  pulled low when pressed, we use the "!"
  //  operator to invert the readings from the pins
 /* controllerData.triangleOn = !digitalRead(2);
  controllerData.circleOn = !digitalRead(3);
  controllerData.squareOn = !digitalRead(4);
  controllerData.crossOn = !digitalRead(5); */
  controllerData.dpadUpOn = !digitalRead(6);
  controllerData.dpadDownOn = !digitalRead(7);
  controllerData.dpadLeftOn = !digitalRead(8);
  controllerData.dpadRightOn = !digitalRead(9);
 /* controllerData.l1On = !digitalRead(10);
  controllerData.r1On = !digitalRead(11);
  controllerData.selectOn = !digitalRead(12);
  controllerData.startOn = !digitalRead(A4);
  controllerData.homeOn = !digitalRead(A5); */
  
  // Set the analog sticks
  //  Since analogRead(pin) returns a 10 bit value,
  //  we need to perform a bit shift operation to
  //  lose the 2 least significant bits and get an
  //  8 bit number that we can use  
  controllerData.rightStickX = analogRead(A2) >> 2;
  // And return the data!
  return controllerData;
}

as tu réglé le débit de ta console comme dans ton code? Serial.begin(115200) ?
de base elle est réglée à 9600 bauds

Que fait Serial.begin(115200) en fin de loop(), alors qu'il y a Serial.begin(38400) dans le .h ?

Bonjour,

Il est clairement indiqué dans UnoJoy.h que le fait d'utiliser la liaison série pose problème

*
*   NOTE: You cannot use pins 0 or 1 if you use this code - they are used by the serial communication.
*         Also, the setupUnoJoy() function starts the serial port at 38400, so if you're using
*         the serial port to debug and it's not working, this may be your problem.

kamill:
Bonjour,

Il est clairement indiqué dans UnoJoy.h que le fait d'utiliser la liaison série pose problème

*

*  NOTE: You cannot use pins 0 or 1 if you use this code - they are used by the serial communication.
*        Also, the setupUnoJoy() function starts the serial port at 38400, so if you're using
*        the serial port to debug and it's not working, this may be your problem.

je nuancerai plus la reponse de kamill :

il est indiqué clairement que setupUnoJoy initialise deja la connection serie a 38400 et que ca peut etre un probleme , justement lorsqu ' elle est redeclarée ailleurs sans regardér.

Du coup simplement enlver l' initialisation a 115200 dans votre code , et utiliser celle deja implanté dans le code de base a 38400 devrait resoudre le probleme :stuck_out_tongue: