Go Down

Topic: Connect Arduino with Bluetooth JY-MCU and Andoid (Read 2 times) previous topic - next topic

NickPyner

Interesting, but I can't see any point in that. I will try to find out more, but there is nothing to suggest a universal result.

Chipakias


Hello , I am using my nextus 7 tablet and both blueterm and bluetooth spp both work. I have included my sw below that will show what you send on a lcd so you can see what you do send ....

Code: [Select]
Quote



#include <SoftwareSerial.h>

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

SoftwareSerial mySerial(3, 2); // RX, TX
#define text
#define text=myserial

void setup() 
{
  
   // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);//added
 // Open serial communications and wait for port to open:
  Serial.begin(115200);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  mySerial.begin(115200);
  mySerial.println("test comms");
  delay(500);
}

void loop()
{

  if (Serial.available())
  delay(100);
    mySerial.write(Serial.read());
    delay(500);
    lcd.clear();
     if (mySerial.available())
    lcd.write(mySerial.read());
       }
  







Peter1929 thank you very much ! I have not yet tested your code but I think that it is the same as a code that I found and worked for me.
Here it is :

char val;
int ledpin = 8;
#include <SoftwareSerial.h>
#define BT_SERIAL_TX_DIO 10
#define BT_SERIAL_RX_DIO 11
SoftwareSerial BluetoothSerial(BT_SERIAL_TX_DIO, BT_SERIAL_RX_DIO);
void setup(){
   pinMode(ledpin, OUTPUT);
  Serial.begin(9600);
  BluetoothSerial.begin(9600);
}

void loop() {
  if(BluetoothSerial.available()){ 
    val = BluetoothSerial.read();}
  if( val == 'H' ){
    digitalWrite(ledpin, HIGH);} 
else {
   digitalWrite(ledpin, LOW);}
  }

However I would like to ask you some thing else. As you can see at the code I gave it
the ability when receives a character to execute a command (at this case to power a led).
The problem I have is that when I change the text from 'H' to 'HA' , this does not work.
Why this happens and what can I do to make it work ?

Chipakias

Does anyone know why when I change the text from 'H' to 'HA' , the code does not work.
Why this happens and what can I do to make it work ?

char val;
int ledpin = 8;
#include <SoftwareSerial.h>
#define BT_SERIAL_TX_DIO 10
#define BT_SERIAL_RX_DIO 11
SoftwareSerial BluetoothSerial(BT_SERIAL_TX_DIO, BT_SERIAL_RX_DIO);
void setup(){
   pinMode(ledpin, OUTPUT);
  Serial.begin(9600);
  BluetoothSerial.begin(9600);
}

void loop() {
  if(BluetoothSerial.available()){ 
    val = BluetoothSerial.read();}
  if( val == 'H' ){
    digitalWrite(ledpin, HIGH);} 
else {
   digitalWrite(ledpin, LOW);}
  }


PaulS

Quote
Does anyone know why when I change the text from 'H' to 'HA' , the code does not work.

Yes. You are reading one character from the bluetooth device. Which ONE key did you press to get 'HA'?

Hmmm, that's what I thought.

How to deal with serial data only comes up about 10 times a day here. You need to do some investigation on your own.

Chipakias


Quote
Does anyone know why when I change the text from 'H' to 'HA' , the code does not work.

Yes. You are reading one character from the bluetooth device. Which ONE key did you press to get 'HA'?

Hmmm, that's what I thought.

How to deal with serial data only comes up about 10 times a day here. You need to do some investigation on your own.


Thank you for your response.
I know that serial data is very common question but I did not find anywhere something
that answers at this certain question.
When you say that I am reading one character from the bluetooth device, you mean that I read one character because I am writing ==>   char val;                   
                                     and         if( val == 'H' ){   
 
or that generally we can read only one character each time from bluetooth ?



Go Up