Note that there are some explanatory texts on larger screens.

plurals
  1. POReading Data form android on bluetooth module
    primarykey
    data
    text
    <p>I have been stuck on this for days. I have come up with a code to send bytes of data to my Bluetooth module. I don't get any errors, but I am not sure that the data is actually being sent. I have used an oscilloscope to check the RX and TX pins on the module, but I get nothing. Anyone know what is wrong? Here is my code:</p> <pre><code>import java.io.IOException; import java.io.OutputStream; import java.util.Set; import java.util.UUID; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class Modes extends Activity { Button gaming; Button graphics; Button sound; Button text; BluetoothDevice mmDevice; BluetoothSocket mmSocket; OutputStream mmOutputStream; BluetoothAdapter mBluetoothAdapter; byte val; private final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.modes); setUp(); gaming.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { System.out.println("gkghfgh"); val = 0; try{ connect(); senData(); }catch(IOException ex){} } }); graphics.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { val = 1; try{ connect(); senData(); }catch(IOException ex){} } }); sound.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { val = 8; try{ connect(); senData(); }catch(IOException ex){} } }); text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { val = 9; try{ connect(); senData(); }catch(IOException ex){} startActivity(new Intent(Modes.this,Text.class)); } }); } private void setUp() { gaming = (Button) findViewById(R.id.button1); graphics = (Button) findViewById(R.id.button2); sound = (Button) findViewById(R.id.button3); text = (Button) findViewById(R.id.button4); gaming.setText("Gaming"); graphics.setText("Graphics"); sound.setText("Sound"); text.setText("Text"); } void connect() throws IOException{ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Set&lt;BluetoothDevice&gt; pairedDevices = mBluetoothAdapter.getBondedDevices(); if(pairedDevices.size() &gt; 0) { for(BluetoothDevice device : pairedDevices) { if(device.getName().equals("RN42-58C1")) { mmDevice = device; break; } } } mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid); mmSocket.connect(); } void senData() throws IOException{ mmOutputStream.write(val); System.out.println("Data Sent"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload