Sending String from Arduino to Processing app on Android over Bluetooth


#1

Hey guys, I’m pretty new to Arduino and Processing and currently trying to do the following thing for a school project: I want to send a String with data from sensors on my Arduino to a android phone or tablet over bluetooth.
For simplicity’s sake I reduced the code in complexity, removing every part of my code that isn’t trying to facilitate the transfer of a String from Arduino to Processing on Android. The following code is simply trying to send the String “S01E” to the processing app on my phone, saving the String into my “String info” and displaying that string in form of a text(info, 20, 110); element.

Additional Info
Arduino bluetooth module is a “Bluefruit EZ-Ling BLuetooth Shield”.
Phone is Samsung Galaxy S8.
Processing App is generated with Android mode of Processing.
My phone is successfully paired with the arduino over bluetooth.

The code compiles successfully, but it only shows my text(“test text”, 20, 120); on my phone, but not my text(info, 20, 110);, which I assume means that the String is not being received and the info String stays empty.

How can i proceed from here? Are there some obvious problems in my code. And how can I properly debug my code with the weird stack of technologies that I use?

Processing Code:

import netP5.*;

import android.content.Intent;
import android.os.Bundle;

import ketai.net.bluetooth.*;
import ketai.ui.*;
import ketai.net.*;
 
KetaiBluetooth bt;
boolean isConfiguring = true;


String info = "";
KetaiList klist;
ArrayList devicesDiscovered = new ArrayList();
  
// States of the two sensors
int B1in = 0;
int B2in = 0;

//********************************************************************
// The following code is required to enable bluetooth at startup.
//********************************************************************


void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  bt = new KetaiBluetooth(this);
}

void onActivityResult(int requestCode, int resultCode, Intent data) {
  bt.onActivityResult(requestCode, resultCode, data);
}
 
// setup() wird einmal zu Beginn dea Programms ausgeführt
void setup() {
 size(displayWidth, displayHeight);
 frameRate(10);
 orientation(PORTRAIT);
 background(255);
 stroke(160);
 fill(50);
  
  //start listening for BT connections
 bt.start();
 //at app start select device…
 isConfiguring = true;
}
 
// Wie loop() beim Arduino wird draw() immer wieder aufgerufen, solange das Programm ausgeführt wird.
void draw() {
  background(255);
  
  text(info,20,110);
  text("test text",20,120);
  println(info);
  
}

void onKetaiListSelection(KetaiList klist)
{
  String selection = klist.getSelection();
  bt.connectToDeviceByName(selection);

  //dispose of list for now
  klist = null;
}

//Call back method to manage data received
void onBluetoothDataEvent(String who, byte[] data) {
 if (isConfiguring)
 return;
 //received
 info = new String(data);
}

And here is my Arduino code:

#include <SoftwareSerial.h>

SoftwareSerial bt(2,3); // RX, TX

 
// Enthält den String, der an den PC geschickt wird
String data = "S01E";
 
// Serielle Schnittstelle einrichten, pinModes setzen
void setup() {

  bt.begin(9600);
  Serial.begin(9600);
}
void loop() {

  Serial.println(data);
  // Um die serielle Ausgabe zu beobachten, einfach nach dem Programmstart den seriellen Monitor in der Arduino Umgebung starten
}