Problems with ACS758 Hall Effect Current Sensors - Calibration and no Signal

I contacted Allegro they were really helpful which was pleasantly surprising.

The 200A has almost certainly failed. The 2.48v is within tolerance and the 2.33v is probably out.

I've been able to better understand the datasheet sections on 0A calibration. "VIOUT(Q) may drift over the lifetime of the device by as much as ±25 mV." and there is an electrical offset voltage noted. @25C it's +/-5mv. It's +/-20mv between 0c and 50c. So still only 45mv. Even allowing for noise it's only 55mv.

About 2.445V at zero amps would be the limit.


I have run into similar frustrations using standard libraries and I2C.  I would have to look into the code and try it out on my own before confirming anything about this particular code; however, in the meantime you might want to try a tool such as I2cScanner that simply scans the I2C bus for all possible addresses and reports addresses that are "alive".  This (or something similar as I am not sure if you are using Arduino API) might be a good start to just see if the I2C is working and that you have the correct address.


Did you forget to load the counter and clear flags in USISR?


I'm trying to make a program which you choose an angle

You have written

rad = angulo*0,0174533;

But, C++ uses the american decimal notation:

rad = angulo*0.0174533;

Thus, you have been multiplying angulo by zero every time.


It is likely 2 features are desired for this project:

A way to enter WIFI credentials after the program is running.
A way to store the WIFI credentials between power cycles.

The solution for the 2nd requirement is to use non volatile memory. Both problems have been solved before for certain types of Arduinos.  Here is a project on GitHub which has solutions for boards using the ESP8266 or ESP32 processors.


After burning bootloader, Windows 10 doesn't recognize the USB device

You need a number of things to be true before the (new) bootloader will work:

The hardware needs to be wired correctly
You have used an appropriate crystal as the clock
You have installed the correct bootloader (ie. one for the Atmega32U4)
The fuses are set to boot into the bootloader
The fuses are set for the correct bootloader size
The fuses are set correctly for the clock type and the clock speed (for example, don't have the "divide clock by 8" bit set)

I have a sketch that analyses your chip signature and fuses which will also report on what bootloader it detected (assuming it is one from a recognized list). You could run that and amend your question to post the resulting display from the serial monitor.

I also have a sketch that programs a bootloader for various chips including the Atmega32U4. This sketch also sets the appropriate fuses.


ArduinoJSON: Using a reference to a reference when parsing array of arrays

The advantage of reference above pointers:

References cannot be NULL, so it's much safer to use them
Address of a reference cannot be acquired, this means a calling function cannot mess up anything outside the type (value) being passed.

For passing a reference to an address the same advantages applies (cannot be NULL, address cannot be changed).

Also, address arithmetic (address + xxx or address - xxx) cannot be used, which prevents tricky programming errors where values outside a variable's memory space can be changed.


How to receive more than 64 bytes on Arduino?

But Arduino has a serial buffer of 64 bytes only. Because of this limitation I am unable to receive further bytes.

This assertion is nonsense. Certainly there is a buffer, but that lets you receive up to 64 bytes (put there by the serial interrupt service routine) before you retrieve a single one.

All you need to do is expeditiously retrieve the data (that is, do a Serial.read()) fast enough that you remove the data from the buffer and store it into memory.

You need to post a Minimal, Complete, and Verifiable Example (MCVE) that demonstrates your problem. For example, are you doing delay(1000) before attempting to read serial data?

See my post about receiving serial data without blocking and also Async (Serial) peripheral interface - for Arduino .


how about this ?
// Read the analog inputs
for (int i = 0; i < length; i++)
{
    analogRead(analog_pins[address + i]); // for pre read

    // Write the state of the analog pin to the response buffer.
    slave.writeRegisterToBuffer(i, analogRead(analog_pins[address + i]));
}


How to know my Arduino core version and its location on my Ubuntu laptop?

The ancient version installed by apt lives in
/usr/share/arduino/hardware/arduino/cores/arduino.

If you download and unpack a recent version, it will stay wherever you
left it. For example, I have an Arduino core in
/home/edgar/Downloads/arduino-1.8.10/hardware/arduino/avr/cores/arduino.
The installation script doesn't really install those files. It does
install some icons and desktop shortcuts, but neither the core nor the
Arduino IDE. Instead, it assumes the downloaded package will stay
wherever it was when you ran the script.

If you want a somewhat cleaner installation, I suggest you move the
package to /opt, recursively chown it to root, and run the setup script
there. The core will then be in
/opt/arduino-<version>/hardware/arduino/avr/cores/arduino.


It all depends on how you are powering the board.
If you're running it from USB then the computer should shut off the power to the USB port. If it doesn't then the Arduino has a small self-resetting fuse on the USB power which should shut the power off for you.
However if you're powering through the barrel jack there's no protection. Worst case scenario: it will blow the voltage regulator, which then "fails short", meaning it passes the whole of the input voltage through to the microcontroller, which then kills it.
So yes, it's possible to damage the Arduino with a short circuit.
Most multimeters have a better way of testing the board though: either the "beepy" continuity test, or the resistance mode.  You can use that to test the continuity or resistance between your 5V and GND pins without having to connect the shield to the Arduino at all. 100% safe.


Try using this shield from Adafruit. I believe it can record and play audio, and they have versions with and without amps.

I do not know about near-simultaneous playback, so read up a bit before buying.


Blew my Arduino. Did I wire this correctly?

It would be best if everything ran at the same voltage. (And it is necessary that everything uses the same ground.)  Which is possible as there are 5V Arduino boards.  Interestingly, the Arduino nano, according to this schematic, runs at 5V.

In order to use the Arduino Nano at 5V, instead of using VIN / Pin 1, you should be able to skip the Arduino's 5V regulator and use +5V / Pin 4.  But this must be a regulated 5V power source.

Now, why are you having problems controlling the servo?

It is difficult to tell, but your boost switching power supply negative input may not be directly connected to the negative output.  With out a common ground, it may be difficult to create the proper signal to control the servo.

To be specific, if the ground or negative side of the servo power supply is not at the same potential as the ground or negative side of the Arduino power supply, controlling the servo may be difficult at best and at worst you could burn something out on the servo or Arduino.

To check, measure with a volt meter to see if there is any difference between the boost switcher negative input and negative output.

To solve this problem consider using a USB power supply plugged into the Arduino Nano and powering the servo off the 5V at pin 4 of the Nano.  Or, keep using your 6V battery and 6V to 9V boost switching power supply.  Connect this as you are to VIN Pin 1.  The Arduino Nano's 5V power regulator should kick in and provide 5V at pin 4.


Upload s sketch to a 5v Pro-Micro board as 3.3V by mistake

Holding RST and GND pins after re-connecting USB, showed it on port menu.
needed another such holding, prior to upload.
All good now.


Yes. Perfectly possible.

How accurate do you need the "hourly"? If you want any form of accuracy at all you will really want to use an RTC module to provide the real time.

Otherwise that, and the higher speed 3s updates, can be timed using the millis() function.  The BlinkWithoutDelay example in the IDE shows you the basic idea of working with timestamps to examine elapsed time.

Also there are simple libraries that could help you, such as SimpleTimer.


Can I use notepad++ for writing sketches?

You can easily use notepad++ or any text editor to edit arduino code files (.pde or .ino). I use the sublime text editor for all my arduino coding.

As you noted, the arduino syntax is c++, so setting the syntax highlighting mode to c++ is all that you need to do; no mod should be necessary.

Arduino includes a "Use external editor" option in the preferences menu that will make it reload the file every time you compile or upload. It also disables editing in the editor window. In this mode, just save your file in any editor, change to the arduino window, and hit upload.

Since 1.5, arduino has had command line support. most editors allow making the "build" button execute arbitrary commands in the current directory. by setting build to run "arduino --verify" or "arduino --upload" you can code in any editor you want even without having an arduino window open.


Where is the definition of system_adc_read() in the esp8266 Arduino code?

The "definition" of uint16 system_adc_read(void) is inside the compiled archive/object file libmain.a inside one of the NONOSDK folders which is located in /tools/sdk/lib/ . The version is selected in platform.txt. For example in my platform.txt:

# default SDK for all boards
# (generic board overrides this variable)
build.sdk=NONOSDK22x_190703
#build.sdk=NONOSDK22x_191024
#build.sdk=NONOSDK22x_191105

Running the xtensa-lx106-elf-objdump.exe -d on this file I can find this section inside:

00000258 <system_adc_read>:
     258:   020c                    movi.n  a2, 0
     25a:   f0c112                  addi    a1, a1, -16
     25d:   0109                    s32i.n  a0, a1, 0
     25f:   fffc01                  l32r    a0, 250 <system_pp_recycle_rx_pkt+0x18>
     262:   0000c0                  callx0  a0
     265:   fff901                  l32r    a0, 24c <system_pp_recycle_rx_pkt+0x14>
     268:   f42020                  extui   a2, a2, 0, 16
     26b:   1b1207                  beq a2, a0, 28a <system_adc_read+0x32>
     26e:   b30c                    movi.n  a3, 11
     270:   902220                  addx2   a2, a2, a2
     273:   1122e0                  slli    a2, a2, 2
     276:   fff701                  l32r    a0, 254 <system_pp_recycle_rx_pkt+0x1c>
     279:   0000c0                  callx0  a0
     27c:   f42020                  extui   a2, a2, 0, 16
     27f:   00a402                  movi    a0, 0x400
     282:   013027                  bltu    a0, a2, 287 <system_adc_read+0x2f>
     285:   020d                    mov.n   a0, a2
     287:   f42000                  extui   a2, a0, 0, 16
     28a:   0108                    l32i.n  a0, a1, 0
     28c:   10c112                  addi    a1, a1, 16
     28f:   f00d                    ret.n
     291:   00                          .byte 00
     292:   00                          .byte 00
     293:   00                          .byte 00
     294:   ff ff 00 00
    ...

000002a0 <system_adc_read_fast>:
     2a0:   e0c112                  addi    a1, a1, -32
     2a3:   11c9                    s32i.n  a12, a1, 4
     2a5:   21d9                    s32i.n  a13, a1, 8
     2a7:   31e9                    s32i.n  a14, a1, 12
     2a9:   5129                    s32i.n  a2, a1, 20
     2ab:   41f9                    s32i.n  a15, a1, 16
     2ad:   0109                    s32i.n  a0, a1, 0
     2af:   03fd                    mov.n   a15, a3
     2b1:   fff901                  l32r    a0, 298 <system_adc_read+0x40>
     2b4:   0000c0                  callx0  a0
     2b7:   4fbc                    beqz.n  a15, 2ef <system_adc_read_fast+0x4f>
     2b9:   fff6e1                  l32r    a14, 294 <system_adc_read+0x3c>
     2bc:   0c0c                    movi.n  a12, 0
     2be:   51d8                    l32i.n  a13, a1, 20
     2c0:   90dcd0                  addx2   a13, a12, a13
     2c3:   001d32                  l16ui   a3, a13, 0
     2c6:   1a13e7                  beq a3, a14, 2e4 <system_adc_read_fast+0x44>
     2c9:   902330                  addx2   a2, a3, a3
     2cc:   1122e0                  slli    a2, a2, 2
     2cf:   b30c                    movi.n  a3, 11
     2d1:   fff201                  l32r    a0, 29c <system_adc_read+0x44>
     2d4:   0000c0                  callx0  a0
     2d7:   f44020                  extui   a4, a2, 0, 16
     2da:   00a402                  movi    a0, 0x400
     2dd:   003d                    mov.n   a3, a0
     2df:   013047                  bltu    a0, a4, 2e4 <system_adc_read_fast+0x44>
     2e2:   043d                    mov.n   a3, a4
     2e4:   005d32                  s16i    a3, a13, 0
     2e7:   cc1b                    addi.n  a12, a12, 1
     2e9:   f4c0c0                  extui   a12, a12, 0, 16
     2ec:   ce9fc7                  bne a15, a12, 2be <system_adc_read_fast+0x1e>
     2ef:   11c8                    l32i.n  a12, a1, 4
     2f1:   21d8                    l32i.n  a13, a1, 8
     2f3:   31e8                    l32i.n  a14, a1, 12
     2f5:   41f8                    l32i.n  a15, a1, 16
     2f7:   0108                    l32i.n  a0, a1, 0
     2f9:   20c112                  addi    a1, a1, 32
     2fc:   f00d                    ret.n
     2fe:   00                          .byte 00
     2ff:   00                          .byte 00
     300:   ff ff 00 00
    ...


You pretty much need a helper function to do that; a small local function that calls strip.Color() with the intended arguments and returns strip.Color()'s return value if there is any.

int first_color(void)
{
   return(strip.Color(0, 60, 0, 0));
}

(assuming strip.Color() returns an int) which you would call with:

value = first_color();

If strip.Color() is a void function, then delete the 'return(' and one ')', fix the definition of first color to be void instead of int, and of course, don't try to use any return value from first_color().


I would do it as a simple state without the blocking while
define two bools

bool buttonPress = false;
bool inMenu = false;

and add it to the loop.To differentiate between different press lengths you need to define them. There is nothing like an "automatic" short press recognition. Also use variables which are "speaking" making it easier to read code for others.

const unsigned long buttonPressLong = 2000;  // 2 seconds
const unsigned long buttonPressShort = 250;  // 0.25 secondis feasable
const unsigned long buttonPressDebounce = 50;
// debouncing for too short presse Thanks Edgar Bonet
unsigned long buttonPressStart = 0;

The program below does what you want (tested on my uno test lab). As Edgar Bonet commented before you should also debounce the button (look it up in WiKi) to exclude unwanted effects The times I use are practical on my hardware, so you could play around by looking at the serial monitor.

const int btn = 2;
const int ledPin =  13;
int selector = 0;
const unsigned long buttonPressLong = 2000;  // 2 seconds
const unsigned long buttonPressShort = 250;  // 0.25 secondis feasable
const unsigned long buttonPressDebounce = 50;  // debouncing for too short presse Thanks Edgar Bonet
unsigned long buttonPressStart = 0;

bool buttonPress = false;
bool inMenu = false;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(btn, INPUT);
  }

void loop() {
  if (digitalRead(btn) == LOW && !buttonPress ) {
    buttonPressStart = millis();
    buttonPress = true;
  }
  // The routine is only triggered if a previous pressing took place, otherwise it's ignored
  else if (digitalRead(btn) == HIGH && buttonPress) {
    if (millis() - buttonPressStart > buttonPressLong && millis() - buttonPressStart > buttonPressDebounce && inMenu) {
      Serial.print("Long press: ");
      Serial.println(millis() - buttonPressStart);
      buttonPress = false;
      inMenu = false;
    }
    if (millis() - buttonPressStart < buttonPressShort && millis() - buttonPressStart > buttonPressDebounce && !inMenu) {
      Serial.print("First short press ");
      inMenu = true;
    }
    if (millis() - buttonPressStart < buttonPressShort && millis() - buttonPressStart > buttonPressDebounce && inMenu) {
      Serial.print("Short press: ");
      Serial.println(millis() - buttonPressStart);
      doSwitchStatement();
      selector++;
      if (selector > 6) {
        selector = 0;
        delay(500);
      }
      buttonPress = false;
    }
  }
  // Here you could do other stuff as it is non blocking
}
doSwitchStatement(){...}// Stays the same as yours

Look at the code used as it is non blocking (of course there is room for improvement) but as a starter for your further experiments ...


How can an Arduino output a specific (i.e. 56 kHz) carrier frequency?

It is indeed possible to generate a 56 kHz signal with an Arduino timer.

A timer actually can be seen as a special register, in the MCU, that holds a value (starting at 0) that gets incremented at a frequency that is the MCU clock frequency (16 MHz on Arduino Uno), possibility divided by a factor called prescaler. When that value reaches a limit, called Compare Match, that you specify, then two things happen:

The timer register value is reset to 0.
One ISR (interrupt service routine) callback function gets called (you can define it to point to your own code).

The idea is to use that ISR to change the output of a logical pin every time it is called (HIGH, then LOW, then HIGH...).

Now, in order to generate a 56 kHz square wave, you'll need your ISR to be called 56000 * 2 times per second (* 2 because you need to change the output value twice per period).

You can choose the prescaler value you want for a timer among the following list:

1 (clock frequency is not divided, hence 16 MHz)
8 (clock frequency is divided by 8, hence 2 MHz)
64
256
1024

There are two sizes of timers/counters on Arduino Uno (they are called timer/counter actually): 8 bits and 16 bits.

On Arduino Uno (ATmega328P), you have three timers overall, but some may be used by the Arduino core library or other libraries used in your sketches (you'll have to check that by yourself):

timer0 (8-bit)
timer1 (16-bit)
timer2 (8-bit): this one has more prescaling options (1, 8, 32, 64, 128, 256, and 1024)

Now you need to generate a 56 kHz wave from 16 MHz, hence, without prescaling, you would need to count to:

16000000 / (56000 * 2) - 1 = 141.857 (- 1 because a timer counts from 0 to this value and resets only after it has been reached)

From this calculation, we can draw two observations:

141.857 is not an integer and thus you won't be able to generate a wave of exactly 56 kHz.
Without prescaling, you need a 16-bit timer as 285 is not representable as an 8-bit unsigned integer.

From now you have two options:

Use a 16-bit timer (timer1), use prescaler = 1, and select 142 as the Compare Match; that will give you the following frequency: 16000000 / (2 * (142 + 1)) = 55944 Hz
Use an 8-bit timer (timer0), use prescaler = 8, and select 17 as the Compare Match; that will give less precision with the following frequency: 16000000 / (8 * 2 * (17 + 1)) = 55555 Hz which is still within the required range.

Now, regarding how to write your sketch for that, I advise you to check out this instructable which is very complete and very interesting to read.

Of course, the ATmega328P complete datasheet is also important if you want to understand, in the slightest details, what you are doing.

Some important notes:

An ISR is executed with disabled interrupts and must thus be as short as possible. In particular, there are several functions from the Arduino library that shall not be called from an ISR.
Arduino Uno clock is not very accurate (it uses a ceramic resonator instead of a quartz, which would have been much more accurate), so this means the output frequency will shift further.


Serial comms failure after long time - can't open COM port

The assumption I am making is "VISA connection" is a PC operating VISA.
I have seen ports shut down on windows several times yet the same port works fine while in DOS.  My suggestion is try a different computer, that should narrow down your problem to which side of the connector is failing.


What's the difference between a clone and a counterfeit Arduino?

The difference is simple:

Clones don't say "Arduino," where counterfeits do

If I were to create 200 boards all labeled "Arduino UNO R3," it would be a counterfeit. If I were to call them "Happyduino," it would be a clone.

Note: You can still write Happyduino (Arduino Compatible) on your product. Here's a quote from the Arduino FAQ section

  Not okay:

  Arduino Xxxxxx
  Xxxxxx Arduino
  Arduino Compatible Xxxxxx - use "Xxxxxx (Arduino-Compatible)" instead

  Okay:

  Xxxxxx for Arduino - products that work with official Arduino boards    (e.g. shields or kits)
  Xxxxxx (Arduino-Compatible) - variations and clones which are    software and hardware compatible

  Note that while we don't attempt to restrict uses of the "duino"
  suffix, its use causes the Italians on the team to cringe (apparently
  it sounds terrible); you might want to avoid it. (It's also
  trademarked by a Hungarian company.)


ATTiny85 I2C connection with Arduino Nano

Problem solved!

I've modified the code, this is the final one:

#include <TinyWire.h>

#define led_pin 1
#define I2C_SLAVE_ADDR  0x11

void setup() {
    // config led_pin as Output for driving an LED
    pinMode(led_pin, OUTPUT);

    // config TinyWire library for I2C slave functionality
    TinyWire.begin( I2C_SLAVE_ADDR );
    // sets callback for the event of a slave receive
    TinyWire.onReceive( onI2CReceive );
}

void loop() {

}

/*
I2C Slave Receive Callback:
Note that this function is called from an interrupt routine and shouldn't take long to execute
*/
void onI2CReceive(int howMany){
    // loops, until all received bytes are read
    while(TinyWire.available()>0){
        // toggles the led everytime, when an 'a' is received
        if(TinyWire.read()=='a') digitalWrite(led_pin, !digitalRead(led_pin));
    }
}

Like this the I2C scanner sees the board at the address 0x11.

The wirings are the following:

Arduino pin SCL to ATTiny85 pin SCL (P2)
Arduino pin SDA to ATTiny85 pinSDA  (P0)
Take care of wire to the same ground both the boards.


Undefined reference in Eclipse of .h and .cpp files

Have you tried placing the H file in the same folder as you main cpp file.  This should prove beyond all doubt that there is nothing wrong with the code (I can't see anything wrong).

I suspect its a path issue.  You need to check that Eclipse is setup up properly to source the libraries from you custom location.  Also it needs to be passing this location on to the compiler.  I don't know how to do that in Eclipse but Google should point you in the right direction. Try this http://forum.arduino.cc/index.php?topic=39972.0 ?

Also you might find it easier to specify the include files in the order system, 3rd party libraries, local libraries and then local include files.  This means that duplicate definition faults are reported against the files nearest to the ones you have written.  If you define time_t using your ordering the fault will be reported against  rather than your header file.

Also a using namespace foo statement removes the benefits that namespaces provide, so its best not to do it.

EDIT
Doh - I should have spotted this sooner.  Template classes have to have the functions inline not in a CPP file.  This is because the CPP file can't change what T is at compile time, but because the H file is included in the file it is used in when it is preprocessed the object represented by T can change.
Basically inline your functions and it will work.


How to handle concurrent HTTP request when using interrupt

Simple: don't do HTTP requests in the interrupt.

It's usually bad to do anything heavy like that in an interrupt.  Instead you should just set a flag in the interrupt (volatile bool) and examine that flag in loop().

volatile bool sendNotification = false;
volatile int notifyVal = 0;

void loop() {
    if (sendNotification) {
        notify(notifyVal);
        sendNotification = false;
    }
}

void handleInterrupt() {
    if ((long)(micros() - last_micros) >= debouncing_time * 1000) {
        notifyVal = digitalRead(interruptPin);
        sendNotification = true;
    }
    last_micros = micros();
}


Distributing power evenly to multiple pins

Yes, of course it is possible.  But if all you need to do it to turn these heat pads on and off, an Arduino is perhaps not the most suitable technology.

But presuming these heat pads are a component of some more complex system that responds to other inputs or outputs to/from the Arduino, you will need a few more components.  You need to accomplish two things that the UNO R3 cannot accomplish by itself, because your heat pads are very much too large a load for your UNO to power directly.  (The power for a single LED bulb is about the most that you can draw from an output pin.)

You need to reduce your 20-V external power source down to something less than 12 volts to supply your heating pads.
You need to switch on and off up to 1 amp of current to flow to each of the three heating pads.  The UNO cannot do this directly.

There are a lot of ways to reduce your 20-volt supply down to less than 12 volts.  Some are much more efficient than others.  Probably the lowest cost efficient way is to use your 20-V source as the input a small DC to DC voltage down stepping converter.  These are available online from Chinese vendors for very low cost.  Just search for "DC-DC converter down".  A quick search finds one rated at 20 amps, with adjustable voltage output can be purchased for less than $10.  These are pretty efficient devices that don't waste the power that a simple voltage dropping resistor would waste.

Then you need either one or three 5-volt relays of some type to switch the power on to the heat pads.  The UNO pins output of 5-volts would not provide current to heat pads, put only enough current to energize the relay(s).  The relay(s) can be either solid state, or coil energized.  Just be sure the relay "contacts" are rated to handle well more than 1 amp if there are three of them, and more than 3-amps if only one.   An Arduino relay shield with four relays, each rated for 10 amps, can be purchased for less than $5.

If you only every want all three heat pads energized at the same time, you only need one relay, and one Arduino output to energize it.

The very simplest solution, if you only want all the pads heating simultaneously, would be to wire the three heat pads in series.  Then you could apply your 20-volts directly across all three heat pads, and you would not need any device to reduce your supply voltage.  Each heat pad would have 1/3 of 20 volts across it, which is well under their 12 volt tolerance.  And you would only need one relay.


It is a timer conflict.

The Servo reference says: "...use of the library disables analogWrite() (PWM) functionality on pins 9 and 10..."

This is a picture of the pinmapping of the Arduino Uno: PighiXXX - Uno.
Pin 9 en 10 uses OC1A en OC1B for PWM, that is Timer1. You can't use PWM on them when the Servo is used.
Pin 11 uses OC2A for PWM, which is Timer2.

I suppose it will work if you choose another PWM pin for analogWrite. Timer0 is used for millis and therefor the PWM frequency will be different (pin 5 and 6). That is mentioned in the analogWrite reference. In most cases that is not a problem.
Pin 3 is a normal PWM pin.

This is a common problem. The documentation is not always clear about the use of timers and other parts of the microcontroller. Many times the source code has to be read to see what is used. In the end, you need more experienced Arduino users to spot the conflict.


Arduino restarts when a function is called

Your code is very complex and running it in an environment where you have limited debug facilities is making life worse for yourself.

When an Arduino reboots it is usually because it has thrown a memory error.  This happens when you try and access memory that is no longer your program's to access (or never was yours).  In this case I originally suspected, based on the complexity of your code, that you were accessing a vector element that you could no longer access.

To prove this I 'ran it on a desktop', in my case a Windows 7 box with Visual Studio 2015 (but you could have used Linux, GCC and GDB).  This meant I wrote a little wrapper program and stubbed the functions you called.  This resulted in the error message shown below.

This is my 'desktop' code:

#include <vector>

std::vector<std::vector<std::vector<float>>> test_split(const int& i, const float& f, std::vector< std::vector< float > >& dataset)
{
    std::vector<std::vector<std::vector<float>>> vals;
    return vals;
}

float gini_index(const std::vector<int>& class_values, const std::vector<std::vector<std::vector<float>>>& group)
{
    return 1.0f;
}

std::vector<std::vector<std::vector<std::vector<float>>>> get_split(std::vector< std::vector< float > >& dataset) {
    std::vector<int> class_values; // declares vector 'class_values'
    for (int i = 0; i < dataset.size(); i++) { // loops through each value in dataset (the dataset contains vectors)  and appends the last value in each vector to class_values
        class_values.push_back(dataset[i][dataset.size()]);
    }
    std::vector<std::vector<std::vector<float>>> b_index;
    b_index.push_back(std::vector<std::vector<float>>(999));
    std::vector<std::vector<std::vector<float>>> b_value;
    b_value.push_back(std::vector<std::vector<float>>(999));
    std::vector<std::vector<std::vector<float>>> b_score;
    b_score.push_back(std::vector<std::vector<float>>(999));
    std::vector<std::vector<std::vector<float>>> b_groups;
    for (int i = 0; i < dataset[0].size(); i++) {
        for (int j = 0; j < dataset.size(); j++) {
            std::vector<std::vector<std::vector<float>>> groups = test_split(i, dataset[j][i], dataset); // gets the split of the dataset (assigns each vector in the dataset to either 'left' or 'right')
            float gini = gini_index(class_values, groups); // calculates the gini
            if (gini < b_score[0][0][0]) {
                b_index[0][0][0] = i;
                b_value[0][0][0] = dataset[j][i];
                b_score[0][0][0] = gini;
                b_groups = groups;
            }
        }
    }
    std::vector<std::vector<std::vector<std::vector<float>>>> vals;
    vals.push_back(b_index);
    vals.push_back(b_value);
    vals.push_back(b_groups);
    return vals; // returns the values.
}

int main(void)
{
    std::vector<std::vector<float>> dataset;

    std::vector<std::vector<std::vector<std::vector<float>>>> result = get_split(dataset);

    return fgetc(stdin);
}

Now you need to workout where it is crashing, easy in Visual Studio but very difficult on an Arduino.  However I would look at simplifying the code too.


How to avoid electromagnetic interference on ESP32 input

I have to check better, but it seems that other have this issue with reed switches that in some configuration act like antennas and receive interferences (see here and here).


What are the basics in writing a program in Arduino?

There are some excellent books available as well as videos and articles on the Internet which will walk you through basic projects.  The most common method of programming is to use the free Arduino IDE which will talk to the board from your Mac or PC.  You can run the board straight from the USB port's power, or from an external source if you need it to be portable.

The programming language is very similar to C.  The program structure is basically a setup portion and then a continuous main loop that runs until the board is powered off.

If you want to experiment without actually purchasing one, there are some emulators available which will let you build entire project on a virtual breadboard before buying any actual components.  Fritzing is a great board planner that you can install, or if you would rather, you can use 123D Circuits from your web browser which will let you edit and simulated the circuits.

Basic knowledge of electrical circuits will be helpful for getting started, and is a great asset when designing larger projects.


It is a "hardware bug" as you so aptly put it. As far as I know, the only way to get the CC3000 board to use pin 2 as the IRQ is to physically rewire the connections. I did exactly that on my board and it works without a problem, leaving pin 3 free to use for whatever else you want. You can see what I did here.
It basically involves cutting the trace wire and running a jumper cable between the holes next to the pins.

The important thing to understand perhaps is that pins 2 and 3 are available to use for IRQ on the Mega and Uno, but it is an actual dedicated pin on the CC3000, hence why you have to go to this effort to change it. Also remember that once you have cut the trace to pin 3 it becomes an open/free pin and is no longer connected to the wifi shield. By the sounds of your requirements this shouldn't matter, but it is still useful to know.

If you haven't already, I recommend that you read the documentation for the CC3000 board, as it really helped me understand the irritating intricacies.

But yeah, if you choose to follow this and reroute the pin, it works perfectly. Hope this helps, even if it is a bit late.


How do I remotely acquire data from Arduino based portable device?

I can't guarantee anywhere in your city, but this hack will work pretty much wherever there is cell coverage for the carrier you choose.

You'll want the GSM shield.

Picture from Arduino

Anyway, it uses pins 2, 3, and 7 on it. It also has the ability to solder (on the bottom of it) a microphone and speaker connection. You'll need to buy a SIM card and a contract to connect your shield to a network. I don't know how often you would use this, but I've seen a pay-as-you-go plan that charges you $2 for unlimited talk/text/internet per day. If you're going to use this once a month, that would be the way to go. I didn't look to see if they supported the GSM shield (it was on TMobile's site). You would want to contact them for more details. Also, depending on where you live, I don't know if you would get good coverage. This goes with any cell phone provider, but make sure that you get coverage where you want to go (and don't always trust the maps they provide).


This board doesn't use as USB adapter an ATMega16u2 with Arduino firmware. It uses a simple USB chip CH340. So you can't put it in DFU mode to upload a firmware.


It won't do any harm to try it at 18V for a while. Most voltage regulators have thermal protection and just cut out if they get a little too hot. If it works reliably, stay with it.

EDIT: Their Uno page warns against overheating the board, so I would test it for a short while and make sure there is no overheating or strong "plastic" smell coming from the board. If there's enough heat to worry, then it's best not to run like that for extended periods.

If 18V is too high, you could get a power resistor (I'd guess say a 10 watt resistor around 24 ohms) to waste approximately half an amp from the power supply. Connect this to the supply, in parallel with the Arduino.  It's wasteful (unless your room needs heating anyway) but will lower the voltage (that reaches the Arduino) a little.


Using RTC DS3231 + Arduino UNO to calculate time lapsed

One idea would be to use force/pressure sensor on chair. You have to find what the sensor outputs when an average person sits on it and calibrate the values accordingly in code. Finally you have to a set threshold value for it. Now if somebody sits on it and if that threshold is exceeded, it means somebody sat on it. So you can now trigger your rtc module or maybe you can use special peripherals called timers , which are inside arduino itself. Both can be used to keep track of time. Tutorials are available for both timers, and ds3231- arduino interfacing. You can easily code. Good luck :-)


I'm kind of confused by your question. You ask where you want to put once-per-startup setup functions, and then discuss the setup function. That's what the setup function is for.

As such, one-time setup functionality goes in the setup function.

FWIW, if you look in the file that calls the setup and loop functions:

#include <Arduino.h>

int main(void)
{
    init();

#if defined(USBCON)
    USBDevice.attach();
#endif

    setup();
    for (;;) {
        loop();
        if (serialEventRun) serialEventRun();
    }
    return 0;
}

For all intents and purposes, the two options are completely identical. Either way, you get a empty busy-wait loop. Frankly, I'd expect the two different options to probably emit the same machine code anyways, so the whole thing is a non-issue.

Note:
if (serialEventRun) serialEventRun(); appears to be a facility to allow you to attach a function that is called upon reception of serial data, but if you do not define a function void serialEvent(){} in your code, it will compile out completely and not be present in the produced machine code.


Arduino uno board not detected when connected via USB no matter what OS

If the port selector in the IDE is greyed out, and the OS is throwing an error, it's likely the Board is damaged. Either The firmware on the serial device or the chip is fried somehow. What's happening is that the usb part is failing, so the Com port part never works.


Lowest voltage applicable on AREF pin on Uno and Mega

According to the datasheet (page 375) the minimum voltage you are allowed to have as a reference voltage for the ADC is 1V.


If you want a variable to be 'yes' and 'no' or perhaps '0' and '1', then you can use a boolean which is 'true' or 'false'. With a boolean you can use logic operators:

boolean dataReady = false;
dataReady = !dataReady;
if( dataReady) ...

A boolean on a 8-bit AVR chip (Arduino Uno,Leonardo,Nano,Mega) is 8 bit. You could also use a byte and make it 0 or 1.

A 8-bit variable is often used when a interrupt routine sets a flag. By making that flag only 8 bit and volatile, it can be used in the loop function as well without the need to disable the interrupts. Reading and writing a 8 bit variable can not be interrupted by an interrupt routine.

Using 8 bits when only 1 bit is needed is normal. You don't have to worry about that.

When you need hundreds of 1 bit variables, then it is possible to select each bit with macro's or a lot #define to select each bit. This is almost never used in normal code, but almost always used for the registers of a sensor.
And last but not least: a struct with bit fields packs the bits. That can be handy sometimes.


I use voltage dividers a lot and have seen this before.

In each and every case where ALL my readings are high, yet they vary predictably (like on my solar panels - they go up during day and down at night), there has always been proven to be a very simple, single cause.

Resistance in the ground lead.

Such as if it is plugged into a breadboard hole that is not holding it well, or if I have extended it and have connections along the way.

So that would be the first thing I would look for.

Having said that, if the readings are very high and do NOT vary predictably, then I would look for a disconnected ground lead.

If all the connections are good but it still misbehaves then I would swap it out with another one to make sure the part itself isn't the problem.


Due to the lack of USB-Support of the ATtiny85 you will be forced to use something like V-USB as the tutorial does. This might have implications when you are targeting a commercial product.

Personally I'd suggest using the ATmega32u4. It has USB build right in.

But basically I don't see any reasons why it should not work.


Can I replace Atmega8 with Atmega328 in my freeduino board?

Shouldn't be a problem. Some later versions already have a ATMega168 instead of the ATMega8. All three are pin-compatible.

In the arduino IDE you should however select a different board (one with a 328, like the UNO). That way the compiler knows the target MCU is the 328, and not the 8.


Reading a car mass air flow, volumetric air flow meter

There's no reason that an MAF couldn't be used with an Arduino.  It's likely that the sensor will run on 12v and output an analog voltage from 0 - 12, so you might need to use a voltage divider with the Arduino.

See this Sparkfun article on implementing a voltage divider to scale down the 0-12 volt signal to 0-5v for the Arduino.


Capacitor ratings don't really matter in your case, as you are using only 5 volt. Only their values (F) do.

Though the crystal you selected has an indication it needs 20pF load capacitors, not 22pF. 22pF is probably still fine. (Also note the ±20% accuracy, so between 17.6 and 26.4pF)

The IRF9531 and IRF9540N have the same pinout. They are also pretty similar in specs. The IRF9540N is slightly better even.

Note that the ATMega328p doesn't have the bootloader pre-installed. It's not that hard to do yourself though.

The EEPROM you selected is an SMD version. Kind of hard to work with if you are still a beginner. Better use a DIP version instead (that one is a bit more expensive, but 4 times the size)

I'd suggest you add an USB to Serials Adapter to the list, so you don't need the Arduino Uno every time you want to reprogram it, and use the Uno for something more useful.


Is there a way to use functions defined in a library in any class?

Yes, there is a way.

However that's not how object oriented programming (OOP) is supposed to be used, at least in theory.

Most likely you won't like my advice, but here it is: take it easy, find a good book or online course and learn to program on a system that is simpler to debug, than a microcontroller.

Your PC, for example.

C is closer to the HW than java. C++ can be seen as both of them, but there is not so much you can do without learning C, properly.
From that perspective, C++ can be seen also as a superset of C, only much more complex.

Have a look at this explanation, for example.
It's quite simple, but exhaustive. Read it carefully and you will find out that pointers are not so difficult to grasp, after all.

If you spend enough time to get the basics right, it will save you lots of frustration (and, yes, time!) later on.

For a more systematic approach, try this.


How do I "conditionally" include libraries and declare global objects of them?

const bool useLCD = true;

should be:

#define useLCD 1

Here is a complete working example of how to use preprocessor macros for conditional compilation:

#define USE_A 1
// #define USE_B 1

#if (USE_A)
int a = 4;
#endif

#if (USE_B)
int b = 6;
#endif

void setup() {
    Serial.begin(115200);
    Serial.print(F("The result is: "));
#if (USE_A)
    Serial.println(a * 2);
#endif
#if (USE_B)
    Serial.println(b * 2);
#endif
}

void loop() {
}


http://altlab.org/d/m/jpralves/recover_atmega2560/

Change fuses/firmware depending on which side you are flashing (M2560/M16U2)

Firmwares: Arduino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-Rev3.hex / stk500boot_v2_mega2560.hex

1st command:

avrdude -C avrdude.conf -P usb -p m16U2 -b 57600 -c usbtiny -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:m

2nd command:

avrdude -c usbtiny -p m16U2 -P usb -b 115200 -V -U flash:w:Arduino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-Rev3.hex

3rd command:

avrdude -c usbtiny -p m16U2 -P usb -b 115200 -U lock:w:0x0F:m

http://pastebin.ca/3178420


Can multiple xbees send data to one xbee

Yes, you can send data from 400 XBees to a single xbee. I would like to clarify one thing. XBees are connecting to a network, not to a particular xbee. And the devices connected in a network can communicate each other.


Three-position makes it a little more tricky than normal.

The simplest option, though depending on what the circuit is, maybe not the safest option, is to use three relays.

Switch only one relay on and it is the same as having the three-position switch in that same state. Switch that relay off and switch another on and you have changed the switch position.

The danger is that this arrangement can have two or even three relays on at once, something that can't happen with a switch.  Also how you do the switching could be critical. Switch one relay off, then add a delay before switching the next one on, so that the previous one has a chance to switch off properly first. That way you avoid having two on at once. Of course, depending on what it is you're switching, that may or may not be an issue.

The safest option, though the hardest to create, would be to physically move the existing switch with, say, a servo motor. Without knowing a little more about the mechanics of your switch I can't really advise more on this option.


How does DDRD |= _BV(PD2) differ from digitalWrite(2,HIGH)?

Each port on the ATmega328P (or the ATmega8 for that matter) is
controlled by two registers¹:

DDRx, where x is B, C or D, is the “data direction register”. It is
used to set the pin to either input or output. Writing to this
register is roughly equivalent to calling pinMode().
PORTx is the port's “data register”. It is mostly used in output
mode to set the pin to HIGH or LOW. Writing to this register is
equivalent to calling digitalWrite().

All this is covered by the Arduino tutorial on direct port access.
And, of course, by the datasheet; more specifically by
section 18.2: “Ports as General Digital I/O”.
As you may now notice, the original code does not use anything like
digitalWrite() to write to the bus, relying instead of the equivalent
of pinMode(). This is related to the electrical characteristics of the
bus:

You write a “physical 1” by actively driving AVC+ high and AVC− low
You write a “physical 0” by releasing the bus, in which case the
potentials of those lines are set by the termination resistors.

That's why you see InitMCU() setting PORTD for driving AVC+ high and
AVC− low, but leaving DDRD in its initial state (“leave pins
tri-stated” says the comment). At this point the bus is in the
“released” state. Then pulses are sent by setting the pins to output
mode (“Drive output to signal high” in the comment) and, after an
appropriate delay, setting them back to input mode (“Release output”).

¹ I am leaving away the details that are irrelevant to the code in
question, like the internal pullup or pin toggling via PINx.


On my lcd my characters collide, how can i remove one(because of the programming)

Either clear the display first, or print enough spaces after to overwrite the existing text.


Arduino + L9637 K-Line reader - 10400 baud on SoftwareSerial?

I've found 9600 baud to be the receive limit among standard baud rates (transmission can go faster). You're proposing an 8% increase over 9600 which sounds like it has a good chance of working but you'll need to experiment to find out.

You also asked why might your data (on the LCD) be wrong.

You'll do your sanity a big favor and do two separate experiments:

First, get known data (literal strings or terminal input) to display correctly on your LCD, before you try to use the LCD to confirm or debug your communications.
Second, get SoftwareSerial running (or find out that it doesn't...) at 10400 baud. In fact try to get up to, say, 12000 baud, or at least push the rate to find out where it starts to fail so you know how much head-room you'll have at 10,400. The simplest way would be to use two Arduinos if you have access to another one. Again, use your terminal or some literal strings on MCU 'A' to send to MCU 'B', MCU 'B' should receive a line and echo it back to 'A', who prints it on its terminal. Printing it on 'B's terminal wouldn't be a bad idea either.

You'll be in a lot better position to combine the two techniques once you have confidence that each one works; especially if you copy-and-paste known-working code segments.


In your case you do not use the entire body, so you can use a macro.

This way the code when KEYDEBUG is 0, will be like the complete function would not exist (except for the void cast, see below).

#include "assert.h"

#define KEYDEBUG 0

#ifndef KEYDEBUG
#define debugging(x) void(x);
#endif

void debugging(int var){
   assert(var);
}

void setup() {
  // put your setup code here, to run once:
  debugging(1);
}

The information below is for not using the function parameter, but keep the function (in case you have code in your function that also does something when KEYDEBUG is 0.

Unused attribute

The cleanest way I could find is using the unused attribute:

#if KEYDEBUG
   void debugging(__attribute__((unused)) int var){
      //Assert
#else
   void debugging(int var){
      //Assert
#endif
   }

or if you prefer better readability:

#if KEYDEBUG
   void debugging(__attribute__((unused)) int var){
      //Assert
   }
#else
   void debugging(int var){
      //Assert
   }
#endif

Cast to void

Less clean but does the job:

void debugging(int var){
   #if KEYDEBUG
      //Assert
   #else
      (void) var; // prevent unused parameter warning
   #endif
}

Macros/Parameter

It's not easy to remove the variable since it's used in a function and will be called from many places probably. You could maybe you use a macro but that gets messy soon.

This solution works, and afaik the compiler will optimize the code out (if not , it will cost very less anyway).


Is it possible to pass HIGH and LOW values as parameter in a function?

digitalWrite expects the pin and value to be uint8_t type. So you can certainly pass LOW or HIGH to functions.

For example:

void runMotor(int _dir, int _step, int wait, uint8_t value){
  digitalWrite(_dir, value);


Serial plotter looks different and doesnt print graph

The serial plotter expects you to send numbers, and only numbers. If it
reads any other text, like for example
“The distance is equal to 9.88cm”
It assumes these are the names of the columns of data that are to
follow. So it chooses one color for each column and prints the color key
on top of the graph.

What do I do??

Just remove the prose and print only the numbers. You may print
something like “distance(cm)” in setup() if you want to have the key
displayed, but that is not required.


1) Do batteries such as CR123As and Eneloops have built in discharge protection so that they stop supplying power when the voltage is too low?

No, they don't.  They just run till there is nothing left.

  2) If no, will draining a non-rechargable CR123A be dangerous or problematic in any way? And will draining MiMHs down to 0.85v/0.55v hurt the batteries?

A single cell can be run completely flat without problems. NiMH may need some "recovery" to wake them back up again, but shouldn't suffer serious problems (and no safety issues).  However, batteries are a different matter: see below.

  3) And, a question that I suppose applies to any battery powered Arduino project: When the supplied voltage drops below the Pro Minis BOD limit, will the Arduino stop using any power, or will it continue draining the batteries until they are completely empty? (In the first case I guess I could stick with the factory set BOD at 2.7v to protect the batteries.)

It will continue draining power. The BOD is a reset circuit - designed to recover the system into a known good state after a dip in the power. A permanent decrease in the input power is beyond the scope of the BOD system.  It will just get stuck in a BOD reset loop and consume all your remaining power.

  4) Finally, relating to the first question: Should I try to construct some kind of battery protection in the circuit, or is unnecessary when using CR123A and NiMH batteries?

For a single non-rechargeable cell you can just let it run flat. For NiMH you need to protect them.  Here's why (and what I was alluding to above):

When you have two or more cells in series (a battery) the current flows through all the cells of the battery equally. That is all fine when the cells are all fully charged - however no two cells are precisely the same.

As the battery runs down each cell will approach "empty" at a different time. With a single cell that's not really a problem, since it will just stop providing enough current to run.  However, with multiple cells one cell will run flat before the others. At that point the current provided by the other cells which still have some charge in them will be pushed through the flat cell backwards.  It is at that point that the flat cell becomes irrevocably damaged.  Current flowing backwards through the cell will try to reverse charge the battery and mess up the internal chemistry beyond recovery.

In the best case scenario, your battery will now have a much lower capacity and need recharging far more often. Worst case scenario: that damaged cell overheats and explodes.

The most prevalent problem that is caused by reverse charging is the depositing of metal crystals on the dielectric (the separator between the two electrodes) in the cell which grow and pierce the dielectric causing short circuits within the cell. There is no way back from that happening.

So you should protect your NiMH batteries from over-discharge by cutting the power to your circuit when the voltage drops below a specific threshold.  You should also recharge all the cells individually, not together in series, or they will end up unbalanced and the same problems of over-discharge can occur.

As a side note: I use the terms "cell" and "battery" with their "proper" usage: A cell is a single power-producing unit, such as an AA "battery".  A battery is a collection of cells.  This is the proper usage of the words, not the common usage where battery can also be taken to mean cell.  I use these terms specifically to differentiate between a single unit and a collection of units because of the major differences in how you need to handle them. It helps prevent confusion if you know that I am talking about just one AA (a cell) or a collection of three AA in series (a battery), for example.


ATTiny85 Serial communication with Bluetooth Module

Hello,

I think you should do this:

char inputChar = '';    //this in global
while (serial.available()) {
    inputChar = serial.read();
    if (inputChar == '2') {    //Char to break
        //Do something and reset i
    } else {
        inputString[i] += inputChar;    //= to +=
    }
    i++;
}


Arduino timer to turn a serve at a certain time

in setup you are calling

pinMode(b, INPUT);
pinMode(up, INPUT);
pinMode(down, INPUT);

but b, up and down all equal 0 so this is what you are doing is :

pinMode(0, INPUT)
pinMode(0, INPUT)
pinMode(0, INPUT)

This doesn't do what you want at all, these need to be assigned to pins. All you are doing is repeatedly setting arduino digital pin 0 to INPUT 3 times.

secondly

while(b == HIGH)

will never fire since b is 0 and is never set to anything else. so it will never == HIGH

Finally,

digitalRead(down);

doesn't do anything useful; what it does is read from pin down which is set to 0, and then drops the return value on the floor

also, this,

if (up == HIGH, down == LOW)

is just very wrong, sholud be

if (up == HIGH && down == LOW)

anyway based on you scematic, fixing this code:

#include <Servo.h>
#include <LiquidCrystal.h>

const int B = 7;
const int UP = 8;
const int DOWN = 9;
int val = 100;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

Servo myservo;

int pos = 0;

void setup()
{
  pinMode(B, INPUT);
  pinMode(UP, INPUT);
  pinMode(DOWN, INPUT);
  lcd.begin(16, 2);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  lcd.setCursor(0, 0);
  lcd.print("milli seconds:");
}

void loop()
{
  // todo: debounce the switches
  int up = digitalRead(UP);
  int down = digitalRead(DOWN);
  int b = digitalRead(B);

  if (up == HIGH && down == LOW)
  {
     val += 1  // todo: handle overflow
  }

  if (down == HIGH && up == LOW )
  {
     val -= 1
  }

  lcd.setCursor(0, 1);
  lcd.print(val);

  if(b == HIGH)
  {
    myservo.write(0);
    delay(val);
    myservo.write(100);
    delay(val);
  }

}

this will do what the origonal code was trying to do, more or less, but the
proper way to do this would be (in psuedo-code):

// Setup pins etc.
// Setup(): pinMode(...) ... etc.
// Loop():
//   debounce buttons
//   handle up/down
//   record milliseconds when button is pressed
//   see how much time has passed
//   trigger servo when timer has passed


Arduino GPS Simulator: SoftwareSerial Issues

First off, some comments about your code:

Never use String unless it is absolutely unavoidable
Unless you have a free() to balance your malloc() you will run out of memory almost immediately
There is never any need to concatenate strings to send through serial like that.

Instead of what you are currently doing, just scrap the String usage and your buf variable completely.  There is no need to concatenate things together - serial sends data one character at a time, so you're gaining nothing by concatenating and only causing yourself more problems.

How you should be doing it:

// The changing value as a float
float gprmc=75832.293;
// Print the prefix
mySerial.print(F("$GPRMC,"));
// Pad the value with zeroes
if (gprmc < 10) mySerial.print(F("0"));
if (gprmc < 100) mySerial.print(F("0"));
if (gprmc < 1000) mySerial.print(F("0"));
if (gprmc < 10000) mySerial.print(F("0"));
if (gprmc < 100000) mySerial.print(F("0"));
// Print the value with 3 decimal places
mySerial.print(gprmc, 3);
// Finally print the suffix
mySerial.println(F(",A,4042.695,N,07400.796,W,,,080120,000.0,W*63"));

Note the use of the F() macro to further reduce RAM usage by keeping the string constants in flash memory.


In the official Arduino examples, a servo motor is powered by the 5V pin of the Arduino board. In real life, that is a bad idea.
Your FS5106B has specified about 1A stall current. The average current is less than that, but the start peak current could indeed be 1A.
Could you try to use a seperate power supply of 5V (or 6V) for the servo motor ?

To check if the Arduino resets, you could do a Serial.begin(9600); in setup, directly followed by Serial.println("the sketch has started");

Some servo motors require different timing. That would not explain the 13 seconds delay, so I assume that your servo motor has normal timing.

Do you use a breadboard ? Sending a current peak through a breadboard (with bad contacts) can cause a lot of voltage spikes.

(To the other problem solvers: I'm ignoring the 13 seconds and assume that once in a while the servo motor is able to start, just a guess, I could be wrong).

[ADDED]
@ChrisStratton is trying to tell you this:

void setup()
{
  pinMode( LED_BUILTIN, OUTPUT);
}

void loop()
{
  digitalWrite( LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite( LED_BUILTIN, LOW);
  delay(1000);
}

The next step would be:

#include <Servo.h>

Servo servo;

void setup()
{
  Serial.begin(9600);
  Serial.println("The sketch has started");
  pinMode( LED_BUILTIN, OUTPUT);
  servo.attach(10);
}

void loop()
{
  servo.write(0);
  digitalWrite( LED_BUILTIN, HIGH);
  delay(1000);

  servo.write(180);
  digitalWrite( LED_BUILTIN, LOW);
  delay(1000);
}

[ADDED2]
Or even more fun, with a counter (as @ChrisStratton wrote):

#include <Servo.h>

Servo servo;

unsigned int counter;

void setup()
{
  Serial.begin(9600);
  Serial.println("The sketch has started");
  pinMode( LED_BUILTIN, OUTPUT);
  servo.attach(10);
}

void loop()
{
  servo.write(0);
  digitalWrite( LED_BUILTIN, HIGH);
  delay(1000);

  servo.write(180);
  digitalWrite( LED_BUILTIN, LOW);
  delay(1000);

  Serial.print("Still alive after ");
  Serial.print(counter);
  Serial.println(" seconds");
  counter += 2;   // two seconds per loop iteration
}


Well, it's easy, as you are using pointers. If the original place gets changed, you can see changed value because you don't have your own copy.

Your if statement is also wrong, as you are comparing two pointers here. They will be different at the first time comparation, but after the assigment they are unlikely to change.

The solution is using:

byte uidList[NR_OF_READERS][8]; // better to use some constant value instead of magic number

and memcpy for making a copy and memcmp for comparing its content. Both are from <cstring> include


Why connect the source pin on a mosfet to the pull down resistor?

I am not sure if I understood right, but I will try to answer:

Why there is ground line going back to the Arduino board?

Because all grounds in DC circuit must be connected together. Simple as that.

Why is there a pull-down resistor on MOSFET?

The MOSFET you are using is N-channel MOSFET. It is "activated" or "open" where voltage on the gate is larger than "Gate threshold voltage", the value you will find in MOSFET datasheet. You want your MOSFET to be off in all times unless you apply voltage to the gate.

In this case it is actually a pull-down resistor from gate to the ground(hence the pull-down resistor). It is coincidence that in N-channel MOSFET you connect source to the ground so it looks like there is a MOSFET on source line, but it is actually just a pull-down resistor on gate to keep MOSFET off.


In general, on a combined "Something plus SD card" shield like this the SD card is a completely separate section to the rest of it. The only real exception is on some audio shields (mp3) where the SD card is directly controlled by the audio CODEC chip.

So yes, you can pick and choose which portions of the shield you actually use in your code. Just by not using the bits you don't want to use.


How to burn the bootloader onto a bare chip without using an Arduino board

The short answer is, you need a AVR programmer

It is a tutorial on the Arduino website:

https://www.arduino.cc/en/Main/Standalone

And the section Bootloading your chips OPTIONAL will answer the question.


How to NOT repeat a piece of code again and again?

In the short example of above, first find out what is a duplicate (the two outer if statements including their body), than the differences:

Rfb versus Rfd
+5 versus -5

Than make a function for the duplicated code, and turn all differences into a parameter (I don't know the type of Rfd, so I take an int for it).

You will get:

case 12:
  processButton(&Rfb,  5); // Offset magnet distance by +5
  processButton(&RFd, -5); // Offset magnet distance by -5
  break;

  ...

void processButton(int* rf, int diff)
{
  if ((millis() - millistimer) > BounceD) {
    if (receivedValue == *rf) {
      magnetDistance += diff;
      millistimer = millis();
      *rf = 0;
    }
  }
}

Note that if magnetDistance and millistimer are local variables you also have to pass them (as pointer to change the value), if they are globals you can keep the code as is above.

UPDATE

The way parameter works is as follows. E.g.

processButton(Rfb,  5);

Will call the following function:

void processButton(int rf, int diff)

Where value rf will be Rfb, and diff will be 5 (+5).

Thus when magnetDistance += diff; is executed, diff will be +5 and magnetDistance will be increased with +5. In the next call, magnetDistance will be -5 and thus will be subtracted.

UPDATE 2

To change a variable, you have to pass it as pointer, otherwise the (copied) parameter value will be changed and not return its value to the called function. So you have to give the parameter as an address (& operator), and use -> instead of . to get to the value.


How much voltage and amps for 2 SG90 servos?

The SG90 servo datasheet is here:
SG90 Servo Datasheet
As you can see, the voltage specification is 4.8 - 6.0 Volts.  But you do NOT want to power this or any other servo via the Arduino.  Servos are quite "noisy" electrically and this can cause instabilities with your Uno.
You want to supply power to the servo directly from a +5V power supply.
I don't see the current draw for this servo specified so you will need to do your own measurements based on the loading of the output shaft.  Be aware that these draw more current with increased load on the shaft.
As far as the control signal, the Arduino Uno can certainly drive it via its PWM outputs.


How to interpret Serial data received by Bluetooth module

Or just storing the inbound data in a char type and use single quotes when parsing incoming bytes so that the compiler knows your dealing with ASCII, print them out on serial and they should be familiar characters, of course with the baud rate mismatch fixed


I cannot upload any code to my arduino nano

For me selecting the ATmega328P (Old Bootloader) from the Tools --> Processor menu in the Arduino IDE solved the problem.
See: https://gyorgybalassy.wordpress.com/2020/10/16/arduino-programmer-is-not-responding-not-in-sync-error/


Returning struct from function generates 'does not name a type' compilation error

I would avoid having multiple .ino files, because of the issues raised
in the other answers. If you want to split your code into multiple
files, the scheme that works reliably is to have:

a single .ino file, named like the containing folder, holding the
“main” program (this is Arduino-specific)
a pair of .h/.cpp files for each “module” implementing a sub-feature
of the program (this is common C++ practice).

Within the .h/.cpp pair, the .h file declares everything the compiler
needs for understanding code that uses the feature: type definitions
(including classes) and function prototypes. The .cpp file holds the
actual implementation.
Applying this scheme to your case would give:
my-sketch.ino (actually, with the name of the containing folder):
#include "angles.h"

void setup() {
  EulerAngles angles;
  angles = anglesCalc();
  Serial.print(angles.yaw);
}

void loop() {
  Serial.println("In loop");
  delay(1000);
}

angles.h:
struct EulerAngles {
  double roll, pitch, yaw;
};

EulerAngles anglesCalc();

angles.cpp:
#include <Arduino.h>
#include "angles.h"

EulerAngles anglesCalc() {
   EulerAngles a;
   // calculate a
   return a;
}

Note that including <Arduino.h> is only useful if the code uses the
Arduino core API. Otherwise you can omit it. The main sketch does not
need to include <Arduino.h> because it is implicitly included in the
.ino file by the Arduino IDE. There is no such implicit inclusion when
the IDE processes .cpp files.


Arduino ESP8266 - wifi evt: 3 and wifi evt: 7 meaning?

The codes are explained in this forum thread. The wifi event types are  described here (and also duplicated here, which are ultimately coming from the Espressif Non-RTOS SDK, chapter 6.2.4):

typedef enum WiFiEvent
{
    WIFI_EVENT_STAMODE_CONNECTED = 0,
    WIFI_EVENT_STAMODE_DISCONNECTED,
    WIFI_EVENT_STAMODE_AUTHMODE_CHANGE,
    WIFI_EVENT_STAMODE_GOT_IP,
    WIFI_EVENT_STAMODE_DHCP_TIMEOUT,
    WIFI_EVENT_SOFTAPMODE_STACONNECTED,
    WIFI_EVENT_SOFTAPMODE_STADISCONNECTED,
    WIFI_EVENT_SOFTAPMODE_PROBEREQRECVED,
    WIFI_EVENT_MAX,
    WIFI_EVENT_ANY = WIFI_EVENT_MAX,
    WIFI_EVENT_MODE_CHANGE
} WiFiEvent_t;

The enum's values are increasing downwards, meaning that 7 is WIFI_EVENT_SOFTAPMODE_PROBEREQRECVED. Receiving a probe request means that some other device has scanned the surrounding WiFi networks and your ESP answered. This indicates that your ESP is in the Software Access Point (AP) + Station (SoftAP + STA) mode. But you only want to be a station in your own WiFi network, not an access point yourself.

The output is triggered by this function.

This comment on an issue suggests that you add WiFi.mode(WIFI_STA); to your setup, like

void setup() {
  WiFi.mode(WIFI_STA);
  dht.begin();
  delay(2000);
  Serial.begin(115200);
  Serial.println("Connecting");
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
  }
  Serial.println("Connected");
  delay(1000);
  readSensor();
  String temperatureString = String(temperature,1);
  String humidityString = String(humidity,1);
  sendDataToServer(temperatureString,humidityString);
}

Subsequently, a WiFi event 3 indicates WIFI_EVENT_STAMODE_GOT_IP. Which also makes sense because you're telling the module to connect to the WiFi, it acquires an IP over DHCP and is then fully connected. This message is harmless since it doesn't indicate an error.

You should investigate on why these debug messages are thrown in the first place. The messages are only printed if two macros are set: DEBUG_ESP_WIFI and DEBUG_ESP_PORT (see here). So something must do #define DEBUG_ESP_WIFI and #define DEBUG_ESP_PORT Serial somewhere.

This is either done in some compiler settings which you are not aware of or because you modified a header file to include this change. Either way, you can try to use the #undef pre-processor macro to remove these definitions again before including the library. Change your first line to the following:

//Try to kill the DEBUG defines
#undef DEBUG_ESP_WIFI
#undef DEBUG_ESP_PORT
#undef DEBUG_WIFI
#include <ESP8266WiFi.h>


Yet another display 16x2 not working with arduino

disconnect the E line, power up the system and adjust the contrast so you see 1 black bar on the first line;
reconnect the E line and see if your code is working.
go from there.


Send Color value from Processing into Arduino

Add print(_hexColor); to you processing sketch. The value it's sending should appear in the Processing Console (at the bottom)


How to change Arduino Nano MODEL_ID?

The Arduino Nano used a special USB-Serial adapter (FTDI FT232RL). You can change the ID but this requires some special hacking. Please see the provided links.

Cheers!


Measuring li-ion that arduino is running from

Using the 1.1V internal analog reference to measure a draining VCC
source by using a voltage divider on it

You could indeed use a voltage divider, and measure a scaled-down Vcc
against the internal 1.1 V reference. This is, however, not what
the code you posted is doing. It is instead measuring the internal
reference against Vcc, as stated in the comment within the code. The
REFS0 bit selects Vcc as the reference for the ADC. The bits MUX1...MUX3
select the internal reference as the input channel.

result = ADCL;
result |= ADCH<<8;

This idiom dates back from a time when the compiler did not know how to
read 16-bit I/O registers: you had to explicitly read one byte at a time
and then put these together into a 16-bit word. This time is long gone,
and you can now just access the 16-bit register as ADC directly. I
would even get rid of the result variable and just:
return 1126400L / ADC;  // Vcc in mV

Edit: As suggested by the busybee, here is the explanation of the
factor 1126400: The ADC meaures the ratio of its input voltage to its
reference voltage, and returns this ratio scaled by a factor 1024. In
this case,
ADC = 1024 × (Vbg ÷ Vcc)
where Vbg is the voltage of the 1.1 V bandgap reference. Thus,
Vcc = 1024 × Vbg ÷ ADC
If we want Vcc in millivolts, we plus the Vbg voltage in millivolts in
the above equation and get
Vcc (in mV) = 1024 × 1100 ÷ ADC = 1126400 ÷ ADC


You are creating a SoftAP (in essence creating a separate Wifi network). In this configuration, the ESP8266 will not "connect" to anything so polling WiFi.Status for the WL_CONNECTED status is meaningless.
To see if the SoftAP instance was created successfully, you should look at the output of WiFi.SoftAP() when you create the SoftAP instance, which returns a boolean indicating success (true) or failure. Or you should see the SSID of your newly created access point appearing on your PC or phone.
I suggest you look at the ESP8266 examples included in the Arduino IDE when you install device support for the ESP8266 to get some ideas about what you can do with a SoftAP.


Arduino code for turning an led on by one clap and then off by one clap

If the sound level is below the threshold, the DO pin of the sensor signals a high value. If the sound level exceeds the threshold, i.e you clap you hands, the DO is pulled to GND and the signal gets LOW for a short while. After this short while the signals gets HIGH again.

Now look at you loop:

void loop()
{
  int status_sensor = digitalRead(Sensor);

  if (status_sensor == 0)
  {
    // you enter this block if you clap your hands and the
    // mcu is fast enough to capture the signal / DO pin (LOW)
    // within the short time interval
    // I'm sure it is fast enough to enter this block multiple
    // times in the interval the clap is active.
    if (status_lights == true)
    {
      status_lights = false;
      digitalWrite(13, LOW);
    }
    else
    {
      status_lights = true;
      digitalWrite(13, HIGH);
    }
  }
}

You see, the LED is toggled as long as the LOW interval of the sensor is active (DO=LOW).

I interpret you statement "My code only turns on the led but dosen't turn it off when I clap." so, that the LED is on, when the program starts without a clap. That means that the environmental noise is loud enough to activate the sensor. Then the loop above is iterated permanently and you switch on and off the LED at a very fast speed. That's like you would apply a PWM waveform on the LED pin. The LED is on but dimmed to about 50%.

To find out if I'm right, just add a delay in the loop. My assumption seems to be correct, if the LED blinks with one herz (one time per second).  The you can adjust the sound threshold until the LED stops blinking.

void loop()
{
  int status_sensor = digitalRead(Sensor);

  // Add the delay here ..........
  delay(500);

  if (status_sensor == 0)
  {

If you have calibrated the sensor, remove the delay from the code and add a new delay after changing the LED states. That should be much shorter, because it's only there to ensure that you don't toggle the LED while the sensor is active.

    if (status_lights == true)
    {
      status_lights = false;
      digitalWrite(13, LOW);
    }
    else
    {
      status_lights = true;
      digitalWrite(13, HIGH);
    }
    // wait until the clap is over
    delay(100);


Using more than one Ping Ultrasonic Range Finder

There is no way to change the frequency, however there are other ways of doing what you want to accomplish. I think the best thing to do is stagger the timing of the pings so they don't happen at the same time.

Example code, modified by me:

#include <Servo.h>
Servo servo; // create servo object to control a servo

int pingPins[] = {7,8}; //The pins for the two sensors
char *pingString[] = {"Ping1", "Ping2"};

void setup()
{
  servo.attach(10); // attaches a servo to pin 10
  Serial.begin(9600);
}

void loop()
{
  unsigned long ultrasoundValue;
  for(int i = 0; i < ultraSoundSignalPins.length; i++)
  {
    ultrasoundValue = ping(i);
    Serial.print(pingString[i]);
    Serial.print(": ");
    Serial.print(ultrasoundValue);
    Serial.print("in, ");
    delay(50);
  }
  Serial.println();
  delay(50);
 }

//Ping function
unsigned long ping(int i)
{
  unsigned long echo;

  pinMode(pingPins[i], OUTPUT);         // Switch signalpin to output
  digitalWrite(pingPins[i], LOW);       // Send low pulse
  delayMicroseconds(2);                 // Wait for 2 microseconds
  digitalWrite(pingPins[i], HIGH);      // Send high pulse
  delayMicroseconds(5);                 // Wait for 5 microseconds
  digitalWrite(pingPins[i], LOW);       // Holdoff
  pinMode(pingPins[i], INPUT);          // Switch signalpin to input
  digitalWrite(pingPins[i], HIGH);      // Turn on pullup resistor
  echo = pulseIn(pingPins[i], HIGH);    //Listen for echo
  return (echo / 58.138) * .39;         //convert to CM then to inches
}

Sources:

https://stackoverflow.com/questions/20273971/arduino-multiple-ultrasonic-sensors-interference
http://forum.arduino.cc/index.php?topic=17898.0


eclipse photon with cdt-arduino plugin can't upload sketches

It sounds to me like Eclipse doesn't know how to reboot the board into the bootloader.

Traditional Arduinos automatically boot into the bootloader when the board is reset, and the board resets every time you open the serial port thanks to the USB chip having DTR connected (through a capacitor) to the reset pin of the man MCU.

Chips with a direct USB connection can't do that (boards like the M0 Feather, the Leonardo, etc).  Instead they have to be rebooted by opening the serial port at 1200 baud and then closing it again.

With the "traditional" boards the IDE neither knows, nor cares, about rebooting the board - it just happens. However with direct USB boards the IDE has to have specific code to perform the reboot at the right time. The Arduino IDE has that code. However I would guess that the Eclipse plugin either doesn't implement that, or doesn't have the ability to implement it.

So you will have to manually reset the board for programming.


I want to print onto serial monitor when it's detected the value change

int distance;
int last_distance; // <== To hold the value from the previous pass
int trig = 3;
int echo = 2;

void setup()
{
  Serial.begin(9600);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
}

void loop()
{
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  distance = pulseIn(echo, HIGH) / 58;
  if (distance != last_distance) {  // <== Check if new distance is different
    Serial.println(distance);       //     Print only if the values are different
  }
  last_distance = distance;         // <== Store this loop's distance for next round
}


Mkr1010 disconnects and reconnects normally until it reaches a point where it never reconnects again

I found that before using WiFi.begin() to re-connect, one needs to use WiFi.disconnect() first. At least that keeps my set-up reliably re-connecting, when its battery is empty or my router is out for a moment. Also, testing for WL_CONNECTED or 3 only means that one's set-up is connected to the router, but the router not necessarily yet to the internet; in case of a restart of the router after a power outage. On one of my routers, one has to wait 10 seconds, on another 18 seconds.

void connectToWLAN()
{
  // Check if the AirLift FeatherWing's WLAN module works
  if (WiFi.status() == WL_NO_MODULE)
  {
    Serial.println("Connection to AirLift FeatherWing WLAN module failed");

    // If not, indicate there is a WLAN module malfunction
    WiFi.setLEDs(0, 255, 0); // Red

    // And stop forever
    while (true);
  }

  // Return to loop() if already connected to the WLAN router
  if (WiFi.status() == WL_CONNECTED)
  {
    return;
  }

  Serial.println("Trying to connect to WLAN router");

  // Indicate there is no WLAN router connection just yet
  WiFi.setLEDs(192, 255, 0); // Yellow

  do
  {
    // Start connection to WLAN router and print a status value
    WiFi.disconnect();
    delay(1000);

    status = WiFi.begin(WLAN_SSID, WLAN_PASS);
    // WL_IDLE_STATUS     = 0
    // WL_NO_SSID_AVAIL   = 1
    // WL_SCAN_COMPLETED  = 2
    // WL_CONNECTED       = 3
    // WL_CONNECT_FAILED  = 4
    // WL_CONNECTION_LOST = 5
    // WL_DISCONNECTED    = 6
    Serial.println(WiFi.status());
    delay(10000);
  }
  while (status != WL_CONNECTED);

  Serial.println("Connection to WLAN router successful");

  // Indicate that the WLAN router connection was established
  WiFi.setLEDs(255, 0, 0); // Green

  // To better see the status indicating RGB LED's state
  delay(2000);
}


How to connect an RF module directly to a PC without using an arduino?

The nRF24L01+ uses SPI. PCs don't (usually) have an SPI interface. So you will need some piece of hardware to provide the PC with an SPI interface.

That could be an Arduino, or it could be a dedicated SPI dongle, such as one based around the FT2232 chip.

Of course, you then would need to write software to use that SPI interface and work with the nRF24L01+ connected to it, including using the same message format / packet system, which won't be a simple task. So you may be better off just using a small Arduino to do the communication and present you with a simple serial interface for sending / receiving messages. That way you can then use the same nRF24L01+ software that you are using elsewhere in your setup.


Which tft works on both Arduino Uno and Raspberry pi

Well any display can work on both of the boards if you can adjust the voltage levels right there is a display which was made for old Nokia phones and it is called nokia-5110-3310 and  is dirt cheap display and it can be used with both Arduino or raspberry pi or any other board which support the protocol here is a link for quick reference.

Adafruit link to the library


Bluetooth a pushbutton from one arduino to another to turn on a LED

So, you have done the hard part and now need the easy bit :)

Firstly you need a button (failing that touching two wire together will just about do).  There are loads of quick tutorials on the web, here is one https://www.arduino.cc/en/Tutorial/Button.  They will end up with you having a pin that goes high or low when the button is pressed, you can either poll/loop to detect the press or go posh and use interrupts (leave that for later).  When the pin detects the press you need to send some data via your HC05 link to the master, something like 'ON' or 1, who cares so long as the master understands it.  And when it disconnects you need to send a off or 0 message (Remember the number 1 and the character '1' are not the same thing, so make sure you know what you are sending).

When the master receives the command it will execute a bit of code that will send a pin high (lets say pin 7).  Connected to pin 7 will be the +ve side of a LED, the -ve leg of the led will be connected to a resistor of 200-250 ohms and the other end of the resistor will be connected to ground.  Then when pin7 goes high it will light the resistor.

simulate this circuit – Schematic created using CircuitLab

As always you probably will need to break it down to test it, have a little app that toggles pin 7 high for 2 seconds and low for two seconds, etc (just like blink).

There is a phenomenon called 'bouncing' which is where the useless human finger presses a switch and doesn't instantly create a perfect connection and perfect disconnection.  This might make the slave send 101010101010101 when you just expect 1, you can either debounce using software or hardware, but only worry about that if you have a good quality switch :)


Is it possible to use Arduino PWM for audio within a PAM8493 amplifier?

Are you using a basic Arduino board (not I2S) and a sampling frequency of 8 kHz or 16 kHz? That could interfere with the default switching frequency of 260 kHz.

My suggestion is to use a low pass RC filter.
You might have to lower the signal level from the Arduino.
The PAM8403 requires a series capacitor and resistor at the input (those are probably already on the amplifier module).
In the end you probably need a voltage divider with a capacitor to ground for each channel.

I don't know if your PWM library has volume control. The TMRh20 has a function to set the volume.

The overall quality will be reasonable, but not very good. There are MP3 shields that can play mp3 files from a SD memory card. Those have better quality.

[ADDED]
I think I have misunderstood your question. Sorry. I'm still not sure that I understand your question now.

Wiki of DFPlayer Mini: DFRobot:DFPlayer Mini
Code on Github for DFPlayer Mini: Github:DFPlayer Mini
The PAM8403 has no volume control, you need to adjust the audio signal that is going to the PAM8403 module.
The DFPlayer Mini code has functions for volume, volumeUp, volumeDown and readVolume. However, it does not seem to have a function to select a specific file.

The Adafruit Music Maker shield is in two versions, one has an amplifier onboard: Adafruit:Music Maker MP3 Shield for Arduino w/3W Stereo Amp - v1.0. With that shield, you can play a file by its name. It can also set the volume. I suppose that is what you want ?


avrdude: stk500_recv(): programmer is not responding - OSX10.11

Has this ever worked?
Can you use avrdude and hit the target?
There is a terminal mode in avrdude you can also use.  At least this would help you determine what is working.

Sounds like a configuration issue.  If you have the ability to 'follow the tail' (tail -f ) I'm assuming that you have 'like' tools we have in Linux like lsusb to assist?

You can ensure yourself that if it says it isn't found, it's not finding it, so it's not wherever it's looking. :)


Best way to measure liquid level of a 10 meter high tank?

I don't know what is the “best”, and in fact I would be interested in
knowing the answer. So far the best option I found seems to be a
submersible level sensor (do a Web search for these words). These are
pressure sensors that you put at or near the bottom of the tank. They
give you a reading proportional to the height of water above the level
of the sensor.

Most of these sensors seems to give an output in the form of a
4 – 20 mA current. They are have only two wires and
expect a supply somewhere in the range of 24 V. You will then need
a suitable supply and some electronics to convert that to an analog
voltage that your Arduino can read. A simple resistor would be enough
but you probably want something that provides some safety in case the
sensor fails short. You can search this site for "4-20 mA", as the topic
of interfacing these kind of sensors has already been covered here
multiple times.


There is no way to guarantee that all packets will arrive. The best you can do is to have the receiving system acknowledge receipt of all packets, with enough data within to verify the correctness of the packets.

UART parity is not a good method to verify correctness since it can only detect single-bit errors within a byte; two bit errors will verify correctly, and of course the entire byte may get dropped before it can even get to the receiver.

RFC 916, "RELIABLE ASYNCHRONOUS TRANSFER PROTOCOL (RATP)", describes a TCP/IP-like method of sending data reliably over an asynchronous medium. It's more wordy than just sending a byte containing status changes, but if you need reliability then you need more than that.


None of this is on the Arduino. You must construct all of this yourself.


How do i make my DC motors run simultaneously?

Start with the BlinkWithoutDelay example code and make modifications to suit your needs.
This is the original code.
    /*
  Blink without Delay

  Turns on and off a light emitting diode (LED) connected to a digital pin,
  without using the delay() function. This means that other code can run at the
  same time without being interrupted by the LED code.

  The circuit:
  - Use the onboard LED.
  - Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA
    and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN
    is set to the correct LED pin independent of which board is used.
    If you want to know what pin the on-board LED is connected to on your
    Arduino model, check the Technical Specs of your board at:
    https://www.arduino.cc/en/Main/Products

  created 2005
  by David A. Mellis
  modified 8 Feb 2010
  by Paul Stoffregen
  modified 11 Nov 2013
  by Scott Fitzgerald
  modified 9 Jan 2017
  by Arturo Guadalupi

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/

// constants won't change. Used here to set a pin number:
const int ledPin =  LED_BUILTIN;// the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the difference
  // between the current time and last time you blinked the LED is bigger than
  // the interval at which you want to blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

Here are the changes that cause the LED to light up for 500 ms, then go dark for 5000 ms.
The changes are marked by // *************.
Hopefully, this will get you the idea about how to use millis() to control a device at desired intervals.
        /*
          Blink without Delay
          http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
        */

        const int ledPin =  LED_BUILTIN;                        // the number of the LED pin

    //  int ledState = LOW;                    // ************* // change this assignment as follows

        int ledState = 0;                      // ************* // ledState used as a state counter

        unsigned long previousMillis = 0;

    //  const long interval = 1000;            // ************* // change the interval as follows

        const long interval =  500;            // ************* // use a 500 ms interval

        void setup() {
          pinMode(ledPin, OUTPUT);
        }

        void loop() {
          unsigned long currentMillis = millis();

          if (currentMillis - previousMillis >= interval) {

            previousMillis = currentMillis;    // ************* // program arrives here every 500 ms

    //      if (ledState == LOW) {             // ************* // this code is not needed
    //        ledState = HIGH;                 // *************
    //      } else {                           // *************
    //        ledState = LOW;                  // *************
    //      }                                  // *************

    //      digitalWrite(ledPin, ledState);    // *************

            if (ledState == 0 ) {              // *************
                digitalWrite(ledPin, HIGH);    // ************* // turn on LED at start of cycle
            }                                  // *************
            else if (ledState == 1 ) {         // *************
                digitalWrite(ledPin, LOW);     // ************* // turn off LED at end of 500 ms
            }                                  // *************

            ledState++;                        // ************* // increment state counter
            if (ledState > 10 )  ledState = 0; // ************* // reset ledState when it has reached end of cycle

          }                                                     // end of if
        }                                                       // end of loop


Adding an LCD to Uno but not enough pins left

You are using 8 GPIO pins for your existing modules. That leaves 12 left for an LCD (assuming you aren't using the serial port).

An LCD can work from as few as 6 pins (4 data, E and RS) - WR can be tied LOW and RESET can be tied HIGH, and the remaining 4 data pins left floating (or tied low).

That still leaves you 6 pins to do other things. Or 4 if you (advisedly) steer clear of using pins 0/1 for anything.


avrdude: stk500v2_ReceiveMessage(): timeout with ADDAC VCC

Your log is showing that communication is failing right away (avrdude never gets a proper response). This can mean that

the VCC is not resetting
there is no bootloader installed
there is some other defect

You can test case is by manually hitting the reset switch around the time that avrdude starts. If the necessary pins are available, you can exclude case 2 by installing a new boot loader with a programmer, which also tests scenario 3 a bit.


RF24Mesh master-base node communication delay

The nRF24L01 "ACK_PAYLOAD" feature allows for two-way data transfer in a single radio transaction.  This is more complicated to set up but plenty of tutorials can be found online, on arduino stackexchange and of course another very helpful source is the nRF24L01 data sheet.  This should solve your problem by ensuring the master/slave radio messages are sent in the same, rather than independent, radio transactions.


Without any hint, what you are actually doing in your long loops, it is difficult to say, what way would be the best for your case. I don't believe, there is a standard way of doing this, but there are basically only two ways of multitasking on a microcontroller:

Interrupt driven: You can set a timer interrupt, that occurs regularly to call the AudioGenerator::loop() function (which fills the buffer with the next data).
Non-blocking code: If you are using non-blocking code, you can first do one thing and then do another in sequence, so fast, that both codes are executed often enough. Thats exactly what the library you use is designed for (according to the README file).

If you are using more than one of these long loops in your loop() function, you may consider doing things with a finite state machine (FSM), so that you don't have to always add the AudioGenerator::loop() function to your long loops, but only once for the normal loop() function.


Atmel Studio and Arduino IDE compiles the same code different

I found the solution (or what the problem is). Avrdude not only requires MCU model but also programmer parameter. If you are using any of Arduino based boards you need to add -c programmer id do avrdude input parameters.


How many UNO pins have internal pull up resistors?

All of them. It's a standard feature on all IO pins in the AVR range.


Gas Sensors with Arduino + Interfacing Circuit

You can connect the directly to the Arduino +5, Gnd and Signal.

I don't know of any calibration data for the sensors that I have.  I suppose you could take the maximum concentration the sensor can measure and divide this by 1024, but I don't know if the value returned is linear or logarithmic.
The data sheet does have some info on, but this page may be more helpful
http://forum.arduino.cc/index.php?topic=230945.0

Oh and don't forget the warm up time on the sensors!


I want to make two arduino to communicate over different wifi. Is that possible?

If they are on the same (wifi) network; then yes.
If you are on a different network, it would be more difficult. You would have to setup port forwarding on your router. Then you would have to somehow know the public IP address of the other router. These addresses can change from time to time with certain ISPs. I wouldn't advice doing this.
Instead I'd go with an third party service. For example Adafruits offers an MQTT server. I'd probably use this even if they are on the same network.


Unrecognizable Message From PROGMEM char*

The way you've written in, the pointer is stored in flash, but the strings are stored in SRAM. Read the appropriate documentation (also found in the Arduino reference) more closely, and do as it says.

char nmPokemon0[] PROGMEM = "MISSINGNO";
char nmPokemon1[] PROGMEM = "Bulbasaur";
 ...

PGM_P nameArray[] PROGMEM =
{
  nmPokemon0, nmPokemon1, ...
};

And don't forget to copy the string to SRAM as shown further down before outputting it, since Serial.println() can't work directly with flash.


Start by checking which pins are used by the shields and if there is any conflicts. Check the shield schematics and example libraries.

If there are any conflicts, check if the shields has any jumpers that may be used to change the pin configuration.

Cheers!


Some things I noticed in your code:

You are writing everything to the same address (is that intentional?)
You are only writing the first 6 six bytes of your arrays (I am pretty sure that is intentional)
You are declaring these arrays to be bigger than what you are putting in them (this is again probably intentional, but I am just guessing)

So here is an example of how I would handle the eeprom:

#include <EEPROM.h>

char sgrpID[31] = "acpilot's arduino";
char addrID[51] = "123 any street rd";
char zpcdID[11] = "12345";
char gwayID[31] = "what a cool toy!";

//These are the definitions of what goes where in memory
//You do not want everything to have the same number
const size_t SGRP_ID_EE_START = (0);  //Zero is good address to start
//To get the next address we merely add the size of the first item
//With the address of the first item
const size_t ADDR_ID_EE_START = (sizeof(sgrpID) + SGRP_ID_EE_START);
//And so on and so forth
const size_t ZPCD_ID_EE_START = (sizeof(addrID) + ADDR_ID_EE_START);
const size_t GWAY_ID_EE_START = (sizeof(zpcdID) + ZPCD_ID_EE_START);

//Use this function to write a char array to the EEPROM at
//The address "address" (and the size of "len")
void WriteEepromArray(size_t address,char* arr,size_t len){
  for (size_t x = 0; x < len; x++){
    EEPROM.write(address+x,arr[x]);
  }
}
//Use this function to load your char array with values from
//The EEPROM
void LoadFromEeprom(size_t address,char* arr,size_t len){  //Be aware that this function modifys the data pointed to by "arr"
  for (size_t x = 0; x < len; x++){
    arr[x] = EEPROM.read(address+x);
  }
}

void setup()
{
  Serial.begin(9600);
  //Some sample writes
  //               starting address----array-----size of the array
  WriteEepromArray(SGRP_ID_EE_START   ,sgrpID   ,sizeof(sgrpID));
  WriteEepromArray(ADDR_ID_EE_START   ,addrID   ,sizeof(addrID));
  WriteEepromArray(ZPCD_ID_EE_START   ,zpcdID   ,sizeof(zpcdID));
  WriteEepromArray(GWAY_ID_EE_START   ,gwayID   ,sizeof(gwayID));
  //Use the following to load:
  LoadFromEeprom(SGRP_ID_EE_START,sgrpID,sizeof(sgrpID));
  Serial.println(sgrpID);   //Now it should be loaded

}

The comments I hope help....otherwise comment below with what I left out.


What connects the resistor to the LED?

Absolutely nothing.

It's hard to work out which holes the LED is plugged into, but I think your current circuit looks something like this:

You need to connect that resistor and LED together.

For your edit:

Now your circuit looks like this:

Behind the 5 pins in that column with the ground wire there is a big chunk of metal connecting them all together.  It's no different to if you'd taken the LED and twisted the pins together into one.  There's no way the power can get up one and down the other when they are connected together like that.  You need to separate them into different columns.

And this is how the (black) connections inside are laid out, and how your (red) electricity is flowing:

And here is how the circuit should look, using a program called Fritzing.  It's a pretty basic design tool, but great for showing wiring.

You can see how the green highlighting shows the columns that are connected.