8

I have a Sparkfun Arduino Pro Micro with an ATmega32u4 on it and a Roving Networks RN32 Bluetooth Module

Theoretically, I should be able to solder the Rx of the Bluetooth to the Tx on the arduino and vice versa and I should get serial communication over the Bluetooth.

Of course, I do not. However, as a first question: How do I get my Arduino to transmit data over the Tx pin?

I uploaded this to the Arduino with no hiccups:

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

void loop(){
  Serial.print("HelloWurld");
}

However, when I plug up my o-scope, I see no signal over the Tx line. Nada. I see data coming over the USB into the COM port on my computer, but nothing over the Tx pin.

How do I get the Arduino to put out serial data on the Tx pin?

10
  • Do you have it powered?
    – TheDoctor
    Commented May 8, 2014 at 22:28
  • And is the ground on the scope connected to the Arduino's ground?
    – TheDoctor
    Commented May 8, 2014 at 22:28
  • Yes, it has the +5v in and the scope is on the arduino's gnd pin. How do I push serial data over the TX (digital0) pin? I know it's a code issue Commented May 8, 2014 at 22:57
  • Your code seems fine
    – TheDoctor
    Commented May 8, 2014 at 23:05
  • 1
    Have you tried pin 1?
    – TheDoctor
    Commented May 8, 2014 at 23:22

5 Answers 5

19

You appear to have a "pro micro" style board in which the USB communication is directly sourced from the main ATmega32u4 processor, rather than generated as serial data and then forwarded to a distinct USB-serial converter as on traditional Arduinos. Your question could have been resolved much more quickly if you had clearly stated the type of board you were using in words, rather than only as a product link (so I edited that into your question).

According to the documentation for the official Arduino Pro Micro:

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.

Therefore to generate output on the hardware UART you will need to change all occurrences of Serial to Serial1

void setup(){ 
    Serial1.begin(9600);
}

void loop(){
    Serial1.print("HelloWurld");
}

The transmit data will be sourced from ATmega32u4 pin 21 which is "D1" (digital pin 1) on the headers. If you wish to probe it, that would be the best place to do so.

If you wish to transmit data out of a different pin which is not connectied to the ATmega32u4's UART (as your example with digital pin 5 hints you might) you must instead use SoftwareSerial or similar implementation to bit-bang the serial data out of a general purpose I/O pin.

For example (inspired by this example):

SoftwareSerial mySerial(4, 5); // RX, TX

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

void loop(){
    mySerial.print("HelloWurld");
}
2
  • Well spotted, Chris! +1
    – Ricardo
    Commented May 12, 2014 at 23:20
  • oh my days... as an arduino noob this distinction between ATmeta32u4 and ATmega328 is mind bending... took me three days to figure out... fact that I was trying same code on ATmega328 code on the 32u4 didn't help. A million thanks Chris Stratton.
    – sumitkm
    Commented Oct 27, 2020 at 19:53
5

The bluetooth board uses 3.3V, not 5V according the datasheet.

So you'll need to shift the voltage level between it and the Arduino board (which is 5V). Note that the spec sheet shows how this can easily be done with 2 resistors (R1 and R2 in sheet typical application circuit, page 5).

Also, on the bluetooth module, the RS232 interface has 4 pins:

  • UART_TX
  • UART_RX
  • UART_CTS
  • UART_RTS

UART_CTS must be 0 to ensure the device reads incoming bytes. Normally this is done by an internal pulldown resistor, but you must ensure you did not connect that pin to +V.

Finally, ensure that the baud rate of the module is properly set to 9600 bauds, the same as in your program.

1
  • I am aware of all this, thank you still the same. However, my issue is much more basic. I need to get data out of the TX pin so that I can hook the bluetooth into that. If I can't get data out of a pin on the Arduino board, the bluetooth is useless. How do I get serial data out of the arduino board? The USB pins are sending out serial data just fine, but I cannot get other pins to output data. Do I need to solder to the USB pins in order to get data into the Bluetooth? Thank you very much for any help, I do appreciate it a ton Commented May 9, 2014 at 19:12
4

So I stumbled upon this thread while having similar problem, but with HC-05 module. So because I have too much free time on my hands during finals (no I don't) I decided to create a small github repo that might help someone sometime. https://github.com/Sackhorn/HC-05-Pro-Micro-Hookup

The code is:

//Writen for pro micro
//These proved to be usefull 
//http://arduino.stackexchange.com/questions/1471/arduino-pro-micro-get-data-out-of-tx-pin
//https://forum.sparkfun.com/viewtopic.php?f=32&t=38889&sid=8178cdb38005ff33cc380a5da34fb583&start=15

void setup()
{
  pinMode(9, OUTPUT);  
  digitalWrite(9, HIGH); 
  Serial.begin(9600);
  Serial1.begin(38400);
}

void loop()
{

  //Serial1 is the physical Serial Connections on TX and RX pins
  if (Serial1.available()) Serial.write(Serial1.read());

  // Serial is from my understanding the virtual connection with computer via USB 
  if (Serial.available()) Serial1.write(Serial.read());
}

enter image description here

1
  • 1
    Nice use of Serial and Serial1. I posted an edit with your code and diagram.
    – Dave X
    Commented Mar 5, 2016 at 2:13
3

Just hook up the serial pins from the bluetooth module to the corresponding Pro Micro pins: TX to RX and RX to TX. I hope this can help someone.

Then look for data like this:

void setup(){ 
   Serial1.begin(9600); // Init Hardware Serial port on pins 0 and 1 - Bluetooth
   Serial.begin(9600); // Init Virtual Serial Port - Machine

   Keyboard.begin(); // Init HID - Keyboard
}

void loop(){
   if (Serial1.available() > 0) {

     char myData = Serial1.read()

     // Send data from Bluetooth/Sensor to the Machine - Virtual Serial Port 
     Serial.println(myData); 

     // Emulate HID Device - Keyboard
     if ( myData == 0x7F ) { // Detect code of android backspace key         
        Keyboard.write(0xB2); //  Convert received code char to PC/Linux ascii keycode for the backspace key. This can change between different OS!      
     }

     else {
        Keyboard.write(myData); 
     }

   }
}
1

You also may want to try the "SoftwareSerial" library. That way you can use almost any pins you want for serial comms. As a matter of fact, you can have a couple of serial ports.

Please do read up on the SoftwareSerial library though. It does have some restrictions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.