Problems getting the MKR 1400 to work

Hi,

I have unsuccessfully been trying to interface a turbidity sensor to a MKR GSM 1400. The circuit, in my mind, is relatively simple with a voltage shifter constructed with a couple of resistances limiting the input from 5v to 3.5v. I have then written some code to read the information from the circuit and output text to a SMS message. However, the system seems to stall where a GSM connection is being sought. I'm assuming this is where the GSM connection is lost after line 63 ( Serial.println("Connection Routine"); // sends this to the monitor and then hangs here ) but feel it should be defaulting to the not connected message rather than hanging.

/*
Sending Turbidity data via SMS

This sketch, for the MKR GSM 1400 board,sends an SMS message
you enter in the serial monitor.

Circuit:

  • MKR GSM 1400 board
  • Antenna
  • SIM card that can send SMS

created 23 April 2019
by Nick Stephens
Adpated from script from Tom Igoe
*/

// Include the GSM library
#include <MKRGSM.h>
#include <stdio.h>
#include <stdlib.h>
#include <avr/dtostrf.h>

#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[] = SECRET_PINNUMBER; //pin number for the sim card being used
const char remoteNum[] = MOBILE_NUMBER; //import Mobile number for text to be sent to
const char emergency[] = EMERGENCY_NUMBER; //Emergency Number if NTU is elevated
const float ntuLimit = atof(NTU_LIMIT); //set NTU limit SMS alerts are sent

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;

const int sensorPin = A0;
const float zeroSet = 0.0; //capability to zero offset the sensor
const int delayInc = 60000 ; // output time delay increment in milliseconds
int timeStamp = delayInc ; // Set time counter
const int Diag = 1 ; //lED dignostics, 1 to switch on 0 for off
const int chaSMS = 200; //SMS character length

// intialise mgeTxt which will be sent to SMS
char mgeTxt[chaSMS]; //create SMS txt array
char outstr[15]; //temp str store for catonation

void setup() {

}

void loop() {
timeStamp = millis()/delayInc;
int aa = chaSMS; //txt message will be limited by how many characters can be sent
int sensorVal = analogRead(sensorPin);

Serial.begin(9600); // initialize serial communications and wait for port to open:

bool connected = false; // connection state

// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
Serial.println(PINNUMBER);
while (!connected) {
Serial.println("Connection Routine"); // sends this to the monitor and then hangs here
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
Serial.println("Connection established");
connected = true;
} else {
Serial.println("Not connected");
delay(1000);
}
}

Serial.println("GSM initialised");
// intialise diagnostic output pins
if (Diag > 0) {
for (int pinNumber = 2; pinNumber <5; pinNumber++){
pinMode(pinNumber, OUTPUT);
digitalWrite( pinNumber, LOW);
}
Serial.println("Diagnostic pins initialised");
}

Serial.print("Senor Data: ");

mgeTxt[0] = (char)0; //clear mgeTxt
outstr[0] = (char)0; //clear outstr
strcat(mgeTxt, "Time: ");
dtostrf(timeStamp,12, 0, outstr);
strcat(mgeTxt, outstr);
outstr[0] = (char)0; //clear outstr
strcat(mgeTxt, " Sens Val: ");
dtostrf(sensorVal,4, 0, outstr);
strcat(mgeTxt, outstr);
float voltage = (sensorVal/1024.0)*5.0 ; // convert the ADC reading to voltage
outstr[0] = (char)0; //clear outstr
strcat(mgeTxt, " Volts: ");
dtostrf(voltage,7, 3, outstr);
strcat(mgeTxt, outstr);
float turbidity = sensorVal ; //(voltage - .5) *100; //convert the voltage to turbidity in NTU
outstr[0] = (char)0; //clear outstr
strcat(mgeTxt, " NTU: ");
dtostrf(turbidity,7, 3, outstr);
strcat(mgeTxt, outstr);
//
Serial.println(mgeTxt); //print message to be sent

// LED diagnostic routine
if(Diag > 0) {
if(voltage < zeroSet) {
digitalWrite(2, LOW) ;
digitalWrite(3, LOW) ;
digitalWrite(4,LOW) ;

}else if (voltage >= zeroSet+0 &&
voltage < zeroSet+1) {
digitalWrite(2,HIGH) ;
digitalWrite(3,LOW) ;
digitalWrite(4,LOW) ;
}else if (voltage >= zeroSet+1 &&
voltage < zeroSet+2) {
digitalWrite(2,HIGH) ;
digitalWrite(3,HIGH) ;
digitalWrite(4,LOW) ;
}else if (voltage >= zeroSet+2) {
digitalWrite(2,HIGH) ;
digitalWrite(3,HIGH) ;
digitalWrite(4,HIGH) ;
}
}

Serial.print("Entering stored mobile number: ");
Serial.println(remoteNum); // Output Number being dialed

// sms text
sendSMS(mgeTxt);
if (turbidity > ntuLimit) {
emerSMS(mgeTxt); //Send text if NTU is elevated beyond a predetermined limit
}

gsmAccess.shutdown();
Serial.println("GSM terminated");

delay(delayInc); //delay for the period between SMS messages

}

/*

  • Send SMS
    */
    int sendSMS(char message[]){
    Serial.print("Now, enter SMS content: ");
    Serial.println("Message:");
    Serial.println(message);
    // send the message
    sms.beginSMS(remoteNum);
    sms.print(message);
    sms.endSMS();
    Serial.println("\nCOMPLETE!\n");
    }

/*

  • Send Emergency SMS
    */
    int emerSMS(char message[]){
    Serial.print("Now, enter SMS content: ");
    Serial.println("Emergency Message:");
    Serial.println(message);
    // send the message
    sms.beginSMS(emergency);
    sms.print("Elevated NTU ");
    sms.print(message);
    sms.endSMS();
    Serial.println("\nCOMPLETE!\n");
    }

/*
Read input serial
*/
int readSerial(char result[]) {
int i = 0;
while (1) {
while (Serial.available() > 0) {
char inChar = Serial.read();
if (inChar == '\n') {
result = '\0';

  • Serial.flush();*
  • return 0;*
  • }*
  • if (inChar != '\r') {*
    _ result = inChar;_
    * i++;*
    * }*
    * }*
    * }*
    }[/color]
    *I have moved things about, tried different circuits and various other options but am running out of ideas if I'm honest but thinking its something I've done stupidly, rather than any technical problem. The first question: is there a better way to handle to the GSM connection so that the program attempts but doesn't hang? *
    It's the intermittent nature with the program/circuit stalling thats really confusing. I am finding that disconnecting the Vin supply to the 1400 unit appears to increase the chance of the system starting (but its not an consistent observation and a number of times the CHRG led on the 1400 unit has come on when the unit has hung. I have a talencell 12000 may unit providing the external power (should be able to provide a 3A discharge current) and have tried a variety of differing supplies without improved success.
    Second question: is this sounding like a current supply problem?
    I am struggling to find information about the meaning of the CHRG led on the 1400.

NereisNick:
Second question: is this sounding like a current supply problem?

That was my first thought. There is an issue that can cause current supply issues even with a proper power supply. The issue and solution are described here:

So that might be worth a try.

NereisNick:
I am struggling to find information about the meaning of the CHRG led on the 1400.

It's the indicator for the battery charge IC on the board.

Thank you for the response. Shame I didn't ask earlier as this issue has been bugging the hell out of me. Has anybody outlined what they are using in terms of capacitors?

I have only just discovered C ratings and I am not sure I can get the desired response. Something I have found on the internet is indicating 0.25C for the 12000mAh talent cell powerbank I am trying to use, which from a comment made by pnndra on the previously link, is not going to be sufficient to work. Is it still possibly using a large capacitor and if so, anybody know where I can find more information about the calculations?

I really don't know much about this other than what's written on that issue thread. pnndra is the lead of Arduino's hardware development so they definitely know their stuff.

I'd say there's no such thing as too much capacitance in this usage. Of course, that's not a very satisfying answer for you, but I'd say just throw the biggest capacitor you have on there and see what happens. If that doesn't work, put a few in parallel to multiply the capacitance until you get something that works. After that, you could buy a single capacitor that meets the needs without being so messy as the bunch of caps wired together.

So a relatively large investment later...

The talent cell battery is part of the problem. A new LiPo 3.7V battery and a reconfiguration of the circuit has helped. The direct linkage of the battery to the GSM 1400 (using the standard 2-pole JST connector) and the utilisation of Vcc did not work. The current draw appears to be the problem as identified by panda in the thread in the earlier post.

I haven't tried the capacitor option but don't need to now as the prototype is working.

Thank you Pert.

You're welcome. I'm glad to hear it's working now. Enjoy!
Per