Arduino send string (or any kind of data) to Processing

edited August 2014 in Arduino

Hey guys! I need your help, as for now, I don't know why my processing code doesn't read the data from arduino as string. Here's my code. Arduino

        int ledPin = 13;
        int LDRpin = 0;
        Servo myServo;
        void setup()
        {
          pinMode(ledPin, OUTPUT);
          pinMode(LDRpin, INPUT);
          Serial.begin(9600);
        }
        void loop()
        {
          int val = analogRead(LDRpin);
          if(val > 30)
          {
            Serial.println("A");
            digitalWrite(ledPin, HIGH);
            delay(1000);
          }else
          if(val < 10)
           {
             Serial.println("B");  
            digitalWrite(ledPin, LOW);
            delay(1000); 
           }
        }

Processing

    import processing.serial.*;
    Serial myPort;
    String inByte;
    
    void setup()
    {
      size(300,300);
      println(Serial.list());
      myPort = new Serial(this, Serial.list()[0], 9600);
      myPort.bufferUntil('\n');
      textSize(32);
    }
    
    void draw()
    {
      background(0);
      while(myPort.available() > 0){  
        inByte = myPort.readStringUntil('\n');
        if(inByte != null)
        {
          println(inByte);
          if(inByte == "A")
          {
            println("ON");
          }else
          {
            println("OFF");
          }
        }
      
      
    }
    }

Here's the scenario: if my LDR's value is greater than 30, my LED turns ON and sends string data ("A") to processing, and when my processing receives a string data value "A", it will then output "ON", else "OFF". I think my processing doesn't read my arduino data as String? Please point this out to me :( Thank you in advance!

Tagged:
Sign In or Register to comment.