MKR1310 talks LoRA when connected to editor but not when powered by power supply via USB cable

My 1310 board will talk via the LoRA connection when it is connected via the USB to the IDE. However, when tryin to use it standalone - powered via teh USB connection but just from a charger, teh system does not appear to talk. I have commented out all use of the serial connection in the sketch and that has not seemed to make a difference. Is there something I am missing in using the 1310 outside of the IDE environment? The code started from the example LoRASendAndRecieve and was modified to send a message every 50 seconds without having to use the serial input to input the string to send and use only specific channels.

Code Below

#include <MKRWAN.h>
LoRaModem modem;

void setup() {
int status;
//Serial.begin(9600);
//while (!Serial);
delay(2000);

loraSetup();

// if(Serial) Serial.println("--------------------------------");
// if(Serial) Serial.println("- MKR WAN 1310 Channel Masking -");
// if(Serial) Serial.println("--------------------------------");

// Print default channels configuration
// if(Serial) Serial.print("- Default mask: ");
// if(Serial) Serial.println(modem.getChannelMask());

// Disable all channels
// if(Serial) Serial.println("- Disabling all channels...");
for (unsigned int i = 0; i < 72; i++) {
modem.disableChannel(i);
}

// Print current channels configuration
// if(Serial) Serial.print("- Current mask: ");
// if(Serial) Serial.println(modem.getChannelMask());

// Enable US915-928 channels
// LoRaWAN® Regional Parameters and TTN specification: channels 8 to 15 plus 65
modem.sendMask("ff000001f000ffff00020000");
// if(Serial) Serial.println(modem.getChannelMask());
modem.setADR(true);
// if(Serial) Serial.print("- Current mask: ");
// if(Serial) Serial.println(modem.getChannelMask());

// if(Serial) Serial.print("Your module version is: ");
// if(Serial) Serial.println(modem.version());
// if(Serial) Serial.print("Latest module version is: ");
// if(Serial) Serial.println(ARDUINO_FW_VERSION);

if (modem.version() != ARDUINO_FW_VERSION) {
// if(Serial) Serial.println("Please make sure that the latest modem firmware is installed.");
// if(Serial) Serial.println("To update the firmware upload the 'MKRWANFWUpdate_standalone.ino' sketch.");
}

// if(Serial) Serial.print("Your device EUI is: ");
// if(Serial) Serial.println(modem.deviceEUI());

// if(Serial) Serial.println("Connecting...");
int connected = modem.joinOTAA(SECRET_APP_EUI, SECRET_APP_KEY);

if (!connected) {
// if(Serial) Serial.println("Something went wrong; are you indoor? Move near a window and retry");

}

// delay(5000);

}

void loop() {
delay(50000);

String msg = String(millis(),DEC);

// if(Serial) Serial.println();
// if(Serial) Serial.print("Sending: " + msg + " - ");
for (unsigned int i = 0; i < msg.length(); i++) {
// if(Serial) Serial.print(msg[i] >> 4, HEX);
// if(Serial) Serial.print(msg[i] & 0xF, HEX);
// if(Serial) Serial.print(" ");
}
// if(Serial) Serial.println();

int err;
modem.beginPacket();
modem.print(msg);
err = modem.endPacket(true);
if (err > 0) {
// if(Serial) Serial.println("Message sent correctly!");
} else {
// if(Serial) Serial.println("Error sending message :(");
// if(Serial) Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength");
// if(Serial) Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)");
}
delay(1000);
if (!modem.available()) {
// if(Serial) Serial.println("No downlink message received at this time.");
return;
}
char rcv[64];
int i = 0;
while (modem.available()) {
rcv[i++] = (char)modem.read();
}
// if(Serial) Serial.print("Received: ");
for (unsigned int j = 0; j < i; j++) {
// if(Serial) Serial.print(rcv[j] >> 4, HEX);
// if(Serial) Serial.print(rcv[j] & 0xF, HEX);
// if(Serial) Serial.print(" ");
}
// if(Serial) Serial.println();
}

void loraSetup() {
// Initialize LoRa module with the US915-928 region parameters
if (!modem.begin(US915)) {
// if(Serial) Serial.println("- Failed to start LoRa module!");
while (1);
};

delay(5000);

// Set poll interval to 30 seconds
modem.minPollInterval(60);
}

Please provide a detailed explanation of what you mean by this statement. What exactly is "connected to the IDE"? Do you mean that you have the Arduino IDE's Serial Monitor open, or only that the board is plugged in to your computer?

If you use the commented code with the "connected via the USB to the IDE" working configuration, does it still work?

For it to operate as expected, all it needs to be is connected to the IDE, the serial monitor does not need to be open. When connected, it works with or without commenting out all of the serial related commands. With all the serial items commented out, I can tell it is working by monitoring the information being passed to the The Things Network.

Please provide a detailed explanation of what you mean by this statement. What exactly is "connected to the IDE"?

The USB cable is connected to my laptop and the Arduino IDE (I am using the on-line version) is open. When you plug in the 1310 to the USB cable, the IDE indicates it is connected to the Arduino MKR WAN 1310. No need to have the serial monitor open. Here is a screen shot of the IDE right after I plugged in the 1310 a few minutes ago. Information started showing up at The Things Network Console as expected.

What happens if you try it with the Arduino IDE closed?

Still works after
Case 1) Just closing editor - but leaving forum tab open
Case 2) Closing all open Arduino tabs and stopping Arduino agent that runs in background.
The 1310 was unplugged and re-plugged in for each of these cases after the described conditions were met, causing it to restart. Came right up on The Things Network as expected.
There is likely still a driver installed for the Arduino device because it does not indicate an unknown device being plugged into the USB port.

I'm sure it's related to the power supply. Something like the computer providing more current or cleaner power than the charger does. Nothing to do with the software aspect of being connected to the computer.

Thank You for all the help! It does appear to be related to that because if I use a Power Bank battery instead of the power supply (charger) the system appears to work. It must be related to noise on the power, because the power supplies (I tried multiple versions) do indicate they are 5 volt outputs. I added some use of the LED to make sure I could tell if the code was running without having to have all the LORA communication visible up to The Things Stack since I have found that sometimes things on that end have issues as well.

You're welcome. I'm glad to hear you were able to eliminate the PC software aspect from consideration as a potential factor in the problem.

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

Hi! I open this topic in order to solve the problem of this post. The problem that appears here is that the arduino board is not working(transmiting) if not connected to the laptop. That is partially true. The mkr1310 in this case is not sending untill it is connected to the Serial Monitor. This: while(!Serial) is keeping the controller stuck. Remove it and you should be fine.

Note: If you follow the examples if the LoRa.h library and connect one of the boards to a power supply, than the system will not work.

Hope this was helpfull!

PS: I am new here and if there is a way to open closed topics, then please respond here and I will attach this post to the mentioned one above.

1 Like

Hi @andynopol. I have merged your follow-up post to the referenced topic and reopened it for replies, to be closed only after another 6 months have passed without activity.

Hi @andynopol

That is valuable advice in general. This is frequently the cause of reports of "works when connected to my computer, but not when connected to a battery".

However, it was not the cause this time. If you look carefully, you will see that @mjpipho312 had already commented that line in their sketch:

Hi! There is a lot of redundant code there not that I take a closer look. So yeah. Maybe the charger or the batery can not offer enough current for the radio to transmit. Another advice is to lower de TX power of the transciever and/or select a lower bandwidth channel.