Ketai Bluetooth Communication Breakdown After Orientation Change

edited November 2013 in Android Mode

For a school project I developped a Processing Android app to control a small electric toy plane. The Android device communicate via Bluetooth (BT) with a BT-module on an Arudino Pro Nano. The Arduino controls two servos and a brushless motor using an ESC. For the BT-Communication I use the Ketai library.

The app is locked in Landscape Mode using orientation(LANDSCAPE) in the setup() method. If I start the app on the Android device in a horizontal direction everything works well. If the app is launched on an device in a vertical orientation the BT connection is established (referring to the LEDs on the BT module) but no BT communication is possible.

If the app is not locked in any orientation mode, the BT communication works, independend on the orientation of the android device at the app launch. However if the orientation of the android device changes afterwards, the BT communication breaks down.

I guess this problem has something to do with a new call of the onCreate() and setup() method after an orientation change. Is there any way to make the BT communikation work, even if you start the (landscape) app on a device being currently in portrait orientation?

Below there is the corresponding section of my code.

Thanks in advance for your help.


import android.os.Bundle;
import android.content.Intent; 
import ketai.net.bluetooth.*;
import ketai.sensors.*;

KetaiBluetooth bt;
KetaiSensor sensor;

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

void onActivityResult(int requestCode, int resultCode, Intent data) {
  bt.onActivityResult(requestCode, resultCode, data);
}

void setup()
{
  if (!bt.isStarted()) {
    orientation(LANDSCAPE);
    bt.start(); 
    bt.connectDevice("00:11:12:11:04:73");
    size(800, 480);
    sensor = new KetaiSensor(this);
    sensor.start();
    frameRate(10);
  }
}

void draw()
{ 

Answers

  • try this: put the orientation() before if()

  • edited November 2013

    orientation() isn't the correct way to set the orientation. I have encountered problems with this function in the past. Instead, you must change a property in the AndroidManifest.xml file in the sketch folder. You must set the property android:screenOrientation in the <activity> tag to be either "portrait" or "landscape". For example, my <activity> tag reads as follows:

    <activity android:name="" android:screenOrientation="landscape">
    
Sign In or Register to comment.