0

I've recently acquired a Bluetooth module to attach to my Arduino Uno, but I'm trying to draw parallels to the standard method of communication that I'm familiar with, which seems to be just directly reading or writing to sensors through methods like digitalRead and digitalWrite, respectively. Additionally however, it seems like it's also possible to connect to a serial console, through the Serial class. These make sense, and I've used both individually (serial console viewed by the built-in Serial window in Arduino IDE, and serial write done through Serial.print/println()).

However, in the Bluetooth module I purchased (HW-10), there are pinouts that connect to the TX/RX ports, which I've currently left unconnected since I'm not using the Bluetooth module or any other serial module. My question is, once I connect these, does this completely replace the connection through USB that is currently used to interface with the Uno?

If so, I had a set of specific functionalities in mind for whether these would be "replaced" by connecting the module through the 4 pinouts (TX, RX, VCC, GND):

1. Serial: Can I write and access the serial monitor through the IDE by connecting to 9600 baud, both in code and in the Serial Monitor

2. Pins: Do these connections also allow me to write and read signals from all of the pins, including analog and digital

3. Sending code: Can I still send code through Bluetooth without needing a USB connection?

Apologies if this question seems really obvious or specific, I'm confused as I've read a bunch of wording saying that the Bluetooth module uses a "serial connection", when I only understood serial functionality as being a method of outputting text, not controlling the Arduino. Thanks in advance for help!

2
  • Typically you would want to use the BT module by connecting it to a separate UART. But since the UNO has only 1 UART you can't do this. You CAN use SoftwareSerial however, which lets you use make a software based UART on normal digital IO pins. Apparently it is possible to program over bluetooth though. create.arduino.cc/projecthub/mansurkamsur/…
    – tavis
    May 11 at 0:07
  • hmm, I don't actually know what a UART is; does this mean that I am unable to alter the state of pins? what about serial and sending code
    – Daneolog
    May 11 at 2:45
3

I don't actually know what a UART is

UART (Universal Asynchronous Receiver Transmitter) is the technical term for the communication interface, which is called Serial in Arduino speak. It's often called UART, because that is more precise, since there are many different communication protocols, which also work serially (meaning transferring data bits one after another in contrast to parallel, where multiple bits are transferred simultaneously), like I2C, SPI or USB. All serial protocols, but totally different from the Arduino Serial interface. Yes, this is a bit confusing. I guess the Arduino term Serial was coined to make the learning curve less steep for beginners (hiding complexity can also make things confusing unfortunately).

So UART is the same as the Arduino Serial interface.

once I connect these, does this completely replace the connection through USB that is currently used to interface with the Uno?

Here it is good to know, how the USB communication works on the Uno. The microcontroller on the Uno (Atmega328p) does not have a native USB interface. So it cannot speak to USB itself. For that there is an extra microcontroller on the board (I think an Atmega32u4). This controller has a native USB interface and it acts as a USB to Serial bridge (it creates a virtual serial interface on the PC and translate between that and its physical Serial/UART interface). The Atmega328p (which you program with your code) has it's RX and TX pins connected to the RX and TX pins on the Atmega32u4, which can then translate between the Serial/UART protocol and the USB protocol. Thus the Atmega328p doesn't know anything about USB. I just talks via Serial/UART to the Atmega32u4. In fact it also doesn't know anything about bluetooth. Most bluetooth modules for Arduino are also just bluetooth-Serial bridges

Now you need to know, that Serial/UART is made for one-to-one connections. With multiple devices you can get problems, when multiple devices try to send data at the same time. I this case (BT module RX to Arduino TX and vice versa) you would get garbled data, if you try to simultaneously send data from bluetooth and USB to the Arduino. The signals would overlap on the Arduinos RX pin, corrupting the data.

That means, that you don't want to send from both interfaces. In fact it is the easiest way to just use one Serial/UART interface for only one device. If you leave the Serial Monitor (or any other Serial communication program) closed on the PC, the PC will not interfere with the communication. Though you need to disconnect the bluetooth module, when you write your program to the Arduino, since this is done via Serial and you don't want it to meddle with the data.

So in result the bluetooth module will not "replace" the connection through USB. It will be added and it is your duty to prevent data corruption.

  1. Serial: Can I write and access the serial monitor through the IDE by connecting to 9600 baud, both in code and in the Serial Monitor

Yes. You don't need to use 9600 baud necessarily. The only requirement is, that you use the same baud number in both sketch and Serial Monitor. That number just represents the speed, that the data is send in. Both sender and receiver need to agree on the same communication speed, or the receiver will not be able to read the data. Imagine someone talking to you, but talking twice the speed with that you are able to understand the words. You will not be able to understand much, because the speaker is just too fast. Either you would need to change your hearing/understanding speed or the sender needs to change it's speaking speed, to make the two match.

9600 baud is just one of the standard baudrates, though one of the lower ones. If you need it to be faster (maybe because you are sending much data in fast succession), you might want to use a higher baudrate.

  1. Pins: Do these connections also allow me to write and read signals from all of the pins, including analog and digital

That is up to you. Serial/UART is just a communication interface. How it is used is up to you. You already have seen, that it is often used to output text for a user to read over the Serial interface, often used as a way to debug the code by sending specific text at specific places in the code. Since that connection works in both ways, you can also program the Arduino to receive commands over Serial/UART and then act upon them.

Here the overlaying communication protocol comes in. Serial/UART just transmits a series of bytes over its two lines. It doesn't care, what these bytes mean. It can be text (for example encoded via the ASCII standard, as the Serial Monitor does), or it can be just some binary data. Also there is no concept of "messages". There are only individual bytes and you don't have control over when exactly they are sent. So to make meaningful use of Serial/UART you need to use an extra communication protocol on top of Serial/UART, that the receiver understands.

When you send text to the Serial Monitor you are the receiver. Thus you would send text (because you can understand text) and a natural way for humans to distinguish individual messages is to use a delimiter character. In normal text that can be a period, though in this field going to a new line has somewhat evolved to the standard (so the delimiter character is the newline character '\n'). If you read the delimiter character (either yourself on the Serial Monitor, or the Arduino in your program), that marks the end of the message. You can also use that text based approach in your Arduino program (and I would say that is the easiest way). Though you don't need to. You could also use any binary protocol on it (or even invent your own protocol).

I would suggest you look at the examples in the Arduino IDE, that involve Serial and maybe try some tutorials on the web. There are many of them available.

  1. Sending code: Can I still send code through Bluetooth without needing a USB connection?

You don't need an USB connection for Serial/UART to work. In fact the Atmega328p, which you program on the Uno, doesn't care about the USB connection at all. It only knows Serial/UART.


I hope that gave you a good overview over that topic. When you understand these core concepts you will be able to understand the tutorials and examples on the internet.

1
  • so sorry for the late response, this helps tremendously and I totally have a better understanding of this. I was actually getting hung up on that serial problem you mentioned, and the explanation that the bluetooth module is a bluetooth-serial bridge, instead of the USB-serial bridge that the Atmega32u4 does; this really helped. from what I understand, it seems like you're saying it would be a good idea to do everything through one method (sending code, altering binary data, etc) to prevent corrupting data by sending through both USB and bluetooth, right?
    – Daneolog
    May 17 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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