Permalink
Browse files

Processing sketch to import text, send over serial

Processing sketch to import a text file, read in one line at a time, and
send it over the serial connection to a Tiny CNC drawing robot.
  • Loading branch information...
MakerBlock committed Jan 2, 2014
1 parent 65f0a6e commit 32b8fc7b46274bc969742e9cf8d21f7c6403db2b
Showing with 8,534 additions and 0 deletions.
  1. +64 −0 SendingSerial003.pde
  2. +8,470 −0 file.gcode
View
@@ -0,0 +1,64 @@
/**
* Simple Write.
* Check if the mouse is over a rectangle and writes the status to the serial port.
* This example works with the Wiring / Arduino program that follows below.
*/
import processing.serial.*;
import java.io.*;
// import java.io.FileReader;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
String command;
void setup()
{
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 115200);
readData("C:/Users/Jay/Desktop/MakerBot/processing-2.0.3/Sketchbook/Sketches/SendingSerial003/file.gcode");
}
void readData(String myGcodeFile)
{
File file=new File(myGcodeFile);
BufferedReader br=null;
try{
br=new BufferedReader(new FileReader(file));
String text=null;
/* keep reading each line until you get to the end of the file */
while((text=br.readLine())!=null){
/* Spilt each line up into bits and pieces using a comma as a separator */
print(text + '\n');
myPort.write(text);
myPort.write('\n');
delay(1000);
}
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}finally{
try {
if (br != null){
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
void importTextFile(){
String[] strLines = loadStrings("file.gcode"); // the name and extension of the file to import!
for(int i = 0; i < strLines.length; ++i){
String[] arrTokens = split(strLines[i], ','); // use the split array with character to isolate each component
float xx = float(arrTokens[0]); // cast string value to a float values!
float yy = float(arrTokens[1]); // cast string value to a float values!
float zz = float(arrTokens[2]); // cast string value to a float values!
// pointList.add( new PVector(xx,yy,zz) ); // add values to a new array slot
}
}
Oops, something went wrong.

0 comments on commit 32b8fc7

Please sign in to comment.