View unanswered posts | View active topics It is currently Fri Nov 24, 2017 9:11 am



Reply to topic  [ 5 posts ] 
Needing Data to show in the Serial Monitor 
Author Message

Joined: Wed Feb 13, 2013 10:18 pm
Posts: 6
Hey there,

I am having massive difficulty having the BLE Shield 2.0 and Arduino Leonardo showing data in the Serial Monitor. I want what I have sent from my iPhone (that has been received by the BLE shield) to show up in the serial monitor. Or to simply to have the serial monitor to print in "Data received" when it is actually recieved. Is there anyone that can help me with this sketch. I have tried multiple sketches and I am just not having luck. Would someone please help me with a sketch that will allow me to see these things?

Tyler


Tue Jan 21, 2014 3:47 am
Profile
Site Admin

Joined: Thu Aug 02, 2012 11:36 am
Posts: 166
Hello Tyler,
I simply used the following sketch successfully to monitor data send from the iPhone and send data to the iPhone as well.

Code:
/*
 * BLE Shield SoftSerial Test Sketch for Arduino 1.0.5
 * v2.0.0 2013-10-20
 *
 * Copyright (c) 2012-2013 Dr. Michael Kroll
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
 * software and associated documentation files (the "Software"), to deal in the Software
 * without restriction, including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 * to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://www.mkroll.mobi
 * http://forum.mkroll.mobi
 */

boolean connected;

void setup()   {
 
  // On the Leonardo, the Serial port is mapped to the USB Cable
  // and is not available at pins D0/D1.
  // We set it to 9600 baud.
  Serial.begin(9600);

  // The BLE-Shield v2.0.0 is running at 9600 baud by default
  // Set the data rate for the Serial1 port on Pins 0/1
  // The jumpers has to be set to RX -> D0 and TX -> D1
  Serial1.begin(9600);

  Serial.print("BLE-Shield v2.0.0 Sketch setup...");

  // The BLE-Shield v2.0.0 is not only litting up the blue LED on connection,
  // but raising and lowering an interrupt on the Arduino.
  // Finally you are able to see the connected state on the Arduino :-)
  // Here we attach the interrupt according to the spec at
  // http://arduino.cc/en/Reference/attachInterrupt
  // The interrupt jumper has to be set to D7
  attachInterrupt(4, connection, CHANGE);   
  Serial.println(" done.");
  connected = false;
}

void loop() // run over and over
{
  // Wait for Data on the serial console and submit it to the
  // BLE-Shield byte per byte. there is no longer a buffer involved.
  if (Serial.available()) {
    int ch = Serial.read();
    Serial.print(ch);
    Serial1.write(ch);
  }
 
  // Wait for data send from the iPhone and print it to the serial console.
  // That's it. Quite simple.
  if (Serial1.available()) {
    Serial.write(Serial1.read());
  }
}

// This method is called if the connection state changes.
// When a connection is established, the Interrupt will be set to high, and
// set to low, once the BLE-Shield is disconnected.
void connection() {
  connected = !connected;
  if (connected) {
    Serial.println("BLE-Shield Connected = true (4)");
  }
  else {
    Serial.println("BLE-Shield Connected = false (4)"); 
  }
}


Please note that the jumpers on the BLE-Shield must bet set as illustrated in the attached image.

The output on the Serial Monitor looks as follows:

Code:
BLE-Shield Connected = true (4)
7210110810811132871111141081004610


Does this help?

Cheers,
Michael.


Attachments:
File comment: BLE-Shield v2.0.0 Jumper Settings.
photo.JPG
photo.JPG [ 193.46 KiB | Viewed 11961 times ]
Tue Jan 28, 2014 9:07 pm
Profile WWW

Joined: Wed Feb 13, 2013 10:18 pm
Posts: 6
Hey Michael,

When I tried this sketch, the one you first provided, and with the jumpers in the correct position it worked. I sent 01234 as a ASCII and saw that code show up perfectly in the serial monitor. However, I am attempting to make the BLE Shield 2.0 work with the Leonardo on pins 4,5. When I changed the sketch bellow I no longer saw data just the "BLE-Shield Connected = true".

Is there a way to do this with software serial 4,5?

here is the code I used to try that:


Code:
/*
 * BLE Shield SoftSerial Test Sketch for Arduino 1.0.5
 * v2.0.0 2013-10-20
 *
 * Copyright (c) 2012-2013 Dr. Michael Kroll
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
 * software and associated documentation files (the "Software"), to deal in the Software
 * without restriction, including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 * to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://www.mkroll.mobi
 * http://forum.mkroll.mobi
 */
 
 #include <SoftwareSerial.h>

SoftwareSerial bleShield(4, 5);
boolean connected;

void setup()   {
 
  // On the Leonardo, the Serial port is mapped to the USB Cable
  // and is not available at pins D0/D1.
  // We set it to 9600 baud.
  Serial.begin(9600);

  // The BLE-Shield v2.0.0 is running at 9600 baud by default
  // Set the data rate for the Serial1 port on Pins 0/1
  // The jumpers has to be set to RX -> D0 and TX -> D1
  bleShield.begin(9600);

  Serial.print("BLE-Shield v2.0.0 Sketch setup...");

  // The BLE-Shield v2.0.0 is not only litting up the blue LED on connection,
  // but raising and lowering an interrupt on the Arduino.
  // Finally you are able to see the connected state on the Arduino :-)
  // Here we attach the interrupt according to the spec at
  // http://arduino.cc/en/Reference/attachInterrupt
  // The interrupt jumper has to be set to D7
  attachInterrupt(4, connection, CHANGE);   
  Serial.println(" done.");
  connected = false;
}

void loop() // run over and over
{
  // Wait for Data on the serial console and submit it to the
  // BLE-Shield byte per byte. there is no longer a buffer involved.
  if (Serial.available()) {
    int ch = Serial.read();
    Serial.print(ch);
    bleShield.write(ch);
  }
 
  // Wait for data send from the iPhone and print it to the serial console.
  // That's it. Quite simple.
  if (bleShield.available()) {
    Serial.write(bleShield.read());
  }
}

// This method is called if the connection state changes.
// When a connection is established, the Interrupt will be set to high, and
// set to low, once the BLE-Shield is disconnected.
void connection() {
  connected = !connected;
  if (connected) {
    Serial.println("BLE-Shield Connected = true (4)");
  }
  else {
    Serial.println("BLE-Shield Connected = false (4)"); 
  }
}


Wed Jan 29, 2014 3:52 am
Profile
Site Admin

Joined: Thu Aug 02, 2012 11:36 am
Posts: 166
Hello Tyler,
please read this article on arduino.cc:

http://arduino.cc/en/Reference/SoftwareSerial

This section is interesting:
Not all pins on the Leonardo support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI)

Try to use pins 8,9 instead of 4,5 and see how it goes.
I don't have a Leonardo and BLE-Shield with me, while writing this answer. I'll test it tonight.

Cheers,
Michael.


Fri Jan 31, 2014 9:31 am
Profile WWW

Joined: Wed Feb 13, 2013 10:18 pm
Posts: 6
Hey Michael,

This is working for me!! Running the Arduino Leonardo in software serial with the BLE Shield 2.0 using pins 8 and 9 works perfectly!

Thank you so much!

Tyler


Sat Feb 01, 2014 12:46 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.