text:
How do I start a function with serial input?
I want to create a LED Sunrise/Sundown alarm clock. Therefore, I will use a Raspberry Pi that is sending commands over serial to a Teensy 3.1. Like:

"30 Minute Sunrise starting with Color(255,140,0)"
"20 Minute Sundown with Color(255,140,0)"
"start something else with these 3 parameter.

But I don't even get the basic serial part working. E.g. I tried this:
void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  if (Serial.available() > 0) {
    if (Serial.read() == 'A'){
      int inte1 = Serial.parseInt();
      int inte2 = Serial.parseInt();
      int inte3 = Serial.parseInt();
      int inte4 = Serial.parseInt();
      int inte5 = Serial.parseInt();
      if (Serial.read() == '\n') {
        Serial.print(inte1);
        Serial.print(inte2);
        Serial.print(inte3);
        Serial.print(inte4);
        Serial.println(inte5);
      }
    }
  }
}

I planned to do a case switch afterwards. Inte1 should define sunrise/sundown, Inte2 the minutes, 'Inte3-5' the rgb color.
However, when I enter "A 1 100 100 100" it is not printing anything at all.
What is the best way do get this working?
Thanks in advance!

Suggested reading: http://hacking.majenko.co.uk/reading-serial-on-the-arduino

Thank you, that was a nice read. The examples compiles fine and I get what this is about, but still not working. Does not print a single line on the serial monitor!

Baud in Teensy and serial monitor is the same!

Have you managed to get even simple "echo what you send" serial communication working?

Yes. Right now: 'char exstr = Serial.read(); Serial.print(exstr)' is working. I don't know why the example does not!

Probably because you're not waiting for the \n and expecting it to already be in the serial buffer when it hasn't actually arrived yet. Don't expect it to be there immediately you have parsed the last int.

I think Majenko is right. Suggested alternative method: How to process incoming serial data without blocking

Yes that \n was missing. Without it does work.

Okay, as Majenko and Nick Gammon have suggested. The \n had not arrived in the serial buffer. That way the if clause was not fulfilled and nothing was printed. This code has worked for me now:
if (Serial.available() > 0) {
 if (Serial.read() == 'A'){
  char inte1 = Serial.read();
  int inte2 = Serial.parseInt();
  int inte3 = Serial.parseInt();
  int inte4 = Serial.parseInt();
  int inte5 = Serial.parseInt();
  Serial.print(inte1);
  Serial.print(inte2);
  Serial.print(inte3);
  Serial.print(inte4);
  Serial.println(inte5);
 }
}

Although i read quite a bit now, serial input is still a mystery to me.


text:
IR frequency difference
I want to create a device that interfaces with the Light Strike Lasertag system using an Arduino Leonardo.
The Light Strike system uses not laser but regular infrared signals. According to a site that I found (http://www.meatandnetworking.com/projects/hacking-at-the-light-strike-laser-tag-game/) it uses 37.8 khz signals. I only found IR-receivers using 37.9 or 38 khz. Can I use them? How far can the modulation frequency differ?
Is there anything else I need to watch out for when creating an IR-interface?

That's more than close enough. See http://electronics.stackexchange.com/questions/84327/universal-ir-receiver-for-tv-remotes. But note that the frequency being sent may vary from one gun to the next. So your may be different from the one that was tested in that article.

Can I use 37.9 or 38 kHz IR-receivers for 37.8 khz communication?

Yes you can, it should be close enough. (I am assuming you are talking about some kind of prebuilt receiver that just receives the IR data and transmits it via RS232 or something like that)

I'd suggest you'd use a phototransistor and a IR diode for the communication. You will have a lot more control over what frequencies you are operating on. Altho it might take a bit more work to program it, the end result will be exactly how you wish.

source: Stack Exchange

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

sort: votes


text:
ISP - Wrong direction frying ATmega
I tried to flash my ATmega328P-PU not over the Arduino but over a self-made programming board and an USBasp. The problem is, I made the board a while ago and didn't mark which direction the 10-pin connector has to go.
My question is, can I fry the ATmega if I connect the 10-pin connector the wrong way around? Also, can this harm the USBasp in any way?
Connecting it the wrong way around would give me the following connections:
USBasp  ---  ATmega

MOSI    -|
NC      -|-  GND
RST     -|
SCK     -|

MISO    ---  Vcc
Vcc     ---  MISO

         |-  MOSI
GND     -|-  NC
         |-  RST
         |-  SCK

As long as there isn't anything connected to the arduino that uses power you'll probably be fine. The clamping diode on the MISO pin will pass VCC from the usbASP to the arduino's vcc. I've done something similar a few time myself, and the chips are still fine. Just don't leave it connected the wrong way for too long. But I'd suggest just getting the multimeter and check that way, before connecting.

No, connecting it backwards shouldn't do any damage, it just won't work.  The clue is in these two connections:
NC      -|-  GND
GND     -|-  NC

With it backwards the ground connection doesn't go anywhere.  Without that ground connection there's no circuit.  With no circuit, no current flows.
The only possible danger is to the protection diodes in the IO pins when you try and operate the programmer.  The lack of a ground connection could cause some current to flow the wrong way through the circuit (in through the ATMega's MISO pin and out through the MCU's Vcc pin) through the ESD protection diode.  That could cause damage to that diode and maybe the rest of the MISO pin's logic, but it's not that likely since the currents involved would be somewhat limited by the route the power then takes through the MISO pin of the programmer.

Thanks for the answer! Is there any danger for the programmer?

I'm not sure what the design of the programmer is, but a sensible one would include resistors in all the IO lines to protect against overcurrent, so it's highly unlikely that it would cause any problems.

Ok, sounds good. Thanks a lot for your help!

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


text:
Arduino Leonardo/Pro Micro sleep and USB
I am using an Arduino Pro Micro (basically a Leonardo in a smaller form factor) in a mobile application where power consumption is really important.
To reduce power consumption, I put the Arduino to sleep, but that disconnects USB. That's not really acceptable in this application, since reconnecting USB after the Arduino wakes takes pretty long (a second or two).
Is there some way to keep the USB connection alive while still conserving energy? E.g. by waking the ATMega32u4 frequently to keep the connection alive? Or is there some not-as-deep sleep moden where the USB connection stays alive?
Edits for clarification:
The device is an USB HID device. If the device goes to sleep after a few minutes of inactivity, having to reconnect after the user pressed a button causes quite a long delay between pressing the button and a reaction on the device.
I am using the ATMega32u4's native USB implementation, so no V-USB or anything similar.
I am putting the device to sleep like so:
Keyboard.end();
USBCON = 0;
LowPower.powerDown(SLEEP_120MS, ADC_OFF, BOD_OFF);

This is how I wake it up again:
USBDevice.attach();
delay(50);
Keyboard.begin(KeyboardLayout_en_US);

Did you try LowPower.idle(...);?

No, not yet, I will try that, thanks!

@EdgarBonet That's exaclty what I needed, it works perfectly, thanks! Do you want to post this as an answer so I can accept it?

Removing the power LED can reduce power consumption also.

@sa_leinad Thanks for the input, I was planning to do that!

The Arduino has several sleep modes. They differ mainly by the clocks
that are kept running, the peripherals that are enabled, and the
possible wake-up sources. All these modes are described in the
datasheet of the ATmega32U4 microcontroller, section 7:
Power Management and Sleep Modes.
You may see here that “Power-down” is one of the deepest sleep modes:
all clocks are disabled, the main oscillator is turned off, and only
asynchronous wake-up sources are available. As you have experienced, the
USB port is not functional in this mode.
In contrast, “Idle” is a somewhat shallow sleep: the CPU is halted but
the peripherals remain clocked. Any enabled interrupt can be used as a
wake-up source. This is a good option if you want the USB link to remain
connected while sleeping, and you can get it with the LowPower.idle()
function.
If you are worried about the sleep mode to be too “shallow” and not save
enough energy, note that the parameters if LowPower.idle() let you
specify which peripherals you want to keep running during sleep. If you
keep running only those that are needed, this should limit the power
consumption to what is strictly needed.

Thanks a lot, this solved my problem! Thanks also for the really nice write-up!

This would better serve as a comment, but I can't post comments (yet)...

What is your application doing? Is it supposed to be asynchronous? Why are 1-2 seconds too long?
By the "USB" connection, you mean the UART/Serial peripheral?
How are you putting the board to sleep? Are you using the Arduino Sleep Modes? If so, which one are you using?

I'll speculate a bit: if you are using the ASP, then you might have to change the source code for the functions you are using to accommodate for keeping that peripheral awake. Do note that it might make the application more power-hungry than you want it to be.
Waking up more often could be done, but ideally you would need a synchronization mechanism, because at least eventually you'll run into an issue where you might miss the data or you'll wake up the device so often, you'll lose your power savings.

the ATmega32u4 on Micro has native USB peripheral

I added the requested information to the question.

@Dakkaron thanks! I'll have to look at this more, this is not necessarily a trivial problem. I'd suggest trying out the standby mode and seeing if the USB is more responsive. Does your application require the powerdown mode? Also, why do you do "USBCON = 0" vs "USBDevice.detach()"?

Thanks for the feedback, I will try that. The main reason I didn't try that, is because my solution is what Google turned up. Thanks for the input!

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


text:
XL335B accelerometer reports false readings
I'm using an XL335B accelerometer in a GY-61 breakout board. I'm powering the device using the UNO's built-in 3.3V power supply. The following code should convert the readings to m/s² (SI); however, it returns (-0.43|-0.52|-5.83) instead of the expected (0|0|-9.81) when lying untouched.
Code:
const float CYCLE_LENGHT_MILLIS = 1000;

// REFERENCE_VOLTAGE 5 & STEP_COUNT 1024
// => VOLTAGE_STEP 0.0048828125
// MAX_ACC_VOLTAGE 3.3
// => MAX_ACC_VOLTAGE_STEP 675.84
// MIN_ACC_VOLTAGE 1.65 = 0.5 MAX_ACC_VOLTAGE
// => MIN_ACC_VOLTAGE_STEP 337.92
// MAX_ACC_MEASUREMENT 29.43 = 3g

// acceleration = (read()-MIN_ACC_VOLTAGE_STEP) * MAX_ACC_MEASUREMENT/(MAX_ACC_VOLTAGE_STEP-MIN_ACC_VOLTAGE_STEP)
//This can be simplified to: acceleration = read()*j - k
// => j = MAX_ACC_MEASUREMENT / (MAX_ACC_VOLTAGE_STEP-MIN_ACC_VOLTAGE_STEP)
// => k = MIN_ACC_VOLTAGE_STEP * j

const float j = 29.43/(675.84-337.92);
const float k = 337.92*j;

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

void loop(){
  Serial.print("(");
  Serial.print(analogRead(0) * j - k);  //X-AXIS
  Serial.print("|");
  Serial.print(analogRead(1) * j - k);  //Y-AXIS
  Serial.print("|");
  Serial.print(analogRead(2) * j - k);  //Z-AXIS
  Serial.println(")");
  delay(CYCLE_LENGHT_MILLIS);
}

Shouldn't it be (analogRead(0) - k) * j?

Not as far as I know. Tested it anyways, it returns (26.53|26.44|21.04).

I've edited my post to add what j and k are. I won't post the reasoning that brought me to acc = read()*j - k here because I would be throwing readability out the window. I'll look into posting it somewhere else in a more organized fashion.

You are assuming here that 3g will result in the maximum voltage of 3.3v. This is not correct. The datasheet says it's 0.3v/g so; 0g-voltage + 3 x 0.3v => 1.65 + 3*0.3 = 2.55volt. Try (analogRead(0)-337.92)/61.44 (337.92 is the 0g voltage in steps; 61.44 is 0.3V is steps)

Now it's returning (-0.06|-0.10|-1.09). What am I missing?

Sorry. That is for g's. So just multiply by 9.81 to get acceleration or whatever that's called. (analogRead(0)-337.92)/61.44*9.81

@Gerben Thanks for your help. If you post your comments as an answer, I'll mark it as the correct one. BTW, is it normal for the IC to be so imprecise? I mean, (-0.63|-0.47|-10.53) when IRL it's (0, 0, -9.81) is not exactly amazing.

You are assuming here that 3g will result in the maximum voltage of 3.3v. This is not correct. The datasheet says it's 0.3v/g so; 0g-voltage + 3 x 0.3v => 1.65 + 3*0.3 = 2.55volt.
To get the g value use (analogRead(0)-337.92)/61.44 (337.92 is the 0g voltage in steps; 61.44 is 0.3V is steps).
To get the acceleration is m/s² just multiply by 9.81; so (analogRead(0)-337.92)/61.44*9.81
Like you stated in the comments, the result isn't that accurate. Just have a look at the datasheet. e.g. Volt per G is typically 300, but can be anything from 270 to 330. Same thing goes for the 0g voltage; 1.35V to 1.65V. So quite a bit of difference can occur between one chip and the next. Even between the 3 axis inside one chip.
So the best thing is to calibrate all 3 axis. For the Z axis; just lay the sensor flat, and get the analogRead value (-1g value). Flip the sensor upside down and get the analogRead value (+1g value). Optionally place the sensor on it's side to get 0g value or just calculate the value in the middle of the above two value. The steps-per-g will be the difference between the two divided by 2 (+1g - -1g = 2g). Put this value and the 0g step-value into the formula. Repeat the procedure for the other 2 axis.

An effective but yet simple calibration is explained in https://chionophilous.wordpress.com/2011/08/26/accelerometer-calibration-ii-simple-methods/

We need to find the 0G mark and the sensitivity on each axis.  Call them m_x, delta_x, m_y, delta_y, m_z, and delta_z (e.g. m_z is the zero-G mark or the “middle” on the z-axis, delta_z is the sensitivity on the z-axis).  That makes 6 numbers,  so we should expect to need at least 6 measurements.

Check also the more accurate setup: https://chionophilous.wordpress.com/2011/08/26/accelerometer-calibration-iii-improving-accuracy-with-least-squares-and-the-gauss-newton-method/

Least-Squares
Here is the idea.  We’ve been assuming that there are just six numbers we need to find to get a good calibration: m_x, m_y, m_z, delta_x, delta_y, and delta_z.   Now matter how we place our sensor before we take readings, we assume it is still and is detecting exactly 1G of acceleration in some direction.
So if we read value x on the X-pin, y on the Y-pin, and z on the Z-pin we can look at the acceleration vector
If our measurements have no noise and our parameters are correct, the length of this vector should be exactly 1 no matter which way it is pointing


text:
Simple Arduino - 74hc595 shift register construction [tmli5]
I'm quite new to Arduino world and I'm trying to understand how shift registers work.
I built this construction :

In fact, it is an Arduino Duemilanove with AtMega on it, but afaik it doesn't matter.
The tutorial I try to follow use SPI library so I try to do it too. I kind of understood that data input, latch and clock had to be pins 7, 4 and 11.
Basically, all I try to do is sending a byte to light the LEDs. As for me now, the sequence should light all LED, then no one, then one after another.
I know there is one more input ont the right side of the SR but I didn't plan this model so I ran out of LEDs...
This is the code I use :
#include <SPI.h>
#include <StandardCplusplus.h>
#include <vector>
#include <iterator>
#include <size_type>

using namespace std;

//pin du shift register
#define DATA_PIN 13
#define LATCH_PIN 4
#define CLOCK_PIN 11
//à utiliser plus tard
#define INPUT_PIN 2

void setup() {
  pinMode(DATA_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  pinMode(CLOCK_PIN, OUTPUT);
  //pinMode(INPUT_PIN, INPUT);

  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.begin();

  //SPI.transfer(getBit(3));
  //digitalWrite(LATCH_PIN, HIGH);
  //digitalWrite(LATCH_PIN, LOW);

  Serial.begin(9600);
  Serial.println("start !");
}

void loop() {
  shift(B11111111);
  shift(B00000000);
  shift(B10000000);
  shift(B01000000);
  shift(B00100000);
  shift(B00010000);
  shift(B00001000);
  shift(B00000100);
  shift(B00000010);
  shift(B00000001);
}

void shift(int n){
  SPI.transfer(n);
  digitalWrite(LATCH_PIN, HIGH);
  digitalWrite(LATCH_PIN, LOW);
  Serial.print("shift : ");
  Serial.println(n);
  delay(1000);
}

When I upload this code, LEDs sequence has no sense, but serial output was totally OK.
What I see (without the output 0 of course) is :
1111111, 0111111, 1011111, 1110111, 1111101 and then 1111111 without further changes, whereas serial output is 255, 0, 128, 64, 32, 16, 8, 4, 2, 1, 255, 0, 128 and so on.
I assume I didn't understand something important, and it prevent me from finding answers in google.
Thanks for helping, it's really disturbing for me.
EDITS :
changed the title, it is a 74HC595.
Strangest behavior too (not gonna create another topic for that now), I dont have to connect both the gnd and VCC from my arduino for this to light LEDs. It changes a little the brighness of LEDs, but surprisingly VCC< GND< both
This is the tutorial I use to understand shift registers : https://youtu.be/6fVbJbNPrEU?t=195, and the one that uses SPI is nXl4fb_LbcI
I am now aware that I should get one resistor for each LED but I don't have that much resistors and as far as I can see this don't harm my LEDs nor underpower them.

Which part are you using? - question says 74HC165, Fritzing drawing shows 74HC595. You show a resistor between the right and left "ground" busses - the IC's ground pin must be connected directly to ground.  You also need current-limiting resistors in series with each LED.

On a 74HC595,  pin 12 (wired to Due pin 13) is STCP, storage register clock input, while pin 14 (wired to Due pin 4) is DS , serial data input.  This conflicts with your
#define DATA_PIN 13, #define LATCH_PIN 4 statements.  Maybe your other code compensates; but anyway fix it on your board and in your code and in your fritzing diagram then edit the question to match.  I suggest you wire Ard pin 12 to '595 pin 12 and  Ard pin 13 to '595 pin 13 to reduce cognitive dissonance.  Also, wire pin 8 of the '595 directly to a ground bus, not to the LED bus that has a resistor between it and ground.

@PeterBennett just a typo, thanks. I didn't know about the resistor, and this conflict with what I understand about current, I will investigate.

@jwpat7 the tutorial video I watched uses different names as yours so it confuses me a little. It also says that these pins are mandatory to use SPI, but maybe I misunderstood. I corrected the Fritzing drawing, it was just an error in drawing.

I dont have to connect both the gnd and VCC from my arduino for this to light LEDs. - that is called "parasitic power" and it isn't good for the chip. Effectively the chip is being powered by the data inputs, which it is not designed to do. my LEDs don't die - not yet, no.

LEDs sequence has no sense - you acknowledge something is going wrong, but you are rejecting the advice which would correct it.

You have a number of problems here. The first is the wiring.

My wiring diagram above is for the Uno / Duemilanove. Since that is what you have, you should follow that.
The pins are fixed in hardware, except for the slave select pin. Thus D13 on the Duemilanove should go to pin 11 on the 595. D11 on the Duemilanove should go to pin 14 on the 595. And your slave select (which may as well be pin 10 on the Duemilanove) should go to pin 12 on the 595.

Your code looks more complex than it needs to be. This code will exercise the 8 LEDs:
#include <SPI.h>

const byte LATCH = 10;

void setup ()
{
  SPI.begin ();
}  // end of setup

byte c;
void loop ()
{
  c++;
  digitalWrite (LATCH, LOW);
  SPI.transfer (c);
  digitalWrite (LATCH, HIGH);
  delay (20);
}  // end of loop

As other responders have said, you should have a current-limiting resistor for each LED. You can't share it like that.
Also the 595 ground (pin 8) should be wired to the Duemilanove ground, not via a resistor.

Reference
Using a 74HC595 output shift register as a port-expander

I corrected my diagram, is it OK now ? I'll let resistor like that because my LEDs don't die and I dont have enough resistors yet.
"The pins are fixed in hardware", I assumed that but I cannot find it on the web. Also the tutorial I use (https://youtu.be/nXl4fb_LbcI?t=777) don't really agree with you.

Yes, well that is certainly sad. I trust you don't believe everything you see on YouTube. :) He is bringing the chip select low and high at the wrong time. See SPI - Serial Peripheral Interface - for Arduino. Have a look at my post about Hacking a scrolling LED strip sign - as I sit here that sign is still showing me the temperature and humidity, so I think my recommendations are correct.

When you're still a young newbie, you trust anyone who's brave enough to make a youtube tutorial you know :-) Also there is quite a lot of different names for pins and concepts. I cannot figure out what are MOSI, SS and SCK compared to data_in, latch, clock clear...
Your LED strip sign is so cool ! I hope someday I'll have the level to do stuffes like this !

In a couple of cases, it's ok to use a single resistor for all the LEDs (supposing the LEDs all have comparable Vf):  1, if only one LED is ever on at once;  2, if you don't care that LEDs get dimmer as more of them are turned on.  For a simple lashup like this it's reasonable to use a single dropping resistor.

Hopefully my diagram clears up the pin names. MOSI (Master Out, Slave In) = Data_In (on the slave), SCK (Serial Clock) = Clock, SS (Slave Select) = Latch (in this case).

Victory !!! Thanks to your last comment, I finally understood it all and everything works perfectly fine ! Last little question : you don't need "beginTransaction" or anything else, as stated in the SPI manual ?

See SPI - Serial Peripheral Interface - for Arduino reply #9. The way I did it above uses deprecated function calls. It still works, or you can use beginTransaction. Read that link for details.


text:
How to pass 2 parameters with RCSwitch library?
I'm learning Arduino's world, but knowing very little about C and C++.
I'm trying to achieve a little RF transmitter which should send the temperature and  humidity from a DHT-11 sensor to a Raspberry Pi.
I'm using the RCSwitch library to send information with the Arduino, and the 433Utils library to receive it on the RPI.
Using those 2 libraries demos, I was able to send an integer, holding temperature or humidity information (mySwitch.send("00001010");), and read it on the RPI.
But how can I send both informations so that the RPI will know which one is the temperature and the humidity ?
I know I could just send both and assume the lowest is the temperature, but this would be very messy and not very rewarding.
EDIT :
Following Edgar's answer in https://arduino.stackexchange.com/a/52992/11604, I know write:
void send_string(const char *str){
    int i = 0;
    for (char *p = str; *p; p++ ) {
        mySwitch.send((i<<8) + *p, 16);
        i++;
    }
}

void loop() {
    delay(1000);
    h=40.650;
    t=32.0078;
    hic=33.586;
    String x = "$H" + String(h) + "T" + String(t) + "HI" + String(hic);
    send_string(x.c_str());
}

Works perfectly ! (see his complete answer for the RPI-side code)

mySwitch.send("T45H50");, mySwitch.send("[45;50]");, mySwitch.send("T45"); mySwitch.send("H50");...

Are you really sending an integer, or are you sending an ASCII representation of the binary bits of an integer?

The send() method take either an integer, a string byte representation or a tri-state code, I cannot send a string directly

The library you have chosen is not designed for transmitting information between nodes. It is intended for sending simple ON/OFF commands to RF-connected switches.  Bending it to send data in the way you want would be difficult.  Not impossible, but difficult.
Instead you should be considering a more suitable system, such as the popular RadioHead library. It appears to have Raspberry Pi support out of the box:

Raspberry Pi Uses BCM2835 library for GPIO http://www.airspayce.com/mikem/bcm2835/ Currently works only with RH_NRF24 driver or other drivers that do not require interrupt support. Contributed by Mike Poublon.

Alternatively a small Arduino as an interface between the RF module and the Pi may be another option.

I think this library is what I was looking for, thanks ! But I don't understand your last sentence, in what is this different than what I'm doing ?

Actually, RadioHead is far too complicated when you don't fully understand what you are doing (hope I'll get it someday). I found a very good answer with RCSwitch https://arduino.stackexchange.com/questions/52989/how-to-transmit-string-data-using-the-rc-switch-library.

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


text:
Help Connecting Arduino Uno To Computer
I am A Newbie to Arduino
I have a Windows 7 PC. Last Time I bought an Arduino Uno Clone but after working for a day, it stopped detecting on the port. So I bought a new Clone Of different brand. Now I Want in which sequence should I install its drivers, Coonect it, Unzip Arduino IDE...Reboot??
I dont want a problem this time. Another question is Should I first connect the clone and then Install its drivers Or first install drivers and then plug the board? When Is the reboot required?
Product Link : https://m.ebay.in/itm?itemId=121708881208
Please Explain...
Thanks In Advance

Tip: Don't buy an "Arduino" from someone that can't even spell "Cable".

In $US, they are selling it for $7.64. This is indeed cheap. In english, there is a phrase; You get what you pay for. This means in this context, you are paying for low quality. If you can, try to but the real thing.

I have shorted my bords a few time and they always came back to "life" after a minute. Maybe you should be more concern about the voltage you supply to the board. Even if it can take up to 12 volt I never use more then 9 volt on the board. And if you run motors on them its always good to supply them with an external power source and use something like a H bridge to power your devices. I made mistakes and my board are still in mint conditions.

I would like to start by pointing out that you are using a clone. The arduino IDE by default does support clones. Just install your port drivers that's far enough.
The reason your board got spoilt the last time definitely was not cause you did not install the drivers in the right order. It could be due to many reasons, few listed below:

Poor PCB quality
Humidity
Cheap USB to UART converter.
Short circuit in your connection

So what I recommend is the either the use of genuine arduino boards if you can afford.
Note: Most likely its only the USB to UART (CH340G) that has been destroyed, you could buy a hot air station and replace the IC, it is a much cheaper solution.

The clone Uno probably cost $5. A hot air station would be more likely to be 10 to 20 times that much, plus you would need the replacement chip and considerable skill to change it over.

@NickGammon You do have a point, the only reason I recommended him to replace the IC was since he was getting into electronics he might as well learn to replace an IC. While we are here, have you had any experience with clones as to why the USB to UART chip tends to get fried easily?

No, I don't know that. Possibly they are manufactured "on the cheap" and have lower tolerances. It might save a hundredth of a cent to omit, for example, protection diodes. It seems to work, people buy it, and you can always blame "user error".

I bought an Arduino Uno Clone - strictly speaking it should be a "Xxxx brand: (Arduino-compatible)". There is only one Arduino Uno, and that is the official one made by Arduino. According to the Arduino FAQ "Arduino" is a trademark of Arduino LLC and should not be used for unofficial variants.. If you mentioned the brand in your question, it might help other people's buying decisions in the future.

I just checked the link and the item is not available anymore. That way it is impossible to say which driver you should install.
I agree with the answers and comments so far, get the real board. I've heard of people who fried their USB ports because of Arduino clones and their terrible/absent circuit protection.
If you can't afford the original board, what will you do if it damages your computer?


text:
Knowing the Ohms of a Radio Speaker
I have extracted a speaker frim a cheap radio. And I want to connect it to arduino uno. But, I dont know the rating of the speaker. And I am Afraid that If it is over rated, it can fry my arduino. The diameter of the speaker is 9 cm (approx). Whether this Speaker is more likely to be  of 4 ohms, 8 ohms, or 16 ohms ???
I dont have a multimeter...What cam be the probable value of speaker ?

Have you tried measuring it?

I'm not aware of any simple rule that relates speaker diameter to speaker impedance.  Traditionally, 8 Ω is quite likely for typical cheap speakers, with 4 Ω not far behind in likelihood.
As pointed out in the Measure Speaker Impedance link that AMADANON gave, the DC resistance of the speaker's coil will be somewhat lower than the speaker's AC  impedance.  The link suggests 6 Ω DC resistance for a speaker with 8 Ω impedance.
As far as driving the speaker from an Arduino output pin, all of the likely values of speaker impedance are too low to allow driving it directly.  Dividing the maximum allowed pin current of 40 mA into 5 V gives 125 Ω as the least resistance an Arduino output should ever see.  When I attach a speaker to an Arduino output, I usually put a 200 to 400 Ω resistor in series with it.  For my purposes (eg alert-buzzers) that gives enough volume without overstressing the Arduino.
If you still have the radio, look for a small transformer near the speaker connection.  If the radio has an audio output transformer, it probably will have a few KΩ of resistance in the primary and a low-resistance secondary.  If you attach the primary of that transformer to the Arduino pin you can deliver slightly more power to the speaker, but may need some  clipping diodes or flyback diodes in the circuit to prevent damage from overvoltages.

Indeed, and if you put 250 Ω in series, you are protected against a short circuit (as that only lets 20 mA through which is acceptable). Plus what jwpat7 said about a flyback diode. Alternatively drive the speaker from a small transistor which will probably make it louder and also protect the output pin.

What difference does it make anyway? If you are protecting the output pin with a resistor, whether the speaker is 4 Ω or 8 Ω isn't going to make much difference to your choice of current limiting resistor. FWIW I measured a speaker which claims to be 8 Ω and got 7.9 Ω on my meter.

@NickGammon, possibly I missed the context of your second comment.  Anyhow, my phrase  “all of the likely values of speaker impedance are too low to allow driving it directly” and the  200 Ω to 400 Ω range I mentioned are consistent with your “whether the speaker is 4 Ω or 8 Ω isn't going to make much difference to your choice of current limiting resistor”.

Yes, I think we are in agreement. :)

To clarify, my comment was not aimed at you. It was aimed at the OP. Why does it matter what the impedance is?

I googled "measure speaker resistance" and found http://www.wikihow.com/Measure-Speaker-Impedance
Step by step instructions
You will need a multimeter - a great thing to have in any case.

I dont have a speaker. What can be the probable value of The speaker. according to its Diameter (9 cm) ?

I have extracted a speaker from a cheap radio. ... I dont have a speaker. - Do you have a speaker or not?

Sorry that was mistyping. I have a Speaker but I dont have a Multimeter. What can be the probable value of The speaker. according to its Diameter (9 cm) ?

What difference will it be in your application if it is 4 or 8 Ohms? Do you really need to know? Just go ahead and test it with a series resistor.

Get a multimeter. If you are doing anything electronics related, you will need one sooner or later. They're not expensive. Or find your local hackerspace/makerspace - they are usually happy to let people use their tools (take your speaker in).  They can also teach you to use the tools. And they're great guys. I don't know where you live, so some of the above statements might not apply to your local hackerspace (but probably do).


text:
Talking to ADS8698 (18-bit ADC) over SPI
I want to talk to an ADS8698 over SPI (see page 36 for details on their SPI implementation) using a Teensy 3.2. Right now I'm only getting zeros back and I feel like (perhaps wrongly) that I've followed the datasheet correctly. I believe my SPI mode is correct and, given the clock rates I'm using, I should be observing the timing constraints properly.
(1) Is there a glaring error here? I haven't coded that many SPI interfaces, so I might have a novice mistake in there.
(2) Is there existing code for a product that uses a nearly identical SPI interface to the ADS8698 (any product that has a similar timing diagram would do)?
#include <SPI.h>

#define USB_RATE 19200//usb transfer rate
#define SPI_CLOCK 10000000//spi clock frequency

#define CS0 10

SPISettings ADC_SPI(SPI_CLOCK, MSBFIRST, SPI_MODE1);

void setup()
{
  // disable both multiplexers
  pinMode(CS0, OUTPUT);
  digitalWrite(CS0, HIGH);
  // prepare serial protocols
  Serial.begin(USB_RATE);
  SPI.begin();
}

void read_ADC()
{
  // begin the session by taking CS0 low
  SPI.beginTransaction(ADC_SPI);
  digitalWrite(CS0, LOW);// slave select disable
  // delayMicroseconds((int) (1e6 * 20/SPI_CLOCK));// wait > 16 clock cycles
  // transfer 16 bits while the ADC performs conversion
  SPI.transfer(0); // I'm not trying to set any registers, just waiting (zero is fine)
  SPI.transfer(0); // I'm not trying to set any registers, just waiting (zero is fine)
  // data should be ready, so try to read it
  Serial.println(SPI.transfer(0));
  Serial.println(SPI.transfer(0));
  // end the session by taking CS0 high
  digitalWrite(CS0, HIGH);// slave select enable
  SPI.endTransaction();
}

void loop()
{
  delay(1000);
  read_ADC();
}

The system is wired like this:

How have you wired it all up?

What do have connected to  analog input 0? Having 0's would be the right result it it's connected to GND.

Hi Gerben, thanks for the response. The system certainly is not noiseless. With nothing connected there will be non-zero readings from the ADC.

I've added the system wiring diagram.

Per the Datasheet PG47
During power-up or reset, the default content of the command register is all 0's and the device waits for a command to
be written before being placed into any mode of operation.
If your still working with this I'm going to be tackling this same thing very soon, hopefully I can get it to work with DMA.
https://forum.pjrc.com/threads/34863-Teensy-CC-Dummy-Load-300W/page4


text:
How to program AVR in Mac OS X?
In our college we are using a module developed by IIT Bombay (called FIREBIRD V[ver 5]). It has ATmega2560 and ATmega8 microcontrollers (master and slave) with bootloader.
The staff uses AVR Studio for programming. But since AVR Studio is supported only on Windows (and I have a Mac), I was looking for AVR programming in Mac. I downloaded Crosspack AVR. But I don't know how to proceed after this point. Also I downloaded TextWrangler (because I was told auto-suggestion is not available in TextEdit).
Also I have downloaded the Arduino IDE, and I don't know what is required or how to configure it to program AVR microcontrollers.
I searched on the web and nothing is clear (mostly they all depend on something to do with terminal and the command line).
I don't have Xcode installed in my Mac (I saw a relatively easy tutorial on how to set up Xcode for this purpose) and the file is 4GB. I am trying to work around using Xcode, but if it's the only nice way do let me know!
Pertinent suggestions would be helpful.

Does the board use ISP or a serial protocol for programming?

It uses serial peripheral interfacing @IgnacioVazquez-Abrams

Then I wouldn't use ISP as the accepted answer suggests.

any suggestions... maybe the hard way!? because anyways it'll be good if i know them

Do you have a link to any documentation for the board?

https://github.com/akshar100/eyantra-firebird-resources/blob/master/Fire%20Bird%20V%20ATMEGA2560%20Robots%202010-12-29/Manuals%20and%20Application%20notes/Manuals/Fire%20Bird%20V%20ATMEGA2560%20Omnidirectional%20Robot/Fire%20Bird%20V%20ATMEGA2560%20Omnidirectional%20Robot%202010-12-26.pdf                 the omnidirectional bot is the one we're using now. I don't think you'll find enough there. I have a pdf about the software part of the robot. I don't know where to find them on the internet.

The software manual was located in a parent directory. Unfortunately nothing states what protocol it uses, so I'm going to have to dig deeper. The non-Arduino clock rate of the board means that you can't select an existing entry though...

Hah. Installing it shows AVROSP.EXE. That means either AVR109 or AVR910, both of which are supported by avrdude.

crossavr has avrdude right? so how do i go about setting it up?

No clue. I've never used crossavr. I'd look at using the Arduino IDE (1.6.x), although you need a file or two in order to make it work with the board. I think I have all the info I need, now to put it together...

anythg that'll make it work is fine.. :-)

First, install and get familiar with version 1.6.x of the Arduino IDE. Then, under the sketchbook directory, within hardware/nex/avr/ (create the directories if they don't exist) create the following files:
boards.txt:
# NEX Robotics Fire Bird V
# Only ATmega2560@14.7456MHz supported for now

nexfirebirdv2560m14.name=Fire Bird V ATMEGA2560 @ 14.7456 MHz
nexfirebirdv2560m14.upload.tool=avrdude
nexfirebirdv2560m14.upload.protocol=avr109
nexfirebirdv2560m14.upload.maximum_size=129024
nexfirebirdv2560m14.upload.maximum_data_size=8192
nexfirebirdv2560m14.upload.speed=115200
nexfirebirdv2560m14.bootloader.low_fuses=0xFF
nexfirebirdv2560m14.bootloader.high_fuses=0xDA
nexfirebirdv2560m14.bootloader.extended_fuses=0xFD
nexfirebirdv2560m14.build.mcu=atmega2560
nexfirebirdv2560m14.build.f_cpu=14745600L
nexfirebirdv2560m14.build.core=arduino:arduino
# This is not the real variant, but it will get the board running
nexfirebirdv2560m14.build.variant=arduino:mega

platform.txt:
name=NEX Robotics Fire Bird V
version=0.0.0

I have verified that an empty sketch will build, but do not have the hardware to test uploading. The upload.protocol value may need to be changed to avr910 or arduino if the current value doesn't work. Make sure to restart the IDE after any changes to the configuration files.
Further improvements that can be done include:

A real variant for the specific board
Support for the on-board ATmega8 (for now just use one of the slave firmwares uploaded with avrdude)
Support for the other AVR boards
Support for the 8051 and ARM boards

If you don't want to use the Terminal and the command line, the Arduino IDE is your best option. Get yourself an AVR programmer (or an Arduino Uno to serve as programmer, with the ArduinoISP sketch uploaded), and code on it.

Then connect your Arduino to your module via SPI. Select the correct processor and port.

You can now upload the sketch:


text:
Need help in modifying the design
I am planning to do a project on Sequential tilt motion lock using Arduino uno and accelerometer. I would like to present the accelerometer within a rotatable object. So what other components do i have to add to be able to do it i.e.. for wireless transmission of data from the object(that has the acc. meter) to the Uno board.

Seems to do the trick already. What else do you need?

@Gerben i would like to perform the task wirelessly..

So then add a wireless serial module.

@IgnacioVazquez-Abrams i am a absolute beginner to electronics and stuff. So if you can suggest a component that will be good for me to purchase and try and do the project.

@SomasundharamSampath There are hundreds of different modules and frequencies available. With what do you wish to control it?

The basic idea of the project is to have a unconventional key to doors.. So i thought of fixing the arduino board to the door and have a portable object within which the acc. meter will be placed... So to give signal to the arduino board from acc. meter i require a wireless module (range:less than 30 meters is sufficient i guess)

If you do a google search for "arduino wireless serial" you'll get several results. Plugging them into the arduino should be trivial. Most suppliers (other than ebay) will also have examples for you to reference where it comes to coding your project to use the module.
You should also be aware that you will usually need a transceiver, and a receiver.
You might take a look into the XBEE solutions, as they appear to be popular.

authors: Тарас Павлик


text:
How to find out if HX711(amplifier and 24-bit ADC) is damaged or not?
I'm using this ADC with a load cell for weight measurement, I had 4 strain gauges and mounted them on a cantilever structure that I made out of acrylic sheet, used calibration program from here: https://github.com/olkal/HX711_ADC/blob/master/examples/Calibration/Calibration.ino,
followed the steps but it gave calibration factor as 0.00 and the output was NaN or inf . I used another program from here: https://github.com/queuetue/Q2-HX711-Arduino-Library/tree/master/examples/simple_scale and the output was just hovering around 83868. So I thought that the mounting was the problem and used a load cell (green label, CZL 601) with the above and found the same results by doing the above.
Then I thought maybe the ADC is at fault , measured the power output from Arduino to the board and it was around 5 V , but when I measured between the E+ and E- , I got 0 V. Since it is the excitation voltage to the bridge, it should be around 5V too right?
Is this the right way of checking the board?
P.S. I measured the four wires of the load cell and connected the opp. ends of the bridge to the E+ , E- , A+ , A- (order doesn't matter here right? connected the pairs that showed the rated resistance to E's and A's separately)
Here's a [pic][1] of the connections
Between White and green wire the Resistance is 350 ohm
Between Bk( connected in the board ) and the red it is 408 ohm
Between White and red it was 263 ohm
Between white and bk it is 320 ohm
Between bk(not connected in the board) and all others it is around 1 MOhm (so ignored that)
[1]: https://photos.app.goo.gl/4HEmZaN1EwZ7Mjur7

Start by checking the communication between the Arduino and the HX711. If that isn't working then you won't see anything useful. E+ won't be 5V until told to be by the Arduino.

@Majenko can you pls elaborate how do I do that! Also since I'm giving the 5V output of UNO to VCC of the HX711 module , I assumed E+ will be 5V ! (Just saw the datasheet , there's a transistor in between )

@Majenko do you mean reading the Dout pin by giving some voltage to A+ ?

Examine the DOUT and CLK pins using either a logic analyser or oscilloscope.

I don't have those things , its actually a small project that I'm doing for my home!  Any other method, that doesn't require more electronics!! Really appreciate the help, it's just that it's not a practical option for me! Thanks

Double check your wiring. Post a picture of your setup so we can check your wiring for you.

@Majenko Couldn't attach here , so attached as a link ...

Have you changed the pin numbers in the sample code to reflect the pins you are using in your setup?

Yes I did! I have gn it as 8 and 9 !

You wouldn't have been the first not to. So it sounds like something is dead. Your Arduino looks some what "battered". You may want to make sure those pins actually work by blinking an LED through them. If they do then it could be that the HX711 is dead. The only way to be sure without more kit is to replace it and see what happens.

Although... looking more closely at your photo - you haven't soldered the headers to your HX711 breakout board. You need to do that or they won't be making a good contact.

Thank you for your I/p. Since I just bought it , I thought I'll plug and see! I'll try to test out other possible causes and let you know!

@Majenko your observations were spot on! once I soldered the components everything fell in place, thanks again!!!

Looking closely at the photo of your setup I can see that you haven't soldered the header to the breakout board. Whilst there are headers available that don't require soldering, and ways of making header connections that don't require soldering, this isn't either of those.
Without solder the connection to the board will be intermittent at best and non-existent in general.


text:
Programming ESP8266 to avoid random exceptions?
Below is the code that I have done on Lolin Wemos D1 R2 and mini it works fine but it throws exceptions every time, I tried understanding my problem by reading this: NodeMCU 1.0 - Exception 9 `Fatal exception 9(LoadStoreAlignmentCause):` but couldn't!
#include <FirebaseArduino.h>
#include <SoftwareSerial.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
//#include "FS.h"

//---------firebase creds---------
#define FIREBASE_HOST "homeauto-3130d.firebaseio.com"
#define FIREBASE_AUTH ""

//--------wifi creds--------
#define WIFI_SSID "********"
#define WIFI_PASSWORD "***************"

SoftwareSerial esp(D2,D8); //rx tx

//--------data from arduino to esp-------
float temp_fb;
float gas_fb;
float hum_fb;

//-------checking time elapsed b4 printing ------
unsigned long last_chk = 0 ;
unsigned long time_elapsed;

//-----ctrlling sending rate to firebase----
bool t_ar , h_ar , g_ar = false ; //chk arrival of all data b4 sending
char r;
int found = 1;

//-----setting feeder pos from firebase
String feed_load = "0" ;

//-----getting time stamp from ntp server
char time_stamp[12];
int len;
const long utcOffsetInSeconds = 19800; //gmt+5hrs:30mins => 19800 sec
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);

//------------------------schedule vars----------------------------

void setup()
{
  Serial.begin(9600);
  esp.begin(4800);

  SPIFFS.begin();

  // connect to wifi.
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("connected: ");
  Serial.println(WiFi.localIP());

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

  if(Firebase.failed())
     {
      Serial.print("failed...");
      Serial.println(Firebase.error());
     }
  timeClient.begin();
}

void loop()
{
  time_elapsed = millis();
  if(time_elapsed - last_chk > 5000)
  {
    Serial.println("checking for data from arduino...");

    last_chk = time_elapsed;
    time_elapsed = millis();
  }
   while(esp.available()>0)
  {

     if(found == 1)
     {
      Serial.println("................found data...............") ;
      timeClient.update();
      len = sprintf(time_stamp , "%d:%d:%d" , timeClient.getHours() , timeClient.getMinutes() , timeClient.getSeconds() ) ;
      Serial.print("Time stamp:\t");
      Serial.println(time_stamp);
      found = 0;
     }
     r = esp.read();

     switch(r)
     {

      case 't':
      {
        Serial.print("got t...") ;
        t_ar = true;
        temp_fb = esp.parseFloat();
        Serial.println(temp_fb);
        break ;
      }

      case 'g':
      {
          Serial.print("got g...") ;
          g_ar = true;
          gas_fb = esp.parseFloat();
          Serial.println(gas_fb);
          break ;
      }

      case 'h':
      {
        Serial.print("got h...") ;
        h_ar = true;
        hum_fb = esp.parseFloat();
        Serial.println(hum_fb);
        break ;
      }
      default: break;

     }

  }

  found = 1 ;

  if(g_ar and t_ar and h_ar)
  {
     //writing to firebase
     Serial.println("got the set.. to fb now");
     Firebase.pushString("Time stamp" , time_stamp);
     Firebase.setFloat("GAS SENSORinst" ,gas_fb);
     Firebase.setFloat("HUMIDITY SENSORinst" ,hum_fb);
     Firebase.setFloat("TEMP SENSORinst" ,temp_fb);
     Firebase.pushFloat("GAS SENSOR" ,gas_fb);
     Firebase.pushFloat("HUMIDITY SENSOR" ,hum_fb);
     Firebase.pushFloat("TEMP SENSOR" ,temp_fb);

  }

  t_ar , h_ar , g_ar = false ;

  feed_load = Firebase.getString("feeder");

  if (feed_load != "0")
   {
    Serial.println("\trecd req to feed");
      esp.print('w');
      esp.print(feed_load);
      feed_load = "0";
      Serial.println("\tsetting feeder to close in firebase");
      Firebase.setString("feeder" , "0");

   }

}

Here's the error log:(I've only pasted the exceptions, they just repeat over and over again)
Exception (28):
epc1=0x4020cda0 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000034 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffc50 end: 3fffffc0 offset: 01a0
3ffffdf0:  0000000b 3ffeeb28 3fff0e18 40206e5c
3ffffe00:  3ffe8857 000001bb 3fff0e18 40207d34
3ffffe10:  3ffe890b 0000003b 3fff0e18 4020817c
3ffffe20:  0000003b 3fffff00 3ffeec64 40203eb0
3ffffe30:  3ffffe78 0000003b 3ffffe60 40209018
3ffffe40:  3ffeeb24 3ffffe60 3ffe890b 3ffffee0
3ffffe50:  3ffeeb24 3ffffea4 3fff0e14 402057ab
3ffffe60:  3fff10bc 003b003f 00fffea4 3fff0f4c
3ffffe70:  000c000f 00ffff5c 3fff0ef4 001d001f
3ffffe80:  00fe876b 3ffeeb20 3fffff62 3ffffee0
3ffffe90:  3ffeeb24 3ffe8888 3fff0ca4 402034ec
3ffffea0:  3ffe876b 3fff0f38 3fff0ec4 3ffeea78
3ffffeb0:  3fffff5c 3ffffee0 3ffe876b 40203e74
3ffffec0:  3ffffee8 3fffff00 3fffff00 3ffeea78
3ffffed0:  3fffff5c 3fff0ca4 3ffeeb20 40204765
3ffffee0:  3ffeeb60 3fff0ed0 05e353f7 40205fef
3ffffef0:  3ffeeb20 3ffeeb20 3fffff50 402047a6
3fffff00:  00220000 3fff0174 3ffeea78 402068ca
3fffff10:  00000006 00000002 40205fbc 402067ac
3fffff20:  00c3c10e 00000006 3fffff5c 40209018
3fffff30:  3ffeeb20 3fffff5c 3ffe8804 4020904e
3fffff40:  3ffeeb20 3ffe851c 3ffeea61 40201438
3fffff50:  3ffe0000 3fffff80 80feeb84 64656566
3fffff60:  00007265 86595cc2 3ffeeb00 4020113a
3fffff70:  00000000 00000000 feefeffe feefeffe
3fffff80:  00000000 00000000 00000001 40100580
3fffff90:  3fffdad0 00000000 3ffeec74 3ffeecb4
3fffffa0:  3fffdad0 00000000 3ffeec74 40209f08
3fffffb0:  feefeffe feefeffe 3ffe8584 401012d1
<<<stack<<<

Exception (9):
epc1=0x4020cda0 epc2=0x00000000 epc3=0x00000000 excvaddr=0x65656663 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffc50 end: 3fffffc0 offset: 01a0
3ffffdf0:  0000000b 3ffeeb28 3fff0e18 40206e5c
3ffffe00:  3ffe8857 000001bb 3fff0e18 40207d34
3ffffe10:  3ffe890b 0000003b 3fff0e18 4020817c
3ffffe20:  0000003b 3fffff00 3ffeec64 40203eb0
3ffffe30:  3ffffe78 0000003b 3ffffe60 40209018
3ffffe40:  3ffeeb24 3ffffe60 3ffe890b 3ffffee0
3ffffe50:  3ffeeb24 3ffffea4 3fff0e14 402057ab
3ffffe60:  3fff0f1c 003b003f 00fffea4 3fff0f04
3ffffe70:  000c000f 00ffff5c 3fff0eac 001d001f
3ffffe80:  00fe876b 3ffeeb20 3fffff62 3ffffee0
3ffffe90:  3ffeeb24 3ffe8888 3fff0c7c 402034ec
3ffffea0:  3ffe876b 3fff0ef0 3fff0cbc 3ffeea78
3ffffeb0:  3fffff5c 3ffffee0 3ffe876b 40203e74
3ffffec0:  3ffffee8 3fffff00 3fffff00 3ffeea78
3ffffed0:  3fffff5c 3fff0c7c 3ffeeb20 40204765
3ffffee0:  3ffeeb60 3fff0cc8 a7ae147a 40205fef
3ffffef0:  3ffeeb20 3ffeeb20 3fffff50 402047a6
3fffff00:  00220000 3fff0174 3ffeea78 402068ca
3fffff10:  00000006 00000002 40205fbc 402067ac
3fffff20:  00c15609 00000006 3fffff5c 40209018
3fffff30:  3ffeeb20 3fffff5c 3ffe8804 4020904e
3fffff40:  3ffeeb20 3ffe851c 3ffeea61 40201438
3fffff50:  3ffe0000 3fffff80 80feeb84 64656566
3fffff60:  00007265 86461819 3ffeeb00 4020113a
3fffff70:  00000000 00000000 feefeffe feefeffe
3fffff80:  00000000 00000000 00000001 40100580
3fffff90:  3fffdad0 00000000 3ffeec74 3ffeecb4
3fffffa0:  3fffdad0 00000000 3ffeec74 40209f08
3fffffb0:  feefeffe feefeffe 3ffe8584 401012d1
<<<stack<<<

edit1 decoding error stack, this is what i get...
Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
PC: 0x402141d4: HTTPClient::connected() at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp line 472
EXCVADDR: 0x00000040

Decoding stack results
0x40206e64: HTTPClient::disconnect(bool) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp line 435
0x40207d3c: HTTPClient::end() at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp line 425
0x40208184: HTTPClient::begin(String, unsigned short, String, String) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp line 379
0x40203eb8: std::string::_Rep::_M_destroy(std::allocator  const&) at c:\users\admin\documents\arduinodata\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits/basic_string.tcc line 452
0x40209164: String::copy(char const*, unsigned int) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\WString.cpp line 214
0x402057b3: FirebaseHttpClientEsp8266::begin(std::string const&, std::string const&) at C:\Users\Admin\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient_Esp8266.cpp line 51
0x402034f4: FirebaseRequest::sendRequest(std::string const&, std::string const&, char*, std::string const&, std::string const&) at C:\Users\Admin\Documents\Arduino\libraries\firebase-arduino-master\src\Firebase.cpp line 73
0x40203e7c: std::basic_string  , std::allocator  >::basic_string(char const*, std::allocator  const&) at c:\users\admin\documents\arduinodata\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits/basic_string.tcc line 218
0x4020476d: FirebaseArduino::getRequest(String const&) at C:\Users\Admin\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseArduino.cpp line 101
0x40205ff7: std::_Function_base::_Base_manager ::_M_manager(std::_Any_data &, const std::_Any_data &, std::_Manager_operation) at c:\users\admin\documents\arduinodata\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2/functional line 1954
0x402047ae: FirebaseArduino::getString(String const&) at C:\Users\Admin\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseArduino.cpp line 132
0x402068d2: SoftwareSerial::rxBits() at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\SoftwareSerial\src\SoftwareSerial.cpp line 394
0x40205fc4: std::_Function_base::_Base_manager ::_M_manager(std::_Any_data &, const std::_Any_data &, std::_Manager_operation) at c:\users\admin\documents\arduinodata\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2/functional line 1931
0x402067b4: std::_Function_handler ::_M_invoke(const std::_Any_data &, unsigned int &&) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\SoftwareSerial\src\SoftwareSerial.cpp line 393
0x40209164: String::copy(char const*, unsigned int) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\WString.cpp line 214
0x4020919a: String::String(char const*) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\WString.cpp line 36
0x40201440: loop() at C:\Users\Admin\Desktop\dummy\iot1\tonodemcu/tonodemcu.ino line 151
0x40201142: setup() at C:\Users\Admin\Desktop\dummy\iot1\tonodemcu/tonodemcu.ino line 72
0x40100580: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\core_esp8266_main.cpp line 160
0x4020a054: loop_wrapper() at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\core_esp8266_main.cpp line 180

Exception 9: LoadStoreAlignmentCause: Load or store to an unaligned address
PC: 0x402141d4: HTTPClient::connected() at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp line 472
EXCVADDR: 0x65656663

Decoding stack results
0x40206e64: HTTPClient::disconnect(bool) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp line 435
0x40207d3c: HTTPClient::end() at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp line 425
0x40208184: HTTPClient::begin(String, unsigned short, String, String) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp line 379
0x40203eb8: std::string::_Rep::_M_destroy(std::allocator  const&) at c:\users\admin\documents\arduinodata\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits/basic_string.tcc line 452
0x40209164: String::copy(char const*, unsigned int) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\WString.cpp line 214
0x402057b3: FirebaseHttpClientEsp8266::begin(std::string const&, std::string const&) at C:\Users\Admin\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient_Esp8266.cpp line 51
0x402034f4: FirebaseRequest::sendRequest(std::string const&, std::string const&, char*, std::string const&, std::string const&) at C:\Users\Admin\Documents\Arduino\libraries\firebase-arduino-master\src\Firebase.cpp line 73
0x40203e7c: std::basic_string  , std::allocator  >::basic_string(char const*, std::allocator  const&) at c:\users\admin\documents\arduinodata\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits/basic_string.tcc line 218
0x4020476d: FirebaseArduino::getRequest(String const&) at C:\Users\Admin\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseArduino.cpp line 101
0x40205ff7: std::_Function_base::_Base_manager ::_M_manager(std::_Any_data &, const std::_Any_data &, std::_Manager_operation) at c:\users\admin\documents\arduinodata\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2/functional line 1954
0x402047ae: FirebaseArduino::getString(String const&) at C:\Users\Admin\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseArduino.cpp line 132
0x402068d2: SoftwareSerial::rxBits() at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\SoftwareSerial\src\SoftwareSerial.cpp line 394
0x40205fc4: std::_Function_base::_Base_manager ::_M_manager(std::_Any_data &, const std::_Any_data &, std::_Manager_operation) at c:\users\admin\documents\arduinodata\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2/functional line 1931
0x402067b4: std::_Function_handler ::_M_invoke(const std::_Any_data &, unsigned int &&) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\libraries\SoftwareSerial\src\SoftwareSerial.cpp line 393
0x40209164: String::copy(char const*, unsigned int) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\WString.cpp line 214
0x4020919a: String::String(char const*) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\WString.cpp line 36
0x40201440: loop() at C:\Users\Admin\Desktop\dummy\iot1\tonodemcu/tonodemcu.ino line 151
0x40201142: setup() at C:\Users\Admin\Desktop\dummy\iot1\tonodemcu/tonodemcu.ino line 72
0x40100580: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\core_esp8266_main.cpp line 160
0x4020a054: loop_wrapper() at C:\Users\Admin\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\core_esp8266_main.cpp line 180

Read from here: NodeMCU Exception 28 - intermitent problem that exception 28 maybe because of some functions not returning values and I can take that because, i just connected the ESP without arduino just to check what happens, but during other times I only recall exception 9 being repeated
The var String feed_load is read from firebase , which gets the value from a app made from MIT app inventor , I store 0 or value of load in it (a float) ; but app inventor stores it as a string, so i am reading it as a string , i tried putting char feed_load[5] but it gave a error saying string cannot be stored in char[5]
kindly help in fixing this problem , there's some more code to be written for scheduling activities , so i don't want the board to be constantly resetting or restarting

decode the stack

Are you sure your code can compile properly? if(g_ar and t_ar and h_ar) is not even a valid c++ syntax.

@hcheung code compiles and has been working for days :)

@Juraj i've added the decoded error stack now !

Do you get compiler warnings?

@SimSon No warnings , only thing i noticed was , that there were multiple files for ESPin Arduino and ArduinoData files (i don't know how this one came into existence, but i didn't bother deleting it, as something else might crop up!!)

it is a known problem. use HttoClient as local variable

@Juraj you mean instead of Firebase.function() , i hv to use Firebase HttpClient and use HttpClient.function() or do i have to use a different library altogether?

Does this answer your question? ESP8266 always resetting after 65 second of running

@Juraj I have to try that library(ESP8266HTTPClient) , since the one i'm using(FirebaseArduino) is still using ArduinoJson 5.13.5 , I thought of using the library from here: https://github.com/mobizt/Firebase-ESP8266 , but generally the former looks like a good library to use for this kind of applications ! I'll see if either of these fixes the problem, thanks!

sorry, I was on a small display of a phone. the FirebaseArduino uses HttpClient. check if there is a fix for FirebaseArduino to workaround the problem

I don't know if this is the actual fix for the problem ,but instead of FirebaseArduino library i used FirebaseESP8266 library and the random exceptions did not come up (yet)
FirebaseESP8266 https://github.com/mobizt/Firebase-ESP8266/
P.S. sorry for not reverting back quicker !!


text:
Fixing serial communication , condition for serial data available checks out even after reading all the data sent
I have been working on monitoring an aquaculture , where I log the environment variables (temp. , humidity, gas sensor data) to firebase and control feeding mechanism via an app(where data can also be viewed)
The setup has all sensors connected to Uno Board, which transmits data serially to esp8266.
Pin 2 of Uno is connected to Pin 2 of esp8266
Pin 3 of Uno is connected to Pin 3 of esp8266
Right now the boards are being powered by USB ports in the computer.
My understanding is that, once all the data are read, the Serial.available() becomes 0 and the while() loop will not execute again, but it worked again and reads data.. to  avoid sending same data over and over again(to FireBase), I used Boolean values to take care of.
The data should be available only once per 30 seconds, so after a string is fully read, I was able to see that pgm entered into while() loop and reads one/two values

// uploaded to esp8266 Lolin(wemos) d1 r2 and mini

#include<ESP8266WiFi.h>
#include<FirebaseArduino.h>
#include<SoftwareSerial.h>

// Set these to run example.
#define FIREBASE_HOST "@#$%^.firebaseio.com"
#define FIREBASE_AUTH "********"

#define WIFI_SSID "###########"
#define WIFI_PASSWORD "&^*^*%$#"

SoftwareSerial esp(D2,D3);

float temp_fb;
float gas_fb;
float hum_fb;

unsigned long last_chk = 0 ;
unsigned long time_elapsed;

bool t_ar , h_ar , g_ar = false ; //chk arrival of all data b4 sending

char r;
String cu_st = "c";

int found = 1;

void setup() {
  Serial.begin(9600);
  esp.begin(4800);

  // connect to wifi.
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("connected: ");
  Serial.println(WiFi.localIP());

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

void loop()
{
  time_elapsed = millis();
  if(time_elapsed - last_chk > 5000){
    Serial.print("checking for data from arduino...\tfeeder state\t");
    Serial.println(cu_st);
    last_chk = time_elapsed;
    time_elapsed = millis();
  }
   while(esp.available()>0)
  {
     if(found == 1)
     {
      Serial.println("................found data...............") ;
      found = 0;
     }
     r = esp.read();
     //Serial.print("first char\t"); just for debugging purposes
     //Serial.println(r);
     switch(r)
     {

      case 't':
      {
        Serial.println("got t...") ;
        t_ar = true;
        temp_fb = esp.readStringUntil(',').toFloat();
        break ;
      }

      case 'g':
      {
          Serial.println("got g...") ;
          g_ar = true;

          gas_fb = esp.readStringUntil(',').toFloat();;
          break ;
      }

      case 'h':
      {
        Serial.println("got h...") ;
        h_ar = true;

        hum_fb = esp.readStringUntil(',').toFloat();
        break ;
      }

      case 'c':
      {
        cu_st = "c" ;
        Firebase.setString("feeder" ,"c");
      }
      default: break;

     }

  }

  found = 1 ;

  if(g_ar and t_ar and h_ar)
  {
     //writing to firebase
     Serial.println("got the set.. to fb now");
     Firebase.setFloat("GAS SENSORinst" ,gas_fb);
     Firebase.setFloat("HUMIDITY SENSORinst" ,hum_fb);
     Firebase.setFloat("TEMP SENSORinst" ,temp_fb);
     Firebase.pushFloat("GAS SENSOR" ,gas_fb);
     Firebase.pushFloat("HUMIDITY SENSOR" ,hum_fb);
     Firebase.pushFloat("TEMP SENSOR" ,temp_fb);
  }

  t_ar , h_ar , g_ar = false ;

  cu_st = Firebase.getString("feeder");

   if (cu_st == "o")
   {
    Serial.println("\t\trecd req to feed");
    esp.print('o');
   }

}

The arduino sends data every 30 Sec.
The servo connected to Arduino was having jitters every time the data was being sent(apparently due to not enough power to supply for all devices connected and both Softwareserial and servo having same timer) so I have added a LED just for trial
For some reason, if block in close_feed() is always executed.
//uploaded to arduino Uno
#include <SoftwareSerial.h>
#include<TimerOne.h>

SoftwareSerial ArduinoUno(3,2);
#include<Servo.h>
#include "DHT.h"

//Servo feeder;

int send_rate = 30000; //every 30 secs send data
unsigned long last_time_stamp = 0;
unsigned long cur_time = 0;

String sen_vals = "";
#define led 13
int feeding = 0 ;
const int gas = 0;//gas sensor o/p
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  ArduinoUno.begin(4800);
  pinMode(led,OUTPUT);
  //feeder.attach(11);
  //feeder.write(85);
  Timer1.initialize(10000); //every 10 millisecond check for arrival of feed command
  Timer1.attachInterrupt(feed_cmd); //chk feed_cmd for every 10 mS
   dht.begin();

  pinMode (3,INPUT); //recieve from esp
  pinMode (2,OUTPUT); //transmit to esp

}

void feed_cmd()
{
  while(ArduinoUno.available())
  {
    char valve = ArduinoUno.read();

    if(valve=='o')
    {
       digitalWrite(led, HIGH);
       //feeder.write(0);
       feeding = 1;
       ArduinoUno.print("c");
       valve = "";
    }
  }
}

void close_feed()
{
  if(feeding == 1)
  {

    feeding = 0;
    delay(5000);
    //feeder.write(85);
    digitalWrite(led,LOW);
    Serial.println("I am closing feeder");

   }
}

void send_data()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  String ht = String('h')+String(h)+String(',')+String('t')+String(t)+String(',');

  float raw_v = analogRead(gas);
  String g = String('g')+String(raw_v)+String(',');

  sen_vals = ht + g ;

  Serial.println(sen_vals);
  ArduinoUno.print(sen_vals);
}

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

  close_feed();
  cur_time = millis();
  if(cur_time > last_time_stamp + send_rate)
  {

    last_time_stamp = cur_time;
    send_data();

  }

}

Some how some blocks are executed even when they shouldn't be.. I wrote the code, but I cant figure out where the code fails, used a lot of serial prints to see how the flow of the code, but it only confused me further!
If somebody can take a look at this code and point out the flaws..I'll greatly appreciate it.
EDIT: I have changed he code as suggested below, but now the Arduino is receiving random things as input(pic attached)
I have added the changed code too(I know this post is getting bigger and bigger, but i thought making changes to already existing code here won't be good for readability )
void setup() {
  Serial.begin(9600);
  esp.begin(4800);

  // connect to wifi.
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("connected: ");
  Serial.println(WiFi.localIP());

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

void loop()
{
  time_elapsed = millis();
  if(time_elapsed - last_chk > 5000){
    Serial.print("checking for data from arduino...\tfeeder state\t");
    Serial.println(cu_st);
    last_chk = time_elapsed;
    time_elapsed = millis();
  }
   while(esp.available()>0)
  {
     if(found == 1)
     {
      Serial.println("................found data...............") ;
      found = 0;
     }
     r = esp.read();
     //Serial.print("first char\t");
     //Serial.println(r);
     switch(r)
     {

      case 't':
      {
        Serial.println("got t...") ;
        t_ar = true;
        temp_fb = esp.parseFloat();
        break ;
      }

      case 'g':
      {
          Serial.println("got g...") ;
          g_ar = true;

          gas_fb = esp.parseFloat();;
          break ;
      }

      case 'h':
      {
        Serial.println("got h...") ;
        h_ar = true;
        hum_fb = esp.parseFloat();
        break ;
      }
      default: break;

     }

  }

  found = 1 ;

  if(g_ar and t_ar and h_ar)
  {
     //writing to firebase
     Serial.println("got the set.. to fb now");
     Firebase.setFloat("GAS SENSORinst" ,gas_fb);
     Firebase.setFloat("HUMIDITY SENSORinst" ,hum_fb);
     Firebase.setFloat("TEMP SENSORinst" ,temp_fb);
     Firebase.pushFloat("GAS SENSOR" ,gas_fb);
     Firebase.pushFloat("HUMIDITY SENSOR" ,hum_fb);
     Firebase.pushFloat("TEMP SENSOR" ,temp_fb);
  }

  t_ar , h_ar , g_ar = false ;
  if (cu_st == "c")
  {
    sent = 0;
  }
  cu_st = Firebase.getString("feeder");
   if (cu_st == "o")
   {
    Serial.println("\t\trecd req to feed");
    if(sent == 0)
    {
      esp.print('o');
      sent =1;
      cu_st = "c";
      Serial.println("setting feeder to close in firebase");
      Firebase.setString("feeder" ,"c");

   }

  }
}

#include <SoftwareSerial.h>

SoftwareSerial ArduinoUno(3,2);
#include<Servo.h>
#include "DHT.h"

//Servo feeder;

int send_rate = 30000; //every 30 secs send data
unsigned long last_time_stamp = 0;
unsigned long cur_time = 0;
unsigned long close_time = 0;
unsigned long open_time = 0;
#define led 13
int feeder = 0 ;
const int gas = 0;//gas sensor o/p
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  ArduinoUno.begin(4800);
  pinMode(led,OUTPUT);
  //feeder.attach(11);
  //feeder.write(85); //closing position
   dht.begin();

  pinMode (3,INPUT); //recieve from esp
  pinMode (2,OUTPUT); //transmit to esp

}

void feed_cmd()
{
  while(ArduinoUno.available())
  {
    char valve = ArduinoUno.read();
    Serial.print("feeder cmd recd ");
    Serial.println(valve);
    if(valve=='o')
    {
       digitalWrite(led, HIGH);
       //feeder.write(0); //open position
       open_time = millis();
       feeder = 1 ;
       Serial.println("I am opening feeder");
    }
  }
}

void close_feed()
{

  if(feeder == 1)
  {
   close_time = millis();
   if(close_time - open_time > 5000)
  {
    feeder = 0;
    digitalWrite(led , LOW);
    Serial.println("I am closing feeder") ;
  }
  }
}

void send_data()
{
  float h = dht.readHumidity();

  float t = dht.readTemperature();

  float raw_v = analogRead(gas);

  ArduinoUno.print("h");
  ArduinoUno.print(h);
  ArduinoUno.print(",t");
  ArduinoUno.print(t);
  ArduinoUno.print(",g");
  ArduinoUno.print(raw_v);
  ArduinoUno.print(",\n");
}

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

  feed_cmd();
  close_feed();
  cur_time = millis();
  if(cur_time - last_time_stamp > send_rate)
  {

    last_time_stamp = cur_time;
    send_data();

  }

}

Thanks for your time!!!

I cannot really narrow down the source of your observed problems, since the problem descriptions are not clear enough. But there are some obvious problems/potential for making it better in your code.
In the Uno Code:

It is totally unnecessary to use a timer interrupt for reading the SoftwareSerial interface. Instead you should write your loop() function non-blocking, meaning, that it does not wait for something to happen, but it will execute other code in the meantime (so no delay in close_feed()). Then you can just read the serial data in the loop function. You are saving a timer this way.
In send_data() you are using the String class to concat a string of human readable data together and then send it. Using the String class in that way is evil, since on every concat operation it will allocate a new buffer for the string, deleting the old one. That makes Swiss cheese out of your heap memory (called heap fragmentation). That can lead to instability. Look at Majenko's blog entry about the Evils of Arduino Strings for more information. Instead of concatting you should simply print the information one after another:
Serial.print("h");
Serial.print(h);
Serial.print(",t");
Serial.print(t);

and so forth.
Your handling of the millis() function should be different. It will roll over after 52 days. To prevent, that your code misfunctions at that time, you need to always take the time difference:
if(cur_time - last_time_stamp > send_rate)

instead of
if(cur_time > last_time_stamp + send_rate)

In the ESP Code:

Your SoftwareSerial read code seems weird to me, but I think it should work. I would introduce a message protocol to the data stream, meaning to mark the end of a full message (a message containing one frame with all relevant data) with a special delimiter character, for example a newline character \n. Then you can read the message until this character into a buffer and then process the message as a whole.

That's about what I can say to this point. If you need a more focused answer, you have you describe further and more detailed the symptoms (what behavior you are seeing and what you expected).

thanks for pointing out some good practices and details ... will work this out...

As far as the issues go, I'm struggling to put it to words... Eg. When the pgm starts, there's no pblm, but when I give command to open from App, it just starts printing I am closing feeder  continuously , that shouldn't be happening right, because we set feeding =0 and only way it goes into if block of close_feed() is if feed_cmd() got invoked again, but that shouldn't happen because we've already read from the incoming serial.. Hope I've explained my issue!!!

You send the feeding character o continuously based on the Firebase value "feeder". It that value reset directly after you have set it? If not, meaning if the Firebase value "feeder " stays "o", the esp will continuously send the character 'o', which will cause the Arduino to continuously close the feeder.

Yes, I get the flow now.... But I thought once Arduino receives the open cmd, by sending "c" to esp, which in turn writes to firebase , this shouldn't be happening I'll re-write it so that esp itself will send "c" to firebase right after sending open cmd to arduino... (funnily enough, that's how i had it earlier, but since the feeder valve was not responding, i thought maybe the value change was changing too quick and "c" was being read skipping "o" cmd )

You should only send the "o" cmd once to the Uno. Even if you immediately send "c" back to the ESP, the ESP most likely will already have send several "o" commands to the Uno. So just send it once instead of continuously

any suggestions as to why this new behaviour has occurred.?


text:
Random characters transmitted from ESP8266 to Arduino
Below is  the code for getting a value from Firebase and sending the received data to arduino for performing necessary action.
The code here here sends a string "o" to arduino once
//uploaded to ESP8266
.
.
.
if (cu_st == "c")
  {
    sent = 0;
  }
  cu_st = Firebase.getString("feeder");
   if (cu_st == "o")
   {
    Serial.println("\t\trecd req to feed");
    if(sent == 0)
    {
      esp.print("o");
      sent =1;
      cu_st = "c";
      Serial.println("setting feeder to close in firebase");
      Firebase.setString("feeder" ,"c");

   }
.
.
.

Below is the code that gets the value, carries out necessary actions.
//uploaded to arduino
.
.
.
void feed_cmd()
{
  while(ArduinoUno.available())
  {
    char valve = ArduinoUno.read();
    Serial.print("feeder cmd recd ");
    Serial.println(valve);
    if(valve=='o')
    {
       digitalWrite(led, HIGH);
       //feeder.write(0); //open position
       open_time = millis();
       feeder = 1 ;
       Serial.println("I am opening feeder");
    }
  }
}

void close_feed()
{

  if(feeder == 1)
  {
   close_time = millis();
   if(close_time - open_time > 5000)
  {
    feeder = 0;
    digitalWrite(led , LOW);
    Serial.println("I am closing feeder") ;
  }
  }
}
.
.
.

My expectation/understanding is that:
feed_cmd() continually checks for any data
As soon as it receives data LED turns ON and after 5 sec close_feed() turns OFF the LED.
But what happens is that the while() in feed_cmd() continually executes showing some random data and also all of what I said above is also being carried out! (pic attached)

Why is there random serial data, even after sending only once and even after reading the sent data?
Is it bad coding / hardware?
Thanks for reading through and would really appreciate it if you can help me sort it out!!
Edit I found this link smthg abt pin voltages  when I was looking for possible explanation for my code's behaviour, If somebody can simplify it and explain it, it'd be better !!

SoftwareSerial at 115200 baud?

@Juraj Serial monitor is set at 9600 baud , softwareserial i.e sending and receiving data from ESP is set at 4800 baud... so is this the issue?

are both SoftwareSerial on 4800 baud?

@Juraj Yes, they are! Here's smthg I tried, pls let me know if you can make sense of this: i just ran arduino code(disconnecting power to esp8266 but not the data lines between them) , every time arduino sent data, the while loop in feed_cmd gave out 23 bytes(i modified the above code and got 255 or 254 as output to softserial.read() )   then I removed those data lines and saw that while sending data, the while loop no longer got executed

@Juraj I'm begining to think that it's a hardware problem, in my arduino , pins 0-7 are exposed(i.e without those  black female connector heads, it just has 'u' shaped pins ) so i used female connectors to connect to them.. I made sure they weren't touching but still every time data was sent, i was getting additional bytes being read . So i thought maybe there's some short circuit and chose 2 pins that are farther away, but now I'm getting additional 16 bytes

The baud rates, voltages, and timing all have to match up for serial communication to work right.
So, set both of your devices to the same baudrate (you specify the number in Serial.begin()), and ensure they're connected properly. (voltages match, TX to RX, and ground is connected)
You can just read/print the serial input to the arduino with something like Serial.print(softSerial.read()) in your code if you think you don't have serial wired up right.
Also in an unrelated issue; the esp32 spits out data on its main serial line at 115200 when it boots up which you can not disable. you can use the serial port afterwards though.
Here's a copy of what gets printed out on one of mine;
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac

misread the question as esp32. I think the 8266 spits data out on boot @ 74880 baud, but can't confirm if I did that to the board I was testing, or if it came like that. Other than different baudrate on bootup, the answer is the same.

here's how i have wrote the code for Softserial : in Arduino SoftwareSerial ArduinoUno(3,2) // rx | tx  in esp8266 SoftwareSerial esp(D2 , D3) //rx | tx While wiring, I have wired 3 -> D3 and 2 -> D2. As far as power supplies go, I have connected them both to PC's usb port . In both codes I have kept Serial.begin(9600) and SoftwareSerial.begin(4800)

The baudrate (that number in parentheses after .begin() ) needs to be the same number on both devices. Also, if you have a 5V Uno (by which I mean the high-voltage on a pin is 5V), you could damage your esp8266 by connecting the two together.


text:
Request for member is Non-class type
Im getting this error:
iotHook.ino: In function 'void setup()':
iotHook:13: error: request for member 'begin' in 'esp', which is of non-class type 'Esp8266()'
request for member 'begin' in 'esp', which is of non-class type 'Esp8266()'

When I try to lunch my begin function of my class:
class Esp8266 {

  public:
    Esp8266();
    void begin(HardwareSerial *wifiCom, HardwareSerial *debugCom);
    ...
  private:

    HardwareSerial *wifiCom;
    HardwareSerial *debugCom;
    ...

}

Esp8266::Esp8266() {
}

void Esp8266::begin(HardwareSerial *wifiCom, HardwareSerial *debugCom) {
  this->wifiCom = wifiCom;
  this->debugCom = debugCom;

  this->debugCom->begin(115200);
  while (!this->debugCom) {
  ;
  }
}

EDIT 1:
Updated image with new code

Why is not picking up the begin function?

Remove the brackets from your constructor.

@Majenko You mean from this Esp8266::Esp8266() {} to Esp8266::Esp8266() ???

No, what Ignacio says. The constructor in your sketch.

Your current problem is that the USB Serial interface of the Leonardo isn't a hardware serial device, it's a CDC/ACM device, and the class for that isn't HardwareSerial, it's Serial_.
So you can't pass it to a function that expects a HardwareSerial.
What you should be using, instead, is the Stream class.  That will allow you to pass any object that is based on the Stream class, such as HardwareSerial, Serial_, Client, etc.  Many different things, including serial and networking protocols, use Stream as their base class.
It does have the down side, though, that you have to initialize the Stream objects in your sketch (that is, do the Serial.begin(...) and Serial1.begin(...) in your sketch not your class) because the Stream class doesn't have the concept of a baud rate, and so no begin(baud) function.
This is what I mean:
class Esp8266 {

public:
    Esp8266();
    void begin(Stream &wifiCom, Stream &debugCom);
private:

    Stream *_wifiCom;
    Stream *_debugCom;

};

Esp8266::Esp8266() {
}

void Esp8266::begin(Stream &wifiCom, Stream &debugCom) {
    _wifiCom = &wifiCom;
    _debugCom = &debugCom;

    while (!_debugCom) {
        ;
    }
}

Esp8266 esp;

void setup() {
    Serial.begin(115200);
    Serial1.begin(115200);
    esp.begin(Serial, Serial1);
}  // end of setup

void loop() {
}  // end of

Note, as well, my use of pass-by-reference (Stream &whatever) so you don't have to pass a pointer in your begin function.  Also notice the use of unique variable names in the class (I always prefix my member variables with _) so you don't have to keep putting this-> in everywhere.

To be able to move the .begin() function inside your class you will have to use both HardwareSerial and Serial_ object types within your class.  There's two ways this may be done.
First is dynamic casting:
void Esp8266::begin(Stream &wifiCom, Stream *debugCom) {
    _wifiCom = &wifiCom;
    _debugCom = &debugCom;

    HardwareSerial *hard;
    Serial_ *cdc;

    if (hard = dynamic_cast<HardwareSerial*>(_wifiCom)) {
        hard->begin(115200);
    } else if (cdc = dynamic_cast<Serial_*>(_wifiCom)) {
        cdc->begin(115200);
    }

    if (hard = dynamic_cast<HardwareSerial*>(_debugCom)) {
        hard->begin(115200);
    } else if (cdc = dynamic_cast<Serial_*>(_debugCom)) {
        cdc->begin(115200);
    }

}

I haven't tested this, and I don't know if the Arduino's cut-down C++ library is even capable of it, but it's worth a try.
The other method is to overload the .begin() function of your class with multiple versions that take different parameters:
void Esp8266::begin(Serial_ &wifiCom, HardwareSerial *debugCom) {
    _wifiCom = &wifiCom;
    _debugCom = &debugCom;
    wifiCom.begin(115200);
    debugCom.begin(115200);
}

void Esp8266::begin(HardwareSerial &wifiCom, HardwareSerial *debugCom) {
    _wifiCom = &wifiCom;
    _debugCom = &debugCom;
    wifiCom.begin(115200);
    debugCom.begin(115200);
}

void Esp8266::begin(HardwareSerial &wifiCom, Serial_ *debugCom) {
    _wifiCom = &wifiCom;
    _debugCom = &debugCom;
    wifiCom.begin(115200);
    debugCom.begin(115200);
}

You're still storing them internally as Stream objects in all cases, but within the begin() function itself you also have them available as their child classes.  It does mean you have duplicate code copied between the different versions of begin().  You could modularize it a little more though by moving the duplicated code into functions which would only need to be duplicated twice, not three times - one to act on a single Serial_ object and one to act on a single HardwareSerial object:
void Esp8266::initSerial(Serial_ *ser) {
    ser->begin(115200);
}

void Esp8266::initSerial(HardwareSerial *ser) {
    ser->begin(115200);
}

void Esp8266::begin(Serial_ &wifiCom, HardwareSerial *debugCom) {
    _wifiCom = &wifiCom;
    _debugCom = &debugCom;
    initSerial(&wifiCom);
    initSerial(&debugCom);
}
... etc x3 ...

Thank you, this is the cleaner answer. Is not very clear to me why I have to initialize the stream object outside of my class. Is important to me because my code have a guessing routine inside my begin function that tries different baud rates till it finds the correct one (http://pastebin.com/GYjE48yj), since I cant use .begin(speed) inside my class, do you know any workaround?

@DomingoSL It's because the .begin(baud) function only exists in the HardwareSerial and Serial_ child classes and not the Stream parent class.  You could try using dynamic casting to attempt to convert the Stream objects into first a HardwareSerial object and then (if that fails) a Serial_ object, but how that would perform (if it's even possible) on an Arduino is anyone's guess. The other option is to provide multiple begin() functions or constructors that take all the possible different combinations of object types and deals with them accordingly.

@DomingoSL I have added more detail to my answer.

You've confused the compiler by making it think that esp is a function that takes no arguments and returns a Esp8266. But the no-argument constructor is called by default, so you don't need the parens there regardless.
Esp8266 esp;

Updated code according to your answer but same error

Please check the edit I made

You do see that that's a completely different problem, right?

The line:
esp.begin (Serial, Serial1);

Should be:
esp.begin (&Serial, &Serial1);

It is expecting a pointer to a HardwareSerial instance.

Also make the instantiation line:
Esp8266 esp;   // <--------- no brackets!

This compiles without errors for me:
class Esp8266 {

  public:
    Esp8266();
    void begin(HardwareSerial *wifiCom, HardwareSerial *debugCom);
  private:

    HardwareSerial *wifiCom;
    HardwareSerial *debugCom;

};

Esp8266::Esp8266() {
}

void Esp8266::begin(HardwareSerial *wifiCom, HardwareSerial *debugCom) {
  this->wifiCom = wifiCom;
  this->debugCom = debugCom;

  this->debugCom->begin(115200);
  while (!this->debugCom) {
  ;
  }
}

Esp8266 esp;

void setup ()
  {
  esp.begin (&Serial, &Serial1);
  }  // end of setup

void loop ()
  {
  }  // end of loop

I would rework to use references anyway, saves all that mucking around with pointers:
class Esp8266 {
  public:
    Esp8266(HardwareSerial & wifiCom, HardwareSerial & debugCom);
    void begin();
  private:
    HardwareSerial & wifiCom;
    HardwareSerial & debugCom;
  };

// constructor
Esp8266::Esp8266(HardwareSerial &wifiCom_, HardwareSerial &debugCom_)
  : wifiCom (wifiCom_), debugCom (debugCom_)
  {
  }

// initialize stuff
void Esp8266::begin()
{
  debugCom.begin(115200);
  while (!debugCom)
  {
  }
}

Esp8266 esp (Serial, Serial1);

void setup ()
{
  esp.begin ();
}  // end of setup

void loop ()
{
}  // end of loop

Corrected for Leonardo
Sorry, my reply above was compiled for the Mega2560, I didn't notice the Leonardo tag.
Majenko is quite right, you need to rework for the Leonardo. My example using references can reduce down to this now:
class Esp8266 {
  public:
    Esp8266(Stream & wifiCom, Stream & debugCom)
      : wifiCom_ (wifiCom), debugCom_ (debugCom) { }

  private:
    Stream & wifiCom_;
    Stream & debugCom_;
  };

Esp8266 esp (Serial, Serial1);

void setup ()
{
  Serial.begin (115200);
  while (!Serial) { }
  Serial1.begin (115200);
  while (!Serial1) { }
}  // end of setup

void loop ()
{
}  // end of loop

By storing a Stream type you can still print to them, however you need to initialize in setup, not in the begin function, which now becomes redundant.
I agree about not using this-> although my preference is for trailing underscores as the use of leading underscores is reserved in quite a few cases, depending on the location and capitalization.

Now the error is:Esp.h:42:6: note:   no known conversion for argument 1 from 'Serial_' to 'HardwareSerial'
no matching function for call to 'Esp8266::begin(Serial_, HardwareSerial)'

With arduino ide 1.6.5: Esp.h:42:6: note:   no known conversion for argument 1 from 'Serial_' to 'HardwareSerial'
no matching function for call to 'Esp8266::begin(Serial_, HardwareSerial)'

You're thinking double-underscore.  Builtin (predefined) macros have the format __BLAH_BLAH (sometimes with trailing __ too)  although some older compiler versions have some non-standard ones with just one underscore (they are naughty).  Certainly for avr-gcc version 5.2.0 all the predefined macros (with the exception of #define AVR 1) are in the standardized double-underscore format.

According to the C++ Standard: Reserved in the global namespaces: identifiers beginning with an underscore. Thus all identifiers in global namespace, starting with an underscore, are reserved. Also reserved in any context are identifiers beginning with an underscore and an uppercase letter. In addition: identifiers containing adjacent underscores (or "double underscore"). So you are only one capitalization away from a reserved identifier, by using leading underscores. You might be tempted, for example, to make a class constant like _ITEM_COUNT which has now become reserved.

Reserved doesn't mean unavailable.  If you like, all my member variables are reserved - I don't want anyone else using them.  Any my constants are most static and ProperlyCapitalized (as are my class names) since they aren't reserved.

That is a completely different thing. I don't want anyone else using them You can achieve that by making them private. If you use a reserved identifier (which possibly becomes a #define) then you run the risk that a word like _FOO will be replaced by some define which the compiler-implementers are entitled to use, and then find all your code doesn't compile. Whatever your motives are, you should not be using reserved identifiers. There has to be a set of identifiers that compiler-writers can use. They have specified what they are. Use them at your peril in your own code.

As if I would ever be daft enough to use _FOO as a variable. And if I did use it as a macro it would complain during compilation. And you never expose member variables to the wider public - you always have them private (or at worst protected) and use getters and setters. You never use all capitals for variables either, that's just daft. So _FOO is never going to be a conflict, since my member variables would never even approach that format. In my past 30 years of programming I have never come across a conflict like you mention. That can't just down to luck, or I'd have won the lottery by now.

The issue is not whether or not you are daft. The issue is, do you follow the Standard, or not? Look, over the years I've written a lot of code with leading underscores, probably a hangover from the way Microsoft did it. So, I did it too - in the past. Of course, you are free to not follow the Standard. And you may never have a problem. But if you choose to use reserved identifiers, and one day one of them becomes #defined as some weird sequence of characters, you will be scratching your head as to why you get a compile error on what looks like a perfectly good line of code.


text:
Why does enabling TIMSK1 mess up serial?
I am intending to write a code where a user will send lines through serial to affect timer interrupts. I am noticing a problem with serial where as soon as I enable the timer interrupts, the serial communication becomes garbled. More specifically, as soon as I enable the timer interrupts and I open the serial monitor, the monitor gets flooded with garbage. I haven't written too much code and this is already happening. Am I making a silly mistake? I am using an Arduino Mega 2560. My code is below:
void setup() {
  Serial.begin(9600);
  Serial.println("Hello World!");
  timer_setup();
}

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

void timer_setup() {
  // waveform generation = 0100 = CTC
  TCCR1B &= ~(1 << WGM13);
  TCCR1B |=  (1 << WGM12);
  TCCR1A &= ~(1 << WGM11);
  TCCR1A &= ~(1 << WGM10);
  // output mode = 00 (disconnected)
  TCCR1A &= ~(3 << COM1A0);
  TCCR1A &= ~(3 << COM1B0);
  // Set the timer pre-scaler
  TCCR1B = (TCCR1B & ~(0x07 << CS10)) | (2 << CS10);
  OCR1A = 0x4000;
  TCNT1 = 0;
  // Enable timer interrupt mask 1
  TIMSK1 |= (1<<OCIE1A);
}

If I comment out the TIMSK1 |= (1<<OCIE1A) line, serial doesn't mess up.

You've enabled interrupts for Timer 1 Compare A interrupt. Where is the interrupt handler?
For example:
ISR(TIMER1_COMPA_vect)
{
  // whatever
}  // end of TIMER1_COMPA_vect

Without that, the processor is just restarting. No wonder serial output is messed up.

Thanks, Nick. I hadn't added it yet because I wasn't testing interrupts yet, just setting it up. I didn't know it would do that if I didn't include the handler.

You can't "set up" interrupts without a handler and expect things to work. Once you enable the flag, you are promising something will handle them. The compiler generates a default handler that jumps to the start of the program (same place Reset goes).


text:
A question about chars and Serial
I have the following code:
int count = 0;
char serial_char;
char serial_message[96];

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

void loop(){
  while(Serial.available() > 0){

    serial_char = Serial.read();
    if (serial_char == '\n' || serial_char == '\r'){

      serial_message[count] = 0; // <<-- What does this line do?
      count = 0;
      Serial.println(serial_message);

    }
    else{
      serial_message[count++] = serial_char;
    }

  }

}

With this code, I can type a message into the serial monitor, and it will print the message back at me. So if I type 'Goodbye', it returns:
Goodbye

If I send it another message 'Word', it returns:
Word

However, my questions is when I comment out the line:
serial_message[count] = 0;

And then I repeat the same sequence of actions before, 'Goodbye' returns 'Goodbye', but when next I enter 'Word', it returns:
Wordbye

Could anyone explain this to me? I am really curious to know why this occurs. What does adding that 0 in the char array accomplish? Thank you.

Try sending a 96 character string and a 97 character string so your code tries to read and then write outside its buffer.

There is a difference between char[] and String.
You are using char[] which is the best way to work on a small processor like the Arduino. However; it is also a bit more difficult.
Char array is just a piece of memory that can contain any data. Because we want to put a variable length string in there we need a convention to know what is the last character of the string. By convention this is a value 0.
This is why we speak about "null terminated strings".
This explains why after sending word (without adding the 0 at the end" you get "Wordbye" because the memory contains 'W' 'o' 'r' 'd' 'b' 'y' 'e' and 0.
The reason why it works OK with 'Goodbye' is because all memory gets set to 0 at startup of the processor.
So as long as the last send word is longer than the previous it works fine.
A last thing. The memory does not actually contain 'W' 'o' 'r' 'd' 'b' 'y' 'e'. The memory contains the ASCII values of the letters 'W' 'o' 'r' 'd' 'b' 'y' 'e'

The zero-value, the "null character", indicates the end of the string. For strings, you allocate some maximum space, in your case 96 bytes:
char serial_message[96];

When storing variable-length strings in that, you need to indicate where the string ends. That's what the zero value does in a null-terminated string. (Note that 0 is really binary 0x00 here; it's not the ASCII character 48, 0x30.) So, the 96 bytes allow for a string of at most 95 characters, followed by the terminator. When printing, it prints the memory contents until it finds that null character.

Oops. I changed it and forgot to change all of it. I have edited it to be correct. Thank you!

Note that the serial_message[96] is initialized with zeros at the beginning, providing default null terminations for strings up to 96 characters long.  What might be interesting is what would happen if one sends strings 96 or more characters long.  At 96, the Serial.println() wouldn't stop printing until it hits a null in whatever is after the buffer in memory, and if you sent more than 96 characters, it could write over important RAM and crash.