Hello I have modified the ReceiveSMS example code from Arduino IDE to work with a 20x4 LCD connected in parallel. I have managed to make it work without serial monitor. Everything works fine but I can only display one SMS at a time. I would like to have it display the first 4 consecutive incoming SMSs onto the 20x4 LCD, one for each row. I'm a beginner without much programming background, can anyone please help me with this?
Thank you.
Code: #include <GSM.h> // include the GSM library #include <LiquidCrystal.h> // include the LCD library
LiquidCrystal lcd(12, 11, 10, 6, 5, 4); // initialize the library with the numbers of the interface pins
// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
void setup()
{
lcd.begin(20, 4);// set up the LCD's number of columns and rows
boolean notConnected = true; // connection state
{
lcd.clear();
lcd.print("SMS Message Display");// Print a message to the LCD
lcd.setCursor(0,1);// set the cursor to column 0, line 1
lcd.print("GSM Modem Offline!!!");
lcd.setCursor(0,2);
lcd.print("Connecting Modem...");
lcd.setCursor(0,3);
lcd.print("Please Wait...");
}
// Start GSM connection
while (notConnected)
{
if (gsmAccess.begin() == GSM_READY)
{
notConnected = false;
}
else
{
lcd.clear();
lcd.print (" Not connected! ");
delay(1000);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print (" GSM Initialised! ");
delay (500);
lcd.setCursor(0, 1);
lcd.print(" Modem Connected! ");
delay (500);
lcd.setCursor(0, 2);
lcd.print("Waiting for Messages");
delay(1000);
}
}
void loop()
{
char c;
if (sms.available()) // If there are any SMSs available()
{
lcd.clear();
while (c = sms.read()) // Read message bytes and print them
{
lcd.write(c);
}
{
delay(2000);
}
I already know how to write data to the 4 lines as you see at the start of the code, I would like to receive multiple SMSs and display each of them onto the for lines consecutively, maybe in some kind of loop and stack/array? Till now I have only been able to display a single SMS on the first line, when another new SMS is received, the display with the previous SMS is cleared and the new SMS is displayed again on the first line.
Basically what I'm trying to do is to receive and display at most 4 new SMSs on the 4 lines of the 20x4 display continuously in some kind FIFO stack (First In First Out), I do not need to save the SMSs on the sim card or anything, the SMS can be discarded after being displayed.
I believed the only part that may need modifications would the loop part as shown below: void loop() { char c; if (sms.available()) // If there are any SMSs available() { lcd.clear(); while (c = sms.read()) // Read message bytes and print them { lcd.write(c); } { delay(5000); } //wait for msg to display in case another new msg is received sms.flush();// Delete message from modem memory } }
Basically what I'm trying to do is to receive and display at most 4 new SMSs on the 4 lines of the 20x4 display continuously in some kind FIFO stack
What you say you want, and what your code does, are NOT the same thing.
Look at your last code. Point out EXACTLY where you position the text on the LCD. If you can't find it, then why do you think the LCD is going to read your mind?
PaulS:
What you say you want, and what your code does, are NOT the same thing.
Look at your last code. Point out EXACTLY where you position the text on the LCD. If you can't find it, then why do you think the LCD is going to read your mind?
That's the thing I do not have a clue where to start, the lcd.write(c); code will display the message on the first row by default. I have posted another topic that can explain what I need better.
the lcd.write(c); code will display the message on the first row by default
No. The lcd.write() statement will display the character in the next available position. Initially, the next available position is the first space on the first row. But, you CAN change where the next write() will happen.