Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Teensy 3.2 BLE Connection

Status
Not open for further replies.

oceanblue

New Member
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!
 
One thing to be aware of with software serial is that it's not full duplex and will not simultaneously transmit and receive. I see that the Teensy LC has 3 serial ports. Can you use that or are you limited to the Teensy 2.0?

Also, are you running at 5V or 3.3V?

Mike.
 
One thing to be aware of with software serial is that it's not full duplex and will not simultaneously transmit and receive. I see that the Teensy LC has 3 serial ports. Can you use that or are you limited to the Teensy 2.0?

Also, are you running at 5V or 3.3V?

Mike.

Hello Sir. Thank you for your reply. I have a Teensy 3.2 and I am running at 3.3V.
 
The Teensy 3.2 has 3 Serial ports. Maybe you can try using the second one on pins 9 (RX) and 10(TX).

Mike.
Edit, they are labeled from zero so the second serial port is on pins 0(RX1) and 1(TX1).
 
Just checked what I did with a Leonardo board and a HC05 module connected to the second serial port,
Code:
  Serial1.begin(9600);      // USART serial port
  Serial1.print("AT+NAMEZumo");
The while (!Serial) ; line is needed on boards that use the main chip for USB - the reset means they need time to connect to the PC again.

Mike.
 
The OP’s query has made the rounds on several boards and the responses have been similar.

It is notable that the project uses a custom flashed HM-11. I suppose an HM-10 works also since that is what the OP has, apparently. used successfully with an Arduino Uno. Because it relies on the Arduino library written specifically for Arduino boards like the Uno, there are, potentially, many reasons why it might not work with a Teensy 3.2, without additional modifications that are not discussed below.

The program in question is printFirmwareInfo.ino available at https://github.com/vroland/MyoBridg...mples/printFirmwareInfo/printFirmwareInfo.ino

The first modification involves a resistor divider that is used on the Arduino Uno Tx pin to drop the 5v to a voltage compatible with the HM-11 (and HM-10). That is, from 5v to 3.3v. You can see the simple divider here https://github.com/vroland/MyoBridge/wiki/Getting-Started-with-MyoBridge-Firmware

If those resistors are not removed, serial transmission between the HM and Teensy will not work because the Teensy 3.2 is also a 3.3v device and the resistors would likely drop the Tx line too low for a “high” level to be received by the HM. That alone can be why the program does not work.

The Uno version in printFirmwareInfo.ino uses software serial. Since hardware serial is almost always better (IMO) and the Teensy has multiple hardware serial ports, it is natural for anyone to advise that the connections to the HM device use hardware serial.

This page https://www.pjrc.com/teensy/td_uart.html shows you the three sets of pins that can be used for the different hardware serial ports. When there is more than one for Tx and Rx, that means that alternate pins can be used and to do so requires a software command (see Serial1.setTX(pin), for example).

For simplicity, let’s say you want to change the software serial to the hardware Serial3 on the Teensy. You would now connect the HM10 Tx and Rx to the Teensy hardware pins for Rx and Tx, respectively – that is, pins 7 and 8.

Now, only a few changes need to be made to printFirmwareInfo.ino.

First remove (or comment out) the line:
#include <SoftwareSerial.h> since you are not going to use software serial.

Replace the statement: SoftwareSerial bridgeSerial(2,3);
With: #define bridgeSerial Serial3

Finally, to be cautious, replace the statement:
bridgeSerial.begin(115200);

With: bridgeSerial.begin(115200, SERIAL_8N1);

All of the Serial.print statements can be left as is because the Teensy will use those with the USB port in (what should be) a compatible fashion as the Uno, although there is more flexibility, see https://www.pjrc.com/teensy/td_serial.html

With those few changes, it might work…and I also might have missed, forgotten, or messed up something.

Hope this helps.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top