RAK19007+RAK4631, USB serial output

Hello,

I’m at the blinky stage of working with the RAK modules :slight_smile: in PlatformIO.

I got the LED going and was looking to provide debug output over USB serial.
Looking at the documentation, it does seem to indicate that is possible.

I added the Serial init code from the GPS example in the blink sketch and after adding some libraries in (adafruit/Adafruit TinyUSB Library, adafruit/Adafruit BusIO, Wire) it compiles and uploads OK.

But the PC does not show a serial port at all. Only when I double press the reset button I get the COM port to show (and can push code to it).

Any hints welcome!

Bas

Welcome to the forum @basrijn

Can you share your code?
Your description of the problem points to a crash of your code before the USB is even initialized.

Hi Bernd,

The blue LED is happily blinking away (as expected, so I think it runs OK)

/*
 * Blink
 * Turns on an LED on for one second,
 * then off for one second, repeatedly.
 */

#include <Arduino.h>

// https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Quickstart/#hardware-setup
// Pin names WB_*
// LED_*

void setup()
{
  // initialize LED digital pin as an output.
  pinMode(LED_BLUE, OUTPUT);

  // Initialize Serial for debug output
  time_t timeout = millis();
  Serial.begin(115200);
  while (!Serial)
  {
    if ((millis() - timeout) < 5000)
    {
      delay(100);
    }
    else
    {
      break;
    }
  }
}

void loop()
{
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BLUE, HIGH);
  // wait for a second
  delay(1000);
  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BLUE, LOW);
   // wait for a second
  delay(1000);
  Serial.print(".");
}

Sorry, I also found these two topics covering similar problems:

  • Pretty old issue tied to the NRF platform
  • This more recent one, where people resolve the issue by doing an update via Arduino IDE. I haven’t tried that yet

Hi,

Some more progress :slight_smile: Installed and configured Arduino IDE following this.

  • Picked the RAK 4361 example Read_Battery_level

  • Needed to install the Adafruit TinyUSB library (in the battery level sketch that uses no Serial)

  • Compile then fails because TinyUSB relies on Wire. Noticed in a comment that it recommended to install the nRF52_OLED library

  • Sketch now compiles and uploads (after double click puts it in upload mode)

  • On reboot the normal comport shows up!

  • Copied my code linked above into the Arduino IDE (replacing the battery code) and upload

  • On reboot the comport is still there! My code plots the expect dot every second

  • Go back to PlatformIO, try to replace the Wire library with beegee-tokyo/nRF52_OLED

  • Compile fails with

Compiling .pio\build\wiscore_rak4631\FrameworkArduino\HardwarePWM.cpp.o
In file included from .pio\libdeps\wiscore_rak4631\Adafruit BusIO/Adafruit_BusIO_Register.h:9:0,
                 from .pio\libdeps\wiscore_rak4631\Adafruit BusIO\Adafruit_BusIO_Register.cpp:1:
.pio\libdeps\wiscore_rak4631\Adafruit BusIO/Adafruit_I2CDevice.h:5:10: fatal error: Wire.h: No such file or directory

No real understanding of what is happening. But I can reproduce it. Does it have to do with the included Wire library being different between PlatformIO and the Arduino IDE?

Bas

It looks like your PIO installation of the BSP failed. Try

  • uninstall the BSP
  • delete the .cache folder inside the .platformio folder
  • reinstall the BSP
  • apply the WisBlock patch (to get the RAK4631 into the Pio BSP)
  • retry

Hi,

Hmmm, I seemed to have upset PlatformIO in the process :frowning: My simple sketch now complains:

cannot open source file “variant.h” (dependency of “Arduino.h”)

This is after deleting the the BSP, deleting the cache and re-adding the BSP, rerunning the RAK_PATCH.

Google has not been helpful in finding a solution. Any idea where variant.h is supposed to come from?

Bas

You might have missed a step as shown here ==> Installation of Board Support Package in PlatformIO | RAKwireless Documentation Center

You need to compile any sketch first to get the full BSP installed in PIO. Only after that the patch is working.

Hi,

Sort off, some files/directories might have been locked. The python script completed OK, but the files were never copied. I manually copied it and things are compiling again.

However, nothing has changed. Sketch runs fine (blinky), but no COM port shows up.
Go back to Arduino IDE, upload same sketch. Com port is back

Bas

The resulting code from ArduinoIDE and PIO should work the same.
I am using PIO for 99% of my projects. Only convert to ArduinoIDE if absolute needed.

No idea why your PIO code is not working.

Hi,

This seems to be a platform thing. The issue exists with

#include <Arduino.h>

void setup()
{
}
void loop()
{
}

I have a COM port when compiled with Arduino. I don’t have a COM port when compiled in PlatformIO.

Checked that it’s not a local Windows detection issue by trying in two other systems. Same no COM port vs COM port result.

Bas

I had the same problem compiling a “new project” or Blink example.
For reference, i am using the Arduino IDE 2.2.1
Admittedly, i was very perplexed and frustrated not being able to compile either of these projects!
Strangely, all the sensor examples and 4631 LORAWAN examples compiled.

I decided to add the includes the the working 4631 LORAWAN examples.

#include <Arduino.h>
#include <LoRaWan-RAK4630.h>
#include <SPI.h>

And the template and BLINK projects successfully compile!

Turns out you only need to add;

#include <LoRaWan-RAK4630.h>

For the collection, this is another thread discussing the same issue. This person was able to resolve it by modifying the Makefile

Hi Bernd,

I’ve been getting some fantastic support on the PlatformIO forum.

A copy of some of the feedback from that thread:

Their installation procedure has a few weaknesses in my eyes, in particular it blindly patches (read: copies their variant folder for the RAK4631) the framework-arduinoadafruitnrf52 package. However when looking at GitHub - RAKWireless/RAK-nRF52-Arduino at v1.3.3, they base their Arduino core off of the Adafruit nRF52 1.3.0 core with some patches. The latest nordicnrf52 platform installs the Adafruit core in version 1.5.0. So right there you’re getting a mismatch in intended base core version. In addition to that , the patches they make in their 1.3.3 version are not only adding their own variant folder, but modifying a few core files as well, and adding new libraires (like for I2S). Their patch file does not add that at all. So you end up with a weird frankenstein monster that’s not quite their core version but also not the Adafruit one.

By manually including some of the libraries, he provided a build that does lead to the serial port showing up (for the same code).

It might be worth reading the full thread and maybe even opening a thread on how to improve the RAK board patch for PlatformIO

Bas

Hi,

Update, Maximilian from the PlatformIO forum has put together a PR to add support for the RAK4361 into PlatformIO.

Bas

I USE PlatformIO almost exclusively as well. Its an older somewhat hacked up install, not using the lastest integration.

I’ve seen the disappearing com port a number of times on Ubuntu as well. Usually im not changing any USB/serial code. Generally it resolves itself by uploading a new program via Arduiono IDE.

Sometimes it has taken multiple uploads to get it back. Sometimes I’ve needed to erase memory via Segger j-link and reinstall bootloader. A mystery.

Generally I’ve seen this right after uploading a new sketch, not after just doing a reset or power on.

There is/was a difference in the upload process between the two IDE’s but I have not fully investigated the differences. Perhaps something gets trashed in the bootloader/softdevice memory area, don’t know.

I’ve seen this with the Wisblock as well as the Seeed Xiao BLE (also nRF52840 based), both using the same runtime, different board support files of course.

sorry for the duplicate, but probably relevant

I have experienced the same issue and I have solved it according to this post on the platformio forum.

it boils down to add the following line to the .ini file

lib_archive = no

https://community.platformio.org/t/com-port-disappears-after-uploading-program-on-wisblock-rak4631-nordic-nrf52-core/28747/4