bonjour à tous,

Pour un projet, Nous devons communiquer à la fois en I2C entre notre arduino (mega 2560) et carte de commande des moteurs, et en UART entre l'arduino et une Raspberry PI 4. Problème, nous recevons seulement une donnée sur trois sur la raspberry et rien sur le moniteur série. Nous avons remarqué qu'en enlevant le Motor.begin, nous recevons bien nos valeurs sur le moniteur série.
Il y a t il donc un problème de compatibilité entre la com I2C et UART?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
 
#include "Grove_I2C_Motor_Driver.h"
#include <Thread.h>
// default I2C address is 0x0f
#define I2C_ADDRESS 0x0f
 
char c;
 
Thread task1;
Thread task2;
 
 
 
void setup() {
 
    // Configurer le port en tant que maitre
 
 
 
  task1.onRun(task1Function);
  task1.setInterval(1000);
 
  task2.onRun(task2Function);
  task2.setInterval(500);
 
  Serial.begin(9600);
  Motor.begin(I2C_ADDRESS);
}
 
void gauche(){
     // Set speed of MOTOR1, Clockwise, speed: -100~100
    Motor.speed(MOTOR1, 20);
    // Set speed of MOTOR2, Anticlockwise
    Motor.speed(MOTOR2, -20);
 
}
 
void droite(){
      // Set speed of MOTOR1, Clockwise, speed: -100~100
    Motor.speed(MOTOR2, 20);
    // Set speed of MOTOR2, Anticlockwise
    Motor.speed(MOTOR1, -50);  
}
 
void fonce(){
      // Set speed of MOTOR1, Clockwise, speed: -100~100
    Motor.speed(MOTOR1, -50);
    // Set speed of MOTOR2, Anticlockwise
    Motor.speed(MOTOR2, -50);
 
  // Initialisation des bus I2C et UART
}
 
void arret(){
     // Stop MOTOR1 and MOTOR2
    Motor.stop(MOTOR1);
    Motor.stop(MOTOR2);
}
 
void loop(){
  task1.run();
  task2.run();  
 }
 
 void task1Function() {
  Serial.println("1");
  if (Serial.available()) {
  c = Serial.read();
  Serial.println(c);
   }
}
 
 void task2Function() {
   //Code pour la tâche 2
    Serial.println("2");
    if (c==2) {
      gauche();
    }
 
    if (c==3) {
      droite();
    }
 
    if (c==1) {
      fonce();
    }
 
    if (c==4) {
      arret();
    }
}