Dec 30th, 2013: Editing original post to reflect progress.
Dec 31st, 2013: My problems seem to be SRAM related. See below (reply).
My thanks to Paul Stoffregen (funny, another Paul S) for helping me to debug earlier tonight at Dorkbot.
January 2nd, 2014: I reduced the memory footprint and successfully transmitted an SMS from the device alone.
My goal is to make an SMS messaging device that can operate without a computer. I'm using a SIM900 GPRS modem shield from Linksprite with a Nokia5110 display from Adafruit and a GKOS (6 button chorded) keyboard I soldered together on some perfboard. Links with details on all three hardware parts are below. These interface with an Uno compatible.
I have written ~50 line sketches that allows two of the three hardware components to work together with each sketch: keyboard outputs to LCD, keyboard outputs to GPRS modem, GPRS modem outputs to LCD. In each case I can use a serial monitor (my computer) to input/output to the SIM900/LCD as well.
My problem is I cannot interface all three devices to each other in a single sketch. When I do (specifically, when I initialize the pins for the LCD) my serial monitor outputs a bunch of 8888888888 characters and then a ton of newlines, and the LCD doesn't display any output. I'll post each of my three sketches, and then how I tried to combine them resulting in the issue. Links to the libraries should also be in my post below.
/* SIM900 outputs to LCD */
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <SoftwareSerial.h>
Adafruit_PCD8544 LCD(6,5,4,3,2);
extern uint8_t SmallFont[];
#define rxPin 7
#define txPin 8
SoftwareSerial SIM900(rxPin, txPin);
void setup()
{
LCD.begin();
LCD.setTextSize(1);
LCD.clearDisplay();
LCD.println("LCD link up!");
LCD.display();
SIM900.begin(19200); // SIM900 baud rate
Serial.begin(19200); // Serial port baud rate
// SIM900.println("AT+IPR=19200"); // Do not autobaud
Serial.println("Serial link up!");
}
void loop()
{
int i = 0;
char someChar[32] = {0};
if(Serial.available())
{
do{
someChar[i++] = Serial.read();
}while (Serial.available());
SIM900.print(someChar);
}
else if(SIM900.available())
{
do{
someChar[i++] = SIM900.read();
}while (Serial.available());
Serial.print(someChar);
LCD.print(someChar); // SIM900 to LCD
LCD.display();
}
}
/* GKOS keyboard outputs to SIM900 */
#include <SoftwareSerial.h>
#include <Gkos.h>
#define rxPin 7
#define txPin 8
SoftwareSerial SIM900(rxPin, txPin);
char* gEntry ="";
Gkos gkos(10,11,14,12,15,16);
void setup()
{
SIM900.begin(19200); // SIM900 baud rate
Serial.begin(19200); // Serial port baud rate
SIM900.println("AT+IPR=19200"); // do not autobaud
Serial.println("Serial link up!");
}
void loop()
{
gEntry = gkos.entry(); // non-blocking
if (gEntry != 0){gPrint();}
// Serial patch to SIM900
if (SIM900.available())
Serial.write(SIM900.read());
if (Serial.available())
SIM900.write(Serial.read());
}
void gPrint()
{
if (strcmp(gEntry, "_Enter") == 0){
//Serial.println("");
Serial.write( byte(10) ); Serial.write( byte(13) ); return;
}
if (strcmp(gEntry, "_BS") == 0){
Serial.write( byte(8) ); return;
}
if (strcmp(gEntry, "_Del") == 0){
Serial.write( byte(127) ); return;
}
if (strcmp(gEntry, "_Tab") == 0){
Serial.write(byte (9) ); return;
}
SIM900.write(gEntry); // send SIM900 keyboard input
}
/* GKOS keyboard outputs to LCD */
// Include libraries:
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <Gkos.h>
Adafruit_PCD8544 LCD(6,5,4,3,2);
extern uint8_t SmallFont[];
char* gEntry = "";
Gkos gkos(10,11,14,12,15,16);
void setup()
{
LCD.begin();
LCD.setTextSize(1);
LCD.clearDisplay();
LCD.println("LCD link up!");
LCD.display();
delay(2000);
LCD.clearDisplay();
}
void loop()
{
gEntry = gkos.entry(); // non-blocking
if (gEntry != 0){gPrint();}
}
void gPrint()
{
if (strcmp(gEntry, "_Enter") == 0){
//Serial.println("");
Serial.write( byte(10) ); Serial.write( byte(13) ); return;
}
if (strcmp(gEntry, "_BS") == 0){
Serial.write( byte(8) ); return;
}
if (strcmp(gEntry, "_Del") == 0){
Serial.write( byte(127) ); return;
}
if (strcmp(gEntry, "_Tab") == 0){
Serial.write(byte (9) ); return;
}
// Put text on the screen
LCD.print(gEntry);
LCD.display();
}
My attempt to combine all three, resulting in the error:
/* Unlimited Combo! */
#include <SoftwareSerial.h>
#include <Gkos.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#define rxPin 7
#define txPin 8
SoftwareSerial SIM900(rxPin, txPin);
char* gEntry ="";
Gkos gkos(10,11,14,12,15,16);
Adafruit_PCD8544 LCD(6,5,4,3,2);
extern uint8_t SmallFont[];
void setup()
{
SIM900.begin(19200); // SIM900 baud rate
Serial.begin(19200); // Serial port baud rate
// SIM900.println("AT+IPR=19200"); // do not autobaud
Serial.println("Serial link up!");
LCD.begin();
LCD.setTextSize(1);
LCD.clearDisplay();
LCD.println("LCD link up!");
LCD.display();
}
void loop()
{
gEntry = gkos.entry(); // non-blocking
if (gEntry != 0){gPrint();
}
// Serial patch to SIM900
int i = 0;
char someChar[32] = {0};
if(Serial.available())
{
do
{ someChar[i++] = Serial.read();
} while (Serial.available());
SIM900.print(someChar);
}
else if(SIM900.available())
{
do
{ someChar[i++] = SIM900.read();
} while (Serial.available());
Serial.print(someChar);
LCD.print(someChar); // SIM900 to LCD
LCD.display();
}
}
void gPrint()
{
if (strcmp(gEntry, "_Enter") == 0){
//Serial.println("");
Serial.write( byte(10) ); Serial.write( byte(13) ); return;
}
if (strcmp(gEntry, "_BS") == 0){
Serial.write( byte(8) ); return;
}
if (strcmp(gEntry, "_Del") == 0){
Serial.write( byte(127) ); return;
}
if (strcmp(gEntry, "_Tab") == 0){
Serial.write(byte (9) ); return;
}
SIM900.write(gEntry); // send SIM900 keyboard input
}
Any help combining the sketches is appreciated.