Android Bluetooth to Arduino and vice versa

ok

i well try it tonight and back to you with the result

i want to ask about APDE is it working with sound library
i???

Yes, you can find an adapted version of the sound lib for the APDE on my Github repo.

1 Like

The best thing you can do to see how to handle the String Str, is to println() it, and visualize it in the console.

1 Like

give me the link if you please of the sound library

Here you go.

1 Like

thanks :ok_hand: :ok_hand: :ok_hand:

hi sir

i have tried this sketch but did not work with me

what i miss ???

import ketai.net.bluetooth.*; 
import android.os.Bundle; 
import oscP5.*; 
import netP5.*; 

OscMessage m; 
KetaiBluetooth bt; 

String str = "myData"; 
int start_time; 

void setup() { 
  bt.start(); 
  m = new OscMessage(str);
} 

void draw() { 
  if (millis() - start_time > 300) { 
    bt.broadcast(m.getBytes()); 
    start_time = millis();
  }
} 

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

Was there any error? Did you give the Bluetooth permissions? If on APDE did you run in App mode?

1 Like

no error just white screen i run it in App mode and give Bluetooth permissions

That’s good, but now you have to pair your phone with another Android phone and install the app I mentioned above to visualize the bytes you are sending.

1 Like

i did

no result just white screen

i try the serial terminal on both tablets they send to each other ((with out the sketch))

Did the terminal app connect to the sender phone?

1 Like

Just to get it right.

  • On the sender phone both oscP5 and Ketai library are installed.
  • Both phones are paired
  • You start the sender sketch on sender phone,
  • You tab on the connect icon in the terminal app.
  • Only appears “Connected” nothing else?
1 Like
  • On the sender phone both oscP5 and Ketai library are installed. yes
  • Both phones are paired yes
  • You start the sender sketch on sender phone, yes
  • You tab on the connect icon in the terminal app.yes
  • Only appears “Connected” nothing else? yes

I have to think about that, because I use this all the time to see what I am sending, and it doesn’t fail.

ok

let us make the terminal send to the sketch do you have ready code for this ?

Try first to read the bytes send by your HC-05 to your phone with the terminal app.

1 Like

i am working on that

When you have this working try to read the bytes with this code on your phone.
The name must be exactly that of your HC-05 module and be sure that there are no other modules paired, to avoid conflicts. Also on the Arduino side set a delay(100), 100 ms between each (short) write(); command.

import ketai.net.bluetooth.*;
import android.os.Bundle;

String device_name = "HC-05";
String Str; 

KetaiBluetooth bt;

void setup() { 
  fullScreen();
  orientation(PORTRAIT);
  bt.getPairedDeviceNames();
  bt.connectToDeviceByName(device_name);
  bt.start();
  textSize(60);
  textAlign(CENTER);
}

void draw() {
  background(0, 0, 200);
  text(Str, width/2, height/2);
}

void onBluetoothDataEvent(String who, byte[] data) {
  Str = new String(data); 
  println(Str);
}

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

hi sir

do i have to use this line or not ?

String device_name = "HC-05";
//String device_mac = "40:45:DA:00:25:05";/// this line i mean