Teensy 3.2 and FONA SMS Project

Status
Not open for further replies.

ladycosmos

New member
Hey everyone! I am new to the forums on here but have been working with the Teensy, Arduino, and other electronics for two years now. I am currently working on a project that is designed to take GPS coordinates and send them to me via SMS. I have run into an issue with sample code, that seems to be getting stuck when I run it on the teensy and have not had any luck on finding a solution. I will post the code and will be open to any comments or suggestions anyone may have. This sample code comes from the FONA library and is the SMS response code in which you text the FONA and it sends an automatic response back. This works flawlessly with the Arduino, but when I make the changes to the code for it to work with the Teensy (using the hardware line instead of software), the FONA receives SMS from me, but does not send an automatic response. I am using Serial2 for the FONA as I am using Serial1 for the GPS (which the GPS portion is not included in the code below).

I greatly appreciate any help and insight!

Code...

#include "Adafruit_FONA.h"
#include <HardwareSerial.h>

#define FONA_RX 10
#define FONA_TX 9
#define FONA_RST 4

// this is a large buffer for replies
char replybuffer[255];

// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three lines
// and uncomment the HardwareSerial line
//#include <SoftwareSerial.h>
//SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
//SoftwareSerial *fonaSerial = &fonaSS;

// Hardware serial is also possible!
HardwareSerial *fonaSerial = &Serial2;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

void setup() {
while (!Serial);

Serial.begin(115200);
Serial.println(F("FONA SMS caller ID test"));
Serial.println(F("Initializing....(May take 3 seconds)"));

// make it slow so its easy to read!
fonaSerial->begin(4800);
if (! fona.begin(*fonaSerial)) {
Serial.println(F("Couldn't find FONA"));
while(1);
}
Serial.println(F("FONA is OK"));

// Print SIM card IMEI number.
char imei[16] = {0}; // MUST use a 16 character buffer for IMEI!
uint8_t imeiLen = fona.getIMEI(imei);
if (imeiLen > 0) {
Serial.print("SIM card IMEI: "); Serial.println(imei);
}

Serial.println("FONA Ready");
}


char fonaInBuffer[64]; //for notifications from the FONA

void loop() {

char* bufPtr = fonaInBuffer; //handy buffer pointer

if (fona.available()) //any data available from the FONA?
{
int slot = 0; //this will be the slot number of the SMS
int charCount = 0;
//Read the notification into fonaInBuffer
do {
*bufPtr = fona.read();
Serial.write(*bufPtr);
delay(1);
} while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaInBuffer)-1)));

//Add a terminal NULL to the notification string
*bufPtr = 0;

//Scan the notification string for an SMS received notification.
// If it's an SMS message, we'll get the slot number in 'slot'
if (1 == sscanf(fonaInBuffer, "+CMTI: \"SM\",%d", &slot)) {
Serial.print("slot: "); Serial.println(slot);

char callerIDbuffer[32]; //we'll store the SMS sender number in here

// Retrieve SMS sender address/phone number.
if (! fona.getSMSSender(slot, callerIDbuffer, 31)) {
Serial.println("Didn't find SMS message in slot!");
}
Serial.print(F("FROM: ")); Serial.println(callerIDbuffer);

//Send back an automatic response
Serial.println("Sending reponse...");
if (!fona.sendSMS(callerIDbuffer, "Hey, I got your text!")) {
Serial.println(F("Failed"));
} else {
Serial.println(F("Sent!"));
}

// delete the original msg after it is processed
// otherwise, we will fill up all the slots
// and then we won't be able to receive SMS anymore
if (fona.deleteSMS(slot)) {
Serial.println(F("OK!"));
} else {
Serial.println(F("Couldn't delete"));
}
}
}
}
 
Status
Not open for further replies.
Back
Top