Skip to first unread message

Lee Dalvin

unread,
Jan 17, 2015, 3:41:35 PM1/17/15
to mitappinv...@googlegroups.com
Hi how do i send large int above 255 through the Bluetooth to my arduino with a character at the back, for example a value of 1500m1?

Jay

unread,
Jan 17, 2015, 4:59:11 PM1/17/15
to mitappinv...@googlegroups.com
As you may or may not know, receiving data from the Arduino works nicely because the data is converted for you being able to send long strings of text. However, it becomes more complex when you're sending data from the smartphone to the Arduino because that work is no longer done for you. That being said, there are blocks available for the Bluetooth component that send data to the Arduino.

You can send numbers larger than 255 by using the block "Send2ByteNumber" or "Send4ByteNumber". However, this information is being sent in bytes, which means that you receive the value one byte at a time. Lets use 1000 for example. If I send the value 1000 to the Arduino and assuming that we use the "Send2ByteNumber" block, and you use Serial.println to check this data, you'll see the following display:

232
3

The number 1000 is packaged into 2-bytes where the top number is the lowest byte, and the bottom number is the highest byte (data is displayed from lowest byte to higher byte). If we converted that data back to decimal you'll see that you get:

3 232 = 00000011 11101000 = 1111101000 = 1000

It'll work the same for the 4-byte block except that the number will display: 232,3,0,0

So there are a couple of things you must do, the first is figure out which block you will be using in terms of sending bytes. The second thing is being able to retrieve that data one byte at a time and repackaging it together on the Arduino and then convert that data into decimal form. As said I before, you only receive data one byte at a time.

Finally there is the character that you wanted to send. Here you can use the "SendText" block which will convert a character according to the "ASCII table decimal number". From there you need to convert that decimal value into a character and then string everything together.

If you have any further questions I will be happy to help. Best of luck!

Lee Dalvin

unread,
Jan 18, 2015, 4:21:33 AM1/18/15
to mitappinv...@googlegroups.com
Hi jay thanks a lot for taking some time out to help me understand how the arduino would receive bytes from the mobile, is it ok if you can provide some methods as to how i would be able to convert the the bytes received and rearrange them back to decimal and display them on the serial monitor in arduino.

SteveJG

unread,
Jan 18, 2015, 8:37:23 AM1/18/15
to mitappinv...@googlegroups.com
@ Lee    you might find the following thread useful:  https://groups.google.com/forum/#!searchin/mitappinventortest/hex$20to$20decimal/mitappinventortest/HcgEhgmPORM/-5lNARq_IFkJ

Is there a solution there for you?

Regards,
Steve

Lee Dalvin

unread,
Jan 18, 2015, 2:29:52 PM1/18/15
to mitappinv...@googlegroups.com
is this able to convert the values and send them directly to arduino to be read?

Jay

unread,
Jan 18, 2015, 2:30:18 PM1/18/15
to
Hi Lee,

You should look into bit wise manipulation, specifically shifters and logic gates. This is an example of a 2-byte converter, I will use the previous number as an example.

byte a = 232; //least significant byte
byte b = 3; //most significant byte
int number; //int variable number

void setup () //Don't know your setup here

void loop ()
{
   number = (a << 8) | b; //Places 3 into integer number and shifts integer number eight times to the left. Then it uses an or gate to place 232 into integer number
   Serial.println(number); //Display 1000
   delay(10000); //Delays the loop so you can see the number display
}

I don't know the extent of your project or what you've figured out so far but I can refer you to a library provided by the Arduino software that can be used for Bluetooth: http://arduino.cc/en/Reference/softwareSerial

Perhaps you should provide us with more details. The forum on the Arduino site is filled with lots of information and people that do these kinds of projects.

-Jay

Lee Dalvin

unread,
Jan 19, 2015, 12:59:41 AM1/19/15
to mitappinv...@googlegroups.com
Hi i am using the slider function in app inventor, is it possible for me to send a value of for example 80ma instead of just 80 to my arduino through the Bluetooth module?
i am currently trying to use a phone app to get my motors on the quad copter to start running, below is an example of an arduino code i have found on the web.
#include <Servo.h>

#define MAX_SIGNAL 2000
#define MIN_SIGNAL 700

#define M1 3
#define M2 5
#define M3 6
#define M4 10

Servo motor1;
Servo motor2;
Servo motor3;
Servo motor4;

int speed1, speed2, speed3, speed4;

void setup() {
  Serial.begin(9600);
  
  motor1.attach(M1);
  motor2.attach(M2);
  motor3.attach(M3);
  motor4.attach(M4);

  motor1.writeMicroseconds(MIN_SIGNAL);
  motor2.writeMicroseconds(MIN_SIGNAL);
  motor3.writeMicroseconds(MIN_SIGNAL);
  motor4.writeMicroseconds(MIN_SIGNAL);

  Serial.println("Sending minimum signal. Power on motor and wait for beeps.");
  delay(4000);

  Serial.println("After beeps, type a signal length terminated by m and the motor number to motor. For example,");
  Serial.print(MIN_SIGNAL);
  Serial.println("m1 to stop the motor 1. ma is for all motors.");
}

void stop() {
  Serial.println("stoping...");
  motor1.writeMicroseconds(MIN_SIGNAL);
  motor2.writeMicroseconds(MIN_SIGNAL);
  motor3.writeMicroseconds(MIN_SIGNAL);
  motor4.writeMicroseconds(MIN_SIGNAL);
  speed1 = MIN_SIGNAL;
  speed2 = MIN_SIGNAL;
  speed3 = MIN_SIGNAL;
  speed4 = MIN_SIGNAL;
}

void loop() {
  int input, number;

  // Wait for input
  if (!Serial.available()) return;

  input = Serial.read();
  // emergency stop command is ', right next to enter key
  if (input == '\'') {
    stop();
    return;
  }

  // Convert string to integer. String terminated with m (for microseconds).
  number = input - '0';
  while ((input = Serial.read()) != 'm') {    
    if (input == -1) continue;

    number *= 10;
    number += input - '0';
  }

  while ((input = Serial.read()) == -1);

  switch (input) {
   case 'a':
     speed1 = number;
     speed2 = number;
     speed3 = number;
     speed4 = number;
     break;
   case '1':
     speed1 = number;
     break;
   case '2':
     speed2 = number;
     break;
   case '3':
     speed3 = number;
     break;
   case '4':
     speed4 = number;
     break;
   default:
     break;
  }

  Serial.print("Now writing: ");
  Serial.print(speed1);
  Serial.print(" ");
  Serial.print(speed2);
  Serial.print(" ");
  Serial.print(speed3);
  Serial.print(" ");
  Serial.println(speed4);

  motor1.writeMicroseconds(speed1);
  motor2.writeMicroseconds(speed2);
  motor3.writeMicroseconds(speed3);
  motor4.writeMicroseconds(speed4);
}

as you can see if i would like to get all my motors to run i would need the app inventor to send a value of for example 1500ma to the arduino , however i was able to only send a value of 0-255 , is there anyway i can do this?
Reply all
Reply to author
Forward
0 new messages