Teensy 3.2 BLE Connection

Thread Starter

oceanblue

Joined Dec 20, 2018
6
Hello! I have a project that involves a teensy 3.2 and a BLE HM-10 module.
I actually need to wirelessly connect a myo armband to my teensy microcontroller through HM-10.

I successfully connected the said components but it is through an Arduino UNO and not teensy. However, I need to use a teensy board and not an Arduino.

Here is the code:

Code:
/**
* @file   printFirmwareInfo.ino
* @author Valentin Roland (webmaster at vroland.de)
* @date   September-October 2015
* @brief  Example file demonstrating connecting to and reading data from the Myo.
*
* This file is part of the MyoBridge Project. For more information, visit https://github.com/vroland/MyoBridge.
*
* @include printFirmwareInfo.ino
*/

#include <MyoBridge.h>
#include <SoftwareSerial.h>

//SoftwareSerial connection to MyoBridge
SoftwareSerial bridgeSerial(2,3);

//initialize MyoBridge object with software serial connection
MyoBridge bridge(bridgeSerial);

//a function to inform us about the current state and the progess of the connection to the Myo.
void printConnectionStatus(MyoConnectionStatus status) {
   
    //print the status constant as string
    Serial.println(bridge.connectionStatusToString(status));
}

void setup() {
  //initialize both serial connections
  Serial.begin(115200);
  while (!Serial) ;
  bridgeSerial.begin(115200);
  //wait until MyoBridge has found Myo and is connected. Make sure Myo is not connected to anything else and not in standby!
  Serial.println("Searching for Myo...");
 
  //initiate the connection with the status callback function
  bridge.begin(printConnectionStatus);
 
  Serial.println("connected!");

  Serial.print("Firmware Version: ");
  Serial.print(bridge.getFirmwareMajor());
  Serial.print(".");
  Serial.print(bridge.getFirmwareMinor());
  Serial.print(".");
  Serial.println(bridge.getFirmwarePatch());
  Serial.print("Hardware Revision: ");
  Serial.println(bridge.getHardwareRevision());

  //declare a storage array for the hardware address
  byte address[6];

  //get the address and store it in our array
  bridge.getHardwareAddress(address);

  //print the hardware address in HEX format
  Serial.print("Hardware Address: 0x");
  for (int i=0;i<6;i++) {
    Serial.print(address[i], HEX);
  }
  Serial.println();

  //get the unlock pose
  MyoPose unlockPose;
  unlockPose = bridge.getUnlockPose();

  //print the name of the unlock pose as string
  Serial.print("Unlock Pose: ");
  Serial.println(bridge.poseToString(unlockPose));
 
  //get the current battery level and print it
  byte batteryLevel = bridge.getBatteryLevel();
  Serial.print("Battery Level: ");
  Serial.println(batteryLevel);
 
  //short vibration to show we are ready
  bridge.vibrate(1);
}

void loop() {
  //update the connection to MyoBridge
  bridge.update();
}
In Arduino, I simply connected the TX Pin of HM-10 to Pin 2 of Arduino and connected the RX Pin of HM-10 to Pin 3 of Arduino.

I did the same connections on my teensy board. But I had to add this part on the code "while (!Serial) ;" to display a text on the serial monitor.
but its stuck on "Searching on myo…" but in Arduino it will display "connected"

Through my research.. I think that it has something to do with SoftwareSerial but I'm not really sure. Also, maybe pin 2 and 3 are not the right pins to connect the Rx and Tx of the HM-10 when it comes to teensy 3.2??

I'll really appreciate your help guys.
Thank you so much!
 
I am assuming that you flashed the HM-10/11 successfully and were able to run the program on the UNO as you stated.

Use one of the hardware serial ports on the Teensy 3.2 and not software serial. TX/RX connections should be to the appropriate pins as has already been linked.

Since both the Teensy 3.2 and HM-10 are 3.3v (unless you have some HM-10 board that I have never seen), do not use the voltage divider resistors that you used with the UNO (see https://github.com/vroland/MyoBridge/wiki/Getting-Started-with-MyoBridge-Firmware)

Modify the program accordingly. This will involve removing software serial and changing references to serial1 or whichever hardware serial port that you chose.
 
Top