Tenho um HC06 para comunicação bluetooth, porem o mesmo não printa nada na porta serial e isso esta me dando dor de cabeça pois preciso ler valores no pc pelo bluetooth para um trabalho academico.
Usei um exemplo da internet para ver se o problema era meu módulo ou algum erro de comunicação.
//Include the SoftwareSerial library
#include "SoftwareSerial.h"
//Create a new software serial
SoftwareSerial bluetooth(2, 3); // TX, RX (Bluetooth)
const int ledPin = 8; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
//Initialize the software serial
bluetooth.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (bluetooth.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = bluetooth.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
bluetooth.println("LED: ON");
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
bluetooth.println("LED: OFF");
}
}
}
usando esse código eu consigo controlar o led, porem nenhum print é feito na porta serial
alguem faz ideia do que acontece?
TiagoGuerino:
Tenho um HC06 para comunicação bluetooth, porem o mesmo não printa nada na porta serial e isso esta me dando dor de cabeça pois preciso ler valores no pc pelo bluetooth para um trabalho academico.
Usei um exemplo da internet para ver se o problema era meu módulo ou algum erro de comunicação.
//Include the SoftwareSerial library
#include "SoftwareSerial.h"
//Create a new software serial
SoftwareSerial bluetooth(2, 3); // TX, RX (Bluetooth)
const int ledPin = 8; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
//Initialize the software serial
bluetooth.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (bluetooth.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = bluetooth.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
bluetooth.println("LED: ON");
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
bluetooth.println("LED: OFF");
}
}
}
usando esse código eu consigo controlar o led, porem nenhum print é feito na porta serial
alguem faz ideia do que acontece?
Olá. Poste o esquemático elétrico
Olha amigo nem todos os pinos funcionam para comunicação serial, por favor verifique esse detalhe, se for o uno Rev 3 tente o 10,11 que sei que funciona.
Depois veja o programa bluetooth, se foi pelo Android eu uso esse https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=pt-BR , ele é chato de conector mas é simples de usar