Coder Social home page Coder Social logo

aron-bordin / android-with-arduino-bluetooth Goto Github PK

View Code? Open in Web Editor NEW
73.0 20.0 77.0 176 KB

Arduino and Android classes to easily connect your mobile device with an Arduino board

License: GNU General Public License v2.0

Java 79.20% Processing 2.42% Arduino 2.48% C++ 15.90%

android-with-arduino-bluetooth's Introduction

Android with Arduino - Bluetooth

Arduino and Android classes to easily connect your mobile device with an Arduino board. With the example bellow, we can send a message to Android using Arduino. Read more here: http://bytedebugger.wordpress.com/2014/06/27/tutorial-how-to-connect-an-android-device-with-arduino-and-bluetooth/

I had tested this lib with BC417 module, but I believe that this class works with major part of modules, because all of them use the same protocol. If you test other module, working or not, please, just start a new issue here to help me. If you have any problem, start an issue here too that I will try to help you.

Android Example (Using Processing)

	import com.aronbordin.*;

	/*make sure to use the same name of the robot. 
	And check if it's paired with your device */
	BluetoothArduino mBlue = BluetoothArduino.getInstance("ExampleRobot");

	void setup(){
	  mBlue.Connect();  
	  textSize(30);
	}

	void draw(){
	  background(0);
	  String msg = mBlue.getLastMessage();
	  text(msg, 100, 100);  
	  
	}

Arduino Example

	#include <SoftwareSerial.h>
	#include "bluetooth.h"

	Bluetooth *blue = new Bluetooth("ExampleRobot");


	void setup(){
		Serial.begin(9600);
		blue->setupBluetooth();	
	}


	void loop(){
		String msg = blue->Read();
		if(msg.length() > 1){
			Serial.print("Received: ");
			Serial.println(msg);
		}
		if(Serial.available()){

			blue->Send("Example message#");
		}
	}

Arduino class reference

int getrxPin(); Get the RX Pin

void setrxPin(int rx); Set the RX Pin

int gettxPin(); Get the TX Pin

void settxPin(int tx); Set the TX Pin

void setupBluetooth(); Run it on setup(). It will configure all bluetooth prefenreces for you. After run it, you cannot change any settings of your bluetooth, like pin, or name

Bluetooth(char name[]); Create a Bluetooth object with the name

Bluetooth(char name[], int r, int t); Create a Bluetooth object with the name and pins

String Read(); Read char by char the data receive

void Send(char c[]); Send a string to any connected deive

*char getName(); Get the device name

void setName(char c[]); Set the device name

Android class reference

Important! This class will read char by char until get the delimiter char(a char that represents the end of the string). By default is '#', but you can chage it with setDelimiter(char d);

BluetoothArduino getInstance(String n); Get/Create a Bluetooth instance with the robot name. The name provided will be used in the connection

boolean isBluetoothEnabled(); Check if the device bluetooth is enabled

boolean Connect(); Connect to the Arduino board.

boolean hasMensagem(int i); Check if had already received a message

String getMenssage(int i); Get the Message by ID

void clearMessages(); Clear all messages

int countMessages(); Count messages

String getLastMessage(); Get the last message received

void SendMessage(String msg); Send a message to the Arduino

char getDelimiter(); Get the end message character

void setDelimiter(char d); Set the end message character

android-with-arduino-bluetooth's People

Contributors

aron-bordin avatar laurens-wuyts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-with-arduino-bluetooth's Issues

BC417 Module?

I can't find BC417 Module for sale on Amazon. Can you direct me to a place I can buy it. I would like to contribute to your repo.

Error in UUID

hi i tried your library, but i get this error when i call Connect() method

[#]Error while conecting: Attempt to invoke virtual method 'android.bluetooth.BluetoothSocket android.bluetooth.BluetoothDevice.createRfcommSocketToServiceRecord(java.util.UUID)' on a null object reference

serialEvent

It will be a good addition to implement serialEvent function of the SoftwareSerial class to use the advantage of separating the serial events from the loop function.

Message Not sending and Receiving

Hi,
Your android code not working even not sending messages or receiving.
What I did here???
I upload your arduino code in my arduino nano board. Then develop arduino app for simply connect and send message using your code. But no luck.
How I know???
I try S2 terminal App It's working. Your arduino code well responding with S2 terminal.
Problem:
Device is connecting well with arduino but not sending & Receiving msg even not throwing any exception.
Here is my activity...

    public class MainActivity extends Activity {
BluetoothArduino mBlue ;
 @Override 
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mBlue = BluetoothArduino.getInstance(this,"Arduino");
    mBlue.Connect();
    Toast.makeText(this,mBlue.getLastMessage(),Toast.LENGTH_SHORT).show();
     Button b=(Button)findViewById(R.id.buttonOn);
     Button c=(Button)findViewById(R.id.buttonSearch);
     b.setOnClickListener(new OnClickListener(){

             @Override
             public void onClick(View p1)
             {

                 mBlue.SendMessage("Hi from Android!");
             }


     });
     c.setOnClickListener(new OnClickListener(){

             @Override
             public void onClick(View p1)
             {
                 Toast.makeText(getApplicationContext(),mBlue.getLastMessage(),Toast.LENGTH_SHORT).show();

             }


         });
 }



}

Calling of Function!

Function "run", beginning at line 111 in BluetoothArduino.java program file, has never been called during the execution. Due to which no message received or delivered in the app.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.