Getting GPIO TxD and RxD to work on WIO

I'm connecting an Arduino MegaR3 and a WIO via bluetooth.
Each is equipped with a simple HC-05 bluetooth serial module.
(I know the WIO has builtin bluetooth, but I can't get that communicating in SPP mode and have given up on that)
On the MegaR3, the HC-05 is connected to Serial3 and the very first line in my code is Serial3.begin;
On the WIO, the HC-05 is connected to the 40-pin GPIO connector where it gets 5v power and GND.
Two pins on this 40-pin GPIO are predefined to be able to work as an additional serial port:
pin 8= BCM14 = WIO TxD - Connects to HC-05 Rx
pin10 = BCM15 = WIO RxD - Connects to HC-05 Tx
(I'm not using the Grove port since that one provides 3,3v and the HC-05 needs 5v power)
However, It seems that as a first line of code
Serial1.begin;
won't do the job like on the Mega. I see other people who use MKR Sercom initialize their Sercom first with code that looks a bit like this:

pinPeripheral(1, PIO_SERCOM); //one line for TxD and one for RxD
static Uart Serial3(&sercom3, PIN_WIRE_SCL, PIN_WIRE_SDA, SERCOM_RX_PAD_1, UART_TX_PAD_0);

However, I have not been able to find example code that works with the WIO and I have not been able to figure out what lines of code with what parameters I would be needing to make this GPIO serial port work on the WIO. Would anybody have any idea what lines of code I need or an idea where to look for it?

Update:
It seems that
Serial1.begin;
works fine. You just have to know one way or another that the 40-pin GPIO connector pins 8 and 10 relate to serial1.
A few remarks:
a) I have to state that I'm a bit disappointed by the steep learning curve that this WIO hardware brings with it.
b) Making reliable electrical contact with the 40-pin GPIO requires square pins that go full depth into the connector. I added a loopback wire between pins 8 and 10 to test, but that didn't work due to bad contact when it should have...

Below my working code to test out & debug serial communication from IDE Serial monitor to WIO GPIO Serial1 and support to read status of the HC-05 onboard LED on the WIO screen:

// Test serial & Display some characters & counters on the WIO screen
/*
 *  GPIO - Pin 2 = +5v / pin 6 = GND / pin 8 = Serial1 WIO Tx / pin 10 = Serial1 WIO Rx / Pin 18 WIO Digital/Analog in (Connected to HC-05 LED output) 
 *  Program passes serial data from SerialUSB to serial1 - writes serial data on the screen and also counters
 */

#define TFT_WHITE   0xFFFF
#define TFT_BLACK   0x0000
#define TFT_LGREY   0xC618

#include "TFT_eSPI.h"
TFT_eSPI tft;    //init library  //Compile error here if NOT Board=Seeeduino WIO selected

const int V=57; //Vertical Field size
const int H=158; //Horizontal Field size
const int L=4;  //line thickness

String ToDisplay = "";
unsigned int PCSentChar = 0;
unsigned int HC05SentChar = 0;

int D3Prev = 2; //Previous value of Digital3 input - 2 is undefined state

void setup() {
  pinMode(WIO_BUZZER, OUTPUT);
  pinMode(D3, INPUT_PULLUP);   //Green wire from HC-05 - equivalent to HC-05 onboard LED  //Using input pullup works better. 
  pinMode(A3, INPUT);          // Values 0-5 means LED off - Values 30-60 means LED on
  SerialUSB.begin(115200);
  
  Serial1.begin(38400);
  while (!Serial1);
  while (!SerialUSB);
  
  tft.begin();
  tft.setRotation(3); //0-3  USB kabel at the bottom
  digitalWrite(LCD_BACKLIGHT, HIGH);  //LOW or HIGH
  tft.fillScreen(TFT_LGREY);   //Reduce brighness a bit
  tft.drawString("WIO Starting", 40, 25 , 4); // Value for Field1
  analogWrite(WIO_BUZZER, 128);
  delay(100);
  analogWrite(WIO_BUZZER, 0);
  //Some very basic background - drawing once
  tft.fillScreen(TFT_WHITE);
  tft.fillRect(0, 118, 320, L, TFT_BLACK); //Horizontal middle line
  tft.drawCircle(280, 180, 18+2, TFT_BLACK);  //Circle around green LED (D3 in)
  tft.setTextColor(TFT_BLACK);
}
 
void loop() {
  if (SerialUSB.available() > 0) {
    char c = SerialUSB.read();
    Serial1.write(c);
    //tft.drawString("WIO Status", 1, 1 , 2); // Label for Field1
    ToDisplay = String(c);
    tft.drawString(ToDisplay, 1 + (PCSentChar%30)*10, 1 , 2); // PC to WIO to HC05

    //Overwrite previous Counter with white
    tft.setTextColor(TFT_WHITE);
    ToDisplay = String(PCSentChar);
    tft.drawString(ToDisplay, 1, V+L+1 , 2); // Prev character count sent from PC
        
    PCSentChar++;
    tft.setTextColor(TFT_BLACK);
    ToDisplay = String(PCSentChar);
    tft.drawString(ToDisplay, 1, V+L+1 , 2); // Character count sent from PC
  }
  if (Serial1.available() > 0) {
    char c = Serial1.read();
    SerialUSB.write(c);
    ToDisplay = String(c);
    tft.drawString(ToDisplay, 1 + (HC05SentChar%30)*10, V+L+V+L+1 , 2); // HC05 to WIO to PC

    //Overwrite previous with white
    tft.setTextColor(TFT_WHITE);
    ToDisplay = String(HC05SentChar);
    tft.drawString(ToDisplay, 1, V+L+V+L+V+L+1 , 2); // Prev character count sent from HC-05
    HC05SentChar++;
    tft.setTextColor(TFT_BLACK);
    ToDisplay = String(HC05SentChar);
    tft.drawString(ToDisplay, 1, V+L+V+L+V+L+1 , 2); // Character count rcv from HC-05
  }
  
  // Read D3 and draw up Green LED
  // if (digitalRead(D3) == HIGH) {Draw Green circle, ELSE White
  //tft.fillCircle(x,y,12,TFT_GREEN);  xy = center point
  int k = analogRead(A3);
  //SerialUSB.println (k);
  if (k > 15) {  //LED on
    if (D3Prev != 1) {
      tft.fillCircle(280,180,18,TFT_GREEN);
      D3Prev = 1;
    }
  } else { //D3 is LOW
    if (D3Prev != 0) {
      tft.fillCircle(280,180,18,TFT_WHITE);
      D3Prev = 0;
    }  
  }
  
}

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