text:
Spikes in CO2 and TVOC measurements with CJMCU-811 sensor
Firstly, I'm not sure if this is the right SE to ask this question. Please feel free to direct me somewhere else if needed.
I am observing large spikes in CO2 and TVOC measurements using the CJMCU-811 sensor. When plotted it looks like this:

Nothing particular is happening around the sensor at those moments of spikes, I'm not breathing on the sensor etc.
I use Arduino Uno with the following code:
/******************************************************************************
  Read CO2 and TVOCs from CJMCU-811 sensor

  Arduino connection:
  3.3V to 3.3V
  ACC to 3.3V
  GND to GND
  WAK to GND
  SDA to A4
  SCL to A5

******************************************************************************/
#include <Wire.h>

#include "SparkFunCCS811.h"
#define CCS811_ADDR 0x5B

CCS811 mySensor(CCS811_ADDR);

void setup()
{
  Serial.begin(9600);
  Serial.println("CCS811 Basic Example");

  Wire.begin();

  CCS811Core::status returnCode = mySensor.begin();
  if (returnCode != CCS811Core::SENSOR_SUCCESS)
  {
    Serial.println(".begin() returned with an error.");
    while (1);
  }
}

void loop()
{

  if (mySensor.dataAvailable())
  {

    mySensor.readAlgorithmResults();

    delay(1);

    Serial.print("CO2 ");
    Serial.print(mySensor.getCO2());

    Serial.print(", tVOC ");
    Serial.print(mySensor.getTVOC());

    Serial.println();
  }

  delay(2000);
}

Of course I can filter and not worry about them, but I'm nevertheless curious what is causing it. Any suggestions what could be the reason for that?

Two suggestions ... do you have a second sensor? If you run two sensors close to each other and the spikes coincide, then something IS happening around the sensor. Or ...  seal the sensor inside a container ... do the spikes still happen?

@Jaromanda X, good point, I have two of them so that will be easy to see.

If the "spikes" are due to some "internal" error, as per the answer, you could always take 5 or so readings in as short a time as the sensor will allow, remove any outliers then average the rest - the code for doing that isn't too difficult

I have two of those sensors in a long term setup and I know those spikes very well. I once put lots of effort in debugging and I personally gave up on the ccs811 and use a different sensor now.
Back then I have already tried what Jaromanda suggests in his comment.
Both of my sensos showed the same behaviour while the spikes on both sensors did not correlate in any form.
Also, if I remember it right, those erronous readings appeared to be at dedicated values.
I tried several pullups, which also didn't make any difference and on the oscilloscope everything looked fine.
Printing the output of the I2C related functions revealed that communication was always stable. If it was I2C related I would expect those erronous readings to be completely random anyway (which they aren't from my experience).
My final (vague) theory was that maybe there exist race conditions between the computation and the I2C interface or maybe the adc and the approximation algorithm (that's all "inside" of the sensor). I once produced such a bug myself which resulted in a similar behaviour.
At least I'm pretty sure that there is nothing you can do in your sketch to fix this problem, because for the mentioned reasons it is very unlikely related to communication problems. You might want to work-around it or look for an updated firmware.
Or (my prefered solution) choose a sensor which does a true CO2 measurement (the ccs811 only returns a pseudo, calculated CO2-equivalent approximation).
Those higher-class sensors use NDIR technique and are only a bit more expensive (still under 50$) but you'll probably have much more reliable readings, less problems and a wider measurement range (up to 0-40000ppm vs 400-8192ppm).
Ps: did you follow the guidelines concerning the "burn-in time"? Because honestly, that was a mistake I did: I simply plugged it in of curiosity to test communication and read about this step afterwards. But I don't believe it has something to do with this problem, because there are physical reasons why one should do so, but those artifacts seem to be of digital nature.

Which CO2 sensor did you end up going with?

@DaveW.Smith I personally like the SCD30 by sensirion, but there are other NDIR-CO2 sensors (this is not meant to be a product recommendstion).

There is a CCS811 library which supports querying the internal firmware version of the sensor, and flashing a new firmware (latest is 2.0.1). Older firmware versions used to have burn-in compensation which apparently caused more harm than good (instead, new firmware requires sensors to be burned-in during 48 hours), and also relied on an external sensor for temperature compensation, which is simply missing on most cheap breakout boards. Ironically many cheap boards come with CCS811 flashed with an older firmware, which periodically samples the voltage on a floating pin and uses that value to correct CO2/TVOC calculations.
Unless your board features a thermistor, consider upgrading the sensor firmware to 2.0.1. Even or boards with a thermistor (e.g. original Adafruit), new firmware might give better results.

I saw similar behavior from 3 CJMCU-811 sensors that I bought (in one order, so probably the same manufacturing lot) in mid 2019. Two gave readings with steady, spikey, but uncorrelated upward growth. The third periodically spiked into the 2000-3000 ppm zone and then popped back to ~450 ppm (in an empty room with decent airflow). A logic analyzer on the I2C lines didn't show issues (or I missed them).
I went as far as adding a line to reset the sensors every few minutes. Replacing the sensors with what I assume was a different manufacturing lot resolved the issue.
I'm using the AdaFruit ccs811 library on ESP8266s (Wemos D1 minis).
Months later: The replacements have gone haywire, occasionally giving readings in the 3000ppm range until reset, at which point they're back to the 400-600ppm range for a while until drifting higher. I recommend avoiding the ccs811.

Values dropping after a reset is something you should expect. The datasheet says "After writing to MEAS_MODE to configure the sensor in mode 1-4, run CCS811 for 20 minutes, before accurate readings are generated", so whatever you read right after a reset is garbage.

I expect the drop, but not from 3000 to 400, then drifting slowly to 800, then spiking back to 3000 and hanging out there until reset. This n a room with a window open, and the sensor placed so that it gets breeze.


text:
The use of 4.7kOhm resistor with DS18B20 temperature sensor
I was using a temperature sensor DS18B20 with Arduino.
I've read that you should connect the digital input line and the 5V line with a 4.7kOhm resistor - like in the picture.
Can someone explain why do we need to do this? And why this resistance? What happens if we don't put a resistor at all or use a different resistance?

Datasheet says?

Here is an interesting blog on the subject https://wp.josh.com/2014/06/23/no-external-pull-up-needed-for-ds18b20-temp-sensor/

The product page FAQ [https://www.maximintegrated.com/en/support/faqs/ds18b20-faq.html] has an entry:
Q: Is the 4.7kΩ resistor needed for 5V and 3.3V operation?
A: Yes, the 4.7kΩ pullup resistor is required for both 5V and 3.3V applications.

The 1-wire bus requires that the control signal be pulled high so the master device can pull it low to ask for data, and the slave device can pull it low to give the data. This allows you to have multiple 1-wire devices on the same "one wire".
The data sheet notes another purpose:
Another feature of the DS18B20 is the ability to operate
without an external power supply. Power is instead
supplied through the 1-Wire pullup resistor through the
DQ pin when the bus is high. The high bus signal also
charges an internal capacitor (CPP), which then supplies
power to the device when the bus is low. This method of
deriving power from the 1-Wire bus is referred to as “parasite
power.” As an alternative, the DS18B20 may also be
powered by an external supply on VDD.

Note that while a resistor is required, it need not be 4.7kohm.  The internal resistors on the arduino are enough to drive 4 sensors at 2-3 feet of wire, not in parasitic mode.  The 4.7k resistor lets you drive systems with much higher capacitance (dozens of sensors at multiple meters).  For playing around or a single sensor, there really is no need.

Here you can find a more in-depth look at this question and why the internal pull-up can very well work. https://wp.josh.com/2014/06/23/no-external-pull-up-needed-for-ds18b20-temp-sensor/

Adding to jose's answer above to answer your other two questions
And why this resistance?
 When the device doesnt have its own power supply it uses the power going through the pull up resistor-thus with this resistance it is powered properly. Also the other reason- as Jose wrote is because it the value which differentiates high or low bits.
What happens if we don't put a resistor at all or use a different resistance?
If you are going to you an out of spec value-dont expect the device to work properly because its using the wrong resistance-e.g. it may not work because if the resistance is too high-then according to ohms law it may not receive enough parasitic power. Though it should be able to tolerate the error tolerance of the resistor-so changing it by a few ohms either way from 4700 ohms will not make a difference. You may damage the device without a resistor.

Thanks! What I still don't understand, is that we do supply the power to the temperature sensor by the 5V line directly (one of the legs of the sensor is conntected to the Arduino's 5V). So, does that mean that the power supply goes from 5V, through the resistor to the digital input line (the middle leg)?

How do you think the sensor works when its powered from the arduino?

Im trying to understand what you are thinking thats why I asked that.

In your particular use-case, you aren't using the parasitic-power feature. The 4.7k ohm resistor is a "pull-up" resistor for the bus's data line. Why 4.7k? At 5V, the most current that can flow through the resistor is about 1mA. That's weak enough that all any other device on the bus needs to do to bring the line down to (near) 0V is sink more than 1mA of current. But when that device let's go (stops sinking current) the line always rises back to 5V.

source: Stack Exchange

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

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

sort: votes


text:
Cannot compile F() macro with R"string"
I am trying to compile the following code:
logger.log_info(F(R"(some text here that may take
    multiple lines
    and here it is done.)"));

But the compiler exists with the following error:

error: unterminated raw string

I am able to use either R or F, but not both together. How should I be able to use them together?

Have you tried terminating the string manually, by adding \0 to the end? Maybe that helps, as the error message complains about the string not being terminated

@chrisl because I am using R, how should \0 be evaluated as string termination?

@chrisl, I tried it, but I am not able to compile because the whole remaining file is now evaluated as part of the string. So this did not work.

There were some bugs with raw string literals and the preprocessor in GCC a while back. What version are you using?

@Mat, Arduino libraries 2.7.4; GCC: 7.3.0

If you put:
    #define DO_NOTHING(s) (s)

    DO_NOTHING(R"xyz(Hello
    World)xyz")

you can see g++ choke on preprocessing the raw string literal in the macro invocation with the latest esp8266 board package as of writing (version 2.7.4).  This comes with g++ 4.8.2 for xtensa.
    ~/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/xtensa-lx106-elf-g++ -E  donothing.h

You may need to adjust the command-line for your system.  donothing.h is just the macro and invocation described above.
Result:
# 1 "donothing.h"
# 1 "<command-line>"
# 1 "donothing.h"

donothing.h:3:13: warning: missing terminating " character [enabled by default]
 DO_NOTHING(R"xyz(Hello
             ^
(R"xyz(Hello World)
donothing.h:4:10: warning: missing terminating " character [enabled by default]
 World)xyz")
          ^
      xyz")

This does not happen with g++ 9.3.0 on an amd64 Linux target.
As a workaround you can reconstruct (more or less) what the F() macro does with the following:
    void setup() {
      Serial.begin(9600);
    }

    void loop() {
      static const char pgm_str[] PROGMEM = (R"xyz(Hello
    World)xyz");

      Serial.println(FPSTR(pgm_str));
      delay(4000);
    }

May I ask you why would you write something outside of the parenthesis of the literal? (namely xyz in your example)? If this is not gonna be shown anyway

Do you have any suggestion to convert the output of the FPSTR(pgm_str) to std::string? because the is the type of the argument I am using. This is the error I get now: no known conversion for argument 1 from 'const __FlashStringHelper*' to 'const string& {aka const std::basic_string<char>&}

std::string works by allocating from dynamic memory, except maybe for small strings, so in order to wind up with one you'd need to copy into it.  In other words, at some point you'll have a second copy in RAM.  What are you ultimately doing with the string?  BTW: the arduino String class usually accepts const __FlashStringHelper *, but this inn't what your ultimately want and it would be a little nuts to load it into one and then the other.

You are right, thanks for that point. That means, using const char * instead of String or std::string should be fine in this case, as no copying will happen and I will be fine to use this string for logging. Right?

I'm not sure I understand.  Where does logger.log_info come from?  Is this a published library you can point me to?  I ask, because if it was made with the Arduino in mind, it is likely that there is some support in it already for reading strings out of "PROGMEM".

No, actually it is not, it is written somewhen by myself, logging data are simply some strings that will be built in runtime. For example: logger.log_info("Current time " + time);. And the argument its takes is std::string, I can simply change it of course to const char *. However, now after changing the argument type, the compiler still complaining about the type: error: no matching function for call to 'Logger::log_info(const __FlashStringHelper*) const'.
Could you keep trying helping me please to solve this? I will accept anyway the answer cuz the main question has been solved!

Heh, unfortunately this is a horrible medium to try to hold a conversation on.  There's probably some policy against suggesting this, but you can find me on irc.freenode.net in #arduino      I can try to edit the answer to include a routine to load std::string from __FlashStringHelper if you like.  Or, I suppose it could just go into a comment, since it's not part of the actual answer to the question.

Let us continue this discussion in chat.

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


text:
ATtiny84A support with "Attiny" board manager installed to Arduino IDE
Referring to page http://highlowtech.org/?p=1695, is it possible to program ATtiny84A as well, or just the chip version ATtiny84 (without "A")? Does anybody know?

6 years old question but anyway, tt works I can confirm, I have been using ATTiny84A-U, SOIC-14 chip.

According to the PDF ATTiny24/44/84 to ATTiny24A/44A/84A Migration AppNote it should be pretty easy as there are only some differences in electrical specifications. No changes in registers or so.
The signature bytes are the same too, so it should be posible even without adding another boards.

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


text:
Sim900 error on AT command AT+HTTPINIT
I want to send data to my php server using sim900 module but I am unable to initialize http service on sim900.
code:
#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(8, 9);

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

  Serial.println("Con");
  delay(2000);
  Serial.println("Done!...");
  gprsSerial.flush();
  Serial.flush();

  // See if the SIM900 is ready
  gprsSerial.println("AT");
  delay(1000);
  toSerial();

  // SIM card inserted and unlocked?
  gprsSerial.println("AT+CPIN?");
  delay(1000);
  toSerial();

  // Is the SIM card registered?
  gprsSerial.println("AT+CREG?");
  delay(1000);
  toSerial();

  // Is GPRS attached?
  gprsSerial.println("AT+CGATT?");
  delay(1000);
  toSerial();

  // Check signal strength
  gprsSerial.println("AT+CSQ ");
  delay(1000);
  toSerial();

  // Set connection type to GPRS
  gprsSerial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  delay(2000);
  toSerial();

  // Set the APN
  gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"web\"");
  delay(2000);
  toSerial();

  // Enable GPRS
  gprsSerial.println("AT+SAPBR=1,1");
  delay(10000);
  toSerial();

  // Check to see if connection is correct and get your IP address
  gprsSerial.println("AT+SAPBR=2,1");
  delay(2000);
  toSerial();

}

void loop()
{
   // initialize http service
   gprsSerial.println("AT+HTTPINIT");
   delay(2000);
   toSerial();

   // set http param value
   // ToDO : send dynamic value
   gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://www.fohoraayo.000webhostapp.com/?lat=1111&lon=1111\"");
   delay(4000);
   toSerial();

   // set http action type 0 = GET, 1 = POST, 2 = HEAD
   gprsSerial.println("AT+HTTPACTION=0");
   delay(6000);
   toSerial();

   // read server response
   gprsSerial.println("AT+HTTPREAD");
   delay(1000);
   toSerial();

   //gprsSerial.println("");
   gprsSerial.println("AT+HTTPTERM");
   toSerial();
   delay(300);

   gprsSerial.println("");
   delay(10000);
}

void toSerial()
{
  while(gprsSerial.available()!=0)
  {
    Serial.write(gprsSerial.read());
  }
}

output:
Config SIM900...
Done!...
AT

OK
AT+CPIN?

+CPIN: READY

OK
AT+CREG?

+CREG: 0,1

OK
AT+CGATT?

+CGATT: 1

OK
AT+CSQ

+CSQ: 31,0

OK
AT+SAPBR=3,1,"Contype","GPRS"

OK
AT+SAPBR=3,1,"APN","web"

OK
AT+SAPBR=1,1

ERROR
AT+SAPBR=2,1

+SAPBR: 1,1,"xx.xxx.x.x"

OK
AT+HTTPINIT

ERROR
AT+HTTPPARA="URL","http://www.fohoraayo.000webhostapp.com/?lat=AT+HTTPACTION=0

ERROR
AT+HTTPREAD

ERROR
AT+HTTPTERM

ERROR

Finally I got it! My sim900 module doesnot supports HTTP.

You can try to use the TCP/IP commands to make a connection and just send a HTTP string along.

For me, your code is working like charm. but change the
gprsSerial.begin(9600)

to
gprsSerial.begin(4800)


text:
Atmega32u4 external 8MHz clock
Does anyone know how to configure the Atmega32u4 to run using an external 8MHz oscillator ?
I needs to still be responsive to the Arduino IDE
Thanks

The ATmega32U4 is configured by default to work with an external 8MHz crystal.

@IgnacioVazquez-Abrams, per Table 28-5 in Atmel-7766-8-bit-AVR-ATmega16U4-32U4_Datasheet.pdf, the -RC models of 32U4 are configured for RC operation :)  See note 1,  “1. The default setting of CKSEL3..0 results in Low Power Crystal Oscillator for ATmega16U4 and ATmega32U4, and Internal RC oscillator for ATmega16U4RC and ATmega32U4RC.”

See §28.2 in Atmel-7766-8-bit-AVR-ATmega16U4-32U4_Datasheet.pdf, which explains usage of various fuse bits.
Also see engbedded.com/fusecalc, which lets you easily figure out fuse settings.  Fusecalc also tells you the strings to use as part of avrdude command strings.
Once you know the fuse settings, send them to your device via a command like
avrdude -p m32u4 -c usbasp -u -U lfuse:w:0xEF:m -U hfuse:w:0xD5:m -U efuse:w:0x07:m

or like
avrdude -p m32u4 -P $port -c arduino -u -U lfuse:w:0xEF:m -U hfuse:w:0xD5:m -U efuse:w:0x07:m

where $port represents a port name like /dev/ttyUSB0.
Note, it makes sense to read the fuses first, and put the readings into Fusecalc to see what they correspond to.  You can read the fuses via a command like
avrdude -p m32u4 -P $port -c arduino -U hfuse:r:-:i

Hi Thanks I see your point and i thought I had to change the fuse settings too, for external 8MHz clock operation with the at328p..... but you don't. The fuse settings are the same.

Why do I know this... well I read the data sheet and the settings for the atmega328 are the same for both Uno (atmega328p, 5v, 16MHz) and pro(atmega328, 3.3v  8MHz). see the boards.txt file inside arduino application. The only difference is the High fuse which is nothing todo with clock speed

Sorry I was answering something else :/ hahaha I think you have both given me the answer I needed........ I just need to change to CKDIV8

I've been head banging all day on this. I only have at328p's to test on still waiting on my 32u4's to be delivered.

@DannyJ, re your second comment,  “settings for the atmega328 are the same for both Uno (atmega328p, 5v, 16MHz) and pro(atmega328, 3.3v 8MHz)”, right.  The same sort of thing will apply on the 32U4, with the same settings at 8 to 16 MHz Low Power Crystal, and other settings for lower frequencies, as shown in  Table 6-3 of  Atmel-7766-8-bit-AVR-ATmega16U4-32U4_Datasheet.pdf.   Note, if by “responsive to the Arduino IDE” you mean that millis() reports correctly, that is controlled by correctly setting the  .build.f_cpu parameter in the appropriate boards.txt section.


text:
Arduino Uno Reading Fuses
I am trying to read the fuse values for the Arduino Uno, but keep getting the following results returned back to me:
enter code hereavrdude: Version 6.0.1, compiled on Dec 16 2013 at 17:26:24
     Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
     Copyright (c) 2007-2009 Joerg Wunsch

     System wide configuration file is "/usr/local/CrossPack-AVR-20131216/etc/avrdude.conf"
     User configuration file is "/Users/hd334/.avrduderc"
     User configuration file does not exist or is not a regular file, skipping

     Using Port                    : /dev/cu.usbmodem1421
     Using Programmer              : arduino
     Overriding Baud Rate          : 115200
     AVR Part                      : ATmega328P
     Chip Erase delay              : 9000 us
     PAGEL                         : PD7
     BS2                           : PC2
     RESET disposition             : dedicated
     RETRY pulse                   : SCK
     serial program mode           : yes
     parallel program mode         : yes
     Timeout                       : 200
     StabDelay                     : 100
     CmdexeDelay                   : 25
     SyncLoops                     : 32
     ByteDelay                     : 0
     PollIndex                     : 3
     PollValue                     : 0x53
     Memory Detail                 :

                              Block Poll               Page                       Polled
       Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
       ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
       eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
       flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
       lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
       signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

     Programmer Type : Arduino
     Description     : Arduino
     Hardware Version: 3
     Firmware Version: 4.4
     Vtarget         : 0.3 V
     Varef           : 0.3 V
     Oscillator      : 28.800 kHz
     SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK (H:00, E:00, L:00)

avrdude done.  Thank you.

I have tried using avrisp as the programmer too, but this reports an invalid device signature. If I override the device signature check with -F I get the same results as above.
I am using an Uno as the ISP to another uno and have connected the two together as detailed in
https://www.arduino.cc/en/Tutorial/ArduinoISP
I have boot loaded the Arduino Atmega328P boot loader and from the fuse settings given in the boards.txt file expect to see:
lfuse reads 0xff
hfuse reads 0xde
efuse reads 0x05
Another question is with the low fuse set to 0xff the CKDIV8 is programmed so won't the clock be set to 2MHz?
Please help

CKDIV should be 0 to enable the divide by 8. Since it's set to 1 the clock frequency will be 16MHz (when using a 16MHz crystal, that is).

Did you do step 5 (Note for the Arduino Uno: you'll need to add a 10 uF capacitor between reset and ground.)?

I connected a 10uF cap between rst on the board to be programmed and the GND on the ISP board

RE CLKDIV8 thanks for clearing that up

Concerning your questions about clock division settings: have a look at this pretty tool, it gives you a avrdude query for setting fuses (take care!). The CKDIV8 bit of the low fuse is set by default, so an AT328p will run at 1MHz, clearing this bit will result in 8 MHz.
When flashing you should never override any checks as this may damage/lock your chip.
I see that avrdudes states the supply voltage to be 0.3 volts which is far to low for communication. Any received bits would be low level and therefore any information read will be 0. ISPs usually provide a supply voltage which often can be selected by switches on the programmer. If you are sure your programmer is allright, check your circuit in general.
Btw, which ISP-model do you use?
Is your mcu assembled on a custom pcb (setup?)? If yes, do you have an arduino(like) board to verify this behaviour?

I'm using a stk500 (USB <> ISP programmer) to read atmega328p fuses. I use this cmd:
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude.exe -CC:"\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega328p -cstk500 -PCOM9 -e -Ulfuse:r:-:i -Uhfuse:r:-:i -Uefuse:r:-:i

Sometime ago I had some issues with device signatures because I missed the "p" in atmega328p definition.
As a tip, you can check the Arduino verbose to help you with more information:
FILE >> PREFERENCES
SHOW VERBOSE OUTPUT DURING: [x] COMPILATION [x] UPLOAD


text:
Capacitors in DC circuits
I have a question about capacitors in DC (digital) circuits. The picture below is an edited schematic of the Arduino Uno R3.
The DTR line is connected to the reset input of the Atmega328 by a 0.1uF capacitor.

The capacitor is needed to initiate a load to the atmega flash memory through the USB -> UART. Why is this the case, everything I have been taught says "Capacitors block DC and let AC through"
All I see is something that can let AC noise through to the Arduino reset? I know its needed, I tested it. But why its needed, how it fulfils that function I have no idea.
Please help

Possible duplicate of What is the cap for in Arduino reset circuit?

@jonk -- fair points, I'll retract the flag but leave the URL just in case.

The capacitor C5 and resistor RN1 are used to TEMPORARILY apply RESET to the microcontroller chip during power-up.  It assumes that C5 is discharged and will conduct the "AC" (change from 0V up to 5V) until it becomes fully charged and releases the reset line so that the microcontroller can start up properly.
You can use this online calculator to see the time-constant for any given resistor and capacitor:  http://www.referencedesigner.com/rfcal/cal_05.php
When the circuit is first powered up, C5 holds the microcontroller -RESET line LOW (the active state) until C5 charges up through RN1.  At that point RN1 holds the -RESET line HIGH which releases the microcontroller to start up in an orderly manner.
It is not clear exactly what is happening between the U3 DTR pin and the junction of C5/RN2.  There is a label that says "LED3 Yellow", but there is no symbol for a LED or any other component there.  But there is typically a way for an external device to apply a reset also, so that you can re-program the microcontroller, and that is likely what is happening there.

I believe D2 is provided to protect the reset input of the microcontroller from any possible reverse-polarity voltage.

Probably, but that stray(?) label confuses things.


text:
Atmega boot loading UART or SPI
I have an Atmega 328 chip and want to load the Arduino boot loader to the chip. I have planned to use a SPI protocol to do this, but I have read other posts saying that they have done similar using an UART with using an FTDI chip. I have planned to use the FTDI to support USB.
I did rad some information that said that loading the boot loader through UART is very slow.
Which is best? I would like to save space, if I do not need a SPI header then I would like to remove this. Is what I have read correct?
Thanks

Loading via UART is not so bad if you configure the bootloader to use a reasonable baud rate (say, 115200 instead of the default 9600). However, you do have to get the bootloader onto the chip in the first place, and that has to be done with SPI.

But if you do have SPI then you don't need the bootloader, not even for Arduino code.

True, but the bootloader could theoretically be loaded before soldering the chip or via pogo pins on test points, alleviating the need for a bulky ISP header while enabling simple firmware updates via UART.


text:
How do I redefine the overlfow of compare interrupts in Arduino programming?
If I'm programming a pin change interrupt I can call attachInterrupt at various points in my code and change what function is called when the interrupt occurs.
The overflow and compareA/B interrupt calls are defined by the ISR macro which is evaluated at compile time, which therefore can't be changed at run time. One solution would be to make that function consist of a single line, which invokes a function pointer. If I'm reading the code correctly, this is how attachInterrupt is implemented. Short of mucking with the interrupt vector table (which seems like a bad idea, or at least very hard to debug if you screw it up), is there another way to redefine the overflow or compare interrupt functions?

For a arduino uno with a microcontroller of the avr family? They have the vector table in code (in flash), you can not change that runtime. You could make each vector of the vector table point to ram which you could change runtime, but that would be the same as having a ISR that invokes a function pointer. That is not a bad idea, as long as it is clear and well defined, it is a normal way to change the function of an interrupt. For the pin-change-interrupt I suggest the EnableInterrupt: https://github.com/GreyGnome/EnableInterrupt

call attachInterrupt at various points in my code ..... you could set a global variable at various points in your code ...... the ISR would execute a function dependent on value of the global variable

What about using a switch statement inside the ISR function and reroute the flow depending on the value of the global variable used in the switch?
uint8_t status = 0;

void myInterruptFn() {
  switch(status) {
    case 0:
      // do something
      status = 1;
      break;
    case 1:
       // do something else
       status = 0;
       break;
   }
}


text:
Software serial conflict with WiFi on ESP8266
I'm trying to use an ESP8266 (Wemos D1 mini) to read from a 19.2K serial port and report the results over WiFi. Programming is via Arduino IDE. The code to read the port works just fine if WiFi is not enabled. Once WiFi is enabled I lose chars from the input stream. I've seen several posts in various places that point to problems with using SoftwareSerial and WiFi at the same time, apparently having to do with timing conflicts. My latest attempt calls
WiFi.disconnect();

before the code that reads the chars from the serial stream, then calls
WiFi.reconnect();

after reading the serial stream but before making the calls to send data over the web. This did not work.
My code is reading from the serial port in a (blocking) loop, which other posts suggest is the problem. This is not a problem when there is no WiFi object connection. I could restructure the code to create a non-blocking read, but that would be a significant effort (and make the code much harder to understand), so before I go that route I'm wondering if there is a different solution.

Why not use the hardware UART?

If I understand correctly, UART0 is connected to the USB interface, which I'm using for flashing and debug messages. UART1 is send-only, and I'm trying to read data.

try the beta version (2.5) of the arduino esp8266 core. it has improvements in SoftwareSerial

As noted, there are conflicts between Wifi and SoftwareSerial. The attempt in the question to disconnect WiFi is a step in the right direction, but not enough. You have to actually turn off the WiFi. The challenge is to reliably shut down the WiFi and then start it up again. This has been discussed extensively in the ESP8266/Arduino Git repository here and is referred to by some as "Issue 644".  An sample implementation of the code to reliably is presented here.
Here's what the on/off functions look like. I strongly urge you to go to the code linked above and copy from there rather than here, though.
extern "C" {
#include "user_interface.h"
#define WIFI_RETRIES 25

int conn_tries = 0;
bool WiFiOff() {
    WiFi.disconnect();
    WiFi.mode(WIFI_OFF);
    WiFi.forceSleepBegin();
    yield();

    /*
     * It can take a while for the ESP to disconnect, so we need
     * to give it a couple of seconds before returning a fail.
     */
    while ((WiFi.status() == WL_CONNECTED)
           && (conn_tries++ < WIFI_RETRIES)) {
        delay(100);
#ifdef DEBUG
        Serial.print(".");
#endif
    }
    if (WiFi.status() != WL_CONNECTED)
        return (true);
    else
        return (false);
}

/*
 * Turn the WiFi back on again with forceSleepWake().
 * NOTE:-  =Your= SSID and password must be in the
 *         user_config.h file.
 */
bool WiFiOn() {
    conn_tries = 0;

    WiFi.forceSleepWake();
    WiFi.mode(WIFI_STA);
    wifi_station_connect();
    WiFi.begin("corazon_del_bosque", "");

    /*
     * It may take a while for the ESP to re-connect, depending
     * upon external factors (e:- has the access-point moved out
     * of range since we were last connected?).  This loop will
     * give us a reasonable time to re-connect without blocking
     * permanently.
     */
    while ((WiFi.status() != WL_CONNECTED)
           && (conn_tries++ < WIFI_RETRIES)) {
        delay(100);
#ifdef DEBUG
        Serial.print(".");
#endif
    }
    if (WiFi.status() == WL_CONNECTED)
        return (true);
    else
        return (false);
}

I'm using this code in my program via the Arduino IDE. The author used it in PlatformIO. Other build systems may have other requirements.

WiFi uses interrupts. Alot. SoftwareSerial doesn't work well with interrupts.  On the Arduino all interrupts are disabled while SoftwareSerial does its work. I don't know how it is implemented on the ESP8266, nor how interrupts operate on the ESP8266, so cannot comment on how to work around it.
However, if you can't use one of the hardware UART channels then maybe you need to start thinking outside the box. And by "the box" I mean "the ESP8266".
Maybe the ESP8266 isn't for you. It's a great chip for making a WiFi interface, but it's not good for much else. It simply lacks the internal peripherals to be useful.  Maybe upgrading to the ESP32 would be a good option for you (that's the ESP8266's big brother). It has a far more feature-rich peripheral set.
Also don't be afraid of using more than one microcontroller. If the ESP8266 doesn't have the interfacing you need then add another MCU to it which does have the interfacing you need - and then get them to communicate using whatever interface you do have available (I2S, SPI, etc).  Yes, it means more programming and a more complex project, but learning such things will certainly unlock more doors for future projects.


text:
DS1307RTC Outputting cryptic 165/165/2165 date. What are some possible fixes?
My board.

I think I have it wired correctly (the lights aren't, but the board is).
I've read through the first few Google results to no avail.
My sample code to test the chip:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
  while (!Serial); // for Leonardo/Micro/Zero

  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
    }

void loop () {
DateTime now = rtc.now();

Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();

Serial.print(" since midnight 1/1/1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");

// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now + TimeSpan(7,12,30,6));

Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();

Serial.println();
delay(3000);
}

Serial output:
`RTC is NOT running!
2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

Had the same issue, however, my RTC was 1302 (not 1307) and yours seems to be as well, please check.
If it's 1302, use this library:
https://github.com/msparks/arduino-ds1302
Also, make sure you connect pins like this:

Arduino Pin 7 goes to CLK
Arduino Pin 6 goes to DAT
Arduino Pin 5 goes to RST
Arduino 5+ goes to VCC
Arduino GND goes to GND

Your picure shows also another device on the bread board. Remove that and ensure that:
Uno Ground --> 1307 Ground
Uno 5Volt --> 1307 +5v
Uno A4 --> 1307 Data
Uno A5 --> 1307 Clock
If the 1307 has a power led indicator, it should be lit.
If that still does not work, then in the code, comment this line out:
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

and uncomment this line to set the 1307 with a specific time stamp:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));

On the DS3231 seems like the device can get unsynchronized with the microcontroller. Not sure if the same problem with DS1307 I think worth trying.
My complete solution on stackoverflow for the same question

The I2C interface is accessible whenever either VCC or VBAT is at a
  valid level. If a microcontroller connected to the DS3231 resets
  because of a loss of VCC or other event, it is possible that the
  microcontroller and DS3231 I2C communications could become
  unsynchronized, e.g., the microcontroller resets while reading data
  from the DS3231. When the microcontroller resets, the DS3231 I2C
  interface may be placed into a known state by toggling SCL until SDA
  is observed to be at a high level. At that point the microcontroller
  should pull SDA low while SCL is high, generating a START condition.

Put in the following line in void setup():
Wire.begin();

(Assuming Wire library has been included.)
This will set up the I2C connection between the Master (Arduino) and the Slave (RTC).
For more generic use, the syntax is: Wire.begin(address);
The complete code is:
void setup () {
  Wire.begin();
  Serial.begin(9600);
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // UNCOMMENT TO SET TIME & DATE TO THAT AT COMPILATION.
  //rtc.adjust(DateTime(2017, 8, 31, 14, 45, 14 )); // UNCOMMENT TO SET TIME & DATE MANUALLY. (YEAR, MONTH, DAY, 24-HOUR, MINUTE, SECOND)

}

I had the same "165" problem.  Very intermittent.  Turns out that I was drawing too much power from the Arduino rails for the circuit I was controlling.  I was being lazy by not powering it independently when I started.  Nick Gannon on arduino.cc showed where the 165 came from and solved my problem.  He included the bcd math.
https://forum.arduino.cc/index.php?topic=184908.0

With the Arduino Due, the 165 problem came up intermittently with a knock off DS3231 (compatible with 1307 supposedly).  Tried switching to a different RTC but it didn't help.  Switching to an Arduino Mega 2560 seems to have resolved it.  The Mega 2560 is a lot slower so maybe it was a clock speed issue?  In any case, it was useful for resolving the intermittent issue.
That said, if you always get 165:165 it means your Arduino is not communicating with your RTC.  This is a different problem and won't be solved by switching Arduinos.

I can verify that the 1302 does not work with the 1307 library.  Very different chips.  No I2C on the 1302.  I'm trying to setup an autosync with the 1302 by studying how the 1307 does it... not having a lot of success.
I did it once before, and it is driving me bonkers that I can't figure it out again.

I had the same exact issue and discovered that the Tiny RTC 1307 board.  I found that the board I had was operating at 3.3v.  Once I moved the board to a 3.3v pin on my Arduino Nano.

I had same issue.
Put in setup rtc.begin();

rtc.begin is already in the OP's setup method.

I had the same problem 165/165.
I change the Crystal 32 kHz which solved my problem.

At best, this answer is extremely cryptic and hard to understand.  Can you explain why changing the crystal solved the issue?


text:
Remote temperature sensor system without slave board
I want to build a temperature control network over my house reading data from each room and sending it to the main board for further processing. I need about 6 sensor nodes sending the data over the air to the main node.
There are tons of tutorials of making master-slave temperature/pressure etc control systems of 2 Arduino boards communicating via wireless channel.
I find it a bit expensive to have a board per sensor node. Is that possible to build a sensor device without a controller using just a sensor, a battery and a wireless transmitter plus required radio components? It's ok to send raw data to the main node. Assuming it knows the protocol it will be able to decode the data there from all the incoming channels.

Only if the wireless transmitter itself is a control board. Like the ESP8266.

As @Majenko said on comment, its possible. One of the choice is ESP8266. Your project has been successfully accomplished, you can check here, here, or here. NSP8266 only needs 3-3.6V (low current) supply voltage.

@Sergey if its cost what's bothering you , there are numerous low-cost options for MCUs. For eg you can club a MSP 430 ( probably <1$) chip with a cheap RF transmitter which wont burn a hole in your pocket and is absolutely reliable. Wifi modules can be a little expensive and need constant connectivity. So, you have a choice on this.


text:
Why is this IIR Filter unstable on the Arduino Due?
I am using an Accelerometer (on the MPU6050) and connected it to the Arduino Due. In order to filter the signal I am using an IIR Filter with the following transfer function:
H(z) = Y(z)/X(z) = B/A
B = 0.00000376 + 0.00001127*z^(-1) + 0.00001127*z^(-2) + 0.00000376*z^(-3)
A = 1 - 2.9372*z^(-1) + 2.8763*z^(-2) - 0.9391*z^(-3)
which is an IIR 3th Order Butterworth, Cutoff Freq: 0.5Hz, Samling Freq: 100Hz. These numbers can be calculated by any IIR calculator.
Thus, then discrete equation is:
y[n] = 0.00000376*x[n] + 0.00001127*x[n-1] + 0.00001127*x[n-2] + 0.00000376*x[n-3] + 2.9372*y[n-1] - 2.8763*y[n-2] + 0.9391*y[n-3]
I first tried it on the Arduino UNO. Then I found out that decimal point precision (float & double) on the UNO is only 6-7 digits. But the therm "B" in the transfer function has for example (0.00000376) 9 digits. I thought this is the porblem, so I switched to Arduino Due and now I am using double (instead of float) which should have enough precision.
It is still unstable. It is not oscillating but getting bigger. I also tried an IIR 4th Order Butterworth, Cutoff Freq: 1Hz, Samling Freq: 100Hz. This one is oscillating.
However, the only IIR that seems to be stable is an IIR 3th Order Butterworth, Cutoff Freq: 1Hz, Samling Freq: 100Hz.
I have no idea so far what the problem is. Could anyone help please?

The precision of a float is about 7 significant digits. The
constant term of B in your transfer function (0.00000376) has only 3
significant digits.
Your transfer function has a pole at z = 1. It is thus not really
stable, but only marginally stable. Any parasite DC component in
the input will make the output drift without bounds.

It seems to me that your problem is not related to the implementation of
the filter on the Arduino, but rather to the filter design. Where did
you get that transfer function from?
Edit: I looked at the filter you are trying to make. It turns out it
is very sensitive to the precision of the coefficients of A(z). If you
try to add these coefficients, they almost cancel out: their sum is
about 3e-5. At zero frequency, both A and B are 3e-5, and the transfer
function, which is their ratio, is 1. By rounding the coefficients to
four decimal places, you made the cancellation exact, and the transfer
function infinite.
Just write the transfer function with more decimal places in the
coefficients and it should work:
H(z) = 3.75592×10−6 (1 + 3 z−1 + 3 z−2 + z−3)
         ÷ (1 − 2.9371759 z−1 + 2.8763097 z−2 − 0.9391038 z−3)

I used:
https://ch.mathworks.com/help/signal/ref/butter.html
for the filter. You can use their "in Browser Matlab" for free.
Then you can also use:
https://ch.mathworks.com/help/matlab/ref/roots.html
in order to see that the absolute values of the complex poles are insed the unit circle. Ok so, what am I getting wrong here? :-/

@user3554669: I don't have a MathWorks account. But you can easily derive the transfer function yourself: Wikipedia provides the continuous-time transfer functions on the page Butterworth filter. And also a description of the bilinear transform, which you can use to derive a discrete-time transfer function.

That's what I am saying. It should be stable. Poles are inside unit circle.

@user3554669: No, it is not expected to be stable. For real stability, poles should be in the interior of the unit disc. A pole in the exterior would cause exponential instability. With a pole at z = 1, unbounded linear drift is expected. Note that rounding errors, even at double precision, could put your pole on the exterior.


text:
How to use breakpoints for debugging
Breakpoints are a great way to see how the compiler runs to your code. Now my question is, is there a possibility to use breakpoints when you debug your code?

As noted in Majenko's answer, the Arduino IDE doesn't provide a breakpoint  mechanism but Atmel Studio does support breakpoints.[*]
However, if you have a switch and an LED, you can track the progress of your program in a way that provides some of the benefits of breakpoints.  You would add a subroutine, say BPReport(), that via serial output or an LCD reports values of critical variables, then lights the LED and waits until the switch has been pressed and released, with debounce.  Call your BPReport() routine whereever you want an unconditional breakpoint.  For conditional breakpoints, you can have a routine BPReportIf(cond) which calls  BPReport() if cond is true.  If you don't want to output via serial, you might use several LEDs or an LCD, and you might use several switches if you want external break controls (for example, cond could be a test of one of the extra switches).
[*] Some hardware debuggers modify downloaded code each time breakpoints are added, changed, or removed.  That usage will wear out flash memory more rapidly than just occasionally downloading to it.  If a chip has been heavily used for such debugging, don't use that chip in a production system.

Though Majenko his answer is correct there are some other options.
As to the real hardware debugging as stated by majenko I would say:

Install and use a real IDE, such as Atmel Studio or the arduino eclipse plugin called sloeber (I'm author), and
Use a full hardware debugger or hardware that has it on board like the Arduio zero or hardware using other debugging technology like the ESP8266 that allows USB debugging

An other debugging option from a completely different category is to organize your code so that decision logic (hardware independent) and action (hardware dependent ) are completely separated.
Then compile your sketch as a local program and debug the "decision logic" on your local machine. This method does not allow for "hardware debugging". This method also enables unit testing.
Note that your local machine is probably a 32 or 64 bitter and most Arduino's are 8 bitters which will result in differences in data types which is an extra attention point when using this method.

The Arduino-Debug library provides a simple on-target debugger for Arduino sketches. Debug command are added directly to the sketch. A debugger command shell is started on break-points and assertions.

The screen-shot above shows the example sketch run on an Arduino Mega with Serial output monitor used by application and Serial1 used for the debugger shell.
Sketch Debug Commands

ASSERT(cond)     Check assert condition. If false the debug shell is
called. The sketch cannot continue.
BREAKPOINT()     The debug shell is called.
BREAK_IF(cond)   The debug
shell is called if the condition is true.
CHECK_STACK(room)    Check
that there is room (bytes) on the stack. If false the debug shell is
called.
DEBUG_STREAM(dev)    Use the given stream device for debug session. Typically Serial.
OBSERVE(expr)    Print the expression to the debug stream.
OBSERVE_IF(cond,expr)    Print the expression to the debug stream if
the condition is true.
REGISTER(var)    Register a variable for access
from the debug shell. Debug Shell Commands

Debug Shell Commands

?VARIABLE  Print variable address and value.
@VARIABLE  Print pointer variable address and reference value.
backtrace  Print simple call-stack.
commands   Print list of commands (see also help).
data   Print contents of data area, i.e. global variables.
go     Leave debug shell and continue execution of sketch.
heap   Print contents of heap, i.e. dynamic allocated data.
help   Print list of commands.
memory Print memory status.
quit   Stop sketch.
stack  Print contents of stack, i.e. call frames, arguments, return addresses.
variables  Print list of registered variables.
where  Print source code file and line where debug shell was called.

All debug shell commands can be abbreviated to single character commands. Please see the README for further details; installation details, example sketch and benchmarking.

Mikael's donated library lets you set conditional breakpoints, print variables' values, memory status, call traces, & examine-and-change variables at a breakpoint. Pro: Doesn't need hardware ($$), doesn't beat-up as hard on the Flash (as setting and removing breakpoints with a hardware debugger would). ....

.... Con: Higher impact on the program's code-space, some RAM space, & possibly run-time, if examining time-critical code; some learning curve to compile in (and later, remove) the library calls; the need to anticipate break-point locations or re-compile them in when you discover where you need them. The Cons are not a criticism of Mikael's work; they come with this technique.

@JRobert Nice Pro-Con summary! I have tried to address some of the Cons by allowing the debugger to be tailored. There is a set of defines that will allow footprint sensitive applications to reduce the debug shell to a minimum. As any debugger for embedded systems it is difficult to debug time critical (continuous) code with break-points. The only alternative is observation points. These could be optimized by using a trace buffer and remove serial output in time critical code.

Not in the Arduino IDE.
You need to:

Install and use a real IDE, such as Atmel Studio, and
Use a full hardware debugger

There is no provision for debugging through the UART/USB interface using the bootloader.


text:
How time intensive or how long can an ISR be?
I would like to code my ISR to be time intensive or interrupt the main program for atleast 1 or more seconds. My goal is to verify that if I am reading a sensor in the main loop, would it stop reading the sensor when the code is interrupted and for how long. I have trying to call various functions from the ISR like to turn on the motor but everything is instantaneous.

Please explain what it is you want to achieve. It sound like you are trying to use ISR for something, while there might be a much better solution.

Putting it simply, I am trying to design a position controller. I have an input which drives a motor. Hall sensors read the revolutions. Trying to determine which of the above, input or hall sensor output should be used as an interrupt

Could you please post your code?

Use a pin interrupt for the hall-effect sensor. That way, whenever the hall-effect sensors triggers, you get an interrupt. Then you can calculate the speed using the difference in millis between this interrupt and the previous one. The main loop will act based on the current speed you've written to some variable. None of these things should take a lot of processor-time.

How long can an interrupt be?

If you don't want anything else to happen, then as long as the time between successive interrupts.

would it stop reading the sensor when the code is interrupted and for how long.

While the interrupt is running nothing else can happen in software. Absolutely nothing. Only one thing ever happens at once - either your main loop or the interrupt. For the entire duration of your interrupt everything else is put on hold.
That includes things that rely on other interrupts to function, such as serial communications, millis() and delay(), etc. That means using such functions from within your interrupt handler is a big no-go.
It is generally very very bad practice to have an interrupt blocking for more time than absolutely necessary (a few milliseconds or even less). If you need to have things taking a long time then you should consider breaking them down into smaller operations and doing different sections at different times through different means.

Thank you. So between a rotary encoder reader and an input signal, I would assume based on the fact that the main loop is suspended, the encoder reader is better suited as an interrupt. Is that right?

Rotary encoders work well with interrupts, yes. React to a change in one of the signals and work out which way it has been turned. You need very rapid responses to a rotary encoder since the signals can change quite fast.

Great, I guess that simplifies things. Thanks for your help

@Vignesh I'm not sure why you are treating this as an either/or situation. They can both be interrupts. All the interrupt has to do is make a record of the new input or increase a count of the number of pulses and set a flag indicating that the value has changed. The main loop then looks for those flags and does all the slow work in the background. Just make sure you code the main loop so that it can cope with the possibility that the data may get changed half way through. e.g. make a copy of it and work from the copy.

Does the delay() function not work for you? It should halt all other processing, whether in ISR or not; so if you call it inside your ISR, your ISR would remain active for as long as the delay.
Of course, ISR should not be long like this. Perhaps there is a better way to code your test. Perhaps a variable that the sensor-reading code checks; if it's set to 1, don't read the sensor, and if it's 0, it's okay to read the sensor, etc.

Thank you. I think the delay() function does not work as it depends on the timer which is suspended when an ISR is called. Will check it either way.

The main goal is to see which aspect of the program should be an interrupt. The rotary encoder reader or an input signal

use delayMicroseconds(), then.

delay() does not work if called from within an ISR. 2) When called from main code, delay() does not halt ISR processing.


text:
Custom ISR triggering function/value
Is there a way to write a custom function which would be the mode/reason to trigger an interrupt. I have an analog joystick connected to my arduino analog pin. It reads a value of 689 on one end and 0 on the other and around 480 in the center. I would like to trigger an interrupt based on these value changes i.e an interrupt when it  more then 600 and another when less then 10. None of the pre-defined modes RISING,HIGH,LOW,FALLING,CHANGE are working satisfactorily.

No. Interrupts are hardware. You cannot "create" interrupts in software.
The closes there is to what you are after is the Analog Comparator (see section 27 of the datasheet).
The analog comparator allows you to trigger an interrupt if a voltage is above (or below) a reference voltage which is up to you to provide.
For anything more complex you would need to use external comparators to trigger on different voltage levels which then trigger external INT pins on the ATMega.

Of course, you can make software interrupts on Arduino; it just costs a hardware pin. The following is a quote from the Atmel ATmega48A/PA/88A/PA/168A/PA/328/P datasheet:
"13. External Interrupts
The External Interrupts are triggered by the INT0 and INT1 pins or any of the PCINT23...0 pins. Observe that, if enabled, the interrupts will trigger even if the INT0 and INT1 or PCINT23...0 pins are configured as outputs. This feature provides a way of generating a software interrupt."
You set up an interrupt on the pin you select for the purpose, you set the pin as output, and then you trig your "software interrupt" by writing a value to the pin.

This could be combined with @Edgar Bonet's suggestion to use a free-running ADC, which generates an interrupt every 104us. The ADC interrupt does a range check and, on entering or leaving the range, raise a PCINT to carry out whatever actions are required.

As Majenko already said, you cannot do that. But you can look for
alternative ways of achieving a similar end result. The real question
is: what are you trying to achieve? Interrupts may not be the best
answer.
I assume what you have in mind is a program roughly along these lines:
// Interrut handler called when input > 600.
void handleHigh()
{
    // ...
}

// Interrut handler called when input < 10.
void handleLow()
{
    // ...
}

void setup()
{
    // Register the interrupt handlers.
    attachInterrupt(ANALOG0, handleHigh, MORE_THAN_600);
    attachInterrupt(ANALOG0, handleLow, LESS_THAN_10);
}

void loop()
{
    doSomeStuff();
}

Of course, that syntax for calling attachInterrupt() does not work, I
just made it up.
The most obvious alternative is to read the value through an analog
input in loop() and act accordingly:
void loop()
{
    // Check the analog input.
    int sample = analogRead(A0);
    if (sample > 600) handleHigh();
    if (sample < 10) handleLow();

    // Do the rest of the job.
    doSomeStuff();
}

No need to use interrupts. The only drawback is that the latency of your
response to a change in the joystick position can be as long as the time
your program takes to run through loop(). This should normally not be
a problem: the joystick is a very slow mechanical device, and your loop
should take no more than a few milliseconds. If the loop if really too
slow, you are probably doing something wrong, like using delay(). You
should then fix that problem rather than trying to work around it with
interrupts.
Just for completeness, there is an interrupt-based solution. Assuming
you have no other analog input to read, you could configure the ADC to
continously read the same input (say, A0) in the so called “free
running mode”, and trigger an interrupt on each reading. In the ISR, you
can then call one of your interrupt handlers if needed (if the sample you
get is outside [10, 600]). Here is how you can do it on an Arduino
Uno:
void setup()
{
    // Configure the ADC in "free running mode".
    ADMUX  = _BV(REFS0)  // ref = AVCC
           | 0;          // input channel = A0
    ADCSRB = 0;          // free running mode
    ADCSRA = _BV(ADEN)   // enable
           | _BV(ADSC)   // start conversion
           | _BV(ADATE)  // auto trigger enable
           | _BV(ADIF)   // clear interrupt flag
           | _BV(ADIE)   // interrupt enable
           | 7;          // prescaler = 128
}

// ADC interrupt service routine.
// Called each time a conversion result is available.
ISR(ADC_vect)
{
    // Read the ADC.
    int sample = ADC;

    // Call the handlers if needed.
    if (sample > 600) handleHigh();
    if (sample < 10) handleLow();
}

Edit: With the code above, the ISR runs every 104 µs. Then you
should make sure that your handlers take significantly less than that
time to complete. Otherwise they will consume 100% of the CPU power
whenever the joystick is in the range to trigger one of them. As a small
optimization, you could declare the handlers static inline in order to
avoid the overhead of a function call.

Thank you Edgar. I cannot use the loop to check the value since I have other code running there but this input has higher priority. But I guess the second suggestion would work. Thank you

@Vignesh: You wrote: “I cannot use the loop to check the value since I have other code running there”. This makes no sense at all. See the doSomeStuff() call in my example: it's still there when you check the input in the loop.


text:
Wearable GPS Antenna
I am using the Adafruit Fona 808 to make a wearable device. One of the main features is GPS but I cannot seem to find a suitable antenna for wearables. My question is: What is a good GPS antenna for a wearable project and should it be active or passive?
Thanks

Whats wrong with the recommended antenna on the product page?

I too thought whats wrong with a normal Antenna, but the answer is the problem is the human body.
There are manufacturers that make "fabric" antennas, but these tend to be Mil-Spec so are going to cost a fortune.  (http://www.pharad.com/gps-wearable-antenna.html)
I found this site that explains what the effect of the body is, and seems to make their own antenna.  http://www.pharad.com/gps-wearable-antenna.html
I think you might be better off looking for a high gain antenna and the choice of active or passive will probably be based on the interference you get from the body.


text:
How do I see the command line equivalent of clicking Verify?
I am using the ESP8266 board manager. I want to see how Arduino IDE compiles my code once I click Verify.
Why do I want to do this?
I am trying to integrate a C library for which there is now Arduino library package available. So I have to integrate it from source. I want to be able to specify custom -I, -L  and -l flags when I compile my code.

Turn on the verbose compiler settings in the preferences.

In the Arduino IDE switch on File>Preferences>Upload erbose and Compile Verbose
When you build you will see all the compiler commands
The verify is often a -v param in the command
You will find the esp8266 platform.txt in a location such as c:\users\[name]\appdata\local\arduino15\packages\esp8266...
The platform.txt contains all the compiler switches, the boards.txt in the same location can also contain board specific switches.
You can not specify different switches for different files in a compilation but you could compile your code into an archive then force it into the build process. Not sure if that is practical or not.


text:
Arduino Com port and PHP Bug
so please read this whole thing.
My Project: I am making a bell system that is based on PHP. The bell is connected to the arduino UNO via a relay and the arduino is connected to the computer via a USB cable. The interface with the database is built with PHP and MySql. Then we have the code which checks every minuit if the bell has to be rung and if it does send a numeric value to the arduino. There is also an option for a longer bell if we send a '0' to the arduino.
My Code: So this is the file that checks if bell has to rung and sends value to arduino
<?php
include('database.php');
$usb_comPort = "COM3";
date_default_timezone_set("Asia/Kolkata");
$time = date("H:i");
$time = trim($time);
$sql = "SELECT bell_amount FROM bell_db WHERE DATE_FORMAT(bell_time,'%H:%i') LIKE '$time'";
$result = mysqli_query($conn, $sql);
$numRows = mysqli_num_rows($result);
if ($numRows == 0) {
  echo 'Error: Nothing found!';
} else {
  $row = mysqli_fetch_assoc($result);
  $bellAmount = $row['bell_amount'];
  $runCommand = "ECHO " . $bellAmount . " > $usb_comPort";
  echo $runCommand;
  exec($runCommand);
}
?>
<html>
<meta http-equiv="refresh" content="60">
<body>
</body>
</html>

and this is the arduino's code:
int b = 0;
void setup() {
Serial.begin(9600);
pinMode(10, OUTPUT); //relay
}

 void loop() {
  b = Serial.read();

    b = b - 48;
    if(b == 0){
      digitalWrite(10,HIGH);

      delay(3000);
      digitalWrite(10,LOW);
      }
    else{
    for (int i=0; i < b; i++){
      digitalWrite(10, HIGH);
      delay(200);
      digitalWrite(10, LOW);
      delay(200);
      }

    }

}

The Issue that i am facing: My aim is that the code should run automatically when the computer is turned on. The code works fine but there is random bug. The code is uploaded to the arduino. When the computer is turned on i want that the system should work but when i run the file  (the one that checks if there is a bell to be rung or not ) it processes the code but it is not able to send a value to the com port so the bell does not ring(the serial light on the arduino does not flash). But if i go to the arduino ide and send a value through the serial monitor once then run the php file, it works!
I am running this on a windows 10 computer, i have an arduino UNO and i have tried this with 2 arduino's same result on both.
So anyone know what i can do?

To make your question easier to read and answer you should remove all the database- and time-related stuff from your PHP code and concentrate only on the communications with Arduino. This forum isn't the place to be debugging non-Arduino code.
I suggest you create a function that tells the Arduino to ring the bell. You debug that by calling it directly and post that function here if you have problems with it. You can simply print out what you would pass to the function when debugging your database and other code.

You need to look at Serial.available() rather than blocking on Serial.read().  Also what happens if your code receives a space?  b = b -48 = -16 and then for (int i = 0; i < -16; i++) it isn't going top work how you expect.

@Matt I have made sure that white space and alphabets are not sent and even if blank is sent nothing happens.

Sounds like the COM port is not setup. Opening the Arduino IDE probably does this automatically.
Try running the following command, only once, after turning on your pc to initialize the COM port.
mode COM3 BAUD=9600 PARITY=n DATA=8

Ps. I'm not a windows user, so this is an educated guess - reference.
Pps. I think you're winning the award for the most complicated way to ring a bell. :)

Thanks dude.. well do you have any other better methods of doing this?

Well I'm not exactly sure what your requirements are, I'll assume is to ring the bell based on information in the database. In that case you could eliminate the webpage and browser all together and write a command line application/daemon/service. You could still write it in php if you wanted, and it would be more accurate and less error prone than relying on the meta/refresh in a browser.


text:
Which side should I connect the resistor on?
I understand that when connecting an LED and a resistor in series; the resistor can be placed on any side of the LED as the current will remain same in a series connection. Please correct me if I'm wrong, but I was under the impression that conventionally the electrons flow from positive to negative. So shouldn't the resistor be placed before an LED to limit the flow of charge.
In this scenario the negative is connected ground and the positive to a power source. So I don't understand the chain Link analogy as well. Where the whole chain moves as a whole because here the flow ends with the GND right ?

Another way to look at it is this:Imagine the current flowing through the LED toward the resistor to be greater than the current flowing out of the resistor toward ground. The only way this could happen is if some of the charge - the difference due to the different currents - accumulated in the resistor. But that cannot happen forever, and not even for any appreciable length of time. (If it could, and did, the device would eventually fail - spectacularly!) So, because charge in must equal charge out over time (and over a very short period, at that) current in has to equal current out.

Charge per unit time.

Wow. That cleared things up. Thank you !! ... So resistance is basically the action of electrons moving slower as the electromagnetic force in the insulator is higher rite ?

Slower in the flow sense or electrons per unit time. And as I understand resistivity, it doesn't involve electromagnetic force but the availability of free electrons. More free electrons available to move through the material -> lower resistivity (and I'm somewhat beyond my knowledge here, but here is a section of a Wikipedia article that discusses it briefly).

Resistor on any side of led will intercept current flow.
Just use another analogy with water, tube and water tap.


text:
Getting sensor data wirelessly from arduino to PC
I am working on a project that involves sending motion sensing data wirelessly from an arduino to computer. Sensor readings have to be transmitted continuously (say every mili second). I am not sure if Xbee is my bet. I came across this link
which suggest s that there should be atleast 10 ms delay between packets if you're using xbees.
What are your experiences with xbees? I don't want to waste money.

what is the distance between devices?

Not more than 5 - 10 meters I think.

if you don't want to waste money take bluetooth adapter. HC-06 is around 4$. Also there are NRF24L01+ 2.4GHz trasceivers. They are cheap and fast

How much data do you need to transmit every millisecond? I like the nRF24l01+ units and have found them reliable at ranges around 10-15 metres but they have a max payload of 32 bytes and top speed of 2Mbps, both of which will limit throughput.

I can connect atmost six sensors to the arduino. So It should be around 20 bytes tops. What do you guys think about xbees? I know I can get those easily in my country. Not entirely sure about nRF24l01+.

Xbee costs about 1000INR. They are really expensive. You should buy HC-05 module, which costs about 320INR.
You can easily interface them with Bluetooth of your Laptop using Processing Application.
You can even use ESP8266 ESP-01 Wireless Module. They Cost about 3$.
Wireless module gets connected with your router. this tutorial will help you to start. You can by this module from here.
nRF24l01+ modules can not be interfaced with Laptop...

Thanks a lot for the suggestion but I am specifically looking for a rf or wifi solution

ESP8266 ESP-01 Wireless Module is a WiFi solution to your problem!!


text:
Arduino's Serial Monitor Showing Constant Value
I have a breadboard Arduino; made with ATMega328PU and a UART connector using a CT2102 breakout board. With the help of this site I created a simple IR sensor, now the problem is that in the Serial Monitor I'm getting a constant value of 1023. Even on removing the receiver (photodiode), the value's starts dropping like a capacitor discharges, and then stabilizes at some value (around 260-300).
When everything was working correctly, the value dropped to a sudden zero on removing the receiver, but now it isn't.
The "robot" was working perfectly and was reading the values correctly, but suddenly, the values dropped; we checked it and the Serial Monitor showed the same values. To check if the connections are working, I removed a wire from the Analog Pin of the Breadboard-Duino, and the values started to drop: like a periodic function.
The following code was used:
int pd=2;                      //Photodiode to digital pin 2
int buzz=13;                   //piezo buzzer to digital pin 13
int senRead=0;                 //Readings from sensor to analog pin 0  or A0
int limit=850 / 4;                 //Threshold range of an obstacle
void setup()
{
  pinMode(pd,OUTPUT);
  pinMode(buzz,OUTPUT);
  digitalWrite(pd,HIGH);       //supply 5 volts to photodiode
  digitalWrite(buzz,LOW);      //set the buzzer in off mode (initial condition)
  Serial.begin(9600);          //setting serial monitor at a default baund rate of 9600
 }
void loop()
{
  int val=analogRead(senRead) / 4;  //variable to store values from the photodiode
  Serial.println(val);          // prints the values from the sensor in serial monitor
  if(val <= limit)              //If obstacle is nearer than the Threshold range
  {
   digitalWrite(buzz,HIGH);     // Buzzer will be in ON state
   delay(20);
  }
  else if(val > limit)          //If obstacle is not in Threshold range
  {
   digitalWrite(buzz,LOW);      //Buzzer will be in OFF state
       delay(20);
  }
}

Any help will be appreciated.
EDIT
The phototransistor/diode is a standard 2pin component which came with the IR sensor.

This is most likely a problem with the connection of the sensor.  What sensor is it? How is it wired? Please show some schematics or good clear photos, as well as links to data sheets.

Majenko, I did check the connections thrice; checked every component two times, but still no luck! :'(

I'm getting a constant value of 1023 - you won't be getting that because you divide the reading by 4. You should get a maximum of 255. Please post the code you are actually using. Also measure the voltages going into A0 with a multimeter, to confirm they vary as something passes between the transmitter and receiver.

I guess your ir emitter is blown.Test it with a multimeter.Apply 5v from Arduino and check the voltage between two pins or just use phone's camera.If multimeter shows anything more than 3v or it just plainly shows applied voltage the led failed or it is open.If it is not,then use phone camera and watch the led through the camera. You should see a blue light emitting from it( if it's working).

If the circuit worked perfectly, as is, and suddenly stopped working, without changing any hardware configuration, it must be a hardware related problem.
Assuming your Arduino Uno is functioning properly and the pins behave accordingly (you can test blink.ino on the pin in doubt), it's either the IR sensor went bad or a the IR LED stopped working properly. Test each component individually. For the IR sensor, you could use any remote control to emit IR light on it and see if values change.
Another way to test bad pins are to switch from A0 to A1 and from PB2 to PB3 or similar.


text:
Using PBC library on Arduino
I want to know if there is a way to install/use the PBC library on Arduino UNO. I want to implement some cryptographic primitives using PBC library.
Thank you.

GMP could be very painful to get working on something as small as the ATmega328P.

Anyway, I want to know how to do it

Hello Miss Jéssica Carneiro, Could you tell me "Is it possible to install PBC library on Arduino ?"

You could use the RELIC toolkit. It has PCB and they have scripts to compile for Due and Mega. I'm not sure if you could use this with Uno. But this library targets resource-constrained devices.


text:
NRF24L01 Direct Communication Library Logics
Actually I'm using the RF24 Library mantained by TMRh20 (https://github.com/TMRh20/RF24).
I'm trying to get some type of direct communication between multiple modules working, but I don't want to use the RF24Network Library (https://github.com/TMRh20/RF24Network) which creates a mesh of connections.
I currently have several arduinos that have to communicate between them. Every arduino has its own address starting from 0x0001 (0x0000 is for a main module that manages everything) and finishing to 0xFFFF.
I want to directly communicate between the two NRF24L01+ modules without any intermediator, because I don't have problems of distance.
The main thing that I want to be able to do is communicate directly not with just one module, but choose if I want to broadcast to all the modules in an area (I know that it can be done with range power modifications in the code) or talk with just one module.
What is the best way to do this type of communication?

I'm unaware of any broadcast method inside the NRF. You could just have all the devices have the same address, an use the first byte of data to indicate who it is for. Or have them all listen to their own address and a separate "multicast" address (e.g. 0xFFFF). These modules can listen to upto 6 addresses, so you could even create several subnets. Also see this related question

Is there a reason you don't wish to use RF24Network?

I have already tried using RF24Network and I don't want to use it for two specific things:

It creates a mesh and I don't need it
It is a very big library and for a 328 processor is too much if I have to keep also other big parts of program

The RF24Network library would not provide a mesh, but a network layer over RF24 links. The RF24Mesh library (by the same maintainer) indeed provides a mesh.

Both of the Libraries you mentioned are well written. I've used both, but decided to write my own based those libraries. For me, the network libraries were written for their project and didn't really fit my needs. So I decided to write my own. I combed the internet for a bare bones NRF24 Library and found this one. This was my starting point. It didn't need the Arduino Core Library and handled all the SPI functions. Then I read the NRF24L01 datasheet several times, then read it again.
With that said, you can broadcast up to 6 radios at a time. Per the datasheet, the receiver knows which radio sent the packet. The STATUS register (0x07), should tell you who sent the packet:

I was unable to get this working (I am still working on it), so for now, I send my packet as a struct:
typedef struct  {

uint8_t id;
uint32_t data;

}
Packet;

Packet pck;
pck.id = 2; // id of my second radio

Keep in mind when you program your Arduino as the receiver, you have to tell it who it will be receiving from. The transmitter and receiver have to be on the same RF channel, speed and same pipe. To choose who receives the packet may not work the way you think, but as I mentioned you can program the receiver to know who the transmitter was and code around it.
I would suggest you dig into the datasheet.

You need to dig into the datasheet and read about ESB (Enhanced ShockBurst).  This is technology that is integrated into the radios and allows for broadcasting and direct pipes.  One of the limitations is that the mesh only works for up to 6 pipes, so be aware that this limits the number of devices that will be able to hear your transmission.
Another option is to have all the nodes listening on the same pipe, and then when node x wants to talk, he stops listening on pipe 1234 and starts writing to it.  You would put some sort of addressing header in the payload section of the packet, then when all of the nodes receive that packet, they can check that address and see whether or not to process it.  This might work well in your situation.
For example, if you have a packet that is sent on the communal pipe with a payload of [broadcast address,data] then your receiving nodes (those within "earshot") can receive the packet, see that it is a broadcast, then process the data.  If you want to send to a single node, create a packet that has a payload of [destination node id,data].  When each node receives that packet on the communal pipe, they will check the destination, and when it doesn't match either their own address or the broadcast address, then they dump it.  Only the intended receiver will actually process the data.

If you set pipe 1 to a common address (let's call it the broadcast address) anytime you send a packet to that address all the modules will receive it on that pipe!
It's as simple as that, but you will not be able to use auto-ack (you will receive multiple acks, one per each receiver) and you can't also use ack payloads.
I wrote a series of blog posts on this modules and I'm going to keep writing on the topic.


text:
Using an Arduino Nano, how many LEDs can I safely power?
I am working on building a wordclock using one of the several design ideas that you can find all over the Internet. Something like a mix of this one: http://www.instructables.com/id/Sleek-word-clock/ and this one: http://www.instructables.com/id/Personalised-Word-Clock/ A lot of the guides suggested building your own Arduino to save money, but I found these Arduino Nano clones for $7/apiece: http://www.amazon.com/gp/product/B00SGMEH7G.
I've done a few simple projects before, but nothing with the same kind of power demand. How can I figure out the power requirements? My plan is to use approximately 64 3mm LEDs via shift register, or possibly the equivalent segments of an LED strip.
The Nano clone does not have a barrel connector for external power adaptor. Should I directly solder on the power cables from an external adaptor? Use a screw terminal or similar? Is the USB adaptor a good enough source of power for 64 LEDs? Or do I have to do something else to supply external power to that many LEDs?
Thanks for any advice! I am experienced in programming but not in electrical engineering so many of the concepts are something I don't have a good handle on yet.

If you use shiftregisters, and don't do any multiplexing, you probably don't want to run the leds at their maximum brightness. Running them at 5mA will probably be more that bright enough. That would, in worst case, mean 64*5=320mA. Which is not that much, though I'd suggest using a 5v adapter, as the tiny voltage regulator in the nano board probably won't handle that much current without getting extremely hot. You can easily find 5v usb chargers that handle upto 2A.

I'm trying to find some videos that explain it better. How should I tie in the 5v USB charger to the Nano?

Just use the mini-usb plug, or connect ground and 5v on the nano to the corresponding wires on the charger.

Are you ever going to power all 64 LEDs simultaneously?  I would imagine a word clock would have just a fraction of the LEDs switched on at any given time, which would greatly reduce the current demands.

If you are running the LEDs from shift registers then the power rating of the Nano is irrelevant.
If you are wanting to use the Nano as the power source (not recommended) then you would need to know both your expected current and what the regulator on the Nano would be able to supply.  My immediate guess is "not enough".
64 LEDs at full brightness would be expected to use a maximum of say 20mA each, so 1.28A just for the LEDs.  That's a huge amount, and way more than any linear regulator can be expected to supply without melting everything around it.
So you can reduce your current requirements by not having the LEDs as bright.  Half the current does not equate to half the apparent brightness. In fact at half the current you probably won't notice much difference at all.  At a tenth of the current you will see them a bit dimmer, but not as much as you would expect.
So you can come up with a compromise between the brightness you desire and the current consumed by each LED.
Say you end up deciding on (as Gerben has suggested) a current of 5mA per LED.  When all LEDs are on that would be (5 × 64) 320mA.  That's reasonable for a linear regulator, but still will generate more heat than is really advisable.
So you should, for this project (assuming you aren't going to be using multiplexing, which is a whole other ballgame), investigate using a switching (aka "buck") regulator.  You can pick these up on eBay for just a couple of dollars and can quite happily supply amps as opposed to milliamps and will allow you to run far more LEDs without going into thermonuclear meltdown.
Another important consideration to think about is how much current an individual shift register can provide - both through its output pins and in total for the whole chip.  There are special constant current LED driving shift registers that remove the need for individual resistors on each LED and give much better control over the LEDs than traditional logic output shift registers.

Thank you. I was planning to use 3 of these: SN74HC595N to control the LEDs.  Are you talking about something like the MAX7221/7219? I found a guide that mentioned that part but I didn't realize one of the benefits was not needing resistors. That sounds really useful, I will use it! Also: do you have any good references I can use to learn about how to safely connect the power?  EDIT: looking at this guide, http://playground.arduino.cc/Main/MAX72XXHardware, does this reduce power usage to safely supplied by the USB port? I would use a small AC adapter with USB micro port.

I often use the TLC59116 which is an I2C device - you can have up to 14 on one bus and each one supports 16 LEDs (so 224 LEDs max).  Connecting the power is easy - the best thing to do is just use the buck regulator for everything - connect it to the 5V/GND pins of the Nano and also the Vcc or 5V and GND pins of any external devices.

Oh, the TLC59116 is also a PWM device, so you can set the brightness of each individual LED - just like the PWM outputs on the Arduino.  I even have a library to control them: https://github.com/MajenkoLibraries/TLC59116


text:
Connect Lilypad to LCD
I am trying to connect an LCD panel (RioRand (TM) IIC/I2C/TWI Serial 2004 20x4 LCD Module Shield For Arduino UNO MEGA R30) to a Lilypad Arduino.  How can I get them to talk to each other?   I cannot figure out how to connect them.

Thank you!  I was able to look that up and I got it to light up.  Cannot seem to get Hello World to work with the program in the tutorial.  I am new to all of this.


text:
Extremely cheap "Arduino" for single tasks?
I have been thinking of a million things to do with my Arduino, but those things are extremely simple and it would leave my Arduino as a $25 waste.
For example, programming Arduino to control my living room lights with my smartphone ... I was thinking of connecting the Arduino in the wall, onto the light switch wires. I am looking for a "permanent" solution, but I figure this would leave me with a $25 waste of circuitry inside my wall.
Are there any "Arduino" types of electronics that perhaps have many less ports, JUST enough to get a single task done?

How much are you willing to learn about electronics?

That would be more than 25 bucks... Controler, relay panel, communication (from $5 Bluetooh to $50 wifi). And what do you think would control the lights from your phone? Capacitors?

@IgnacioVazquez-Abrams As much as I can.

@Martynas Yes I figured that too, since I needed the Bluetooth add-on and perhaps even a USB board.

Digispark comes to mind, or any of the ATTiny breakout boards at Tindie. Or, make your own PCBs, I just now finished soldering a few ATMega328p circuits to boards I designed. Microcontroller is $1.50, PCBs range from $2 to $8 each, time is "free."
Also consider "compatible with" designs; while you're not directly supporting the ecosystem, if you've already paid full price once and your conscience is clear, eBay has plenty.

Perfboard will also work, if your circuit isn't too complicated.

You can embed a bootloaded ATMega328 (or any of the other compatible ATMega processors) http://arduino.cc/en/pmwiki.php?n=Main/Standalone in your project. That way, you will only need the processor and a couple of components, setting you back only a couple of dollars and saving quite a lot of space:
http://arduino.cc/en/pmwiki.php?n=Main/Standalone
If that is one bridge to far, you can have a look at the Arduino Pro or Arduino Pro Mini. Those boards are complete boards, only smaller and cheaper, and specifically designed for a more definitive use in projects.
If you need even more space and cost reduction, you can switch to a stand-alone ATTiny processor. The better models of those can also contain an Arduino program. Instructables has this great tutorial that shows you how to use an ATTiny85 or ATTiny45 as a lightweight 'Arduino'.
Recently, I have tried to use an ATTiny13A for a project, but that one only has 1KB of flash memory, which leaves you with hardly any space for the Arduino bootloader, let alone your program, so therefor I chose to program it directly using AVR Studio, at which point I think you cannot in any way call it an Arduino project anymore. :) Still, it's not that different. You only miss out on some of the library functions, and the implied application loop.

This is a typical scenario for an Arduino Uno board: you buy one and use it for prototyping your project. Once done, you design your own PCB, as small as possible, connecting only the required wires to the ATMega328p.
For the next project, you buy another ATMega328p (just the MCU), plug it on the Uno and start again.

Is there any link you can provide that describes the entire process of what you said? Sounds very interesting but I am new to Arduino and Electronics. Thanks!

One example is this instructables: http://www.instructables.com/id/DIY-Arduino-or-The-DIY-Duino/. Printing your own PCB is fairly easy using Fritzing https://www.youtube.com/watch?v=Hxhd4HKrWpg

I've had the same exact problem.
Since I like developing using the Arduino IDE I've created an how to assemble a board using just Thru Hole Components to replace the Official board.
Please visit the following link for further information http://jpralves.net/cseduino
All the components will cost about 5 USD.

Welcome to Arduino SE! Can you please add the schematic into this post so it still has value if your site would go down? Thanks!

There are good instructions here:
http://arduino.cc/en/Main/Standalone
and here:
http://arduino.cc/en/Tutorial/ArduinoToBreadboard
Alternatively you can go for an Arduino mini http://arduino.cc/en/Main/ArduinoBoardMini or a corresponding Chinese clone.


text:
Delay() function and I2C interrupt
In my design, one arduino pulls a line high on other arduino, the other arduino polls this pin and if that is high sends the data on I2C bus.
The first arduino holds the line high for 100ms using the delay() method, the other arduino is sending the data during this time, but the I2C receive interrupt is not being triggered.
I have attached a sequence diagram for a better explanation for what is happening.
I suspect that the delay() method somehow is disabling the I2C ISR from triggering.

"... the delay function does not disable interrupts."

How have you set up I²C? Which is slave and which master? Why bother with any signalling other than I²C?

because, my earlier design had a scenario where both the device started communicating over I2C at the same time, now the second device shall only send when the first asks it to do so.

Sorry guys, I made a very silly mistake here, i was using Serial.print here in ISR, following the Slave_Receiver example in the Arduino examples. I got a bit carried away with the use of those Serial debug messages and added lots of them,
I got this info from
https://stackoverflow.com/questions/17985830/arduino-using-interrupts-freezes-processing-and-serial-output
checkout answer by elias
The code does not freeze now. Sorry for the troubles, i hope this helps someone else in return.


text:
Global Arrays read as Zero
I have written a code for my Arduino which spans multiple files, In the file containing the main task, i have a Global Array like this
addr_t childAddr[NUM_CHILDS] = { CHILD1_I2C_ADDR, CHILD2_I2C_ADDR };

where
#define NUM_CHILDS  0x02
#define CHILD1_I2C_ADDR         0x10
#define CHILD2_I2C_ADDR         0x02

Now to debug my issue, in my Task i do this
Serial.print(childAddr[0]);
Serial.print(childAddr[1]);

All i receive is
00

I looked at the issue online, someone pointed it towards overshooting the RAM, I am working on a Pro Mini with ATmega328P with 2K RAM.

In desperate attempts to solve this i even tried addr_t childAddr[NUM_CHILDS] = { 0x10, 0x02}; and also tried assigning the valuess inside my Task, still the array reads as Zero.

I found a workaround for this, I declared the array locally and am using it. As per my understanding i think, C++ initializes all global variables to Zero, What eludes me is the fact that, i tried initializing them inside a function and they still read as zero.

what type is addr_t?

Its is an unsigned char

Your code on Github does not have that array at global scope, so it is almost impossible to debug code which we can't see.

Since addr_t is a character type, I suspect Serial.print() is trying to output the ASCII character representation of your two values. ASCII codes 0x10 and 0x02 are non-printing characters, so it might just be outputting 0's for lack of anything better to do.
To output the data as actual numbers, try casting them to integers:

Serial.print( static_cast<unsigned int>(childAddr[0]) );
Serial.print( static_cast<unsigned int>(childAddr[1]) );

Sorry, It does not work either, I have defined the array locally within the function now, and it seems to work fine with/without the static_cast<unsigned int>(childAddr[0]) I am getting the correct values with my version and your version of Serial Print. Pretty strange though. Is there any kind of compiler setting for this?

No, there should be no setting which affects it. It might help if you add all your code to the question though (if possible). There could be other issues like masking or initialisation order.

well the code is really long to be posted here... I will give a link to my repo at github. https://github.com/ArunMKumar/IIEC/blob/Active/Project.cpp   In this file if you search for addr_t childAddr you can get to the part i am talking about, currently it is declared in function scope, it was dclared at line45. also i appreciate your efforts in helping me solve this.

@ArunKumar It looks like initialisation order could be the problem, although I can't tell just from that code. Basically, the code that's trying to use the global array might be executing before the global array has actually been setup. It can happen if you run code in the constructor of an object that is instantiated globally or statically. A possible solution is to create your objects on the heap during setup() (i.e. using the new keyword), but I don't know if that would break something else in your code/libraries.

You should try to post a minimal piece of code that reproduces your problem. From what you posted I assembled this:
typedef unsigned char addr_t;

#define NUM_CHILDS  0x02
#define CHILD1_I2C_ADDR         0x10
#define CHILD2_I2C_ADDR         0x02

addr_t childAddr[NUM_CHILDS] = { CHILD1_I2C_ADDR, CHILD2_I2C_ADDR };

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();
  Serial.println(childAddr[0]);
  Serial.println(childAddr[1]);
  }  // end of setup

void loop ()
  {
  }  // end of loop

Output is:
16
2

Clearly the problem isn't where you think it is.

By the way, in your file Project.h you have this:
#include "Project.h"

Why is it including itself?

void commRxISR(int count){
    /*
        ISR for the dats received on the I2C bus
    */
    Serial.write("Inside serial receive ISR\n");
    while (1);
    while (0 < Wire.available()){
        MyNode.commChild.commWriteInBuffer(Wire.read());    // Project specific implementation
    }
}

The infinite loop in the ISR is interesting. Also don't do Serial prints inside an ISR. They can (almost certainly will) hang the system.