Two Arduino Serial Communication -Missing or Slow

Hi trying to connect two Arduino's - Mega & Uno in serial communication. Pressing KEY"s Connected with UNO and UNO as serial code sender and Mega as receiver and transmitter to pc . testText() it's call function it's having display code line . without testText () call function serial communication working properly but with testText() PC receiving slowly . How to enable the Interrupt activation when there is serial data Arrived - Serial Interrupt and how to make sure receiver not missing any receiving codes from receiver ```
void loop(void) {

testText();
if (Serial2.available()) {

c = Serial2.read();

Serial.print(c);

}

}

Why don't you show the testText() code if you identified it as the trouble maker?

There is no Serial interrupt. Do you mean serialEvent()?

void testText(void){
  u8g.setFont(u8g_font_6x13);
  u8g.drawFrame(1,48,32,15);u8g.drawFrame(36,48,28,15);u8g.drawFrame(65,48,40,15);u8g.drawFrame(110,48,18,15);  
  u8g.drawFrame(1,1,65,12); 
  u8g.drawStr( 2, 60, "key1  key2  key3  key4 ");
  u8g.setPrintPos(10, 25);
  u8g.print(buffer2); 
  u8g.setPrintPos(112, 10); 
  u8g.print((char)176);  
  u8g.setFont(u8g_font_5x7);
  u8g.setPrintPos(16, 10);
  u8g.print(idcode);
  u8g.drawStr( 72, 10, "T=       C");
  u8g.drawStr(2,10, "Test:          "); 
  u8g.setPrintPos(86, 10);    
  temperatureValue= (0.045*sensorValue);  
  u8g.print(temperatureValue);
  
  
   
  }

Serial Event is kind of serial capture ?

the Uno Serial port is already being used by the PC.

you could try powering the Uno independently (USB charger) and monitoring the activity on the Mega connected to the PC


--------------------------------------------------------------------------------
----------  Mega

void
loop (void)
{
    if (Serial.available ()     // from PC
        Serial2.print (Serial.read());

    if (Serial2.available ()    // from UNO
        Serial.print (Serial2.read());
}

--------------------------------------------------------------------------------
----------  UNO

void
loop (void)
{
    if (Serial.available ()
        Serial.print (Serial.read());   // echo back
}

Split testText() into multiple functions that do simple things quickly so that incoming characters can be processed in between. In general you can print the empty form in one function, called in setup(), and in another function only update the temperatureValue field. Then call the update function whenever the temperature has changed.

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