Bluetooth communication between Teensy 3.2 and Arduino Uno

Status
Not open for further replies.

qsanders

Member
Hi,

I have been looking through the threads for quite a few hours now and haven't really found the answer to my problem. Currently, I have a teensy 3.2 and a force sensor connected to the teensy. I also have another object that is instrumented with additional sensors and is connected to an arduino uno which is connected through usb to my computer. Connected to the teensy I have an HC-05. I also have an HC-05 connected to the arduino as well. I have configured the teensy HC-05 so that it is in slave mode, and have configured the arduino uno HC-05 so that it is in master mode. All I am trying to do is send the data from the teensy to the serial monitor of the arduino uno using the bluetooth modules. If anyone could shed any light on how to go about this it would be greatly appreciated.
 
I followed the example in martyn currey post. That didn't seem to work. So far this is what I have working (code pasted below). However, what's strange is that I am able to send data from the arduino just fine but I am not able to send data from the teensy to the arduino. I tried switching all of the Serial's to Serial1 but that didn't seem to do the trick.

char c = ' ';

void setup()

{
Serial.begin(9600);
Serial.println("__________Engineers Garage______________");
Serial.println("---------------Master------------------");

Serial1.begin(9600);

}

void loop()

{
if (Serial1.available())

{
c = Serial1.read();

Serial.write(c);

}

if (Serial.available())

{

c = Serial.read();

Serial1.write(c);

}

}

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(0, 1); // RX | TX

void setup()
{
Serial.begin(9600);
Serial.println("__________Engineers Garage______________");

Serial.println("---------------Slave------------------");

BTserial.begin(9600);

}

void loop()

{

if (BTSerial.available())

Serial.write(BTSerial.read());

if (Serial.available())

BTSerial.write(Serial.read());

}
 
Formatted post #3 code with IDE CTRL+T and removed extra lines. Used '#' on toolbar to add CODE tags for display. Assuming Master is Teensy as it uses hardware serial. Put delay in setup for Teensy Serial USB to connect.

Never read the linked code - changed .write to .print on Teensy ??? never sure which is expected when it matters.

Not sure what starts transfer between the two? Is this any better?

Code:
char c = ' ';

void setup()
{
  Serial.begin(9600);
  while (!Serial && millis() < 2000) ; // wait
  Serial.println("__________Engineers Garage_____TEENSY_________");
  Serial.println("---------------Master------------------");
  Serial1.begin(9600);
}

void loop()
{
  while (Serial1.available())
  {
    c = Serial1.read();
    Serial.print(c);
  }

  while (Serial.available())
  {
    c =  Serial.read();
    Serial1.print(c);
  }
}
Code:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(0, 1); // RX | TX

void setup()
{
  Serial.begin(9600);
  Serial.println("__________Engineers Garage______Arduino Uno________");
  Serial.println("---------------Slave------------------");

  BTserial.begin(9600);
}

void loop()
{

  if (BTSerial.available())
    Serial.write(BTSerial.read());

  if (Serial.available())
    BTSerial.write(Serial.read());
}
 
No unfortunately I am still getting the same result. For some reason when I use that code when I type something into the serial monitor for the arduino uno it sends to the teensy just fine. But, when I type something into the serial monitor of the teensy it doesn't seen anything over to the arduino uno serial monitor.
 
I think I might of figured it out.

On the teensy I had one hc-05 configured to master and (tx pin --> rx pin, rx pin --> tx pin) , but on the uno I have the hc-05 configured to slave and (tx pin --> tx pin, and rx pin --> rx pin).

when I switched the pins on the arduino so that (tx --> rx, rx-->tx) I was able to send data from the teensy to the uno. But I am not able to send data from the uno to the teensy anymore. The other thing that happend is that it's only allowing me to send 2 characters. The third character always disappears and is replaced by a "?". I attached a picture of what that looks like. Error_Serial_monitor.jpg
 
Odd that both SerMon windows show :: "______Arduino Uno________" ... "--Slave---"
With no print from Teensy showing?

It is easy to Cross the Rx/Tx between the UNO and T_3.2? Taking the hc-05's out of the loop for a test?
 
It's very strange. When I take out the hc-05's It no longer shows :: "______Arduino Uno________" ... "--Slave---" on both SerMon windows. It shows :: "______Teensy________" ... "--Master---" on the proper SerMon but now I can only send data from the uno to the teensy and not from the teensy to the uno.

This was reversed when I had the hc-05s plugged in. But as was shown early the SerMon showed the same thing in that instance.
 
Not that familiar with UNO and never used softserial - not sure what pins that is on with the UNO - but AFAIK the pins for Serial are also connected to USB? There may be confusion there is using the same pins.

Perhaps the soft serial will work on pins other than those shared with USB - and that might show it working better.

The Serial crossed RX><TX between the two should work properly and understandably before expecting the hc-05's to work it seems.
 
Status
Not open for further replies.
Back
Top