Communication Sérial entre ATTiny85 et un Arduino Uno

De Sam's Projects.
Aller à : Navigation, rechercher

Sommaire

Description

Pour charger des programmes dans l'ATTiny85, suivez ce tuto.

UPDATE : Avec un cable de 27m cablé sur le Tx/Rx, le signal passe toujours. Mais lorsque je met le VCC et le Ground sur un long cable, ca marche plus. Problème de synchro je pense.

Composants

  • Arduino Uno
  • ATTiny85
  • LED

Téléchargements

Déroulement

  • Installer la librairie SoftEasyTransfert
  • Charger le programme SoftEasyTransfertRecepteur dans l'ATTiny85
  • Charger le programme SoftEasyTransfertEmetteur dans l'Arduino Uno
  • Brancher une LED sur le pin 3 de l'ATTiny85
  • Cabler le pin 10 de l'Arduino Uno au pin 0 de l'ATTiny85
  • Cabler le pin 11 de l'Arduino Uno au pin 1 de l'ATTiny85

La LED de l'ATTiny85 devrait clignoter sporadiquement.

Programme

SoftEasyTransfertEmetteur.ino.c

#include <SoftEasyTransfer.h>
 
/*   For Arduino 1.0 and newer, do this:   */
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 10);
 
/*   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(1000);
}

SoftEasyTransfertRecepteur.ino.c

#include <SoftEasyTransfer.h>
 
/*   For Arduino 1.0 and newer, do this:   */
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1);
 
/*   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(3, OUTPUT);
  digitalWrite(3,HIGH);
 
 
}
 
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(3, HIGH);
      delay(mydata.pause * 100);
      digitalWrite(3, LOW);
      delay(mydata.pause * 100);
    }
  }
  //you should make this delay shorter then your transmit delay or else messages could be lost
  delay(250);
}
Outils personnels
Espaces de noms

Variantes
Actions
Farfouillage
Liens divers
Boîte à outils