We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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!
Answers
do you have android sdk installed? specifically api level 15?
android processing is very picky about version numbers.
no. i thought by installing the android mode this is also done. i´m going to install the sdk. is there something more i have to do in the sdk?
thanks a lot for your fast answer!
now i´ve installed android 4.0.3 in the sdk manager. but the error is sadly the same. are there some more things i should install in the sdk?
Thank you!
so when i switch to android mode it says:
under error section it says:
The class "PApplet" does not exist The class "PApplet" does not exist (double-click for suggestions) sketch_160221e 2
how can i get the android mode running?
I installed the Java SDK and now it´s working.
Now i tried to run my android sketch on my device. I already selected my device at the android tab. When i press "run on device" its building the android projekt. there are some warnings in the console:
When it´s finished my phone is trying to start the app but it´s suddenly stopping and in the console debug info is comming:
Got someone an idea for me please? I got no idea whats wrong with my sketch because it´s running in java mode. so i think my problem is related to converting my sketch to android mode.
Thank you.
Try initializing
bt
,KetaiBluetooth bt;
,KetaiBluetooth bt = new KetaiBluetooth(this);
i think you can ignore the import warnings - processing includes a lot of files just in case you use them.
from ketai, and check in "sketch permissions" bluetooth, bletooth_admin
Hey thank you for all for your help!
@Deathy:
i already got this in my sketch: KetaiBluetooth bt; so should i just add this?: KetaiBluetooth bt = new KetaiBluetooth(this);
tried this but i get some errors from inside the android tools:
@camperos:
thank you! i forget about the permissions. but what about the code you posted? should i add the code to my sketch?
After setting the permissions i got a new debug report:
Thanks for helping!
Those errors are pretty clear. Looks like an error with your code (that you haven't posted)
Okay....thats bad.
I posted my running java mode skech and my android version in the first post.
To prevent running into code problems i fist made a running java mode sketch. I tried to leave the code like in the java mode version. can you please have a look on my code?
Thank you...
Hi, put the code before setup(), like: https://github.com/ketai/ketai/blob/master/examples/BluetoothCursors/BluetoothCursors.pde
WOW Thank you!! My code running on my smartphone...that feels nice.
but.....
sadly i´m not receiving the data. I think this is the problem:
debug report: Did not find onBluetoothDataEvent callback method.
I got a problem in my code in this section:
In my Java serial connection sketch i did it like this:
I got no idea who can fix this... it took weeks for me to get the java sketch running, but this time i´m lost.
But the Programm is running on my phone... this is great! :)
Thanks
just print (log) the who and data objects to start with. then you can see what you need to do with them to extract the payload.
sorry i´m very new to this....I tried a couple of things but.....
How can i print who and data as easy as possible? because it´s already array and not like in the java serial version a complete string. so i didn´t get it to just print it. i tried some things but nothing worked. i found another code and now i can see some data flickering across the screen:
Can you please give me a hint how to work with the array? Sorry for my english.
Thanks
Is there an easy way to print the who and data objects? sorry i´m not getting it...
Thank you.
Now i got it....i receive the data from my arduino via bluetooth!
But one thing isn´t perfect:
I receive the data with this sketch very slow (sometimes it takes 2sec until value is refreshed). I think this problem is related to " if ((char)data[data.length-1]=='\n') dataEnd = true;", but its needed to identify my data clearly. When i´m only text/print (log) the value of data i can see data comming in from the arduino very fast.
Anybody got an idea for another faster solution. Or is something wrong in the skech? Should i post this problem in another category?
Thank you.