Hi,
I've got arduino reading text sent from Applescript and hopefully I'm packaging that code properly thanks to PaulS tips and tricks that I've read on this forum. This is a big set for me so, many thanks!
The couple of issues I have at the moment are, When I view the serial in arduino, every time I send the text it just adds it to the line.
i.e. I get: hello worldhello worldhello worldhello world
If I use Serial.println I then get
h
e
l
l
o
w
o
r
l
d
I'm new at this so bare with me, but I'm thinking that "hello world" is being put into an array and the each letter is being printed by Serial.println rather than the whole string.
How would I get the whole string to print on a new line in serial each time?
Heres my code:
Note this is a bit of a mash of PaulS sketch and an LCD sketch as I'm also trying to get this string (hello world sent from applescript) to print to the LCD.
(eventually I that will be the track name from itunes)
// include the library code:
#include <LiquidCrystal.h>
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char inData[80];
byte index;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
 // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
 Serial.begin(9600);
}
void loop() {
 // set the cursor to column 0, line 1
 // (note: line 1 is the second row, since counting begins with 0):
 lcd.setCursor(0, 1);
 // print the number of seconds since reset:
 lcd.print(millis()/1000);
Â
  // Read all serial data available, as fast as possible
 while(Serial.available() > 0)
 {
  char inChar = Serial.read();
  if(inChar == SOP)
  {
   index = 0;
   inData[index] = '\0';
   started = true;
   ended = false;
  }
  else if(inChar == EOP)
  {
   ended = true;
   break;
  }
  else
  {
   if(index < 79)
   {
    inData[index] = inChar;
    index++;
    inData[index] = '\0';
   }
  }
  // set the cursor to column 0, line 0
  lcd.setCursor(0, 0);
  Serial.println(inChar);
  lcd.print(inChar);
 }
Â
 // We are here either because all pending serial
 // data has been read OR because an end of
 // packet marker arrived. Which is it?
 if(started && ended)
 {
  // The end of packet marker arrived. Process the packet
  // Reset for the next packet
  started = false;
  ended = false;
  index = 0;
  inData[index] = '\0';
 }
}
The other problem I have is that only the last letter of the string "hello world" is being printed to the top line of my LCD.
Is this also because of the way the string is being packaged?
Many thanks for any help.