Raspberry pi with processing outputing X Y data to arduino

Right OK, I fear I'm rapidly out of my depth so grateful for any help!

I'm running a processing sketch on a pi 3 attached to a touch screen. As the screen is touched its drawing a line with the finger. Whilst doing that its printing the X , Y coordinates to the console in processing.

What i'm trying to do is get these coordinates to the arduino. The arduino has an uploaded HEX file onto the onboard chip. These are controlling 2 steppers. So if you have the arduino IDE running you type X10 into the serial monitor and in drives the stepper. So, the arduino is tied up with grbl so I can't run a sketch to look for data or act on data being sent.

I some how need to get the X Y data to the arduino. Is the best way through a USB cable? I've followed this useful link to set up the serial arduino command setup

(Processing 2.1 + Oracle Java + Raspberry Pi + Serial + Arduino = ☺ – We Saw a Chicken …)

and have data going from processing to arduino

this works as a test flashing the arduino light on and off

import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int ledPin = 13;
 
void setup()
{
  println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0], 9600);
  arduino.pinMode(ledPin, Arduino.OUTPUT);
}
 
void draw()
{
  arduino.digitalWrite(ledPin, Arduino.HIGH);
  delay(1000);
  arduino.digitalWrite(ledPin, Arduino.LOW);
  delay(1000);
}

this is also working with my attempt to get X10 to the arduino grbl shield but no X10 going to arduino. mouse released in processing square LED on arduino blinks.

import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
 
void setup()
{
  size (200,200);
  println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0],9600);
}
 
void draw() {
  background(100);
}
void mouseReleased(){
  arduino.digitalWrite('X', 10);
}

heres the code for the processing sketch do far it works but no data going to the serial of the arduino, should I be using digitalwrite to write the data into the arduino serial monitor, should i not be using USB but rather TX RX?

import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
 
void setup()
{
  size (200,200);
  println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0],9600);
}
void setup() 
{
  size(200,200); //make our canvas 200 x 200 pixels big
  String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 9600);
}
 
void draw() {
  stroke(255);
  if (mousePressed == true) {
    line(mouseX, mouseY, pmouseX, pmouseY);
  }
}
void mousePressed ()
{
    println("PRESSED x:" +mouseX + " y:" + mouseY);
}
void mouseDragged ()
{
  println("G01 x" +mouseX + " y" + mouseY + " F100");
}

Thankyou in advance for any help. Loving the whole coding hardware... but struggling with the depth of knowledge required and coding logic!

ianb88:
What i'm trying to do is get these coordinates to the arduino. The arduino has an uploaded HEX file onto the onboard chip. These are controlling 2 steppers. So if you have the arduino IDE running you type X10 into the serial monitor and in drives the stepper. So, the arduino is tied up with grbl so I can't run a sketch to look for data or act on data being sent.

I some how need to get the X Y data to the arduino. Is the best way through a USB cable? I've followed this useful link to set up the serial arduino command setup

This all sounds very confusing.

On the one hand you say you have the GRBL program loaded on your Arduino and on the other hand you seem to have some unspecified HEX file uploaded that can make sense of commands from the Serial Monitor such as X10.

And you apparently also have a Processing program that can produce some co-ordinate data, but you have not provided any examples of what that looks like.

I am not familiar with Processing (I generally use Python) but it should be possible to write a program that can create GCode instructions to send to GRBL. Or create whatever type of instruction the other un-named Arduino program requires.

However I'm not sure how practical it would be to make stepper motors follow a line on a PC as it is being drawn in real time. It might make more sense to complete a line segment, or a whole drawing, and then send the data to the Arduino.

...R

Hi Robin.

Thanks for your reply

The Arduino is running an uploaded HEX file that is the GRBL programme. So if you type X10 in the serial monitor it controls via the shield the X - axis stepper. As its running GRBL I can't run a arduino sketch to connect to processing, it simply must read X10 Y12 for example.

The processing code is in the last block of code in my original post and basically outputs

G01 X11 Y27 F100

G01 is a linear movement, F is the feed rate, both constant. X and Y varying as the screen is pressed.

I just need a way to get the code out of the console on processing into the serial monitor on the arduino. I can't see this serial monitor, so can you write data to it in this manner via the USB cable between the two?

I've tried uploading data from processing and this works. But i can't get this data to to the arduino. I'm thinking its something in the code in processing that isn't right?

ianb88:
I just need a way to get the code out of the console on processing into the serial monitor on the arduino

That is not the correct approach.

You need to arrange for your Processing program to send the data directly to the Arduino rather than using the Serial Monitor to send it. That should be perfectly possible but I cannot explain how to do it.

...R

I just need a way to get the code out of the console on processing into the serial monitor on the arduino.

No, you don't. What you do need is to have Processing write to the serial port, NOT the processing debug window. Processing has plenty of examples that show how to do that.