Skip to main content
Became Hot Network Question
Fixed code quoting and indenting inconsistency. Pulled title into question as a description of the problem with minor edits. Shorter, less complicated title.
Source Link
timemage
  • 5.4k
  • 1
  • 14
  • 25

trying to transfer Getting different numbers after sending an unsigned int between 2 arduino, but sending 61805 and first 8-9 times i am getting 61805 then after these numbers 61937 28013 61937between Arduinos via Serial

//sender's I am trying to transfer unsigned int values between 2 Arduinos. When sending 61805 for the first 8-9 times, I am getting 61805. But after then after these numbers: 61937 28013 61937.

Sender's code:

```unsigned int s = 0;
   void setup () 
   {   
   Serial.begin(9600) ;
   } 
   void loop() 
   {
    s = 61805;
    Serial.write(highByte(s)) ;
   Serial.write(lowByte(s));
   }
unsigned int s = 0;

void setup ()
{
  Serial.begin(9600) ;
}

void loop()
{
  s = 61805;
  Serial.write(highByte(s)) ;
  Serial.write(lowByte(s));
}

Receiver's code:





//receiver's code


unsigned int upperByte, lowerByte, r=0,p=0; 

void setup() 
{
  Serial.begin(9600);
}  

void loop () 
{
  if (Serial.available() > 1 )
  {
     upperByte = Serial.read();
     lowerByte = Serial.read();
  }
   
  r = (upperByte << 8) + lowerByte ;lowerByte;
     Serial.println(r);
 
}

trying to transfer unsigned int between 2 arduino, but sending 61805 and first 8-9 times i am getting 61805 then after these numbers 61937 28013 61937

//sender's code

```unsigned int s = 0;
   void setup () 
   {   
   Serial.begin(9600) ;
   } 
   void loop() 
   {
    s = 61805;
    Serial.write(highByte(s)) ;
   Serial.write(lowByte(s));
   }




//receiver's code


unsigned int upperByte, lowerByte, r=0,p=0;
void setup() 
{
  Serial.begin(9600);
} 
void loop () 
{
  if(Serial.available() > 1 )
  {
     upperByte = Serial.read();
     lowerByte = Serial.read();
  }
    r = (upperByte << 8) + lowerByte ;
     Serial.println(r);
 
}

Getting different numbers after sending an unsigned int 8-9 times between Arduinos via Serial

I am trying to transfer unsigned int values between 2 Arduinos. When sending 61805 for the first 8-9 times, I am getting 61805. But after then after these numbers: 61937 28013 61937.

Sender's code:

unsigned int s = 0;

void setup ()
{
  Serial.begin(9600) ;
}

void loop()
{
  s = 61805;
  Serial.write(highByte(s)) ;
  Serial.write(lowByte(s));
}

Receiver's code:

unsigned int upperByte, lowerByte, r=0,p=0; 

void setup() 
{
  Serial.begin(9600);
}  

void loop () 
{
  if (Serial.available() > 1)
  {
    upperByte = Serial.read();
    lowerByte = Serial.read();
  }
 
  r = (upperByte << 8) + lowerByte;
  Serial.println(r);
}
Source Link

trying to transfer unsigned int between 2 arduino, but sending 61805 and first 8-9 times i am getting 61805 then after these numbers 61937 28013 61937

//sender's code

```unsigned int s = 0;
   void setup () 
   {   
   Serial.begin(9600) ;
   } 
   void loop() 
   {
    s = 61805;
    Serial.write(highByte(s)) ;
   Serial.write(lowByte(s));
   }




//receiver's code


unsigned int upperByte, lowerByte, r=0,p=0;
void setup() 
{
  Serial.begin(9600);
} 
void loop () 
{
  if(Serial.available() > 1 )
  {
     upperByte = Serial.read();
     lowerByte = Serial.read();
  }
    r = (upperByte << 8) + lowerByte ;
     Serial.println(r);

}