RX TX with 2 arduinos 8 bits

First, this is my code of master arduino:

byte buf [8];

int B_1 = 30;
int V_1 = digitalRead(B_1);
int B_2 = 31;
int V_2 = digitalRead(B_2);
int B_3 = 32;
int V_3 = digitalRead(B_3);
int B_4 = 33;
int V_4 = digitalRead(B_4);
int B_5 = 34;
int V_5 = digitalRead(B_5);
int B_6 = 35;
int V_6 = digitalRead(B_6);
int B_7 = 36;
int V_7 = digitalRead(B_7);
int B_8 = 37;
int V_8 = digitalRead(B_8);


void setup(){ 
  pinMode(30,INPUT);
  pinMode(31,INPUT);
  pinMode(32,INPUT);
  pinMode(33,INPUT);
  pinMode(34,INPUT);
  pinMode(35,INPUT);
  pinMode(35,INPUT);
  pinMode(37,INPUT);
  Serial.begin(9600);
}


void loop(){ 
        buf[0] = digitalRead(V_1);
        buf[1] = digitalRead(V_2);
        buf[2] = digitalRead(V_3);
        buf[3] = digitalRead(V_4);
        buf[4] = digitalRead(V_5);
        buf[5] = digitalRead(V_6);
        buf[6] = digitalRead(V_7);
        buf[7] = digitalRead(V_8);
        Serial.write(0xff);
        
  for(int i = 0; sizeof(buf); i++){
  Serial.write(buf[i]);
  delay(2);
  }        
}  

Then, this is the code of the slave arduino:

//int led = [8];
char buf [8];
int leds[] = {2,3,4,5,6,7,8,9};
void setup(){
//pinMode(3,OUTPUT);
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}

void loop(){

for(int i = 0; sizeof(buf); i++){
Serial.write(buf[i]);
delay(2);
}
}

unfortunately I do not have any functioning about my code but I do not why.

Failure to use current limiting resistors with the LEDs can easily destroy an Arduino.

This probably does not do what you intended:
for(int i = 0; sizeof(buf); i++)

Welcome. We would like to help you but we need more information which is explained on the guidelines for this Forum. Start by posting an annotated schematic with links to technical information on each of the hardware devices. Frizzy pictures are wiring diagrams and are basically useless for troubleshooting problems. I will spend my time helping others that did post a schematic and the necessary information, obviously they read the guidelines.

image

You are relying on the USB connectors for GND return, bad idea.

You need a dedicated GND connection between the two Arduinos.

Using the TXRX pair on UNOs to communicate to other UNOs is fraught with difficulties because those lines are also driven by the interface IC of the USB connection. It can be done, but only with forethought. Better to use software serial at 9600 Baud for the UNO-UNO connection, on two digital pins of your choice.
Also,
Yes, you need a ground connection between your UNOs.
Yes, your for loop is incorrect; rethink the "; sizeof(buf);" part.
Yes, your LEDs need series current limiting resistors, regardless of what countless examples, Youtubers, etc. have done or attest to. Just do it.
And, although not wrong, your dip switch inputs are needlessly complex. Read about "INPUT_PULLUP", and rewire.
Finally, although we tend to "hate on" breadboard sketches and the like around here, at least you've begun by attempting to communicate effectively. A schematic would be better, but for the present need your image is fine.

As I see in the diagram, your Arduinos are Uno.
What is the point to use pins like 30-37?

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.