0

I've collected some string information in processing and I am trying to send it to Arduino. I am getting processing to send the information, however, my output in arduino is weird. I get numbers like "77789...". I am not sure What I am doing wrong. All I need to do is, basically get a string from processing and send it to arduino to display it on a LCD screen.

Any help on this would be appreciated.

Here is my processing code:

import processing.serial.*;

Serial myPort;

XML MSFTxml; // loading Query

XML MSFT; // results of the query
XML row; // first row in the query

XML symbol; // Name of the stock
String symbolTxt;


String val;

void setup() {
  size(200,200);
  myPort = new Serial(this,"COM3", 9600);

}

void draw() {

updateXMLCall();

delay(10000);
}
void updateXMLCall () {

   MSFTxml = loadXML("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D%27http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes.csv%3Fs%3DMSFT%26f%3Dsl1d1t1c1ohgv%26e%3D.csv%27%20and%20columns%3D%27symbol%2Cprice%2Cdate%2Ctime%2Cchange%2Ccol1%2Chigh%2Clow%2Ccol2%27&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");  
   MSFT = MSFTxml.getChild("results"); //Getting the first tag "results" in the query MSFT
   row= MSFT.getChild("row"); //first child tag "row"
   symbol = row.getChild("symbol"); //name of the stock   
   symbolTxt = symbol.getContent().toString(); //converting the name of the stock into a string
   myPort.write(symbolTxt);
   println(symbolTxt);
}

Here is my arduino Code:

#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;

const int colorR = 50;
const int colorG = 0;
const int colorB = 0;

void setup()
{
  Serial.begin(9600);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);
  // Print a message to the LCD.
  lcd.setCursor(0, 1);
}

void loop()
{  
  String content = "";
  if (Serial.available()) {
    while (Serial.available()) {
      content += Serial.read();
      lcd.print(content);
      Serial.print(content);
      lcd.setCursor(0, 1);
    }
  }
  delay(100);
}
Ôrel
  • 7,044
  • 3
  • 27
  • 46
tailedmouse
  • 365
  • 3
  • 16
  • 2
    Your problem is the '+=' , look here to parse data send via serial: http://stackoverflow.com/questions/5697047/convert-serial-read-into-a-useable-string-using-arduino – Ôrel May 17 '15 at 02:19
  • @Ôrel Thanks so much! that helped a lot :D I got it working. I used readStringUntil(/n); that seemed to be just the thing I was looking for – tailedmouse May 17 '15 at 18:34
  • 1
    @Ôrel you probably want to turn that into an answer instead of a comment, so it can be accepted and future SO users who run into the same issue can find an accepted answer =) – Mike 'Pomax' Kamermans May 18 '15 at 05:41

1 Answers1

1

The problem is the use of += in C += doesn't concat strings. You need to concatenate the char get from Serial.read() like here for example: Convert serial.read() into a useable string using Arduino?

Community
  • 1
  • 1
Ôrel
  • 7,044
  • 3
  • 27
  • 46