1

I'm trying to create eyes for a project, and while I have been able to properly program the different expressions, and have them triggered by commands from the COM3 terminal, I have not been able to make any commands from the Bluetooth Terminal on my phone work.

Details:

Mega2560

2x 8x8 LED Displays - MAX7219

HC-05 Bluetooth Transceiver - default Baud - 9600

Using LEDControl.h, SoftwareSerial.h

This is the loop on my device, when I type the commands A, B, etc. into the COM3 terminal it works just fine, but the same commands on the phone are just interpreted as ASCII, even when I put parentheses around them.

void loop()
{
  // Feed any data from bluetooth to Terminal.
  if (EEBlue.available()){
  Serial.write(EEBlue.read());
  }
  if (Serial.available())  //verifies if there is serial data available
  {
    char cmd = Serial.read();

    if(cmd == 'A') {
      display_eyes(eye_neutral_l, eye_neutral_r);
    }
    if(cmd == 'B') {
      display_eyes(eye_shock_l, eye_shock_r);
    }
    if(cmd == 'C') {
      display_eyes(eye_love_l, eye_love_r);
    }
    if(cmd == 'D') {
      display_eyes(eye_suspicious_l, eye_suspicious_r);
    }
    if(cmd == 'E') {
      display_eyes(eye_happy_l, eye_happy_r);
    }
    if(cmd == 'F') {
      display_eyes(eye_hurt_l, eye_hurt_r);
    }
    if(cmd == '1') {
      display_eyes(eye_mad_l, eye_mad_r);
    }
  // Feed all data from termial to bluetooth
  EEBlue.write(Serial.read());
  }
}
3
  • The serial data, that you use in your Arduino program, is checked against ASCII values, so you actually really need to send ASCII. What exactly to you mean by "are interpreted as ASCII" on the phone? What terminal program do you use on the phone? And what data output do you get on the PC terminal, when you send data over bluetooth? You are echoing it there, so you should be able to see, what is actually received on the Arduino.
    – chrisl
    Commented Apr 25, 2019 at 7:21
  • Oh, I just saw, that you only react to command with eye expressions, when there is something on Serial, which as I assume is connected to the PC. When there is data on the EEBlue interface, you just echoing it to Serial, but you don't process it.
    – chrisl
    Commented Apr 25, 2019 at 7:22
  • So do I need to add something like char cmd = EEBlue.read(); ?
    – MWhitmore
    Commented Apr 25, 2019 at 18:56

1 Answer 1

1

Your problem is, that you read from the EEBlue serial interface, but you are just echoing it over Serial and don't do anything with it. The display code is only executed, when the commands come through Serial.

The simplest way is to copy the code in the if(Serial.available()) statement into the if(EEBlue.available()) statement and changing the read to use EEBlue. Of course you should delete the existing EEBlue.read() from this statement.

But that way would mean to have double the code to maintain. It is cleaner to first read data from either serial interface and then process it. Something like this:

if(Serial.available()){
    cmd = Serial.read();
} else if(EEBlue.available()){
    cmd = EEBlue.read();
}

// insert the code to check the cmd variable for the expected values and act accordingly

cmd = 0; // Resetting the cmd to prevent multiple executions of one command

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.