n SCREENSHOT 3. These UART function calls are part of
the mikroC Pro for PIC32 compiler/IDE. To use them in our
application, all we need to do is select the UART library with a
click from our mouse.
We’re going to have to work here and write some
original code. The gsm_process function takes care
of working the AT command state machine and the
gsm_cmdSingle function handles hanging up the phone.
That leaves us holding the bag for sending the actual text
message:
//***********************************************
//* WRITE STRING
//***********************************************
void writeString(char *strBuf)
{
while(*strBuf)
{
UART2_Write(*strBuf++);
}
UART2_Write(0x0D);
}
//***********************************************
//* SEND SMS MESSAGE
//***********************************************
void sendSMSmsg(char* msg)
{
gsm_cmdSingle( “AT+CMGS=\”1234567890\””);
//dial it up
writeString(msg);
//send message text
UART2_Write(0x1A);
//CTL-Z
UART2_Write(0x0D);
//CR
rc = false;
//wait for OK
do{
if (UART2_Data_Ready() == 1)
{
UART2_Read_Text(uart2Buf, “OK”, 255);
rc = true;
}
}while(rc == false);
}
GSM Click Hardware Prep
Before we can compile, download, and execute our
Screenshot 3 lists the UART function calls we can
make using the built-in MikroElektronika mikroC UART
library. The writeString function is human-generated using
the UART2_Write library function. The 1234567890 is a
place keeper for the actual phone number you want the
GSM click to send the message to. The coolest function
call is the UART2_Read_Text. The 255 argument tells the
function to wait forever for an OK string. Naturally, you can
gear that down to whatever wait time is good for you.
SMS code, we must obtain a SIM card and sign up with a
cellular carrier. I actually signed up with two carriers: Ting
and T-Mobile. I got my Ting SIM card from Adafruit. It took
about 10 minutes to get the Ting card activated and it was
all done online. With Ting, you only pay for what you use.
No contracts and no fees. I ordered my T-Mobile SIM card
from Amazon.
I made the mistake of not ordering the starter kit,
which comes with an activation number. That meant I had
to call T-Mobile customer service to obtain one. That took
two calls over two days as the T-Mobile folks expect you to
have a telephone not an Io T gadget in hand. Plus, T-Mobile
74 May/June 2018