bonjour,
je suis entrain de bidouiller un code pour controller des leds via un ecran tactile...
tout marche,
sauf que je n'ai pas assez de sorties pwm disponible sur ma carte mega, (l'ecran tactile me prend des sorties)
j'ai a ma disposition une carte uno....et je pense relier les 2, pour qu'elle communique entre elles (en fait j'ai juste besoin que la mega donne la bonne valeur de la led a la carte uno, ..relation maitre-esclave)
j'ai essayer plusieurs choses, et je bute...je n'arrive pas a les faire communiquer ensemble dans un premier temps
j'utilise la librairie SoftEasyTransfer, et NewSoftSerial sous arduino 23
le code de la carte master (mega)
#include <SoftEasyTransfer.h>
/* For Arduino 1.0 and newer, do this: */
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(2, 3);
/* For Arduino 22 and older, do this: */
#include <NewSoftSerial.h>
NewSoftSerial mySerial(2, 3);
//create object
SoftEasyTransfer ET;
struct SEND_DATA_STRUCTURE{
//put your variable definitions here for the data you want to send
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int blinks;
int pause;
};
//give a name to the group of data
SEND_DATA_STRUCTURE mydata;
void setup(){
mySerial.begin(9600);
//start the library, pass in the data details and the name of the serial port.
ET.begin(details(mydata), &mySerial);
pinMode(13, OUTPUT);
randomSeed(analogRead(0));
}
void loop(){
//this is how you access the variables. [name of the group].[variable name]
mydata.blinks = random(5);
mydata.pause = random(5);
//send the data
ET.sendData();
//Just for fun, we will blink it out too
for(int i = mydata.blinks; i>0; i--){
digitalWrite(13, HIGH);
delay(mydata.pause * 100);
digitalWrite(13, LOW);
delay(mydata.pause * 100);
}
delay(5000);
}
j'ai bien ma led qui s'allume aleatoirement..pas de probleme
le code de l'esclave (uno)
#include <SoftEasyTransfer.h>
/* For Arduino 1.0 and newer, do this: */
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(2, 3);
/* For Arduino 22 and older, do this: */
#include <NewSoftSerial.h>
NewSoftSerial mySerial(2, 3);
//create object
SoftEasyTransfer ET;
struct RECEIVE_DATA_STRUCTURE{
//put your variable definitions here for the data you want to receive
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int blinks;
int pause;
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE mydata;
void setup(){
mySerial.begin(9600);
//start the library, pass in the data details and the name of the serial port.
ET.begin(details(mydata), &mySerial);
pinMode(13, OUTPUT);
}
void loop(){
//check and see if a data packet has come in.
if(ET.receiveData()){
//this is how you access the variables. [name of the group].[variable name]
//since we have data, we will blink it out.
for(int i = mydata.blinks; i>0; i--){
digitalWrite(13, HIGH);
delay(mydata.pause * 100);
digitalWrite(13, LOW);
delay(mydata.pause * 100);
}
}
//you should make this delay shorter then your transmit delay or else messages could be lost
delay(250);
}
et la ..rien....
en premier probleme je pense a une erreur de cablage...
mega pin 3---> uno pin 2
pin 2---> pin 3
(j'ai aussi essayé l'inverse)
faut il utiliser une autre pin, 0,1 (rx,tx) ?
faut il utiliser un autre type de connections (j'ai une horloge sur le port sda et scl de l'arduino mega)?
merci