Im trying to get readings from my bluetooth adapter (HC06) on my Arduino Micro.
ive got a very simple code but im only getting "-1" om my serial monitor. does someone has a clue why this is happening?
#include <SoftwareSerial.h>
int bluetoothTx = 7;
int bluetoothRx = 8;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(9600);
}
void loop()
{
Serial.println(bluetooth.read());
}
if I send a 1bytenumber with my android app (appinventor2.0) it works great. ill get a number from 0-255 (more won't fit in a single byte so thats an issue).
but when i try to send it as a 2bytenumber, 4bytenumber or text I get 3 lines on my serial monitor instead of one single line with one number.
for example:
3
7
6
what I want:
376
does anybody know why this is happening and how i can fix it?
Thnaks in advance
Tymen
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(19200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(13, OUTPUT);
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() //
{
while(mySerial.available()){
delay(10);
char text = mySerial.read();
Serial.println(text);
}
@ Paul : I also found out that Serial only take 1 byte at a time. so that why its acting so wierd on 2/4/text.
so i figured i need to use the buffer, but i havent figured out how. first time im using this function.
@Whandall: each time i want to upload a new code i have to unplug and plug the BT module. its a pain... so im using the software serial instead.
meanduck: @Whandall: each time i want to upload a new code i have to unplug and plug the BT module. its a pain... so im using the software serial instead.
You don't have to do that on a Micro, it has a seperate hardware Serial.
Serial goes to upload and USB,
Serial1 goes to the free rx and tx pins.
In addition, some pins have specialized functions:
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data using the ATmega32U4 hardware serial capability. Note that on the Micro, the Serial class refers to USB (CDC) communication; for TTL serial on pins 0 and 1, use the Serial1 class.
buffering your serial input so i cant get multiple bytes of data in to one var. I keep getting multiple lines for one push of data. and i do not know how to get this in to one variable.