Hello,
I recently made a simple LoRa remote control. This remote control would use an Arduino Nano to send out a serial command via a Reyax RYLR896 LoRa module that would transmit to a receiver. Pressing a button on the remote control would turn on an LED on the receiver. Very simple, worked flawlessly.
I have since attempted to remove the Arduino Nano from the remote control side and move the entire project over to an Atmel Tiny85 (I THINK this is the same as the Attiny85). Aside from changing the GPIO pins, the code remains essentually unchanged. Unfortunately, it does not work.
Pressing the button on the remote works, as the "transmit led" on the remote flashes, letting me know that the button has indeed been pushed and detected, however the LoRa singal is not transmitting. I've never used the Software Serial library on one of these Attiny chips before, so it's possible that one of my settings is incorrect and would appreciate any advice.
NOTE: This code DOES compile and upload to the Attiny chip.
Transmitter Code:
#include <SoftwareSerial.h>
#define transLed 4
#define recLed 3
#define Rx 2
#define Tx 1
#define button 0
SoftwareSerial LoraSerial(Rx, Tx);
String incomingString;
int oldState, newState, state = 0;
const unsigned long ackTime = 5000;
//unsigned long previousTime = 0;
unsigned long timerStart = 0;
bool ack = true;
void setup() {
pinMode(transLed, OUTPUT);
pinMode(recLed, OUTPUT);
pinMode(button, INPUT);
//Serial.begin(9600); // Serial Terminal
LoraSerial.begin(9600); // LoRa COMMS
}
void loop() {
//unsigned long currentTime = millis();
// Send a message to Receiver when button is pushed
if(digitalRead(button) == HIGH){
if(state == 0){
LoraSerial.println("AT+SEND=715,1,H");
//Serial.println("H");
state = 1;
timerStart = millis();
ack = false;
}
else {
LoraSerial.println("AT+SEND=715,1,L");
//Serial.println("L");
state = 0;
timerStart = millis();
ack = false;
}
digitalWrite(transLed, HIGH);
delay(250);
digitalWrite(transLed, LOW);
}
// Flash an LED if Acknowledgement is received from Receiver
if(LoraSerial.available()){
incomingString = LoraSerial.readString();
if(incomingString.indexOf("A") > 0){
//Serial.println("Acknowledged!");
ack = true;
digitalWrite(recLed, HIGH);
delay(250);
digitalWrite(recLed, LOW);
}
}
if((!ack) && (millis() - timerStart >= ackTime)){
// Blink LEDs
digitalWrite(transLed, HIGH);
digitalWrite(recLed, HIGH);
delay(100);
digitalWrite(transLed, LOW);
digitalWrite(recLed, LOW);
delay(100);
digitalWrite(transLed, HIGH);
digitalWrite(recLed, HIGH);
delay(100);
digitalWrite(transLed, LOW);
digitalWrite(recLed, LOW);
delay(100);
digitalWrite(transLed, HIGH);
digitalWrite(recLed, HIGH);
delay(100);
digitalWrite(transLed, LOW);
digitalWrite(recLed, LOW);
delay(100);
state = !state;
ack = true;
timerStart = 0;
//Serial.println("Ack FAIL");
}
}
NOTE: I've commented out the sections of code that are meant to print a messages to the serial console. I did this, just in case the Attiny85 cannot handle multiple serial lines.
THINGS TO CONSIDER
-
Is the clock source set correctly? I've seen conflicting details on what frequency the internal clock should be set to on Attiny chips when transmitting serial data. I've tried both 1MHz and 8MHz, unsuccessfully.
-
Does the baud rate matter? For the initial project, I had the baud rate set (on both the Arduinos and the LoRa Modules) to 9600, which worked fine. I've seen some reports that the Attiny chips work best with 38400. I've tried both, to no avail.
-
Can this Attiny85 source the correct current to transmit data via the LoRa Module? I recognize that the Arduino Nano that I used initially would trasmit serial data at 5V. I'm unsure what this Attiny transmits at. I am powering it with 5V and I believe the GPIOs that flash the LEDs only supply 2 Volts. I'm unsure if this matters.
-
I'm using a voltage divider to power the LoRa Module as the Attiny operates at 5V but the LoRa module operates at only 3.3V. One thing I noticed is that, when I remove the LoRa module, the voltage across the Vcc and Gnd are roughly 3.3V, however when I plug back in the module, my meter only reads ~2V. This is a bit strange to me, but that could also mean that the forward voltage drop of the module is 1.3V. Am I supplying enough power?
-
Are the pins that I am using to transmit data acceptable? Again, I'm not super familiar with these Attiny chips but have seen nothing to indicate that specific pins need to be used for RX and TX.
Unless there's something else, those are all of my ideas. Please let me know if I need to clarify any details and/or if any additional information is needs. I can post details about the circuit diagram, however I've quadruple-checked everything and I don't believe there are any faults in the wiring. I've be happy to be proven wrong.
Thank you all in advance for your advice and knowledge.
Best,
Joe