Teensy 4.1 and Arduino Uno Communication by using LoRa

Hi everyone,

Now, I am trying to make a project by using teensy 4.1 and arduino uno. I have my lora module is Ebyte E32 433T20D model. My purpose is when I push the button in the arduino uno, it will send signal to the teensy 4.1 and open the relay on teensy 4.1. I tried solve it for 2 days and I couldn't. Unfortunately I didn't even send simple message to the teensy. Is it possible? Is anyone can help me about that project.

Best regards!
 
Here is the Teensy 4.1 code:
Code:
#include <Wire.h>
#include <MS5611.h>
#include <SD.h>

// Röle pinlerini tanımla
int rolePin1 = 6; // X ekseni için röle 1
int rolePin2 = 7; // X ekseni için röle 2
int rolePin3 = 8; // Y ekseni için röle 3
int rolePin4 = 9; // Y ekseni için röle 4
int rolePinBaro = 4; // Barometre pini

// LED ve Buzzer pinlerini tanımla
int ledPin = 13; // LED pini
int buzzerPin = 10; // Buzzer pini

// Sensör etkinleştirme pinini tanımla
int sensorEnablePin = 2; // Sensörleri etkinleştirme pimi

// MPU6050 I2C adresi
const int MPU6050_ADDR = 0x68;

// MPU6050 register adresleri
const int ACCEL_XOUT_H = 0x3B;
const int PWR_MGMT_1 = 0x6B;

// MS5611 barometre nesnesi
MS5611 baro;
int32_t pressure;
float altitude;
float initial_altitude = 0;
bool initial_altitude_set = false; // İlk okunan mesafenin ayarlanıp ayarlanmadığını takip eder

// SD kart için dosya nesnesi
File dataFile;

// Sistemin veri alma sıklığını ayarlamak için interval ayarlanır.
unsigned long previousMillis = 0;
const long interval = 500; // 500 ms

void setup() {
  // Seri iletişimi başlat
  Serial.begin(9600);
 
  Serial.println("MPU6050 ve MS5611 Sensör Verisi");

  // Röle pinlerini çıkış olarak ayarla
  pinMode(rolePin1, OUTPUT);
  pinMode(rolePin2, OUTPUT);
  pinMode(rolePin3, OUTPUT);
  pinMode(rolePin4, OUTPUT);
  pinMode(rolePinBaro, OUTPUT);

  // Röleleri başlangıçta kapalı konuma getir (HIGH KAPALI/ LOW AÇIK)
  digitalWrite(rolePin1, HIGH);
  digitalWrite(rolePin2, HIGH);
  digitalWrite(rolePin3, HIGH);
  digitalWrite(rolePin4, HIGH);
  digitalWrite(rolePinBaro, HIGH);

  // LED ve Buzzer pinlerini çıkış olarak ayarla
  pinMode(ledPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);

  // LED'i aç ve buzzer'ı 1 saniye çalıştır
  digitalWrite(ledPin, HIGH); // LED'i yak
  digitalWrite(buzzerPin, LOW); // Buzzer'ı çalıştır
  delay(1000); // 1 saniye bekle
  digitalWrite(ledPin, LOW); // LED'i kapat
  digitalWrite(buzzerPin, LOW); // Buzzer'ı kapat

  // Sensör etkinleştirme pinini giriş olarak ayarla
  pinMode(sensorEnablePin, INPUT);

  // I2C bus'ı başlat (Wire1, Pin 16 ve Pin 17)
  Wire1.begin();
 
  // MPU6050'yi uyandır (PWR_MGMT_1 register'ını sıfırla)
  Wire1.beginTransmission(MPU6050_ADDR);
  Wire1.write(PWR_MGMT_1);
  Wire1.write(0); // 0 yazmak, uyku modundan çıkarır
  Wire1.endTransmission(true);

  // MS5611 barometreyi başlat
  Wire.begin();
  baro = MS5611();
  if (baro.begin()) {
    Serial.println("MS5611 başlatıldı.");
  } else {
    Serial.println("MS5611 başlatılamadı!");
  }

  // SD kartı başlat
  if (!SD.begin(BUILTIN_SDCARD)) {
    Serial.println("SD kart başlatılamadı!");
    return;
  } else {
    Serial.println("SD kart başlatıldı.");
  }

  // Verileri kaydetmek için dosyayı aç
  dataFile = SD.open("sensor_data.txt", FILE_WRITE);
  if (!dataFile) {
    Serial.println("Dosya açılamadı!");
  } else {
    Serial.println("Veri kaydı başlatıldı.");
  }
}

void loop() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    if (digitalRead(sensorEnablePin) == HIGH) { // Sensör etkinleştirme pini HIGH durumundaysa
      int16_t accx, accy, accz;

      // MPU6050'den ivme verilerini al
      Wire1.beginTransmission(MPU6050_ADDR);
      Wire1.write(ACCEL_XOUT_H); // İlk veri register'ını belirt
      Wire1.endTransmission(false);
      Wire1.requestFrom(MPU6050_ADDR, 6, true); // 6 byte veri iste

      // Verileri oku
      accx = Wire1.read() << 8 | Wire1.read();
      accy = Wire1.read() << 8 | Wire1.read();
      accz = Wire1.read() << 8 | Wire1.read();

      // X ekseni verilerini eşle
      int degerx = map(accx, -17000, 17000, 0, 180);
      // Y ekseni verilerini eşle
      int degery = map(accy, -17000, 17000, 0, 180);

      // Seri monitöre ivme verilerini yazdır
      Serial.print("X: ");
      Serial.print(degerx);
      Serial.print(" Y: ");
      Serial.println(degery);

      // X ekseni için röle kontrolü
      if (degerx < 75) {
        digitalWrite(rolePin1, LOW); // X ekseni 75'ten küçükse röle 1 kapalı
        digitalWrite(rolePin2, HIGH);  // Röle 2 açık
      } else if (degerx > 105) {
        digitalWrite(rolePin1, HIGH);  // Röle 1 açık
        digitalWrite(rolePin2, LOW); // X ekseni 105'ten büyükse röle 2 kapalı
      } else {
        digitalWrite(rolePin1, HIGH);  // Diğer durumlarda röle 1 açık
        digitalWrite(rolePin2, HIGH); // Diğer durumlarda röle 2 açık
      }

      // Y ekseni için röle kontrolü
      if (degery < 70) {
        digitalWrite(rolePin3, LOW); // Y ekseni 70'ten küçükse röle 3 kapalı
        digitalWrite(rolePin4, HIGH);  // Röle 4 açık
      } else if (degery > 96) {
        digitalWrite(rolePin3, HIGH);  // Röle 3 açık
        digitalWrite(rolePin4, LOW); // Y ekseni 96'dan büyükse röle 4 kapalı
      } else {
        digitalWrite(rolePin3, HIGH);  // Diğer durumlarda röle 3 açık
        digitalWrite(rolePin4, HIGH); // Diğer durumlarda röle 4 açık
      }

      // MS5611 barometreden basınç ve yükseklik verilerini al
      pressure = baro.readPressure(); // Basıncı oku
      altitude = (1.0 - pow((float)pressure / 101325, 0.190284)) * 44330.77; // Yüksekliği hesapla

      // İlk yükseklik değerini ayarla
      if (!initial_altitude_set) {
        initial_altitude = altitude;
        initial_altitude_set = true;
      }

      // Normalize edilmiş yüksekliği hesapla
      float normalized_altitude = altitude - initial_altitude + 1;

      // Seri monitöre basınç ve normalize edilmiş yükseklik verilerini yazdır
      Serial.print("Pressure: ");
      Serial.print(pressure);
      Serial.print(" Pa, Altitude: ");
      Serial.print(normalized_altitude);
      Serial.println(" meters");
      
      // Barometre için röle kontrolü
      if (normalized_altitude > 1) {
        digitalWrite(rolePinBaro, LOW); // Yükseklik 2.05 veya daha büyükse röleyi aç
        Serial.println("Role Acik");
      } else if (normalized_altitude <= 1) {
        digitalWrite(rolePinBaro, HIGH);  // Yükseklik 2.05 veya daha düşükse röleyi kapat
        Serial.println("Role Kapali");
      }

      // SD karta verileri yaz
      if (dataFile) {
        dataFile.print("X: ");
        dataFile.print(degerx);
        dataFile.print(" Y: ");
        dataFile.print(degery);
        dataFile.print(" Pressure: ");
        dataFile.print(pressure);
        dataFile.print(" Pa, Altitude: ");
        dataFile.print(normalized_altitude);
        dataFile.println(" meters");
        dataFile.flush(); // Veriyi hemen SD karta yaz
      } else {
        Serial.println("Dosya yazılamadı!");
      }
    } else { // Sensör etkinleştirme pini LOW durumundaysa
      Serial.println("Sensörler devre dışı.");
      // Sensörler devre dışıyken röleleri kapat
      digitalWrite(rolePin1, HIGH);
      digitalWrite(rolePin2, HIGH);
      digitalWrite(rolePin3, HIGH);
      digitalWrite(rolePin4, HIGH);
      digitalWrite(rolePinBaro, HIGH);
    }
  }
}
 
Teensy 4.1:
Code:
#include <LoRa_E22.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);  // RX, TX
LoRa_E22 E22(&mySerial);

#define M0 7
#define M1 6

struct veriler {
  char deger[15];
} data;

void setup() {
  pinMode(M0, OUTPUT);
  pinMode(M1, OUTPUT);
  digitalWrite(M0, LOW);
  digitalWrite(M1, LOW);
  Serial.begin(9600);
  mySerial.begin(9600);
  E22.begin();
  delay(500);
  Serial.println("Teensy Alıcı Başlatıldı");
}

void loop() {
  if (E22.available() > 1) {
    ResponseStructContainer rsc = E22.receiveMessage(sizeof(veriler));
    
    if (rsc.status.code == 1) {
      struct veriler data = *(veriler*)rsc.data;
      Serial.println("Gelen Mesaj: ");
      Serial.println(data.deger);
    } else {
      Serial.print("Receive failed, code: ");
      Serial.println(rsc.status.code);
    }

    rsc.close();
  } else {
    Serial.println("Veri Yok");
  }
  delay(1000);
}
Arduino Uno Code:
Code:
#include <LoRa_E22.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);  // RX, TX
LoRa_E22 E22(&mySerial);

#define M0 7
#define M1 6

struct veriler {
  char deger[15];
} data;

void setup() {
  pinMode(M0, OUTPUT);
  pinMode(M1, OUTPUT);
  digitalWrite(M0, LOW);
  digitalWrite(M1, LOW);
  Serial.begin(9600);
  mySerial.begin(9600);
  E22.begin();
  delay(500);
  Serial.println("Arduino Verici Başlatıldı");
}

void loop() {
  sprintf(data.deger, "Merhaba");
  ResponseStatus rs = E22.sendFixedMessage(0, 1, 18, &data, sizeof(veriler));
  Serial.print("Veri gönderimi sonucu: ");
  Serial.println(rs.getResponseDescription());
  Serial.print("Gönderilen veri: ");
  Serial.println(data.deger);
  delay(2000);
}
First, I tried to make use code like this but it didn't work
 
On the Teensy 4.1 try hooking up the Lora unit to a real hardware Serial port, such as Serial1 on pins 0 and 1

Pins 10 and 11 are not Hardware Serial pins. The software serial library is setup to only work on Hardware Serial pins.
Code:
// Teensy 4.1
#elif defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41)
  #define SS1_RX  0
  #define SS1_TX  1
  #define SS2_RX  7
  #define SS2_TX  8
  #define SS3_RX 15
  #define SS3_TX 14
  #define SS4_RX 16
  #define SS4_TX 17
  #define SS5_RX 21
  #define SS5_TX 20
  #define SS6_RX 25
  #define SS6_TX 24
  #define SS7_RX 28
  #define SS7_TX 29
  #define SS8_RX 34
  #define SS8_TX 35
 
On the Teensy 4.1 try hooking up the Lora unit to a real hardware Serial port, such as Serial1 on pins 0 and 1

Pins 10 and 11 are not Hardware Serial pins. The software serial library is setup to only work on Hardware Serial pins.
Code:
// Teensy 4.1
#elif defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41)
  #define SS1_RX  0
  #define SS1_TX  1
  #define SS2_RX  7
  #define SS2_TX  8
  #define SS3_RX 15
  #define SS3_TX 14
  #define SS4_RX 16
  #define SS4_TX 17
  #define SS5_RX 21
  #define SS5_TX 20
  #define SS6_RX 25
  #define SS6_TX 24
  #define SS7_RX 28
  #define SS7_TX 29
  #define SS8_RX 34
  #define SS8_TX 35
Thanks for your answer, I also tried 0 and 1 pins but it didn't change :(. I also adjust the lora channels and frequenciess by using RF_Settings software by EBYTE.
 
I use the Lora devices and do not have any problem.
I use this library.
Is there any chance you can share the pin connections on the Teensy and Arduino with me? In addition, if you have a sample code that you use for communication, that would be great for me. Best regards!
 
I don't use it between Uno and Teensy just Teensy to Teensy.
In-fact I have migrated to the E220 devices as they had better availability when E32 was difficult to come by.
I wrote an E220 library based on the E32 library shown above.

Below is example code from this E32 library.
Teensy Receive Code:
Code:
/*

  This example shows how to connect to an EBYTE transceiver
  using a Teensy 3.2

  This code for for the receiver


  connections
  Module      Teensy
  M0          2
  M1          3
  Rx          1 (This is the MCU Tx line)
  Tx          0 (MCU Rx line)
  Aux         4
  Vcc         3V3
  Gnd         Gnd

*/

#include "EBYTE.h"

// connect to any of the Teensy Serial ports
#define ESerial Serial1

#define PIN_M0 2
#define PIN_M1 3
#define PIN_AX 4

// i recommend putting this code in a .h file and including it
// from both the receiver and sender modules

// these are just dummy variables, replace with your own
struct DATA {
  unsigned long Count;
  int Bits;
  float Volts;
  float Amps;

};

int Chan;
DATA MyData;
unsigned long Last;

// create the transceiver object, passing in the serial and pins
EBYTE Transceiver(&ESerial, PIN_M0, PIN_M1, PIN_AX);

void setup() {

  Serial.begin(9600);

  // wait for the serial to connect
  while (!Serial) {}

  // start the transceiver serial port--i have yet to get a different
  // baud rate to work--data sheet says to keep on 9600

  ESerial.begin(9600);

  Serial.println("Starting Reader");

  // this init will set the pinModes for you
  Transceiver.init();

  // all these calls are optional but shown to give examples of what you can do

  // Serial.println(Transceiver.GetAirDataRate());

  // Transceiver.SetAddressH(4);
  // Transceiver.SetAddressL(0);
  // Chan = 15;
  // Transceiver.SetChannel(Chan);
  // save the parameters to the unit,
  // Transceiver.SaveParameters(PERMANENT);

  // you can print all parameters and is good for debugging
  // if your units will not communicate, print the parameters
  // for both sender and receiver and make sure air rates, channel
  // and address is the same
  Transceiver.PrintParameters();

}

void loop() {

  // if the transceiver serial is available, proces incoming data
  // you can also use ESerial.available()
  if (Transceiver.available()) {

    // i highly suggest you send data using structures and not
    // a parsed data--i've always had a hard time getting reliable data using
    // a parsing method
    Transceiver.GetStruct(&MyData, sizeof(MyData));
   
    // You only really need this library to program these EBYTE units.
    // For reading data structures, you can call readBytes directly on the EBYTE Serial object
    // ESerial.readBytes((uint8_t*)& MyData, (uint8_t) sizeof(MyData));

    // dump out what was just received
    Serial.print("Count: "); Serial.println(MyData.Count);
    Serial.print("Bits: "); Serial.println(MyData.Bits);
    Serial.print("Volts: "); Serial.println(MyData.Volts);
    // if you got data, update the checker
    Last = millis();
  }
  else {
    // if the time checker is over some prescribed amount
    // let the user know there is no incoming data
    if ((millis() - Last) > 1000) {
      Serial.println("Searching: ");
      Last = millis();
    }

  }

}

Arduino send code

Code:
/*

  This example shows how to connect to an EBYTE transceiver
  using an Arduino Nano

  This code for for the sender


  connections
  Module      Arduino
  M0          4
  M1          5
  Rx          2 (This is the MCU Tx lined)
  Tx          3 (This is the MCU Rx line)
  Aux         6
  Vcc         3V3
  Gnd         Gnd

*/

#include <SoftwareSerial.h>
#include "EBYTE.h"

#define PIN_RX 2
#define PIN_TX 3
#define PIN_M0 4
#define PIN_M1 5
#define PIN_AX 6

// i recommend putting this code in a .h file and including it
// from both the receiver and sender modules

// these are just dummy variables, replace with your own
struct DATA {
  unsigned long Count;
  int Bits;
  float Volts;
  float Amps;

};

int Chan;
DATA MyData;

// you will need to define the pins to create the serial port
SoftwareSerial ESerial(PIN_RX, PIN_TX);


// create the transceiver object, passing in the serial and pins
EBYTE Transceiver(&ESerial, PIN_M0, PIN_M1, PIN_AX);

void setup() {

  Serial.begin(9600);

  // start the transceiver serial port--i have yet to get a different
  // baud rate to work--data sheet says to keep on 9600
  ESerial.begin(9600);

  Serial.println("Starting Sender");

  // this init will set the pinModes for you
  Transceiver.init();

  // all these calls are optional but shown to give examples of what you can do

  // Serial.println(Transceiver.GetAirDataRate());
  // Serial.println(Transceiver.GetChannel());

  // Transceiver.SetAddressH(1);
  // Transceiver.SetAddressL(0);
  // Chan = 5;
  // Transceiver.SetChannel(Chan);
  // save the parameters to the unit,
  // Transceiver.SaveParameters(PERMANENT);

  // you can print all parameters and is good for debugging
  // if your units will not communicate, print the parameters
  // for both sender and receiver and make sure air rates, channel
  // and address is the same
  Transceiver.PrintParameters();

}

void loop() {

  // measure some data and save to the structure
  MyData.Count++;
  MyData.Bits = analogRead(A0);
  MyData.Volts = MyData.Bits * ( 5.0 / 1024.0 );

  // i highly suggest you send data using structures and not
  // a parsed data--i've always had a hard time getting reliable data using
  // a parsing method
  Transceiver.SendStruct(&MyData, sizeof(MyData));
 
  // You only really need this library to program these EBYTE units.
  // for writing data structures you can call write directly on the EBYTE Serial object
  // ESerial.write((uint8_t*) &Data, PacketSize );
 

  // let the use know something was sent
  Serial.print("Sending: "); Serial.println(MyData.Count);
  delay(1000);


}
 
I don't use it between Uno and Teensy just Teensy to Teensy.
In-fact I have migrated to the E220 devices as they had better availability when E32 was difficult to come by.
I wrote an E220 library based on the E32 library shown above.
Teensy Receive Code:
Code:
/*

  This example shows how to connect to an EBYTE transceiver
  using a Teensy 3.2

  This code for for the receiver


  connections
  Module      Teensy
  M0          2
  M1          3
  Rx          1 (This is the MCU Tx line)
  Tx          0 (MCU Rx line)
  Aux         4
  Vcc         3V3
  Gnd         Gnd

*/

#include "EBYTE.h"

// connect to any of the Teensy Serial ports
#define ESerial Serial1

#define PIN_M0 2
#define PIN_M1 3
#define PIN_AX 4

// i recommend putting this code in a .h file and including it
// from both the receiver and sender modules

// these are just dummy variables, replace with your own
struct DATA {
  unsigned long Count;
  int Bits;
  float Volts;
  float Amps;

};

int Chan;
DATA MyData;
unsigned long Last;

// create the transceiver object, passing in the serial and pins
EBYTE Transceiver(&ESerial, PIN_M0, PIN_M1, PIN_AX);

void setup() {

  Serial.begin(9600);

  // wait for the serial to connect
  while (!Serial) {}

  // start the transceiver serial port--i have yet to get a different
  // baud rate to work--data sheet says to keep on 9600

  ESerial.begin(9600);

  Serial.println("Starting Reader");

  // this init will set the pinModes for you
  Transceiver.init();

  // all these calls are optional but shown to give examples of what you can do

  // Serial.println(Transceiver.GetAirDataRate());

  // Transceiver.SetAddressH(4);
  // Transceiver.SetAddressL(0);
  // Chan = 15;
  // Transceiver.SetChannel(Chan);
  // save the parameters to the unit,
  // Transceiver.SaveParameters(PERMANENT);

  // you can print all parameters and is good for debugging
  // if your units will not communicate, print the parameters
  // for both sender and receiver and make sure air rates, channel
  // and address is the same
  Transceiver.PrintParameters();

}

void loop() {

  // if the transceiver serial is available, proces incoming data
  // you can also use ESerial.available()
  if (Transceiver.available()) {

    // i highly suggest you send data using structures and not
    // a parsed data--i've always had a hard time getting reliable data using
    // a parsing method
    Transceiver.GetStruct(&MyData, sizeof(MyData));
   
    // You only really need this library to program these EBYTE units.
    // For reading data structures, you can call readBytes directly on the EBYTE Serial object
    // ESerial.readBytes((uint8_t*)& MyData, (uint8_t) sizeof(MyData));

    // dump out what was just received
    Serial.print("Count: "); Serial.println(MyData.Count);
    Serial.print("Bits: "); Serial.println(MyData.Bits);
    Serial.print("Volts: "); Serial.println(MyData.Volts);
    // if you got data, update the checker
    Last = millis();
  }
  else {
    // if the time checker is over some prescribed amount
    // let the user know there is no incoming data
    if ((millis() - Last) > 1000) {
      Serial.println("Searching: ");
      Last = millis();
    }

  }

}

Arduino send code

Code:
/*

  This example shows how to connect to an EBYTE transceiver
  using an Arduino Nano

  This code for for the sender


  connections
  Module      Arduino
  M0          4
  M1          5
  Rx          2 (This is the MCU Tx lined)
  Tx          3 (This is the MCU Rx line)
  Aux         6
  Vcc         3V3
  Gnd         Gnd

*/

#include <SoftwareSerial.h>
#include "EBYTE.h"

#define PIN_RX 2
#define PIN_TX 3
#define PIN_M0 4
#define PIN_M1 5
#define PIN_AX 6

// i recommend putting this code in a .h file and including it
// from both the receiver and sender modules

// these are just dummy variables, replace with your own
struct DATA {
  unsigned long Count;
  int Bits;
  float Volts;
  float Amps;

};

int Chan;
DATA MyData;

// you will need to define the pins to create the serial port
SoftwareSerial ESerial(PIN_RX, PIN_TX);


// create the transceiver object, passing in the serial and pins
EBYTE Transceiver(&ESerial, PIN_M0, PIN_M1, PIN_AX);

void setup() {

  Serial.begin(9600);

  // start the transceiver serial port--i have yet to get a different
  // baud rate to work--data sheet says to keep on 9600
  ESerial.begin(9600);

  Serial.println("Starting Sender");

  // this init will set the pinModes for you
  Transceiver.init();

  // all these calls are optional but shown to give examples of what you can do

  // Serial.println(Transceiver.GetAirDataRate());
  // Serial.println(Transceiver.GetChannel());

  // Transceiver.SetAddressH(1);
  // Transceiver.SetAddressL(0);
  // Chan = 5;
  // Transceiver.SetChannel(Chan);
  // save the parameters to the unit,
  // Transceiver.SaveParameters(PERMANENT);

  // you can print all parameters and is good for debugging
  // if your units will not communicate, print the parameters
  // for both sender and receiver and make sure air rates, channel
  // and address is the same
  Transceiver.PrintParameters();

}

void loop() {

  // measure some data and save to the structure
  MyData.Count++;
  MyData.Bits = analogRead(A0);
  MyData.Volts = MyData.Bits * ( 5.0 / 1024.0 );

  // i highly suggest you send data using structures and not
  // a parsed data--i've always had a hard time getting reliable data using
  // a parsing method
  Transceiver.SendStruct(&MyData, sizeof(MyData));
 
  // You only really need this library to program these EBYTE units.
  // for writing data structures you can call write directly on the EBYTE Serial object
  // ESerial.write((uint8_t*) &Data, PacketSize );
 

  // let the use know something was sent
  Serial.print("Sending: "); Serial.println(MyData.Count);
  delay(1000);


}
Thank you so much, I will try this codes as soon as I get home.
 
One last question, in RF_Settings, is adress and channel values are correct? I thought adreeses will be 0 (teensy) and 1 (arduino). Channels will be 23.
 

Attachments

  • 1722086603423.png
    1722086603423.png
    50.6 KB · Views: 26
Yes the code I listed just uses the default settings.
To alter the settings just uncomment the code in the setup() routine.
BE AWARE that as listed the code commented out code uses TWO DIFFERENT channels. THIS WILL NOT WORK.
Make sure that when you uncomment the code, that both the transmit and receive use the same channel.

I always use a .h file so that the stuff which is common between send and receive are not mixed up.

Teensy Receive Code:
Code:
// i recommend putting this code in a .h file and including it
// from both the receiver and sender modules

// these are just dummy variables, replace with your own
struct DATA {
  unsigned long Count;
  int Bits;
  float Volts;
  float Amps;

};

int Chan;
DATA MyData;
unsigned long Last;

// create the transceiver object, passing in the serial and pins
EBYTE Transceiver(&ESerial, PIN_M0, PIN_M1, PIN_AX);

void setup() {

  Serial.begin(9600);

  // wait for the serial to connect
  while (!Serial) {}

  // start the transceiver serial port--i have yet to get a different
  // baud rate to work--data sheet says to keep on 9600

  ESerial.begin(9600);

  Serial.println("Starting Reader");

  // this init will set the pinModes for you
  Transceiver.init();

  // all these calls are optional but shown to give examples of what you can do

   Serial.println(Transceiver.GetAirDataRate());
   Serial.println(Transceiver.GetChannel());

   Transceiver.SetAddressH(1);
   Transceiver.SetAddressL(0);
   Chan = 5;
   Transceiver.SetChannel(Chan);
   save the parameters to the unit,
   Transceiver.SaveParameters(PERMANENT);

  // you can print all parameters and is good for debugging
  // if your units will not communicate, print the parameters
  // for both sender and receiver and make sure air rates, channel
  // and address is the same
  Transceiver.PrintParameters();

}

void loop() {

  // if the transceiver serial is available, proces incoming data
  // you can also use ESerial.available()
  if (Transceiver.available()) {

    // i highly suggest you send data using structures and not
    // a parsed data--i've always had a hard time getting reliable data using
    // a parsing method
    Transceiver.GetStruct(&MyData, sizeof(MyData));
 
    // You only really need this library to program these EBYTE units.
    // For reading data structures, you can call readBytes directly on the EBYTE Serial object
    // ESerial.readBytes((uint8_t*)& MyData, (uint8_t) sizeof(MyData));

    // dump out what was just received
    Serial.print("Count: "); Serial.println(MyData.Count);
    Serial.print("Bits: "); Serial.println(MyData.Bits);
    Serial.print("Volts: "); Serial.println(MyData.Volts);
    // if you got data, update the checker
    Last = millis();
  }
  else {
    // if the time checker is over some prescribed amount
    // let the user know there is no incoming data
    if ((millis() - Last) > 1000) {
      Serial.println("Searching: ");
      Last = millis();
    }

  }

}

Arduino send code


Code:
/*

  This example shows how to connect to an EBYTE transceiver
  using an Arduino Nano

  This code for for the sender


  connections
  Module      Arduino
  M0          4
  M1          5
  Rx          2 (This is the MCU Tx lined)
  Tx          3 (This is the MCU Rx line)
  Aux         6
  Vcc         3V3
  Gnd         Gnd

*/

#include <SoftwareSerial.h>
#include "EBYTE.h"

#define PIN_RX 2
#define PIN_TX 3
#define PIN_M0 4
#define PIN_M1 5
#define PIN_AX 6

// i recommend putting this code in a .h file and including it
// from both the receiver and sender modules

// these are just dummy variables, replace with your own
struct DATA {
  unsigned long Count;
  int Bits;
  float Volts;
  float Amps;

};

int Chan;
DATA MyData;

// you will need to define the pins to create the serial port
SoftwareSerial ESerial(PIN_RX, PIN_TX);


// create the transceiver object, passing in the serial and pins
EBYTE Transceiver(&ESerial, PIN_M0, PIN_M1, PIN_AX);

void setup() {

  Serial.begin(9600);

  // start the transceiver serial port--i have yet to get a different
  // baud rate to work--data sheet says to keep on 9600
  ESerial.begin(9600);

  Serial.println("Starting Sender");

  // this init will set the pinModes for you
  Transceiver.init();

  // all these calls are optional but shown to give examples of what you can do

   Serial.println(Transceiver.GetAirDataRate());
   Serial.println(Transceiver.GetChannel());

   Transceiver.SetAddressH(1);
   Transceiver.SetAddressL(0);
   Chan = 5;
   Transceiver.SetChannel(Chan);
  // save the parameters to the unit,
   Transceiver.SaveParameters(PERMANENT);

  // you can print all parameters and is good for debugging
  // if your units will not communicate, print the parameters
  // for both sender and receiver and make sure air rates, channel
  // and address is the same
  Transceiver.PrintParameters();

}

void loop() {

  // measure some data and save to the structure
  MyData.Count++;
  MyData.Bits = analogRead(A0);
  MyData.Volts = MyData.Bits * ( 5.0 / 1024.0 );

  // i highly suggest you send data using structures and not
  // a parsed data--i've always had a hard time getting reliable data using
  // a parsing method
  Transceiver.SendStruct(&MyData, sizeof(MyData));
 
  // You only really need this library to program these EBYTE units.
  // for writing data structures you can call write directly on the EBYTE Serial object
  // ESerial.write((uint8_t*) &Data, PacketSize );
 

  // let the use know something was sent
  Serial.print("Sending: "); Serial.println(MyData.Count);
  delay(1000);


}
 
IGNORE WHAT I SAID ABOUT ADDRESSES etc. They are only valid if you are sending data in Fixed transmission mode.
If you are only using two devices then sending in Transparent Transmission is the way to go. Address is ignored in this setup.
If you do want to use Fixed Transmission then you have to send the address (Hi & Lo) and channel in a preamble before the data for each message.
 
IGNORE WHAT I SAID ABOUT ADDRESSES etc. They are only valid if you are sending data in Fixed transmission mode.
If you are only using two devices then sending in Transparent Transmission is the way to go. Address is ignored in this setup.
If you do want to use Fixed Transmission then you have to send the address (Hi & Lo) and channel in a preamble before the data for each message.
Thank you so much for informing me. I will remind you as soon as I try
 
The Manual for the E32 is not a good as the manual for the E220.
Reading between the lines I can see the following.
When the Transmitter sees a Fixed Transmission, it changes its address and channel to that of the recipient.
After the data has been transmitted it switches back to it's address and channel before the transmission.
So it would seem to be a special case of the Transparent Transmission.

By the way I first started off using the same library as you.
I changed when I found that it would work fine for a while, then just stop working.
Kris Kasprzak's library is constructed in a much more straight forward manner and is much simpler.
Kris is also a member of this forum (@KrisKasprzak).
 
Hi everyone,

Now, I am trying to make a project by using teensy 4.1 and arduino uno. I have my lora module is Ebyte E32 433T20D model. My purpose is when I push the button in the arduino uno, it will send signal to the teensy 4.1 and open the relay on teensy 4.1. I tried solve it for 2 days and I couldn't. Unfortunately I didn't even send simple message to the teensy. Is it possible? Is anyone can help me about that project.

Best regards!
One thing to check is the voltage. Normally the Uno runs at 5 volts, and the Teensy runs at 3.3 volts. Unfortunately, if you feed 5 volts from the Unto to the Teensy, it can damage the Teensy. The damage might be only to the pins that are connected, or it can even make the whole Teensy inoperable.

Another thing to check is whether the grounds for the Teensy and Arduino are connected unless you are using an optocoupler.

If you can run the Uno at 3.3v it would be better, but I don't remember if it was an option (and it may be the LORA requires 5v).

Alternatively, you need to convert the voltages. There are 3 main ways to do this:
  • Assuming the communication is directional (i.e. one pin is always communicating from the remote device and another pin communicating from the host), you can put a resistor inline to drop the voltage. You would have to do a google search for the proper resistor. Note, I believe I2C is bi-directional, and you can't just use the resistor to drop voltage. But UART and SPI communications are uni-directional.
  • There are voltage level shifters that you insert between the two systems. For lower speed traffic, you can use the level shifters that can do the voltage shifting in both directions. For high speed traffic, such as neopixels, you may need faster level shifters that only translate voltage in one direction. Back in the day, I used to use this logic level shifter for i2c and neopixels (with external pullups for neopixels). An example of a uni-directional shifter that is fast enough for neopixels is: 74AHCT125 shifter.
  • You hook up an optocoupler which means the Arduino and Teensy electrical connections are never connected. An optocoupler is a unit with two wires for input and two wires for output. If the input wires complete a circuit (i.e. one is ground and the other is connected to a pin set high), it turns on a LED within the sealed compartment. On the other side is a light sensor, and if it sees light, it completes the circuit. Of course, there are speed limits in terms of how fast the LED can be turned on and the sensor can read it. And an optocoupler is uni-directional.
  • I can imagine other ways that are similar to the optocoupler where the Arduino does something and the Teensy senses the action without the Teensy and Arduino sharing electrical circuits (using IR, having a servo press a button, etc.).
Though it begs the question of why have two boards. Why not hook the LORA directly to the Teensy?
 
Last edited:
I don't use it between Uno and Teensy just Teensy to Teensy.
In-fact I have migrated to the E220 devices as they had better availability when E32 was difficult to come by.
I wrote an E220 library based on the E32 library shown above.

Below is example code from this E32 library.
Teensy Receive Code:
Code:
/*

  This example shows how to connect to an EBYTE transceiver
  using a Teensy 3.2

  This code for for the receiver


  connections
  Module      Teensy
  M0          2
  M1          3
  Rx          1 (This is the MCU Tx line)
  Tx          0 (MCU Rx line)
  Aux         4
  Vcc         3V3
  Gnd         Gnd

*/

#include "EBYTE.h"

// connect to any of the Teensy Serial ports
#define ESerial Serial1

#define PIN_M0 2
#define PIN_M1 3
#define PIN_AX 4

// i recommend putting this code in a .h file and including it
// from both the receiver and sender modules

// these are just dummy variables, replace with your own
struct DATA {
  unsigned long Count;
  int Bits;
  float Volts;
  float Amps;

};

int Chan;
DATA MyData;
unsigned long Last;

// create the transceiver object, passing in the serial and pins
EBYTE Transceiver(&ESerial, PIN_M0, PIN_M1, PIN_AX);

void setup() {

  Serial.begin(9600);

  // wait for the serial to connect
  while (!Serial) {}

  // start the transceiver serial port--i have yet to get a different
  // baud rate to work--data sheet says to keep on 9600

  ESerial.begin(9600);

  Serial.println("Starting Reader");

  // this init will set the pinModes for you
  Transceiver.init();

  // all these calls are optional but shown to give examples of what you can do

  // Serial.println(Transceiver.GetAirDataRate());

  // Transceiver.SetAddressH(4);
  // Transceiver.SetAddressL(0);
  // Chan = 15;
  // Transceiver.SetChannel(Chan);
  // save the parameters to the unit,
  // Transceiver.SaveParameters(PERMANENT);

  // you can print all parameters and is good for debugging
  // if your units will not communicate, print the parameters
  // for both sender and receiver and make sure air rates, channel
  // and address is the same
  Transceiver.PrintParameters();

}

void loop() {

  // if the transceiver serial is available, proces incoming data
  // you can also use ESerial.available()
  if (Transceiver.available()) {

    // i highly suggest you send data using structures and not
    // a parsed data--i've always had a hard time getting reliable data using
    // a parsing method
    Transceiver.GetStruct(&MyData, sizeof(MyData));
  
    // You only really need this library to program these EBYTE units.
    // For reading data structures, you can call readBytes directly on the EBYTE Serial object
    // ESerial.readBytes((uint8_t*)& MyData, (uint8_t) sizeof(MyData));

    // dump out what was just received
    Serial.print("Count: "); Serial.println(MyData.Count);
    Serial.print("Bits: "); Serial.println(MyData.Bits);
    Serial.print("Volts: "); Serial.println(MyData.Volts);
    // if you got data, update the checker
    Last = millis();
  }
  else {
    // if the time checker is over some prescribed amount
    // let the user know there is no incoming data
    if ((millis() - Last) > 1000) {
      Serial.println("Searching: ");
      Last = millis();
    }

  }

}

Arduino send code

Code:
/*

  This example shows how to connect to an EBYTE transceiver
  using an Arduino Nano

  This code for for the sender


  connections
  Module      Arduino
  M0          4
  M1          5
  Rx          2 (This is the MCU Tx lined)
  Tx          3 (This is the MCU Rx line)
  Aux         6
  Vcc         3V3
  Gnd         Gnd

*/

#include <SoftwareSerial.h>
#include "EBYTE.h"

#define PIN_RX 2
#define PIN_TX 3
#define PIN_M0 4
#define PIN_M1 5
#define PIN_AX 6

// i recommend putting this code in a .h file and including it
// from both the receiver and sender modules

// these are just dummy variables, replace with your own
struct DATA {
  unsigned long Count;
  int Bits;
  float Volts;
  float Amps;

};

int Chan;
DATA MyData;

// you will need to define the pins to create the serial port
SoftwareSerial ESerial(PIN_RX, PIN_TX);


// create the transceiver object, passing in the serial and pins
EBYTE Transceiver(&ESerial, PIN_M0, PIN_M1, PIN_AX);

void setup() {

  Serial.begin(9600);

  // start the transceiver serial port--i have yet to get a different
  // baud rate to work--data sheet says to keep on 9600
  ESerial.begin(9600);

  Serial.println("Starting Sender");

  // this init will set the pinModes for you
  Transceiver.init();

  // all these calls are optional but shown to give examples of what you can do

  // Serial.println(Transceiver.GetAirDataRate());
  // Serial.println(Transceiver.GetChannel());

  // Transceiver.SetAddressH(1);
  // Transceiver.SetAddressL(0);
  // Chan = 5;
  // Transceiver.SetChannel(Chan);
  // save the parameters to the unit,
  // Transceiver.SaveParameters(PERMANENT);

  // you can print all parameters and is good for debugging
  // if your units will not communicate, print the parameters
  // for both sender and receiver and make sure air rates, channel
  // and address is the same
  Transceiver.PrintParameters();

}

void loop() {

  // measure some data and save to the structure
  MyData.Count++;
  MyData.Bits = analogRead(A0);
  MyData.Volts = MyData.Bits * ( 5.0 / 1024.0 );

  // i highly suggest you send data using structures and not
  // a parsed data--i've always had a hard time getting reliable data using
  // a parsing method
  Transceiver.SendStruct(&MyData, sizeof(MyData));
 
  // You only really need this library to program these EBYTE units.
  // for writing data structures you can call write directly on the EBYTE Serial object
  // ESerial.write((uint8_t*) &Data, PacketSize );
 

  // let the use know something was sent
  Serial.print("Sending: "); Serial.println(MyData.Count);
  delay(1000);


}
Hello again, I installed the library first then, I made the pin connections. After that I tried these codes. Arduino sends data but teensy coulnd't get the data. Teensy serial port message is just 'Searching:'. I tried to change something but I couldn't understand the what the problem is. Unfortunately, I'm pretty new at this. According to your message I removed the comment lines etc. but it didnt change. Teensy 4.1 code:
Code:
#include "EBYTE.h"

#define ESerial Serial1

#define PIN_M0 2
#define PIN_M1 3
#define PIN_AX 4

struct DATA {
  unsigned long Count;
  int Bits;
  float Volts;
  float Amps;
};

int Chan;
DATA MyData;
unsigned long Last;

EBYTE Transceiver(&ESerial, PIN_M0, PIN_M1, PIN_AX);

void setup() {
  Serial.begin(9600);

  while (!Serial) {}

  ESerial.begin(9600);

  Serial.println("Starting Reader");

  Transceiver.init();

  Serial.println(Transceiver.GetAirDataRate());
  Serial.println(Transceiver.GetChannel());

  Transceiver.SetAddressH(1);
  Transceiver.SetAddressL(0);
  Chan = 5;
  Transceiver.SetChannel(Chan);
  Transceiver.SaveParameters(PERMANENT);

  Transceiver.PrintParameters();
}

void loop() {
  if (Transceiver.available()) {
    Transceiver.GetStruct(&MyData, sizeof(MyData));

    Serial.print("Count: "); Serial.println(MyData.Count);
    Serial.print("Bits: "); Serial.println(MyData.Bits);
    Serial.print("Volts: "); Serial.println(MyData.Volts);

    Last = millis();
  }
  else {
    if ((millis() - Last) > 1000) {
      Serial.println("Searching: ");
      Last = millis();
    }
  }
}
Arduino code:
Code:
#include <SoftwareSerial.h>
#include "EBYTE.h"

#define PIN_RX 2
#define PIN_TX 3
#define PIN_M0 4
#define PIN_M1 5
#define PIN_AX 6

struct DATA {
  unsigned long Count;
  int Bits;
  float Volts;
  float Amps;
};

int Chan;
DATA MyData;

SoftwareSerial ESerial(PIN_RX, PIN_TX);
EBYTE Transceiver(&ESerial, PIN_M0, PIN_M1, PIN_AX);

void setup() {
  Serial.begin(9600);

  ESerial.begin(9600);

  Serial.println("Starting Sender");

  Transceiver.init();

  Serial.println(Transceiver.GetAirDataRate());
  Serial.println(Transceiver.GetChannel());

  Transceiver.SetAddressH(1);
  Transceiver.SetAddressL(0);
  Chan = 5;
  Transceiver.SetChannel(Chan);
  Transceiver.SaveParameters(PERMANENT);

  Transceiver.PrintParameters();
}

void loop() {
  MyData.Count++;
  MyData.Bits = analogRead(A0);
  MyData.Volts = MyData.Bits * (5.0 / 1024.0);

  Transceiver.SendStruct(&MyData, sizeof(MyData));

  Serial.print("Sending: "); Serial.println(MyData.Count);
  delay(1000);
}
 
I did say at post #15 to ignore all I said about addresses. That's only relevant if you are using Fixed Transmission, which you won't be.
Just wire it up as per the examples in the EBYTE.h library and DO NOT uncomment any of the lines.
If you are still having problems send photos of your setups with clear pictures of the wiring from the Arduino to E32 LORA and from Teensy to it's E32 LORA.
 
I installed the EBYTE library but there is an error while uploading code to the teensy.
 

Attachments

  • 1722183580888.png
    1722183580888.png
    83.5 KB · Views: 33
Back
Top