Raspberry pi with processing outputing X Y data to arduino

edited March 2017 in Raspberry PI

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

(http://scruss.com/blog/2014/01/07/processing-2-1-oracle-java-raspberry-pi-serial-arduino-☺/)

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!

Answers

  • @ianb Make sure you're using the correct serial port - this is particularly an issue with the Pi 3. See the Wiki for more information.

    If size is not an issue, I'd recommend connecting the Arduino via USB (it should show up as /dev/ttyUSB0).

    Using the Pi's build-in serial port is an option too, but you'd have to keep the caveats listed on the Wiki section in mind, and, that the Raspberry Pi is running on 3.3V, while many Arduino-boards run on 5V. If you only have to send data from Processing to Arduino (uni-directional, with just one wire), that shouldn't be a problem, but if you're exchanging data in both ways (with wires for both RX and TX), then you should be using a voltage converter.

  • thanks for your reply gohai, I found a way through a USB cable and using /dev/ttyAMA0

    and used myPort = new Serial(this, Ardunio.list()[0], 9600);

    {myPort.write

Sign In or Register to comment.