Hello,
i made the following sketch to communicate with my arduino. The sketch is running fine in java mode but my goal is to run the sketch on my phone:
import processing.serial.*;
Serial myPort; // Objekt der Serial-Klasse
char HEADER = 'H'; // Zeichen zur Identifikation des Anfangs einer Nachricht
short LF = 10; // ASCII-Linefeed
float kmhArduino;
int distArduino;
int siebenArduino;
PFont font;
short portIndex = 0; // com-Port wa¨hlen, 0 ist der erste Port
void setup() {
size(480, 800);
font = loadFont ("Arial-BoldMT-48.vlw");
println(Serial.list());
println(" Verbinde mit -> " + Serial.list()[portIndex]);
myPort = new Serial(this, Serial.list()[portIndex], 9600);
}
void draw() {
background(0, 0, 50);
fill(255, 0, 0);
textFont(font, 48);
text("Sk8tacho V1.0", 50, 100);
textFont(font, 40);
fill(255, 255, 0);
text(kmhArduino + "kmh", 100, 300);
text("Distance: " + distArduino + "m", 50, 400);
fill(255, 0, 0);
textFont(font, 30);
text("made by inventED 2015", 50, 700);
}
void serialEvent(Serial p)
{
String message = myPort.readStringUntil(LF); // Serielle Daten einlesen
if (message != null)
{
print(message);
String [] data = message.split(","); // Kommaseparierte Nachricht zerlegen
if (data[0].charAt(0) == HEADER && data.length > 3) // check validity
{
kmhArduino = float(data[1]);
distArduino = int(data[2]);
//siebenArduino = int(data[7]); // falls mehr werte gebraucht werden
}
}
}
i already tried to convert it to android mode. but when i switch to android mode i get this errors in the console:
Exception in thread "Thread-126" java.lang.NullPointerException
at processing.mode.android.AndroidBuild.setSdkTarget(AndroidBuild.java:76)
at processing.mode.android.AndroidEditor.updateSdkMenu(AndroidEditor.java:347)
at processing.mode.android.AndroidEditor.access$300(AndroidEditor.java:50)
at processing.mode.android.AndroidEditor$7.run(AndroidEditor.java:249)
Here is my converted android mode code:
//import processing.serial.*;
//Serial myPort;
import android.os.Bundle;
import ketai.net.bluetooth.*;
KetaiBluetooth bt;
char HEADER = 'H'; // Zeichen zur Identifikation des Anfangs einer Nachricht
short LF = 10; // ASCII-Linefeed
float kmhArduino;
int distArduino;
int siebenArduino;
PFont font;
short portIndex = 0; // com-Port wa¨hlen, 0 ist der erste Port
void setup() {
size(480, 800);
font = loadFont ("Arial-BoldMT-48.vlw");
/*println(Serial.list());
println(" Verbinde mit -> " + Serial.list()[portIndex]);*/
//myPort = new Serial(this, Serial.list()[portIndex], 9600);
bt.start(); // BT Service starten.
//***************************************************************
// Hier muss die individuelle Adresse deines BT Moduls eingegeben werden.
bt.connectDevice("98:D3:31:30:2C:04"); // HC-05 BT-Modul
//bt.connectDevice("00:13:01:06:20:83"); // HC-05 BT-Modul
//bt.connectDevice("00:11:12:11:04:73"); // BT-Shield Arduino
//***************************************************************
}
void draw() {
background(0, 0, 50);
fill(255, 0, 0);
textFont(font, 48);
text("Sk8tacho V1.0", 50, 100);
textFont(font, 40);
fill(255, 255, 0);
text(kmhArduino + "kmh", 100, 300);
text("Distance: " + distArduino + "m", 50, 400);
fill(255, 0, 0);
textFont(font, 30);
text("made by inventED 2015", 50, 700);
}
/*void serialEvent(Serial p)
{
String message = myPort.readStringUntil(LF); // Serielle Daten einlesen
if (message != null)
{
print(message);
String [] data = message.split(","); // Kommaseparierte Nachricht zerlegen
if (data[0].charAt(0) == HEADER && data.length > 3) // check validity
{
kmhArduino = float(data[1]);
distArduino = int(data[2]);
//siebenArduino = int(data[7]); // falls mehr werte gebraucht werden
}
}
}*/
void onBluetoothDataEvent(String who, String[]data) //Callback Methode: Es liegen Daten vom Arduino an der BT-Schnittstelle an.
{
if (data != null)
{
//print(message);
//message.split(","); // Kommaseparierte Nachricht zerlegen
if (data[0].charAt(0) == HEADER && data.length > 3) // check validity
{
kmhArduino = float(data[1]);
distArduino = int(data[2]);
//siebenArduino = int(data[7]); // falls mehr werte gebraucht werden
}
}
}
when i try to run the sketch i get this error in the console:
BUILD FAILED
C:\Users\ED\Documents\Processing\modes\AndroidMode\sdk\tools\ant\build.xml:538: Unable to resolve project target 'android-15'
Total time: 0 seconds
Would be really cool if anybody can help me out!! I´m pretty new to coding and processing, sorry if something is not clear.
I´m using Windows 7 64-bit, tried Processing 3.0.2 windows 64-bit version and 32-bit version.
Thank you!