Using serial SCI1 or SCI9

I would like to have access to Serial SCI1 or SCI9 in software with the Serial library. My plan is to have Tasmota flashed on the ESP32 and communicate with the MCU by using firmata. Is it something doable? Can the devs allow us to use the other Serial port of the MCU with the Serial library?

Thanks

Not sure which pins you wish to use, but here is an example sketch I have that use pins 18 and 19 as a Serial port...

/* USB to Serial - Teensy becomes a USB to Serial converter
   http://dorkbotpdx.org/blog/paul/teensy_as_benito_at_57600_baud

   You must select Serial from the "Tools > USB Type" menu

   This example code is in the public domain.
*/

// set this to the hardware serial port you wish to use
#if defined(ARDUINO_UNOR4_WIFI)
UART _UART4_(18, 19);
#define SerialX Serial3
#else
UART _UART2_(18, 19);
#define SerialX Serial2
#endif


#define HWSERIAL SerialX

unsigned long baud = 115200;
const int reset_pin = 4;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  digitalWrite(reset_pin, HIGH);
  pinMode(reset_pin, OUTPUT);
  Serial.begin(baud);    // USB, communication to PC or Mac
  HWSERIAL.begin(baud);  // communication to hardware serial

}

long led_on_time = 0;
byte buffer[80];
unsigned char prev_dtr = 0;

void loop() {
  int rd, wr, n;

  // check if any data has arrived on the USB virtual serial port
  rd = Serial.available();
  if (rd > 0) {
    // check if the hardware serial port is ready to transmit
    wr = HWSERIAL.availableForWrite();
    if (wr > 0) {
      // compute how much data to move, the smallest
      // of rd, wr and the buffer size
      if (rd > wr) rd = wr;
      if (rd > 80) rd = 80;
      // read data from the USB port
      n = Serial.readBytes((char *)buffer, rd);
      // write it to the hardware serial port
      HWSERIAL.write(buffer, n);
      // turn on the LED to indicate activity
      digitalWrite(LED_BUILTIN, HIGH);
      led_on_time = millis();
    }
  }

  // check if any data has arrived on the hardware serial port
  rd = HWSERIAL.available();
  if (rd > 0) {
    // check if the USB virtual serial port is ready to transmit
    wr = Serial.availableForWrite();
    if (wr > 0) {
      // compute how much data to move, the smallest
      // of rd, wr and the buffer size
      if (rd > wr) rd = wr;
      if (rd > 80) rd = 80;
      // read data from the hardware serial port
      n = HWSERIAL.readBytes((char *)buffer, rd);
      // write it to the USB port
      Serial.write(buffer, n);
      // turn on the LED to indicate activity
      digitalWrite(LED_BUILTIN, HIGH);
      led_on_time = millis();
    }
  }

  // check if the USB virtual serial port has raised DTR
#ifndef ARDUINO_UNOR4_WIFI
  unsigned char dtr;
  dtr = Serial.dtr();
  if (dtr && !prev_dtr) {
    digitalWrite(reset_pin, LOW);
    delayMicroseconds(250);
    digitalWrite(reset_pin, HIGH);
  }
  prev_dtr = dtr;
#endif
  // if the LED has been left on without more activity, turn it off
  if (millis() - led_on_time > 3) {
    digitalWrite(LED_BUILTIN, LOW);
  }

#ifdef ARDUINO_UNOR4_WIFI
#else
  // check if the USB virtual serial wants a new baud rate
  if (Serial.baud() != baud) {
    baud = Serial.baud();
    if (baud == 57600) {
      // This ugly hack is necessary for talking
      // to the arduino bootloader, which actually
      // communicates at 58824 baud (+2.1% error).
      // Teensyduino will configure the UART for
      // the closest baud rate, which is 57143
      // baud (-0.8% error).  Serial communication
      // can tolerate about 2.5% error, so the
      // combined error is too large.  Simply
      // setting the baud rate to the same as
      // arduino's actual baud rate works.
      HWSERIAL.begin(58824);
    } else {
      HWSERIAL.begin(baud);
    }
  }
#endif
}

Warning: I tried to edit out a bunch of test stuff, I might have missed some.

Also this sketch probably won't work right on the currently released code, as Serial
methods like availableToWrite are not implemented and several other issues. I have a pending PR that hopefully fixed a lot of those issues.... But has not been pulled in yet.

But hopefully this gives you some ideas on how to use the other pins.

Pins would be P109/P110 (34/35) on that schematic

I’m note sure how your code would work as it seems to be for the Atmel chip and not the Renesas.

The Renesas chip has 4 UART/SCI so it would be convenient to access them as Serial, Serial1, Serial2, Serial3 as outlined here

The code I included was extracted from sketch that runs on both WI-FI and MINIMA

However as I mentioned parts won’t work in current release as some of the member functions don’t work. Like availableForWrite always returns 0

Pins 34 and 35 are used for the Serial object to communicate with the ESP32 through a level shifter which implements the USB communication with the host

The 4 uarts
Serial as I mentioned
Serial1 Arduino pins 0 1
Serial2 talks to ESP32 for Wi-Fi and BLE

The 4th one on 18 and 19 which typically used for Wire object

sounds good. Also, I managed to flash a custom firmware on the ESP32-S3 module. So far it works. Now I would like to upload a sketch on the Renesas MCU. I tried the USB bridge mode : https://docs.arduino.cc/tutorials/uno-r4-wifi/cheat-sheet#usb-bridge

It does not seem to create a serial device so I can upload a sketch to the MCU. Any ideas?

Sorry no idea. My guess is for the IDE to work with these boards, when that bridge is set, might require a new variant defined in the boards.txt plus in the variant section of the install. That would maybe be a cross between the WIFI and the MINIMA. That is it would probably then need to define the USB information with the USB Descriptor and the like.

Wondering if the double click on the reset button will put it into some special mode?
That is in a similar state as the MINIMA, which probably has different uploader to handle it.

But no idea of details, like does the processor chip have the same Bootloader as the MINIMA? ...

Hopefully someone like @ptillisch can answer more on that.

Good luck
Kurt

I just found this :

The bootloaders are different as you figured out. I will try flashing the minima bootloader and let you know how that work.

Fred

1 Like

I made significant progress tonight but struggled a lot.

So to have the Uno R4 WiFi working after soldering the RA4M1 USB under the board, you need to have the minima boot loader flashed. After that, you need to short the boot pin with 5V so the board stay in USB serial instead of RA USB BOOT.

After that, I could not get LED_BUILTIN to blink. After a while, I discovered that the pin are messed up because I'm using minima on a wifi board. For example, the LED is on pin 5. I figured it out because the LED on the wifi schematic is on P102, and you have to get the pin from minima, here is the source

I also got the serial bridge between ESP and RA4M1 to work by defining UART UART2(11,12); and using Serial2

enough for tonight, next step, loading ConfigurableFirmata.

I think that there should be a 3rd mode in the Arduino Uno R4 Boards in the IDE that would be the Uno Wifi with RA4M1 USB mode.
Also, the Uno Wifi boot loader should check if incoming program is coming from the ESP or the USB pins so we would not have to change the boot loader for the minima