How can i Send Variables Value thru i2c Protocoll between 2 Arduinos.

Hello Friends! :smiley:

So iam having a problem with I2C Communication between 2 Arduino basically iam trying to Write a 12 variables like this in Slave mode - Wire.Write(Varchar1,Varchar2,Varchar3) how can i concatenate the values? and send to Master?

this is my code

//Master


#include <Wire.h>
char c;
String teste;
void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  Wire.requestFrom(2,2);    // request 6 bytes from slave device #2

  while(Wire.available())    // slave may send less than requested
  {
    c = Wire.read(); // receive a byte as character
    teste += c;
  }
  
  Serial.println(teste); 
  teste = "";
  delay(10);
  
}
// Code for Slave Sender - Program for Arduino 2
// Wire Slave Sender
// by Nicholas Zambetti

// Demonstrates use of the Wire library
// Sends data as an I2C/TWI slave device
// Refer to the "Wire Master Reader" example for use with this

// Created 29 March 2006

// This example code is in the public domain.

#include <CapSense.h>
#include <Wire.h>

CapSense   cs_2_3 = CapSense(2,3);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapSense   cs_2_4 = CapSense(2,4);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapSense   cs_2_5 = CapSense(2,5);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapSense   cs_2_6 = CapSense(2,6); 
CapSense   cs_2_7 = CapSense(2,7); 
CapSense   cs_2_8 = CapSense(2,8); 
CapSense   cs_2_9 = CapSense(2,9);
CapSense   cs_2_10 = CapSense(2,10); 
CapSense   cs_2_11 = CapSense(2,11);
CapSense   cs_2_12 = CapSense(2,12);
CapSense   cs_2_13 = CapSense(2,13); 


char p3tr='0';
char p4tr='0';
char p5tr='0';
char p6tr='0';
char p7tr='0';
char p8tr='0';
char p9tr='0';
char p10tr='0';
char p11tr='0';
char p12tr='0';
char p13tr='0';

void setup()
{
  cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_4.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_5.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_6.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_7.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_8.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_9.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_10.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_11.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_12.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_13.set_CS_AutocaL_Millis(0xFFFFFFFF);
  
  cs_2_3.set_CS_Timeout_Millis(1);
  cs_2_4.set_CS_Timeout_Millis(1);
  cs_2_5.set_CS_Timeout_Millis(1);
  cs_2_6.set_CS_Timeout_Millis(1);
  cs_2_7.set_CS_Timeout_Millis(1);
  cs_2_8.set_CS_Timeout_Millis(1);
  cs_2_9.set_CS_Timeout_Millis(1);
  cs_2_10.set_CS_Timeout_Millis(1);
  cs_2_11.set_CS_Timeout_Millis(1);
  cs_2_12.set_CS_Timeout_Millis(1);
  cs_2_13.set_CS_Timeout_Millis(1);
  Wire.begin(2);                // join i2c bus with address #2
  Wire.onRequest(requestEvent); // register event
}

void loop()
{
  long total3 =  cs_2_3.capSense(1000);
  long total4 =  cs_2_4.capSense(1000);
  long total5 =  cs_2_5.capSense(1000);
  long total6 =  cs_2_6.capSense(1000);
  long total7 =  cs_2_7.capSense(1000);
  long total8 =  cs_2_8.capSense(1000);
  long total9 =  cs_2_9.capSense(1000);
  long total10 =  cs_2_10.capSense(1000);
  long total11 =  cs_2_11.capSense(1000);
  long total12 =  cs_2_12.capSense(1000);
  long total13 =  cs_2_13.capSense(1000);
  
  if (total3>100){
    p3tr = '1';
  }
  else{
    p3tr = '0';
  }
  if(total4>100){
    p4tr = '1';
  }  
  else{
    p4tr = '0';
  }
  if(total5>100){
    p5tr = '1';
  }
  else{
    p5tr = '0';
  }
  if(total6>100){
    p6tr = '1';
  }
  else{
    p6tr = '0';
  }
  if(total7>100){
    p7tr = '1';
  }
  else{
    p7tr = '0';
  }
  if(total8>100){
    p8tr = '1';
  }
  else{
    p8tr ='0';
  }
  if(total9>100){
    p9tr = '1';
  }
  else{
    p9tr = '0';
  }
  if(total10>100){
     p10tr = '1';
  }
  else{
   p10tr = '0';
  }
  if(total11>100){
   p11tr = '1';
  }
  else{
    p11tr = '0';
  }
  if(total12>100){
    p12tr = '1';
  }
  else{
    p12tr = '0';
  }
  if(total13>100){
     p13tr = '1';
  }
  else{
    p13tr = '0';
  }
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{



  Wire.write(????????); //i dont no i try all most everything

        
}

The question is how to send ALL variables ‚Äúp3tr,p4tr‚Ķ‚ÄĚ value to the master??

  Wire.requestFrom(2,2);    // request 6 bytes from slave device #2

6 bytes? Or 2 bytes?


String teste;

Please note that, at present, the String library has bugs as discussed here and here.

In particular, the dynamic memory allocation used by the String class may fail and cause random crashes.

I recommend reworking your code to manage without String. Use C-style strings instead (strcpy, strcat, strcmp, etc.).


void requestEvent()
{
  Wire.write(????????); //i dont no i try all most everything
}

Make a struct. Put all the data into it (up to 32 bytes). Send the struct.

Tnx nick!! forget the rest of the code… my real problem is… How to concatenate Char variables Values?
Wire.write(p3tr+p4tr…); doenst work

test[] = {p3tr,p4tr};
for (int i =0; i<=1; i++){
Wire.write(test[i])

}

Doesnt work! only shows the last value

Pls help how can i do this?

Moderator edit: [code] … [/code] tags added. (Nick Gammon)

That's why I said to write a struct. Which you didn't do.

Inside a requestEvent you can only do a single write. If you do more, it writes the last one.

http://www.gammon.com.au/i2c

Yes, a struct is the way to go, but just quickly looking at your code below;
You used the quote wrapper instead of the code wrapper when you posted and so the code appears incorrect on the forum.
It was not until I copied your code and saw that in fact you do use the variable i in your write method as that was what I was going to mention, you don‚Äôt use ‚Äėi‚Äô.

So, to make it more clear for you, you did this

test = {p3tr,p4tr};
for (int i =0; i<=1; i++){
Wire.write(test)

}

Which of course will not do much writing as looking at this you should be writing test[i] not just test .

While you should have used code wrapper to produce this

test[] = {p3tr,p4tr};
for (int i =0; i<=1; i++){
Wire.write(test[i])

} 
Doesnt work! only shows the last value

Pls help how can i do this?

Can you spot the difference?

A trap for sure for people using the quote wrapper for code

rockwallaby…

Now its working! tnx to you Nick Gammon :D!
Master

// Written by Nick Gammon
// February 2012

#include <Wire.h>



const byte MY_ADDRESS = 25;
const byte SLAVE_ADDRESS = 42;
String capSensValues;
String analogSensValues;

int analogInPin[16]; //array para abrir as  4 portas analogicas


void setup() 
{
  Wire.begin (MY_ADDRESS);
  Wire.onReceive (receiveEvent);
  Serial.begin(9600);
    

}  // end of setup

void loop() 
{
  
   
      
    Wire.beginTransmission (SLAVE_ADDRESS);

    Wire.write ("A");

    Wire.endTransmission ();
      
   while (Wire.available () > 0)
    {
    byte b;
   

    b = Wire.read ();

    capSensValues += b; 

    } 
  

 //if ( Serial.available()) { // Se serial estiver disponivel faca
    
   // char recebido = Serial.read(); // le o que vem da porta serial e atribui em uma variavel do tipo char
   // if recebido = 
    for (int i=0; i<=15;i++){
      analogInPin[i] = i;
        int analog = analogRead(analogInPin[i])/4; //Atribui o valor do sensor 0,1,2 ou 3 e divide por 4 na variavel analog
      analogSensValues += analog;
      analogSensValues += ",";
  }
      analogSensValues += capSensValues;
  Serial.println(analogSensValues);
  analogSensValues = "";
  capSensValues = "";
  }
  
  
  
  




void receiveEvent (int howMany)
 {
 /* while (Wire.available () > 0)
    {
    byte b;
   

    b = Wire.read ();

    capSensValues += b; 

    } 
   
  //Serial.println(capSensValues);

    */
 
    // end of while available
} // end of receiveEvent

Slave

// Written by Nick Gammon
// February 2012

#include <Wire.h>
#include <CapSense.h>

const byte MY_ADDRESS = 42;
const byte OTHER_ADDRESS = 25;

CapSense   cs_2_3 = CapSense(2,3);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapSense   cs_2_4 = CapSense(2,4);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapSense   cs_2_5 = CapSense(2,5);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapSense   cs_2_6 = CapSense(2,6); 
CapSense   cs_2_7 = CapSense(2,7); 
CapSense   cs_2_8 = CapSense(2,8); 
CapSense   cs_2_9 = CapSense(2,9);
CapSense   cs_2_10 = CapSense(2,10); 
CapSense   cs_2_11 = CapSense(2,11);
CapSense   cs_2_12 = CapSense(2,12);
CapSense   cs_2_13 = CapSense(2,13); 


byte p3tr=0;
byte p4tr=0;
byte p5tr=0;
byte p6tr=0;
byte p7tr=0;
byte p8tr=0;
byte p9tr=0;
byte p10tr=0;
byte p11tr=0;
byte p12tr=0;
byte p13tr=0;


void setup () 
{
  cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_4.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_5.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_6.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_7.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_8.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_9.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_10.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_11.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_12.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_13.set_CS_AutocaL_Millis(0xFFFFFFFF);
  
  cs_2_3.set_CS_Timeout_Millis(2);
  cs_2_4.set_CS_Timeout_Millis(2);
  cs_2_5.set_CS_Timeout_Millis(2);
  cs_2_6.set_CS_Timeout_Millis(2);
  cs_2_7.set_CS_Timeout_Millis(2);
  cs_2_8.set_CS_Timeout_Millis(2);
  cs_2_9.set_CS_Timeout_Millis(2);
  cs_2_10.set_CS_Timeout_Millis(2);
  cs_2_11.set_CS_Timeout_Millis(2);
  cs_2_12.set_CS_Timeout_Millis(2);
  cs_2_13.set_CS_Timeout_Millis(2);
  
  Wire.begin (MY_ADDRESS);
  
  Wire.onReceive (receiveEvent);
  Serial.begin(9600);
}  // end of setup

void loop() 
{
  
  long total3 =  cs_2_3.capSense(1000);
  long total4 =  cs_2_4.capSense(1000);
  long total5 =  cs_2_5.capSense(1000);
  long total6 =  cs_2_6.capSense(1000);
  long total7 =  cs_2_7.capSense(1000);
  long total8 =  cs_2_8.capSense(1000);
  long total9 =  cs_2_9.capSense(1000);
  long total10 =  cs_2_10.capSense(1000);
  long total11 =  cs_2_11.capSense(1000);
  long total12 =  cs_2_12.capSense(1000);
  long total13 =  cs_2_13.capSense(1000);
if (total3>100){
    p3tr = 1;
  }
  else{
    p3tr = 0;
  }
  if(total4>100){
    p4tr = 1;
  }  
  else{
    p4tr = 0;
  }
  if(total5>100){
    p5tr = 1;
  }
  else{
    p5tr = 0;
  }
  if(total6>100){
    p6tr = 1;
  }
  else{
    p6tr = 0;
  }
  if(total7>100){
    p7tr = 1;
  }
  else{
    p7tr = 0;
  }
  if(total8>100){
    p8tr = 1;
  }
  else{
    p8tr =0;
  }
  if(total9>100){
    p9tr = 1;
  }
  else{
    p9tr = 0;
  }
  if(total10>100){
     p10tr = 1;
  }
  else{
    p10tr = 0;
  }
  if(total11>100){
     p11tr = 1;
  }
  else{
    p11tr = 0;
  }
  if(total12>100){
     p12tr = 1;
  }
  else{
    p12tr = 0;
  }
  if(total13>100){
     p13tr = 1;
  }
  else{
    p13tr = 0;
  }
while (Wire.available () > 0)
  {
    char c;
    c = Wire.read ();
      if (c=='A'){
           Wire.beginTransmission (OTHER_ADDRESS);
            byte a[11] = {p3tr,p4tr,p5tr,p6tr,p7tr,p8tr,p9tr,p10tr,p11tr,p12tr,p13tr};
            
             Wire.write(a,11);
           Wire.endTransmission ();
    Serial.println(c);  
    }
    

  }
/*  Wire.beginTransmission (OTHER_ADDRESS);
 byte a[11] = {p3tr,p4tr,p5tr,p6tr,p7tr,p8tr,p9tr,p10tr,p11tr,p12tr,p13tr};
 


  Wire.write(a,11);

 
  Wire.endTransmission ();
  */
  delay (1);
}  // end of loop

// called by interrupt service routine when incoming data arrives
void receiveEvent (int howMany)
 {
 /* while (Wire.available () > 0)
  {
    char c;
    c = Wire.read ();
      if (c=='A'){
           Wire.beginTransmission (OTHER_ADDRESS);
             byte a[11] = {p3tr,p4tr,p5tr,p6tr,p7tr,p8tr,p9tr,p10tr,p11tr,p12tr,p13tr};
             Wire.write(a,11);
           Wire.endTransmission ();
    Serial.println(c);  
    }
    

  }*/  // end of while available
}  // end of receiveEvent

I didnt finish yet but its working

// called by interrupt service routine when incoming data arrives
void receiveEvent (int howMany)
 {
 /* while (Wire.available () > 0)
  {
    char c;
    c = Wire.read ();
      if (c=='A'){
           Wire.beginTransmission (OTHER_ADDRESS);
             byte a[11] = {p3tr,p4tr,p5tr,p6tr,p7tr,p8tr,p9tr,p10tr,p11tr,p12tr,p13tr};
             Wire.write(a,11);
           Wire.endTransmission ();
    Serial.println(c);  
    }

Inside a receiveEvent you don't need beginTransmission and endTransmission. Just do the write.

And since it is an ISR don't do any serial prints. So more like:

// called by interrupt service routine when incoming data arrives
void receiveEvent (int howMany)
   {
    if (Wire.read () =='A')
      {
      byte a [11] = {p3tr, p4tr, p5tr, p6tr, p7tr, p8tr, p9tr, p10tr, p11tr, p12tr, p13tr};
      Wire.write (a, sizeof a);
      }
    }

The way you said didnt work so well it loose some bytes and sometimes get wrong values…
The way i did works great but if i change Baud Rate 9600 to 115200 it works lot faster, but sometimes miss some characters i dont no why!! if i set a delay(20) works correctly but i dont want a delay… how can i fix this?

Master

// Written by Nick Gammon
// February 2012

#include <Wire.h>



const byte MY_ADDRESS = 25;
const byte SLAVE_ADDRESS = 42;
String capSensValues;
String analogSensValues;
String teste;
String teste1;
int analogInPin[16]; //array para abrir as  4 portas analogicas


void setup() 
{
  Wire.begin (MY_ADDRESS);
  Wire.onReceive (receiveEvent);
  Serial2.begin(115200);
  Serial.begin(115200);  

}  // end of setup

void loop() 
{
  
   if ( Serial.available()) {
    char recebido = Serial.read();
    if (recebido == 'a'){
      
    Wire.beginTransmission (SLAVE_ADDRESS);

    Wire.write ("A");

    Wire.endTransmission ();
      
   while (Wire.available () > 0)
    {
    byte b;
   

    b = Wire.read ();

    capSensValues += b; 

    } 
  //Transformando String em Array de Char
    teste = capSensValues;
    char charBuf[11];
    teste.toCharArray(charBuf,12);
    for (int i=1; i<=11; i++)
     {
        teste1 += charBuf[i];
        if (i<10){
        teste1 += ",";
      }
  //Fim da Transformacao    
    
    }

    for (int i=0; i<=15;i++){
      analogInPin[i] = i;
        int analog = analogRead(analogInPin[i])/4; //Atribui o valor do sensor 0,1,2 ou 3 e divide por 4 na variavel analog
      analogSensValues += analog;
      analogSensValues += ",";
  }
      
      analogSensValues += teste1;
  Serial.println(analogSensValues);
 //Serial.println(teste1);
  analogSensValues = "";
  capSensValues = "";
  teste1="";
  delay(20); //I want without this!
  }
  
 }
   }


void receiveEvent (int howMany)
 {

    // end of while available
} // end of receiveEvent

Slave

// Written by Nick Gammon
// February 2012

#include <Wire.h>
#include <CapSense.h>

const byte MY_ADDRESS = 42;
const byte OTHER_ADDRESS = 25;

CapSense   cs_2_3 = CapSense(2,3);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapSense   cs_2_4 = CapSense(2,4);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapSense   cs_2_5 = CapSense(2,5);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapSense   cs_2_6 = CapSense(2,6); 
CapSense   cs_2_7 = CapSense(2,7); 
CapSense   cs_2_8 = CapSense(2,8); 
CapSense   cs_2_9 = CapSense(2,9);
CapSense   cs_2_10 = CapSense(2,10); 
CapSense   cs_2_11 = CapSense(2,11);
CapSense   cs_2_12 = CapSense(2,12);
CapSense   cs_2_13 = CapSense(2,13); 


byte p3tr=0;
byte p4tr=0;
byte p5tr=0;
byte p6tr=0;
byte p7tr=0;
byte p8tr=0;
byte p9tr=0;
byte p10tr=0;
byte p11tr=0;
byte p12tr=0;
byte p13tr=0;


void setup () 
{
  cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_4.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_5.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_6.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_7.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_8.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_9.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_10.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_11.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_12.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_2_13.set_CS_AutocaL_Millis(0xFFFFFFFF);
  
  cs_2_3.set_CS_Timeout_Millis(2);
  cs_2_4.set_CS_Timeout_Millis(2);
  cs_2_5.set_CS_Timeout_Millis(2);
  cs_2_6.set_CS_Timeout_Millis(2);
  cs_2_7.set_CS_Timeout_Millis(2);
  cs_2_8.set_CS_Timeout_Millis(2);
  cs_2_9.set_CS_Timeout_Millis(2);
  cs_2_10.set_CS_Timeout_Millis(2);
  cs_2_11.set_CS_Timeout_Millis(2);
  cs_2_12.set_CS_Timeout_Millis(2);
  cs_2_13.set_CS_Timeout_Millis(2);
  
  Wire.begin (MY_ADDRESS);
  
  Wire.onReceive (receiveEvent);
  Serial.begin(9600);
}  // end of setup

void loop() 
{
  
  long total3 =  cs_2_3.capSense(1000);
  long total4 =  cs_2_4.capSense(1000);
  long total5 =  cs_2_5.capSense(1000);
  long total6 =  cs_2_6.capSense(1000);
  long total7 =  cs_2_7.capSense(1000);
  long total8 =  cs_2_8.capSense(1000);
  long total9 =  cs_2_9.capSense(1000);
  long total10 =  cs_2_10.capSense(1000);
  long total11 =  cs_2_11.capSense(1000);
  long total12 =  cs_2_12.capSense(1000);
  long total13 =  cs_2_13.capSense(1000);
if (total3>100){
    p3tr = 1;
  }
  else{
    p3tr = 0;
  }
  if(total4>100){
    p4tr = 1;
  }  
  else{
    p4tr = 0;
  }
  if(total5>100){
    p5tr = 1;
  }
  else{
    p5tr = 0;
  }
  if(total6>100){
    p6tr = 1;
  }
  else{
    p6tr = 0;
  }
  if(total7>100){
    p7tr = 1;
  }
  else{
    p7tr = 0;
  }
  if(total8>100){
    p8tr = 1;
  }
  else{
    p8tr =0;
  }
  if(total9>100){
    p9tr = 1;
  }
  else{
    p9tr = 0;
  }
  if(total10>100){
     p10tr = 1;
  }
  else{
    p10tr = 0;
  }
  if(total11>100){
     p11tr = 1;
  }
  else{
    p11tr = 0;
  }
  if(total12>100){
     p12tr = 1;
  }
  else{
    p12tr = 0;
  }
  if(total13>100){
     p13tr = 1;
  }
  else{
    p13tr = 0;
  }
while (Wire.available () > 0)
  {
    char c;
    c = Wire.read ();
      if (c=='A'){
           Wire.beginTransmission (OTHER_ADDRESS);
            byte a[11] = {p3tr,p4tr,p5tr,p6tr,p7tr,p8tr,p9tr,p10tr,p11tr,p12tr,p13tr};
            
             Wire.write(a,11);
           Wire.endTransmission ();
    Serial.println(c);  
    }
    

  }

 
}  // end of loop

// called by interrupt service routine when incoming data arrives
void receiveEvent (int howMany)
 {

}  // end of receiveEvent

You need to read how to send/receive data as I posted here:

http://www.gammon.com.au/i2c

Both your master and slave are wrong.


MASTER

Your master was:

   Wire.beginTransmission (SLAVE_ADDRESS);
   Wire.write ("A");
   Wire.endTransmission ();
   while (Wire.available () > 0)
    {
    byte b;
    b = Wire.read ();
    }

You should send and then do a Wire.requestFrom, like this:

  Wire.beginTransmission (SLAVE_ADDRESS);
  Wire.send ("A");
  Wire.endTransmission ();
  
  int count = Wire.requestFrom (SLAVE_ADDRESS, 11);  
  byte value [11];
  if (count == 11)
    {
    for (int i = 0; i < 11; i++)
      value [i] = Wire.read ();
    }
  else
    {
    // slave did not respond with 11 values
    }

SLAVE

Your slave was:

while (Wire.available () > 0)
  {
    char c;
    c = Wire.read ();
      if (c=='A'){
           Wire.beginTransmission (OTHER_ADDRESS);
            byte a[11] = {p3tr,p4tr,p5tr,p6tr,p7tr,p8tr,p9tr,p10tr,p11tr,p12tr,p13tr};
            
             Wire.write(a,11);
           Wire.endTransmission ();
    Serial.println(c);  
    }
  }

You need a requestEvent and a receiveEvent, like this:

void setup() 
{
  Wire.begin (MY_ADDRESS);
  Wire.onReceive (receiveEvent);  // interrupt handler for incoming messages
  Wire.onRequest (requestEvent);  // interrupt handler for when data is wanted
}  // end of setup

The receiveEvent handler receives the command (‚ÄúA‚ÄĚ in your case). The requestEvent responds to it. You don‚Äôt do both in the one place.

eg.

void receiveEvent (int howMany)
 {
   command = Wire.read ();  // remember command for when we get request
} // end of receiveEvent


void requestEvent ()
{
  if (command == "A")
    {
    byte a[11] = {p3tr,p4tr,p5tr,p6tr,p7tr,p8tr,p9tr,p10tr,p11tr,p12tr,p13tr};
    Wire.write (a,11);  
    }
}  // end of requestEvent

I did those examples for a reason. You have totally changed them.