Accessing serial ports

Hello,

       I am using the web compiler to program GR-Peach.The Gr peach has around 5xSPI,8xUART The default UART is set to ser0.I tried to acess Serial 4 as below,

void setup()

{

Serial4.begin(9600);

Serial.begin(9600);

}

void loop(){

char a;

a=Serial4.read();

Serial.println(a);

delay(600);}

But only the default serial (Ser.0) works and the Serial 4 seems like it is not activated.Could anyone help me on accessing all Serial ports(8 UARTS)

  • I'm not sure the cause, but could you try below code? I think it's not neccessary delay(600)

    if(Serial4.available()){

    Serial.println(Serial4.read());

    }

  • In reply to Okamiya Yuuki:

    hello yuuki,

                     I have tried that and i still can't access Ser4,I am also having trouble in accessing the SPI's(5X SPI) how can i differentiate them in web compiler and access each one?

  • Hello rockey,

    I am also using extra serial port, so you may try serial code as below. I tested on my GRPeach Board working properly and do not forget to Serial4.begin(9600) in void setup.

    #include<Arduino.h>

    String inString = "";    // string to hold input
    void setup() {
     Serial.begin(9600);
     Serial4.begin(9600); //set baudrate(9600) accordingly
    }

    void loop() {
      // put your main code here, to run repeatedly:
    if(Serial4.available()){
        while(Serial4.available())
          {
            char inChar = (char)Serial4.read(); //read the input
            inString += inChar;        //make a string of the characters coming on mySerial
          }
          Serial.println(inString);
          inString = ""; 
      }
    }

  • In reply to Brijesh:

    High, I tried loop-back test as below.

    Connected jumper wire between Ser0 TX(pin 1) and Ser4 RX(pin 8).

    When I ran below code, a character input from keyboard was displayed in a serial monitor on PC.

    void setup()

    {

    Serial.begin(9600);

    Serial0.begin(9600);

    Serial4.begin(9600);

    }

    void loop()

    {

    if(Serial.available()){

    Serial0.write(Serial.read());

    }

    if(Serial4.available()){

    Serial.write(Serial4.read());

    }

    }

  • In reply to Okamiya Yuuki:

    hello yuuki,

                  Thank you very much for your information I have sorted out the problem now I am able to access the serial ports.I am also having trouble in accessing the SPI's(5X SPI) how can i differentiate them in web compiler and access each one?