1

I am reasonably new to arduino and even newer to Processing so still struggle with trouble shooting my code.

The intention of my sketch is have Processing receive IR codes from the arduino and execute different AppleScript applications accordingly.

It works sometimes! However I would really love it to work all the time :)

-The AppleScript apps definitely work and have been successfully launched

-The processing monitor has been printing the 'Val' variable consistently

The issue is that even though processing is reading from the serial port and assigning the IR codes printed there to the 'val' variable, it only sometimes executes the conditional

I added a delay to my arduino sketch to slow down how much data was entering the port and make it easier for Processing to read but it's inconsistent.

Any help would be greatly appreciated!

Arduino code:

#include <boarddefs.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
#include <IRremoteInt.h>

int RECV_PIN = 10;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  Serial.print("Hello");
  irrecv.enableIRIn(); // Start the receiver
}

void loop()
{
  if (irrecv.decode(&results))
    {
     Serial.println(String(results.value,HEX));
     delay(100);
     irrecv.resume(); // Receive the next value
    }
}

Processing Code

import processing.serial.*;

Serial myPort;  // Create object from Serial class
String val;     // Data received from the serial port
String Down = "890";
String Up = "8188A2C8"; 
String CH1 = "E10";
void setup()
{
  // I know that the first port in the serial list on my mac
  // is Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[2]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 9600);
}

void draw()
{
  {
  if ( myPort.available() > 0) 
  {  // If data is available,
  val = myPort.readString();         // read it and store it in val

   print(val);

    if(val.equals(Down) == true) 
    {launch("/Applications/QlabDown.app");
  }
  if (val.equals(Up) == true) {
    launch("/Applications/QlabUp.app");
  }
  if (val.equals(CH1) == true) {
    launch("/Applications/CH1.app");
  }
} 
}
}
3
  • what does this mean? Processing receive IR codes from the arduino .... how is Processing receiving infrared signals?
    – jsotola
    Oct 10, 2019 at 2:08
  • Assuming there are two Arduinos. One running the "Arduino code" and the other running the "Processing code". The "Arduino code" has the manditory setup() and a loop() functions. But the "Processing code" only has the mandatory setup() function and is missing the loop() function.
    – st2000
    Oct 10, 2019 at 2:12
  • Sorry for not being clear, the Processing sketch is being ran on my laptop and is receiving the IR codes via the USB serial port created when the arduino is plugged into the laptop.
    – Harrie
    Oct 10, 2019 at 4:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.