Can anyone help? I'm trying to develop two sketches, where data can only be sent when a request is made for it between two arduinos. A simple hello world message can suffice. I tried out the Serial Ascii Call and Response on the arduino IDE but it didn't work for me???. Do find below the code sketches
//Arduino Sketch 1
uint16_t alpha;
uint16_t lambo;
Banana nanas; //to hold the Banana object
uint16_t dataArray[2];
void Setup(){
Serial.begin(9600);
establishContact();
}
void loop(){
alpha=nanas.getRad;
lambo = nanas.getBars;
dataArray[0] = alpha;
dataArray[1] = lambo;
Serial.write((uint8_t*)dataArray, sizeof(dataArray));
Serial.flush(); //clear the serial port
}
void establishContact()
{
if (Serial.available())
{
while (Serial.available() > 0)
{
int newByte = Serial.read();
if (newByte == 'Q')
{
Serial.write(newByte);
Serial.flush();
}
}
}
}
The sketch for the other arduino is shown below
//Arduino sketch 2
static char buffer[2];
void setup(){
Serial.begin(9600);
Serial1.begin(9600);
establishContact();
}
void loop(){
if(Serial1.available())
{
while(Serial1.available() > 0){
uint16_t gondola1 = Serial1.read();
uint16_t gondola2 = Serial1.read();
uint16_t crixus = gondola2 >> 8;
crixus = (crixus | gondola1);
gondola1 = Serial1.read();
gondola2 = Serial1.read();
uint16_t mario = gondola2 >> 8;
mario = (mario | gondola1);
buffer[0] = crixus;
buffer[1] = mario;
Serial.write(buffer, sizeof(buffer);
Serial1.flush();
}
}
}
void establishContact(){
if (Serial.available()){
uint16_t newByte = Serial.read();
if(newByte == 'Q')
{
Serial.flush();
Serial.write(newByte);
}
}
}
redeclaration of uint16_t gondola1
error.Setup()
should besetup()
in the first sketch? What exactly isBanana
? Why complicate things, if all you want to do is send 'Hello world' on request? If that isnt your goal, then edit your post and say exactly what the sketches are for and exactly what you mean byit didn't work for me
.