我使用此接线图连接到NRF24L01 +模块的ATTiny85:diagram。 ATTiny85定期进入和退出睡眠状态,向接收器发送一些值,即Arduino Uno。如果ATTiny正在运行Arduino电源(3.3v),一切正常。当我从单独的CR2032纽扣电池运行ATTiny时,它可以提供大约3v的电压,而Arduino从不接收任何数据。我有一个状态LED连接到ATTiny,以确保ATTiny正确唤醒,它是。以下是两者的代码:
修改: 将它连接到外部3.3v而不是Uno使一切工作 - 为什么纽扣电池的电压不起作用?我认为一切都低于2.8v,CR2032最低。
ATTiny代码
#include <avr/sleep.h>
#include <avr/interrupt.h>
// Routines to set and claer bits (used in the sleep code)
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define CE_PIN 3
#define CSN_PIN 3 //Since we are using 3 pin configuration we will use same pin for both CE and CSN
#include "RF24.h"
RF24 radio(CE_PIN, CSN_PIN);
byte address[11] = "SimpleNode";
unsigned long payload = 0;
void setup() {
radio.begin(); // Start up the radio
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(15,15); // Max delay between retries & number of retries
radio.openWritingPipe(address); // Write to device address 'SimpleNode'
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(500);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(500);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(1000);
setup_watchdog(6);
}
volatile int watchdog_counter = 0;
ISR(WDT_vect) {
watchdog_counter++;
}
void loop()
{
sleep_mode(); //Go to sleep!
if(watchdog_counter >= 5)
{
digitalWrite(4, HIGH);
watchdog_counter = 0;
payload = 123456;
radio.write( &payload, sizeof(unsigned long) ); //Send data to 'Receiver' ever second
delay(1000);
digitalWrite(4, LOW);
}
}
//Sleep ATTiny85
void system_sleep() {
cbi(ADCSRA,ADEN); // switch Analog to Digitalconverter OFF
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
sleep_mode(); // System actually sleeps here
sleep_disable(); // System continues execution here when watchdog timed out
sbi(ADCSRA,ADEN); // switch Analog to Digitalconverter ON
}
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void setup_watchdog(int ii) {
byte bb;
int ww;
if (ii > 9 ) ii=9;
bb=ii & 7;
if (ii > 7) bb|= (1<<5);
bb|= (1<<WDCE);
ww=bb;
MCUSR &= ~(1<<WDRF);
// start timed sequence
WDTCR |= (1<<WDCE) | (1<<WDE);
// set new watchdog timeout value
WDTCR = bb;
WDTCR |= _BV(WDIE);
}
收件人代码
#define CE_PIN 7
#define CSN_PIN 8
#include <SPI.h>
#include "RF24.h"
RF24 radio(CE_PIN, CSN_PIN);
byte address[11] = "SimpleNode";
unsigned long payload = 0;
void setup() {
while (!Serial);
Serial.begin(115200);
radio.begin(); // Start up the radio
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(15,15); // Max delay between retries & number of retries
radio.openReadingPipe(1, address); // Write to device address 'SimpleNode'
radio.startListening();
Serial.println("Did Setup");
}
void loop(void){
if (radio.available()) {
radio.read( &payload, sizeof(unsigned long) );
if(payload != 0){
Serial.print("Got Payload ");
Serial.println(payload);
}
}
}
这里的问题是ATTiny和Uno需要同时打开才能建立连接,还是与电池有关,还是其他什么呢?任何帮助将不胜感激。
答案 0 :(得分:2)
从电池运行Arduino Nano时,我遇到了同样的问题。 Nano有一个3.3V引脚,用于为NRF24L01 +模块供电。
当电池组电压降至3.3V以下时,3.3V引脚电压也会下降。几分钟后,RF模块没有发送任何消息。
我通过先前为不同项目购买的12V升压调节器来配置电池,从而暂时解决了问题。这些12V然后转到联合国&#34; Nano上的引脚接受6-20V。这种设置效果很好但绝对不是最佳的。
因此,我计划使用3.3V升压调节器,例如 Pololu 3.3V升压稳压器U1V11F3 ,根据供应商的说法,它可以有效地产生3.3V电压输入电压低至0.5V。
我认为这对你的项目也有帮助。