Ciao a tutti, sto utilizzando la libreria easytransfer per permettere la comunicazione tra due arduino.
Ho collegato assieme gli arduino (come illustrato dallo schema della libreria TX RX) poi ho collegato ad ogni arduino un sensore US srf02 in i2c.
Ho implementato questo programma
#include <EasyTransfer.h>
#include <Wire.h>#define cmdByte 0x00 // Command byte
#define rangeByte 0x02 // Byte for start of ranging databyte highByte = 0x00; // Stores high byte from ranging
byte lowByte = 0x00; // Stored low byte from rangingint US_Read(char s[2])
{
int s_address, range = 0;s_address = US_Address(s);
Wire.beginTransmission(s_address);
Wire.send(cmdByte);
Wire.send(0x51);
Wire.endTransmission();delay(300);
Wire.beginTransmission(s_address);
Wire.send(rangeByte);
Wire.endTransmission();Wire.requestFrom(s_address, 2);
while(Wire.available() < 2);
highByte = Wire.receive();
lowByte = Wire.receive();range = highByte*256 + lowByte;
return(range);
}//Questa funzione contiene gli indirizzi dei vari sensori US SRF02
//Gli indirizzi possono essere richiamati dal numero o dalla lettere corrispondente al sensore
int US_Address(char s[2])
{
int s_newaddress;if(strcmp(s, "A")==0)
{s_newaddress = 0x70;}
else if(strcmp(s, "B")==0)
{s_newaddress = 0x71;}
else if(strcmp(s, "C")==0)
{s_newaddress = 0x72;}
else if(strcmp(s, "D")==0)
{s_newaddress = 0x73;}
else if(strcmp(s, "E")==0)
{s_newaddress = 0x74;}
else if(strcmp(s, "F")==0)
{s_newaddress = 0x75;}
else if(strcmp(s, "G")==0)
{s_newaddress = 0x76;}
else if(strcmp(s, "H")==0)
{s_newaddress = 0x77;}
else if(strcmp(s, "I")==0)
{s_newaddress = 0x78;}
else if(strcmp(s, "L")==0)
{s_newaddress = 0x79;}
else if(strcmp(s, "M")==0)
{s_newaddress = 0x80;}
else if(strcmp(s, "N")==0)
{s_newaddress = 0x81;}
else if(strcmp(s, "O")==0)
{s_newaddress = 0x82;}
else if(strcmp(s, "P")==0)
{s_newaddress = 0x83;}
else if(strcmp(s, "Q")==0)
{s_newaddress = 0x84;}
else if(strcmp(s, "R")==0)
{s_newaddress = 0x85;}return(s_newaddress);
}//create object
EasyTransfer 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 SB;
int SC;
};//give a name to the group of data
RECEIVE_DATA_STRUCTURE mydata;void setup(){
Wire.begin(9600);
Serial.begin(4800);
//start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
ET.begin(details(mydata), &Serial);//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.
Serial.println(mydata.SB);
Serial.println(mydata.SC);
}mydata.SB = US_Read("B");
ET.sendData();//you should make this delay shorter then your transmit delay or else messages could be lost
delay(250);
}
Inserendo in un PIC il codice mydata.SB = US_Read("B"); e nell'altro mydata.SC = US_Read("C");
Ho provato poi a collegare uno dei due pic al computer e ad aprire il serial monitor, in teoria questo doveva stamparmi i valori provenienti dal sensore collegato all'altro computer.
Ho avuto invece un output incomprensibile composto da puntini e simboli strani, sto sbagliando qualcosa?