Configure Bluetooth HC - 05 with Arduino Mega 2560 - android

i cannot understand, when i trying to configure and connect bluetooth with my android device.
(i used bluetooth HC-05 from lc-technology and Arduino Mega 2560)
I’m trying to connect the arduino and android with bluetooth but it failed.
This is a code for arduino
char incomingByte;
int LED = 12;
void setup (){
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop(){
if (Serial.available()){
incomingByte = Serial.read();
if(incomingByte == '1'){
digitalWrite(LED, LOW);
}
if(incomingByte == '0'){
digitalWrite(LED, HIGH);
}
}
}
I try to send data from bluetooth device (i use Bluetooth Terminal and BlueTerm) to Bluetooth Arduino and never give a response
i've been trying to uses another pin for tx & rx on Arduino Mega 2560, but it never give a response.
Does someone have a solution on that problem ?
Thanks before for your help. I'll apreciate you for your help.

The software you provided is working.
I had exactly the same problem as you reported, with Arduino Uno and the Bluetooth module from the same maker.
After many test I came to the following conclusion: the problem is in the Bluetooth module itself cause it doesn't properly manage the tension levels of the TX pin. You don't see any response cause Arduino can not handle the tension levels from the bluetooth module.
You find more informations about my tests at the following link:
Arduino Forum
A picture of the tension levels of an HC-05 Bluetooth device Tx pin (from 3.1 down to 0 Volt)
In the next picture the tension levels of the HC-05 Bluetooth device Tx pin of the maker you and me have used (from 3.3 down to 1.7 Volt), note that the signal can't go down to 0 Volt

Check the following things:
If you are trying to light up external LED at pin 12 then it is OK.
But in case you are trying to light up the on-board LED, it is pin 13.
Check the baud rate you are using in the device to send data.
It must be same as the one used in the code.
The HC-05 can operate in a wide range of baud rate (check Google).
By default it's programmed to 9600.
If somehow yours is different, you'll have to reprogram it (again check Google to see how).
It's irrelevant to say this but 1 represents logic HIGH and 0 represents logic LOW.
Although it's up to you to program the way you want, but still it's best to follow the convention to avoid confusion.

Related

Arduino Sends Junk value to Android App (App Inventor 2) via Bluetooth

I just used an arduino code to send text data to an android application which I made in app inventor. I used Bluetooth module HC-05 for connectivity.It almost works but instead of sending few characters, it sends junk data. Here's the arduino code:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("h");
delay(500);
Serial.println("s");
delay(500);
Serial.println("o");
delay(500);
}
And here's the App blocks and Design:
And here's the screenshot when I ran the app:
I click "Show" and I get these random junk data. And the next time I click show, I don't get any data at all. Can anybody explain how to solve this ?
For Junk values, Try to change the baud rate!
I think you are sending a data from BT device to android device only one time. try running the code continuously in arduino device.
while(1){
loop();
}
Check if you connected BT module to USART0 (RX0, TX0) port
try change baud rate, usually HC05 has 9600, but it may have also 19200 and sometimes 115200.
note, that HC05 has 3.3V, and almost all Arduino boards are 5V. So you need to use level shifters. Else specify what board and module you use

Is it possible to use an Arduino accelerometer to rotate an Android screen?

I have installed Android 4.2.2 on a ARM board, Orange Pi (A20). I have also an accelerometer based on Arduino Nano (ATMega328) to communicate with the system, via serial USB (UART).
Is a chance exist (with some work!) to make this accelerometer active to rotate the screen, and better, to play with ?
I managed to receive some datas.
1) Build cp210x.ko in the kernel, and insmod it in Android
2) With the Arduino application on Ubuntu, I have programed the chip with the example "MPU6050_raw" (from here) and adding a delay (and incidentally a sensor value)
If the delay is not set, the Orange freeze. It's the begining of my tests..
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(2000); // delay in between reads for stability
}
3) On Android, with the app SerialPort_1.1.apk, set the device /dev/ttyUSB0 and the baudrate to 38400.
Here is the result:
This is a start, now I think the most difficult will be to create my app to treat theses datas...

Is there anyway I can send SERIAL-USB data thru a HDMI port?

I have been working on a project where our Android tablet has only 1 microUSB port.
Since we must communicate via serialUSB with an external device, it became a little fuzzy after we noticed that leaving the tablet powering the bus (Host Mode) drains it`s battery till death. Moreover, we still must supply enough energy to power the tablet.
After a lot of attempted fails, such as using a OTG-Y cable, modifying Kernel Battery Config and using a USB Hub, I need to discover a way to perform the communication and keep the tablet charging.
Thought about using the HDMI or even the audio/serial. Is there any solution I can look forward to solve this?
At this point, I'm getting out of ideas.
You can use an arduino, but not a normal one, you'll need a mega, i say this because the ardiono mega is the only arduino i know of with more than one serial UART. The Uno for example shares the RX/TX serial pins with the same UART as the USB interface.
If you DO have a mega, you can get a cheap USB to Serial module such as this: http://www.ebay.com/sch/i.html?_from=R40&_sacat=0&_nkw=arduino+usb+to+serial&_sop=15
Now, you plug your PC into the mega's normal USB This will power the Mega from your PC.
Then you connect your tablet to the serial module.
All that's left to do is create a simple ino script for your mega to transfer data from serial (pc-USB) to serial2 (Tablet), and vice versa..
Example:
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // PC <--> USB
Serial1.begin(115200); // Serial <--> Tablet
}
void loop() {
// put your main code here, to run repeatedly:
serialComs(); // Tells loop to execute the serialComs() function
}
// Serial Comunication function
void serialComs() {
// read from port 1 (Tablet), send to port 0 (PC):
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0 (PC), send to port 1 (Tablet):
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
NOTE: You may need to add #DEFINE entries before void setup to define which pins are which on your serial to USB module.
I think your way througt the HDMI will not work. And you have only one other option:
You could also load your battery directly. You could open the case and power your tabled instead your battery. This should also work. I think ther is no other way.
Also you could try a OTG hub: http://www.miniinthebox.com/de/3-in-1-micro-usb-otg-host-adapter-kabel-hub-fuer-samsung-smartphone-tablet-n9000_p1996674.html?currency=EUR&litb_from=paid_adwords_shopping&litb_from=&adword_mt=&adword_ct=73333307802&adword_kw=&adword_pos=1o1&adword_pl=&adword_net=g&adword_tar=&adw_src_id=4196617767_313342362_22461529362_kwd-140182704282&gclid=CJqW-Na8zMcCFc8aGwodznEIZA
But not all tables allow charging and using USB at the same time.

Android Bluetooth Low Energy Motorola API pairing

I am working on using the BT 4.0 API that Motorola has provided with the RAZR. In one of their documents it states to use the Android API to pair before connecting and using their framework. Per their instructions I have been pairing with OS Bluetooth settings application, but it never prompts me for a key. It will pair but doesn't appear to bond, and this is critical for me.
My question is, when they say "using the Android API" is this referring to simply using the OS Bluetooth utility to pair before hand (like I have been doing), or is there some way to do it with code in my application. They reference the "createBond()" function which, to my knowledge, is not an accessible function (at least not without some squirrely libraries or reflection).
Any advice is greatly appreciated, especially anyone who has used the API successfully, if they could give an account of their process. I'm just looking for some clarity at this point :)
Lloyd,
You are correct, follow the instructions in the link you posted.
Outside of coding, when they say use the standard android api for "non-le" operations, they mean go ahead and pair the ble device the same way you would any bluetooth classic devices inside android settings -> wireless & network -> bluetooth -> scan for devices.
If the device you are using is a motorola le compatible device the ble device will be paired but not connected.
Now, in the code, you can detect this paired device through the same method of
BluetoothAdapter.getDefaultAdapter().getBondedDevices()
To double check if your Android Phone is LE compatible, run this code:
public static boolean checkBLESupport() {
boolean deviceSupportsLE;
try {
#SuppressWarnings({ "unused", "rawtypes" })
Class object = Class.forName("android.server.BluetoothGattService");
deviceSupportsLE = true;
} catch (Exception e) {
deviceSupportsLE = false;
}
return deviceSupportsLE;
}
And to double check if the bluetooth device you paired is LE, when you are looping through the bonded devices.
Check the device with this code.
if (device.getBluetoothClass() == null) {
Log.i(TAG, "This device is BLE compatible");
b = true;
} else {
Log.i(TAG, "This device is not BLE");
b = false;
}
Now for establishing connection from your LE compatible phone to your LE compatible bluetooth device, follow the Gatt service instructions under the link you posted. http://developer.motorola.com/docs/bluetooth-low-energy-api/
Take note that under this example it is connecting to a bluetooth low energy heart rate monitor.
If you are not trying to connect to the heart rate monitor with LE heart rate profile, here is a link to another Motorola document that details creating your own LE Profile to use with the GATT framework. http://developer.motorola.com/docs/bluetooth-low-energy-gatt-framework-api/
If the instructions are not clear enough at any point in either of these documents, motorola offers sample android applications using the frameworks in those documents.
I guess motorola stack has BLE support. But what i feel is that it does not pair with the devices that require bonding though It does work some sensors. I have tried with a proximity sensor that require bonding. It never gets paired though the devices is discovered with Razr which even does not with S3.
There's a helpful video here.
Late to the game, but can confirm -
If your BLE Peripheral requires bonding, Moto X - and some other older Motorola devices - MUST be paired via Bluetooth Settings prior to programmatic connection via the Android GATT interface.
If you bond via the createBond method, or reading of an encrypted characteristic, your connection will be dropped typically in under 60 seconds, despite DDMS logs that show a good bond may be established.

ADK blink tutorial: on board LED is always on

I have a Duemilanove and ADK and I followed this and with the exception of some SDK updates, I followed it exactly.
Problem: the onboard LED doesn't blink but is always on.
Issues:
byte array is being successfully sent to the ADK from the phone, verified by monitoring serial port of arduino board
High & low signal is being properly handled in the arduino code (same verification).
the blink tutorial without the ADK blinks the on board LED properly.
So, what is wrong? Is it possible that the ADK board is always sending a HIGH signal to the on board LED and I need to use an 'external' LED for testing? A lot of the tutorials I've seen do this so could that be why?
Try to write a small blink program, just to check that everything is alright in your ADK board.
The onboard Arduino LED is on initially. It looks like it is never being turned off.
In the linked instructions, under the section How To Receive Data From The Android Device , the first line of the loop() function is:
byte msg[0];
Then to receieve data in the call to AndroidAccessory.read() the value sizeof(msg) is used to determine how many bytes to read.
However, because msg was defined to be 0 bytes long, no bytes will be read, len will be zero and the LED will not be updated.
Instead, try changing the line to:
byte msg[1];
I haven't used the shield you are using but it looks like it uses SPI for communication. SPI uses pin 13 for the serial clock signal (SCK). Given this I would expect the SCK signal may be interfering with you trying to control the LED.
I would suggest trying to wire an LED to a different digital pin such as pin 8 and update the Arduino sketch to use pin 8. This would remove the possibility of conflict.

Categories

Resources