#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // 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(9600);
mySerial.println("Hello, world?");
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
But when I connect to the module and try to send data, nothing appears on the serial monitor. I hooked up the bluetooth module by connecting its RX to the arduino micro's TX_pin(pin 0) and connecting the bluetooth modules TX pin to the arduino micro's RX pin (pin 1)
I don't know about Micros but I assume that they have hardware serial on pins 0,1, so there is no more need to use software serial on the micro than there is on the UNO. I suspect the problem is that you are calling for software serial on the hardware serial pins. If you really need to use software serial, and I bet you don't, use some other pins for it.
I can't explain why your original attempt failed, it was probably something stupid that only happens once, but I believe that what works on Uno works on Micro - until perhaps you run out of memory, which isn't likely.
Yes this is exactly what I did with the Arduino micro and no results. I have an app on my phone which I can send numbers to on my Arduino Uno, but with the micro it does not work. Nothing shows up on the serial monitor, but I can connect to the bluetooth module fine.
As I test it, it is connected to my computer. And just to be sure we are on the same page, we are talking about this arduino micro : http://arduino.cc/en/Main/arduinoBoardMicro, correct?
OK. As I said, I'm not familiar with the Micro, but it appears to be just a stripped down Uno, running on 5v and using the same pins, and surely the same software. You obviously know how to connect it up, so I thought it might be some silly power problem.
Using h/w serial pins 0,1 you should be able to watch proceedings on the PC serial monitor while you do the deeds on your Android device, but only watch. You cannot send from the serial monitor.
I thought it would be that simple as well. I have a simple android app which sends numbers to through bluetooth. It works fine on the arduino uno, but when I try it on the arduino micro, no dice..idk what to do
Here are all of the things I can think of that might help solve your problem.
You don't need to use SoftwareSerial; you can use the Serial1 class to communicate using D0 and D1 on the Micro. (No additional libraries necessary.) The Serial class will not communicate through the D0 and D1 pins on the Micro. I don't know what happens if you use SoftwareSerial on Micro pins D0 and D1, as in your sketch. Using SoftwareSerial on other pins should be OK (but probably unnecessary).
The Micro is not a "stripped down Uno," it's essentially a miniaturized Leonardo. On the Leonardo/Micro, TTL hardware serial on D0 and D1 are accessed by the Serial1 class, and are separate from the virtualized serial port used to communicate over the USB connection using the Serial class. (On the Uno, the D0 and D1 pins are connected to the same port as the USB serial communications, using the Serial class.)
Thus, to communicate with a BT module using the D0 and D1 (RX and TX) pins on the Micro, you'll need to initialize with
Serial1.begin(9600);
(assuming your BT module is communicating at 9600 baud), and read from the BT module with
Serial1.read();
just as you would use Serial.read() to read from the serial port on an Uno. However, if you wish to use the Arduino IDE serial monitor to see what the Micro is receiving from the BT module, you will need to repeat the received data from Serial1 to Serial (instead of from SoftwareSerial to Serial), e.g.
if(Serial1.available)Serial.write(Serial1.read()); // writing to Serial what is read from Serial1.
Make sure you know for sure what baud rate your BT module is set to and match it with the Arduino code. Also make sure that your BT module is not in AT mode.
If you are using one of the cheap JY-MCU HC-06 BT modules, you may need to pull up the Micro's RX pin due to an undocumented change in the BT module hardware. See http://forum.arduino.cc/index.php?topic=313378.0. This tripped me up for days.
Also, watch out for level-shifting if it is needed for your BT module. You should be able to read 3.3 V output without shifting, but writing to a 3.3 V device with the Micro's 5V pins could damage the device.
One other thought: do you know in what format your android app is sending the BT data? Characters? Bytes? What is the encoding? (If you are using AppInventor2 to create your Android app, you are most likely sending character strings in UTF-8 encoding, which should be easily read by your BT module.)
Finally, you might want to set your Serial baud rate (communication with your PC over USB) to the same baud as your BT module, just to avoid problems that might arise from buffers being filled or read too quickly.
Would you mind posting your code for getting this Bluetooth module to work with the Arduino Uno? I've been having some trouble getting mine to pair with a phone.
I would continue to use software serial to talk to the BT module (but use different pins. 2 and 3 for example) and use the hardware serial for debugging.
This may be a liitle basic for you but take a look at Arduino and HC-06 (ZS-040). It should get you working.