Skip to main content
Fixed defining pack array
Source Link

I am trying to communicate Pc - Arduino Uno.

My Arduino code is here: (It is working as below)

int ndx = 0;   
char pack[12];            
void setup() {
Serial.begin(9600);
while(!Serial){;}
}

  void loop() { 

   while(Serial.available() ){  
    char rb = Serial.read();
    pack[ndx] = rb;
    ndx++;
    Serial.write(rb);
    if(ndx == 12){ 
        ndx=0;
      }     
    }
    }

If I try in

Serial.write(rb);

Like that:

Serial.write(pack[ndx]);

Program is acting weird, I mean sending weird bytes. I do not know what is the reason. Can you help me, please? What is going on in code? My python code: https://github.com/mucahitkayadan/Python

I am trying to communicate Pc - Arduino Uno.

My Arduino code is here: (It is working as below)

int ndx = 0;                
void setup() {
Serial.begin(9600);
while(!Serial){;}
}

  void loop() { 

   while(Serial.available() ){  
    char rb = Serial.read();
    pack[ndx] = rb;
    ndx++;
    Serial.write(rb);
    if(ndx == 12){ 
        ndx=0;
      }     
    }
    }

If I try in

Serial.write(rb);

Like that:

Serial.write(pack[ndx]);

Program is acting weird, I mean sending weird bytes. I do not know what is the reason. Can you help me, please? What is going on in code? My python code: https://github.com/mucahitkayadan/Python

I am trying to communicate Pc - Arduino Uno.

My Arduino code is here: (It is working as below)

int ndx = 0;
char pack[12];            
void setup() {
Serial.begin(9600);
while(!Serial){;}
}

  void loop() { 

   while(Serial.available() ){  
    char rb = Serial.read();
    pack[ndx] = rb;
    ndx++;
    Serial.write(rb);
    if(ndx == 12){ 
        ndx=0;
      }     
    }
    }

If I try in

Serial.write(rb);

Like that:

Serial.write(pack[ndx]);

Program is acting weird, I mean sending weird bytes. I do not know what is the reason. Can you help me, please? What is going on in code? My python code: https://github.com/mucahitkayadan/Python

Source Link

Arduino Serial Writing Array Problem

I am trying to communicate Pc - Arduino Uno.

My Arduino code is here: (It is working as below)

int ndx = 0;                
void setup() {
Serial.begin(9600);
while(!Serial){;}
}

  void loop() { 

   while(Serial.available() ){  
    char rb = Serial.read();
    pack[ndx] = rb;
    ndx++;
    Serial.write(rb);
    if(ndx == 12){ 
        ndx=0;
      }     
    }
    }

If I try in

Serial.write(rb);

Like that:

Serial.write(pack[ndx]);

Program is acting weird, I mean sending weird bytes. I do not know what is the reason. Can you help me, please? What is going on in code? My python code: https://github.com/mucahitkayadan/Python