text:
20x4 LCD will write but then won't update
I am controlling a solar tracker, and it needs to be reset every 10 minutes or it loses its mind.  My program works fine, controlling power relays, so I have added I2C&Power to be able to see the status remotely.  For now it is set up on the workbench with fairly short cables.  I also have a RTC and the i2cscanner finds them all..
LCD init code is pretty basic:
// 20 x 4  LCD Display
#include LiquidCrystal_I2C.h
// set the LCD address to 0x3F for a 20 chars 4 line display\/ Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

then
lcd.begin(20,4);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("PV Control 3.9");

My LCD (20x4) works fine at first, writing the top line with the name of the program, then the bottom line with a temperature reading, then every 10 minutes I need the second line to show when the power is off for 10 seconds.  It shows "power off" just fine, but after the delay(10000) it is supposed to overwrite that line with  "power on" but nothing changes...
Serial.println("POWER OFF");
lcd.setCursor(4,1);
lcd.print("-Power Off- ");
digitalWrite(power1,HIGH);  // DC HOUSE power off
digitalWrite(power2,HIGH);  // DC HOUSE power off
delay(10000);
Serial.println("POWER ON");
lcd.setCursor(4,1);
lcd.print("-Power On-  ");
digitalWrite(power1,LOW);  // DC HOUSE power on
digitalWrite(power2,LOW);  // DC HOUSE power on

The problem is that it continues to say "power off" and doesn't overwrite it.
I can see from the Serial Monitor that the program is running fine, but the LCD doesn't change after the first set of lcd.prints at those character positions.
I haven't heard of anybody having this problem, but perhaps someone out there know about this.   Any suggestions would be very welcome.
Question is:  How can I make the LCD update lines that have been originally written?

UPDATE:  Problem solved by simply clearing and rewriting the display when things change.  I can't debug libraries but at least it is working now.

it needs to be reset every 10 minutes or it loses its mind - I'm not familiar with electronic devices losing their mind, so to speak. Can you elaborate? As for your other problems, it is impossible to answer without seeing your code.

Please post the code that does not work, otherwise your question is unanswerable. Also the exact ref of your LCD would be good to know (they are not all the same). Finally a wiring diagram might be helpful too.

Have you tried to isolate the problem, ie remove all other sensors and only keep code that handles the display updates at specific times?

Ha.  Loses its mind means it becomes non-responsive - comatose.  I suppose I can be criticized for anthropomorphizing computer equipment.  :

If you look above you will see the source code is pretty basic.  And the problem has been solved by simply clearing the display and rewriting it.

I agree with SDsolar. I read the question, read the solution and am happy with SDsolar's response. No need for anything else

Ah ha.   I solved it by using lcd.clear() and simply repainting the entire display with every change.  I have much simpler LCD programs that don't require doing this, but it worked in this instance.
Same code as above, but with this before each power notification:
lcd.clear();
lcd.setCursor(2,0);
lcd.print("PV Control 3.9");

etc...

UPDATE:
  Now that I have two 20x4 LCD screens showing readings from two separate Arduinos (PV Controls and Weather station) I have discovered that it is very important to keep the screen writes to a minimum.  No time delays in between writing parts of the screen, for instance (like when I had Serial.print statements in there for debugging), doing all the readings and calculations before writing the screen, and timing the screen updates to be infrequent, like on the order of 65 seconds for weather and 10 minutes for the PV.  I2C does not have collision detection so it is important to try to prevent the two screens from being updated at the same time.  The I2C&Power arrangement is working great.  One source of power is all it takes to activate the entire network.

Neither the question nor this answer are adding much value to the site. You have an unspecified LCD, with an unspecified library, called by code you haven't posted. Your solution doesn't clarify why this is needed in this case and not other cases.

@Gammon, you must not have read the actual question..  I suggest you scroll back up and take a look.  Meanwhile, the problem is solved by clearing and rewriting the display.  I don't have the expertise to debug libraries, but at least it now works.

I see a drive-by downvoted this answer.  I don't get that.  Bottom line is that this answer solved the problem.  Some peoples' kids.....

@Gammon, re adding value to the site:  For me, this added a lot of value.  I may not be like you so we may come to different conclusions.  Your comment that it does not add much value is at least parsed enough to not be an absolute, but there are a lot of different levels of people using this information.  Why not record our experiences?


text:
Change the sequence of LEDs with button press
I am new to arduino.
I have created a circuit , here is the image:

I want something that as I press the button the sequence of LEDs will change and as I press the button again , the sequence will change again.
I programmed code as following but it don't works correctly:
int led1 = 11;
int led2 = 10;

int output = 2;
int input = 4;
int mode = 0;

void setup() {
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  pinMode(output,OUTPUT);
  pinMode(input,INPUT_PULLUP);
  digitalWrite(output,LOW);

}

void loop() {
  while(mode == 0 && digitalRead(input) == 1){
    digitalWrite(led1,HIGH);
    digitalWrite(led2,HIGH);
    delay(100);
    digitalWrite(led1,LOW);
    delay(100);
    digitalWrite(led1,HIGH);
    delay(100);
    digitalWrite(led2,LOW);
    delay(100);
    digitalWrite(led2,HIGH);
  }
  if(digitalRead(output) == 0){
    mode++;
    if(mode >= 2){mode = 0;}
  }
  while(mode == 1 && digitalRead(input) == 1){
    analogWrite(led1,255);
    delay(400);
    analogWrite(led1,150);
    delay(400);
    analogWrite(led2,255);
    delay(400);
    analogWrite(led2,150);
  }

}

According to the above code , two leds led1 and led2 are connected with arduino. When the button is off the both LEDs turns on then led1 turns off then turn on again , next time led2 turns off and turns on again.As the button will be pressed , brightness of led1 will be less than the brightness of led2 and then
will again be equal to the brightness of led2, then brightness of led2 will be less than the brightness of led1 and then will be equal to the brightness of led1. But as I press the button , nothing happens but the led1 and led2 keeps turning on and off . However sometimes when I press the button then it works.
What is the problem with my code and how to solve it?

@jsotola I mean that when the button is not pressed ,  the LEDs will turn off and then turn on again but when I will  press the button , the LEDs will be fading.

That is quite puzzling now.

@jsotola I have edited , have a look now.

Another example :As the button is kept off , the only led will blink and when the button will be pressed , the led will fade , code
Image of the circuit , When I press the button the led keeps blinking , don't fade , why it is so and how to solve this ?

@jsotola I mean there is no change when I press the button.

nothing happens but the led1 and led2 keeps turning on and off .... Since the LEDs are already flashing so when I press the button there is no change in the LEDs flashing i.e. nothing happens.

i think that i understand now. ... you have two display modes. ... clicking the button switches modes.  .... i think that you are not detecting the button press... write some test code that turns on the led when the button is pressed, off when released ..... also, you will need to debounce the switch when you are switching modes (once you get the switch to work)

If you put 9V battery on 5V and GND you gonna burn your arduino. For supply your arduino through GPIO: use max 5.5V on GND and VIN.

@Comeister I have connected 9V battery with my arduino but it don't burns. It is working like charm

Connect the 9 V supply to the “Vin” of the Arduino, not the “5V”. Otherwise the Arduino will “work like a charm” only until it dies. 2) Read the Blink Without Delay Arduino tutorial. You will learn that, if you want to do several things in at the same time (like blinking an LED and being responsive to the button), you have to ban delay() from your code.

I'm voting to close this question as off-topic because it has been abandoned by the asker

There are a few issues with your wiring.

As already stated in comments, you should not connect the battery to
the 5V input of the Arduino. Use the “Vin” input instead.
You should put a current-limiting resistor in series with each of your
LEDs. Any value in the range 330 Ω – 1 kΩ should be fine.
Your Arduino (and your LEDs) will last longer if you stop abusing it!
There is no point in using two digital IO pins to read a button. Just
connect the button between a digital input and GND. Alternatively, you
can wire it like in Holmez's answer, but that requires an extra wire
and a resistor.

And there are two main issues with your code:

You forgot to debounce the button. Mechanical button are bouncy.
The easiest way to debounce them is to use a ready-made library like,
e.g., Bounce2.
You are using delay(), which means you cannot respond to user input
while your Arduino is busy delaying. You should manage your timings
with milis() instead, as explained in the Blink Without Delay
Arduino tutorial.

Here is my take at your problem. This is based on the
finite state machine programming pattern, with a state defined by
two variables. There is a mode variable used to keep track of whether
we are in “digital” or in “analog” mode. And there is a “phase” variable
used to keep track of the phase along the blinking pattern. Phases 0
through 3 correspond to (LED1/LED2) in the states: (HIGH/HIGH),
(LOW/HIGH), (HIGH/HIGH), (HIGH/LOW). Note that, for simplicity, the LEDs
are controlled with analogWrite(), even in “digital” mode.
#include <Bounce2.h>

const uint8_t BUTTON_PIN = 4;
const uint8_t LED1 = 11;
const uint8_t LED2 = 10;

Bounce button;

void setup()
{
    button.attach(BUTTON_PIN, INPUT_PULLUP);
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT);
    analogWrite(LED1, 255);
    analogWrite(LED2, 255);
}

/*
 * Vary the LED brightnesses along the following pattern:
 *
 *  phase:   0   1   2   3   0
 *          ___     ___________
 *  LED1:      \___/
 *          ___________     ___
 *  LED2:              \___/
 */
void loop()
{
    static enum { DIGITAL, ANALOG } mode = DIGITAL;
    static uint8_t phase = 0;
    static uint16_t phase_duration = 100;
    static uint8_t low_level = 0;
    static uint16_t last_change = 0;

    // Switch modes on button presses.
    button.update();
    if (button.fell()) {
        switch (mode) {
            case DIGITAL:
                mode = ANALOG;
                low_level = 150;
                phase_duration = 400;
                break;
            case ANALOG:
                mode = DIGITAL;
                low_level = 0;
                phase_duration = 100;
                break;
        }

        // Set initial phase.
        phase = 0;
        last_change = millis();
        analogWrite(LED1, 255);
        analogWrite(LED2, 255);
    }

    // Switch phase after phase_duration elapsed.
    if (millis() - last_change >= phase_duration) {
        last_change += phase_duration;
        phase = (phase + 1) % 4;
        switch (phase) {
            case 0:
                analogWrite(LED2, 255);
                break;
            case 1:
                analogWrite(LED1, low_level);
                break;
            case 2:
                analogWrite(LED1, 255);
                break;
            case 3:
                analogWrite(LED2, low_level);
                break;
        }
    }
}

Use a boolean:
boolean blink = false;
if(digitalRead(output) == 1){
    blink = !blink;
}

if(blink == true){
    digitalWrite(led1,HIGH);
    digitalWrite(led2,HIGH);
    delay(100);
    digitalWrite(led1,LOW);
    delay(100);
    digitalWrite(led1,HIGH);
    delay(100);
    digitalWrite(led2,LOW);
    delay(100);
    digitalWrite(led2,HIGH);
}else{
    analogWrite(led1,255);
    delay(400);
    analogWrite(led1,150);
    delay(400);
    analogWrite(led2,255);
    delay(400);
    analogWrite(led2,150);
}

It is not working.

I think delay command don't let the button being detected when pressed.

There are several issues that I can see.
To start with, you have the button wired to 2 pins, one configured as an input and one as an output. Starting out, you should connect the button as in the example below.

This will read LOW until the button is pressed.
I suspect in your case that because your using in INPUT_PULLUP, your button will read HIGH when the button isn't pressed, but will continue to read HIGH even after the button is pressed - which leads to the second issue of your first while loop - because mode is initialised to 0, and the button is always reading HIGH, the condition for your while loop will always be true, consequently, the loop will never exist.
The next issue (if you change the code so the first while loop does exit) is that you're trying to do a digitalRead on an OUTPUT pin - as an OUTPUT pin, it will never detect the state of the button.
Another issue will be that when you press the button and the if statement is reached (because digitalRead(input) == 0), even if the button is pressed for the shortest time, the loop function will be run several times, and the if statement will be run several times which will effectively result in the mode containing either 0 or 1 almost at random.
While the best way to fix this is with an interrupt (another lesson for another day), a simple way is something like this:
    int buttonPressedProcessed = 0; // an indicator so we know if the button press has been processed.

void setup() {
    ...
}

void loop() {
  while(mode == 0 && digitalRead(input) == 1){
    buttonPressedProcessed = 0; // reset button pressed and processed indicator
    ...
  }
        // check also the button pressed and processed indicator
  if(digitalRead(input) == 0 && buttonPressedProcessed == 0){
    buttonPressedProcessed = 1; // set button pressed and processed indicator
    mode++;
    if(mode >= 2){mode = 0;}
  }
  while(mode == 1 && digitalRead(input) == 1){
    buttonPressedProcessed = 0; // reset button pressed and processed indicator
    ...
  }
}

your using in INPUT_PULLUP, your button will read HIGH when the button isn't pressed, but will continue to read HIGH even after the button is pressed - which leads to the second issue of your first while loop - because mode is initialised to 0, and the button is always reading HIGH, the condition for your while loop will always be true, consequently, the loop will never exist. .... it will read zero after I press the button , looks like you have not tested the code.

@J.Doe I have struck that through, as you were right about that bit. The rest of the answer still stands though, and should provide the solution to your problem.

It is not working as I expected , if I increase the time in delay in the code, the button will not work when it is pressed during delay.

This is a bit misleading. There's nothing wrong with the way the button is wired in the question; it may be unecessary to use an output for the low side of the button, but it is entirely workable, and that output is driven low.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Brownout detector triggered
I'm running a pretty basic setup. When I run a small program just doing some serial.println, it works fine, when I try to do operations that needs more power, the brownout detector gets triggered. I'm running my chip on an ok buff power supply so I don't get what the problem is.

The ESP typically runs on 3.3 Volt, not 3.0 Volt.
Secondly, it looks like the board has a voltage regulator, all power goes through the voltage regulator. If that's the case the voltage you need to supply must be lower that the drop-out voltage of the regulator (which is typically around a volt).

the thing you see on the PCB is a 10k resistance, from power to the EN pin as required, i havent added any voltage regulators

(the big blue thing is just the USB to UART, it doesnt draw any power or provide any power)

and btw the operating range of the ESP32 is 3v to 3.6v,

I mistook the 3-pin part in the schematic for a linear voltage regulator. I know the ESP can run on a lower voltage. But since you were having power related problems it might be a idea to at least check whether the problem remains when supplying 3.3V. 3.0 is the minimum voltage the ESP runs at, and there might be some resistance in the wires, and breadboard, that could cause a high enough voltage drop when the ESP is drawing more current for the ESP to brown out.

Why is the USB to serial board connected to your 3 volt supply? Also make sure your breadboards power rails (blue and red) don't have a split in the middle. Some breadboards have this "feature".

for some reason the usb to uart need power suply,

im not home atm but running it on 3.3v will probably not change anything

tho the weird thing is that it consistently brownout evry second time

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
How do I convert this program to assembly from c++
I am trying to implement a program in assembly code for an Arduino UNO. A potentiometer is used on an ADC pin for variable time (t). LED1 flashes for t seconds, then stays on for t seconds, then goes off and another LED(LED2) goes on for t seconds and then the cycle repeats (t is variable time that comes from potentiometer). I have a working program in c++ but I want to convert it to assembly. I have just started learning assembly and am not very good at it.
The part I am really stuck on is the analogRead() function. I do not know how to implement this on assembly. Anyone know how to do this?
#define led 3
#define led2 2

void setup()

{

Serial.begin(9600);

//initializing pins
pinMode(led,OUTPUT);

pinMode(led2,OUTPUT);

}
void loop()

{

// read the input on analog pin 0:
int sensorValue = analogRead(A0);

// Convert the analog reading(which goes from 0 - 1023) to a voltage(0-5V):
int voltage = sensorValue * (5.0 / 1023.0);

// print out the value you read:
Serial.println(voltage);

for(int i=0;i<2*voltage;i++)

{

digitalWrite(led,LOW);

delay(100);

digitalWrite(led,HIGH);

delay(100);

}

//red stays on
digitalWrite(led,HIGH);

delay(voltage*500);

digitalWrite(led,LOW);

//green stays on
digitalWrite(led2,HIGH);

delay(voltage*500);

digitalWrite(led2,LOW);

}

are you able to run simple blink code, that does not use analog input, in assembly?

It sounds like you want to forsake all the work people have put into the Arduino environment and do what is called bare metal programming.  If that is the case, say so and I will respond with a new answer to your question.  Be aware, this will immerse you into firmware programming where you will need to do everything the Arduino environment is doing for you.  This can get so technical that some companies hire special embedded programmers who specialize in Board Support Packages or BSPs.

@jsotola Yes I am able to do that

@st2000 Yes please

Download a copy of the Atmega328P datasheet from here  http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf  There are examples in C and in Assembly for doing many things.  See Section 24.  I think you can also use AVRDUDE commands to create/save assembly code as part of the compile process, write some simple code and see how the compiler does it.

Well, @CrossRoads basically told you what to do.  You will need to read and understand the parts of the datasheet which describes the peripheral you are interested in using as well as the core of the processor.  You don't need to bother with the electrical or physical packaging details.  Yes, I know the PDF is 600 pages.  (This is what the Arduino is abstracting you from.)  Welcome to firmware and bare metal programming!

The obvious solution for converting any program to assembly is... to
compile it! You can disassemble the resulting binary with a command
like:
avr-objdump -S -C the_program.elf > the_program.lss

This will output a listing of the program, with the original source
interspersed with an hex dump of the binary and the corresponding
disassembly.

The part I am really stuck on is the analogRead() function.

Here it goes:
000003a6 <analogRead>:
 3a6:   8e 30           cpi r24, 0x0E   ; 14
 3a8:   08 f0           brcs    .+2         ; 0x3ac <analogRead+0x6>
 3aa:   8e 50           subi    r24, 0x0E   ; 14
 3ac:   87 70           andi    r24, 0x07   ; 7
 3ae:   20 91 00 01     lds r18, 0x0100 ; 0x800100 <__data_start>
 3b2:   90 e4           ldi r25, 0x40   ; 64
 3b4:   29 9f           mul r18, r25
 3b6:   90 01           movw    r18, r0
 3b8:   11 24           eor r1, r1
 3ba:   82 2b           or  r24, r18
 3bc:   80 93 7c 00     sts 0x007C, r24 ; 0x80007c <__TEXT_REGION_LENGTH__+0x7e007c>
 3c0:   80 91 7a 00     lds r24, 0x007A ; 0x80007a <__TEXT_REGION_LENGTH__+0x7e007a>
 3c4:   80 64           ori r24, 0x40   ; 64
 3c6:   80 93 7a 00     sts 0x007A, r24 ; 0x80007a <__TEXT_REGION_LENGTH__+0x7e007a>
 3ca:   80 91 7a 00     lds r24, 0x007A ; 0x80007a <__TEXT_REGION_LENGTH__+0x7e007a>
 3ce:   86 fd           sbrc    r24, 6
 3d0:   fc cf           rjmp    .-8         ; 0x3ca <analogRead+0x24>
 3d2:   80 91 78 00     lds r24, 0x0078 ; 0x800078 <__TEXT_REGION_LENGTH__+0x7e0078>
 3d6:   20 91 79 00     lds r18, 0x0079 ; 0x800079 <__TEXT_REGION_LENGTH__+0x7e0079>
 3da:   90 e0           ldi r25, 0x00   ; 0
 3dc:   92 2b           or  r25, r18
 3de:   08 95           ret

Now, in order to more easily make sense of it, you need to know what all
those magic numbers mean. The command
avr-nm -nC the_program.elf

will dump the symbols associated with every RAM and flash address. In
order to tell those apart, 0x800000 is added to every RAM address. This
will tell you that, in this specific program, the RAM address 0x0100
is actually the address of the variable analog_reference from the
Arduino core library. Thus, you can replace the line
 3ae:   20 91 00 01     lds r18, 0x0100 ; 0x800100 <__data_start>

by
    lds  r18, analog_reference

Then you can use the datasheet to get the names of the memory-mapped IO
registers, and the names of the bits from those registers. I have done
all this for you, so here is the cleaned-up disassembly of
analogRead():
analogRead:
    cpi  r24, 14
    brcs 1f
    subi r24, 14
1:  andi r24, 0x07
    lds  r18, analog_reference
    ldi  r25, 1<<REFS0
    mul  r18, r25
    movw r18, r0
    clr  r1
    or   r24, r18
    sts  _SFR_MEM_ADDR(ADMUX), r24
    lds  r24, _SFR_MEM_ADDR(ADCSRA)
    ori  r24, 1<<ADSC
    sts  _SFR_MEM_ADDR(ADCSRA), r24
2:  lds  r24, _SFR_MEM_ADDR(ADCSRA)
    sbrc r24, ADSC
    rjmp 2b
    lds  r24, _SFR_MEM_ADDR(ADCL)
    lds  r18, _SFR_MEM_ADDR(ADCH)
    ldi  r25, 0
    or   r25, r18
    ret

If you compare this with the source code of analogRead(), it
should now make perfect sense.

I am trying to implement a program in assembly

Now, if you want to write the assembly yourself, that's a whole
different story. If you allow yourself the use of the Arduino core, then
you can simply
    ldi r24, 14  ; pin A0 is pin 14
    call analogRead

If you don't want to rely on external libraries, and really write
everything yourself, it's going to be a lot harder. I suggest you do
this as a two-step process:
Step 1: Learn how to program the ATmega328P in plain C, at the
register level, using no library other than the avr-libc. You can start
by reading this short tutorial about direct port access.
But then you should quickly move on to studying the
datasheet and the manual of the avr-libc. Yes,
that's a lot to digest. I hope you didn't expect this to be quick and
easy. But note that, on those documents, you can skip all the chapters
related to functions you are not going to use.

I am really stuck on is the analogRead() function.

In the specific case of your example program, you don't need a version
of analogRead() that can read any pin with any reference. You can
instead write a simpler version that just reads the currently selected
pin using the currently selected reference:
int simple_analog_read(void)
{
    ADCSRA |= 1<<ADSC;                    // start the converion
    while (ADCSRA & (1<<ADSC)) continue;  // wait till it's done
    return ADC;                           // return the reading
}

Of course, this assumes you have appropriately initialized the ADC.

int voltage = sensorValue * (5.0 / 1023.0);

You really, really don't want to implement something like this in
assembly. The AVR hardware supports neither floating point nor
divisions. All this is handled by the compiler through supporting
libraries, and they are not simple. What you really want is something
like
int voltage = (sensorValue * 5) >> 10;

which is incidentally more correct, as the scaling factor is 5/1024, not
5/1023 (see the datasheet).
Step 2: Learn assembly, and rewrite your low-level C code in
assembly. If your C code is low-level enough this should not be too
hard. As a learning aid, you can ask the compiler to do it for you and
then try to make sense of what it did. If you just try to compile the
simple_analog_read() function I wrote above you will see the
translation to assembly is almost trivial.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Arduino UNO + ESP8266 WiFi Relay by LC Technology
I have Arduino Uno, and recently obtained ESP8266 WiFi Relay by LC Technology. I tried to look up some information about that on the net, but all the answers / suggested solution didn't work for me. Let me briefly explain the problem.
I have connected this module to arduino in a very simple way:

TX -> pin 7
RX -> pin 6
5V -> IN +
GND -> IN -

Simple code:
#include "Arduino.h"
#include <SoftwareSerial.h>

#define TxPin 7
#define RxPin 6

SoftwareSerial ESPrelay(RxPin, TxPin);

void setup() {
    Serial.begin(9600);
    ESPrelay.begin(9600);

    readRx();

    ESPrelay.println("AT");
    readRx();
}

void loop() {
    Serial.println(ESPrelay.read());
    // this above is constant -1
}

void readRx() {
    String msg = "";
    while (ESPrelay.available()) {
        char rxByte = ESPrelay.read();
        msg += rxByte;
    }
    Serial.println(msg);
    delay(500);
}

I can see WiFi AP created by the module - so I think module itself works fine - communication between Arduino and module is somewhat broken.
I tried all different AT commands, but none of them seems to take an effect (tried switching modes and connecting to home WiFI, but no luck) also, no response is returned. Could someone try and help me debug this issue?
I tried changing 9600 to 115200 when communicating, but no luck with this either.

Did you remove the ESP-01 from the relay board?

No, I didn't...

and how did you wire it then?

https://imgur.com/a/xoNjI62 - from the left: 1) IN+ -> 5V 2) IN- -> GND 3) RXD -> pin 6 4) TXD -> pin 7

connect everything to the pins header, not to screw terminals. the IN terminals are for powering the relay coil

I did now, and nothing has changed. Still 0 response for AT and AT+RST commands.

you should connect RX to TX.  TX to 6 and RX to 7

so the other way around than what I had? Sorry got a little bit confused. I tried connecting it the other way around and still nothing... Are you willing to hop on discord chat?  Might be easier/faster to communicate...

call read readRx in the loop(). add delay before sending "AT" in setup to let the esp8266 time to boot

I had 115200 set up before, hence was not seeing anything. Changed back to 9600 and I can see response from the module!

Serial connection requires connecting transmit TX pin to receive RX pin. Your SoftwareSerial pins ar pin 6 RX and pin 7 TX. So your wiring should be esp8266 TX to Uno pin 6 and esp8266 RX to Uno pin 7.
Connect 5 V and ground to the pins header, not to screw terminals. The IN terminals are for powering the relay coil.
Call read readRx() in the loop(). Add delay before sending "AT" in setup to let the esp8266 time to boot.


text:
Optocoupler on Tinkercad acting weird
So, maybe it's my understanding that is at fault or maybe it's tinkercad. It's probably the former. But anyway here's my problem
I've connected it according to picture
https://i.sstatic.net/SJ88F.jpg
There is no power going through the anode. The cathode is going to ground.
On the upper side 5v is going to base and the emitter sends signals to an input on pin 12.
If i digitalRead pin 12 and Serial.write it. it says 1. which is weird, least for my understanding.
As i understood there needs to be power going through the anode which lights up the diode inside the optocoupler. however there is no power going through the anode yet the emitter gives off a signal.
Anyone mind helping me out in understanding why this is?
Please ignore the resistors on the image

fixed it, or least a link to the picture

You connected 5V to the base of the transistor inside, so the transistor is turned on all the time.
Move the 5v pin one to the right (middle pin on the 4N35, i.e. the collector), and it should work.

https://imgur.com/a/Yv6UiZx do you mean like this? now the base is collected to ground, the collector to 5v, the emitter to the input pin.
on the other side 5v is connected to the anode and cathode is to the ground. Yet this produces the input pin to return only zeroes. this time it should be only ones

No, leave the base unconnected like this: https://imgur.com/a/uaUCqsC

Ok that actually works great, i'm a bit confused however. does giving power to the base just ignore the what i understand "main" function of the octocoupler?

Every transistor is light sensitive. That is why transistors are in black plastic instead of transparent plastic. The output of the optocoupler is a transistor and it can use the light (often a led or ir led) turned on by the input, but also the base pin can be used (for something, I don't know who uses that). Some optocouplers don't even have that base pin.

ah so you could say that the base pin is just extra functionally and not part of the main function of the octocoupler?

@magicmike992 Yes, it is extra. The base pin is used here to filter spikes: https://www.electronics-tutorials.ws/blog/optocoupler.html so it seems to be used, but a spike can be filtered at the input or output as well.

The light from the led "activates" the base. So you don't need to connect it to anything, to have it function.


text:
How to set a timer for a function and be able to reset it in the middle of the process?
Hello me and my friend have to do an assignment for school but we need some help. We have to make a LED turn on and of with a button and a relay. But when I press the button the LED should be on for 10 minutes and then go off unless we press the button inside those 10 minutes then the LED should turn off. Then repeat this process when we press the button again.
const int relay = 6;
const int button = 5;
int stateold = 1;
int statenew = 0;
int LED = 0;

void setup()
{
  pinMode(relay,OUTPUT);
  pinMode(button,INPUT);
  time = millis();
}

void loop()
{
  statenew = digitalRead(knop);
  if(stateold==0 && statenew==1){
    if(LED==0){
      digitalWrite(relay,HIGH);
      LED = 1;
      }
    }
    else{
       digitalWrite(relay,LOW);
        LED = 0;
    }
  }
 stateold=statenew;

}

you need to think about the LED on for 10 minutes differently ... it is not one 10 minute action ... it is two very brief actions 10 minutes apart ... do the assignment on paper ... use the kitchen light to represent the LED ... use a clock to time the 10 minutes .... write down everything that you have to do to turn on the light for 10 minutes ... pretend that the button was pressed at some point inside the 10 minute interval ... the steps that you wrote down can be turned into working code

Thank you, you helped me a lot to thing in the right direction.

happy to help .... programming is basically telling a very stupid machine exactly what to do at all times and how to react to every single event of interest

i forgot to mention, in the pencil and paper excersise in your kitchen, you cannot use your brain to remember anything ... things like starting time and the previous state of the button have to be remembered on paper

Below code is an example of what you described; pressing the button will turn on the LED and it will only turn off if 10 minutes passed or button is pressed again.
Read the comments in the code:
#define btn 5
#define rly 6

bool btnState;
bool ledState;
unsigned long timer = 0;

void setup() {
  pinMode(btn, INPUT_PULLUP);
  pinMode(rly, OUTPUT);
}

void loop() {
  btnState = digitalRead(btn); // Read the button status (default is 1)

  if (!btnState) { // If button state == 0 (pressed)
    ledState = !ledState; // Toggle this boolean
    timer = millis(); // and reset the timer
  }

  if (ledState) { // If LED state == 1
    digitalWrite(rly, HIGH); // Turn on the Relay
  } else { // Otherwise turn it off
    digitalWrite(rly, LOW);
  }

  if (ledState && millis() - timer > 600000) { // If 10 minutes passed turn off the relay
    digitalWrite(rly, LOW);
    ledState = !ledState;
  }
}

You should also de-bounce the button and you may want to turn on/off the LED when button is pressed and released, not just when it's pressed.

Thank you very much you help us a lot and it works now. Only in the last if statement you forgot a ledState = !ledState.

@daan YW, yep it should toggle the ledState in timer statement.


text:
Error compiling code for Arduino/Genuino Uno. "multiple definition of `__vector_7"
#include <PulseSensorPlayground.h>

int pulsePin = A0;                 // Pulse Sensor purple wire connected to analog pin A0
int Redled = 7;  // The pin for the Red LED which notifies you if you're heart rate is increasing.
int Greenled = 8; // The pin for the Green LED which notifies you if you're heart rate is stable.
int buzzer = 9; // The pin for the piezo which plays music when you're heart rate is increasing.
int music[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440};//The frequency the piezo will play.

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers
//push button part stop

// Volatile Variables, used in the interrupt service routine!
volatile int BPM;                   // int that holds raw Analog in 0. updated every 2mS
volatile int Signal;                // holds the incoming raw data
volatile int IBI = 600;             // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false;     // "True" when User's live heartbeat is detected. "False" when not a "live beat".
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.

static boolean serialVisual = true;   // Set to 'false' by Default.  Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse

volatile int rate[10];                      // array to hold last ten IBI values
volatile unsigned long sampleCounter = 0;          // used to determine pulse timing
volatile unsigned long lastBeatTime = 0;           // used to find IBI
volatile int P = 512;                      // used to find peak in pulse wave, seeded
volatile int T = 512;                     // used to find trough in pulse wave, seeded
volatile int thresh = 525;                // used to find instant moment of heart beat, seeded
volatile int amp = 100;                   // used to hold amplitude of pulse waveform, seeded
volatile boolean firstBeat = true;        // used to seed rate array so we startup with reasonable BPM
volatile boolean secondBeat = false;      // used to seed rate array so we startup with reasonable BPM

void setup()
{

 pinMode(Redled, OUTPUT); //This defines the pin to be an output
 pinMode(Greenled, OUTPUT);//This defines that the Green Led will be an output.
 pinMode(buzzer,OUTPUT);//This defines that the piezo pin will be an output.

  Serial.begin(115200);
  interruptSetup();                // sets up to read Pulse Sensor signal every 2mS
                                    //   analogReference(EXTERNAL);

}

//  Continuous and does not stop
void loop()
{

   serialOutput();

  if (QS == true) // A Heartbeat Was Found
    {
      // BPM and IBI have been Determined
      // Quantified Self "QS" true when arduino finds a heartbeat
      serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial.
      QS = false; // reset the Quantified Self flag for next time
    }
   if (BPM > 50){ //If the heart rate is more than 55 BPM(Beats Per Minute) then...

    digitalWrite(Redled, HIGH);//The Red Led will turn on
    digitalWrite(Greenled, LOW);//Green Led will turn off

   }
   else if(BPM < 50)//If the heart rate is below 55 BPM then...
   {
   digitalWrite(Redled, LOW);//The Red Led will stay off
   digitalWrite(Greenled, HIGH);//The Green Led will stay on
   tone(3, 500, 1000);

   }
  delay(20); //  take a breakx

  }

void interruptSetup()
{
  // Initializes Timer2 to throw an interrupt every 2mS.
  TCCR2A = 0x02;     // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
  TCCR2B = 0x06;     // DON'T FORCE COMPARE, 256 PRESCALER
  OCR2A = 0X7C;      // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
  TIMSK2 = 0x02;     // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
  sei();             // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
}

void serialOutput()
{   // Decide How To Output Serial.
 if (serialVisual == true)
  {
     arduinoSerialMonitorVisual('-', Signal);   // goes to function that makes Serial Monitor Visualizer
  }
 else
  {
      sendDataToSerial('S', Signal);     // goes to sendDataToSerial function
   }
}

void serialOutputWhenBeatHappens()
{
 if (serialVisual == true) //  Code to Make the Serial Monitor Visualizer Work
   {
     Serial.print(" Heart-Beat Found ");  //ASCII Art Madness
     Serial.print("BPM: ");
     Serial.println(BPM);

     delay(300);

   }
 else
   {
     sendDataToSerial('B',BPM);   // send heart rate with a 'B' prefix
     sendDataToSerial('Q',IBI);   // send time between beats with a 'Q' prefix
   }
}

void arduinoSerialMonitorVisual(char symbol, int data )
{
  const int sensorMin = 0;      // sensor minimum, discovered through experiment
  const int sensorMax = 100;    // sensor maximum, discovered through experiment
  int sensorReading = data; // map the sensor range to a range of 12 options:
  int range = map(sensorReading, sensorMin, sensorMax, 0, 11);
  // do something different depending on the
  // range value:
}

void sendDataToSerial(char symbol, int data )
{
   Serial.print(symbol);
   Serial.println(data);
}

ISR(TIMER2_COMPA_vect) //triggered when Timer2 counts to 124
{
  cli();                                      // disable interrupts while we do this
  Signal = analogRead(pulsePin);              // read the Pulse Sensor
  sampleCounter += 2;                         // keep track of the time in mS with this variable
  int N = sampleCounter - lastBeatTime;       // monitor the time since the last beat to avoid noise
                                              //  find the peak and trough of the pulse wave
  if(Signal < thresh && N > (IBI/5)*3) // avoid dichrotic noise by waiting 3/5 of last IBI
    {
      if (Signal < T) // T is the trough
      {
        T = Signal; // keep track of lowest point in pulse wave
      }
    }

  if(Signal > thresh && Signal > P)
    {          // thresh condition helps avoid noise
      P = Signal;                             // P is the peak
    }                                        // keep track of highest point in pulse wave

  //  NOW IT'S TIME TO LOOK FOR THE HEART BEAT
  // signal surges up in value every time there is a pulse
  if (N > 250)
  {                                   // avoid high frequency noise
    if ( (Signal > thresh) && (Pulse == false) && (N > (IBI/5)*3) )
      {
        Pulse = true;                               // set the Pulse flag when we think there is a pulse

        IBI = sampleCounter - lastBeatTime;         // measure time between beats in mS
        lastBeatTime = sampleCounter;               // keep track of time for next pulse

        if(secondBeat)
        {                        // if this is the second beat, if secondBeat == TRUE
          secondBeat = false;                  // clear secondBeat flag
          for(int i=0; i<=9; i++) // seed the running total to get a realisitic BPM at startup
          {
            rate[i] = IBI;
          }
        }

        if(firstBeat) // if it's the first time we found a beat, if firstBeat == TRUE
        {
          firstBeat = false;                   // clear firstBeat flag
          secondBeat = true;                   // set the second beat flag
          sei();                               // enable interrupts again
          return;                              // IBI value is unreliable so discard it
        }
      // keep a running total of the last 10 IBI values
      word runningTotal = 0;                  // clear the runningTotal variable

      for(int i=0; i<=8; i++)
        {                // shift data in the rate array
          rate[i] = rate[i+1];                  // and drop the oldest IBI value
          runningTotal += rate[i];              // add up the 9 oldest IBI values
        }

      rate[9] = IBI;                          // add the latest IBI to the rate array
      runningTotal += rate[9];                // add the latest IBI to runningTotal
      runningTotal /= 10;                     // average the last 10 IBI values
      BPM = 60000/runningTotal;               // how many beats can fit into a minute? that's BPM!
      QS = true;                              // set Quantified Self flag
      // QS FLAG IS NOT CLEARED INSIDE THIS ISR
    }
  }

  if (Signal < thresh && Pulse == true)
    {   // when the values are going down, the beat is over
      Pulse = false;                         // reset the Pulse flag so we can do it again
      amp = P - T;                           // get amplitude of the pulse wave
      thresh = amp/2 + T;                    // set thresh at 50% of the amplitude
      P = thresh;                            // reset these for next time
      T = thresh;
    }

  if (N > 2500)
    {                           // if 2.5 seconds go by without a beat
      thresh = 512;                          // set thresh default
      P = 512;                               // set P default
      T = 512;                               // set T default
      lastBeatTime = sampleCounter;          // bring the lastBeatTime up to date
      firstBeat = true;                      // set these to avoid noise
      secondBeat = false;                    // when we get the heartbeat back
    }

  sei();                                   // enable interrupts when youre done!
}// end isr

This is the error code I get
Arduino: 1.8.10 (Windows 10), Board: "Arduino Uno"

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

(.text+0x0): multiple definition of `__vector_7'

sketch\Heart_Beat_Sensor_Code.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

Multiple libraries were found for "PulseSensorPlayground.h"
 Used: C:\Users\amaan\Documents\Arduino\libraries\PulseSensor_Playground
exit status 1
Error compiling for board Arduino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

You're using two libraries that are both trying to use Timer 0 (the PulseSensor library and the tone() function).

How would I fix that?

You would have to rewrite (or otherwise edit) this "pulse sensor playground" library (whatever that is) to use a different timer. Or not use tone().

Both the tone() command and the PulseSensor_Playground library use Timer 0's interrupt.  That means there are two implementations of the ISR for that interrupt. However you can only have one implementation of a function or ISR, so it conflicts.
You will have to modify the PulseSensor_Playground library to use a different timer. There may be a way in the code already (some libraries implement such a thing) - if not then you'll have to rewrite the library to use another timer.


text:
Burning a Uno bootloader into a Nano
I bought some cheap Arduino Nanos from ebay, but the watchdog does not work in them.
So I removed their old bootloader and burnt a new Nano bootloader from the Arduino IDE. Same problem, the watchdog didn't work.
Then, I burned a Uno bootloader to the Arduino Nano and now the watchdog works properly. The only issue here is that in Arduino IDE I now have to tell it that I am programming an Arduino Uno instead of a Nano. So far everything seems to work just fine.
Are there other problems that may arise from using a Uno bootloader in a Nano? I notice that there are some extra analog pins in Arduino Nano, but I will still be able to use them with the Arduino Uno bootloader right?

Assuming they're based on the more recent Arduino Nano 3.x series or later, the microcontroller in your Nanos is probably an ATmega328 running at 16 MHz. That's the same as the Uno, so there should be no major problems hopefully.
It might be worth checking that you've got the latest version of the Arduino IDE though. I seem to remember there was a problem in some older bootloaders which prevented the watchdog from working properly.

Yes I've got the latest version and I can confirm that the latest NANO bootloader still has issues with the watchdog.
Yes the uC are the same, NANO is SMD and UNO is not. The other thing that makes me brain scratch is the fact that UNO's analog pins go from 0 to 5 and NANO from 0 to 7. Which, being the same uC, makes no sense... Are UNO boards "ignoring" the two remaining analog pins?

The Nano is based on a 32-pin package version of the ATmega328, whereas the Uno is only based on a 28-pin version. One of the differences is that the 28-pin version has 2 fewer ADC channels. There's certainly a chance that compiling for Uno will mean you can't read the extra two analog channels via analogRead(), but I'm not sure. You could certainly access them directly though via low-level programming.

Incidentally, there is an SMD version of the Arduino Uno which uses the 32-pin package. However, it's designed to be directly equivalent to the functionality of the non-SMD Uno board, so the extra ADC pins on the uC are left unconnected.

A6 and A7 should work just fine when you select the Uno as target board. However A6 and A7 can only be used as analog inputs, not as digital-in or digital-outputs. To keeps things more consistent, and prevent noobs from miswiring things, I think it was a good idea to leave out those pins.

In boards.txt in the Uno section, you change one line for the pinout type from uno.standard to all_pins or something like that to make the analog inputs A6 & A7 available. Compare the standard Nano line against the Uno line and you can see the difference.  I can't access the Arduino files from here to say what they are specifically, sorry.
Ok, here we go:
Uno
uno.build.variant=standard
Nano
nano.build.variant=eightanaloginputs
So change the Uno line to
uno.build.variant=eightanaloginputs
Then you can bootlood the Nano board with Uno bootloader and should have A6, A7 available without issue.

This is not actually needed - while the "eightanaloginputs" option exists, the standard pins_arduino.h still defines constants for A6 and A7 even without it.

Really!  I'll have to try them sometime.  Thanks.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Mapping string values
I have a bunch of thermometers (between 1 and 128). The thermometers have an internal OneWire ID such as "28edce1e500e5" and it is not readable by humans.
Normally I would make an associative array like this:
map["28edce1e500e5"] = "Temp1";
map["28ffd33b9116420"] = "Temp2";

Serial.print(map[printAddress(allDevices[i])]);
Serial.print(" : ");
Serial.print(sensors.getTempC(allDevices[i]));

But it looks like the only hashmap library for Arduino is no longer supported and appears to be quite expensive.
The solution does not have to involve associative array.
The values are populated from a JSON file, loaded from an SD card.
I'm looking for a solutiuon to the problem, not a way to implement an associative array. (Unless that's the best way to solve the problem)

There you go, i formulated it as a question now.

Actually the 1-Wire ROM identity is not a string. It is 8-bytes which actually includes a family code (1 byte) and a CRC code (1-byte). You can simply use uint64_t or uint8[8] instead. Put them sorted in a vector and use binary search for the mapping. The standard clib has support for that. http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga885c1ccefb716ff16ab73a57003140be

Make a struct containing the name and id.
struct device{char[MAX_ID_LENGTH] id; char[MAX_NAME_LENGTH] name; }

Then store the those pairs in an array which you can have sorted by one field or the other. That way you can binary search on that field.

I cannot make it work with chars, but String it works, do you know what is wrong ?

Ok this is working and on the NodeMCU it got enough memory not to be a problem. Though it could be improved im going to accept this answer!

Taking the device structure from rachet freak's post you could implement a map of your own using something like this:
template  <class K, class V> class MyMap
{
public:
    MyMap()
    {
    }

    void Add(K key, V value)
    {
    }

    void Remove(K key)
    {
    }

    V operator[](const& K)
    {
    }

private:
}

But I think templates are expensive under Arduino so you might want to manually instantiate it to drop the template.


text:
Bluetooth: sync time from an NTP server via Internet connection shared with Android phone
I saw that it is possible to sync time from an NTP server over WiFi. I have the HC-06 Bluetooth module and an Android phone that can share its Internet connection with Arduino via Bluetooth. Would it be possible to sync time/date using this infrastructure? And if yes - how (which libraries, etc..)? Has anybody done it already and there is a tutorial on that?

you can;t use Bluetooth tethering with HC-06

No, not really. It is possible, but not easily like you want it to be. The HC-06 is a Bluetooth-Serial bridge. In the Bluetooth protocol there are many types of interfaces, that a client device might expose to the master. A Bluetooth mouse exposes a HID interface, a headset exposes a corresponding audio interface and the HC-06 exposes a pure Serial interface. Thus the HC-06 does not support what ever interface is used for tethering.
Ways, that may make it possible:

Change the firmware of the HC-06 for exposing the correct interface and interact with it. For this you need to know how to reprogram the HC-06 and how exactly bluetooth works. I guess this is over your current level.
Write an app for your Andriod smartphone, which plays the Serial-Internet bridge on the phone. The app would translate between Serial and Internet, involving your own protocol on the Serial interface. Easiest, when you just make a specialized app for syncing time, so that it does not have to do any other communication.

And at that point it is just too much work to go either way. It is unlikely, that you find libraries or any code for this, since it just doesn't make much sense. Instead you could move from an Arduino to an ESP, which can directly connect to the WiFi network in question and thus get directly the time from the internet, without tethering. That is way easier and you can use the many libraries, that already exist for that problem.

I try not to expose WiFi link on my phone (in order to save battery), so I would prefer Bluetooth. Is the above mentioned tethering possible on Nano 33 BLE? And if yes - how will look the code?

@user1876484, BLE doesn't support tethering. Tethering is a function of classic Bluetooth. and Nano 33 BLE supports only BLE


text:
Arduino Uno CTC mode interrupt is not tiggering
I am trying to generate LED blink after 4 second using Interrupt  but Interrupt is not triggering not even once .
Request: if you have arduino uno r3 please check at your end and let me know result.
I have read Timer counter section multiple times and applied everything i can for example :-

Enabled Global Interrupt
Select CTC Mode
Enable Interrupt for OCIE0A
Prescaling to clk/1024
Initializing OCR0A
When OCR0A equal TCNT0 ,interrupt will generate

int var;
void setup() {
  // put your setup code here, to run once:
    SREG = SREG | (1<<7);          // Gloval interrupt enable
    TCCR0A = TCCR0A | (1<<WGM01); // Clear counter on compare match mode
    OCR0A = 255; // when TCNT equal OCR0 interrupt will generate
    TIMSK0 = TIMSK0 | (1<<OCIE0A); //  Output Compare Match A Interrupt Enable
    TCCR0B = TCCR0B | (1<<CS01) | (1<<CS02);  // Prescaling by 1024
    DDRB = DDRB | (1<<5);
    Serial.begin(9600);      // Testing
    Serial.println("Start");   // Testing
}

void loop() {
  // put your main code here, to run repeatedly:

}

ISR(TIMER0_COMPA_vect){
    var++;
    Serial.print(var); // Testing
    volatile long unsigned i;
    if(var == 246){
        PORTB = PORTB | (1<<5);
        for(i=0; i<30000; i++);
        PORTB = PORTB & ~(1<<5);
        for(i=0; i<30000; i++);
        var=0;
    }
}

clock is 16 00 00 00 Hz
Prescaling by 1024 = 15625
1 Tick = 1/15625 = 0.00 00 64 sec
OCR0 is initialized by 255
TCNT0 Ticks to 255
Total time taken to generate one interrupt = 255 * 0.00 00 64 =
0.01632 sec that means after every  0.01632 sec Interrupt supposed to generate
How many interrupt is required to generate LED after 4 sec =>
4/0.01632 = 246

Update working code
int var;
void setup() {
  // put your setup code here, to run once:
  SREG = SREG | (1<<7);          // Gloval interrupt enable
  TCCR0A =(1<<WGM01); // Clear counter on compare match mode
  OCR0A = 255; // when TCNT equal OCR0 interrupt will generate
  TIMSK0 = (1<<OCIE0A); //  Output Compare Match A Interrupt Enable
  TCCR0B = (1<<CS00) | (1<<CS02);  // Prescaling by 1024

  DDRB = DDRB | (1<<5);

    Serial.begin(9600);      // Initialize the USART
    Serial.println("Start");   // Write the welcome message

}

void loop() {
  // put your main code here, to run repeatedly:

}

ISR(TIMER0_COMPA_vect){
  var++;
 // Serial.print(var);
  volatile long unsigned i;
  if(var == 246){
        PORTB = PORTB | (1<<5);
        for(i=0; i<300000; i++);
        PORTB = PORTB & ~(1<<5);
        var=0;
  }
}

There are a few issues with your code:
First, you should completely overwrite the timer control registers
rather than changing single bits. For example, when you write
TCCR0A = TCCR0A | (1<<WGM01); // Clear counter on compare match mode

You end up with a timer mode that results from the combination of the
bits that were already set there and the ones you are setting. Judging
from the comment, you assume that this will be CTC mode, but this is not
granted, because the Arduino initialization routine has already set some
bits in this register. Since you are taking the timer for your own
usage, just overwrite all the control registers:
TCCR0A = (1<<WGM01); // Clear counter on compare match mode

and same for TCCR0B and TIMSK0.
The second problem is that you misread the “Clock Select Bit
Description” table from the datasheet. Your timer is being clocked from
an external clock source on T0 pin. Presumably you have nothing
connected there, so the timer does not increment. You probably meant
TCCR0B = (1<<CS00) | (1<<CS02);  // Prescaling by 1024

A smaller issue is your delay loop. The program would be easier to
understand if you instead use a proper delay function. The Arduino
delay() will not work, as you have reconfigured Timer 0, but you can
use _delay_ms() from the avr-libc if you #include <util/delay.h>.

Thanks a lot , you are right i miss read Prescaling bits . my code is working now


text:
I am trying to read input from 5th PIN of PORT B?
In a nutshell i want to read a PORTB 5th pin without using digitalRead API ( i am trying to learn baremetal using arduino-uno-r3)
Just to Learn How internal register works i did not used digitalRead API, instead i have used DDRB register to set the 5 bit of DDRB as Low indicating PORTB 5th pin is in input mode then i am using an if statment to check if 5th bit of PINB is high or low my expection was that when i connect arduino pin 13 to 5v  if statment will become TRUE.
void setup() {
  // put your setup code here, to run once:
  DDRB = DDRB & ~(1<<5);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(PINB & (1<<5)){
     Serial.println("Got data");
    }
}

When i executed above code i am constantly getting if as TRUE

Do you use an external pullup or pulldown resistor?

your code is operating on the 6th bit ... bits are numbered 0 to 7, so 5th bit is bit 4

I have not used any pull up resistor and i am sure PINB 5th bit is 13 pin of aurdino

No, digital 13 is PB5, i.e. the 6th bit. The 1st bit is PB0, the 2nd bit is PB1, etc.

If nothing is connected to the pin then it can read either high or low.  Google “floating pin”.  If you’re expecting it to read low when not connected to anything then you’re thinking wrong.

@EdgarBonet so what should i change in code

@Delta_G then what is the point of low and high if pin is always (floating ) high

http://www.electronoobs.com/images/Arduino/tut_31/arduino_uno_scheamtic.png PB5 IS 13TH PIN ON ARDUINO i think i am correct

It's not 13th pin, it's pin “digital 13”. Not the same.

The point is that if the pin is tied to a voltage it will read that voltage.  If it is unconnected then what voltage is on the pin?  If you answer zero then you need to go and study basic electronics some more.  A pin should read LOW when it is connected to ground and HIGH when connected to 5V.  If it is unconnected then you don't know what the voltage level at the pin is.  It can pick up any stray noise and read anything.

The point is, "Don't try to read a pin that isn't connected to anything."

There seem to be several, separate issues in your question.
One is a simple matter of language. In English, “1st” is an abbreviation
for “first”, which is an ordinal adjective applied to an item in a list
meaning that there is no other item before it in that list. In the same
vein, “5th” means “fifth”, which applies to the item that has exactly
four items before it. For instance, the list of pins of port B is {PB0,
PB1, PB2, PB3, PB4, PB5}. PB0 is the first in the list, and PB4 is the
fifth. The fact the first item bears the number 0 makes this confusing.
Thus, I recommend avoiding ordinal adjectives altogether and instead
calling the pins by their names, like “digital 13” (Arduino naming) or
“PB5” (AVR naming).
The second issue, and probably your main concern, is about the floating
input pin. You cannot expect a reliable reading from a floating input. I
will not try to explain why, as the issue has been discussed ad nauseam
here and elsewhere. Just do a Web search. The simplest solution is to
use the built-in pull-up resistor and externally connect a push button
between the pin and ground. You will read LOW whenever the button is
pressed:
void setup() {
    pinMode(13, INPUT_PULLUP);
    Serial.begin(9600);
}

void loop() {
    if (digitalRead(13) == HIGH)
        Serial.println("HIGH");
    else
        Serial.println("LOW");
}

The last point is about going bare metal and learning how to use the I/O
registers directly. A small warning first: you have to keep in mind that
this is board-specific. You tagged your question with both “arduino-uno”
and “arduino-mega”, but these boards have different pin mappings
(digital 13 is PB7 on the Mega). The general way of using the DDRx,
PORTx and PINx registers is the same across all AVR chips, but is not
portable to Arduinos based on a different architecture.
So let's assume this is intended to work only on an Uno, Nano, or
other board based on an ATmega328P.
Judging from the example code you show, you seem to
already understand pretty well how these registers work. There is no
problem in your code, beside the fact that it requires an external
pull-up. If you want to enable the internal pull-up, you have to set the
appropriate bit in PORTB. This can seem confusing, as the same register
is used for pull-up control (when the pin is in input mode) and for
output control (when the pin is an output). Essentially, each GPIO pin
has four distinct electrical states which are controlled by to I/O bits:
│ DDRxn │ PORTxn │ state        │
├───────┼────────┼──────────────┤
│   0   │    0   │ INPUT        │
│   0   │    1   │ INPUT_PULLUP │
│   1   │    0   │ OUTPUT LOW   │
│   1   │    1   │ OUTPUT HIGH  │
└───────┴────────┴──────────────┘

The example program above can be translated to low-level AVR style as
follows:
void setup() {
    DDRB &= ~_BV(PB5);  // input mode
    PORTB |= _BV(PB5);  // enable pullup
    Serial.begin(9600);
}

void loop() {
    if (PINB & _BV(PB5))
        Serial.println("HIGH");
    else
        Serial.println("LOW");
}

Nicely put @edgar.  I might add a comment (as the OP did say he/she wanted to do bare metal programming) that different Arduinos board can contain different processors.  And  what works here in this answer is for a specific processor.  And that other processors can and most often work very differently.

@st2000: Good point. Edited the answer.


text:
Connecting ACS 712 30A to my Solar Panel with Arduino
I am trying to connect my Solar Panel (array of 2 x 265Wp 24v panels connected in series) to my Arduino UNO R3/Nano so that I can make a current/voltage measurement system that can be connected to the internet for remote data access.
I am not sure if an Allegro ACS712 30Amp chip could handle the voltage/current of my system which is usually over 60v dc and 4-5 amps. I can relate the ACS712 to a simple ammeter which is connected in series of the load where a shunt resistance is used between the two connecting ends of the ammeter.
The confusing part here for me is that the solar panel is connected via an MPPT charge controller to my 1.5 KVA inverter which in turn powers my house equipment, and I am not sure if the two connecting ends of the ACS712 can handle this load (which sometime exceeds to over 450 Wh) if connected in between the wire connecting the panel and charge controller.
Can anyone help me with a suggestion or better with a diagram showing the suggested system.

The question might be better suited to the Electronics SE.

the ACS712 is not based on shunts, it's based on the Hall-effect, like a clamp meter.

If you're going to post a question about a specific part, always post a link to the datasheet you're using. (If you're not using a datasheet, go find one and read it!) Making people hunt around for the specs for your part is a good way to discourage them from answering.

I am not sure if an Allegro ACS712 30Amp chip could handle the voltage/current of my system which is usually over 60v dc and 4-5 amps.

Easily. It's designed for mains voltages up to 30A. You're using a fraction of that. You could even use the 20A version to get more accuracy and resolution.

The confusing part here for me is that the solar panel is connected via an MPPT charge controller to my 1.5 KVA inverter which in turn powers my house equipment, and I am not sure if the two connecting ends of the ACS712 can handle this load (which sometime exceeds to over 450 Wh) if connected in between the wire connecting the panel and charge controller.

Why is that confusing? If you're monitoring the feed between the solar panel and the charge controller what comes out of that system at the other end is of no concern. Just because you are drawing a larger current from the output doesn't mean that the solar panels are providing that current - that comes from the batteries. Now if you were monitoring the current to/from the batteries that would be a different matter. You'd need to calculate the peak current that your house would draw at mains voltage then convert that to the current at the battery voltage (converting to watts in between is a good step. Note that Wh is meaningless when you want a peak value - Wh is a total power over a period of time ["area under a curve"], but you don't care about time, only peak ["maximum value of curve"]).

I know what you mean.
It can read it, but sure the terminals and the power going though it are tiny and therefore have to take a current at the terminals.
Try a ASC758LCB-100U-PFF-T.
You say your 60V 5 Amps. therefore for I will say "yes" this is 300 watts
There are two terminals per side for the connection
1-2 and 3-4.. I would Solder Join them to enure it can hold the current.
Im looking at this issue and I have made the suggestion above on what you could use as a alternative. it has been used for more powerful systems, in a 30 amp MPPT charge controller.
The area of each terminal is 0.51x0.25x1.27 (0.6477mm2) AWG puts it as a 1.8 amp current area or AWG 19
At worst case, the chip legs will be like a fuse and it will just "pop". so dont go to the fuse box first. they are also internally fused.


text:
Serial Communication with a Serial device
I have a blood glucose meter which supports downloading data to computer using a serial cable and its own software. I made a serial cable for this with a usb to ttl pl2303 and its working. I can download the data from the device to my pc using that software but now I want get the data to my arduino using serial communication. I have a serial monitor software which detects the communication between the device and the software usin com port.
Can any one please tell me how to get the data to my arduino?
I have attached the dump file from that serial monitor.
[31/08/2019 21:32:16] - Open port COM12 (C:\Program Files\Eltima Software\Serial Port Monitor\SerialMonitorx64.exe)

[31/08/2019 21:35:10] - Open port COM12 (C:\Users\User\AppData\Local\Diabetes_Management\Diabetes_Management_APP.exe)

[31/08/2019 21:35:10] Written data (COM12)
    55                                                U
[31/08/2019 21:35:11] - Close port COM12

[31/08/2019 21:35:11] - Open port COM12 (C:\Users\User\AppData\Local\Diabetes_Management\Diabetes_Management_APP.exe)

[31/08/2019 21:35:11] Written data (COM12)
    05                                                .
[31/08/2019 21:35:12] - Close port COM12

[31/08/2019 21:35:12] - Open port COM12 (C:\Users\User\AppData\Local\Diabetes_Management\Diabetes_Management_APP.exe)

[31/08/2019 21:35:13] Written data (COM12)
    05                                                .
[31/08/2019 21:35:13] Read data (COM12)
    01 47 6c 75 63 6f 73 65 0d 0a 02 31 2c 32 30 31   .Glucose...1,201
    38 2c 30 37 2c 32 30 2c 30 31 2c 30 30 2c 31 2e   8,07,20,01,00,1.
    31 2c 6d 6d 6f 6c 5f 4c 0d 0a 32 2c 32 30 31 38   1,mmol_L..2,2018
    2c 30 37 2c 32 30 2c 30 31 2c 30 30 2c 31 2e 31   ,07,20,01,00,1.1
    2c 6d 6d 6f 6c 5f 4c 0d 0a 33 2c 32 30 31 38 2c   ,mmol_L..3,2018,
    30 37 2c 32 30 2c 30 31 2c 33 37 2c 32 2e 34 2c   07,20,01,37,2.4,
    6d 6d 6f 6c 5f 4c 0d 0a 34 2c 32 30 31 38 2c 30   mmol_L..4,2018,0
    37 2c 32 30 2c 30 31 2c 33 36 2c 31 2e 31 2c 6d   7,20,01,36,1.1,m
    6d 6f 6c 5f 4c 0d 0a 35 2c 32 30 31 38 2c 30 37   mol_L..5,2018,07
    2c 32 30 2c 30 31 2c 33 35 2c 33 32 2e 37 2c 6d   ,20,01,35,32.7,m
    6d 6f 6c 5f 4c 0d 0a 03 04                        mol_L....
[31/08/2019 21:35:14] - Close port COM12

.
--------------------------------------
#   Time                Function                                                Dir   Status           Data                                                        Data (chars)       Data length   Req. length  Port        Comments
0   31/08/2019 21:32:16 IRP_MJ_CREATE                                           DOWN                   C:\Program Files\Eltima Software\Serial Port Monitor\SerialMonitorx64.exe                                 COM12
1   31/08/2019 21:32:16 IRP_MJ_CREATE                                           UP    STATUS_SUCCESS   C:\Program Files\Eltima Software\Serial Port Monitor\SerialMonitorx64.exe                                 COM12
2   31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_WAIT_MASK)      DOWN                   19 01 00 00                                                 ....                  4                       COM12
3   31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_WAIT_MASK)      UP    STATUS_SUCCESS                                                                                COM12
4   31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_BAUD_RATE)      DOWN                                                                                COM12
5   31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_BAUD_RATE)      UP    STATUS_SUCCESS   80 25 00 00                                                 €%..                  4                       COM12
6   31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_LINE_CONTROL)   DOWN                                                                                COM12
7   31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_LINE_CONTROL)   UP    STATUS_SUCCESS   00 00 08                                                    ...                   3                       COM12
8   31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_CHARS)          DOWN                                                                                COM12
9   31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_CHARS)          UP    STATUS_SUCCESS   1a 00 00 1a 11 13                                           ......                6                       COM12
10  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_HANDFLOW)       DOWN                                                                                COM12
11  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_HANDFLOW)       UP    STATUS_SUCCESS   00 00 00 00 00 00 00 00 00 08 00 00 00 02 00 00             ................      16                      COM12
12  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_WAIT_ON_MASK)       DOWN                                                                                COM12
13  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_BAUD_RATE)      DOWN                                                                                COM12
14  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_BAUD_RATE)      UP    STATUS_SUCCESS   80 25 00 00                                                 €%..                  4                       COM12
15  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_LINE_CONTROL)   DOWN                                                                                COM12
16  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_LINE_CONTROL)   UP    STATUS_SUCCESS   00 00 08                                                                          3                       COM12
17  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_CHARS)          DOWN                                                                                COM12
18  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_CHARS)          UP    STATUS_SUCCESS   1a 00 00 1a 11 13                                           ......                6                       COM12
19  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_HANDFLOW)       DOWN                                                                                COM12
20  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_HANDFLOW)       UP    STATUS_SUCCESS   00 00 00 00 00 00 00 00 00 08 00 00 00 02 00 00             ................      16                      COM12
21  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_BAUD_RATE)      DOWN                   00 4b 00 00                                                 .K..                  4                       COM12
22  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_BAUD_RATE)      UP    STATUS_SUCCESS                                                                                COM12
23  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_RTS)            DOWN                                                                                COM12
24  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_RTS)            UP    STATUS_SUCCESS                                                                                COM12
25  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_DTR)            DOWN                                                                                COM12
26  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_DTR)            UP    STATUS_SUCCESS                                                                                COM12
27  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_LINE_CONTROL)   DOWN                   00 00 08                                                    ...                   3                       COM12
28  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_LINE_CONTROL)   UP    STATUS_SUCCESS                                                                                COM12
29  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_CHARS)          DOWN                   1a 00 00 1a 11 13                                           ......                6                       COM12
30  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_CHARS)          UP    STATUS_SUCCESS                                                                                COM12
31  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_HANDFLOW)       DOWN                   01 00 00 00 40 00 00 00 00 08 00 00 00 02 00 00             ....@...........      16                      COM12
32  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_HANDFLOW)       UP    STATUS_SUCCESS                                                                                COM12
33  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_MODEMSTATUS)    DOWN                                                                                COM12
34  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_MODEMSTATUS)    UP    STATUS_SUCCESS   f0 00 00 00                                                 ð...                  4                       COM12
35  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_TIMEOUTS)       DOWN                   00 00 00 00 00 00 00 00 2c 01 00 00 00 00 00 00 2c 01 00 00 ........,.......,...  20                      COM12
36  31/08/2019 21:32:16 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_TIMEOUTS)       UP    STATUS_SUCCESS                                                                                COM12
37  31/08/2019 21:32:26 IRP_MJ_WRITE                                            DOWN                   55                                                          U                     1           1           COM12
38  31/08/2019 21:32:26 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   55                                                          U                     1                       COM12
39  31/08/2019 21:32:31 IRP_MJ_WRITE                                            DOWN                   2e                                                          .                     1           1           COM12
40  31/08/2019 21:32:31 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   2e                                                          .                     1                       COM12
41  31/08/2019 21:32:35 IRP_MJ_WRITE                                            DOWN                   2e                                                          .                     1           1           COM12
42  31/08/2019 21:32:35 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   2e                                                          .                     1                       COM12
43  31/08/2019 21:32:38 IRP_MJ_WRITE                                            DOWN                   2e                                                          .                     1           1           COM12
44  31/08/2019 21:32:38 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   2e                                                          .                     1                       COM12
45  31/08/2019 21:32:44 IRP_MJ_WRITE                                            DOWN                   2e                                                          .                     1           1           COM12
46  31/08/2019 21:32:44 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   2e                                                          .                     1                       COM12
47  31/08/2019 21:33:42 IRP_MJ_WRITE                                            DOWN                   55                                                          U                     1           1           COM12
48  31/08/2019 21:33:42 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   55                                                          U                     1                       COM12
49  31/08/2019 21:33:45 IRP_MJ_WRITE                                            DOWN                   2e                                                          .                     1           1           COM12
50  31/08/2019 21:33:45 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   2e                                                          .                     1                       COM12
51  31/08/2019 21:33:47 IRP_MJ_WRITE                                            DOWN                   2e                                                          .                     1           1           COM12
52  31/08/2019 21:33:47 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   2e                                                          .                     1                       COM12
53  31/08/2019 21:33:48 IRP_MJ_WRITE                                            DOWN                   2e                                                          .                     1           1           COM12
54  31/08/2019 21:33:48 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   2e                                                          .                     1                       COM12
55  31/08/2019 21:33:57 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_BAUD_RATE)      DOWN                   6e 00 00 00                                                 n...                  4                       COM12
56  31/08/2019 21:33:57 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_BAUD_RATE)      UP    STATUS_SUCCESS                                                                                COM12
57  31/08/2019 21:33:57 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_BAUD_RATE)      DOWN                                                                                COM12
58  31/08/2019 21:33:57 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_BAUD_RATE)      UP    STATUS_SUCCESS   4b 00 00 00                                                 K...                  4                       COM12
59  31/08/2019 21:34:01 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_BAUD_RATE)      DOWN                                                                                COM12
60  31/08/2019 21:34:01 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_BAUD_RATE)      UP    STATUS_SUCCESS   4b 00 00 00                                                 K...                  4                       COM12
61  31/08/2019 21:34:04 IRP_MJ_WRITE                                            DOWN                   55                                                          U                     1           1           COM12
62  31/08/2019 21:34:04 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   55                                                          U                     1                       COM12
63  31/08/2019 21:34:09 IRP_MJ_WRITE                                            DOWN                   2e                                                          .                     1           1           COM12
64  31/08/2019 21:34:09 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   2e                                                          .                     1                       COM12
65  31/08/2019 21:34:11 IRP_MJ_WRITE                                            DOWN                   2e                                                          .                     1           1           COM12
66  31/08/2019 21:34:11 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   2e                                                          .                     1                       COM12
67  31/08/2019 21:34:15 IRP_MJ_WRITE                                            DOWN                   2e                                                          .                     1           1           COM12
68  31/08/2019 21:34:15 IRP_MJ_WRITE                                            UP    STATUS_SUCCESS   2e                                                          .                     1                       COM12
69  31/08/2019 21:34:21 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_WAIT_MASK)      DOWN                   00 00 00 00                                                 ....                  4                       COM12
70  31/08/2019 21:34:21 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_WAIT_ON_MASK)       UP    STATUS_SUCCESS   00 00 00 00                                                 ....                  4                       COM12
71  31/08/2019 21:34:21 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_SET_WAIT_MASK)      UP    STATUS_SUCCESS                                                                                COM12

Dump file 1
New Dump file

I tried to do this...... check after the read response..... but no response

Its tooo long that i couldnt upload here

i added some dump data

the dump file contains more text i couldnt post it here... how can i post the text file?

yes this is the communication between the device and the software..... its a long file but i posted a part of it..... i never worked like this devices.... thats why i have no idea how it works.... i know basic serial communication arduino to arduino... blutooth module... displays....

https://meta.stackexchange.com/questions/47689/how-can-i-attach-a-file-to-a-post .... use TAB delimited data if you have an option when exporting the data dump

Sir i attached two file..... two from two different serial sniffer software

This depends on what data you need. The device seem to output a lot of information. You need to parse the string for the needed data. For example I found a line in the second dump file like <SOH>Glucose [len=8] followed by lines with glucose reading

yes.... iIn first file there is a tab called function... i can see that..... it uses some function to control it loke "IOCTL_SERIAL_GET_HANDFLOW" and many more.... this is probably programing the serial device......

download Processing and use it to diagnose the communication protocol ( https://processing.org/download/ ) ... see the example serial port sketches ... the new data.txt file that you attached has promising information ... edit the file so that the timestamp is in left column ... <20190901033932.479 SYS>   COM is open
<20190901033932.530 SYS>   Baud rate 1200 .... that will make it easier to follow

looks like you have to initiate the data exchange at 1200 baud and then switch to 9600 baud .... open port at 1200 baud, send U (0x55), close port ... open port at 1200 baud, send <ENQ> (0x05), close port .... open port at 9600 baud, send <ENQ> (0x05), data should start to be sent ..... if that works then try sending U<ENQ> together


text:
Using Arduino fix_fft or arduinoFFT library to filter some specific sound?
I would like to know if there is a way to filter some specific sound using FFT on arduino. For instance, there is wind sound frequency in my analysis and I want to take it off. I searched for that a lot, but I didn't find something useful to solve this problem.

FFT is a tool for analyzing sound. It is not very appropriate for
filtering, unless you have loads of computing power to spare. And it is
even less appropriate for real-time filtering, if that is what you are
after.
Attempting to filter-out a noise based on its frequency is a reasonable
strategy for narrow-band noise, i.e. noise that lies in a narrow band of
frequencies. You can hope that, with some luck, removing this narrow
band doesn't affect too much the interesting part of the signal.
Alas, wind noise is very broad band, although it has more weight at low
frequencies:

(image source).
If the frequencies that interest you are above ≈ 2 – 4 kHz, you could
try a simple high-pass filter. Something like this should work even on
an Arduino if the sample rate is not too high:
static uint16_t filter(uint16_t input)
{
    static uint16_t sum;
    uint16_t delta = input - (sum >> SCALE);
    sum += delta;
    return delta
}

where SCALE is a small constant that determines the cut-off frequency.
Edit: The Z-domain transfer function of this filter is
H = (z − 1) / (z − u)
where u = 1 − 2−SCALE. Its cut-off frequency is then
approximately fsamp ÷ (2 π 2SCALE).

Excellent answer. Note that AVR based Arduinos are a long way from having "Loads of computing power." In fact they are quite the opposite, and do floating point math in software. Their math is really slow, and FFT is floating point intensive.


text:
exit status 1 error compiling for board arduino/Genuino Uno when tone code is used
I am just trying to use an ultrasonic sensor with a buzzer but the buzzer doesn't respond to my code. I mean it doesn't make any sound. I tested it to check if by sending 5 volts to it, it will make a sound.. and it did... but using this code below... for some reason, it doesn't make any sound....
#include <NewPing.h>
#define TRIGGER_PIN 11
#define  ECHO_PIN 12
#define buzzer 13

NewPing sonar1 (TRIGGER_PIN, ECHO_PIN);

long inches1;
int sound = 250;

void setup (){

  Serial.begin (9600);

  pinMode (TRIGGER_PIN, OUTPUT);
  pinMode (ECHO_PIN, INPUT);
  pinMode (buzzer, OUTPUT);

}

void loop () {

  inches1 = sonar1.ping_in();
   if (inches1 <= 5 ){
 //   sound = 250;
    tone(buzzer, 1000); // Send 1KHz sound signal...
    delay(1000);        // ...for 1 sec
    noTone(buzzer);     // Stop sound...
    delay(1000);
    Serial.print (inches1);
    Serial.print ('\n');
   }
  delay (200);
}

don't use tone() if it makes sound with 5 V. only set pin HIGH

hhhmmmm.....
i see... i will try.. thanks for your answer... :)

what exit code are you talking about?

What's the whole message the Arduino IDE gives you. Exit 1 usually means you've got a missing library or a syntax error in your code.

If you have a look at the complete error message you will see that there is a collision between the libraries NewPing and Tone.
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

(.text+0x0): multiple definition of `__vector_7'

libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

yes, but the point is that they don't have to use tone()

I agree! But the question is "error" and perhaps someone take in the information that libraries can have conflicts, I have seen it to many times.


text:
when submit data to ESP8266, ets Jan 8 2013,rst cause:4, boot mode:(1,6) wdt occurs
I am trying to make my ESP8266(nodemcu) as a Web server. When my code operates, and user connects esp's wifi and enters '192.168.4.1/set_peroid' by IE or chrome, this webpage appears:

This is setting menu page. Usually, user puts sampling rate and time peroid, and duration or counter. Then presses 'submit', these data are going to be saved on my esp's EEPROM.
This is the code: (apologize about its complexity)
void input_handleForm() {

  int sample_int=0;
  int s_peroid_int=0;
  int m_peroid_int=0;

  int h_timer_int=0;
  int m_timer_int=0;

  int count_int=0;
  unsigned short curr_tmp=0;
  unsigned short max_tmp=0;

  //setting sampling rate
  String sample_str = server.arg("sample"); //get string data to 'sample' blank
  sample_int = sample_str.toInt(); //and convert to int data

  sample_int = (sample_int/4);
  EEPROM.write(SAMPLING_TIMES, sample_int); //devide by 4 and save it

  //setting user peroid (second or minute)
  String s_peroid_str = server.arg("peroid_s"); //get string data to peroid(sec) blank
      if(s_peroid_str !=NULL){
          s_peroid_int = s_peroid_str.toInt(); //and save it

            if(s_peroid_int<1){
              s_peroid_int=1;
            }
          EEPROM.write(SECOND_INDEX,s_peroid_int); //and save to the eeprom
          EEPROM.write(MINUTE_INDEX,0);
         }
       else{
          s_peroid_int =0;
          EEPROM.write(SECOND_INDEX,0);
        }

  String m_peroid_str = server.arg("peroid_m"); //get string data to peroid(min) blank

      if(m_peroid_str != NULL){

        m_peroid_int = m_peroid_str.toInt(); //save it by int

          if(m_peroid_int <1){
            m_peroid_int=1;
          }

        EEPROM.write(MINUTE_INDEX,m_peroid_int);//and save the integer to eeprom
        EEPROM.write(SECOND_INDEX,0);
      }
      else{
        m_peroid_int=0;
        EEPROM.write(MINUTE_INDEX,0);
       }

      //if user do not input anything ...
      if(m_peroid_int ==0 && s_peroid_int ==0){
        s_peroid_int = 1;
        EEPROM.write(SECOND_INDEX,s_peroid_int);
      }

    //setting timer
    String h_timer_str = server.arg("hour"); //get string data to hour blank
      if(h_timer_str != NULL){
        h_timer_int = h_timer_str.toInt();

          if(h_timer_int <1){
            h_timer_int=0;
          }
      }
      else{//if get null
        h_timer_int=0;
      }

    String m_timer_str = server.arg("minit"); //get string data to minute blank
      if(m_timer_str !=NULL){
        m_timer_int = m_timer_str.toInt();

          if(m_timer_int<1){
            m_timer_int=1;
          }
      }
      else{//if get null
        m_timer_int =0;
      }

      //caculate the 'repeat count' by (time/peroid)

      unsigned long until = (h_timer_int * 60) + m_timer_int;
         //until is set standard by minute. if user's peroid is second, have to *60

        if(until>0 && m_peroid_int >0){ //if peroid is setted by minute

            unsigned short index = until/ m_peroid_int;
            index+=3;
            EEPROM.put( MAXIMUM_INDEX , (unsigned short) index );

        }

        else if(until>0 && s_peroid_int>0){ //if peroid is setted by second
              until = until * 60; //make until(minute) to second
              unsigned short index = until / s_peroid_int;
              index+=3;
              EEPROM.put( MAXIMUM_INDEX, (unsigned short) index );

        }

        else if(until ==0){ //if user do not set timer, then scan the counter input.

          String count_str = server.arg("counts");//get string data to 'count' blank

            if(count_str !=NULL){
               count_int = count_str.toInt();
               unsigned short count_short = (unsigned short) count_int;
               count_short+=3;
                EEPROM.put( MAXIMUM_INDEX, (unsigned short) (count_short) );
            }

            else{//if user do not set timer and do not input count then...
              unsigned short tmp_default = 5;
               EEPROM.put(MAXIMUM_INDEX, (unsigned short) tmp_default );
            }

        }

         EEPROM.commit();

         delay(100);

    String s = "setting done.";
    s += "<a href='/'> Go Back </a>";
    server.send(200, "text/html", s); //Send web page

}

Even though they look complex, they are usually working. But problem is, when input the data and press 'submit', sometimes, very sometimes the program breaks down, irregularly. And when it breaks down, it says:
ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

Although there is 'wdt reset', but system does not reset. ESP just stops and does nothing.
Please give me advice about what is the problem, and help for a solution.

you have io 0 LOW (the 1 in mode should be 3 for normal boot). on reset esp8266 starts in flashing mode

wdt rest is watchdog reset. it happens when the code doesn't get out of the loop 10 or more seconds and yield() or delay() is not called to let the SDK handle the WiFi

thank you for answering.


text:
about required memory size in ATmega32 to execute a certain program
If I want to add two numbers and print the output on LCD
char answer[8];
float a=5.1,b=3.2,c;
c=a+b;
 dtostrf(c,8,3,answer);//convert float to ASCII to print it on LCD
for(i=0;i<8;i++) Lcd8_Write_Char(answer[i]);

What is the required memory space to execute this program?

You can't execute that program. It's incomplete. Also it's not easy to second guess the optimizer in the compiler. All I can say is "at least 8 plus whatever i needs and maybe a b and c if they don't get optimized out".  So between 8 and 24 bytes plus anything else the rest of the program will need.

You can easily find out the size of a program and the needed RAM, by writing a full program (with void setup() and void loop()) and compile it in the Arduino IDE. It will tell you, what you want to know

@chrisl afaik local variables and stack size are not taken into account while compiling, so one needs to use the SRAM size mentioned by the compiler + the maximum amount / deepest stack flow arguments usage + local variables.

You can use the utility freeRAM https://playground.arduino.cc/Code/AvailableMemory/ to check what the compilation can't tell you. Besides, your variable answeris too small by 1 (the trailing \0 )