Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Teensy 3.2 BLE Connection

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Posts
    2

    Teensy 3.2 BLE Connection

    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!
    Last edited by oceanblue; 12-23-2018 at 08:10 AM. Reason: typographical error

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,794
    IIRC softwareserial is not ideal for use on Teensy - but when used it has to be on actual Serial capable pins. Move wires and update code to use pins for Serial1 or 2 if softwareserial is really needed.

    Also the UNO can only present USB by having another onboard chip, which does not break PC connection during reprogramming. Where the Teensy itself has real USB hardware that is much more capable - but goes offline when the code is not running - like during an upload and restart and without while(!Serial) or while(!Serial && millis()<3000) the Teensy is up and running a couple hundred millis typically before the PC establishes the connection resulting in lost Serial output during that time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •