how to send value like 9999999 or greater to one arduino form another arduino?
store that value in a unsigned long variable (4 bytes) and send it or split it by using an union .Now send it byte by byte to the another arduino.
is there any command like union.NOW in arduino??
and how can i collect byte by byte in another arduino
You can "separate" the bytes that compose a long in various ways, for instance:
long l = 9999999;
byte b1 = l & 0xFF;
byte b2 = (l >> 8) & 0xFF;
byte b3 = (l >> 16) & 0xFF;
byte b4 = (l >> 24) & 0xFF;
Then transmit the bytes separately and recompose the initial value on the other side like:
long l = (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
You might need some casts in there, but I hope you get the idea.
and how can i collect byte by byte in another arduino
You might just send the number as ascii to the second arduino, capture the ascii characters on the second arduino, then convert them there into a number. The below simple servo test code demonstrates the basic process.
// zoomkat 7-30-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// Powering a servo from the arduino usually *DOES NOT WORK*.
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.attach(9);
}
void loop() {
while (Serial.available()) {
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(3);
}
}
if (readString.length() >0) {
Serial.println(readString);
int n = readString.toInt();
Serial.println(n);
myservo.writeMicroseconds(n);
//myservo.write(n);
readString="";
}
}
You might just send the number as ascii to the second arduino, capture the ascii characters on the second arduino, then convert them there into a number
IMO this is to much overhead to just Nilanj wants.Also the use of object String just for have the concatenation operation is very poor code.
I think SukkoPera solution is more reliable , easy and efficient.
thanks buddies