create new tag
view all tags

A serial protocol to control the movement of the robot.

Setting up the HC-05 as a master

Before being able to send any message from the Arduino Nano, acting as the controller, to the Arduino Uno, controlling the DC motors, the Bluetooth connection must be established. For this to happed we must first configure the HC-05 as a Bluetooth master and tell it with which Bluetooth slave (its Bluetooth address) to communicate. I find the HC-06 address with the PC using bluetoothctl to be 00:21:13:00:ba:68.

To put the HC-05 into AT mode, allowing to configure its, the small pushbutton must be pressed while power is applied to the module. It then blinks at ~ 2 Hz indicating that it has entered AT mode and it communicates with its serial line at 38400 Baud.

Here are the AT mode commands and the answers from the HC-05 module when setting it up as master, with 38400Baud, 1 stop bit, no parity and asking it to pair itself with the HC-06 at the address given above. Once paired, both modules send double blinks with a frequency of ~ 2 Hz.

Once the Bluetooth connection is setup we can think about the a communication protocol between the two Arduinos. Since both micro-controllers see the connection as a simple serial line it seems evident to send data in ASCII format which allows to easily read what is sent and what is received on the other side.

The protocol has the following form:


where F stands for forward, B for backward, L for left, R for right and C for checksum. The ___ replace 3 digit hex numbers.

The joystick

The joystick consists of 2 potentiometers which are connected to 2 analog input on the Arduino Nano and which therefore deliver 2 values in the range of 0..1023 (the Arduino ADCs have 10 bit resolution. These two 10 bit values must now be translated into four 9 bit values describing the motor movement forward, backward, left and right. The figure below shows that for values above the mid-point (~512) the midpoint value must be subtracted to get the motor value while for values below the mid-point the motor value is given by mid-point-joystick value.


The calculated values are converted into 3 hex characters and inserted into the protocol string before it is sent to the other side. A checksum is calculated by summing all characters up to C:0x (included) and added as the last 3 characters.

The strategy for the development of small functions implementing the above steps is described in the protocol recipe.

-- Uli Raich - 2017-11-21


Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng joystick2motor.png r1 manage 13.4 K 2017-11-21 - 15:01 UnknownUser  
Topic revision: r1 - 2017-11-21 - uli
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback