#include <GyverPower.h>
#include <powerConstants.h>
#define avoidPin A1 // задаем имя для порта с датчиком
#define B1Pin 2
int avoid;
void setup() {
Serial.begin(9600); // инициализация монитора порта
pinMode(B1Pin, INPUT);
pinMode(avoidPin, INPUT);
power.autoCalibrate();
power.hardwareDisable(PWR_ADC | PWR_TIMER1);
power.setSystemPrescaler(PRESCALER_2);
power.setSleepMode(STANDBY_SLEEP);
}
void loop() {
boolean B1val = digitalRead(B1Pin);
avoid = digitalRead(avoidPin); // получаем данные с датчика препятствий
if (B1val == HIGH) {
if (avoid == HIGH)
Serial.println("None");
else
Serial.println("Warning!");
}else if (B1val == LOW) {
power.sleep(SLEEP_1024MS);
}
delay(1500);
}
�����ff��� - but should print "None"
J-M-L
November 29, 2023, 12:58pm
2
make sure your Serial monitor is set at 9600 bauds
side note, why are you correctly using HIGH for avoid and did not use LOW and HIGH for B1Val (you used 1 and 0)
Yes, My Serial monitor set at 9600 bauds
J-M-L
November 29, 2023, 1:31pm
4
what's your arduino ? what's your circuit ? anything connected to the Serial pins 0 and 1 if it's a UNO or MEGA and the likes?
if you unplug everything and just keep the USB cable - does this work?
void setup() {
Serial.begin(9600);
while(!Serial);
Serial.println("Hello World");
}
void loop() {}
Yes, this code is running is OK
J-M-L
November 29, 2023, 1:51pm
7
just to be on the safe side try this
#include <GyverPower.h>
#include <powerConstants.h>
#define avoidPin A1 // задаем имя для порта с датчиком
#define B1Pin 2
int avoid;
void setup() {
Serial.begin(9600); // инициализация монитора порта
pinMode(B1Pin, INPUT);
pinMode(avoidPin, INPUT);
power.autoCalibrate();
power.hardwareDisable(PWR_ADC | PWR_TIMER1);
power.setSystemPrescaler(PRESCALER_2);
power.setSleepMode(STANDBY_SLEEP);
}
void loop() {
boolean B1val = digitalRead(B1Pin);
avoid = digitalRead(avoidPin); // получаем данные с датчика препятствий
if (B1val == HIGH) {
if (avoid == HIGH) Serial.println("None");
else Serial.println("Warning!");
} else { // B1val is LOW
Serial.println("Going to sleep!");
Serial.flush(); // <== make sure everything is sent out
power.sleep(SLEEP_1024MS);
}
delay(1500); // what is that for ?
}
kolaha
November 29, 2023, 2:02pm
8
programmer-10:
void loop() {
avoid = digitalRead(avoidPin); // получаем данные с датчика препятствий // один бит єто не данные,даже если его записать в int
if (B1val == HIGH) {// <----here you check if it equal HIGH, and then if it not
...
}else if (B1val == LOW) { // <--- if it not you check again if it not HIGH, mean: equal LOW
...
}
delay(1500);
}
it can be written:
if (B1val) {
...
}else {
...
}
xfpd
November 29, 2023, 2:56pm
9
@programmer-10 ... see @J-M-L comment above.
To all: Are any timers associated with PORTD and Serial Monitor/baud? The library file has something strange in it... this is a copy/paste , not a typographical error on my part)
PWR_TIMER1 - Timer 0
PWR_TIMER0 - Timer 1
PWR_TIMER2 - Timer 2
PWR_TIMER3 - Timer 3
PWR_TIMER4 - Timer 4
PWR_TIMER5 - Timer 5
This is an automatic translation, may be incorrect in some places. See sources and examples!
# GyverPower
GyverPower - library for power management of MK AVR
- System clock management
- Enable/disable peripherals:
-BOD
- Timers
- I2C/UART/SPI
- USB
-ADC
- Sleep in different modes (list below)
- Sleep for any period
- Timer calibration for accurate sleep time
- millis() adjustment
### Compatibility
- Atmega2560/32u4/328
- Attiny85/84/167
This file has been truncated. show original
kolaha
November 29, 2023, 4:54pm
10
if TIMER0 is accidentally disabled no interrupt will be possible: no UART, no I2C, no millis
J-M-L
November 29, 2023, 5:21pm
11
The UART communication on the Atmega328P does not directly depend on any timers. Same for I2C, The TWI module uses its own set of registers and logic to generate the necessary clock signals and handle the timing requirements of the I2C communication protocol
Does it work properly if you comment out all the lines concerned with power down?
J-M-L
November 29, 2023, 5:34pm
13
probably worth to get rid of this
programmer-10:
#include <GyverPower.h>
and use directly the avr functions
see Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors
2 Likes
fompi
March 19, 2024, 9:01pm
14
power.setSystemPrescaler(PRESCALER_2);
If you are using this, you need to multiply your bauds to 2.
Like this:
Serial.begin(9600 * 2);
system
Closed
September 15, 2024, 9:01pm
15
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.