MKRWAN 1310 LoRA TTN

I am trying to get my MKRWAN 1310 to send ultrasonic sensor data to The Things Network, I can get this to work while the device is connected to my laptop and I compile the code. The moment I change to 12W USB charger, nothing is been sent. I have tried removing all Serial prints from the code, bu that did not help anything.

Can someone help me out here, my code is below:

//lisätään MKRWAN.h kirjasto
#include <MKRWAN.h>
#include "arduino_secrets.h"

//Määritellään ultraääni sensorin pinnit
#define trigPin 2
#define echoPin 3

//määritellään muuttujia
float kesto;
float etaisyys;

String lahetys;

unsigned long alkuAika = 0;
unsigned long katkoAika = 120000;
unsigned long aika;

//alustetaan LoRa modemi
LoRaModem modem;

String appEui = SECRET_APP_EUI;

String appKey = SECRET_APP_KEY;


//laitteiston alustusta
void setup() {
  delay(500);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

 while (!Serial);

//Tarkisteaan, että oikea verkko käytössä

  if (!modem.begin(EU868)) {


    while (1) {}

  }

  //liitytään loraverkkoon avaimilla
 int connected = modem.joinOTAA(appEui, appKey);

//tarkistetaan onnistuiko yhteys
  if (!connected) {


    while (1) {}

  }

 // modem.minPollInterval(60);

}
void loop() {
alkuAika = millis();


if (alkuAika - aika > katkoAika){

aika = alkuAika;

digitalWrite(trigPin, LOW);
delayMicroseconds(5);

//aktivoidaan sensori
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

//lukee echoPinnin, pulseIn palauttaa pulssin keston
kesto = pulseIn(echoPin, HIGH);
//lasketaan etäisyys
etaisyys = kesto*0.034/2;

 lahetys = String(etaisyys);

   int err;
//lähetetään dataa LoRa verkkoon
  modem.beginPacket();

 modem.print("Vedenpinnan korkeus: " + lahetys);

  err = modem.endPacket(true);



}

}

what voltage and current rating is the charger?

It's an Apple USB charger 12V

looks like a 2amp adapter which should be OK
ran a simple test using a MKRFOX 1200 (I don't have a MKRWAN 1310) with the blink program - when running blinks LED and outputs a * to the serial monitor

/*
  Blink

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

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
}

// the loop function runs over and over again forever
void loop() {
  Serial.print("*");
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second
}

connected it to a USB phone charger and it works fine blinking the LED
try it on the MKRWAN 1310 using your Apple USB power adapter
if it works it proves that the MKRWAN can run code without a laptop using just the Apple adapter

managed to solve this, while (!Serial); part was casuing the device to wait until Serial is available as it was powered externally, Serial never became available and code did not run.

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