Pages: [1]   Go Down
Author Topic: Arduino, LCD and Serial connection to Sony Ericsson Phone  (Read 1028 times)
0 Members and 1 Guest are viewing this topic.
South-East UK
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi folks,

I dug out an old SE T630 phone I had in a drawer and shoved a pre-pay SIM in and have it successfully working using AT commands through serial.

Now what I want is for the Arduino to "parse" the incoming messages.  For example, display them on my (20x4 parallel) LCD. Or do something else when it recognises a certain string.

I am a C / programming noob and have built up most of my Arduino code thus far by googling and looking at the Arduino.cc resources, so this challenge came as, well, a bit of a challenge!

I have finally found an example sketch online which seems to do most of what I want, i.e. read serial output and shove it to the LCD.

From here: http://www.midnightcheese.com/2011/10/displaying-twitter-and-weather-on-your-arduino-lcd-screen/

I have this, thus far:

Code:
#include <LiquidCrystal.h>
#include <wstring.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);

void setup() {
   lcd.begin(4, 20);       // Set the LCD's number of rows and columns
  Serial.begin(9600);     // Initialize communication with serial(USB) port.
  lcd.print("Hello.");    // Print welcome message to LCD.

}

int bufferArray[250];     // Our array to store characters arriving from serial port.
int output = 0;
int i = 0;

void loop() {

  int count = Serial.available();

  if (Serial.available() > -1) {
    delay(1000);
    for (i=0; i<count ; i++) {
     bufferArray[i] = Serial.read();          // Put into array
     output = 1;                              // Show new data has been recieved
    }
  }
  
  if (output != 0) {                          // If new bytes have been recieved                
    int position = 0;
    if (bufferArray[0] == '!') {              // Print on first line if message begins with '!'
      lcd.clear();
      lcd.setCursor(0,0);
      position = 1;
    } else if (bufferArray[0] == '@') {       // Print on second line if message begins with '@'
      lcd.setCursor(0,1);
      position = 1;
    } else if (bufferArray[0] == '^') {       // Clear screen if message begins with '^'
      lcd.clear();
      lcd.setCursor(0,0);
      position = 1;
    } else {
      lcd.clear();
      lcd.setCursor(0,0);
    }
    int j;
    for (j = position; j < count; j++) {
      lcd.write(bufferArray[j]);
    }
    output = 0;                               // Don't print on next iteration
    memset(bufferArray, 0, count);
    count = 0;
  }

}


And I don't really need any of the ifs, etc. I just want it to show the AT commands, SMS content etc on the LCD.  However when I've tried editing the above, cutting bits out etc, it seems to break it! smiley-sad

Can anyone help me simplify the above code so it's just the 'bare minimum' I can work from?  And maybe help out how I may be able to call various functions and do things (let's keep it simple for now and illuminate an LED when I send a text to it with the word "LED" in the body, for example)?

I realise I'm asking quite a lot but some guidance as if I'm a 5 year old would be much appreciated!  

Some background info on Sony Ericsson integration:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1290601471/all
http://www.smssolutions.net/tutorials/gsm/sendsmsat/

Thanks smiley
« Last Edit: December 19, 2011, 05:27:47 pm by hcanning » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  if (Serial.available() > -1) {
    delay(1000);
    for (i=0; i<count ; i++) {
     bufferArray[i] = Serial.read();          // Put into array
     output = 1;                              // Show new data has been recieved
    }
  }
0 (nothing to read) is greater than -1.

If you are going to loop only for the number of characters available, why do you need to test that there might be no bytes to read?

Why, pray tell, when you know that there is (or might be, actually) data to read do you fart around for a second not reading it?

If all you want to do with the data is show it on the LCD, why are you storing it in an array?
Logged

South-East UK
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know, x3.

Did you miss the part of my post where I said I don't know what a lot of that code refers to, and it's the only way I found of displaying serial to LCD? It seemed like an ideal starting point.

I assumed the array was necessary to store it as a string before outputting it, I dunno.


Maybe I should rephrase the question...

What's the easiest way of outputting the results of AT commands to LCD?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What's the easiest way of outputting the results of AT commands to LCD?
Code:
lcd.print(Serial.read());
in a loop.
Logged

South-East UK
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Doesn't work. I just get numbers.  

If I do lcd.print((char)Serial.read()) it sort of works, but I just get each letter in succession at the first character of the display. It doesn't display properly.
« Last Edit: December 20, 2011, 03:11:28 am by hcanning » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If I do lcd.print((char)Serial.read()) it sort of works, but I just get each letter in succession at the first character of the display. It doesn't display properly.
You asked for the easiest way to display the data. That was the easiest. Of course, you are expected to set the position of the cursor to the next position (although I thought that was done automatically).

Post the code you are actually using now.
Logged

South-East UK
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have any code. I only have what I found and posted in the first post. Which works, but seems like a bit of a long winded way of doing it.

I'm not a programmer, I've only just started out with Arduino.  I'm asking for guidance on starting out with this particular project.  Is the arrogance really necessary?
« Last Edit: December 20, 2011, 06:42:28 am by hcanning » Logged

Pages: [1]   Go Up
Jump to: