Please help me, not print none, print ������ff���, My arduino is UNO

#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"

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

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

I use Uno Arduino.

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 ?
}

it can be written:

   if (B1val) {
   ...
   }else { 
    ...
   }

@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

if TIMER0 is accidentally disabled no interrupt will be possible: no UART, no I2C, no millis

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?

probably worth to get rid of this

and use directly the avr functions

see Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors

2 Likes
power.setSystemPrescaler(PRESCALER_2);

If you are using this, you need to multiply your bauds to 2.
Like this:

Serial.begin(9600 * 2);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.