Hardware Serial bluethooth requires especial configuration?

Hi to all…

Im trying to print the temperature of a Ds1820 probe on the serial port of my PC from a HC-05 conected to arduino.

To use this I was advice to try Hardware serial (Connecting Arduino TX to Rx from bluettoth and vice-versa, once the sketch was uploaded).

I use the diagram from here

I configure the module using this tutorial;
From Instructables

1.- The Ds1820 works properly and prints the temperature
2.- The along code also prints the temperature on LCD
3.- The Program runs and prints the temp in the LCD
4.- The HC-05 blinks, and is recognized as bluetooth device on Windows.
5.- Once paired the security code is register and enables two COM ports COM 10 and COM11
6.- Sublime text and Arduino Ide recognize the new ports and allow to pick one to star serial monitor
7.- The serial monitor starts but nothing appears on screen.

8.- The LCD keeps tracking the temperature as normal.

// Ds1820 to HC06.ino
/* 
Este programa tiene la intención de enviar datos de temperatua obtenidos
de una sonda DS1820 atravez de un modulo bluethooth mediante el puerto 
serial al PC. Y al mismo tiempo imprimir la temperatura en una LCD. 

Servira como vase para construir una herramienta de calibración de 
refrigeracion. 

*/

//--------------------------------LYBRARIES--------------------------------//
#include <OneWire.h>
#include <DallasTemperature.h>       //DS1820 LIB 

#include <Wire.h>
#include <LiquidCrystal_I2C.h>       //Libreria IC2 

#include <SoftwareSerial.h>


//------------------------------CONSTUCTORS -------------------------------//

#define ONE_WIRE_BUS 2               			//Pin for one wire bus 
OneWire oneWire(ONE_WIRE_BUS);       			//define bus for com protocol 
DallasTemperature sensors(&oneWire); 			//Pass our oneWire reference to DT
DeviceAddress ambient_sensor	;     			//arrays to hold device address

                                     //Constructor objeto LCD 
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

//SoftwareSerial BTSerial(10, 11); // RX | TX



//----------------------------HARDWARE PINS--------------------------------//



//----------------------------GLOBAL VARIABLES-----------------------------//
float ambient_temperature = 0; 
float past_ambient_temp = 0; 

char  buffer[10]; 
char  first_line [17]; 





//===============================VOID SETUP===============================//
void setup() {
lcd.begin(16,2); 
Serial.begin(9600); 
Serial.println("Starts program"); 
lcd.print("Starts program");


//-----------------------------------SENSOR DS1820-------------------------------------------------//
 sensors.begin();											// locate devices on the bus
 Serial.print(sensors.getDeviceCount(), DEC);				//Linea para debug 

 if (!sensors.getAddress(ambient_sensor, 0)) Serial.println("Unable to find address for Device 0"); 
 Serial.print("Device 0 Address: ");
 //Funcion para imprimir la direccion del dispositivo  --printAddress(ambient_sensor);
 // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
 
 sensors.setResolution(ambient_sensor, 10);

}


//================================VOID LOOP================================// 
void loop() {
	
	sensors.requestTemperatures(); 				// Comando para obtener temperatura de todos los sensores

	printTemperatures(ambient_sensor);			//obtiene la tem del sensor de ambiente  

	//Serial.println(ambient_temperature);
	//Serial.println(past_ambient_temp);

	if (ambient_temperature != past_ambient_temp){	
		
		dtostrf(ambient_temperature, 5, 2, buffer); //converts float to string  
		sprintf(first_line," %s C ", buffer ); 		//convert temp to a string 

		lcd.clear();
		lcd.print(first_line);
		Serial.println(first_line);
		past_ambient_temp = ambient_temperature;  		
		}

//else 	lcd.print("Problema");
}

void printTemperatures (DeviceAddress ambient_sensor){
 ambient_temperature = sensors.getTempC(ambient_sensor);
 //Serial.print(F("Temp C: "));
 //Serial.print(sensor_temp);
 }

Im powering the Arduino uno via Usb cable… I try a battery but don have a operative voltage.

Any idea why its not printing via usb?
I need to have special instructions?

Thanks in advance.
-Alex.

You cannot use hardware Serial to print to both the Serial monitor and the Bluetooth device. That is why you see nothing on the screen.

So.... Were I read the data?

I tougth the tx and Rx will send the instruction to blueethoth device instead of USB. The Bluetooth will send using its protocol and the dongle receive it. To be printed on screen.

Whath command will send the data to the BT? Inatead of serial.print?

Regards. -Alex

Whath command will send the data to the BT? Inatead of serial.print?

Consider using SoftSerial on 2 other pins to communicate with Bluetooth then you can use Serial to print to the Serial monitor.

Alternatively get a Mega or an Leonardo, both of which can use 2 serial ports

Pins 0 and 1 on an Uno or Mega are the Rx and Tx pins used to communicate with the PC over the USB connection. On a Leonardo pins 0 and 1 are separate from the USB communication.

If you are using an Uno you can use SoftwareSerial to create a second serial port for your HC05. If you have a Mega just use one of the other Hardware Serial ports.

...R

Oh I see... I will try the lib....

This means that I can't use the hardware serial on a uno as long there is a USB cable connected.

So I can test it with another power supply I guess.

Thanks a lot! Heli, Robin.

Alex.

So I can test it with another power supply I guess.

It is almost certain that it will still not work properly if you keep printing messages to Serial whether or not the USB is connected and, of course, if the Serial monitor is not there why print messages anyway ?

O I see.. In that case.... Whath is the appropriated command to print or send data over the HC05 to Bluetooth to the jab dongle?

Regards. Alex.

We are going round in circles. Your choices are

1 - use SoftSerial on pins other than 0 and 1 to communicate with the Bluetooth module 2 - use an Arduino with more than one serial port and dedicate one to communicate with the Bluetooth module 2 - use Serial to communicate with the Bluetooth module alone and do no other Serial input or output.

Thanks Heli...

The reason because Im using hardware serial, is because it was suggested to me in the forums, because Im trying of implementing a arduino to arduino com... and apparently soft serial is a headache.

In this sketch I think I was using the serial over the Bluetooth, but apparently the fact of he device is connected to the PC in interfering rigth?

Im not using any other serial input or output... The temperature is printed on LCD at changue... and I think the serial will send the data to the BT, but as you mentioned do not.

Pherhaps a ports conflict. I will try with the lib and come back with some results.

-Alex.

apparently soft serial is a headache.

Where did you read that ?

If you feel that you must use hardware Serial for Bluetooth then remove [u]all[/u] of the Serial.prints except those used by Bluetooth.

So I make another try...

Remove the Hc.05 and pair again... It says COM10... so I went to sublimetext>arduino>serial monitor

Change the baudrate, to the set... and the port to COM10... so I start the serial monitor

"Serial port COM10 already in use. Try quitting any programs that may be using it."

I upload the example of the library and the same results.

The example print on the COM1 regular serial monitor and uses the COM 10 to print from the other serial. But in my case dont do so.

Any toughs? -Alex.

I upload the example of the library and the same results.

Upload it here so we know what code you are talking about and explain what is connected to what pin.

This is the example provided with the library;

/*
  Software serial multple serial test
 
 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.
 
 The circuit: 
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)
 
 Note:
 Not all pins on the Mega and Mega 2560 support change interrupts, 
 so only the following can be used for RX: 
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
 
 Not all pins on the Leonardo support change interrupts, 
 so only the following can be used for RX: 
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
 
 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example
 
 This example code is in the public domain.
 
 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

The arduino pin 10RX is connected to Rx from BT
Arduino pin 11 is to BT

In all cases I siwithc the wires… Still the same problem;

“Serial port COM10 already in use. Try quitting any programs that may be using it.”

Regards.
-Alex.

I dont know... I need to configure the HC as master or slave? to force the conection?

Before appears a small rectagle saying; "one BT device is trying to connect"... But I guess it was for the code...

“Serial port COM10 already in use. Try quitting any programs that may be using it.”

That sounds like a Windows message, which is odd.

Try this. It should do nothing but I would be interested if you get the same message,

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
  mySerial.begin(9600);
  Serial.begin(9600);
}

void loop()
{
}

Hi bob... Log time but during the most of the weekend I cant advance this...

Now... I saw something odd

1.- The baudrate of the BT at the AT command is 9600 2.- The baudrate of the softserial is 4800

I try to upload my code with 9600baud rate and I cant pair the BT with windows...

Now I will try to set the same speed baud rate on the AT terminal and the softserial.

At the at mode; 9600,0,0 the first 0 means; ending bit 0 and the second 0 means even transmition, this is correct?

Thanks in advance.

well this is odd… I have configured the Bt as 4800 baudrate, and after modify the code to use the same speed on the softserial…

At config

Correct instaled.

Now it recognizes the BT, and pair it… Even let me select port COM10 and 11 in the serial monitor, dont show
the old error “port in use”… successfully open the both serial ports

But dont prints anything…

COM11

COM10

The code;

// Ds1820 to HC06.ino
/* 
Este programa tiene la intención de enviar datos de temperatua obtenidos
de una sonda DS1820 atravez de un modulo bluethooth mediante el puerto 
serial al PC. Y al mismo tiempo imprimir la temperatura en una LCD. 

Servira como vase para construir una herramienta de calibración de 
refrigeracion. 

*/

//--------------------------------LYBRARIES--------------------------------//
#include <OneWire.h>
#include <DallasTemperature.h>       //DS1820 LIB 

#include <Wire.h>
#include <LiquidCrystal_I2C.h>       //Libreria IC2 

#include <SoftwareSerial.h>



//------------------------------CONSTUCTORS -------------------------------//

#define ONE_WIRE_BUS 2               //Pin for one wire bus 
OneWire oneWire(ONE_WIRE_BUS);       //define bus for com protocol 
DallasTemperature sensors(&oneWire); //Pass our oneWire reference to DT
DeviceAddress ambient_sensor ;     //arrays to hold device address

                                     //Constructor objeto LCD 
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

SoftwareSerial BTSerial(10, 11); // RX | TX



//----------------------------HARDWARE PINS--------------------------------//



//----------------------------GLOBAL VARIABLES-----------------------------//
float ambient_temperature = 0; 
float past_ambient_temp = 0; 

char  buffer[10]; 
char  first_line [17]; 





//===============================VOID SETUP===============================//
void setup() {
lcd.begin(16,2); 
Serial.begin(9600); 
Serial.println("Starts program"); 
lcd.print("Starts program");

BTSerial.begin(4800); 


//-----------------------------------SENSOR DS1820-------------------------------------------------//
 sensors.begin(); // locate devices on the bus
 Serial.print(sensors.getDeviceCount(), DEC); //Linea para debug 

 if (!sensors.getAddress(ambient_sensor, 0)) Serial.println("Unable to find address for Device 0"); 
 Serial.print("Device 0 Address: ");
 //Funcion para imprimir la direccion del dispositivo  --printAddress(ambient_sensor);
 // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
 
 sensors.setResolution(ambient_sensor, 10);

}


//================================VOID LOOP================================// 
void loop() {
 
 sensors.requestTemperatures(); // Comando para obtener temperatura de todos los sensores

 printTemperatures(ambient_sensor); //obtiene la tem del sensor de ambiente  

 //Serial.println(ambient_temperature);
 //Serial.println(past_ambient_temp);

 if (ambient_temperature != past_ambient_temp){ 
 
 dtostrf(ambient_temperature, 5, 2, buffer); //converts float to string  
 sprintf(first_line," %s C ", buffer ); //convert temp to a string 

 lcd.clear();
 lcd.print(first_line);
 //Serial.println(first_line);
 BTSerial.println(first_line); 
 past_ambient_temp = ambient_temperature;   
 }


}

void printTemperatures (DeviceAddress ambient_sensor){
 ambient_temperature = sensors.getTempC(ambient_sensor);
 //Serial.print(F("Temp C: "));
 //Serial.print(sensor_temp);
 }

AlexLPD: The arduino pin 10RX is connected to Rx from BT

Connect Rx to Tx

Hi nick I must be tired and miss write… But in any chances I cahngues the wires, and nothing happens … so:

I found yet another port baudrate, under windows<bT< devices <advanced< port configuration

Like this

Shows me the baudtate at 9600…

So I went back to AT mode, I modify the code at 9600 and blueetoh baud rate also al 9600, to match all three… re install and pair the BT…

But I still got a white screen… nothing happens… I chek the loop to be running by holding the sensor and the value printed moves.

But nothing on the screen.

Any toughs?.
-Alex.