Dr. Michael Kroll's Mobile Computing Forum
http://forum.mkroll.mobi/

Needing Data to show in the Serial Monitor
http://forum.mkroll.mobi/viewtopic.php?f=14&t=587
Page 1 of 1

Author:  tylerdarlington [ Tue Jan 21, 2014 3:47 am ]
Post subject:  Needing Data to show in the Serial Monitor

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

Author:  mkroll [ Tue Jan 28, 2014 9:07 pm ]
Post subject:  Re: Needing Data to show in the Serial Monitor

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 13916 times ]

Author:  tylerdarlington [ Wed Jan 29, 2014 3:52 am ]
Post subject:  Re: Needing Data to show in the Serial Monitor

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)"); 
  }
}

Author:  mkroll [ Fri Jan 31, 2014 9:31 am ]
Post subject:  Re: Needing Data to show in the Serial Monitor

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.

Author:  tylerdarlington [ Sat Feb 01, 2014 12:46 am ]
Post subject:  Re: Needing Data to show in the Serial Monitor

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

Page 1 of 1 All times are UTC + 1 hour [ DST ]
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/