BTLEserial.print is BLANK

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
eliddell
 
Posts: 13
Joined: Mon Sep 08, 2014 10:49 am

BTLEserial.print is BLANK

Post by eliddell »

I working on a prototype with an Arduino UNO and an AdaFruit Low Energy Blue tooth

I have an array of uint32_t that I am trying to send via blue tooth to a given device. I don't think i can send the array so I was trying to send it as a comma separated string.

I can print out each individual index of that array just fine, but its completely blank when i try to make a comma separated String.. See code and comments below.

Ay Array:

Code: Select all

uint32_t items[]= {0,3513728,7925384,0,0,0};
In My Loop:

Code: Select all

String output = "";

for(int i = 0; i<6;  i++){

  BTLEserial.print(items[i]); // Prints as expected
  output += getStringForUI32_T(items[i]);
  output+=",";

 }
 BTLEserial.print(output); // prints BLANK
I imagine this has something to do with memory but I am at a complete loss.. Please help!

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: BTLEserial.print is BLANK

Post by adafruit_support_rick »

It works with Serial, so it ought to work with BTLE. There may be something else wrong with your sketch. Here's the csketch I'm using. See if it works for you:

Code: Select all

uint32_t items[]= {0,3513728,7925384,0,0,0};

String output = "";

void setup()
{
  Serial.begin(9600);


for(int i = 0; i<6;  i++){

  Serial.println(items[i]); // Prints as expected
  output += getStringForUI32_T(items[i]);
  output+=",";

 }
 Serial.println();
 Serial.print(output); // prints BLANK
}

void loop() {}

int radix =10;
char buffer[33];

char* getStringForUI32_T(uint32_t value){
     return ultoa(value,buffer,radix);

}

User avatar
eliddell
 
Posts: 13
Joined: Mon Sep 08, 2014 10:49 am

Re: BTLEserial.print is BLANK

Post by eliddell »

I don't see a difference:

here is my entire loop()

Code: Select all

void loop()
{
  //Serial.println("--------------------Loop begin-------------------");



  // Tell the nRF8001 to do whatever it should be working on.
  BTLEserial.pollACI();

  // Ask what is our current status
  aci_evt_opcode_t status = BTLEserial.getState();
  // If the status changed....
  if (status != laststatus) {
    // print it out!
    if (status == ACI_EVT_DEVICE_STARTED) {
      Serial.println(F("* Advertising started"));
    }
    if (status == ACI_EVT_CONNECTED) {
      Serial.println(F("* Connected!"));
      //BTLEserial.print("Goodmorning");
    }
    if (status == ACI_EVT_DISCONNECTED) {
      Serial.println(F("* Disconnected or advertising timed out"));
    }
    // OK set the last status change to this one
    laststatus = status;
  }

  if(status == ACI_EVT_CONNECTED){

    //LightDetect

    photocellReading = analogRead(photocellPin);  

    // Serial.print("Analog reading = ");
    // Serial.print(photocellReading);     // the raw analog reading

    // We'll have a few threshholds, qualitatively determined
    if (photocellReading < 200) {

      bagIsLifted = false;

    } 
    else {
      bagIsLifted = true;

    }


    if(numChecks<6){
      if(numChecks ==0){
        itemsList =String( "");
      }
      else{
        itemsList+=",";
      }
      uint32_t cardid = 0;
      boolean success;
      boolean success2;
      boolean success3;

      uint8_t uid[] = { 
        0, 0, 0, 0, 0, 0, 0      };  // Buffer to store the returned UID
      uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)

      // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
      // 'uid' will be populated with the UID, and uidLength will indicate
      // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
      Serial.println("que:");

      Serial.println("----------");


      if(numChecks==0 || numChecks==1){
        digitalWrite(SS1, LOW);
        digitalWrite(SS2, HIGH);
        digitalWrite(SS3, HIGH);
        success = nfc1.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
        //
        Serial.println(success,DEC);
        if (success) {

          nfc1.PrintHex(uid, uidLength);

          if (uidLength == 4)
          {
            // We probably have a Mifare Classic card ... 
            cardid = uid[0];
            cardid <<= 8;
            cardid |= uid[1];
            cardid <<= 8;
            cardid |= uid[2];  
            cardid <<= 8;
            cardid |= uid[3]; 
            Serial.print("Seems to be a Mifare Classic card 11111111111 #");
            Serial.println(cardid);

          }
          Serial.println("");
        }
      }

      if(numChecks==2 || numChecks==3){
        digitalWrite(SS1, HIGH);
        digitalWrite(SS2, LOW);
        digitalWrite(SS3, HIGH);
        success2 = nfc2.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

        if (success2) {

          nfc2.PrintHex(uid, uidLength);

          if (uidLength == 4)
          {
            // We probably have a Mifare Classic card ... 
            cardid = uid[0];
            cardid <<= 8;
            cardid |= uid[1];
            cardid <<= 8;
            cardid |= uid[2];  
            cardid <<= 8;
            cardid |= uid[3]; 
            Serial.print("Seems to be a Mifare Classic card 2222222222 #");
            Serial.println(cardid);


          }
          Serial.println("");
        }
      }
      //delay(200);
      if(numChecks==4 || numChecks==5){
        digitalWrite(SS1, HIGH);
        digitalWrite(SS2, HIGH);
        digitalWrite(SS3, LOW);

        success3 = nfc3.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
        //

        if (success3) {

          nfc3.PrintHex(uid, uidLength);

          if (uidLength == 4)
          {
            // We probably have a Mifare Classic card ... 
            cardid = uid[0];
            cardid <<= 8;
            cardid |= uid[1];
            cardid <<= 8;
            cardid |= uid[2];  
            cardid <<= 8;
            cardid |= uid[3]; 
            Serial.print("Seems to be a Mifare Classic card 3333333 #");
            Serial.println(cardid);

          }
          Serial.println("");
        }
      }



      items[numChecks] = cardid;
      itemsList.concat(getStringForUI32_T(cardid));
      // Serial.println(itemsList);
      numChecks++;
    }
    else{



      output = "";
      char *lastOne = "";
      char *newOne ="";
      char mBuff[100];
      for(int i = 0; i<6;  i++){
        newOne = getStringForUI32_T(items[i]);
        if(newOne!=lastOne){

          output += newOne;  
          BTLEserial.print(newOne); //prints as expected
          
          output+=",";
        }
        else{
          BTLEserial.print(0);
        }
        lastOne = getStringForUI32_T(items[i]);



      }

      BTLEserial.print(output); //BLANK
      numChecks = 0;
      delay(1000);

    }

  }
}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: BTLEserial.print is BLANK

Post by adafruit_support_rick »

I saw that you had posted the same thing on Arduino stack exchange. In there, you said it didn't work with Serial.print, either. The sketch I posted does work with Serial.print, so I was wondering what that sketch did on your system.

It's possible you have a memory issue with the string. Try calling the reserve function on "output" in your setup routine:
http://arduino.cc/en/Reference/StringReserve

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”