text:
Programming an EL Sequencer
I have a EL Sequencer and FTDI 5V breakout board.  I have been have been unable to program it.  All my attempts get some variation of "programmer is not responding".
I was using these instructions as a starting place.  I soldered the 6 pinholes as indicated.  I have connected everything.  I am not sure if I should switch the FTDI jumper to 3.3V (it is currently at 5V).  The pin in the EL Sequencer is labelled 5V, but the instructions also say "the EL Sequencer runs an ATmega328p at 8 MHz and 3.3V".  Should I change the jumper to 3.3V?
I have downloaded the latest IDE from here.  But there is no board option for the EL Sequencer.  What board should I select?
Anything else I need to do to program the EL Sequencer?
Thank you,

is the FTDI board working correctly?

I am not sure how to check.  It was new when I purchased it.

just because it is new does not mean that it works ......... connect RX and TX together ..... plug the module into your computer .... open serial monitor, choose the correct com port ..... type something on the keyboard ..... you should see the characters on the screen .... you should also see the LEDs on the module flash

Thank you for telling me how to test the FTDI.  I did as you suggested and received the same characters that I typed.  I also saw the LED on the FTDI flash.  It appears the FTDI is working.  Is there a similar way to check the EL Sequencer?

no there is not .... just connect everything together as before and try choosing Arduino Uno in the Arduino IDE


text:
How to assign two or more variables incoming from app
I'm really new to Arduino and have some doubts about how Arduino reads data. Lets suppose I have 3 variables a,b,c. I need these variables in my Arduino to make whatever. Since all variables are read using Serial.read() how can I distinguish between them in my Arduino?
Example:
Variable a: 2
Variable b: 3
Variable c: 4
Arduino example code:
void loop() {
int a = Serial.read();
int b = Serial.read();
int c = Serial.read();

if(a == '0'){
digitalWrite(yellowLed, HIGH);
}

if(b == '0'){
digitalWrite(blueLed, HIGH);
}

if(c == '0'){
digitalWrite(redLed, HIGH);
}

In every loop, my Arduino does serial.read() 3 times, if I only send value b from my app, since int a = Serial.read() executes first, will my b value be assigned to a? If yes, how can I avoid that problem and force the correct assignment? Aditionally, in every loop, if Serial.read() doesnt read anything, will my values be changed to null or zero?

https://majenko.co.uk/blog/reading-serial-arduino

didn't you ask a very similar question recently - https://arduino.stackexchange.com/questions/59976/how-can-i-distinguish-values-sent-from-arduino

This is a classic problem that is solved either by uniquely identifying each value or by agreeing on a pre-defined sequence of data.  However, it can be said that many solutions exist for this problem & that these are only 2 examples.
In the first case, the sender and receiver need to agree that all data will be sent in pairs.  A pair of bytes, for example, where the first identifies the data and the second is the data.  In this case the order of data does not matter.  And much more of one type of data can be sent than another.  This is good to use when the data rate is irregular and does not need to be fast.  Stock prices for example.
In the second case, the sender and receiver need to agree that all data will be sent in the same sequence even if there is no data to be sent.  Such a scheme may employ a special synchronizing bit to identify the beginning of a sequence of data.  Usually, when there is no data to be sent, a zero is sent.  But if zeros are significant, then special null characters will have to be agreed upon.  This is good when the data rate is regular and needs to be fast.  Digitized audio for example.

I think I will use the first option. But I have another doubt, since in every loop my variables try to read from Serial, if Serial is empty, will their value be changed to 0? if I use Serial.avalaible() in an if statement, will I get rid of that problem?

The Serial.available() tests if there is new data.  Use it to tell if there is no data and skip reading data for this iteration.

source: Stack Exchange

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

sort: votes


text:
Using a toggle switch to run part of a sketch
First, I am a beginner for this.  I just ordered my first book on coding Arduino and I'm working through some simple applications using a DS3231 (that has a temperature reading), LCD, MicroSD card module, etc.  My board is a Uno R3.  Currently, I need a sketch to run part of a program which contains a loop to collect data and have this run when a toggle switch is turned on.  So, toggle goes on and part of program runs, toggle goes off and this part exits.
The reason I need a toggle with constant on/off is the problem with G forces and vibration.  I momentary push button input will not be reliable.  Ultimately, all the components will be in a amateur high-power rocket to run a roll control program.
If you can help, I greatly appreciate your assistance.

push button switch and a toggle button switch are the same electrically ..... a toggle switch has a mechanical device that keeps the switch closed when it is activated  .......... pressing a pushbutton, or flipping a toggle switch, or twisting two wires together are all the same thing as far as the Arduino is concerned

I did find an example where a push button was held during a calibration.  As you probably know, there are many examples where a momentary switch is used, but few where a toggle is used.  I appreciate the suggestion to use the if-else statements to get this accomplished.  I'm waiting to receive some resistors and the screw-type switches I use for rocketry to test the circuit out.  I'm interested in how to prevent the potential bounce when I'm closing the screw switch.  This could happen because these switches do have some play until the switch is tightened.

i am uncertain that you understand my comment ...... electrically, there is no difference between a pushbutton and a toggle switch ...... there is no reason why you should be distinguishing between the examples on the web ....... just use a debounce library in your sketch

There are different ways to accomplish the same thing.
The condition is a flag, or a read port.
if(digitalRead(inPin))
     {
     // Your first code here.
     }
else
     {
     // second code
     }

Switch contacts will bounce when opening or closing. You may want to consider that. Usually it is stable within 10 milliseconds. Depending on what you are doing it may or may not be relevant.

You need a few things.
At the top of your sketch, before setup()
byte togglePin = x; // from 2 to 19 with an Uno. Wire to connect pin to Gnd when closed.

In setup()
 pinMode (togglePin, INPUT_PULLUP);

In loop()
if (digitalRead(togglePin) == LOW){
// switch closed, do something - or stop doing something
// maybe set a flag too, like
toggleState = 0;
}
else {
// switch, stop doing something - or start doing something
toggleState = 1;
}

The flag can be used elsewhere in your code
if (someOtherCondition && toggleState == 0){
// run a timer or motor or something
}
if (someOtherCondition && toggleState == 1){
// turn off timer or motor or something
}

Thank you!  I'm going to try this.  RE previous comments, sorry if there was any misunderstanding.  Just wanted to assure that people understood that I wasn't using a momentary switch like turning an LED on and off.  I need to turn on the system, start the program and  then wait for me to turn on the screw switch to start the sensor and control program.  This will only be done once per flight.

You could use a while (digitalRead()==Low) in setup() instead. It will sit there reading the pin until the condition becomes false.

The if-else statement works great; thanks again for the help.  To gain some experience, I also used the toggleState variable too.  I just had to add to define as an int in the beginning of the program.  Do you think the (digitalRead()==Low) would be faster or behave any differently?  Also, I'm curious, do comments (i.e. //) slow program execution, or does compiling disregard these comments?

Comments do nothing, the compiler strips them out.  "Do you think the (digitalRead()==Low) would be faster or behave any differently?" Than what?

I was thinking that although there might be several ways to accomplish the same behavior, some routines may be faster.  And, I mean perceived faster, not just machine time.  Although I'm sure that slower routines would add time if they are repeated many times.  Anyway, I just received my first book on Arduino sketching and started reading it.  Hopefully, I'll know more in about a week.  But, I'll still have questions no doubt.  This is an excellent resource!

Sure, that's true. You can do port manipulation to read & write the bits faster, but you lose whatever checking that the Arduino software does for you in the background.  For example, I might do (if (PIND && 0b00000100) == 0b00000100){  }  vs if (digitalRead(D2) == HIGH){  } to see if a pin is High,  or PORTB = PINB | 0b00000100; vs digitalWrite (D10, HIGH); to set a pin (make it high), but for a lot of things the possible1-2uS saved are not perceivable. I once had to update 45 shift registers at 20KHz rates, and needed all the speed available. I used an oscilloscope to confirm the timing.

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


text:
How to send big data (long string) from PC to Arduino using Bluetooth
One of the requirements of my projects is to send data from my application to the Arduino robot.
I have windows 10, and my robot is Arduino Uno.
The Bluetooth I'm using on my robot is HC-06.
The app side:

I'm writing some script (With the format I've created)
Then converting it into JsonString
Opening the port and sending a start communication signal.
Sending the JsonString, each represents another command and they're separated with a special character that can't be written in the script.
Here's the problem, I tried sending string length of 256 bytes (not a JsonString) just to test the Bluetooth.

The test I did in my robot

I read the data
Turned the led on
Waited (data.length() / 10) seconds
Turned the led off

For my data of 256 bytes, the led was ON for 12.8 seconds, which is 128 bytes. And sometimes when I changed some stuff The time was 6.4 seconds.
C# (Application)
string data = @"0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";

protocolBT.BTcontroller.OpenPort();
protocolBT.BTcontroller.SendChar(ProtocolBT.COM_OpenChar);
protocolBT.BTcontroller.SendBigData(data);
protocolBT.BTcontroller.ClosePort();

The Bluetooth Class
public class BluetoothController
{
    private readonly SerialPort _serialPort;

    public BluetoothController(string portName, BaudRate baudRate)
    {
        _serialPort = new SerialPort(portName, (int)baudRate, Parity.None, 8, StopBits.One);
    }

    public static bool IsBluetoothSupported()
    {
        return BluetoothRadio.IsSupported;
    }

    public static void SetConnection()
    {
        if (IsBluetoothSupported())
        {
            if (BluetoothRadio.PrimaryRadio.Mode == RadioMode.PowerOff)
                BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
        }
    }

    public void OpenPort()
    {
        try
        {
            _serialPort.Open();
        }
        catch(IOException IOex)
        {
            throw IOex;
        }
    }

    public void ClosePort()
    {
        _serialPort.Close();
    }

    public void SendData(string msg)
    {
        try
        {
            if (_serialPort.IsOpen)
            {
                byte[] data = Encoding.UTF8.GetBytes(msg);
                _serialPort.Write(data, 0, data.Length);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public void SendBigData(string msg)
    {
        try
        {
            if (_serialPort.IsOpen)
            {
                foreach (char ch in msg)
                {
                    SendChar(ch);
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public void SendChar(char ch)
    {
        try
        {
            if (_serialPort.IsOpen)
            {
                byte[] data = Encoding.UTF8.GetBytes(new char[]{ ch });
                _serialPort.Write(data, 0, data.Length);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

}

And this is my Arduino test code
#include <SoftwareSerial.h>

#define RX 10
#define TX 11
SoftwareSerial BT = SoftwareSerial(RX, TX);

String startCom = "»";

String MessageStart = "";
bool isListen = false;
String data = "";

int yellow = 12;

void setup()
{
  // Define LED
  pinMode(yellow, OUTPUT);

  // Test yellow led
  digitalWrite(yellow, HIGH);
  delay(1000);
  digitalWrite(yellow, LOW);

  // Define Bluetooth
  pinMode(RX, INPUT);
  pinMode(TX, OUTPUT);
  BT.begin(9600);
}

void loop()
{
  if(isListen == false)
  {
    readStartCommand();
  }
  else if(isListen == true)
  {
    readAllData();

    int len = data.length();
    if(len > 0)
    {
      robotLedOn(0); // Turn on the yellow led
      for(int i = 0; i < len; i++) // Wait (len * 0.1) second
      {
        delay(100);
      }
      robotLedOff(0); // Turn off the yelloe led
    }
  }
}

void readStartCommand()
{
  if(BT.available() > 0)
  {
    char ch = BT.read();
    Message += ch;

    if(MessageStart == startCom)
    {
      // Blink the yellow led if the start communication command recieved
      robotLedOn(0);
      delay(1000);
      robotLedOff(0);
      delay(2000);

      MessageStart = "";
      isListen = true;
    }
  }
}

void readAllData()
{

  while(BT.available() > 0)
  {
    data += BT.read();
  }
  isListen = false;
}

I tried to put the 256 bytes data manually to string in the Arduino and the timer was on 25.6 seconds.
So I think that there is a limit for the size of the data that Bluetooth can handle.
Note:

I need Json because I have complicated commands, not only leds. Some of the commands require multi-parameters from different types.
Soon I will get Arduino-Mega because I don't have enough pins in my Uno.

Tried:

Change the timeout, it still stops receiving at 128 bytes.
with read() and setTimeout(100-2000) Timer result: 12.8 seconds
With readString() and setTimeout(100-2000) Timer result: 6.4 seconds
My WriteBufferSize in the PC Bluetooth is 2048 bytes. So I'm pretty sure that all the data is sent.
Different Baud Rates and using the Library instead of the
The only change is that now the timer stops at 15.5 seconds...
Use BT.flush() and all my data is sent 100% for sure, the problem is in receiving in my Arduino. I think there is a buffer limit for the data...
Using another Bluetooth device, still the result is 15.5 seconds instead of 25.6 seconds.

why are using JSON? ..... why don't you simply use single byte commands with single byte data such as, for example  L10 or L:1:0 which could mean LED 1 off ?

https://majenko.co.uk/blog/reading-serial-arduino

For any communication you have to indicate your packet end somehow. You can use termination character ot fixed data length. And you have to read data from serial port on Arduino side until receive the termination character ot reach the packet length.

timeout is not applied for available() and read() that is why your code stops reading at a gap in data flow. are the coming in until you blink the LED 3 seconds? then you loose data there


text:
How to choose a port on Arduino Create
I have connected my Mega2560 Arduino to my computer; locally everything works fine - I have been able to upload and run programs.
However, on Arduino Create, it shows that there's no connection to my board. I have downloaded the plugin. The instructions say to "choose a port", and in the image it displays a menu with "[board] at [port]" but in my menu there is no "at", it just says "Arduino/Genuino Mega or Mega 2560" with an option to choose a flavour, but no port.
How can I choose a port and get my Arduino connected?

Which operating system? I have used it, but it was slow and not pleasant to work with.

@Jot both Windows 10 and Mac OS Mojave. Both using Chrome


text:
Creating a library for arduino
I found a really nice 24 bit I2C adc which was fairly cheap as well (ADS1219) but as far as I could tell there are no libraries for it so I decided to make my own. I have managed to write functions and get everything working on the arduino itself but I've been having massive issues with converting it into a library.
So I tried a very basic sketch to see if I can do something as simple as printing hello world using the library.
Here is my ADS1219.h file:
#ifndef ADS1219
#define ADS1219

#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

class ADS1219{
public:
 ADS1219();
 void begin();
 void printHello();
};

#endif

And the ADS1219.cpp:
#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#include

ADS1219::ADS1219{
 Serial.println("New object created!");
}

void ADS1219::begin(){
 Serial.begin(9600);
}

void ADS1219::printHello(){
 Serial.println("Hello World");
}

and my main sketch:
#include

ads = new ADS1219;

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

void loop() {
  ads.printHello();
  delay(2000);
}

but I get this really long error which basically says I've failed with creating the ads object.
I tried ADS1219 ads; as well but same error ... not sure what's wrong tbh.
Arduino: 1.8.8 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

In file included from sketchADS1219.cpp:7:0:

ADS1219.h:14:11: error: expected unqualified-id before ')' token

   ADS1219();

           ^

ADS1219.h:12:14: error: an anonymous struct cannot have function members

 class ADS1219{

              ^

ADS1219.h:18:1: error: abstract declarator '' used as declaration

 };

 ^

ADS1219.cpp:9:17: error: expected id-expression before '{' token

 ADS1219::ADS1219{

                 ^

ADS1219.cpp:13:21: error: explicit qualification in declaration of 'void begin()'

 void ADS1219::begin(){

                     ^

ADS1219.cpp:17:26: error: explicit qualification in declaration of 'void printHello()'

 void ADS1219::printHello(){

                          ^

In file included from C:UsersOM222ODesktopadslibadslib.ino:1:0:

ADS1219.h:14:11: error: expected unqualified-id before ')' token

   ADS1219();

           ^

ADS1219.h:12:14: error: an anonymous struct cannot have function members

 class ADS1219{

              ^

ADS1219.h:18:1: error: abstract declarator '' used as declaration

 };

 ^

adslib:3:1: error: 'ads' does not name a type

 ads = new ADS1219;

 ^

C:UsersOM222ODesktopadslibadslib.ino: In function 'void setup()':

adslib:7:3: error: 'ads' was not declared in this scope

   ads.begin();

   ^

C:UsersOM222ODesktopadslibadslib.ino: In function 'void loop()':

adslib:11:3: error: 'ads' was not declared in this scope

   ads.printHello();

   ^

exit status 1
expected unqualified-id before ')' token

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

Sorry I didn't know that existed ... there are so many different SEs hahaha. I'll move it to there.

First error is "#define ADS1219". Use the convention "#define ADS1219_H" instead. Please come back for more C++ help :).

That changed absolutely nothing :D

I even tried downloading the exact code some poeple showed to create libraries but I still had no luck! literally the exact same code doesn't wanna work on my machine! Any ideas on what I might be doing wrong? edit: here is the link which I followed: https://www.alanzucconi.com/2016/05/11/libraries-for-arduino/

You don't have to check for an old arduino version. That is no longer used. It is almost 2019. Just include the Arduino.h (only in the file ADS1219.h). What is a #include without specifying which file to include? In the sketch a ads ADS1219; is enough. Github is full of arduino libraries, you can find many examples there, for example: https://github.com/Locoduino/SlowMotionServo/tree/master/src and https://github.com/winlinvip/SimpleDHT (just two random chosen libraries, there must be hundreds of them).

@Jot that is exactly what I have done which is why I even have the line to check for arduino versions ... I don't know what version 1 is, but I directly copied that part of the header from other libraries. As I said, I'm directly copying other people's code and seeing where it breaks for now, till I learn to write everything from scratch :D

I created the exact same question here ... and I can't delete this one ... can somebody else do it? I don't wanna be spamming questions

I think I stuffed up the merging of the two questions. This is now the active one.

@OM222O did you have a look at those two random examples? The difference between those and your code is what is wrong. We told you everything to make it work. Fix the define, fix the includes, add the "()" for the constructor, remove the "= new" for the declaration. That's all, then it will work.

Your problem stems from this line:
#define ADS1219

You define the macro ADS1219 as empty. From that point on all references to ADS1219 get replaced with nothing. For example:
class ADS1219{
public:
 ADS1219();
 void begin();
 void printHello();
};

becomes:
class {
public:
 ();
 void begin();
 void printHello();
};

And
void ADS1219::begin(){
 Serial.begin(9600);
}

becomes:
void ::begin(){
 Serial.begin(9600);
}

By using the same name in your header guard as your class name you screw everything else up.
I always use strict rules for header guard macros to ensure that they never conflict with anything else.  You should change yours to read something else.  I would use:
#ifndef _ADS1219_H
#define _ADS1219_H

// ... content

#endif

You are also lacking the parenthesis in the constructor implementation:
ADS1219::ADS1219{
 Serial.println("New object created!");
}

should read:
ADS1219::ADS1219(){
 Serial.println("New object created!");
}

And you don't give your ads variable a type and you don't want to use new:
ads = new ADS1219;

should read:
ADS1219 ads;

Also in the cpp file he should not include again the Arduino.h file, but rather include only the library file (ADS1219.h). Moreover, in my libraries I stopped including WProgram.h. Do you think it is still required?

I haven't included wprogram.h for ages. It doesn't hurt to include a file multiple times as headers should include header guards.

thanks this has fixed my issue for now :D I will try to finis the rest on my own but I still might need some help.I'll publish it as soon as I finished

Are you sure you're compiling this for C++ and not C?
In any case, you're defining
#define ADS1219

I'm not sure what that does to your class name. Have you tried to
#define ADS1219_H  // <- Standard include guard

instead? Does this yield different results.

arduino is C itself but the file extension is cpp (c plus plus) so I'm a bit confused myself. Changing it to ADS1219_H yields the same error message.

Considering that the class keyword only makes sense in a C++ environment it should be C++ and the compiler should be configured as such. To me, this looks like you're already doing that in the Arduino IDE so it should be configured correctly. Unfortunately I'm out of luck here. Just one sidenote (not related to your issue): You're missing the parantheses on the line where you instantiate your object (the one with the new keyword)

thanks for pointing that out and yes, I am using the IDE. I'm pretty sure it uses GCC linker and is already configured correctly.

Standard include guard - isnt' that what #pragma once is used for?

Arduino is c++ not c.

I have made a lot of progress and almost everything works fine ... except I initially used strings in switch case for setting up the voltage reference and conversion modes ... it did not like it at all. I instead aimed to use enums for the same purpose but I'm getting this error now:
Arduino: 1.8.8 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

In file included from sketch\LibraryExample1.ino.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:81:18: error: expected identifier before numeric constant

 #define INTERNAL 3

                  ^

C:\Users\OM222O\Documents\Arduino\libraries\ADS1219/ADS1219.h:49:3: note: in expansion of macro 'INTERNAL'

   INTERNAL = VREF_INTERNAL,

   ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:81:18: error: expected '}' before numeric constant

 #define INTERNAL 3

                  ^

C:\Users\OM222O\Documents\Arduino\libraries\ADS1219/ADS1219.h:49:3: note: in expansion of macro 'INTERNAL'

   INTERNAL = VREF_INTERNAL,

   ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:81:18: error: expected unqualified-id before numeric constant

 #define INTERNAL 3

                  ^

C:\Users\OM222O\Documents\Arduino\libraries\ADS1219/ADS1219.h:49:3: note: in expansion of macro 'INTERNAL'

   INTERNAL = VREF_INTERNAL,

   ^

In file included from C:\Users\OM222O\Desktop\LibraryExample1\LibraryExample1.ino:2:0:

C:\Users\OM222O\Documents\Arduino\libraries\ADS1219/ADS1219.h:51:1: error: expected declaration before '}' token

 }adsRef_t;

 ^

exit status 1
Error compiling for board Arduino Nano.

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

my ADS1219.h file is:
#ifndef ADS1219_H
#define ADS1219_H

#if (ARDUINO >=100)
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif

#include <Wire.h>

#define CONFIG_REGISTER_ADDRESS 0x20
#define STATUS_REGISTER_ADDRESS 0x24

#define MUX_MASK                0x1F
#define MUX_DIFF_0_1            0x00
#define MUX_DIFF_2_3            0x20
#define MUX_DIFF_1_2            0x40
#define MUX_SINGLE_0            0x60
#define MUX_SINGLE_1            0x80
#define MUX_SINGLE_2            0xA0
#define MUX_SINGLE_3            0xC0
#define MUX_SHORTED             0xE0

#define GAIN_MASK               0xEF
#define GAIN_ONE                0x00
#define GAIN_FOUR               0x10

#define DATA_RATE_MASK          0xF3
#define DATA_RATE_20            0x00
#define DATA_RATE_90            0x04
#define DATA_RATE_330           0x08
#define DATA_RATE_1000          0x0c

#define MODE_MASK               0xFD
#define MODE_SINGLE_SHOT        0x00
#define MODE_CONTINUOUS         0x02

#define VREF_MASK               0xFE
#define VREF_INTERNAL           0x00
#define VREF_EXTERNAL           0x01

typedef enum{
  ONE   = GAIN_ONE,
  FOUR  = GAIN_FOUR
}adsGain_t;

typedef enum{
  INTERNAL  = VREF_INTERNAL,
  EXTERNAL  = VREF_EXTERNAL
}adsRef_t;

typedef enum{
  SINGLE_SHOT   = MODE_SINGLE_SHOT,
  CONTINUOUS    = MODE_CONTINUOUS
}adsMode_t;

class ADS1219  {
  protected:
    uint8_t address;
  public:
    // Constructor
    ADS1219(int drdy, uint8_t addr = 0x40);

    // Methods
    void begin();
    void resetConfig();
    long readSingleEnded(int channel);
    long readDifferential_0_1();
    long readDifferential_2_3();
    long readDifferential_1_2();
    long readShorted();
    void setGain(adsGain_t gain);
    void setDataRate(int rate);
    void setConversionMode(adsMode_t mode);
    void setVoltageReference(adsRef_t vref);

  private:
    void writeRegister(uint8_t data);
    uint8_t readRegister(uint8_t reg);
    long readConversionResult();
    uint8_t config;
    int data_ready;
};
#endif

and my cpp file is:
#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#include <Wire.h>
#include "ADS1219.h"

static uint8_t i2cRead(void) {
  #if ARDUINO >= 100
  return Wire.read();
  #else
  return Wire.receive();
  #endif
}

static void i2cWrite(uint8_t x) {
  #if ARDUINO >= 100
  Wire.write(x);
  #else
  Wire.send(x);
  #endif
}

ADS1219::ADS1219(int drdy, uint8_t addr) {
  data_ready = drdy;
  address = addr;
  config = 0x00;
}

void ADS1219::begin() {
  Wire.begin();
}

uint8_t ADS1219::readRegister(uint8_t reg){
  Wire.beginTransmission(address);
  i2cWrite(reg);
  Wire.endTransmission();
  Wire.requestFrom((uint8_t)address,(uint8_t)1);
  return i2cRead();
}

void ADS1219::writeRegister(uint8_t data){
  Wire.beginTransmission(address);
  i2cWrite(CONFIG_REGISTER_ADDRESS);
  i2cWrite(data);
  Wire.endTransmission();
}

long ADS1219::readConversionResult(){
  Wire.beginTransmission(address);
  i2cWrite(0x10);
  Wire.endTransmission();
  Wire.requestFrom((uint8_t)address,(uint8_t)3);
  byte dataMSB = i2cRead();
  byte data = i2cRead();
  byte dataLSB = i2cRead();
  long data32 = dataMSB;
  data32 <<= 8;
  data32 |= data;
  data32 <<= 8;
  data32 |= dataLSB;
  return (data32 << 8) >> 8;
}

void ADS1219::resetConfig(){
    writeRegister(0x00);
}

long ADS1219::readSingleEnded(int channel){
    if (channel > 3) return 0;
    config &= MUX_MASK;
    switch (channel){
    case (0):
      config |= MUX_SINGLE_0;
      break;
    case (1):
      config |= MUX_SINGLE_1;
      break;
    case (2):
      config |= MUX_SINGLE_2;
      break;
    case (3):
      config |= MUX_SINGLE_3;
      break;
    default:
      break;
  }
  writeRegister(config);
  while(digitalRead(data_ready)==1);
  return readConversionResult();
}

long ADS1219::readDifferential_0_1(){
  config &= MUX_MASK;
  config |= MUX_DIFF_0_1;
  writeRegister(config);
  while(digitalRead(data_ready)==1);
  return readConversionResult();
}

long ADS1219::readDifferential_2_3(){
  config &= MUX_MASK;
  config |= MUX_DIFF_2_3;
  writeRegister(config);
  while(digitalRead(data_ready)==1);
  return readConversionResult();
}

long ADS1219::readDifferential_1_2(){
  config &= MUX_MASK;
  config |= MUX_DIFF_1_2;
  writeRegister(config);
  while(digitalRead(data_ready)==1);
  return readConversionResult();
}

long ADS1219::readShorted(){
  config &= MUX_MASK;
  config |= MUX_SHORTED;
  writeRegister(config);
  while(digitalRead(data_ready)==1);
  return readConversionResult();
}

void ADS1219::setGain(adsGain_t gain){
    config &= GAIN_MASK;
    config |= gain;
  writeRegister(config);
}

void ADS1219::setDataRate(int rate){
    config &= DATA_RATE_MASK;
    switch (rate){
    case (20):
      config |= DATA_RATE_20;
      break;
    case (90):
      config |= DATA_RATE_90;
      break;
    case (330):
      config |= DATA_RATE_330;
      break;
    case (1000):
      config |= DATA_RATE_1000;
      break;
    default:
      break;
  }
  writeRegister(config);
}

void ADS1219::setConversionMode(adsMode_t mode){
    config &= MODE_MASK;
    config |= mode;
  writeRegister(config);
}

void ADS1219::setVoltageReference(adsRef_t vref){
    config &= VREF_MASK;
    config |= vref;
  writeRegister(config);
}

it seems to be passing Gain (or maybe hasn't compiled that yet) but failing on the reference selection ... I don't know what I should change in order to fix the issue.
Edit: I'm really hoping it's not another naming convention thing ... if it is, I'm sorry but C++ seems to waaaaayyyy too picky about names in general

Hint: Use a private enum for all the control codes etc. Using #define is old-school and actually the root-cause of many of the issues. C++ allow namespaces, private, const, etc, which is much more semantic rich. Here is an example to help you along; https://github.com/mikaelpatel/Cosa/blob/master/libraries/ADXL345/ADXL345.hh

Hint: To avoid some of the constants, masks, etc, it is possible to use bit-fields in struct's. Here is an example: https://github.com/mikaelpatel/Cosa/blob/master/libraries/DS2482/DS2482.hh

thanks a lot! I'll have a look. I'm most of the way finished with the program :D


text:
Which LCD Pins, if any, require PWM?
In the Arduino Tutorial Page named "Hello World" aimed to help people connect a 16x2 LCD Display compatible with Hitachi HD44780 driver to an Arduino Uno. The pins used to connect the Arduino Uno and LCD Module are as follows:

LCD RS pin to digital pin 12
LCD Enable pin to digital pin 11
LCD D4 pin to digital pin 5
LCD D5 pin to digital pin 4
LCD D6 pin to digital pin 3
LCD D7 pin to digital pin 2

Pins 3,5 and 11 are connected to PWM Pins, however, I'm wondering if they actually need these PWM capabilities or does this tutorial just pick random pins and the LCD's D6, D4 and Enable pins doesn't actually need the PWM capabilities available of these pins.
I'm asking this as I'm considering on using an Arduino Mega for my next project and it would be much easier and neater for all the pins of the LCD to go onto the digital pins instead of some being on the digital and others on the PWM pins.

you are overthinking it. PWM is an additional capability of the pin. all gpio pins of Uno and Mega are digital pins. of course the LCD libray doesn't use PWM

Likely all programmable pins on modern embedded processors are able to perform digital I/O.  In addition, many can also perform other tasks such as PWM, or Analog to Digital Conversion (ADC).  This is true for many of the different processors used on different Arduino boards.
Often, the nice people who write the C++ driver class of programs or Arduino Libraries offer the user the ability to change pin assignments used by the Arduino Libraries when instantiating an instance of the driver.  This is true for the LiquidCrystal driver in the tutorial in the question.  This can be an advantage as processor's resources are limited.  For example, if you need PWM controlled pin to dim LEDs, you can move LCD controlling pins to other non-PWM pins.
The LCD specified in the tutorial linked to in the above question uses a common Hitachi HD44780 interface.  Such assemblies only need embedded processor Digital I/O pins for control.  Had the LCD no electronic driver, the segments need to be directly driven by very low alternating current (AC).  This is difficult for embedded processors.  However, it may be possible using enough PWM pins and some clever software & hardware.

Too many words.

PWM is not used on those pins for the LCD operation. You can choose more convenient pins as long as they are general purpose pins. For example, not A/D input only.
(I thought you might appreciate a short clear answer)


text:
Signal reading from existing snackmachine
So - i started a project at my civil-service. I want to fill a old snack-machine with things we need in the ambulance (bandages, cool-packs, etc.)
In order to get the current amount of everything without counting everything all these things should be stored in the snack-machine.
The Arduino should be attached to the signal wires of the machine. If a signal is firing (when a button is pressed) the microcontroller should decrease the current amount of the item in the connected database.. so it is easy to see if some product is running low.
The machine itself works with AC.
 now the problem: I'm not that professional with microcontrollers/hardware and this is my first big project.
If the Arduino is connected between the motherboard of the machine and the buttons the Arduino won't interrupt when something is pressed. I attached a picture of the circuit. (The only thing what's not on the picture are resistors between arduino and the buttons). The voltage on the wires is about 7.5-8 Volts alternative current.

So, your idea is to count the number of times that an item has been released, and use that to calculate the number of items left in the machine?  This does not seem very foolproof.  Is the database updated in real time?

7.8V AC connected to arduino ... that doesn't seem safe

I think you might get a problem with checking the button matrix. A matrix is typically checked by giving a HIGH consecutively to each row and checking the states of the columns. So the machine will drive some of the lines HIGH in it's own pace and you would have to synchronize to that, so that you don't disturb it, and only read the machines output voltage (not generating your own). It would also be possible to intercept the lines to the matrix and activating the corresponding lines on the machine with the Arduino, but I think you would have to use more external parts for that.

Even if you solve somehow the multiplexed keyboard input pointed by @chrisl still somebody can push the a key multiple times while dispensing an item counting as fake dispenses. Reliable reading of the multiplexed keyboard is tricky even for an experienced programmer, you need a different approach, I would think of lever switches or optos on the dispensing mech.  Can you post a picture of the dispensing mechanism?


text:
Trying to save .wav files with new name every loop
I have built a set up with an Arduino UNO hooked up to a switch, so that whenever the switch goes from HIGH to LOW it saves audio to an SD card. I am using the TMRpcm Library. The problem is the current code will only be able to record 1 audio file; I want to the Arduino to run for a long period of time collecting multiple audio files as the switch is turned on and off. I need a way that will allow it so everytime the switch is pushed back down the next file saved will have a different name than the one previously saved (preferably by an increased numeric value eg "1.wav" & "2.wav"). I have tried audio.startRecording(audiofile+".wav", 16000, A0); and it makes it so no files save to the SD card accept an empty file simple titled 'WAV'. I have tried using a switch case but it will not allow me to reach a case over 10, without running out of RAM. Currently, my code can save 1 audio file but I want it to reach a point where it can save as many as the SD card can hold, without having to restart the software.
My current code is here. Any help would be greatly appreciated
//////////////////////////////////////// SD CARD
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10
TMRpcm audio;
//////////////////////////////////////// SWITCH CASE
int audiofile = 0;     // # of recording
unsigned long i = 0;
bool recmode = 0;      // recording state
//////////////////////////////////////// SWITCH
int inPin = 2;         // input Switch Pin
int state = HIGH;      // the current state switch
int reading;           // the current reading from the switch

void setup() {
  Serial.begin(9600);
  pinMode(A0, INPUT);  // Microphone
  pinMode(inPin, INPUT_PULLUP); // Switch
  //////////////////////////////////////// SD CARD
  SD.begin(SD_ChipSelectPin);
  audio.CSPin = SD_ChipSelectPin;
}

void loop() {

  reading = digitalRead(inPin);
  ////////////////////////////////////////
  while (i < 300000) {
    i++;
  }
  i = 0;
  ////////////////////////////////////////
  if (reading == LOW) {
    if (recmode == 0) {
      recmode = 1;

      Serial.println("Recording");

      audiofile++; // To move case
      audio.startRecording("1.wav", 16000, A0);
    }
  }
  ////////////////////////////////////////
  else if (reading == HIGH) {
    recmode = 0;

    Serial.println("Hung-Up");
    audio.stopRecording("1.wav");
  }
}

You cannot simply add an integer to a string literal with audiofile + ".WAV", because of the different types. But you can use a char buffer and sprintf("%i.WAV",audiofile);

Also asked at: https://forum.arduino.cc/index.php?topic=587263 If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information.

@chrisl Thank you very much, this almost solved all my issues!

@per1234 my apologies. I am new to forums as of today and am learning the ground rules on how to properly use them. Thank you for the heads up!

I would (and do) use snprintf to format a string as a filename:
// Global scope, or local static
uint32_t myFileNumber = 1;
char filename[12];

// in your function - results in 00000001.WAV
snprintf(filename, 12, "%08d.WAV", myFileNumber);

%08d will allow between 00000000.WAV and 99999999.WAV and always with 8 digits. Any more and it will get truncated and corrupted (100000000.WA) but won't cause a buffer overrun. You will have to take precautions that you never have more than 100 million files ;)


text:
Code getting stuck waiting for GPS Output
I'm basically trying to make a device that pulls the GPS information from a SIM808 and pushes it to a server online via GPRS.
I am sorry as I am not good at programming so ive spent days trying to debug this but i have not been able to figure out whats wrong.
Ill get the basics out of the way.
Board: Mega2560 (I know its overkill but its what i had in hand)
SIM+GPS sensor: SIM808 Module  TinyGPS v13
RTC: DS1307
Arduino IDE v1.8.8
Down to the specifics,
I started with SoftwareSerial Library but i heard it was inefficient so i switched to AltSoftSerial.
The serial library is working as I do get output using AT commands.
The problem is that when i load up the stock TinyGPS example sketch sometimes it works sometimes it gives me error saying the GPS module wasn't detected.
i tried using AT commands directly or a different GPS library but i cant figure out how to pass on data to a database over GPRS.
but basically I am sure the wiring isn't faulty nor is the GPS module (i hope) as it gives an output at ATCommands, even the RTC module is confirmed working. I know the URL in the ATCommand is fake but that is for demonstration purposes.
Coming to the code below. If i change the bool newData = false; to bool newData = true; the the code works just once with wrong GPS information.
any help would be greatly appreciated. Thank You
Edit 1: The problem has been solved, it wasn't working when i used both GPS and GPRS on SIM808 i switched to NeoGPS 6m module and GPRS from SIM800/808 it worked. Thank You.
#include <AltSoftSerial.h>
#include <TinyGPS.h>

#include <Wire.h>
#include <DS1307new.h>

TinyGPS gps;

SoftwareSerial sGPS (46,48);

uint16_t startAddr = 0x0000;  //Start address to store in NVRam
uint16_t lastAddr;        //New address to store in NVRam
uint16_t TimeIsSet = 0xaa55;  //Helper that time must not be set again

int currentDay = 0;
int currentMonth = 0;
int currentYear = 0;
int currentHour = 0;
int currentMinute = 0;

float flat, flon;
float previousFLat = 0.0;
float previousFLon = 0.0;

void setup()
{

  Serial.begin(9600);
  sGPS.begin(9600);

  /*
  Control the clock.
  Clock will only be set if NV-RAM Address does not contain 0xaa.
  DS1307 should have a battery backup.
  */

  RTC.getRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
  if (TimeIsSet != 0xaa55)
  {
    RTC.stopClock();

    RTC.fillByYMD(2011,4,8);
    RTC.fillByHMS(22,7,0);

    RTC.setTime();
    TimeIsSet = 0xaa55;
    RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
    RTC.startClock();
  }
  else
  {
    RTC.getTime();
  }

  /*
   Control Register for SQW pin which can be used as an interrupt.
*/
  RTC.ctrl = 0x00;                      // 0x00=disable SQW pin, 0x10=1Hz,
                                        // 0x11=4096Hz, 0x12=8192Hz, 0x13=32768Hz
  RTC.setCTRL();
  delay(5000);
  }

  void loop()
{
    RTC.getTime();

    currentDay = RTC.day;
    currentMonth = RTC.month;
    currentYear = RTC.year;
    currentHour = RTC.hour;
    currentMinute = RTC.minute;

  bool newData = false;

  //For one second we parse GPS data and report some key values

  for (unsigned long start = millis(); millis() - start < 1000;)

  {
  while (sGPS.available())
    {
      char c = sGPS.read();
      Serial.write(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
      newData = true;
    }

  }

  if (newData)
  {
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);

    if ((flat !=previousFLat)||(flon !=previousFLon))
    {
      previousFLat = flat;
      previousFLon = flon;
      Serial.print (previousFLat,6);
      Serial.println(previousFLon,6);
      SendSQL();
    }
  }

}

  void SendSQL()
  {

    //Serial.println("Start Send");
    Serial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
    delay(500);
    Serial.println("AT+SAPBR=3,1,\"APN\",\"airtelgprs.com\"");
    delay(500);
    Serial.println("AT+SAPBR=1,1");
    delay(500);
    Serial.println("AT+SAPBR=2,1");
    delay(3000);
    Serial.println("AT+HTTPINIT");
    delay(500);
    Serial.println("AT+HTTPARA=\"CID\",1");
    delay(500);
    Serial.print("AT+HTTPARA=\"URL\",\"www.google.com/add_data.php?");
    Serial.print("addDay=");

      if (currentDay <10)
        {
        Serial.print("0");
        Serial.print(currentDay);
        }

      else
        {
        Serial.print(currentDay);
        }

      Serial.print("/");

      if (currentMonth < 10)
        {
          Serial.print("0");
          Serial.print(currentMonth);
        }

      else
        {
          Serial.print(currentMonth);
        }

      Serial.print("/");
      Serial.print(currentYear);
      Serial.print("&addHour=");

      if (currentHour <10)
        {
          Serial.print("0");
          Serial.print(currentHour);
        }

        else

        {
          Serial.print(currentHour);
        }

        Serial.print(":");

        if (currentMinute <10)

        {
          Serial.print("0");
          Serial.print(currentMinute);
        }

        else

        {
          Serial.print (currentMinute);
        }

          Serial.print ("&addLati=");
          Serial.print(previousFLat, 6);
          Serial.print("&addLongti=");
          Serial.print(previousFLon, 6);
          Serial.println("\"");
          delay(3000);
          Serial.println("AT+HTTPACTION=0");
          delay(15000);
          Serial.println("AT+HTTPTERM");
          delay(500);
          Serial.println("AT+SAPBR=0,1");
          delay(500);
          Serial.println("Finish");
        }

what did you do to debug the problem? .... which parts worked? .... which parts failed?

tip: replace if (currentDay <10) block with only two lines if (currentDay <10) Serial.print("0"); and Serial.print(currentDay);  ...... do the similarly for the other if blocks

I agree with above answer use the Serial ports available and do something in your setup to probe the sim808 until you get some feedback I am using SIM868 in one of my projects and had the same problem of not getting any feedback until i set a while loop up in the setup that was probing by only sending 'AT' to the module (I did not use tinyGPS i only used Serial and sent it AT commands)
Here the application notes with the AT commands for the GPS side of SIM808
This approach will give you a better idea of what is happening and where you are going wrong

You have a Mega with 4 hardware serial ports. Use of those - Serial1, Serial2, Serial 3 - to talk to the GPS.
I did a project with a SIM808 module from DF Robotics.  I spent some time just powering the GPS part of it up and watching what came out.  Do the same with some simple serial print statements.
if (Serial1.available() >0){
Serial.print(Serial1.read());
}

Then when you understand what comes out, you can watch in setup() for the end of messages that indicate you have good GPS data, or just send AT commands until you get a good reply back. My module took I think 7-8 seconds before it would talk, so I just waited in setup() until I started getting messages. I knew what to expect from the above testing, it was always a fixed amount, so I grabbed all that, looked at the last few to make sure it was as expected, then started the GPS commands to see if it had good data from the satellites before continuing. I suspect the TinyGPS library does similar, but the SIM808 module added some extra characters, or you had to add extra characters, to identify GPS commands from the text message commands the SIM808 expected.

The problem has been solved, it wasn't working when i used both GPS and GPRS on SIM808 i switched to NeoGPS 6m module and GPRS from SIM800/808 it worked. Thank You.


text:
toggling Rx, Tx pins after Serial.begin
What should one expect when the following program runs on Arduino Uno?
void setup()
{
    Serial.begin(9600);
    DDRD |= 0b11;
}

void loop()
{
    PORTD |= 0b11;
    delay(100);
    Serial.print("ABCD");
    PORTD &= ~0b11;
    delay(100);
    Serial.print("DEFG\n");
}

When Serial.begin() is used, the pins PD0, PD1 might be configured as UART pins. After that if DDR is used, are the pins configured as GPIO, or are they still UART Rx, Tx pins?

what happens when you run the sketch?

As always, the answer is in the datasheet:

TXD/PCINT17 – Port D, Bit 1

TXD, Transmit Data (Data output pin for the USART). When the USART Transmitter is enabled, this pin is configured as an output regardless of the value of DDD1.
  PCINT17: Pin Change Interrupt source 17. The PD1 pin can serve as an external interrupt source.

RXD/PCINT16 – Port D, Bit 0

RXD, Receive Data (Data input pin for the USART). When the USART Receiver is enabled this pin is configured as an input regardless of the value of DDD0. When the USART forces this pin to be an input, the pull-up can still be controlled by the PORTD0 bit.

As to what trying to set the output level on the TX pin would have, only experimentation can show.  It's not defined in the datasheet (because who would do it?)


text:
Nano damaged. Power LED OK. USB Detected. No Sketch upload. No Program running
seems i damaged one of my Nanos. i have to say i am new to Arduino and have basic electronik skills and i realized after shopping via amazon that the Nanos i have are clones with CH340G.
never the less they are working. i was building a light driven open/close circuit for my chickens. using L293D motordriver, LCD, photocell. my sketch was just reading the photocell and outputting it on the LCD. not yet using the L293D in the sketch but assembled it already (without Motors and MV+).
The program was running for ~ 2 minutes. i was testing the reading for the photocell and was wondering why at low light the reading was still quite high ~ 600+. then all disappeared from the LCD apart of the background light.
as i couldnt get it running i tried to upload Blink again -> not working
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x96 code here
...
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x96
Problem beim Hochladen auf das Board. Hilfestellung dazu unter http://www.arduino.cc/en/Guide/Troubleshooting#upload.

after a while i was reading about programmers so i turned another Nano into a ArduinoISP trying to write either Booloader or Sketch via ISP bypassing USB (as i understood the different articles)
which gave
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x15
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x15

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x01
avrdude: stk500_initialize(): (a) protocol error, expect=0x14, resp=0x10
avrdude: initialization failed, rc=-1
     Double check connections and try again, or use -F to override
     this check.

avrdude: stk500_disable(): unknown response=0x12
Der ausgewählte serielle Port avrdude: stk500_disable(): unknown response=0x12
 ist nicht vorhanden oder das Board ist nicht angeschlossen

then i used Atmega_Board_Detector and Atmega_Board_Programmer which both seem to work.
output of Boarddetector:
    Atmega chip detector.
    Written by Nick Gammon.
    Version 1.20
    Compiled on Dec 27 2018 at 15:13:27 with Arduino IDE 10808.
    Attempting to enter ICSP programming mode ...
    Entered programming mode OK.
    Signature = 0x1E 0x95 0x0F
    Processor = ATmega328P
    Flash memory size = 32768 bytes.
    LFuse = 0xFF
    HFuse = 0xDE
    EFuse = 0xFD
    Lock byte = 0xEF
    Clock calibration = 0x9E
    Bootloader in use: Yes
    EEPROM preserved through erase: No
    Watchdog timer always on: No
    Bootloader is 512 bytes starting at 7E00

    Bootloader:

    7E00: 0x11 0x24 0x84 0xB7 0x14 0xBE 0x81 0xFF 0xF0 0xD0 0x85 0xE0 0x80 0x93 0x81 0x00
    7E10: 0x82 0xE0 0x80 0x93 0xC0 0x00 0x88 0xE1 0x80 0x93 0xC1 0x00 0x86 0xE0 0x80 0x93
    7E20: 0xC2 0x00 0x80 0xE1 0x80 0x93 0xC4 0x00 0x8E 0xE0 0xC9 0xD0 0x25 0x9A 0x86 0xE0
    7E30: 0x20 0xE3 0x3C 0xEF 0x91 0xE0 0x30 0x93 0x85 0x00 0x20 0x93 0x84 0x00 0x96 0xBB
    7E40: 0xB0 0x9B 0xFE 0xCF 0x1D 0x9A 0xA8 0x95 0x81 0x50 0xA9 0xF7 0xCC 0x24 0xDD 0x24
    7E50: 0x88 0x24 0x83 0x94 0xB5 0xE0 0xAB 0x2E 0xA1 0xE1 0x9A 0x2E 0xF3 0xE0 0xBF 0x2E
    7E60: 0xA2 0xD0 0x81 0x34 0x61 0xF4 0x9F 0xD0 0x08 0x2F 0xAF 0xD0 0x02 0x38 0x11 0xF0
    7E70: 0x01 0x38 0x11 0xF4 0x84 0xE0 0x01 0xC0 0x83 0xE0 0x8D 0xD0 0x89 0xC0 0x82 0x34
    7E80: 0x11 0xF4 0x84 0xE1 0x03 0xC0 0x85 0x34 0x19 0xF4 0x85 0xE0 0xA6 0xD0 0x80 0xC0
    7E90: 0x85 0x35 0x79 0xF4 0x88 0xD0 0xE8 0x2E 0xFF 0x24 0x85 0xD0 0x08 0x2F 0x10 0xE0
    7EA0: 0x10 0x2F 0x00 0x27 0x0E 0x29 0x1F 0x29 0x00 0x0F 0x11 0x1F 0x8E 0xD0 0x68 0x01
    7EB0: 0x6F 0xC0 0x86 0x35 0x21 0xF4 0x84 0xE0 0x90 0xD0 0x80 0xE0 0xDE 0xCF 0x84 0x36
    7EC0: 0x09 0xF0 0x40 0xC0 0x70 0xD0 0x6F 0xD0 0x08 0x2F 0x6D 0xD0 0x80 0xE0 0xC8 0x16
    7ED0: 0x80 0xE7 0xD8 0x06 0x18 0xF4 0xF6 0x01 0xB7 0xBE 0xE8 0x95 0xC0 0xE0 0xD1 0xE0
    7EE0: 0x62 0xD0 0x89 0x93 0x0C 0x17 0xE1 0xF7 0xF0 0xE0 0xCF 0x16 0xF0 0xE7 0xDF 0x06
    7EF0: 0x18 0xF0 0xF6 0x01 0xB7 0xBE 0xE8 0x95 0x68 0xD0 0x07 0xB6 0x00 0xFC 0xFD 0xCF
    7F00: 0xA6 0x01 0xA0 0xE0 0xB1 0xE0 0x2C 0x91 0x30 0xE0 0x11 0x96 0x8C 0x91 0x11 0x97
    7F10: 0x90 0xE0 0x98 0x2F 0x88 0x27 0x82 0x2B 0x93 0x2B 0x12 0x96 0xFA 0x01 0x0C 0x01
    7F20: 0x87 0xBE 0xE8 0x95 0x11 0x24 0x4E 0x5F 0x5F 0x4F 0xF1 0xE0 0xA0 0x38 0xBF 0x07
    7F30: 0x51 0xF7 0xF6 0x01 0xA7 0xBE 0xE8 0x95 0x07 0xB6 0x00 0xFC 0xFD 0xCF 0x97 0xBE
    7F40: 0xE8 0x95 0x26 0xC0 0x84 0x37 0xB1 0xF4 0x2E 0xD0 0x2D 0xD0 0xF8 0x2E 0x2B 0xD0
    7F50: 0x3C 0xD0 0xF6 0x01 0xEF 0x2C 0x8F 0x01 0x0F 0x5F 0x1F 0x4F 0x84 0x91 0x1B 0xD0
    7F60: 0xEA 0x94 0xF8 0x01 0xC1 0xF7 0x08 0x94 0xC1 0x1C 0xD1 0x1C 0xFA 0x94 0xCF 0x0C
    7F70: 0xD1 0x1C 0x0E 0xC0 0x85 0x37 0x39 0xF4 0x28 0xD0 0x8E 0xE1 0x0C 0xD0 0x85 0xE9
    7F80: 0x0A 0xD0 0x8F 0xE0 0x7A 0xCF 0x81 0x35 0x11 0xF4 0x88 0xE0 0x18 0xD0 0x1D 0xD0
    7F90: 0x80 0xE1 0x01 0xD0 0x65 0xCF 0x98 0x2F 0x80 0x91 0xC0 0x00 0x85 0xFF 0xFC 0xCF
    7FA0: 0x90 0x93 0xC6 0x00 0x08 0x95 0x80 0x91 0xC0 0x00 0x87 0xFF 0xFC 0xCF 0x80 0x91
    7FB0: 0xC0 0x00 0x84 0xFD 0x01 0xC0 0xA8 0x95 0x80 0x91 0xC6 0x00 0x08 0x95 0xE0 0xE6
    7FC0: 0xF0 0xE0 0x98 0xE1 0x90 0x83 0x80 0x83 0x08 0x95 0xED 0xDF 0x80 0x32 0x19 0xF0
    7FD0: 0x88 0xE0 0xF5 0xDF 0xFF 0xCF 0x84 0xE1 0xDE 0xCF 0x1F 0x93 0x18 0x2F 0xE3 0xDF
    7FE0: 0x11 0x50 0xE9 0xF7 0xF2 0xDF 0x1F 0x91 0x08 0x95 0x80 0xE0 0xE8 0xDF 0xEE 0x27
    7FF0: 0xFF 0x27 0x09 0x94 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x04 0x04

    MD5 sum of bootloader = 0xFB 0xF4 0x9B 0x7B 0x59 0x73 0x7F 0x65 0xE8 0xD0 0xF8 0xA5 0x08 0x12 0xE7 0x9F
    Bootloader name: optiboot_atmega328

    First 256 bytes of program memory:

    00: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    10: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    20: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    30: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    40: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    50: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    60: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    70: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    80: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    90: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    A0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    B0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    C0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    D0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    E0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    F0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF

    Programming mode off.

Output of Board Programmer:
    Atmega chip programmer.
    Written by Nick Gammon.
    Version 1.38
    Compiled on Dec 27 2018 at 15:15:38 with Arduino IDE 10808.
    Attempting to enter ICSP programming mode ...
    Entered programming mode OK.
    Signature = 0x1E 0x95 0x0F
    Processor = ATmega328P
    Flash memory size = 32768 bytes.
    LFuse = 0xFF
    HFuse = 0xDE
    EFuse = 0xFD
    Lock byte = 0xEF
    Clock calibration = 0x9E
    Type 'L' to use Lilypad (8 MHz) loader, or 'U' for Uno (16 MHz) loader ...
    Using Uno Optiboot 16 MHz loader.
    Bootloader address = 0x7E00
    Bootloader length = 512 bytes.
    Type 'Q' to quit, 'V' to verify, or 'G' to program the chip with the bootloader ...
    Erasing chip ...
    Writing bootloader ...
    Committing page starting at 0x7E00
    Committing page starting at 0x7E80
    Committing page starting at 0x7F00
    Committing page starting at 0x7F80
    Written.
    Verifying ...
    No errors found.
    Writing fuses ...
    LFuse = 0xFF
    HFuse = 0xDE
    EFuse = 0xFD
    Lock byte = 0xEF
    Clock calibration = 0x9E
    Done.
    Programming mode off.
    Type 'C' when ready to continue with another chip ...

other observations:
when trying to upload a sketch the rx LED blinks where thin a few times but not bright and at the speed it usually does. the L LED blinks at power on a few times.
i have 2 questions:

can you see anything in my circuit that could have damaged the NANO?
any idea to recover the NANO?

i am more curious on the first question as i don't want to take out another one. the second is more curiosity what can be done on a Nano.
and i am clueless why it died as i run all the experiments individually on an UNO
attached pictures and my fight with Fritzing for the schematics.

Many Thanks already
UPDATE:
just recognized that also my working NANOs can not be programmed via ArduinoISP Sketch using a Programmer NANO. so as the tools from Nick Gammon.
are working https://github.com/nickgammon/arduino_sketches. i assume my chip is working and it is up to the USB Chip or connection.
UPDATE2:
my NANO is fully back in live. what ever happened seems to have corrupted my flash. so after the TIPs from @Majenko with the 10uF Cap between Reset and GND i was able to programm via a "Programmernano". but here is another catch
when you first flash bootloader and then right away flash a sketch via programmer as well, this erases again the bootloader. you can check this with the
Atmega chip detector.
Written by Nick Gammon.
    Bootloader is 2048 bytes starting at 7800

    Bootloader:

    7800: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    7810: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    7820: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    7830: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF

So i just flash the Bootloader via ArduinoISP and then connect the NANO directly to USB to flash a sketch

Is GND connected in there somewhere on the protoboard.

yes it is not visible on the second picture as it is below the LCD. you can see it on the first picture

The orange wire at row 52 it looks like?  The right hand button does not appear to connect to anything at row 46, if that makes a difference.  Hard to say what a floating input pin would do without your code (could be read as High, or Low, leading to erratic behavior).

right hand button is connected to D6 under the nano board

new bootloader or old bootloader? and the selection in Tools menu?

originally it was old bootloader. i did run the  Atmega_Board_Programmer via my programmer nano and this might have updated it. i could choose lilyboot or UNO. ive choosen UNO

If you remove the Nano from the breadboard does it start working? 2. Did you disable reset on your "programming" Arduino?

I don't think the button is connected - looks to me like the wire is off by 1 hole in each picture.

@Majenko 1. it does not work even when everything is removed. 2. no i didnt do. ill search how to do this

@CrossRoads it is really hard to see at the picture but the brown cable goes into the line of the button but the metal is visible above the line before

10uf capacitor between reset and gnd.

@Majenko Many Thanks Programming with ArduinoISP is now working. Programming via USB still not ill now research the Diode

Ch340g is probably dead then

we had it here once already. after bootloader burn, tempted to upload a sketch over ISP too and deleting bootloader in the process

Try replacing the diode as in this link, it worked for me: https://forum.arduino.cc/index.php?topic=166089.0
A short on VCC might damage the diode.
As for the answer to the first question, yes there is a flaw in the design, if the external power is lost the LCD and the L293D will be powered from USB through the above diode.
"Small change" , see Juraj's comment below.

i just measured the diode with multimeter and it seems ok. same values as a working nano. as far as i read when the Diode dies the whole power via USB is dead. isnt it?

@MG52441 Yes but it can be "almost dead" at the point that the LED is still lit.  Can you check the 5V pin with a voltmeter when USB is connected? For a quick test you can short the diode keeping only the nano with USB power no external circuit and no external power.

5v Pin shows 4.67V. it will take a bit of time to the test with shortening the diode.

@MG52441 4.67V looks good to me. Is the power LED flickering when  you try to program the board? Do you use external power while programming (see the above issue)?

no not at all. when i connect usb Power LED shines bright. L LED flashes shortly. then when programming the rx led blinks w very sort and not bright at all.

i am just searching how much current the LCD and the L293D will draw. do you think it will exceed the limits posted here https://electronics.stackexchange.com/questions/67092/how-much-current-can-i-draw-from-the-arduinos-pins

ok found this http://forum.arduino.cc/index.php?topic=255472.0 seems that the LCD with backlight can draw up to 160 mA. so probably i exceeded the max. current.

i shorted the diode no change likely the CH340G is dead. thx for the Tip. ill read up on using external power

@MG52441 Tnks, I don't know if it helps but my Arduino CH340g clone needs a setting in Tools, Processor, Processor"ATmega328P" ATmega328P old bootloader to work properly.

@MG52441, why did you accept this answer?

@Juraj It seems that this was the original fault , drawing to much current from 5V line, then he messed up the bootloader. But if the OP thinks that a different answer is better I made a small change to allow him to remove his choice. Do you have a better answer to question no 1?

@Juraj probably a bit my fault as i did asked 2 questions. what is wrong with my circuit and what can be done to recover the NANO. acutally Dorians second part of the Answer was probably closest to what my main question was. i should use other power source. neverthe less i measured now the current drain and on the backlight of the LCD i have ~ 20 mA on the +5v i have ~ 46mA i didnt measured the individual Digital Pins yet. it should be still within the boundaries of what the Board can handle. so i might have accidently shortend something. i was now giving it another try and it runs well now.

Based on the output from my sketches that you have posted, the CPU chip is fine (Atmega328P). Since you cannot program via the USB port is looks likely that the CH340G is damaged.
A fall-back position is to use another one of the sketches (Atmega_Hex_Uploader) in the link you posted, and upload code via the SPI interface. To make this work you need to purchase a micro-SD card interface as described here for around $US 15.
As for why it failed, this should be investigated promptly. Possibly the answer by Dorian will help.


text:
20 m LED WS2811 Pixel Stripe 12 V
i need some help for my masterthesis.
I plan an Light and Sound installation and for this I decided to use the shape of an Dodecahedron and I want to put LED RGB Pixel Stripes on the surfaces to light the space. Imagine it like a huge ceiling light in shape of a half Dodecahedron.
What I have:

1 x Arduino Starter Kit
4 x RGB LED Pixel Stripe: BTF-LIGHTING WS2811, 5M, 60 LEDs/m, 300LEDs RGB, DC12V

(0,3W/LED = 90W/5 M (1 LED Stripe) = 360 W/20 M an in total 40A (4 LED Stripes))

2 x LED Stripe: Minger SMD 2835, 5m, 300 LEDs, Dimmable, 6000K Kaltweiß, DC12V
(?)

The half of the Dodecahedron has 6 surfaces. Each surface gets like 300 to 350 cm RGB LEDs and 150 cm of Cold White.
My plan is to program the RGB LEDs with Strobe-Light (10 Hz) and changing colours and at the End of the installation the Cold White ("Daylight") is lighten up the space. (But this is another challenge for me ;))
How to connect all of them with my Arduino Uno? Any ideas?
Thank you very much!

So, addressable RGB LED strips.  You can drive each string from an Arduino output, or daisy chain the signal thru all of them and just pump out the needed data using Adafruit Neopixel library, or the FastLED library. Make multiple power connections to keep the amount of 12V current going thru any one strip to a reasonable level.

Connect one output pin to each strip you are using.  In this video I have 4 strips connected to 4 output pins.  https://www.youtube.com/watch?v=CGOxbehyoM4

Actually, it sounds really easy. :) But I´m still afraid to connect all of it.

Here's the datasheet for the WS2811  https://cdn-shop.adafruit.com/datasheets/WS2811.pdf

Your big challenge is going to be power. Sum up the current requirements of ALL of your LED strips. Find a power supply that puts out ≈20% more than that. Read up on the max power you can pass through each strip, You can daisy-chain the power on multiple strips up to the current handling ability of the strips. Say the docs say a strip can pass max 5A through it, and each draws 1A. So you could chain the power connections of 5 of them one to the next, but no more than that. Also make sure you use power wire that's rated for your current needs. Remember your ground wires need to be heavy enough for your current needs as well. (The signal wires can be much lighter gauge.)
The signal lines don't need to follow the same topology as the power connections, but it's simpler to wire up if they do. (You could make the control lines of ALL of the LED strips in one long "snake" but run the power wires in a star pattern so the power wires don't exceed the current carrying limits of the strips or of your power wires. You could also wire both the power and the signal lines in a star pattern, and drive each point of the star with a separate Arduino pin.) You should be able to find a chart online that gives you the current carrying ability of different gauges of wire. There, too, use wire that's rated a little over the current need, just to be safe. (That chart also talks about maximum length of wire to keep the voltage drop below 2%, which is a good idea.)


text:
error while uploading a code
Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

avrdude: can't open input file C:\Users\PETER_~1\AppData\Local\Temp\arduino_build_223764/nyu_probe_activity1_code.ino.hex: No such file or directory
avrdude: read from file 'C:\Users\PETER_~1\AppData\Local\Temp\arduino_build_223764/nyu_probe_activity1_code.ino.hex' failed
An error occurred while uploading the sketch
Invalid library found in D:\programs\ArDuInO\arduino-1.8.5\libraries\OLED_Mono_I2C: D:\programs\ArDuInO\arduino-1.8.5\libraries\OLED_Mono_I2C
Invalid library found in D:\programs\ArDuInO\arduino-1.8.5\libraries\OLED_Mono_I2C: D:\programs\ArDuInO\arduino-1.8.5\libraries\OLED_Mono_I2C

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

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

Have you installed the Arduino IDE from the Windows appstore? If so, install the newest version from the official website instead, since the appstore Version is known to be faulty


text:
Do the libraries of the Arduino Uno work with the Arduino Mega?
I did a project with the Arduino Due and the libraries for the VS1053 MP3 Shield were not compatable with the Due. Are the libraries that work with the Uno compatable with the Arduino Mega?

Are the libraries that work with the Uno compatable with the Arduino Mega?

Sometimes.
They have a higher chance of being compatible, due to them both using the same AVR core, but since internal peripherals differ slightly there is a chance that, depending on what the library does, it won't work right.
You just have to try it and see.

The main question is: Is that shield compatible with Arduino Mega as SPI is not located on pins 10-12?

@KIIV Do you know the answer to that question?

If it's this one then I would suspect that yes it is. Pins 11 to 13 are linked directly to the SPI header (note: this means you can't use pins 11-13 for other things on the Due/Mega).


text:
SIlly PID question using the PID library
I'm new to PID.
My goal: control the motor to get it to run a given RPM by a potmeter (which is setpoint).
Sensor is optical (detects white line, reflections), counts 100 round in x amount of time. Small calculation gives detected RPM.
I'm using an Arduino and the PID library.
Now my question.
Let's say I've implemented the PID lib on the arduino. It all calculates and so on, but it gives a PID_value which I don't understand.
Ex:
setpoint = 5000
detected = 4999
received PID value = 40
It's my guess that this (or rather: all) PID-lib I'm using always gives a value between 0 and 255 and I have to map/scale that value to my AC trigger.
Could someone point me in the right direction? Thanks!

Which PID library? Can you post your code?

See PID Library - SetOutputLimits() - you can change the limits.
For a meaningful result you need to make the output do something reasonable to the speed. Since your detected speed is lower than the desired speed, you have found it outputs a positive value, which is good, as far as it goes. But you have to interpret that in the context of what you are currently sending to the motor. If you are using PWM to control the motor you could feed the output (40 in this case) to the motor. If that makes it go even slower hopefully the PID library will compensate.
It's hard to make more suggestions without seeing the code.

you, sir, are a genius. Thank you, my brain did stop at #include <PID.h> I will look into the RTFM bit of PID....


text:
New code results in audio noise
I am working on a circuit that can record audio to an SD when a switch is HIGH and stop recording when the switch is LOW. I am using the TMRpcm library. I previously had an issue solved on these two forumsRecording Audio - Film Name Errorand Trying to save .wav files with new name every loop. These solutions solved my problem but have left me with a new one. Currently the audio recorded on the new code (which I have pasted below) results is a very noisy and muffled audio quality; while the audio recorded on the old code (also posted below) is very clear. Could this be a physical issue and if so what should I do about it? Or is it an issue I am missing in the code?
OLD CODE - provides good quality audio
//////////////////////////////////////// SD CARD
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10
TMRpcm audio;
//////////////////////////////////////// SWITCH CASE
int audiofile = 0;     // # of recording
unsigned long i = 0;
bool recmode = 0;      // recording state
//////////////////////////////////////// SWITCH
int inPin = 2;         // input Switch Pin
int state = HIGH;      // the current state switch
int reading;           // the current reading from the switch

void setup() {
  Serial.begin(9600);
  pinMode(A0, INPUT);  // Microphone
  pinMode(inPin, INPUT_PULLUP); // Switch
  //////////////////////////////////////// SD CARD
  SD.begin(SD_ChipSelectPin);
  audio.CSPin = SD_ChipSelectPin;
}

void loop() {

  reading = digitalRead(inPin);
  ////////////////////////////////////////
  while (i < 300000) {
    i++;
  }
  i = 0;
  ////////////////////////////////////////
  if (reading == LOW) {
    if (recmode == 0) {
      recmode = 1;

      Serial.println("Recording");

      audiofile++; // To move case
      switch (audiofile) {
        case 1: audio.startRecording("1.wav", 16000, A0); break;
        case 2: audio.startRecording("2.wav", 16000, A0); break;
        case 3: audio.startRecording("3.wav", 16000, A0); break;
        case 4: audio.startRecording("4.wav", 16000, A0); break;
        case 5: audio.startRecording("5.wav", 16000, A0); break;
        case 6: audio.startRecording("6.wav", 16000, A0); break;
        case 7: audio.startRecording("7.wav", 16000, A0); break;
        case 8: audio.startRecording("8.wav", 16000, A0); break;
        case 9: audio.startRecording("9.wav", 16000, A0); break;
        case 10: audio.startRecording("10.wav", 16000, A0); break;
      }
    }
  }
  ////////////////////////////////////////
  else if (reading == HIGH) {
    recmode = 0;

    Serial.println("Hung-Up");
    switch (audiofile) {
      case 1: audio.stopRecording("1.wav"); break;
      case 2: audio.stopRecording("2.wav"); break;
      case 3: audio.stopRecording("3.wav"); break;
      case 4: audio.stopRecording("4.wav"); break;
      case 5: audio.stopRecording("5.wav"); break;
      case 6: audio.stopRecording("6.wav"); break;
      case 7: audio.stopRecording("7.wav"); break;
      case 8: audio.stopRecording("8.wav"); break;
      case 9: audio.stopRecording("9.wav"); break;
      case 10: audio.stopRecording("10.wav"); break;
    }
  }
}

NEW CODE - poor quality audio
//////////////////////////////////////// SD CARD
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10
TMRpcm audio;
//////////////////////////////////////// SWITCH CASE
unsigned int i = 0;     // # of recording
unsigned long d = 0;
bool recmode = 0;      // recording state
//////////////////////////////////////// SWITCH
int inPin = 2;         // input Switch Pin
int state = HIGH;      // the current state switch
int reading;           // the current reading from the switch

void setup() {
  //Serial.begin(9600);
  pinMode(A0, INPUT);  // Microphone
  pinMode(inPin, INPUT_PULLUP); // Switch
  //////////////////////////////////////// SD CARD
  SD.begin(SD_ChipSelectPin);
  audio.CSPin = SD_ChipSelectPin;
}

void loop() {
  char buffer[50];
  sprintf(buffer, "%i.wav", i++);
  reading = digitalRead(inPin);
  ////////////////////////////////////////
  while (d < 300000) {
    d++;
  }
  d = 0;
  ////////////////////////////////////////
  if (reading == LOW) {
    if (recmode == 0) {
      recmode = 1;

      //Serial.println("Recording");

      audio.startRecording(buffer, 1600, A0);
      //Serial.println(buffer);
    }
  }
  ////////////////////////////////////////
  else if (reading == HIGH) {
    recmode = 0;

    //Serial.println("Hung-Up");

    audio.stopRecording(buffer);
  }
}

Old code:
audio.startRecording("1.wav", 16000, A0);

New code:
audio.startRecording(buffer, 1600, A0);

Spot the typo?

Thank you, I have no idea how I missed that (16000)

Easily done. It just takes a fresh pair of eyes.


text:
comprehensive list of common library methods that do not work in interrupt service routines
Where is a comprehensive and authoritative list of commonly used library or built-in methods (functions) that do not work properly in Arduino interrupt service routines?
I am aware of the following:

do not use delay()
do not use Serial print methods

which are part of Nick Gammon's advice linked here. His TLDR summary is:

TL;DR :
When writing an Interrupt Service Routine (ISR):
Keep it short
Don't use delay ()
Don't do serial prints
Make variables shared with the main code volatile
Variables shared with main code may need to be
            protected by "critical sections" (see below)
Don't try to turn interrupts off or on

however, I am looking for, as I said, a list that is more comprehensive and authoritative.

An authoritive list (for example by the Arduino foundation) would only be able to include libraries developed by this authority. That wouldn't include most of the available libraries. Nobody wants to garantee for a library, of which he is not an author.

... that do not work properly in Arduino interrupt service routines ...

A much safer approach would be to ask what does work properly in an ISR. Considering that my advice was to "keep it short" that would tend to exclude calling any functions except ones which are known to be OK. For example, calling millis() or micros() to find out the current timer values would be OK (bearing in mind that the figures returned by millis() will not increment).
Anything complex enough to be placed in a library would tend to be excluded simply based on that, in my opinion, unless specifically documented otherwise.
So, I wouldn't try to write files, do serial output, do I2C output, drive motors, etc.
Really, what an ISR should be doing is one or more of:

Setting a flag (eg. "key has been pressed")
Note the time (eg. "Pulse received at this moment")
Retrieve some value (eg. what number is in a timer register)

Then the main code, not in an ISR, does something lengthier with that data.
The other thing to be concerned about is: Is a function re-entrant?
Just as an example, if you are doing strcpy in an ISR, is the strcpy function coded to be re-entered? (I don't know the answer just now). If it is not re-entrant, and you happen to be doing a strcpy in the main code, and the ISR also does a strcpy then one of them will be corrupted.

In terms of getting a comprehensive list, that would be almost impossible. Some libraries are no longer maintained. Others might be maintained but change from one month to the next, and the change might affect how they work inside an ISR. This is like the question people ask about "which libraries use which timers or pins?". These questions are difficult or impossible to adequately answer.

The basic rule is quite simple, but the list is practically impossible to produce.
The rule is:

You cannot use anything that relies on an interrupt to function from within an interrupt service routine.

AVR chips only have one interrupt priority. Only one interrupt routine can function at a time. If an interrupt fires whilst an ISR is currently executing that interrupt will be delayed until the ISR finishes.  If that ISR relies on a function that itself needs an ISR to fire (such as millis(), or serial transmission), then it will never get to finish.
A partial list of things to know:

You cannot transmit serial more than there is room in the TX buffer for, or it blocks.
The time generated by millis() (which delay() relies on) never changes.
Servo motors cannot be controlled and will jitter if an interrupt routine takes too long.
tone() generated sounds will also jitter since the ISR is delayed while another ISR is executing

And basically anything else that uses interrupts.


text:
avrdude: stk500_recv(): programmer is not responding: lilypad arduino
i realise this is probably the most common error that is asked about on this forum, but it is a major issue for me. i have an arduino lilypad main board (with the ATMega328P, boot loader already burned), and a generic FTDI serial to usb adapter plugged into my windows 10 laptop. When i try to upload the Blink program from the Arduino IDE, it fails with the error:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xfe
i am using a windows 10 laptop, the Arduino IDE from the windows store. this is a new lilypad, and i have never been able to upload to it. take note that when i reset the board, the pin13 light does flash (but  not the way the Blink program specifies, obviously.
i have already tried:

Rebooting my computer
Restarting the IDE
Turning the COM port on and off
Taking out the RX/TX wires from the FTDI converter
Pressing the reset button right before uploading (or during uploading)
Changing which board it is set as in the IDE
Unplugging and re-plugging the USB-Serial converter

if you have any other possible solutions they would be appreciated, thanks

does the board have a bootloader? 2)the programmer setting is ignored if you use serial upload 3) add a photo of the wiring

it does have the boot loader already, I will add a photo of the wiring tomorrow (GMT+10)

Sorry, probably irrelevant in this case, but AVRISP MKII is the enabled option in the IDE programmers section

what is "Taking out the RX/TX wires from the Lilypad"

Last time I bought one of the Lilypads, it did not have a bootloader. I had to buy a SMD programmer adapter that presses down over the 328P chip to bootload it as the board did not break out the ICSP pins to any pads.
I think I got mine here https://hobbyking.com/en_us/atmel-atmega-socket-firmware-flashing-tool.html but I haven't seen them in stock for a while.  Very handy tool tho. Another option is to tack wires to the appropriate uC pins and, connected to a 2x3 header that your Programmer can connect to. Remove the wires when done.

Thanks, how can I confirm if my Lilypad has a bootloader?

In the IDE, in File:Preferences, turn on Verbose outputs.  Press and hold reset, then start a download. When you see "Compiled xxx of 32,xxx bytes", release reset. You will see the down load attempted three times. It may take a few tries to get the timing right. If you can't ever get it working, then you probably don't have a bootloader.

the 2x3 points are for the ICSP header

Yes, I see the picture now. Add 2x3 male pins, and plug on a Programmer and put a Bootloader on the '328P.


text:
sending data with rs485
I need to read acceleration data with ADXL335 using ARDUINO MICRO (or NANO) and send this data with RS485 module to another RS485 module connected to an ARDUINO UNO (300m between RS485 modules). Treated to use the codes below but slave does not receives any data.
Data from AXDL335 are in the form "xxx  yyy  zzz"
Do I need to write in a "string format" before send with RS485 (master)??
Many thanks in advance!!
master code
#include <SoftwareSerial.h>
#define SSerialRX   10
#define SSerialTX   11
#define SSerialTxControl  3
#define RS485Transmit  HIGH
#define RS485Receive  LOW
int x;                                                // channel X  ADXL335
int y;                                                // channel Y  ADXL335
int z;                                                // channel Z  ADXL335
SoftwareSerial RS485Serial(SSerialRX, SSerialTX);
void setup() {
  Serial.begin(9600);                                 // configure baud rate monitor

  pinMode(SSerialTxControl, OUTPUT);
  digitalWrite(SSerialTxControl, RS485Receive);
  RS485Serial.begin(4800);                            // starts serial(485) and configure baud rate
}

void loop() {

 x=analogRead(0);                                     //read X in analog(0)
 y=analogRead(1);                                     //read Y in analog(1)
 z=analogRead(2);                                     //read Z in analog(2)
                                                      // print read values in monitor
 Serial.print(x);Serial.print(" ");Serial.print(y);Serial.print(" ");Serial.print(z);Serial.println(" ");
 RS485Serial.print(x);
 delay (250);

 RS485Serial.flush();
 delay (750);
 }

SLAVE CODE
#include <SoftwareSerial.h>
#define SSerialRX   10
#define SSerialTX   11
#define SSerialTxControl  3
#define RS485Transmit  HIGH
#define RS485Receive  LOW
char x;
SoftwareSerial RS485Serial(SSerialRX, SSerialTX);

void setup() {
  Serial.begin(9600);        // configure baud rate monitor
  pinMode(13, OUTPUT);
  pinMode(SSerialTxControl, OUTPUT);
  digitalWrite(SSerialTxControl, RS485Receive);
  RS485Serial.begin(4800);  // start serial(485) and configure baud rate
}

void loop()
{
 if (RS485Serial.available()>0) {
  x = RS485Serial.read();
  if (x!="n")

  Serial.print(x);Serial.println(" ");
  delay(1000);

 }
}

print will print the number as text. use write as counterpart of read or use parseInt to read text printed with print(number)

x is char. you can't compare it with a string with !=. you can compare it with a char x != 'n'. when would x be 'n'?

For 300 meters you need to do it right and avoid things that can cause troubles. I suggest to stay away from the SoftwareSerial. Use a (pro) micro with its hardware serial port. Can you tell what kind of cable it is? Can you give a link to that cable? Some cables are cheap and have almost no copper in it. What kind of rs485 modules do you use? Are you testing this on your table or already with the 300 meters in between? How often do you need the data? Perhaps a slow wireless lora module might work. Add the extra information to your question. Your master has the control pin in receive mode.

dear Jot
I apologize since I am not native English speaker. At the beginning and if it works on the bench I think of using the RS485 modules of the LC electronics where the chip is already mounted with the DI RE RE pins already connected. If it works at my desk I will push the RS485 away until I check how far the signal emitted every 1 Hz is transmitted and properly received. There I will see which type of cable (4 ways I imagine it should be) can carry the signal and also feed the arduino and the accelerometers. Thanks for your help !!


text:
How can I reduce the memory usage on my code?
I wrote this code to control my christmas tree. It takes up the majority of the memory on my Arduino Uno:
Sketch uses 31822 bytes (98%) of program storage space. Maximum is 32256 bytes.
Global variables use 1882 bytes (91%) of dynamic memory, leaving 166 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.

Does anyone know how I can reduce the memory usage?
Code:
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>

#define TREEONE 3
#define TREETWO 4
#define TREETHREE 5
#define TREEFOUR 10

SdFat sd;
SFEMP3Shield MP3player;

const uint8_t volume = 10; // MP3 Player volume 0=max, 255=lowest (off)
//10 for basement 50 for testing

const uint16_t monoMode = 1;

int song = 3;
int num = 0;
int count = 0;

//put arrays here
byte arrayTree[] = {17,16,9,8,3,2,5,4,17,16,9,8,3, ...etc };

void setup() {
  initSD();
  initMP3Player();

  pinMode(TREEONE, OUTPUT);
  pinMode(TREETWO, OUTPUT);
  pinMode(TREETHREE, OUTPUT);
  pinMode(TREEFOUR, OUTPUT);

  digitalWrite(TREEONE, HIGH);
  digitalWrite(TREETWO, HIGH);
  digitalWrite(TREETHREE, HIGH);
  digitalWrite(TREEFOUR, HIGH);
}

void loop() {
  if(!MP3player.isPlaying()){
    MP3player.playTrack(song);
    MetallicaChristmas();
  }
}

void initSD() {
  if(!sd.begin(SD_SEL, SPI_HALF_SPEED))
    sd.initErrorHalt();
  if(!sd.chdir("/"))
    sd.errorHalt("sd.chdir");
}

void initMP3Player() {
  uint8_t result = MP3player.begin();
  MP3player.setVolume(volume, volume);
  MP3player.setMonoMode(monoMode);
}

void treeFunc() {
    //delay(arrayTimes[i]);
    num = arrayTree[count];

    //TREEONE
    if(num>15){
      if((num%2)==0){
        digitalWrite(TREEONE,HIGH);
      }else{
        digitalWrite(TREEONE,LOW);
      }
    }
    //TREETWO
    if((num%16)>7){
      if((num%2)==0){
        digitalWrite(TREETWO,HIGH);
      }else{
        digitalWrite(TREETWO,LOW);
      }
    }
    //TREETHREE
    if((num%8)>3){
      if((num%2)==0){
        digitalWrite(TREETHREE,HIGH);
      }else{
        digitalWrite(TREETHREE,LOW);
      }
    }
    //TREEFOUR
    if((num%4)>1){
      if((num%2)==0){
        digitalWrite(TREEFOUR,HIGH);
      }else{
        digitalWrite(TREEFOUR,LOW);
      }
    }
  count = count + 1;
}

void MetallicaChristmas()
{
  //event 1
  delay(670);
  treeFunc();
  delay(248);
  treeFunc();
  //event 2
  delay(116);
  treeFunc();
  delay(248);
  treeFunc();
  //event 3
  delay(100);
  treeFunc();
  delay(248);
  treeFunc();
  //event 4
  delay(132);
  treeFunc();
  delay(248);
  treeFunc();
  //event 5
  delay(125);
  treeFunc();
  delay(248);
  treeFunc();
  //event 6

  ...etc.

I see some ints that could be replaced with byte, that would save a couple of bytes. Other than that, it seems to be the libraries you are using.   If you need more room tho, jump to a '1284P processor. 128K of flash, 16k SRAM. I offer boards in several form factors, your code will port right over with the MightyCore add-in to the Arduino IDE.  https://www.crossroadsfencing.com/BobuinoRev17

Please show the full sketch. How long is the arrayTree array? Is every other number 1 less than the previous number? How long is the MetallicaChristmas function? There is a smaller sdfat library, but I don't know if it is compatible with SFEMP3Shield. Read about PROGMEM and struct.

I think that if you store the delays in an array, just like arrayTree. And use PROGMEM on both arrays your code will become smaller and use less dynamic memory. And also make it easier to read/maintain.

Without a full sketch, we can not compile it ourself to see how far we can get to reduce memory usage.

O, there it is: https://arduino.stackexchange.com/questions/60109/problem-with-mp3-shield-and-function-calling-combination

As well as PROGMEM (as described in the comments), there are a couple of other efficiencies that you can make:

A function call is expensive (takes a lot of code space), and you are performing a LOT of them!

The repetitious calls to delay() followed by treeFunc() are wasteful. Your commented-out line
//delay(arrayTimes[i]);

looks like you were going to do the right thing, so I’d restore that (use count instead of i) and put the delay() numbers in a new int arrayTimes[] array.
PROGMEM this array too, of course!
Once you’ve done this, you can remove all the calls to delay(). You’ll be left with nothing but repeated calls to treefunc(), which you can replace with a single loop:
for (count=0;count<sizeof(arrayTree);++count) {
   treeFunc();
} // for

Don’t forget to get rid of the count = count + 1; line from treeFunc() - it’s now in the for loop.

Also expensive is calling the same function twice except with different parameters in both sides of the if in treeFunc(). Instead of:
if (<condition>) {
   Function(1);
} // if
else {
   Function(0);
} // else

you can instead do:
Function(<condition>);

For this to work, you need to know that HIGH has the value 1 and LOW has the value 0 - and that a true condition has the value 1 and a false condition has the value 0.
So, you need to change the if () slightly:
digitalWrite(THREEONE, (num%2)>0);

Finally, the mod % operator itself is very expensive, since it is effectively a division, and the Arduino chip doesn’t know how to divide - so the code to do so is large. But the code you’ve written is using binary arithmetic, which the Arduino can do instantly - you just have to write it as such.

Instead of (num%2)>0 use num & B0001.
Instead of (num%4)>1 use num & B0010.
Instead of (num%8)>3 use num & B0100.
Instead of (num%16)>7 use num & B1000.

You’ve probably copied the guts of this code from somewhere else, and while it works it isn’t very efficient. Writing the code as above will greatly reduce your code size, exchanging repeated calls for much smaller PROGMEM arrays.


text:
Arduino: incorrect calculation of long integer
I'm doing a simple calculation with integers (on Arduino with ESP8266 12E), but I can't get the expected result and can't find the error. Can someone guide me?
#define A      200
#define B      A * 62
#define C      500

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

   unsigned long aux = 0;

   aux = (B * 500) / C;    // (12400 * 500) / 500 = 12400
   Serial.printf("aux = %d\n", aux);
   aux = aux * C;          // 12400 * 500 = 6200000
   Serial.printf("aux = %d\n", aux);

   // ERROR: Should result in "500", but is resulting in "1922000"
   aux = aux / B;          // 6200000 / 12400 = 500

   Serial.printf("aux = %d\n", aux); // It's printing "1922000"
}

In your #define of B you missed parenthesis (). Change your definition to:
#define B      (A * 62)

Without parenthesis you first divide 6200000 by 200 and then multiply result by 62, which is not what you intend.

Dude, you're 100% right. I've spent several hours trying to figure out what was wrong ... Thank you so much!

@wBB remember that in C, macros are replaced in the code, exactly as you wrote them, in the preprocessor step before the code gets compiled. So it helps as a sanity-check in these cases to expand the macros yourself in your code to see if you're getting what you intended.

It really is was my lack of exeperience in C that led me to the problem. Thanks!

Fully-parenthesizing macros (as noted in answer by dmz) solves one class of problem.
Another thing you should do is, in any arithmetic expression which involves literal constants, use the L suffix on at least one of the constants involved if there's any chance the result will exceed 32767 (the maximum guaranteed-representable value for int). The type of an arithmetic operation in C is based on the types of the operands of that operation only; the type of the variable to which the result is assigned is irrelevant.
(edit)
For example:
long q, r;
unsigned char v = 231;
unsigned char w = 197;

q = v * w * 5;
r = v * w * 5L;

q might contain 30927, since after the Usual Arithmetic Conversions (6.3.1.8) [in this case, the Integer Promotions (6.3.1.1-2)] all operands are of type int and it's possible for INT_MAX to be 32767 in which case each operation would be performed modulo 32768.
r will contain 227535, since the constant 5L is of type long and thus all operations in this expression will be performed on values of type long.

...and the format specifier for an unsigned long is %lu not %d - the compiler for the asker's esp8266 uses a 32-bit int so they get away with some things they would not on an ATmega-based Arduino where an int is the minimum 16 bit size allowed by the specification.

@mlp usually I use a typecast on almost everything. Example: int J = -1, typecast (unsigned char) J  //prints 255. When you talk about the suffix L, what do you mean? Can you give an example?

As explained in previous answers, fully parenthesizing the macros is the
standard solution to this problem in C. However, on Arduino you are
programming in C++, and in C++ it is considered good practice to replace
this usage of #define by explicit constants:
const int A = 200;
const int B = A * 62;
const int C = 500;

Not only this makes the initial problem go away, it also provides some
type safety: you can choose to give these constants other types (e.g.
long) if appropriate.

Some compilers will interpret "const" as a variable going into program memory which then in turn results in issues with memory spaces.
Consts offer type protection, which can also be (partially) achieved by casting inside the define "#define A ((int)200)" for instance.

@le_top: Do you have a specific example of the kind of “issues with memory spaces” you can get? I doubt you could find an example that does not invoke undefined behavior.

Something along these lines for example:  "const int a=100; int b=200; void setB(const int *c) {b=c;}  void ex1() {setB(&a);}" .  But there are other cases.  When "const" puts "a" in ROM, some embedded compilers can not cope with this kind of assignment and do not report all violating cases.  So I tend to put "CONST" if there is a future risk for this.  (with a "#define CONST const" if possible).

@le_top: I guess you mean b=*c. This sounds like a compiler bug to me. What compiler had issues with this? I tried your code on avr-gcc, and it had no issues, even when I replaced const by __flash const, which has the effect of putting a in flash.

Yes, b=*c.  It will depend on the compiler and the uC.  I file reports when I find bugs - when the compiler does not warn about it it is a bug, but otherwise it is a documented limitation.On Arduino you should use PROGMEM rather than __flash.  I do not want to put a specific compilrer forward, my comment was mainly about warning that there are compilers for embedded systems that interpret const in a way that breaks code compatibility.  That's also why you're required to add "__flash" to get the variable in FLASH - keeping it in RAM eases code generation (and speed) for those processors.


text:
Servo motor rotates back to 0 after reaching destination
I am using a XMG-996R servo motor. It is controlled by and Arduino Uno board. The problem is when I tell it to go to a certain angle, it will rotate to the desired position but then return to 0. The motor keeps rotating back and forth between the destination and 0 degrees. I tried this with different servos and they all do the same.
I am using 3 AA batteries as an external power supply. I have also tried using 4 AA batteries or a 9V battery. The same thing happens no matter the power supply.
My control wire is connected to the Arduino, positive is connected to the external power source. The negative is connected to the ground of the power source and the ground of the Arduino.
This is my code:
include <Servo.h>

Servo servo;

void setup(){
   servo.attach(9);
   servo.write(90);
}

void loop(){

}

I have also tried putting the write() into loop as well as putting servo.write() before servo.attach(). neither of these methods made a difference.
What can I do to make the servo rotate to the given degree and stay at that degree? Thanks.

This belongs in an Arduino forum, but I think you need to keep calling write to constantly send pulses to it. Move write into the main.

Yes, I tried that. the same thing happened. I increasing the amps. This fixed part of the problem. Now the servo rotates past the target, to the machine limit, back to the target degree and stops.

I put a ceramic capacitor on the motor, now it works fine.