ASCII Characters being Misunderstood

Hey, I have an Arduino Genuino/Uno board, connected with bluetooth, and anytime that I send an ASCII Character to the board, it is being misinterpreted and transformed into an "unknown" symbol. I have attached a screencap of the Serial Monitor for reference, and have uploaded my project for reference. PLEASE HELP SOON, THIS IS FOR THE CLASS FINAL!!!

I do not know if it is a problem with the code, or if it is a problem with my board, and, yes, I did the troubleshooting guide, and it all checked out.

I have a laser, and a servo motor included in the board, and the code should notify you of where they are located.
Also, the project is based off of the SparkFun Redbot robot, and has all of the motors, sensors, and bluetooth chip.

Thanks!

Please leave a reply if you have any idea as to what is wrong.

blueToothStart.ino (1.4 KB)

DriveFunctions.ino (3.93 KB)

driveRobot.ino (1.15 KB)

readBlueTooth.ino (1.78 KB)

Redbot_Bluetooth_Control.ino (2.89 KB)

I can't see any screencap and you seem to have attached 5 small sketches with no indication of how they fit together or which of them has whatever problems you are seeing.

One common reason for unknown symbols in screen monitor is a mismatch of baud rate. Have you checked that?

Steve

@anthonygerdes2004, do not cross-post. Other thread removed.

Hey, I have an Arduino Genuino/Uno board, connected with bluetooth, and anytime that I send an ASCII Character to the board, it is being misinterpreted and transformed into an "unknown" symbol.

What is your setup? Serial Monitor <---->UNO <------> Bluetooth Module <-----> Android Phone. Is it correct?

You send a character (say A) from Android phone and it does not appear correctly on the Serial Monitor. Is it this problem? If so ( as suggested in Post#1), check for the matching baud rate between Serial Monitor Window and your sketch (Serial.begin(Bd)).

Please, post your codes with code tags (</>).

  • perhaps the baud rate on your serial monitor is wrong
  • perhaps the app sending character data to your UNO is not sending ASCII, but UTF-16

GolamMafa,

GolamMostafa:
What is your setup? Serial Monitor <---->UNO <------> Bluetooth Module <-----> Android Phone. Is it correct?

You send a character (say A) from Android phone and it does not appear correctly on the Serial Monitor. Is it this problem? If so ( as suggested in Post#1), check for the matching baud rate between Serial Monitor Window and your sketch (Serial.begin(Bd)).

Please, post your codes with code tags (</>).

My setup is: Arduino Uno w/Bluetooth Module attached (RM42-I/RN is the thing that looked like an ID code), to a Serial Monior w/Andriod Phone/Tablet, which sends and recieves ASCII Characters and numeric Output.

(UNO <-- Bluetoth Module<-- <-- Andriod Phone)
^-<-- Serial Monitor)

my problem is that anything I send with ANY android phone/tablet is misinterpreted by the Bluetooth chip, and thus renders my bot inoperable. I have trobleshooted by attaching the power input to th ewall dirctly with the proper adapter, Physical conection to the robot with the cords adnd bleutooth print, and checking my board for anything that could impede the electrical conductivity of the contacts (ie: hair, liquids, solids, etc.).

I have checked the Baud tate on both bot and pc, and there is nothing wrong, and the baud rate is exactly the same as it is in the sketch.

The issue is appearing in all of the sketches, and they are supposed to be a single sketch, in a sketch folder as program tabs

I cross posted because I did not know if the problem belonged in the Bard issues section or the code issues section.

Also, Im including a screencap of the Serial Moitor, and Theh sketches included are in a single folder, as one sketch; meaning that they are referenced in the main file "Redbot_Bluetooth_Control", and I have the picture of the board without the bluetooth card attached, and an Image of the bluetooth card itself.

This is all the extra info that I can think of right now, and if you need more, then feel free to message me on the board.

Also, here's the code for the RedBot_Bluetooth_Control:

#include <Servo.h>
/*
  Functions for controlling a RedBot's motors, and setting up a Bluetooth connection.
  RedBot Pin Mapping
  0 - Hardware Serial TX (used for USB connection)
  1 - Hardware Serial RX (used for USB connection)
  2 - Motor A forwards/backwards
  3 - Available
  4 - Motor A brake (enable)
  5 - Motor A Speed
  6 - Motor B Speed
  7 - Motor B forwards/backwards
  8 - Motor B brake (enable)
  9 - Available
  10 - Available
  11 - Available
  A0 - Software Serial TX (also known as Pin14)
  A1 - Software Serial RX (also known as Pin15)
  A2 - Available
  A3 - Available
  A4 - Available
  A5 - Available
  A6 - Available
  A7 - Available
*/

#include <RedBot.h> // include the RedBot library
// create aliases for motor pins. This gives us a name rather than number which is easier to work with.
// motor A
#define motorafb 2     // Motor A on pin 2- forward/backwards 
#define motorab 4      // Motor A on pin 4 - brake
#define motorahs 5     // Motor A on pin 5 - Speed
// motor B
#define motorbfb 7     // Motor B on pin 7 - forward/backwards 
#define motorbb 8      // Motor B on pin 8 - brake
#define motorbhs 6     // Motor B on pin 6 - Speed

RedBotSoftwareSerial bluetooth; // create a "bluetooth" software serial instance for the Xbee Bluetooth card
// use bluetooth.print, bluetooth.read and bluetooth.write to use this serial port
RedBotMotors motors; // create a "motors" instance to use the motor functions
// use motors.drive, motors.pivot, motors.leftMotor and motors.rightMotor to drive the robot

// define global variables
char dataIn = 'S';           //Character/Data coming from the phone.  Initialized to S or stopped.
char command = 'S';      //Used to store alpha charachters coming from the phone that control robot direction
unsigned char velocity = 125;  //Used to store numeric charachters coming from the phone that control robot speed.
int potVal = 0;
int pos = 0;
int photoResist = 0;
int lMotorSpeed;
int rMotorSpeed;
Servo laser;
void setup() {
  blueToothStart();
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(A2, INPUT);
  pinMode(A5, INPUT);
  pinMode(A4, INPUT);
  Serial.begin(9600);  // Begin the serial monitor at 9600bps
  laser.attach(A6);
}

int lives = 3;
int ctr = 0;
void loop() {
  photoResist = analogRead(A5);
  Serial.print("photoResist = ");
  Serial.println(photoResist);
  readBlueTooth();
  driveRobot(command, velocity);
  Serial.print("dataIn = ");
  Serial.println(dataIn);
  potConstrain();
  laser.write(pos);
  if (photoResist >= 600) {
    ctr++;
    spin(1750, velocity, velocity);
  }
  Serial.print("lives = ");
  Serial.println(lives);
  Serial.print("ctr = ");
  Serial.println(ctr);
  if (ctr >= 3) {
    digitalWrite(9, HIGH);
    digitalWrite(10, HIGH);
  } else {
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);
  }
}

Here's The code for the readBlueTooth program:

void readBlueTooth()
{
  if (bluetooth.available() > 0) {   //Check for data on the serial lines.
    dataIn = bluetooth.read();  //Get the character sent by the phone and store it in 'dataIn'.
    if (dataIn == 'F') {
      command = 'F';
    } else if (dataIn == 'B') {
      command = 'B';
    } else if (dataIn == 'L') {
      command = 'L';
    } else if (dataIn == 'R') {
      command = 'R';
    } else if (dataIn == 'S') {
      command = 'S';
    } else if (dataIn == '0') {
      velocity = 0;
    } else if (dataIn == '1') {
      velocity = 25;
    } else if (dataIn == '2') {
      velocity = 50;
    } else if (dataIn == '3') {
      velocity = 75;
    } else if (dataIn == '4') {
      velocity = 100;
    } else if (dataIn == '5') {
      velocity = 125;
    } else if (dataIn == '6') {
      velocity = 150;
    } else if (dataIn == '7') {
      velocity = 175;
    } else if (dataIn == '8') {
      velocity = 200;
    } else if (dataIn == '9') {
      velocity = 225;
    } else if (dataIn == 'q') {
      velocity = 255;
    } else if (dataIn == 'c') {
      ctr == -32768;
    } else if (dataIn == '.') {
      ctr == 400;
    } else if (dataIn == 'l') {
      driveInSquare();
    }
  }
}

Raw_Bluetooth_Module-300.png

PaulMurrayCbr:

  • perhaps the baud rate on your serial monitor is wrong
  • perhaps the app sending character data to your UNO is not sending ASCII, but UTF-16

The app that I use is Bluetooth spp pro, and it does not have th ecapabilities to send caracters in UTF-16; only ASCII or Hex(00-FF).

The Serial monitor is not wrong, merely that it is printing out exactly what the bluetooth chip recieves, and the recieved data is being misinterpreted.

I have Troubleshooted for a continuous period of over 8 hours, and the only possible conclusion is that the bluetooth chip is faulty; seeing as I uploaded multiple sketches to the board, and none of them resulted in the bluetooth working.