Rover v2 and bluetooth control

Hi!

I require your help regarding a problem I’m encountering.

Description:
I have the Rover V2 and followed the tutorial I found on this site a while back to connect my bluetooth device to the rover, downloaded the code and installed the app on my android device. It all worked very well, but unfortunately, my bluetooth device died…so I decided to purchase a bluetooth low energy device (HM-10) this time around since it is compatible with Apple and Android. So my question is, will the HM-10 work with the rover v2? I tried a few things and it will power on, but I am thinking that the HM-10 is not compatible with the android app?
Hardware concerned:
HM-10 bluetooth module, rover v2
Software concerned:
any suggestion for a bluetooth app that uses HM-10 and works in a similar way to the one from the tutorial
Troubleshooting steps already taken:

Additional information:

Thank you so much in advance for your help!

Since the HM-10 only has four pins it does not fit correctly into the socket provided on the rover v2, so I used some jumpers to connect it properly. It powers on (a red light on the module) but my tablet does not find it when scanning for devices.

I assume I still need to do something different though…

Also not 100% certain without testing it (little nuances may mean it doesn’t work). If you had not already purchased a module, this should have worked: https://www.robotshop.com/en/bluetooth-ble-link-bee.html
As jeff77 indicated, the pinout to the rover V2 is different, so with the HM-10 you’d need to wire it correctly. Otherwise, it uses standard serial and should accept serial commands normally. Note that it takes 3.3V, not 5V.

Regarding an app, we’ve seen most simply use “bluetooth”, so BLE should be compatible.
Serial terminal: https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal
Controller: https://play.google.com/store/apps/details?id=nextprototypes.BTSerialController (no BLE mentioned though)

I found a bluetooth terminal app on iPhone with an example of how to turn an led on and off by sending a command of 0 for On and 1 for Off. Then I pulled up the basic “go forward” sketch for the Rover v2 and basically removed the LED and added in what was needed to make the Rover go forward by sending 1 and 2 for off. I connected the HM-10’s rx and tx to the Rover’s 0 and 1, ground to ground pin and vc to 3.3v.

It did work, so I tried to implement that code with the rest of the Rover’s movements in the “Bare minimum” sketch…for example, a command of 1 = forward, 2 = reverse, etc… This did not work and I tried all sorts of variations of the code. The code even compiled and uploaded, but wouldn’t work.

I know what I am not understanding is exactly how coding works, like the “if”, “else” functions, etc… I have a general idea, but a lot of the tutorials I have found say to do entirely different things than what I have been able to get to work (at least for the go forward example)

Here is what I was able to do…

#include <SoftwareSerial.h>
/* Copy and paste the code below into the Arduino software */
int E1 = 6; //M1 Speed Control
int E2 = 5; //M2 Speed Control
int M1 = 8; //M1 Direction Control
int M2 = 7; //M2 Direction Control
SoftwareSerial Bluetooth(0, 1);
void setup()
{ Serial.begin(9600);
Bluetooth.begin(9600);
pinMode(E1, OUTPUT);
pinMode(E2, OUTPUT);
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
}
void loop() {
int command;

if (Bluetooth.available()) {
command = Bluetooth.read();
Serial.println(“Input received:”);
if (command != 1)
{ Serial.println(“1”);//forward
analogWrite (E1, 255);
analogWrite (E2, 255);
digitalWrite(M1, LOW);
digitalWrite(M2, LOW);
}

else if (command != 2) {

  Serial.println("2");//stop
  analogWrite (E1, 0);
  analogWrite (E2, 0);
  digitalWrite(M1, LOW);
  digitalWrite(M2, LOW);
}

}
}

In those two sections of code you use:
command != 1
command != 2
The operator “!=” means NOT equal to
I think you meant to use “==” which means equal to.
The first block ( command !=1) will run the following lines of code anytime the command is NOT equal to “1”
similarly for the second block (command != 2)
Also, one other thing to check. Are you sending the axcii CHARACTERS “1” and “2” or the binary NUMBERS 1 and 2?
The code you show above is checking for the binary numbers

EDIT: The ASCII characters “1” and “2” are actually the binary numbers 49 (0011 0001) and 50 (0011 0010)

Can you get the app to send the (serial) characters w, a, s, d and something else rather than just binary?

The App says to select Decimal and change to FFE1. I see what you mean about the commands, but Im not sure what binary numbers and ASCII is??

Ok, I kind of understand what you mean, but wouldn’t I have to change something in the code other than just adding another = to the command?

Everything in a computer is stored in “bits” – binary digits that can be either 0 or 1. Usually they are grouped into blocks of 8, which is called a “byte.” When you store text, it uses a code called “ASCII” that represents each character as a byte, with a certain coding for each character. That same byte can also be used simply as a number from 0 to 255. The number 0 would have all bits set to 0, the number 255 would have all bits set to 1. The number 1 would be “00000001” and the number 2 would be “00000010”. But the ASCII characters use the same codes differently, with the characters for “1” and “2” using the actual numbers for 49 and 50.
In most programming languages, sending something like send(1) will send the binary code for 1, where using send(‘1’) or send(“1”) will send the ascii code instead.

It might be a good idea for you to study some basic programming.

Yes, thank you…I do understand a little of that. I am going to keep experimenting with the code and maybe find a different app/or see if it will allow me to send ASCII characters.

I have no idea what your app is sending. It could be either. Either can work, but both sides must match. As a general rule, it is usually better to send ascii characters in situations like this. It’s just one more thing to watch out for.

Can you provide a link to the App, or a name and where it can be found?

It’s called Bluetooth Terminal

I have been reading a lot about ASCII tables and possible ways to write a code that works. I come across a lot of example code that is similar, but none where the person wrote a W,A,S,D control type code that is only used by entering the commands in the serial terminal. A lot of them have char ==B or something like that, but the way I understand it is that it will only work with an intended app…

You don’t necessarily have to change what is being sent. You can change what you are looking for.
You can find out what is being sent very easily. Make a test app on the Arduino that prints any value received. Remove all the code that checks for certain bytes and replace it all with code that prints the byte:

void loop() {
int command;

if (Bluetooth.available())
{
command = Bluetooth.read();
Serial.println(command); // This will print the number of the byte that is received
}

Then, you can press the desired buttons on your app and find out what number is sent for each. Then add your code back in to check for those specific numbers. As I mentioned before, it doesn’t really matter WHAT is sent, just that the Arduino program checks for the right ones
Your code should then look something like this:

if(command == 49)
{
do stuff for this button
}
else if(command == 50)
{
do stuff for this button
}
else if …

Ok I tried this and it worked
#include <SoftwareSerial.h>
int led = 2;

SoftwareSerial Bluetooth(0, 1);
void setup() {
Serial.begin(9600);
Bluetooth.begin(9600);
pinMode(led, OUTPUT);

}
void loop() {
int command;

if (Bluetooth.available()) {
command = Bluetooth.read();
Serial.println(“Input received:”);
if (command == 65)
{

  Serial.println('A');
  digitalWrite(led, HIGH);

}
if (command == 66)
{
  Serial.println('B');
}  digitalWrite(led, LOW);

}
}

Then I tried adding a second led and the code below, but it didn’t work

#include <SoftwareSerial.h>
int led = 2;
int led1 = 3;
SoftwareSerial Bluetooth(0, 1);
void setup() {
Serial.begin(9600);
Bluetooth.begin(9600);
pinMode(led, OUTPUT);
pinMode(led1, OUTPUT);
}
void loop() {
int command;

if (Bluetooth.available()) {
command = Bluetooth.read();
Serial.println(“Input received:”);
if (command == 65)
{
// A non-zero input will turn on the LED
Serial.println(‘A’);
digitalWrite(led, HIGH);

}
if (command == 66)
{
  Serial.println('B');
  digitalWrite(led, LOW);
}
if (command == 67)

Serial.println(‘C’);
digitalWrite(led1, HIGH);
{
if(command == 68)
Serial.println(‘D’);
digitalWrite(led, LOW);

}

}
}

You are missing curly braces around the code after the last two if(command == … lines
if(command == 67)
{ // curly brace here
// other code for “C”
} // closing curly brace here
if(command == 68)
{ // curly brace here
// other code for “D”
} // closing curly brace here

The default Arduino coding style of having the opening curly brace on the same line is, in my not so humble opinion, garbage:
if(command == 65) {

Much better to put it on a line by itself:
if( command == 65)
{
// code here
} // close on its own line too

That makes it obvious when one is missing – which is a VERY common fault in all C style languages (C, C++, java, C#, …)

I have fixed the errors with the curly braces in my code and it compiles, uploads but when I send the commands through the app the first led turns on and off, but for the second led (command ==67) for (‘D’) and (command ==68) for (‘C’)…these two commands do not turn the second led on or off.

I’m going to double check my wiring again, make sure led is not burned out. Here is the code…

#include <SoftwareSerial.h>
int led = 2;
int led1 = 3;
SoftwareSerial Bluetooth(0, 1);
void setup() {
Serial.begin(9600);
Bluetooth.begin(9600);
pinMode(led, OUTPUT);
pinMode(led1, OUTPUT);
}
void loop() {

int command;

if (Bluetooth.available()) {
command = Bluetooth.read();
Serial.println(“Input received:”);
}
{
if (command == 65)
{
Serial.println(‘A’);
digitalWrite(led, HIGH);
}
if (command == 66)
{
Serial.println(‘B’);
digitalWrite(led, LOW);
}
if (command == 67)
{

  Serial.println('C');
  digitalWrite(led1, HIGH);
}
if (command == 68)
{

  Serial.println('D');
  digitalWrite(led1, LOW);   
  }

}
}