Working Arduino code is broken for Teensy LC. Help needed for working HC-12 code

Status
Not open for further replies.

Schnitzel

New member
I have a piece of code that works perfectly fine for Arduino uno and micro, however trying to get it to work for Teensy LC has been hell.

The goal is to have the Arduino communicate to the Teensy LC using the HC-12 long range transmitter/transceiver module. and this tutorial

Code that works for Arduino, needs translation for Teensy, I'll spare you my hopeless attempts:
Code:
/*    Arduino Long Range Wireless Communication using HC-12
                      Example 01
   by Dejan Nedelkovski, www.HowToMechatronics.com
*/

#include <SoftwareSerial.h>

SoftwareSerial HC12(0, 11); // HC-12 TX Pin, HC-12 RX Pin

void setup() {
  Serial.begin(9600);             // Serial port to computer
  HC12.begin(9600);               // Serial port to HC12

}

void loop() {
  while (HC12.available()) {        // If HC-12 has data
    Serial.write(HC12.read());      // Send the data to Serial monitor
  }
  while (Serial.available()) {      // If Serial monitor has data
    HC12.write(Serial.read());      // Send that data to HC-12
  }
}

The RX and TX pin of the HC-12 are connected respectively to pin 0 and 1 on the Teensy.

I'm asking your help for the software side of things.
 
I would think something like:
Code:
/*    Arduino Long Range Wireless Communication using HC-12
                      Example 01
   by Dejan Nedelkovski, www.HowToMechatronics.com
*/


void setup() {
  Serial.begin(9600);             // Serial port to computer
  Serial1.begin(9600);               // Serial port to HC12

}

void loop() {
  while (Serial1.available()) {        // If HC-12 has data
    Serial.write(Serial1.read());      // Send the data to Serial monitor
  }
  while (Serial.available()) {      // If Serial monitor has data
    Serial1.write(Serial.read());      // Send that data to HC-12
  }
}

Which is more or less a stripped down version of the Teensy Example program: File->Examples->Teensy->Serial->EchoBoth
Or there is a better one in the examples->USB_Serial->USBToSerial
 
Status
Not open for further replies.
Back
Top