this code works perfectly if connected with usb cable. but as soon as i connect my Arduino nano with battery (two 18650 batteries in series connected to VIN) it runs loop only once. it sends only 0 to another LoRa module (3.3v) and i assume it runs loop only once. blink works without a problem.
#include <SPI.h>
#include <LoRa.h>
int counter = 0;
void setup() {
Serial.begin(9600);
Serial.println("LoRa Sender");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
LoRa.beginPacket();
LoRa.print(counter);
LoRa.endPacket();
counter ++;
delay(3000);
}
Edit
battery pack voltage is 7.01v.
connections I've tried so far:
- 2x 18650 -> VIN = Does not work
- 2x 18650 + regulator -> 5v = Does not work
- 2x 18650 + regulator -> USB = Does work
- USB -> USB = Of course works
when I say it works I mean it Arduino powers up and LoRa module sends data but only once and looks like loop is running only once.
-
it works if i connect usb cable with a power bank. but wont work if i power with regulated 5v on 5v pinLongToeBoy– LongToeBoy2021年08月02日 17:55:20 +00:00Commented Aug 2, 2021 at 17:55
-
voltage on vin pin is 7.01vLongToeBoy– LongToeBoy2021年08月02日 18:00:23 +00:00Commented Aug 2, 2021 at 18:00
-
1A diagram of how you have all this wired together may be relevant.timemage– timemage2021年08月02日 22:13:14 +00:00Commented Aug 2, 2021 at 22:13
-
are you powering the lora with the nano's 5v pin? iirc, Vin goes through an LDO, USB is fed directly.dandavis– dandavis2021年08月02日 22:53:56 +00:00Commented Aug 2, 2021 at 22:53
-
no. i'm powering lora from 3v3 as vcc for lora is not 5v tolerantLongToeBoy– LongToeBoy2021年08月03日 12:37:05 +00:00Commented Aug 3, 2021 at 12:37
1 Answer 1
Again, it would be nice to looking at how you have it set up. You didn't mention any proper signal level conversion, so I'm going to assume there isn't any. My best guess is one of the signals being produced by the Lora module is near the edge of being correct on the ATMega328P.
In comments I asked:
If you measure the "5V" pin does the measured value read appear to be lower in the working scenarios and higher in the failing scenarios?
The reason for the question is that the logic levels of the ATmega328P are dependent on its VCC, what we're nominally calling "5V".
when in working condition 5v output reads 4.48 but when using regulator and its failing 5v pin is constantly at 5.05v
By operating the 328P closer to 3.3V (when you're at 4.48), you're lowering the threshold voltage needed for the Lora's signals to reliably register as a HIGH on the Nano's pins.
You will likely need proper level conversion between the Nano and Lora module, but that will depend on the exact module. Keep in mind that if your module says it has "5V tolerant" data pins, that doesn't mean it produces logic levels acceptable to a 5V Arduino Nano; it just means the module will accept 5V signals at its own inputs.
-
1shouldn't according to datasheet, read ATmega328p operating at 5V everything above 3 V as HIGH?2021年08月03日 17:59:12 +00:00Commented Aug 3, 2021 at 17:59
-
In a roundabout way it does say that. I assume you're talking about the 0.6 * VCC for VIH low spec. I'm aware of that. I can't tell if you genuinely think this is relevant and not understood or you're just screwing with me. On the assumption that you're running at exactly 5V and you have a VIN(min) of 3V, you are still talking to a 3.3V device, nominal, which may not even be operated at exactly 3.3V. Taking the RFM95W as an example, VOH(min) is 0.9 * VCC, or 2.96V at 3.3V VCC. Even if the figure were slightly above 3V, they are still operating with no margin to speak of.timemage– timemage2021年08月06日 14:50:19 +00:00Commented Aug 6, 2021 at 14:50
-