text:
Thought Dropbox was gone, but Arduino IDE kept it running. Search led to Temboo & Arduino Yun. Will it cripple my IDE to cut it out?
Just discovered that long after uninstalling Dropbox the service was still running.  I disabled it in the normal Services control panel.  It turned out to be hiding in /winndows/system32 as dbxsvc.exe
Then went a step further and did this in an Administrator CMD window:
cd /windows/system32
attrib -h -s dbxsv*.*
del dbxsvc.exe
copy con dbxsvc.exe
Nyah^Z
attrib +r dbxsvc.exe

So that should take care of that.
Upon further system searching (using Everything) discovered that Dropbox is used by software called Temboo, which is some kind of cloud-share package for coordinating Arduino Yun applications.
It turned out that it was the Arduino IDE that kept it running.
More searching led me here:
Arduino & Temboo: How It Works
Excerpt:

ON YOUR YÚN Your Arduino Yún includes two lightweight software
  components that make it easy to connect with hundreds of APIs and
  cloud services from any sketch.
First, there's a small C++ library called Temboo.cpp that comes
  bundled with the Arduino IDE. When you include this library in a
  sketch, it provides a streamlined syntax for configuring and invoking
  calls to run Temboo Choreos.
Behind the scenes, calls to Temboo are routed to a client program that
  comes packaged with your Linino base image. This client is a Python
  program that formats the Choreo execution request and uses HTTPS to
  forward the request to Temboo via the cURL utility.
THE TEMBOO PLATFORM Temboo is a scalable, fault-tolerant environment
  for running and managing smart code snippets that we call Choreos.
  Choreos can call APIs, simplify the OAuth process, send email
  messages, perform encoding, update databases, and lots more. You can
  even create your own custom Choreos. Temboo automatically generates
  the sketch code you needed to call these processes, making it simple
  to get up and running with any service from your Yún.
The request from the Yún's temboo client causes the Choreo specified
  in your sketch code to be executed on the Temboo platform. In many
  cases, this means assembling your inputs into the format expected by a
  third-party API, performing the API interaction, handling errors, and
  dispatching filtered results back to the Yún via HTTPS. The results
  are made available to your Arduino sketch by way of Process’s Stream
  methods.

I only use the standard Arduino IDE and regular Arduino Unos and Nanos.  Sure some are Chinese-made, and some use the CH340 connection type.
I do not want my system reaching out through the firewall to any cloud-based services, nor do I appreciate that the Arduino IDE thwarted my earlier effort to disable and remove Dropbox.
I get that it came bundled with the standard Arduino IDE.
So my question is whether anyone knows if it will damage anything if I remove this junkware?
--ADDENDUM - Why to dump Dropbox:
The Dropbox hack is real
Excerpt:

Motherboard reported on what had been rumoured for some time, namely
  that Dropbox had been hacked.
Not just a little bit hacked and not in
  that "someone has cobbled together a list of credentials that work on
  Dropbox" hacked either, but proper hacked to the tune of 68 million
  records.
Very shortly after, a supporter of Have I been pwned (HIBP)
  sent over the data which once unzipped, looked like this:
(The Dropbox data across 4 text files)
What we've got here is two files with email address and bcrypt hashes
  then another two with email addresses and SHA1 hashes. It's a
  relatively even distribution of the two which appears to represent a
  transition from the weaker SHA variant to bcrypt's adaptive workload
  approach at some point in time. Only half the accounts get the "good"
  algorithm but here's the rub: the bcrypt accounts include the salt
  whilst the SHA1 accounts don't. It's just as well because it would be
  a far more trivial exercise to crack the older algorithm but without
  the salts, it's near impossible.
At first glance the data looks legit and indeed the Motherboard
  article above quotes a Dropbox employee as confirming it.

To me it looks like the Temboo website is a gateway to Dropbox. The Yun (and the IDE) have nothing at all to do with communication with Dropbox, nor have any software that can do it. The Yun talks to Temboo. Temboo talks to Dropbox.

And if you're scared someone may have your password from some arbitrary point in the past, then change your password, as well as on any other sites you used the same password.

There is no Dropbox software included with ANY version of the Arduino IDE, nor installed on any Linux based Arduino board.
That is not how Temboo and Dropbox work.
You have Temboo as a (source code) library which you can compile into your sketch, and as a user-agent that runs on the Linux portion of the Yùn. That then forwards a request to the Temboo web servers detailing what operations you want to perform on what services.
It is then the Temboo web servers that connect to Dropbox (or whatever service you want to use) and perform operations on your behalf.
If you have Dropbox software installed on your computer it is not the fault of the Arduino IDE.

Dropbox was removed months ago.  That's why I was so surprised to see the service running.


text:
Arduino not detected
I took an Arduino from a friend yesterday but when I connect it to the laptop there is no light blinking from the Arduino and the laptop doesn't detect any device.
Is there a problem with the Arduino or is there a possibility that the USB has problems?

Try it on other computers. If it works on other computers then it's your laptop's problem. If not then the Arduino or the cable is broken.

I tried on other computers it's the same issue

So your Arduino or it's cable is either broken. Try with other cables. If it's still broken, you have a busted Arduino and probably need to buy a new Arduino.

Okie I'll try other cables

Are you sure your laptop doesn't detect any device? It is possible that you need to install right driver for your arduino. The problem could be with:

Cable: Try to replace it with a working cable
Drivers Issue: You need to install driver for your Arduino. Generally, your laptop will issue warnings if it didn't find any appropriate driver for it.
USB-To-UART Bridge: This is an IC in arduino board. It needs to be working for laptop to detect your board.
Microcontroller: Since, you told us that your board is blinking, then microcontroller will be working for sure.

Can you see any part getting hotter? Have you tried with other laptop and cable?

The device is not blinking and I have already installed a driver but the problem that when I connect nothing happens not even a blinking light .i am going to try to use my friends USB incase it's the cables problem

Adding on to abhiarora's answer, if there are no lights at all on the Arduino, and you verify your cable is outputting power, then you may have shorted the device and need to replace the USB port diode.  On my Arduino Nano, this diode is directly under the USB-mini port, on the bottom of the board.
Picture of diode:

I replaced this on my Arduino Nano with the CDBW0520L-HF from Comchip Technology and the Arduino worked perfectly. (Link provided is from www.arrow.com).
And in case you have a Chinese Arduino Nano like me:

When you say Arduino, which product specifically are you referring to ? the Arduino UNO ?
Assuming it is the Arduino UNO (or Nano) you will need to first check if it is a genuine Arduino product or a clone (not that there is anything wrong with using a clone). Check your board for a CHIP near the USB port. See if it reads FTDI or CH340. If it reads CH340, then you have a clone. Not to worry, you can still use it as any normal Arduino, you will just need to install the appropriate drivers for the CH340 chip. A simple search for "CH340 driver" can fetch you the right results for your operating system.

Yes I am using the nano

I already bought a new one if it also doesn't blink and my computer doesn't detect it then I'll do what u suggested ....thanks

Can you check which chip is used on your existing one ? the FTDI or the CH340 ?

It's CH304 is the chip I am using

Then i would definitely insist that you try installing the drivers for CH340 and try. The standard arduino drivers that come with the Arduino IDE do not work on CH340 clones. A simple google search should give the drivers for download. If you can't find one that works, let me know and I will provide a source.

I already bought a new one but there is no harm in trying ur suggestion ...thanks for your help

source: Stack Exchange

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

sort: votes


text:
Write char array containing new line to SD card
How do I a buffer (char array) containing new line character to SD card using SdFat?
I tried:
File myFile = SD.open("test.txt", FILE_WRITE)
myFile.write(buffer, BUFLEN)

but I get this instead:
0000 0000 0000 0000 0000 0000 0000 3337
3837 3838 3937 3035 2c20 2020 2031 2c20
2020 3531 0a33 3738 3738 3839 3730 352c
2020 2020 322c 2020 2035 310a 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000

If I use the normal method, then it seems that SdFat stop printing at the newline character:
myFile.print(buffer);
Note: the buffer containing data samples in fixed width csv format
3787889751,    1,   49
3787889752,   10,   49
3787889753,    1,   49

I think we'll need a minimal, complete, verifiable example of your code, because I don't think the problem is what you think it is: your stated output doesn't match your stated string, even before the newline.

File.print() stops printing at a NULL character (ASCII 0) not a new line.  You can stick as many new lines as you like in a string and it will print.  Try this example
void loop ()
{
  Serial.print ("Hello\nMultiline\nPrint\n");
  Serial.print ("Hello\0Multiline\0Print\n");
}

File.write() writes binary data to a file, it will write BUFLEN bytes, even if you don't give it that many bytes.
Looking at the output from you hex editor your string ends with ... 2020 2035 310a which would be 3 spaces (20), 51 (35 and 31) and a new line (0A).  There is also a null (00) after that, but I can't tell how many because you have 0s to pad the output (or fill the file).
If you look further back in the output (3rd col, 3rd row) you can see another newline (0a33) so that proves its not new lines that is stopping your output.
Without your code we can't say whats wrong, but I agree with Mark that its not what you think it is.
To write data to a CSV file I would write each row of data into a struct and then hold those structs within a list.  Then have a function that iterated through the list and printed each record to the file.  That way you wouldn't need a buffer.  If it didn't have to be a CSV then you could just call
myFile.write (currentRecord. sizeof(StructRecord));

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


text:
Speed of reading I2C
How long does it take to read I2C?
I'm reading data from I2C sensor through a 20Hz timer interrupt. The interrupt handler only set the readSensorFlag, and I double checked that it happens at 20Hz through putting a Serial print there.
void TIMER2_Interrupt(void) {
  if (NRF_TIMER2->EVENTS_COMPARE[0] != 0) {
        readSensorFlag = true;
        NRF_TIMER2->EVENTS_COMPARE[0] = 0;
      }
    }

Now in the main loop I perform the reading of sensors.
void loop() {
  // Reading data from sensors to a buffer
  if (readSensorFlag) {
    readSensorFlag = false;

    if (bufferCounter < BUFLEN - 2*SAMPLESIZEINCHAR - 1) {
      epoch = millis();
      proximity = vcnl.readProximity();
      ambientLight = vcnl.readAmbient();

The strange this is that: if I set proximity and ambient light to be some constant and not reading from I2C, then the recorded sampling frequency is 20Hz:
  1988,    7,   10
  2038,    8,   10
  2088,    9,   10
  2188,    1,   10
  2238,    2,   10
  2288,    3,   10

If I revert back reading I2C code (second column is data from sensor), then frequency is only 8Hz!!!
 17637,    8,   33
 17763,    9,   33
 17937,    1,   34
 18067,    2,   35
 18194,    3,   34
 18320,    4,   34

How could reading I2C block the timer interrupt? And how could it be so slow? (I've tried a similar sensor before, and could reach 100Hz with that).

That sensor needs time for a measurement. Are you using the Adafruit library ? https://github.com/adafruit/Adafruit_VCNL4010 That library starts a measurement and waits for it to finish. The code has delays, polling, waiting loops and even wrong use of the Wire library. It was not written to be fast.

Let's take a look at a typical function for reading this sensor. This is from the Adafruit_VCNL4010 library and is for reading the proximity:
uint16_t  Adafruit_VCNL4010::readProximity(void) {
  uint8_t i = read8(VCNL4010_INTSTAT);
  i &= ~0x80;
  write8(VCNL4010_INTSTAT, i);

  write8(VCNL4010_COMMAND, VCNL4010_MEASUREPROXIMITY);
  while (1) {
    //Serial.println(read8(VCNL4010_INTSTAT), HEX);
    uint8_t result = read8(VCNL4010_COMMAND);
    //Serial.print("Ready = 0x"); Serial.println(result, HEX);
    if (result & VCNL4010_PROXIMITYREADY) {
      return read16(VCNL4010_PROXIMITYDATA);
    }
    delay(1);
  }
}

So let's tot up all the I2C transactions in that one function:
read8
write8
write8
{repeated
    read8
    [read16]
    delay(1)
}

So in a best case scenario, assuming it's in a "ready" state, that's the minimum number of transactions, and the delay doesn't occur.  So what is in each of those transactions?

read8:

Begin the transaction, write the address, end transaction, delay 170µs, begin request, read 1 byte, end transaction.  Total 4 bytes plus 170µs

write8:

Begin transaction, write address, write data. Total 3 bytes.

read16:

Begin the transaction, write the address, end transaction, begin request, read 2 bytes, end transaction.  Total 5 bytes (I notice this one has no delay...?)
So now we can see a best case scenario total of bytes transferred:
4 read8 *
3 write8
3 write8
{repeated
    4 read8 *
    5 [read16]
    delay(1)
}

4+3+3+4+5 = 19 bytes, plus 2x170µs delay.

The default clock speed for I2C on the Arduino is 100kHz. We have 19 bytes, plus start/stop/ack bits. So 19 * 8 for the data bytes (152 bits) plus 19 ACK bits (171 bits) and 5 * start + 5 * stop. That's 181 bits in total.
181 bits, at 100kHz, takes 1.81ms to transfer. Add to that the 2*170µs delay, and we are up to a best case scenario of 2.15ms transfer.
Double that up for reading the ambient light as well, and we're up to 4.3ms transfer. That's a theoretical absolute maximum of about 230Hz readings.
Remember: that's a best case scenario.  If the sensor isn't ready to return a reading at the time that there will immediately be a 1ms delay imposed and the number of transactions will increase.
So why would it not be ready to send a reading? The simplest explanation is that it's not set to a suitable sampling rate.
The library doesn't appear to change the sampling rate for the proximity from the default 1.95 samples per second, nor the ambient light sampling rate from the default of 2 samples per second - so unless you are using a different library, or manually changing these settings through your own Wire calls, even at a reduced triggering speed you'll not be getting anywhere near the kind of information you are after.
The fastest you can get for ambient light sampling is 10 samples per second. Proximity caps out at a more respectable 250 samples per second. But only if you tell it to...

Thank you so much, you've always been able to find the root of the problem! I set the sampling frequency to 20Hz (in a register of VCNL4010), and voila, it works!


text:
ESP8266 constantly reconnects
So, my ESP8266 now has this problem where every three seconds it goes offline for a split second and the light blinks as it comes back. It seems to be constantly resetting... I recieved this problem when I had it connected to a power brick in my pocket, and I am pretty sure it happened because of static. I would have bought a protective case for it but it appears that I csn only find 3D printed parts but I currently do not own a 3D printer. I am wondering how I can fix it. If I try to re-flash it the re-flash fails because it disconnects before the flashing finishes.

It may be your code getting into a loop that takes longer than the watchdog timeout.

If it is static damage its unlikely you can fix it.  Have you tried running it of a different power supply?

@CodeGorilla I managed to fix the problem, I just needed to re-flash with a python script rather than Ubuntu's ESPTool.

I managed to fix the problem. I have a PC with Ubuntu 16.04 and I tried to re-flash it using Ubuntu's ESPTool, which was why it was failing. I noticed it failed constantly at a certain point. To fix it, I re-flahed the firmware with this python script, and it was successful.


text:
Is there any option to connect XDTouch IrTouchScreen to Arduino?
Is there any option to connect XDTouch IrTouchScreen with USB interface or RS232 to Arduino board?
At the cable of this touchscreen i have something like at the photo.
At the top of the photo pins (+, t, r, -) from touchscreen to SP232EEN, and at the bottom of photo pins (+, D-, D+, -) from CY7C63803-SXC module to USB output.

Looks like your touch screen may talk RS-232. It uses the SP232EEN (a MAX232 clone) to interface with an MCU (Cypress CY7C63803) to get USB.
Connect wires to T1 IN and R1 OUT (I assume it's on channel 1) to your Arduino for UART communication. You would most likely need to disconnect those pins from talking to the Cypress chip, or they will interfere. Use the +5V and GND pins of the USB interface to power it direct from the Arduino.
Alternatively cut that board off and use a cheap MAX232 interface board to connect to the Arduino - that may be cheaper.  T and R are TX and RX (though from which PoV is anyone's guess).

Thanks for Your reply. I disconnect board from cable and I connect to FTDI RS232 module via RX and TX wire.
Red(+) ------>  5V FTDI module,
Blue(T) ------>  RX FTDI module,
Yellow(R) ------>  TX FTDI module,
Black(-) ------>  GND FTDI module
And when I touch touchscreen in response I get weird data.
I checked response at all popular baudrate and nothing.

Example response from touchscreen on 9600 baud example response

Your typical FTDI board ISN'T RS-232. It's UART. RS-232 uses inverted NRZ high voltage (10V) logic and RISKS DAMAGING YOUR FTDI BOARD. DISCONNECT IT NOW.  You need a MAX232 BASED BOARD LIKE I STATED IN MY ANSWER

Ok I see. I bought MAX232EPE 5V and i connect to touchscreen like in this schema and FTDI connect to my computer. Is this connection is ok? I'm asking because I'm afraid I can break something.

If the MAX232EPE you have is an entire module with the required boost capacitors etc then yes, that is fine. If it's just a bare chip you will need more components to get it to work.


text:
Controlling TFT LCD with Arduino
I bought this LCD module. How many pins does this LCD module uses? They have written in the product description that this LCD module uses 8 bit communication, but the LCD module has 16 bit pinout (DB0-DB15). What is the right pin number?
Is there any Arduino LCD library that supports this LCD module, which uses the OTM4001A LCD driver? Usually for LCD the UTFT library works, but it does not support the OTM4001A LCD driver.
Thanks for your help!

Trust what is on the board, not what the eBay seller says. They invariably can't tell the difference between a TFT screen and a doll, and they sell everything in between. They just regurgitate Chinglish nonsense. If the board says DB0-DB15 then DB0-DB15 is what you need to use.
Plus it says in the description:

Support 16 bit RGB565 format , can connect any 16 bit data bus.

At least this one has told you what the driver chip is (OTM4001A) - many times they can't even do that and don't even understand what you are asking when you request that information.
Mind, it's a driver chip I have never come across before, so maybe I should get one on order to support it in DisplayCore...


text:
What are safe memory usage limits?
The Arduino IDE used to warn you when your sketch used too much memory. This warning now seems to have been removed. I compiled a sketch, and was surprised to see it use 175% of data memory...but not give me any explicit warning that this would be unstable, much less be physically unable to load onto the Arduino.
What are program and data memory usage levels that you should be concerned about? I seem to remember the best practice was to keep data memory under 80%. Is this still true? Is there any general rule for program memory?

I'm surprised it even compiled...

It seems unlikely the linker would accept this, perhaps there's a broken configuration as it seems like the percentage is being calculated against something that mismatched the linker map - for example, link for one chip, compare against another.

@Majenko, Me too :)

Had you selected the wrong board?

What version of the Arduino IDE are you using?

The compiler can only report the amount of statically allocated (RAM) memory. Depending on what you are doing in your sketch the value may be important, or it may be completely meaningless.
Suffice it to say, the total of heap + stack + static must not exceed the memory of your MCU.
When it comes to the Flash memory you can go right up to 100%.

There is a "StackPaint" https://arduino.stackexchange.com/questions/763/im-using-too-much-ram-how-can-this-be-measured but I don't know if that still compiles today.

It's a tough question to answer as it depends on the rest of the sketch.  You can safely use every single byte of memory as long as you're sure that's all you're using.  The number that it spits out on compile doesn't tell you that.  It just tells you about global and static variables really.  If you've got a loop that doesn't call any functions then you only need to save a few bytes for the stack. But if you've got a function that creates a local array with 500 ints then you're not safe even if that number it spits out on compile is only 50%.


text:
SD Library Print Full File/Folder name
Right now I have the following code for the Arduino SD Library
#include <SPI.h>
#include <SD.h>

void printDirectory(File dir, int numTabs)
{
  while (true)
  {
    File entry =  dir.openNextFile();
    if (! entry)
    {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++)
    {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory())
    {
      Serial.println(':');
      printDirectory(entry, numTabs + 1);
    }
    else
    {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.print(entry.size(), DEC);
      Serial.println(":");
    }
    entry.close();
  }
}

My hangup is that for file or folder names of 9 or more characters I get back char56~1.TXT How can I get the full name of the files and folders?
Also, What is the best way to, instead of printing to the serial port, only print trees that have a .TXT (or .CSV ) extension?

8.3 filenames and the FAT file system are the only type of filenames supported by the SD library.
https://en.wikipedia.org/wiki/8.3_filename
You can use the SdFat library. It supports long filenames.

Ok! I'll use it. Are there any examples of how to do a recursive file/folder list with the SdFat library? Or would this code still work?

Just see the github page...


text:
DS1307 Real-Time Clock
I am trying to make an Arduino project based on the Sparkfun DS1307 RTC (real-time clock).
There are a few issues with how Arduino libraries don't support checking if the Arduino board has been powered down and check for that.
Then using that as a conditional as to when the program should fall back to the compiled time if the RTC isn't set to a time yet because of something else.
When I power down the clock, it will automatic fall back to the compiled time every single time, regardless of what is currently on the RTC. Clearly this is not something you would want.
Edited - This is my current code. Keep in mind there are a few more changes I could do like take Byte zero declare out of the loop so it is still rough.
#include <Wire.h>
#include <SparkFunDS1307RTC.h>

#define DS1307_ADDRESS 0x68

void setup() {
  Wire.begin();
  Serial.begin(9600);
  rtc.begin();
  if(false){
    //Should check RTC somehow to determine if should fallback to compiled time here.
    Serial.println("The DS1307 clock has lost power and reset to compiler's time");
    rtc.autoTime();
  }
}

void loop() {
  if(digitalRead(7)==LOW)
    printDate();
  delay(1000);
}

byte bcdToDec(byte val){
  return ((val/16*10) + (val%16));
}

void printDate(){
  rtc.update();
  Wire.beginTransmission(DS1307_ADDRESS);
  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);
  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> Sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());
  //Print the date like 3/1/1/11 23:59:59
  Serial.print(month);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);
}

You only need to set the time in the RTC once. There is no need to keep it in the code. But if you still want to, the DS1307 has a Clock Halt bit that is set when the RTC has lost it's power. So you can only set the time when this bit is set.

How do I check if this bit ha been set?

https://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/understanding-the-code#setting-the-time

That link doesn't answer my question. How do you check if RTC lost power? All that link does is show codes I already know about. I am able to set RTC to a new time. The trouble is each time I power up arduino board it will assume RTC is wrong regardless and overwrite it. Which end up with a RTC that still think it is January but really is June for example depending on time compiled.

When the RTC loses power the CH bit is set to 1. When you set the time this bit is also set to 0. So when the Arduino restarts, and this bit still reads 0, you know that you shouldn't change the time.

Please show us your code!

Changed to post my code.

The link did answer your question. Use if (! rtc.initialized()) { instead of your current if(false){. But I still don't see the use. You only set the time once on the RTC. If for some reason in the future the RTC loses power, it doesn't make a difference if you don't set the time, or use the compiled time, as both will be wrong.

I am trying to write a book explaining the basic code and want a nice simple single program. Instead of going back in code to change to true/false depending on your needs. I will test that out tonight. Edit: Looks like initialized() only works with adafruit not sparkfun DS1307 library.

That would indeed make it easier for others. The sparkfun library has no way to read the CH bit. You could instead check if the current year is smaller that 2017. The default value for year is 2000 if the chip loses power.

Yeah that would work well.

DS1307 gives a square wave output which can be set to specific frequencies which is available in the datasheet.
Initially the square wave output is disabled.
You can enable it when you set the time.
When you power up again, check for the square wave and if it is absent you can set the time again.
This can be easily done by creating a timeout code and resetting the timeout timer in an interrupt. If square wave is present an interrupt will be generated accordingly and the timeout time period will be set to initial value.
If the timeout time expires you set the clock. This can even track clock failures in real time. Also you can use the same interrupt to extract data from the RTC as square wave output can be configured to 1Hz and hence you can poll the RTC at every 1Hz and take the data from the RTC.

There are a few issues with how arduino's libraries doesn't support checking if the arduino board has been powered down and check for that.

How is it supposed to do that? The board's powered down.

When I powered down the clock. It will automatic fallback to compiled time every single time regardless of what is currently on RTC. Clearly this is not something you would want.

So don't have a compiled in time.

I saw there was a flag in one of the custom library that check if RTC clock lost power (due to battery dying or disconnect or whatever). But it was for the different brand of RTC DS1307 that I have.

Easy. Here is one way to do it.

Read the clock off the rtc.
Wait a known period of time, based on the mcu frequency,
Read the clock off the rtc again.
Compare the two time reading and it should have advanced. If not, fall back to compiled time.

There are other ways to do it as well, like bor, or square wave output, interrupt on vbat line, ......

This RTC real time clock as far I am aware always tick forward. So checking for that time delta doesn't tell me if the clock has been reset to default time or not. Which is what the question is about.

You could periodically store the date and time in the battery-backed SRAM in the DS1307. Every few seconds, once a minute, something like that.
Upon sketch start, perhaps in setup(), read the current RTC time, compare to the stored time, if the current time is later than the stored time, you can do the math and see how long the Arduino has been down.  Or use the Arduino's EEPROM to hold the last stored time if you are concerned about the RTC losing it's battery and resetting to it's default date and time, which would be earlier than the EEPROM time.

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


text:
Can a 433mhz receiver receive data from a 433mhz tag/fob?
If I use a 433mhz receiver on an Arduino Nano, will it detect a 433mhz tag? I'm not talking about the transmitter that is shown below but a tag/key fob.

Example of 433mhz tag

Nothing in the receiver can power the fob.

@IgnacioVazquez-Abrams the fob has its own power from a battery.

It might be possible to hack the patented protocol :) http://cdn2.hubspot.net/hub/186315/file-2401365665-pdf/docs/Assets/m163-i_tech_spec_sheet.pdf

That should be possible. You'd have to reverse engineer the encoding and protocol though.


text:
SdFat library Change output style of sd.ls(LS_R)
I'm using the SdFat Library's sd.ls(LS_R) function to give me a serial output stream of all files on an SD card. My issue is that I would like to have it use a different character than '\n' at the end of each line as I'm using it as a termchar for my overall comms protocol. How can I get it to print a : or (another symbol that doesn't appear in file names) instead of a \ln

I am currently trying to have fun Modding my own sd.ls().
Worst way, modifying the library:
Go into FatFilePrint.cpp
(Suggestion: Create yourself a new 'flag' like LS_COMMA)
Find the line
void FatFile::ls(print_t* pr, uint8_t flags, uint8_t indent) { ...

add your flag
if (flag & !LS_COMMA) {
   pr-->write(':');
} else {
    //original library set of
    // pr->write(stuff);
}

--> SuperClass version # (prefered )
this will override the original ls() method by creating a new Class inheriting from the original one.
rather then invoking it from "volume",
    sd.ls( your params);
invoke it from a directory file instead.
superFatFile rootDir;
rootDir.open("/");
rootDir.ls( __your_params__);

Place this superClass declaration in your .h
don't hesitate to remove any of the "flags" related code if YOUR requirement never calls for them.
class superFatFile : public FatFile {
    public:
    void ls(print_t* pr, uint8_t flags /* = 0 */, uint8_t indent /* = 0 */){
        superFile file;
        rewind();
        while (file.openNext(this, O_READ)) {
            if (!file.isHidden() || (flags & LS_A)) {
                // adds 'spaces' indent for dir level
                for (uint8_t i = 0; i < indent; i++) {
                    pr->write(' ');
                }

                if (flags & LS_DATE) {
                    file.printModifyDateTime(pr);
                    pr->write(' ');
                }

                if (flags & LS_SIZE) {
                    file.printFileSize(pr);
                    pr->write(' ');
                }

                // prints filename
                if (!file.isDir()) {
                    file.printName(pr);
                    pr->write('\r');
                    pr->write('\n');    // HERE IS YOUR SEPARATOR CARACTERS !!!
                }

                // execute recursivly if LS_R flag was set
                if ((flags & LS_R) && file.isDir()) file.ls(pr, flags, indent + 2);

            }

        }
        file.close();
    } // end of new LS method
}; // end of superClass

Nice,
I ended up changing my termchar


text:
Scrambled query responses from ESP8266 to Uno, what are possible causes of the problem?
I have a small test sketch that sends queries to an ESP8266 chip [mounted on an ESP-01 board], and these responses are invariably scrambled,
though the response varies from execution to execution, e.g.,
(execution 1)
_________[ Connect to AP ]__________
__________[ AT+CWJAP="KCTcircuit2","" ]__________
AT+CWJAX="I⸮Tcircuiz2",""H

(execution 2)
__________[ Connect to AP ]__________
__________[ AT+CWJAP="KCTcircuit2","" ]__________
AT+CWJAH="KCTcircuiz2!,""H

What could be the source of the problem?  I need to resolve this before I can start testing the real sketch.
My test sketch follows [stripped of extraneous code]:
#include <SoftwareSerial.h>
// _______________________________
#define sendit(x) ( { \
    Serial.print(F("__________[ ")); \
    Serial.print(x); \
    Serial.println(F(" ]__________")); \
    esp8266.write(x); \
    esp8266.write(F("\r\n")); \
    esp8266.readBytes(buffer, sizeof(buffer)); \
    Serial.println(buffer); \
    delay(2000); \
  } )

// _______________________________
#define desc(x) ( { \
    Serial.println(); \
    Serial.print(F("__________[ ")); \
    Serial.print(F(x)); \
    Serial.println(F(" ]__________")); \
  } )

// _______________________________
SoftwareSerial esp8266(12, 13); // RX, TX
char buffer[50];

// _______________________________
void setup()
{
    Initialise();
}

// _______________________________
void loop()
{
}

// ____________________________________________________________________________________________________
void Initialise()
{
    SerialReadBuffer.reserve(64);
    esp8266.begin(115200);
    Serial.begin(9600);
    CommandList();
}

// ____________________________________________________________________________________________________
void CommandList()
{
  desc("Test AT Startup");
  sendit("AT");
  desc("Restart the module");
  sendit("AT+RST");
  desc("Query baud rate");
  sendit("AT+CIOBAUD?");
  desc("Query firmware version");
  sendit("AT+GMR");
  desc("WIFI mode");
  sendit("AT+CWMODE?");
  desc("Get local IP address");
  sendit("AT+CIFSR=?");
  desc("Query current multiplex mode");
  sendit("AT+CIPMUX=?");
  desc("Enable echo (Sends back received command before response)");
  sendit("ATE1");
  desc("Set Station mode");
  sendit("AT+CWMODE=3");
  desc("Lists available APs");
  sendit("AT+CWLAP");
  sendit("AT+CWLAP");
    desc("Connect to AP");
  sendit("AT+CWJAP=\"KCTcircuit2\",\"\"");
  desc("Prints the SSID of Access Point ESP8266 is connected to.");
  sendit("AT+CWJAP?");
  desc("List clients connected to ESP8266 softAP");
  sendit("AT+CWLIF");
  desc("Get IP address of ESP8266 station.");
  sendit("AT+CIPSTA?");
  desc("Get information about connection");
  sendit("AT+CIPSTATUS=?");
  desc("Get local IP address");
  sendit("AT+CIFSR=?");
  desc("Get the SSID of Access Point ESP8266 is connected to.");
  sendit("AT+CWJAP?");
  desc("Get the SSID of Access Point ESP8266 is connected to -CUR");
  sendit("AT+CWJAP_CUR?");
  desc("Configuration of softAP mode");
  sendit("AT+CWSAP?");
  desc("Configuration of softAP mode = CUR");
  sendit("AT+CWSAP_CUR?");
  desc("Disconnect from AP");
  sendit("AT+CWQAP");
  Serial.println(F("__________________"));
  Serial.println();
 }

Typical output is as follows:
"ESP8266_ATcmdtest", compiled on: Jun  5 2017 at 14:00:04
Running on: Arduino UNO: ATmega328P

__________[ Test AT Startup ]__________
__________[ AT ]__________
ATn

__________[ Restart the module ]__________
__________[ AT+RST ]__________
AT+QST$

__________[ Query baud rate ]__________
__________[ AT+CIOBAUD? ]__________
AT+CHOBAUD⸮⸮

__________[ Query firmware version ]__________
__________[ AT+GMR ]__________
AT+TJ⸮⸮AUD⸮⸮

__________[ WIFI mode ]__________
__________[ AT+CWMODE? ]__________
AT+CWLODE?G⸮

__________[ Get local IP address ]__________
__________[ AT+CIFSR=? ]__________
AT+CHFSR=?⸮

__________[ Query current multiplex mode ]__________
__________[ AT+CIPMUX=? ]__________
AT+CIPMUX=r⸮

__________[ Enable echo (Sends back received command before response) ]__________
__________[ ATE1 ]__________
ATE0=PMUX=r⸮

__________[ Set Station mode ]__________
__________[ AT+CWMODE=3 ]__________
AT+CWMODE=⸮⸮

__________[ Lists available APs ]__________
__________[ AT+CWLAP ]__________
AJ+CWL@P⸮=⸮⸮
__________[ AT+CWLAP ]__________
AT+CWLAP⸮=⸮⸮

__________[ Connect to AP ]__________
__________[ AT+CWJAP="KCTcircuit2","" ]__________
AT+CWJAH="KCTcircuiz2!,""H

__________[ Prints the SSID of Access Point ESP8266 is connected to. ]__________
__________[ AT+CWJAP? ]__________
AT+CWJAP?⸮KCTcircuiz2!,""H

__________[ List clients connected to ESP8266 softAP ]__________
__________[ AT+CWLIF ]__________
AV+CWLIFx⸮KCTcircuiz2!,""H

__________[ Get IP address of ESP8266 station. ]__________
__________[ AT+CIPSTA? ]__________
AT+CIPSTA?CTcircuiz2!,""H

__________[ Get information about connection ]__________
__________[ AT+CIPSTATUS=? ]__________
AT+CIP*UQUM⸮⸮2ircuiz2!,""H

__________[ Get local IP address ]__________
__________[ AT+CIFSR=? ]__________
AT+CIFSR=?}⸮⸮2ircuiz2!,""H

__________[ Get the SSID of Access Point ESP8266 is connected to. ]__________
__________[ AT+CWJAP? ]__________
AT+CWJAP? }⸮⸮2ircuiz2!,""H

__________[ Get the SSID of Access Point ESP8266 is connected to -CUR ]__________
__________[ AT+CWJAP_CUR? ]__________
AT+CW⸮AP5UI⸮⸮⸮ircuiz2!,""H

__________[ Configuration of softAP mode ]__________
__________[ AT+CWSAP? ]__________
AT+CWSAP?HI⸮⸮⸮ircuiz2!,""H

__________[ Configuration of softAP mode = CUR ]__________
__________[ AT+CWSAP_CUR? ]__________
AT+CWSAP5UI⸮r⸮ircuiz2!,""H

__________[ Disconnect from AP ]__________
__________[ AT+CWQAP ]__________
AZ+CWPAP⸮UI⸮r⸮ircuiz2!,""H
__________________

I also have another, simpler, sketch that accepts commands from the Serial Monitor instead.  It has equivalent behaviour in terms of responses.

Cause: software serial at 115200 baud.
Solution: configure the esp8266 for a lower baud rate or use hardware serial.
The problem is basically that the Arduino cannot run 115200 baud SoftwareSerial reliably. It is common to get corruption of incoming characters, or characters completely skipped, due in part to the SoftwareSerial implementation being unable to react fast enough to the data coming in. The time between one stop bit and the next start bit is often shorter than the amount of time taken to store the data in the receive ring buffer, so the ISR cannot respond to the new start bit in time, and data is lost.  Running at a lower baud rate gives more time for the data to be stored before the next start bit arrives, thus giving the ISR time to finish and be ready to respond to the next byte coming in.
You need to change the baud rate of the ESP8266 itself (I find 9600 is a good reliable value) using one of (depending on your firmware version):
AT+CIOBAUD=9600

or
AT+UART_DEF=9600,8,1,0,0

or
AT+IPR=9600

Last time I did it on an ESP8266 it was the first one that worked.
Then you will need to change your program to use 9600 baud instead of 115200 baud in your esp8266.begin(...).

Though not mentioned above, I have tried also 9600, 19200, 38400, 57600.  All are indecipherable, except for 9600, which yields absolutely nothing.  115200 is the only one that even approximates a proper response.

I have also used multiple ESP8266 chips, plus different Uno and Mega2560 boards.

@KCTucker: yes, the module is set too high, that's what he's saying. once you lower it, it will not only work, it will work without the glitches you're asking about.

@Majenko For clarification, I found that AT+IPR worked fine, as, apparently, would AT+UART_DEF=9600,8,1,0,0.
However, the change effected by AT+CIOBAUD was not sustaining.
A reference @ http://www.esp8266.com/viewtopic.php?f=13&t=718
indicates that AT+CIOBAUD changes the baudrate only temporarily, which matches my own experience.

Since you mentioned you tried other baud rates, I am guessing it could be an RF issue. ESP8266 is a very sensitive device and is known to have weird electrical behaviour. Do you have a cap between VCC and GND?

You could try a lower baud rate, it might work but still isn't a solution. Which board are you using? 115200 works just fine on my NodeMCU.

BTW, you do know right that you don't really need two boards. You can program the ESP in Arduino IDE itself, using Arduino code.

Of course.  This is just a simple test script.  The actual script requires 11 data pins though.


text:
Can I control a Z84 counter timer circuit with Arduino?
Link to pin description and to the Datasheet.
I'm thinking about connecting channel outputs to LEDs and control the clock with IO-Arduino or a 555: I would program it with a 595 register.
Can someone explain me why this is a bad idea?

Your datasheet link point to google.com

I wouldn't say it was a "bad" idea - pointless maybe, but not "bad". A good learning experience if nothing else.

can you confirm that the project above could work? i wouldn't like to burn or break something.

I can see no reason why it wouldn't work. As long as you generate the right signals to emulate the Z80 bus it'll be fine. Just remember the resistors on the LEDs.


text:
Reading HMC5883L hex values in 2's compliment C code
I want to develop my C code for HMC5883L.
I have 2 questions for my current code development.
My first question is:
But what I found in the datasheet is that the values are in the 2's compliment, so I don't know how to deal with them?! Do I have to take the values as they are in the data registers and convert them to decimal values and that's it? Or I have to convert them from 2's compliment to the original hex values?
This is a quote from the datasheet:

Send 0x3D 0x06 (Read all 6 bytes. If gain is changed then this data set is using previous gain)
  Convert three 16-bit 2’s compliment hex values to decimal values and assign to X, Z, Y, respectively.

My second question:
How o read the data registers? What is the procedure?
I saw in the datasheet the following method but I didn't understand it.

Loop
  Send 0x3D 0x06 (Read all 6 bytes. If gain is changed then this data set is using previous gain)
  Convert three 16-bit 2’s compliment hex values to decimal values and assign to X, Z, Y, respectively.
  Send 0x3C 0x03 (point to first data register 03)
  Wait about 67 ms (if 15 Hz rate) or monitor status register or DRDY hardware interrupt pin
  End_loop

So, I didn't understand that I send read command then I send write command, so how HMC5883L would return the value to me?
Regards,

2's complement is the normal signed values in any modern system, including Arduino.
Just place the bytes into a signed variable of the right size in the right positions and there is your value.
In I2C, to read a register, you typically have to make two transactions. The first is a write to set the register number you want to access, the you follow that with a read transaction to get the data.

Comments are not for extended discussion; this conversation has been moved to chat.

Any comments that amplify on the answer should be merged into the answer. Anyone with sufficient reputation can do that.


text:
Wiring Feather Huzzah ESP8266 to Monochrome 1.3" 128x64 LCD
I'm new to Arduino and the pinouts for the Adafruit 938 LCD doesn't seem to match the pinouts that I looked up for the Huzzah ESP8266.
Does anyone know the proper pinout for this display and the Huzzah?

At the Adafruit site it says: (for the 938) The driver chip, SSD1306 can communicate in two ways: I2C or SPI.  And (for the Huzzah) 9 x GPIO (3.3V logic), which can also be used for I2C or SPI.  I think the problem you are faced with is that the Huzzah has programmable pins that can be configured for many things.  Two of which are, evidently, I2C or SPI.  BTW, this isn't necessarily an easy 1st Arduino project.

Shouldn't it be just as easy as connecting certain wires to certain pins? I just am confused with the pinout, thats all..

You may need pull up resistors for the I2C bus.  I2C was designed so all devices are open collector drivers so the bus needs at least 1 pull up resistor on the data line and 1 on the clock line.  That said, sometimes the pull up resistors have been added by the people who designed the PCB.  For SPI I believe you don't need pull up resistors.  However the labeling can get confusing (MISO connects to MOSI & the other MOSI connects to the other MISO).  As for the pin-outs, the same pins might be used for more than 1 feature.  You need to sift through the data sheets and figure this out.


text:
Stepper Motor with Limit Switches
I have the code below which is my attempt to control a stepper motor direction that moves a carriage to the right and left. In addition there are limits at each end of the travel that when activated stops movement in the respected direction. My problem is that the motor works just fine in the left and right directions but I can only get one of the limit switches to work. I'd appreciate any suggestions.
int PUL = 7; //define Pulse pin
int DIR = 6; //define Direction pin
int ENA = 5; //define Enable Pin
int RGT = 3;
int LFT = 2;
int potPin = A5;
int count = 0;
int interval = 1000;
int val = 0;
int Spd = 500;

#define Limit01 8  // Pin 2 connected to Limit switch out
#define Limit02 9  // Pin 3 connected to Limit switch out

void setup() {
  pinMode (PUL, OUTPUT);
  pinMode (DIR, OUTPUT);
  pinMode (ENA, OUTPUT);
  Serial.begin(9600);
}

void loop() {

  if (digitalRead(LFT) == LOW) {  //  If joystick is moved Left
    if (digitalRead(Limit01) == HIGH) {} // check if limit switch is activated

    else {  //  if limit switch is not activated, move motor clockwise

      digitalWrite(DIR, LOW);
      digitalWrite(ENA, HIGH);
      digitalWrite(PUL, HIGH);
      delayMicroseconds(500);
      digitalWrite(PUL, LOW);
      delayMicroseconds(500);
    }
  }

  if (digitalRead(RGT) == LOW) { // If joystick is moved right

    if (digitalRead(Limit02) == HIGH) {} // check if limit switch is activated

    else {  //  if limit switch is not activated, move motor counter clockwise

      digitalWrite(DIR, HIGH);
      digitalWrite(ENA, HIGH);
      digitalWrite(PUL, HIGH);
      delayMicroseconds(500);
      digitalWrite(PUL, LOW);
      delayMicroseconds(500);

    }
  }
}

You did not initialize the inputs. It looks like the switch has a pull-down, so no internal pull-up, but anyway initialize them at the beginning. Then.. Are you sure the switch is working? Did you try to use a sketch to read the switches state to check if they work?

Can you supply a schematic of how the switches are wired? Have you measured the voltages on the limit switch inputs with the switch in the open and closed positions?

What I understood from your question is you want only one limit switch to control the stepper motor in both directions.So here is the code that might be helpful for you in that case:
int dirpin_T1 = 2;
int dirH_T1 = 3;
int steppin_T1 = 4;
int limit = 10; // ASSUME LIMIT-SWITCH IS PLACED AT RIGHT CORNER
void setup() {
  pinMode(limit,INPUT);

  pinMode(dirpin_T1, OUTPUT);
  pinMode(dirH_T1, OUTPUT);
  pinMode(steppin_T1, OUTPUT);

}

void loop() { //STEPPER TRAVELLING LEFT TO RIGHT

    digitalWrite(dirpin_T1, LOW );
    digitalWrite(dirH_T1, LOW);
   do
   {
      digitalWrite(steppin_T1, LOW);  // This LOW to HIGH change is what creates the
      digitalWrite(steppin_T1, HIGH); // "Rising Edge" so the easydriver knows to when to step.
      delayMicroseconds(50);

   }(digitalRead(limit)==HIGH); //AS LIMIT-SWITCH PRESSED MOTOR STOPS
  delay(500);
  //WHEN LIMIT-SWITCH IS LOW CHANGE THE DIRECTION OF MOTOR ROTATION
  if(digitalRead(limit)==LOW)
  {
      digitalWrite(dirpin_T1, LOW ); //CHANGE MOTOR DIRECTION (LOW TO HIGH)
      digitalWrite(dirH_T1, HIGH);
     for(int i=0; i<36000;i++)
      { //please try changing value of i as it depends on how much rotations you want your motor to step forward

      digitalWrite(steppin_T1, LOW);  // This LOW to HIGH change is what creates the
      digitalWrite(steppin_T1, HIGH); // "Rising Edge" so the easydriver knows to when to step.
      delayMicroseconds(50);
     }

  }
}

The simple logic would be to move the motor in one direction until limit-switch is HIGH. And to move it to the other direction when its LOW i.e already pressed.Correct me if I am wrong and try modifying the code as per this logic.However you need to change your code depending upon what type of driver you are using. Right now I am using TB6560 driver.You can use if loop instead of do while loop to make it easier to understand.

What is if(digitalRead(S01)==HIGH){} supposed to do?

its a limit switch

Well, it looks like a statement that do nothing and has no side effects.

thats a blank loop that will cause motor to stop when digitalRead(S01)==HIGH, otherwise motor will keep rotating

I have no experience with stepper motors and none at hand to play with. Out of curiosity, what happens if you comment out that piece of code?

Earlier comment was missing so that led little confusion as above. Comments are lines in the program that are used to inform yourself or others about the way the program works. They are ignored by the compiler, and not exported to the processor, so they don’t take up any space in the microcontroller’s flash memory. Comments' only purpose is to help you understand (or remember), or to inform others about how your program works.

No, I'm asking your the ìf` part. I've been programming since 1975, and I know what a comment is. I have great experience writing beautiful, nice comments. Everybody loves them. They are so beautiful people keeps saying, "please, stop writing so nicely. I can't take my eyes of yours wonderful comments."

Use
while ( condition)
{ code to execute }
making sure the code itself is "short" not to overrun the condition
If you use while construct instead of do / while you are checking the condition first before code execution.
while( not at limit switch)
move stepper one step
Also the limit switch active state should be ground, not +V. Safety issue.
If you  accidentally ground the signal it will be valid, if the signal path is grounded already , by accident, putting  +V to it won't be detected.


text:
Arduino freezing with OLED display
I have a 0.96" OLED display hooked up to my Arduino Mega via SPI. I installed the Adafruit library and GFX library. I can run through the little graphical demo from Adafruit just fine as well as display static text with no problem.
However, I am trying to put together a project I thought would be simple and straight forward. I am trying to use a DHT22 to collect temperature and humidity and then display it on the OLED. The problem I am running into is that the Arduino freezes after an indeterminate amount of time. The most it has been able to run is about 6 minutes.
Here is the code I am using:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>

#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

// If using software SPI (the default case):
#define OLED_MOSI   8
#define OLED_CLK   9
#define OLED_DC    10
#define OLED_CS    11
#define OLED_RESET 12
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

long previousMillis = 0;
long interval = 5000;

    String temperature;
    String humidity;

void setup(){
  dht.begin();

  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC);

  display.clearDisplay();

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);

  display.println(" Madgayrah");
  display.display();
  while(millis()<2000);
}

void loop() {

  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;

    float h = dht.readHumidity();
    float f = dht.readTemperature(true);

    if(isnan(h) || isnan(f)){
      int x = 6;
      String dashes = "";
      for(int y=1; y<=x; y++){
        dashes += "-";
      }
      temperature = humidity = dashes;
    }else{
      temperature = String(f)+(char)248;
      humidity = String(h)+"%";
    }

    display.clearDisplay();
    display.setTextColor(WHITE);
    display.setCursor(0,0);

    display.setTextSize(1);
    display.println(String(previousMillis/1000));
    display.println("");

    display.println("Temperature:");
    display.setTextSize(2);
    display.println(temperature);

    display.setTextSize(1);
    display.println("Humidity:");
    display.setTextSize(2);
    display.println(humidity);

    display.display();
  }
}

In my attempt at debugging I discovered that NOT printing out the temperature and humidity variables allows the program to run indefinitely. However, for some reason turning on either one of those lines and printing out that variable leads to the issue of the Arduino freezing.
ADDITIONAL INFORMATION:
I am using a 12 volt external power supply hooked up to the barrel of the Mega. The Mega is providing 5 volts and ground to a bread board which powers/grounds both the OLED and the DHT22.
Any ideas as to what could be causing the freezing issue on what "should be" a simple and straightforward project? Thanks.

How much current does the OLED pull?  It may be too much to pull through the Arduino.  It may need it's own power.

having a problem where even with watchdog the device never recovers until i unplug the LCD

Because your program uses various String objects in several different sizes, there's a good chance that heap memory (in RAM) is getting fragmented to the point that String allocation begins to fail, or begins to allocate on top of stack variables.  (Typically, heap and stack work toward each other, from opposite ends of memory that is free after static variables are allocated.)
For example, the code for(int y=1; y<=x; y++){ dashes += "-"; } with x=6 creates half a dozen String objects, all of different lengths.
To avoid this problem, you could carefully release each heap allocated object when done with it, or more effectively, could avoid using String objects, which actually aren't needed in this program.
For example, instead of display.println(String(previousMillis/1000)); say display.println(previousMillis/1000); and instead of building dashes a character at a time before using it, just say "------" in place of dashes.

I had exact same problem and james's answer helped me realize the problem is related to heap memory.
In addition to what he has already commended, I found here that you should also wrap all your constant strings in F() function.
For example instead of
display.println(" Madgayrah");

You write
display.println(F(" Madgayrah"));

This will store the string in the flash memory instead of SRAM.
Also if you only use OLED display for printing text, I strongly recommend the more lightweight SSD1306Ascii library
It output text to oled display without buffering which causes slight flickering but massively reduce the amount of memory required to drive the OLED.
Another helpful tip is to use arduino's watchdog. Basically after you enable that you need to constantly call wdt_reset(); function and if you failed to call it for certain amount of seconds, arduino will automatically reset.


text:
Seven-Segment Display doesn't work on two lights
This is my code:
void setup() {
    pinMode(2, OUTPUT);
}

void loop() {
    digitalWrite(2, HIGH);
}

This is my circuit:

Problem:

Light A and B doesn't work when I plug the red cable to 4 and 5.
All the other lights works just fine.

Did you try using a different part?

Do you mean to another 7-segment display ?
I don't have one right now but I can buy one tomorrow. I was hoping that I have any type of error. I don't have any error ?

You don't have enough code to have any fatal errors. You haven't proven that the pins are the correct ones though.

Be sure you have a current-limiting resistor in series with any LED segments that you light up, in either the ground side or the high side.  Do segments A or B light up when you apply 5 V instead of trying to drive them with an Arduino IO?

As jwpat7 states, you need a current-limiting resistor for each segment, between the data pin (on the Arduino) and the segment pin (on the display). Your Fritzing diagram only shows one resistor in the circuit, from the common cathode to GND on the Arduino.
You can not, or should not, share one resistor to ground (assuming that you have a common cathode seven segment display). You need a current-limiting resistor on each anode (again, (assuming that you have a common cathode seven segment display).
If you are sharing the current-limiting resistor between all segments, and then try to light more than more segment, at a time (which it sounds like you are doing ("when I plug the red cable to 4 and 5"), then the current through the current-limiting resistor will increase, and as a result, the voltage will change significantly enough, such that there is not sufficient voltage drop across the LED in order to make it light up.
Remember, 0.7 V is dropped across the LED.
Test each on the segments, one at a time, to make sure they all work, as Ignacio states in his comment.
Also, your sketch should be more complete, along the lines of:
void setup() {
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
}

void loop() {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
}

Connect up all of the pins, using a current-limiting resistor on each anode, and then try it programmatically.
If your seven segment display is a common anode, then, again, you need a resistor between each cathode and the data pins, and bring the pins LOW to light the corresponding segment, i.e.
    digitalWrite(8, LOW);


text:
Using SoftwareSerial along with FastLED library to control WS2812 LEDs
I am controlling WS2812 LEDs with Arduino nano using FastLED library. I want the LED patterns to change on receiving a command from another Arduino Nano over software serial, I don't have the option to use he hardware serial.
I have read that in order to write data to LEDs, the library disables all the interrupts. However the SoftwareSerial library also uses interrupts to transmit data properly. Is there any possible way to achieve this? Presently, when I am trying to do this I am getting garbage data.

How fast do you need to update the LEDs? The nice thing about WS2812s is that if you don't update them they maintain the current settings which means you only need to drive them once you have received a serial message.
The best way to do this would be to use some form of flow control over the serial port. e.g. you send a special control code over the serial line requesting the master to stop sending data. You then wait long enough for that to be sent and any data currently in transmission to arrive (so a absolute minimum of 20/(baud rate) seconds). After that time you call the function to update the LEDs. Once the LED update is done you send a second control code indicating that the other end can resume transmission.
This is the basic structure of software flow control (or XON/XOFF as it is also called) that most serial ports support as an option. You can either use the standard implementation or use something a little simpler since you only need data and flow control in one direction.
The other option is to design the system around rules that ensure you don't miss data. The system sending you the LED updates knows that once you get the update you will need to apply it to the LEDs and that during that time you can't receive serial data. So after an update it waits and doesn't send more data until you've had time to do that.

The FastLED and NeoPixel libraries turn off interrupts for the specific timing of the WS2812. The Adafruit NeoPixel has a few extra options to be able to still handle some interrupts. The FastLED has a wiki that describes the problem with interrupts: FastLED wiki interrupts
The SoftwareSerial requires interrupts. When the SoftwareSerial is busy, the Arduino is occupied.
To me it seems impossible to make both libraries work at the same time. I think you have to change something. For example use a Arduino Micro or Pro Micro and use the spare hardware serial port. Or use a ledstrip with leds that have a clock signal and don't need specific timing.
If that is not possible, you might have to use pin 0 (RX) and pin 1 (TX), which are also used by the serial monitor and to upload a sketch.
It is possible to split RX and TX. The only thing that RX and TX have in common is the baudrate, but you can use them for seperate tasks.
For example, use TX to send (debug) messages to the serial monitor, and use the RX to receive commands from another Arduino board. Disconnect that other Arduino board to upload a sketch.
[ADDED] After reading the answer by @Andrew and the FastLED wiki about interrupts, I think that my answer and @Andrew's answer are equally good answers. Perhaps the best way is to do it all: faster Arduino board, hardware serial port for commands, do one thing at a time, implement some kind of XON/XOFF in software, and if possible use other leds.

Of course the best solution is to not use arduino at all. If you use a processor that lets you run an SPI bus with 12 bit data at 2.4 MHz then the hardware can handle the timing requirements and there is no need to disable interrupts to start with. Unfortunately that's not always an option.

Another approach is to make the commands to change the pattern very short. Like, one letter/byte.
This assumes that the patterns are stored on your Arduino, and you just choose which one to show.
In order for that to work, the Arduino has to confirm commands it received, and return an error if it receives something it does not understand (e.g. only half of the command). This allows the host to check if the Arduino received the command or if it was animating at that time, in that case re-send the command.
This approach avoids the issue that you receive partial data (because the smallest transmission unit is used). Commands can still be lost, but then they can be re-sent.


text:
Windows stops recognizing Arduinos
I've just got my first Arduino Pro Mini and a USB to TTL chip. When I try to upload the program I get the message The uploader process failed followed by
avrdude: ser_open(): can't open device "\\.\COM6": Access is denied.
and a bunch of lines like

avrdude: ser_drain(): read error: The device does not recognize the command.
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: The device does not recognize the command.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x48
avrdude: ser_send(): write error: sorry no info avail

with 10 attempts after which nothing comes from avrdude and I can't upload nor get Arduino's visible in port choice menu all the time until the Windows 7 boots again. I can upload to my Arduino Uno with no problems before I try the ttl chip. TTL chip also shows up in the port menu before trying to upload, with correct name next to the port number. I installed drivers I found on a official site that sells the chip that looks just the same as mine, before I did that it wouldn't show up in the port choice menu at all. Is there any way to reset whatever it is that is preventing me from uploading to Arduinos so I don't have to restart my computer every time it happens? I managed to upload one program to the Arduino Pro and it's working fine but after a couple of hours, when I tried again, it didn't work. Maybe it would be of some use to say that I left my pc on sleep with the TTL chip plugged in and powered by the usb. My guess is that this chip is defective and was near it's life end when I uploaded so now it's just confusing the driver to the point where Windows decides to block the driver for the session.

Did you try to close arduino IDE and then reopen it? Did you try to unplug the USB-to-TTL converter and plug it again? Did you try close Arduino - unplug - plug again - open Arduino IDE?

@frarugi87 Yes, of course. I've figured out how to fix this and much more, answer coming soon ;)

i see this question a lot, so it would be helpful if you could post an answer...

@dandavis I posted it that day but for some reason it didn't appear. It should be ok now.

After a couple of hours I figured out what was happening so I will write all my analysis here for anyone having some of my problems.
First, a list of my components:
-USB TTL ship, used to upload programs to Arduino Pro. The one on the picture on instructables dot com /id/Usb-to-SerialTTL-adapter/, and used that driver.
-Arduino Pro. Chinese copy, red board just like Sparkfun's. 328p chip @ 5V = 16mhz.
-A board very similar to this one. It has a chip with FT232 written on it, also FTDI in bold letters.

The big USB TTL pcb I was using has 5 output pins: 3v3, 5v, TX, RX, GND. Turns out this is not enough to program Arduino Pro as you need one more pin. If you don't connect this pin, avrdude just gets stuck after opening the COM port and waits indefinitely/until you kill the process. To even be able to see this USB TTL chip in Windows, you need to download a driver from the website(first link) and my guess is that the driver is buggy since it won't exit the process when it encounters this type of error, further leading to suspicious/dangerous behaviour which results in Windows completely shutting down all COM ports until next restart.
To get this pin(it's called DTR/GRN), I borrowed the other chip(3rd) and I connected it regarding to this scheme:
I also had to download a different driver for it, I don't remember where I downloaded it from but it's called CDM21226 driver, when you install it it says FTDI driver installed.
Now my uploading was getting stuck no more, however after the first successful upload to my Arduino Pro the upload process would get stuck in the part where it is burning the program, if you turn verbose option in Arduino IDE on, you can see something like Writing: [#######              ].
It turns out this driver was faulty too, as I uninstalled it and when I installed it with the very same setup as before it worked seamlessly ever since. It also took me some time how to uninstall a Windows driver without using Device Manager because it wouldn't show up there - no device attached to it.
To do that open Command Prompt as admin and type pnputil.exe -e to get a list of all drivers. Among them will be one called FTDI and that's the guy, in my case he was called oem51.inf. To delete him, type pnputil.exe -d oem51.inf, or add -f before -d to force deletion - in my case it kept saying device is busy so it required this drastic measure. Change 51 to the number you have above your ftdi driver. After this just install the driver again and everything should be fine, even without reboot.
Phew...
So much work to get a simple program burned to Arduino Pro. Hope you have less trouble with it than I did.

If someone can edit the first link that would be great since I am not allowed to put more than two links in my post :/


text:
Pause in the program for some time
I have a variable timeInSec which records the time as loop begins. It is defined as timeInSec = millis();. I have two conditions. If (timeInSec - lastRun)< 5 (that is 5 sec) , the first condition is executed(the if statement).Otherwise if (timeInSec - lastRun)>5 the second condition is executed(else statement). Here is the code:
void loop(){
  timeInSec = millis();  // Records time in seconds
  // if(lastRun > 0) {   // if i run this, only else statement is executed
  // delay(10000);
  // }
  if((timeInSec - lastRun) < 5000){  // Treshold time (if condition which runs when timeInSec is less than 5 seconds)
    // Some code
  }
  else{ // If treshold time exceeds (executes when timeInSec is > 5seconds)
   delay(10000);  // if i run this, only else statement is executed
   lastRun = timeInSec;
  }
}

Here the else statement executes once and control goes back if statement again. I want to pause the control at else statement for 10 seconds and then go back to if statement for further execution. Everytime  the control should pause at else statement for 10 seconds. I have used delay in the else statement and in this case only else statement is being executed. The same happens if I use delay at the start of loop (as in code). I have tried without using delay but didn't succeed.
Thanks for the help!

Do not try to change millis(). Instead, record the last time the
second code (else statement) ran, and check whether that was more than
five seconds ago:
void loop() {
    static uint32_t lastRun;
    uint32_t now = millis();
    if (now - lastRun < 5000) {
        // Some code
    }
    else {
        // Some code
        lastRun = now;  // record the time
    }
}

This is essentially the same technique used in the Blink without
delay Arduino
tutorial.

Thanks for the reply. The code works perfect. I have a small doubt here. If I keep a delay at the start of else code say delay(2000); , only the else statement runs continuously instead of going to if statement. If I remove the delay in else, the code works perfect. Please tell me the reason. I need the compiler to stop in else statement (after execution) for 2 seconds and then go to if statement. I have used the delay in else statement but it didn't work. To achieve the same I have typed if(lastRun>0){delay(2000);} ,but it didn't work.

@SriHarsha: Do not use the comments to ask new questions. You can either write a new question or, if you believe this really belongs to the same question, edit that question.

@edgar-Thanks for the suggestion. I have edited the question.

TLDR; try else{ delay(2000); lastRun = millis(); } instead. Using the now variable after a delay, will result in using the old time.

@Gerben-Thanks for the reply. It works perfect.


text:
Recursive list of files on SD card with indexing
I'm trying to create a way to make a recursive list of the long name of files from an SD card with an index so that I call the file I'd like. Right now, I'm having trouble getting the files to list (!CFile.open() is always returning true regardless of the number of files on the card)
#include<SPI.h>
#include "SdFat.h"
#include "FreeStack.h"

// SD card chip select pin.
const uint8_t SD_CS_PIN = 10;

SdFat sd;
SdFile file;
SdFile dirFile;

// Number of files found.
uint16_t numberOfFiles = 0;

// Position of file's directory entry.
uint16_t dirIndex[300];
//**Is there a way I make an array without allocating the size here?
//------------------------------------------------------------------------------
void setup()
{
  Serial.begin(38400);
  while (!Serial) {}

  // Initialize at the highest speed supported by the board that is
  // not over 50 MHz. Try a lower speed if SPI errors occur.
  if (!sd.begin(SD_CS_PIN, SD_SCK_MHZ(50)))
  {
    sd.initErrorHalt();
  }
  if (dirFile.open("/", O_READ))
  {
  Serial.print("Reading: ");
  Serial.println();
  printDirectory(&dirFile, 0);
  }
}
void printDirectory (SdFile* CFile, int numTabs)
{
  while (file.openNext(CFile, O_READ))
  {
    if (file.isHidden()||file.)
    {
      //file hidden, skip
    }
    else
    {
      for (uint8_t i = 0; i < numTabs; i++)
      {
        Serial.print('\t');
      }
      if (file.isSubDir())
      {
        file.printName(&Serial);
        Serial.println();
        printDirectory(&file, numTabs++);
      }
      else
      {
        // Save dirIndex of file in directory.
        dirIndex[numberOfFiles] = file.dirIndex();
        // Print the file number and name.
        Serial.print(numberOfFiles++);
        Serial.write(' ');
        file.printName(&Serial);
        Serial.println();
      }
    }
  file.close();
  }

If someone could help me catch what I've got wrong, I'd like to get a second opinion.
Edit: Updated Code
Edit 2: I'm now getting the first level, but the second level is not printing I think I may be doing something wrong with pointers?

dirFile.open("/", ...) opens the root directory which always exist, even if there are no files.
You can check if there are files by checking openNext. If the first call returns false, there are no files or folders.
Some unrelated remarks:

Name variables you use, with more than 1 character (so e.g. numberOfFiles instead of n)
Do not increase a variable inside a Serial.print statement .. if you remove the 'test/debug' code, your sketch behaves differently.

Update:
I now see your question about the array. 300 is probably what you assume is the maximum number of files. Note that if 300 is passed, the sketch will crash.
What you can do to prevent this:

Easy solution: stop storing files after 300. In this case, make 300 a constant.
Solid solution: do not use a predetermined length array. However, this means some disadvantages:

You have to create a list structure and dynamically change the code.
This is slower (probably not an issue since SD card communication is much slower)
It can result in memory gaps, resulting in hard to solve memory problems later if the code is extended and more memory is needed.

I suggest you add some code, to stop storing at 300.

Ok, changing if (!CFile.open("/", O_READ)) to if (!CFile.openNext(&dirFile, O_READ)) has no effect. There seems to be something wrong with the printDirectory function

Hey, I think I updated the code to reflect what you were saying. Can you let me know if you see something else I'm missing?

It's a bit hard to easily see if it's complete ... the best way is to create several empty/non empty sub directories and iterate through them (e.g. running the sketch) and check against the output on Serial.

At least the comment "// THIS is returing true regardless of if there are files on the card should be removed now :-)

Ok, I've updated the code to something that is working better. I think there's still something that needs to be fixed though. XD

@ATE-ENGE if you think there should be fixed something, it's better first to find out what exactly is the problem (of there is no problem found, there is nothing to be fixed).

I saw your additional questions about arrays and updated my answer accordingly


text:
Problems with I2C connection on ESP8266 - 12F, which pins should I use?
Previously I had pined the temp/hum sensor HDC1080 with an Arduino using this sketch and everything worked fine. Now I want to run it over an ESP-12F, I uploaded it but it has issues at the time of establishing I2C connection. Basically, I'm not sure if at the end of setup() the I2C connection has actually begun, because I get this at the serial monitor:

As far as I see, the code skips everything related to Wire library. I blame it on the SDA/SCL pins, but actually none of the pins are working for me. I found that default I2C GPIO's are 2 and 14, I tried with them and got no result; later I tried with 12/16, as the commented Wire.begin line says, but it was the same. I even read some possible solutions in this post but I not even have the mentioned libraries.
Could you give me any suggestion, please? This is the sketch I'm using:
#include <Wire.h>

#define HDC 0x40 //B1000000 MSB
#define cociente 65536 //2^16

uint16_t humrawvalue;  //Raw data value, MS byte = valmsb, LS byte = vallsb
uint16_t temrawvalue;  //Raw data value, MS byte = valmsb, LS byte = vallsb
uint8_t humvalmsb, humvallsb;  //Raw 8-bit byte of humidity
uint8_t temvalmsb, temvallsb;  //Raw 8-bit byte of temperature
int incomingByte = 0; //Action input
float humidity, temperature;

void setup() {
  delay(100);
  Serial.begin(9600);
  delay(100);
  Serial.println("Hello");
  //Wire.begin(12,16);
  Wire.begin();
  Wire.setClockStretchLimit(1500);
}

void loop() {
  if (Serial.available() > 0) {    //User presses 1 to start sensor reading
    // read the incoming byte:
    incomingByte = Serial.read();
    yield();
    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
  }

  Serial.println("---g-");  //Just guideline

  if (incomingByte == 49){
    Serial.println("IIIII");  //Just guideline
    Wire.beginTransmission(HDC);
    Wire.write(0x00);
    Wire.endTransmission(true);
    delay(200);

    Wire.requestFrom(HDC,4,true); //It asks for 4 bytes, 2 bytes per register
    if(Wire.available()){
      Serial.println("     ");
      Serial.println("Measuring: ");
      temvalmsb = Wire.read();
      temvallsb = Wire.read();
      humvalmsb = Wire.read();
      humvallsb = Wire.read();

      Serial.println("====TEMPERATURE====");
      Serial.print("MSB: "); Serial.println(temvalmsb, BIN);
      Serial.print("LSB: "); Serial.println(temvallsb, BIN);
      temrawvalue = temvalmsb <<8| temvallsb; //Locates each byte in its proper place
      Serial.print("Temp: "); Serial.println(temrawvalue, BIN);
      temperature = ((float)temrawvalue/(float)cociente)*165.0-40.0;
      Serial.print("Temperatura [C]: "); Serial.println(temperature);

      Serial.println("====HUMIDITY====");
      Serial.print("MSB: "); Serial.println(humvalmsb, BIN);
      Serial.print("LSB: "); Serial.println(humvallsb, BIN);
      humrawvalue = humvalmsb <<8| humvallsb;
      Serial.print("Hum: "); Serial.println(humrawvalue, BIN);
      humidity = ((float)humrawvalue/(float)cociente)*100.0;
      Serial.print("Humidity [%]: "); Serial.println(humidity);

      Serial.println("     ");
      delay(3000);
    }
  }
  Serial.println("++++"); //Just guideline
  delay(3000);
}

Regards!

2 and 14? i thought 4+5 were the hardware i2c pins... if you don't specify, that what's used

@dandavis that's the main problem, each datasheet shows different information about I2C. I just tried with 4,5 and testing the signal on an scope but there's no difference,  I just get  a DC signal

Is the device a 5V device?

Update: it never worked. ESP-12F was still very unstable, what made it impossible to connect this specific sensor. With serial protocol for other devices the micro did it fine, but struggled when using I2C

Unlike most Arduinos, the ESP8266 doesn't have a hardware TWI, so I²C is bit-banged in software. This means that you can use any GPIO pins. By default, Wire.begin() initializes pins 4 (SDA) and 5 (SCL), but you can specify other pins using Wire.begin(int sda, int scl).
Documentation
(Note: the datasheet specifies GPIO2 as SDA and GPIO14 as SCL, but that doesn't matter, AFAIK, it's just a convention.)

Wire doesn't work on ESP8266. See github issue: https://github.com/esp8266/Arduino/issues/3046

Are you referring the I2C pins on the Arduino? You could just skip the Arduino and wire it direct to the ESP8266 and in your code define which pins you are using for I2C or amend the library accordingly. If you go down this route, make sure you use the correct I2C scanner for the ESP8266. Which can be found on this Instructable, otherwise your I2C won't be detected.
http://www.instructables.com/id/ESP8266-I2C-PORT-and-Address-Scanner/
If you do stick with the Arduino, make sure the library is using the right address, again checking using the Arduino I2C scanner sketch to find which I2C address it is using.
https://playground.arduino.cc/Main/I2cScanner