Pages: [1]   Go Down
Author Topic: ArduinoCommander (Android-Bluetooth) with Leonardo  (Read 3115 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to get a bluetooth connection to work with following circumstances:
- Board is Leonardo
- Bluetooth shield is this: http://www.exp-tech.de/Shields/Stackable-Bluetooth-Shield---BT-Shield-v2-2--Master---Slave-.html
- Board with StandardFirmata except:
     o all Serial exchanged to Serial1
     o changed baud rate line to "Firmata.begin(9600);"
     o added in setup section the condition "while(!Serial1) ... "

I can see the bluetooth device with other devices, but the computer says that device does not provide any services (like SSP what I need). The Android Tablet PC with Arduino Commander tries to connect but has no success.
Does anybody has a hint for me how to troubleshoot? Thanks!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
- Board with StandardFirmata except
Why? Why start with code you have no control over? Write some simple sketch that does nothing but echo what it gets over one port to the other, until you get the BT thing working. Then, get more complicated as you need to. Leave making Firmata work with bluetooth until you know BT works at all.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Android software for controlling the Arduino (UNO) via bluetooth expects this firmata. My hope was that I could skip the Arduino programming and just use the firmware that exists.
When it didn't work in first place, I checked for differences between UNO<->Leonardo and came up with the changes I mentioned. Still no luck   smiley-neutral

So again:
What points do I need to look after when trying to use the standard firmata with Leonardo to get the same funcionality as with the UNO? Thanks again
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  // pins with analog capability default to analog input
  // otherwise, pins default to digital output
  for (byte i=0; i < TOTAL_PINS; i++) {
    if (IS_PIN_ANALOG(i)) {
      // turns off pullup, configures everything
      setPinModeCallback(i, ANALOG);
    } else {
      // sets the output to 0, configures portConfigInputs
      setPinModeCallback(i, OUTPUT);
    }
  }


I found that the program has problems with the "systemResetCallback" function in the fortodo loop shown above.
If I disable it, LED from Bluetooth shield says "open serial port". If I enable it, LED stays dark.
Does anyone know what the problem may be?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It reads more like a monologue here but anyway:
I used the example "SerialCallResponse" to read values over Serial1 (bluetooth in my case) and write it to Serial (connected computer). This works nice (actually I also checked for "j" and "n" and used these letters to switch on/off an LED. To give input via Android Bluetooth I used SENA BTerm and on Leonardo I used this modified example (I only put it here because it would have saved me some time - perhaps it helps someone:
Code:
int inByte = 0;         // incoming serial byte
int led = 13;

void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(9600);
  Serial1.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  while (!Serial1) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

//  pinMode(2, INPUT);   // digital sensor is on digital pin 2
  establishContact();  // send a byte to establish contact until receiver responds
}

void loop()
{
  // if we get a valid byte, read analog ins:
  if (Serial1.available() > 0) {
    // get incoming byte:
    inByte = Serial1.read();
    Serial.write(inByte+1);
    Serial.write(inByte);
   
    if (inByte == 106) {            // 'j'
        pinMode(led, OUTPUT);     
        digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
    }
    if (inByte == 110) {            // 'n'
        pinMode(led, OUTPUT);     
        digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
    }

   
  }
}

void establishContact() {
  while (Serial1.available() <= 0) {
    Serial.print('A');   // send a capital A
    delay(1000);
  }
}


This is only a slightly different source than "SerialCallResponse", so I would not call this my style :-)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It reads more like a monologue here but anyway:
But that sketch is not Firmata... Which you insisted was crucial.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Unfortunately you are right. But your suggestion to start with simple sketch and check functionality at all was more satisfying than poking around in the dark.
Next step will be to import piece by piece from standardfirmata into this sketch until it stops working again...
Logged

Pages: [1]   Go Up
Jump to: