text:
How do I inherit a class that requires &foo() in its constructor?
General
I have a library with a class constructor class Math(&foo1,&foo2);, which I would like to put into a library for class Algebra(), where foo1 and foo2 are defined in Algebra.cpp
My current constructor Algebra::Algebra():Math(&Algebra::foo1,&Algebra::foo2) is returning an error in the Arduino IDE to the effect of:
error: no matching function for call to 'Math::Math(void (Algebra::*)(long unsigned int, byte), byte (Algebra::*)(long unsigned int))':Math(&Algebra::foo1, &Algebra::foo2)
Meta Note: I believe this is on topic because I'm dealing specifically with developing code for the Arduino Mega using libraries and hardware components designed for Arduino. If I am in error, and there is a better exchange for this question please let me know

Specifically,
I'm writing a library to combine Adafruit's I2C FRAM with the Extended database library (I have validated that the libraries work when called into a sketch independently, but I'd like to combine them to be more easily inheritable in [Big_Machine_api.h] that I will be making later)
I'm testing my library with this sketch:
/*
 EDB_AT24C1024.pde
 Extended Database Library + Adafruit_FRAM_I2C EEPROM Test Sketch

 The Extended Database library project page is here:
 http://www.arduino.cc/playground/Code/ExtendedDatabaseLibrary

 The Adafruit_FRAM_I2C library project page is here:
 https://github.com/adafruit/Adafruit_FRAM_I2C

 */
#include "Arduino.h"
#include <Wire.h>
#include <Adafruit_FRAM_I2C_EDB.h>
#define TABLE_SIZE 131072

// Arbitrary record definition for this table.
// This should be modified to reflect your record needs.
struct LogEvent {
  int id;
  unsigned long Rotations;
}
logEvent;

// Create an EDB object with the appropriate write and read handlers
Adafruit_FRAM_I2C_EDB db;

// Run the demo
void setup() {
  Serial.begin(115200);
  Serial.println("DONE");
}

void loop() {
}

My ADAFRUIT_FRAM_I2C_EDB.h file:
#ifndef ADAFRUIT_FRAM_I2C_EDB_h
#define ADAFRUIT_FRAM_I2C_EDB_h

#include <Arduino.h>
#include <Adafruit_FRAM_I2C.h>
#include <EDB.h>

#define MB85RC_DEFAULT_ADDRESS        (0x50) /* 1010 + A2 + A1 + A0 = 0x50 default */

class Adafruit_FRAM_I2C_EDB : public EDB {
 public:
  Adafruit_FRAM_I2C_EDB(uint8_t addr = MB85RC_DEFAULT_ADDRESS);
  void getDeviceID(uint16_t *manufacturerID, uint16_t *productID);

 private:
  Adafruit_FRAM_I2C _fram;
  uint8_t _FRAMaddr;
  void writer(unsigned long address, byte data);
  byte reader(unsigned long address);

};
#endif

My ADAFRUIT_FRAM_I2C_EDB.cpp file:
#include "Arduino.h"
#include "Adafruit_FRAM_I2C.h"
#include "EDB.h"
#include "Adafruit_FRAM_I2C_EDB.h"
Adafruit_FRAM_I2C_EDB::Adafruit_FRAM_I2C_EDB(uint8_t addr)
:_FRAMaddr(addr),EDB(&Adafruit_FRAM_I2C_EDB::writer, &Adafruit_FRAM_I2C_EDB::reader) {
  _fram = Adafruit_FRAM_I2C();
  _fram.begin(_FRAMaddr);
}

void Adafruit_FRAM_I2C_EDB::getDeviceID(uint16_t *manufacturerID, uint16_t *productID) {
  _fram.getDeviceID(manufacturerID, productID);
}

void Adafruit_FRAM_I2C_EDB::writer(unsigned long address, byte data) {
  _fram.write8(address, data);
}

byte Adafruit_FRAM_I2C_EDB::reader(unsigned long address) {
  return _fram.read8(address);
}

Full Error List:
C:[...]\Arduino\libraries\Adafruit_FRAM_I2C_EDB\Adafruit_FRAM_I2C_EDB.cpp:16:84: note: candidates are:

In file included from C:[...]\Arduino\libraries\Adafruit_FRAM_I2C_EDB\Adafruit_FRAM_I2C_EDB.cpp:3:0:

C:[...]\Arduino\libraries\EDB-master/EDB.h:54:5: note: EDB::EDB(void (*)(long unsigned int, uint8_t), uint8_t (*)(long unsigned int))

     EDB(EDB_Write_Handler *, EDB_Read_Handler *);

     ^

C:[...]\Arduino\libraries\EDB-master/EDB.h:54:5: note:   no known conversion for argument 1 from 'void (Adafruit_FRAM_I2C_EDB::*)(long unsigned int, byte) {aka void (Adafruit_FRAM_I2C_EDB::*)(long unsigned int, unsigned char)}' to 'void (*)(long unsigned int, uint8_t) {aka void (*)(long unsigned int, unsigned char)}'

C:[...]\Arduino\libraries\EDB-master/EDB.h:50:7: note: constexpr EDB::EDB(const EDB&)

 class EDB {

       ^

C:[...]Arduino\libraries\EDB-master/EDB.h:50:7: note:   candidate expects 1 argument, 2 provided

C:[...]Arduino\libraries\EDB-master/EDB.h:50:7: note: constexpr EDB::EDB(EDB&&)

C:[...]\Arduino\libraries\EDB-master/EDB.h:50:7: note:   candidate expects 1 argument, 2 provided

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

You only use &foo when constructing if the constructor needs *foo.

Ok, my constructor  Algebra::Algebra():Math(Algebra::foo1,Algebra::foo2) results in error: invalid use of non-static member function:Math(Algebra::foo1, Algebra::foo2) Where would I go from here?

Algebra::Algebra(FooType &foo1, FooType &foo1):Math(foo1, foo2)?

You just pass the variables to the parent constructor in the initialization list of the child. No need for qualifications or anything like that.
Here's an example that compiles:
class Math {
    private:
        int _foo1;
        int _foo2;

    public:
        Math(int &foo1, int &foo2) : _foo1(foo1), _foo2(foo2) {}
};

class Algebra : public Math {
    private:
        int myFoo1 = 12;
        int myFoo2 = 34;

    public:
        Algebra() : Math(myFoo1, myFoo2) {}
};

Math's constructor takes two integers passed by reference.  The Algebra constructor's initialization list calls the parent Math constructor with two of its own member integers that are then automatically passed by reference, since that is what the constructor calls for.
However, that isn't what your actual problem is. You're asking about one thing, then showing an error that is for a completely different problem.
You have a constructor (actually any function will do the same) that expects a pair of pointers to two functions:

void (*)(long unsigned int, uint8_t)
uint8_t (*)(long unsigned int)

That is, you need two functions, such as:
void reader(unsigned long a, uint8_t b) {
}

and
uint8_t writer(unsigned long a) {
    return 3;
}

But instead you are attempting to pass member functions of a class.  The problem here is that although they look the same, because they are class members they aren't the same.
Any class member function has an additional implied parameter, which is a pointer to the containing class instance and is called this.  So your functions actually look more like:
void reader(Adafruit_FRAM_I2C_EDB *this, unsigned long a, uint8_t b) {
}

and
uint8_t writer(Adafruit_FRAM_I2C_EDB*this, unsigned long a) {
    return 3;
}

(Note: that's only an approximation - it's actually a lot more involved than that, but it serves to illustrate the problem).  As you can see that doesn't match what is expected, and so you can't pass those functions to the parent constructor - they're simply wrong.
This is a commonly occuring problem - often seen when trying to use a class member function with attachInterrupt(). You just can't do it.  Or not like that anyway.
The only way of passing a member function directly is for that member function to be static. That then acts like a normal function, and there is no this parameter. However, it can only act on other static variables and functions. So using it takes a little more care - plus of course static functions and variables are shared between all instances of a class.

Is there a way I can edit the constructor to accept void writer (Class *this, unsigned long a, uint8_t b) and uint8_t reader (Class *this, unsigned long a) ? I've been trying to make it work, but my FRAM library does not seem to want to work as a static function.

The parent class would need to know about the child class and explicitly include it in the prototype. Either that or you create a separate interface class that the parent uses in the prototype and the child inherits from. Personally I wouldn't take either route, but would have the parent define some pure virtual read/write function stubs and then create a child class that implements those stubs.


text:
Can the Arduino interface with USB devices without the USB host shield?
I'm looking to connect various USB-devices to an Arduino Uno (specifically, a gamepad and a webcam, but I'm interested in the general case). Is this possible without using the USB host shield, since the Uno has a USB port and USB-to-serial converter? I could use the shield, but I'm curious if/why it's neccessary.
The Sparkfun website states that:

The SparkFun USB Host Shield contains all of the digital logic and analog circuitry necessary to implement a full-speed USB peripheral/host controller with your Arduino.

Does the Arduino not already contain this, just needing the proper software (although obviously it's easier to use the already written library for the Host Shield). Or are there hardware limitations?
According to
Can a Ethernet USB Dongle be instead of ethernet shield for arduino?
(Majenko's answer), it can, in theory, be done with the Due, but not with the Uno. In that case, is this because the Uno uses the ATmega16U2 instead of the FTDI FT232RL for USB communication?

I don't think it is impossible, USB is some kind serial bus with specific protocols, i.e. device tagging splitting devices to specific time ranges (some similar protocols like one wire). I think the only limitation is speed, therefore syncing all the USB specific commands and data is the thing that causes trouble,

@GeneralChaos You're right, it's not "impossble" - but it is highly impractical. There is a software implementation of a USB device (VUSB) which doesn't need any special hardware. It's iffy at best and barely works at the best of times. There is no reason why you couldn't write a host equivalent - however, it could never work at anything more than the 1.5MHz of USB 1.0 "Low Speed", so could never talk to anything other than a simple keyboard or mouse.  Things like ethernet or webcams are completely impossible without Host or OTG hardware, which the Due has built in to the main chip.

First things first you need to learn the basics of how USB works.
In USB there are two main "things": Hosts and Devices.
You have one Host (usually your computer) and many Devices (such as Arduinos, Printers, Scanners, Webcams, WiFi dongles, etc).
Being a host involves knowing about what devices you are going to have attached to you and how to communicate with them. Being a device means just communicating with the host in your own way.
As you can see it is a far more complex job being a host than being a device.
Arduinos are devices. The small USB interface chips they use are very low powered and can only be a device, never a host.
If you want to plug a device into something it has to be a host (note: I am purposely ignoring hubs here).
The Arduino Due uses a far more powerful chip, and that is capable of being a host (using what is known as On-The-Go mode).
To do it with anything less powerful than a Due you require additional hardware that is specifically designed to be a USB host - and that is where the USB host shield comes in. It has a chip that is designed specially to be a USB host so you can plug a device in to it.
None of the chips on the Uno are designed to be a host. They just don't have the power.

No.  USB strictly distinguishes between host and device roles.  A few chips have functional blocks capable of performing either role, but the 8u2/16u2 are not examples of this.
Typical USB serial converters like the FT232, CP210x, CH340, PL2303, etc are also strictly devices and incapable of being hosts
There are inexpensive host-capable MCUs like the Kinetis KL25Z, but to use them in their cheapest form you would need a different software approach (for example mbed rather than Arduino) and a lot more personal effort.  The Teensy-LC is related, but you pay more for the Arduino code loading helper on it than for the MCU that runs your program itself.

source: Stack Exchange

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

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

sort: votes


text:
SoftwareSerial receives beginning of data mangled
I'm using SoftwareSerial to communicate with a Sigfox module. Documentation for the read function assigns its value to a char. However using it I get mangled characters and also have read in other question that I should assign it to int as it can return -1 for no data and [0;255] for received character.
This is my basic troubleshooting example:
#include <SoftwareSerial.h>
SoftwareSerial Sigfox(11,10);

void setup() {
  Serial.begin(9600); // HW serial
  Sigfox.begin(9600); // SW serial --> sigfox
}

void loop() {
  if(Sigfox.available()) {
    int c = Sigfox.read();
    Serial.write(c);
  }
  if(Serial.available()) Sigfox.write(Serial.read());
}

When c is char, I get -5 instead of OK. Also other output is mangled. When c is int, it receives the data OK.
My question is - why they use char in the example in documentation? Why is char signed in Arduino?
I want to read the entire line of text from serial port and store it into array. How to define that array? I have found an example on web that uses char buffer[32], but then again I get mangled data when I assign to it. If I use array of byte/int/unsigned char, I can't print it as Serial.write(SF_buffer); won't compile because of no matching function for call to 'write(unsigned char [32])'.
So what variable types should I use to receive and store the text from SoftwareSerial correctly?
Here is my function for reading the whole line:
unsigned char SF_buffer [32]; // max length of line to read from serial
bool SigfoxReadine() { // return true when whole line was received and is in buffer
  static int SF_cnt=0;
  while (Sigfox.available()) {
    int c = Sigfox.read();
    SF_buffer[SF_cnt++] = c;
    if ((c == '\n') || (SF_cnt == sizeof(SF_buffer)-1)) {
       SF_buffer[SF_cnt] = '\0';
       SF_cnt = 0;
       return(true);
    }
  }
  return(false);
}

UPDATE:
Trying readBytesUntil - the same result, but I have found that issue is only when I send data to module using println as in this example:
#include <SoftwareSerial.h>
SoftwareSerial Sigfox(11,10);

void setup() {
  Serial.begin(9600); // HW serial
  Sigfox.begin(9600); // SW serial --> sigfox
  Sigfox.println("AT$I=11");
}

void loop() {
  if(Serial.available()) Sigfox.write(Serial.read());
  SF_read();
}

void SF_read() {
  if (Sigfox.available()) {
    char buff[32];
    int l = Sigfox.readBytesUntil('\n', buff, sizeof(buff));
    if (l > 0 && buff[l - 1] == '\r') {
      l--; // to remove \r if it is there
    }
    buff[l] = 0; // terminate the string
    Serial.println(buff);
  }
}

The response to first command (in setup) is mangled. The response to the same AT command manually written into serial monitor (and sent to module via Sigfox.write in loop) is OK.

ӂ*⸮FBB1E27EE7
3430E2FBB1E27EE7

Also maybe I'm little lost in when to use print and when write... Example says to use write() to send back the char that was read(). Juraj's response uses println() to print the null-terminated buffer. What is the difference when I write/println this buffer?

refer to this when dealing with char data type ... http://www.asciitable.com/

yes, using int data type is advisable ... if you use byte data type, then there is a conflict between data and an error flag ... a -1 is equivalent to hex 0xff, which is decimal 255 .... for int type, the decimal 255 is represented as 0x00ff and -1 is represented as 0xffff ... no conflict between those two .... please note that only a single byte is transmitted over serial ... the two byte int is created by the serial library so that your sketch has a way of receiving an error status from the library

Serial.write(SF_buffer, length); or for null terminated char array Serial.print(SF_buffer);

@Juraj if SF_buffer is char type, I get mangled output (SF_buffer[SF_cnt++]=c;). How to assign the int c into the char array correctly?

use byte. does the devices send characters with ascii codes above 127?

@Juraj usually not. But with char I got mangled for example original "OK" into "-5". I think I tried byte yesterday, but will try again when I get home.

did you wire ground? Serial.write(Sigfox.read()); must work

@Juraj yes I did :) That one works. It breaks when I save the value from read to variable and try to write that variable back. If I save it to char, "OK" prints as "-5". If I save it as byte or int, it prints OK, but then I have issue how to save whole line into array of chars.

what Arduino do you use?

@Juraj Arduino Pro Mini, Serial is connected to FTDI and USB. SoftwareSerial is Sigfox Wisol module. Arduino 1.8.9.

I like the readBytes or readBytesUntil function. It doesn't end on a small gap between received bytes and fills the buffer. This functions are blocking with timeout, but if read some other device the input is usually fast and terminated reliably.
example for readBytesUntil:
if (Serial.available()) {
  char buff[32];
  int l = Serial.readBytesUntil('\n', buff, sizeof(buff));
  if (l > 0 && buff[l - 1] == '\r') {
    l--; // to remove \r if it is there
  }
  buff[l] = 0; // terminate the string
  Serial.println(buff);
}

does readBytes exist also for SoftwareSerial? Documentation mentions it only for Serial

it is in the Stream base class

@Marki555, did it help?

testing... seems more strange now :) the issue from yesterday now seems to exist only when sending data to via Sigfox.println and not when using Sigfox.write...

edited the question with new findings

Found the issue! Thanks for troubleshooting help.

Last test showed it mangles data only when using println() and doesn't depend on the char type. Then I remembered something about CRLF in the Sigfox datasheet:

Is recommended to use full duplex UART. In case of using half duplex, AT
  commands has to be ended only with one of ‘\r’ or ‘\n’ not both. Because if you send
  “AT\r\n” the Sigfox devkit starts sending “OK” instantly after it receive ‘\r’, but
  microcontroller is still sending byte ‘\n’.

SoftwareSerial is in fact half-duplex only (although I didn't find it in the reference documentation) and println() sends both '\r' and '\n', so while sending the later, Sigfox module is already trying to send back the answer, which gets mangled by SoftwareSerial.
Feel free to add your answer to explain why char is signed in Arduino and when to use print() and when write() with serial port.

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


text:
What shift register would I need for input OR output?
Background:
A few days ago I received a 23LC1024 1Mbit SRAM chip, which works like a charm.
However, before I ordered that one, I ordered a LP621024D-70LL which also is a 1 Mbit SRAM but in DIP32 format, meaning LOTS of pins.
Now I made a breadboard setup with 3 shift registers 74HC595 to be able to set the address (tested with LEDs but should work).
However, when trying use a shift register for the data which can be read or write, I don't think I can use a 74HC595 since it is only for output. However, I also don't think a 74HC165 (shift in register) would work (if I had one).
Questions:

What kind of shift register would I need, one that can do both input and output? I read about I2C registers but that seems to be a bit of overkill.
I only have 74HC595 shift registers for setting the address, would that slow down SRAM? I mean are there faster registers? Not that I want to buy it, but just curious.

Here is a picture of a working LP621024D-70LL ... too bad the chip is barely visible , on the left are 2 74HC595s and right are also 2 (right one not used), these 3 shift registers take care of the address (17 bits -> 3 bytes). The SRAM itself is hidden under the center of the cables.

Would any of   74LS194, 74LS195, 74LS395, CD4035B be relevant?

since you already have input, use an 74HC165  8-bit parallel-in/serial out shift register. They are cheap.
another cheap option with I/O is an expander like the PCF8574, which are almost cheap

Are you sure that a 74HC165 would work? Because since I now do not have any multiple-input-ic I use 8 pins which I have to set in Write mode for writing a byte, and Read mode for reading a byte. I have the 'feeling' I would need a 74HC595 for writing and a 74HC165 for reading but of course that is not possible simultaneously.

The 75HC595 has an Output Enable pin. Use that to disable the outputs of the 595 when you want to read from the 165. You don't care about what the 165 does while you're writing with the 595, it's high impedance.

Personally though I'd use an MCP23017 or MCP23S17 (depending on what bus I was using elsewhere at the same time).

I think I will try a MCP23017 or the other ... just to try :-) ... however, I already know why using a 32DIP is not a good idea (I will post a picture)

From the web page about the 23LC1024:

The memory is accessed via a simple Serial Peripheral Interface (SPI) compatible serial bus.

Using the SPI hardware on your Uno will be a lot faster than using software-based shifting. See my page about SPI.

Yes and I can fully confirm it now. To give a bit of background: I ordered a 23LC1024 but these are like 4$ and this chip above was like 1,50$. But it seems it is not worth all the extra wiring and for my project I need faster memory anyway ... I was hoping it would both be more than fast enough. But even because of the wiring I probably will not use easily this SRAM chip anymore. But I learned a lot about timing measurements, SPI and shift registers.

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


text:
How should I connect 5 buttons to arduino so that I can use the least number of inputs all the buttons are connected to ground
The problem here is that I want to connect 5 input buttons to an Arduino but I do not want to utilize 5 input pins of Arduino, is there any matrix like connection using which I can reduce the number of inputs used. The conditions here are:

All the buttons will be connected to ground and initialized using:
pinMode(PIN_NUMBER, INPUT_PULLUP)

Only digital input is required and not analogue

Look at the schematics of almost any keyboard (just Google: "keyboard schematic" and select the images tab). Are any of them using switches that are grounded on one side? There are "matrix" type solutions but your "buttons connected to ground" throws all those solutions out of the window. A one pin solution is possible if you would allow using an analog input and some resistors.

@Andyaka yes, only one at a time

@Bimpelrekkie what I mean by "buttons connected to ground is" that out of the two terminals of a button (switch) will be connected to the common ground. I don't know if this comment make it simpler or even more complicated.

@ShaktiPhartiyal it did not change anything..

@Andyaka can you please elaborate / illustrate how and what exactly you mean

@ShaktiPhartiyal  is that "one terminal always connected to ground" an actual restriction or did you add that restriction hoping to make the solution easier? Because without that restriction (and a few diodes), two digital IO pins are totally sufficient, with that restriction, you need an analog input pin, or extensive external logic circuitry, or one pin for every button.

@MarcusMüller I added them, ok what is I remove that restriction ? I still do not want to use an analogue input.

@ShaktiPhartiyal you make our and your own life difficult by adding restrictions like the ground connections and no analog input. You will get more suggestions if you leave things as open as you can, so ask: "How to detect which (of 5) button is pressed while using as few pins as possible on my microcontroller." Then you might get some suggestions. Look at the suggestions and see if that suits your needs. If you have restrictions then make clear why they are there, you will need to have a good reason. An "I don't like analog inputs" for example isn't a good reason.

is this a school assignment?

@Nick How is this Arduino question more then EE? It is pretty valid for any MCU with limited pins available.

please explain why you don't want to use an analog pin and accepted a solution which allows to read analog value with a digital pin

@Juraj I do not want to use analogue due to possible noise and voltage fluctuations that may arise.

And yet you accepted Andyaka's answer, which requires you to generate an analog voltage to control the PWM chip. Do you have a real concern about noise, or are you just being superstitious? Anything involving switches is going to have to deal with debouncing (a form of noise) anyway.

If all switches have one input grounded, you cannot use matrixing.
In any case, the best you could do would be a 2 * 3 matrix, which uses 5 signals, the same as individual switching (though you may be able to share the strobes with other signals e.g. display strobes)
If you are allowed to use an analog input you can pull the input high with one resistor, and allow each switch to pull it low with a different resistance. Then each switch results in a different analog voltage and you can decipher an ADC reading into a switch input. That way, only one input is required.

Assuming no ground connection: You could totally do this with only 2 GPIO pins (with internal weak pullups), 5 switches, 2 diodes, 2 resistors:  One switch to from one each of pins to a resistor to ground (check by checking input voltage) 2 switches between the GPIOs, differentiated only by the direction of their series diodes and one without a diode (check by putting the other pin to output mode, low output voltage, and see whether that changes the "high" state").

If you have only one digital pin available, you might consider the 1-wire bus. For example, the DS2408 provides 8 open-drain GPIO pins.

If you can use an analog input pin, then Brian's answer is correct.
Some simple adjustments of the resistor values create equal-size voltage steps for the A/D converter as shown below.

For the 4-switch case, this gives 5V for no switch pressed, and 0-3.75V in approximately equal steps for a switch press. This approach works well up to 16 switches and beyond.
The general approach for calculating the resistor values is as follows:

Select the pullup resistor value; say, 10K ohms.
Decide how many switches are required: N = 16.
The top switch generates 0 volts by shorting the A/D input to ground.
The next switch down will generate Vcc / N volts:
R = 10k × 1/(N-1) = 666.7 Ω
Select the nearest standard 5% value: 680 ohms
Repeat for switches i = 2 through N - 1:

The next switch down will generate Vcc × i / N volts, but you must subtract out the values of the resistors above it. This helps avoid cumulative errors.
R = 10K × i/(N - i) - 680 Ω - ...
Select the nearest standard 5% value.

For the specific example of 16 switches, you should end up with the following resistor values: 680, 750, 910, 1000, 1200, 1500, 1800, 2200, 2700, 3900, 5600, 7500, 13K, 27K and 82K. Even with 5% resistors, all of the resulting voltages are within 0.25% of full scale of their nominal values.

If you do not want to use analog input but not opposed to adding one more component then you can get by with 3 digital pins, two connected to shift register (e.g. SN74HC164) and one reading common return from all buttons. Binary counter can also be used, but with rather high latency.
If you are OK with complicating things even more, you can use external logic for initializing the register, in which case two pins would be sufficient - one for clock output and another for feedback input.
Here is a simple circuit that can be extended to scan any number of buttons by chaining registers or choosing chips with more bits.

Unlike the answers stretching "digital input" function (as implied by OP) to include PWM and Serial communication, this method uses simplest digital I/O: one pin cyclically selects the button, another reads whether it is pressed or not.
The same 2-pin principle (selector output + feedback input) can be used in many different combinations. For example, you can have one side of each switch connected to the ground, as you mentioned in your question. The other sides are fed back to Arduino via analog MUX (e.g. 74HC4051). The MUX address is selected by binary counter (e.g. 74HC193) and the counter is reset by its own QD pin when it reaches 0x08.


text:
MIFARE RC522 I2C Library
I was looking at this link on RFID I2C interface. I added the library to arduino, but in main.cpp, I see an error:

In function 'void setup()':
sketch_mar27a:16: error: no matching function for call to 'TwoWire::begin(int, int)'
Wire.begin(SDA_PIN, SCL_PIN); // Initialize I2C

I looked at Wire.cpp file and found that there is no such member function overloaded with two parameters.
How should I fix the problem? Even if I fix this one problem, I am not sure if this code is working code.
Where can I find working code with I2C interface? I have resource problem and SPI PORT cannot be used.
The code:
#include <Wire.h>

#include "MFRC522_I2C.h"

#define SDA_PIN 5
#define SCL_PIN 6
#define RST_PIN 3

MFRC522 mfrc522(0x28, RST_PIN);  // Create MFRC522 instance.

void ShowReaderDetails();

void setup() {
  Serial.begin(9600); // Initialize serial communications with the PC
  Wire.begin(SDA_PIN, SCL_PIN); // Initialize I2C
  mfrc522.PCD_Init();   // Init MFRC522
  ShowReaderDetails();  // Show details of PCD - MFRC522 Card Reader details
  Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
}

void loop() {
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  // Dump debug info about the card; PICC_HaltA() is automatically called
  mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

void ShowReaderDetails() {
  // Get the MFRC522 software version
  byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
  Serial.print(F("MFRC522 Software Version: 0x"));
  Serial.print(v, HEX);
  if (v == 0x91)
    Serial.print(F(" = v1.0"));
  else if (v == 0x92)
    Serial.print(F(" = v2.0"));
  else
    Serial.print(F(" (unknown)"));
  Serial.println("");
  // When 0x00 or 0xFF is returned, communication probably failed
  if ((v == 0x00) || (v == 0xFF)) {
    Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
  }
}

Please edit your answer and include the sketch "sketch_mar27a".

the example code in that link is for nodemcu (i.e. ESP8266) - the ESP8266 wire library DOES have a void begin(int sda, int scl); - so it seems the library you are using is targeted to ESP8266

SPI is a multi-slave bus. Unless you've run out of free pins to use for CS, or you have slaves that don't play nice, you can connect your RFID module to the SPI bus as well. Also your sketch will most likely compile if you only correct the offending line to simply Wire.begin(). Your library uses the standard Wire library but assumes the target is an ESP8266, whose version of Wire has an extended begin() method.
But this may all be no use since the MFRC522 you have (assuming it's the cheap blue module) is hardwired to use only the SPI interface. Unless you're ready to modify the PCB (cut traces, etc) as others have done.

Thanks for the info,  I am not using any SPI devices and SP pins are used for other purpose and that is why I thought I will try I2C. I too have cheap china made blue module. So no meaning in trying I guess. But does UART interface works in this module?

@Rajesh No, UART doesn't work either, SPI is what it was made for. All the other NodeMCU pins are in use? If you really must use RFID, you're only concerned with each card's unique ID and you don't intend to store data on the card, you can try the cheap 125 kHz readers/cards like this: https://www.aliexpress.com/item/Free-shipping-10pcs-lot-UART-125Khz-EM4100-RFID-Card-Key-ID-Reader-Module-RDM6300-RDM630-For/32284373493.html. They use a UART interface and you only need an RX pin really since they're read-only.


text:
Is this example for playing music without delay correct?
I've followed the directions from this answer, to try and play music without delay. This is my code so far:
#include "pitches.h"

int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};

const int tonePin = 4;
unsigned long previousMillis = 0;
int counter = 0;
int numberOfNotes = sizeof(melody)/sizeof(int);
boolean outputTone = false;

void setup() {
  pinMode(tonePin, OUTPUT);
  //Serial.begin(9600);
}

void loop() {
  unsigned long currentMillis = millis();
  unsigned long noteDuration = 1000 / noteDurations[counter];
  unsigned long pauseBetweenNotes = noteDuration * 1.30;

  if (counter < numberOfNotes) {
    if (outputTone && ((currentMillis - previousMillis) >= noteDuration)) {
        previousMillis = currentMillis;
        noTone(tonePin);
        outputTone = false;
        counter++;
    }
    else {
        if ((currentMillis - previousMillis) >= pauseBetweenNotes) {
        previousMillis = currentMillis;
        Serial.println(melody[counter]);

        if (melody[counter] == 0) {
          noTone(tonePin);
        } else {
          tone(tonePin, melody[counter]);
        }

        outputTone = true;
      }
    }
  }
}

pitches.h can be found here.
So with this code, the music plays, but slower. The pauses between notes seem longer, and I can't figure out why.
Also, I'm not sure where should I increment my notes counter.

In this code, your pauseBetweenNotes is *in addition to * the duration of the note. In your previous code, IIRC, it included the duration of the note.
Change it to 0.3 times and I think it will behave as you expect.

This is the example. If I understand correctly, a note is played for the duration of noteDuration, and then there is a silence for pauseBetweenNotes, and so on, and that, noteDuration + pauseBetweenNotes is the full duration of one note? But pauseBetweenNotes is still a full note duration + 30%? (There is no need for the noTone function then right?).

I've never used this pitches library, but it looks like tone() returns immediately, and the note carries on playing in the background.  In the linked example, the tone will start playing and the code will continue.  It immediately sleeps for 1.3x the length of the note - so the note will finish and then we'll still have 0.3x the length to sleep.  Does that make sense?  In your code above, we wait for the length of the note, and THEN sleep for 1.3x the length of the note.

There's a variable called "pauseBetweenNotes". Try modifying that and see if the pause between notes becomes smaller.
Regarding your counter question, the way the counter is set up looks fine to me.


text:
Arduino Nano - Strange problems
Update:
The arduino works only when I connect 3.3v to reset pin. And I successfully uploaded a sketch but it stops when I disconnect 3.3v and reset.
Update 2:
-- Removed --
Update 3:
Its working perfectly and running smoothly for like 5+ min but the problem starts again

I bought a new arduino nano V3 clone. Till now, I have been facing very strange problems with it:

The pre-uploaded blinking sketch works for a few seconds (like 5 sec and only works when powered after a break) and then it starts to glitch
The L led stays on or off after that
Reset button does nothing (No led blinks or anything)
Can't upload any sketch
Programmer is not responding
RX led blinks during uploading (3 times only)
USB not recognized when connected

Here is what I tried to solve:

Loopback test > Successful
Changed ports
Changed proccessor
Tried uploading with parallel programming
Sketch worked with another arduino nano clone
Manual reset
Tried with Old bootloader
Tried uploading sketch with older version of Arduino IDE.

Here is the exact image of one I have:

Here is the error message:
Arduino: 1.8.10 Hourly Build 2019/07/23 10:33 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\arduino-builder -dump-prefs -logger=machine -hardware C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware -tools C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\tools-builder -tools C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -built-in-libraries C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\libraries -libraries C:\Users\MN\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328old -vid-pid=1A86_7523 -ide-version=10810 -build-path C:\Users\MN\AppData\Local\Temp\arduino_build_778230 -warnings=none -build-cache C:\Users\MN\AppData\Local\Temp\arduino_cache_273206 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -verbose C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\examples\01.Basics\Blink\Blink.ino
C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\arduino-builder -compile -logger=machine -hardware C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware -tools C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\tools-builder -tools C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -built-in-libraries C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\libraries -libraries C:\Users\MN\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328old -vid-pid=1A86_7523 -ide-version=10810 -build-path C:\Users\MN\AppData\Local\Temp\arduino_build_778230 -warnings=none -build-cache C:\Users\MN\AppData\Local\Temp\arduino_cache_273206 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr -verbose C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\examples\01.Basics\Blink\Blink.ino
Using board 'nano' from platform in folder: C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\arduino\avr
Detecting libraries used...
"C:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230\\sketch\\Blink.ino.cpp" -o nul
Generating function prototypes...
"C:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230\\sketch\\Blink.ino.cpp" -o "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230\\sketch\\Blink.ino.cpp" -o "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230\\sketch\\Blink.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core: C:\Users\MN\AppData\Local\Temp\arduino_cache_273206\core\core_arduino_avr_nano_cpu_atmega328old_96bc3f74325b2724b539066aa6a6e44d.a
Linking everything together...
"C:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\tools\\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230/Blink.ino.elf" "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230\\sketch\\Blink.ino.cpp.o" "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230/..\\arduino_cache_273206\\core\\core_arduino_avr_nano_cpu_atmega328old_96bc3f74325b2724b539066aa6a6e44d.a" "-LC:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230" -lm
"C:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230/Blink.ino.elf" "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230/Blink.ino.eep"
"C:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230/Blink.ino.elf" "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230/Blink.ino.hex"
"C:\\Users\\MN\\Downloads\\Compressed\\arduino-nightly-windows\\arduino-nightly\\hardware\\tools\\avr/bin/avr-size" -A "C:\\Users\\MN\\AppData\\Local\\Temp\\arduino_build_778230/Blink.ino.elf"
Sketch uses 924 bytes (3%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr/bin/avrdude -CC:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM6 -b57600 -D -Uflash:w:C:\Users\MN\AppData\Local\Temp\arduino_build_778230/Blink.ino.hex:i
An error occurred while uploading the sketch

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\MN\Downloads\Compressed\arduino-nightly-windows\arduino-nightly\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM6
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x85
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x85
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x85
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x85
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x85
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x85
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x85
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x85
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x85
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x85

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

What is wrong with my arduino?
Note: I was uploading the blink (Example) code, tried with others too...

What kind of power supply do you use? Does it work with other sources (e.g. USB ports)? Can you hook up an oscilloscope to the crystal pins?

@Erlkoenig Same happens when powered with the 5V arduino power supply.

@Erlkoenig Which pins are the crystal pins?

Just to eliminate a possibility, Do you have another computer you can try it with?

@GMc I don't have any other computer, but as I have already mentioned I tried the same sketch with another nano and it worked

Sorry I missed that. FWIW, The crystal is (most likely) the little silver box next to the CPU chip. It will (most likely) have something like 16.0MHz engraved on it. Here is a link that includes a photo showing where the crystal is (scroll down a bit) http://www.circuitstoday.com/arduino-nano-tutorial-pinout-schematics

You can look up the MCU's data sheet and look for the "XTAL" pins, which are probably easier to contact than the crystal pins themselves. While you're at it, also check the voltage supply and reset input with the oscilloscope...

I don't have any oscilloscope

did you solder the headers?

@Juraj Yeah, I soldered them.

check the soldering for shorts

Nope, Its perfectly soldered

@Juraj Check the update

you have some week solder connection between reset and ground pin. it pulls the reset down holding the MCU in reset.

So should I resolder?

take a magnifying glass and check it. maybe it only needs a little cleaning. check both reset pins

and check the ICSP header too

@Juraj I resoldered and cleaned it. It worked constantly for like a min but its now in the same state again.

Let us continue this discussion in chat.

Check the soldering on the SMD resistors. It could be that the pullup on RESET is not connected properly.

@Majenko Not sure but all smd resistors seem to be good

Here is a video https://youtu.be/MMiZEQKPJMM

why only use external power without going through USBport as data input

@abu-ahmedal-khatiri I tried with usb port too

When soldering the pin headers, I used too much flux. So this caused contact between the GND and RST on the ICSP causing the arduino to stay in the reset position. I removed the ICSP pin headers and there was a lot of flux. I removed it and now my arduino is working perfectly. Thanks to @Juraj for figuring it out that there must be a contact between GND and RST

The compiler log said:
-libraries C:\Users\MN\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328old -vid-pid=1A86_7523 -ide-version=10810
It seems your AVR is not updated, try to update your Arduino Avr Bords on the boards manager. also make sure your avrdude.conf file might to be :

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

Dont forget to wire RX to GND or connected RX to TX directly.
Hope this helps.

But wasn't the arduino supposed to work with the old loaded sketch with external power provided?

Yes it should be work using 3v or 5v, same to me, based your error message, you can try my way cause the nano have auto-reset of the arduino-nightly.

Did you try to change in the Tools menu from Atmega328P(OldBootloader) to Atmega328P #NewBootloader. See at Detecting... section and Compiling... are difference using of fqdn.

I have almost tried everything. I will try your way later

Sounds like it is missing the 10K reset pullup resistor.  Try adding one from the RST pin to VCC, which is pin 2 of the 6-pin header.

Your answer doesn't actually explain too much.  Can you provide detail about it?

Reset pin without a pullup resistor can float, leading to odd results as the Nano can reset intermittently. The resistor keeps that from happening.  I don't see on in the picture presented.

What if it has on the underneath? Can you please show me through pictures cause its hard for me to understand.

Sure - post pictures of the top and bottom of Your card - I don't have one of those myself.


text:
How to get number of available pins in code?
Different boards have different number of pins.
Is there a way to know this number in code (at least digital and analog pins), or do I have to determine board type (like in this thread) and know the number of pins by myself?

Reasoning for this is that I'm creating prototype using Uno and using 2-3 analog pins for temperature readings, but I want to be able to use the same code for different board in the future with eg. 8 analog pins, so I don't have to remember to change pin numbers in code and maybe solder it convenient way etc. Also being able to use for eg. "last available analog pin" for certain job could help keep code/schematics nice and clean.

you might be able to detect floating analog inputs, but it's better to glance at the board.

It is quite easy actually:
Serial.print("number of digital pins: ");
Serial.println(NUM_DIGITAL_PINS);
Serial.print("number of analog inputs: ");
Serial.println(NUM_ANALOG_INPUTS);

Note that these are compile-time constants defined as macros in a file
named pins_arduino.h. There is one such file for every board supported
by the Arduino environment. Just to take Curt J. Sampson's example, if
someone “made a board with an MCU with 100 digital IO pins available,
yet if only ten of these are brought out to pins on the board”, then the
macros would tell you you have 10 digital pins. Assuming of course that
you installed the proper support package for that particular board.

Great, thats what I was looking for! But why on Uno this code returns "20 digital pins" if I see 14 (0-13)?

@madneon: because the analog inputs A0 through A6 are also the digital pins 14 through 19.

This is very neat. Didn't know that. But does it really show all connected pins of the chip or does it just tell about how many theoretical i/o's are present on the atmega?

@ansi_lumen: it's the number of available pins on the board, not on the chip.

In the ultimate case, a "board" is not something you can determine programmatically in software; it's not possible in general to tell if, e.g., a particular pin on the microcontroller is connected to a corresponding head pin on the board.
That said, as Edgar Bonet point out, the Arduino board definitions used in the IDE will generally do what you want. Just keep in mind, these are just someone saying "the board should be like this"; a cheap clone board, for example, might be different without a new and proper board definition.
With running code on the microcontroller itself, examining what it can see of the board, you can usually tell which microcontroller you're using. But that just tells you about the chip and its pins, and not about where leads from those pins might go. It sounds to me as if you're asking to find a way to see if your particular microcontroller (e.g., an ATmega328P) is on, say, an Arduino Uno or some other board where certain MCU pins may or may not be hooked up to board pins. The MCU can't tell whether any of its particular pins are connected to headers on the board. As a more specific example, someone could build a board with an MCU with 100 digital IO pins available, yet if only ten of these are brought out to pins on the board, the others are not easily usable.
uino.cc/en/Main/ArduinoBoardUno) or [Arduino Nano]
For your application, you're thinking in a good direction when considering how to make things easier for others using your code. However, I'd suggest that in the long run it's better just to have clear definitions in an obvious place in your sketch (at the top of the file in a single-file sketch, perhaps in a config.ino in a multi-file sketch, or passed in to an initialization function for a library) that says explicitly what pins are used and is easy to change for others. Having the default pins used by the sketch move around if I load the sketch on a different board strikes me as rather confusing.
Keep in mind your audience: the people who are going to be using this on a board different from yours are Arduino hobbyists, and so they're already (or will soon become :-P) familiar with the idea of pins, pin definitions in code, and pin conflicts.

I added more details in last section of question.

You can identify the host processor at run time - each one has its own signature - but not necessarily the board it's running on (consider an Uno and a breadboard-uino for example). So you'd have to make each kind of board you use distinguishable in some way, such as jumpering 3 pins each high or low to make a 3-bit binary code representing one of 8 board types. The next solution is to define that code or some other identifier at compile time with a #define statement, and use the identifier in one or more #ifdef statements to compile board-specific pin definitions.
If you plan on using standard boards the IDE knows about, the IDE pre-defines some useful symbols for you. Here's the compile command the IDE used for an empty sketch for an UNO (I've reformatted it for readability):
"/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++"
-c
-g
-Os
-Wall
-Wextra
-std=gnu++11
-fpermissive
-fno-exceptions
-ffunction-sections
-fdata-sections
-fno-threadsafe-statics
-MMD
-flto
-mmcu=atmega328p
-DF_CPU=16000000L
-DARDUINO=10612
-DARDUINO_AVR_UNO
-DARDUINO_ARCH_AVR

The last four lines make the equivalent of #defines for the clock-frequency, the IDE version number, the Arduino-board, and the overall MCU architecture, respectively.
So in your code, a block like:
#ifdef ARDUINO_AVR_UNO
   // pin definitions for Uno here
#endif

will only be compiled if you selected "Arduino/Genuino Uno" as your board type in the IDE. There are similar symbols for other board types. So for a Nano, ARDUINO_AVR_NANO would be defined instead.


text:
I think I have a bad batch of TPIC6B595
I want drive a large number of LEDS from an Arduino Pro Mini using a number of TPIC6B595. I purchased these on ebay, perhaps a mistake.
Initially I connected two TPIC6B595 as I would connect 74HC595 (with the exception of taking account of how the open drain outputs work) to the SPI pins of an Arduino Mega (my test bench system) and tried sending an alternating bit pattern to the LEDs. No alternating LEDs. I checked SRCLR was Vcc and OE (G) was Gnd. I poked about with my scope (Rigol DS1102D)  and SRCK, RCK and SERIN looked as expected. Suspiciously SEROUT (pin 18) of the first chip was permanently LOW. Note that this is all on a breadboard.
I have used the 74HC595 now many times and from time to time I have made stupid mistakes in wiring/software. These usually stand out on the scope like a sore toe. Not this time.
So I decided to simplify it all and clock some data into a single TPIC6B595 using a simple non-SPI sketch and see if anything comes out of the SEROUT.
Here are the connections to the TPIC6B595 and to the Mega:
1 Not connected,  20  Not connected,
2 Vcc             19  Ground,
3 Arduino pin 12  18  Not connected (except to scope when tested),
4 Not connected   17  Not connected,
5 Not connected   16  Not connected,
6 Not connected   15  Not connected,
7 Not connected   14  Not connected,
8 Vcc             13  Arduino pin 11,
9 Ground          12 Ground (See note 1),
10 Ground         11  Ground.

The chip is bypassed by a 1uF electro across pins 2 and 10. Not ideal but the clock rates are low and it isn't unreliable, it just doesn't work at all.
Note 1: I am not trying to test the transfer between the Shift Register and the output D flip-flops so RCK should be irrelevant. I just want to see data going in to SER IN , coming out on SER OUT.
Here's the Arduino code. It generates a slow clock and an alternating data bit every few clock cycles:
const int ser_clk = 11; // blue
const int ser_in  = 12; // white
byte data, count;

void setup()
{
  pinMode(ser_clk, OUTPUT);
  pinMode(ser_in,OUTPUT);

  digitalWrite(ser_clk, LOW);
  digitalWrite(ser_in, LOW);

  count = data = 0;
}

void loop()
{
  digitalWrite(ser_clk, HIGH);
  delay(1);
  digitalWrite(ser_clk, LOW);
  delay(1);

  count++;
  if (count >= 3)
     {
       count = 0;
       if (data == 0)
          {
            data = 1;
            digitalWrite(ser_in, HIGH);
          }
       else
          {
            data = 0;
            digitalWrite(ser_in, LOW);
          }
     }
}

Here's a screenshot of the wave-forms (photo of scope - sorry can't make UltraScope work):

The cyan trace is the "clock" from pin 11 of the Arduino feeding pin 13 (SRCLK) of the TPIC6B595. The yellow trace is the data from pin 12 of the Arduino feeding pin3 (SER IN) of the TPIC6B595. I am only looking to get the same data pattern out of SEROUT, pin 18 of the TPIC6B595 and this should do it. The clock is as slow as a wet week (see cursor) and even if I have bad set up and hold times and the wrong transitions the data is held for enough cycles for something to make it through surely?? Pin 18 is persistently and forever low. No screenshot - seems to be no point.
I bought several of these TPIC6B595. Tried 3 so far. All the same. Now I might have killed them with static. I am not using wrist straps, but I also don't believe I could have killed 3 of them.
As improbable as that is I think they are dead or duds, or is there something else wrong that is so obvious I cannot see it?
Regards, Fred.

so RCK should be irrelevant. you probably want to read the datasheet to be sure of that, :)

Shifting should still work even without latching. This is to allow daisy-chaining multiple devices and latching them only once all the devices have been charged.

Have you tried substituting them with a normal '595 and seeing if the desired behavior results?

fwiw all the "too cheap" components i've bought from ebay have worked fine...

Thanks to all those who responded. I have a double embarrassment here as I have the answer. Firstly if you can answer your own question there is an argument it should never have been posted, more thought needed first. Sorry everyone. Secondly when the cause is ignoring well known good practice then it is even worse.
So when tying a pin to Vcc (in this case SRCLR) it is known bad practice to hard couple it to Vcc. A pull-up resistor is a much better method. In this case suitable pull-ups were in the next room and I could not be bothered so I just jumpered SRCLR to Vcc. After I had written the post I was staring at the breadboard and thought - I should not have really done that replaced the jumper with a 10K pullup to Vcc. Instantly the SEROUT pin of the TPIC6B595 came to life as it should have. Now I have taken this short-cut before and gotten away with it. But it seems not this time.
Subsequently I have a one chip version of the alternating LEDS running with the SPI interface.
As to the suggestion by dannyf about the datasheet, there is no doubt the datasheet is a good place place to go. Prior to developing my test sketch as per my original post I consulted the datasheet and if you look in Section 8, page 11 of the TI datasheet revised June 2015 there is a Functional Block Diagram. This block diagram clearly shows that the RCK signal is concerned only with the C2 column of D flip-flops which take the output from the shift register and latch it to the output FET through the output enable logic. RCK is independent of the process to clock data through the shift register, controlled by SRCLK. You will note my test did not exercise the transfer function it was just interested in getting data into the shift register and out again.
I stand by my assertion that for the serial shift register function and checking SEROUT, RCK is not relevant. Once you want to start data transfers from the shift register to the output register then it is different matter. No disagreement there. Having that timing wrong will lead to a mess of corrupted data.
Thanks again to all. This is solved and is a lesson to abide by good practice always.
Regards, Fred.

so I just jumpered SRCLR to Vcc. there may be something else at play. wiring srclr to vcc is perfectly acceptable -> the datasheet shows it, and the input block shows a serial resistor so in effect you have a pull-up resistor. puzzling to say the least.


text:
Maximum frequency of digital signal in Arduino Uno?
As Arduino Uno has a 16 MHz oscillator but while running program it has less frequency because some of the processing power is used for running the program.
I have used the delay(1) but it is giving me around 500 Hz.
My questions:

Is there any way to achieve more than 500 Hz?
What would be the maximum frequency of digital signal for below program?

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

void loop() {
  digitalWrite(13, HIGH);
  digitalWrite(13, LOW);
}

note that digitalWrite is relatively slow. Also, wrapping everything inside a while(true){...} will make it a bit faster, instead of letting the loop function exit.

Yes, use the hardware timers.
You can achieve 8 MHz.

Example sketch which outputs 8 MHz on pin 9 on a Uno:
#ifdef __AVR_ATmega2560__
  const byte CLOCKOUT = 11;  // Mega 2560
#else
  const byte CLOCKOUT = 9;   // Uno, Duemilanove, etc.
#endif

void setup ()
  {
  // set up 8 MHz timer on CLOCKOUT (OC1A)
  pinMode (CLOCKOUT, OUTPUT);
  // set up Timer 1
  TCCR1A = bit (COM1A0);  // toggle OC1A on Compare Match
  TCCR1B = bit (WGM12) | bit (CS10);   // CTC, no prescaling
  OCR1A =  0;       // output every cycle
  }  // end of setup

void loop ()
  {
  // whatever
  }  // end of loop

If you change OCR1A you can get lower frequencies. If you change the prescaler you can get lower frequencies again.
See my page about timers for more details.

Below I have put a oscilloscope waveform from your code. Thanks!

Nick Gammon's code worked fine for me. Here is an oscilloscope picture of the waveform I've got from his code:

His code above (from Nick Gammon, on Jan 25 '16 at 20:33) worked excellent for me. I used his code on Arduino UNO and got about 7.9 MHz of output frequency on an approximately 1 V amplitude (peak-to-peak, with spikes making it go to about 2 V peak-to-peak amplitude).
The image above was obtained with my 40 MHz Oscilloscope from ICEL Manaus (manufacturer) at pin 9 (I used the Arduino UNO), with a LED and a resistor as a load at pin 9:

a green LED of about 1.79 V voltage drop
and a 4.7 Ohms resistor with 5% tolerance

The oscilloscope probe (Channel 2, with fall slope trigger detect) is on the 4.7 Ohms resistor. It follows the connection order out of the pin 9 from Arduino UNO:
PIN 9 > green LED > 4.7 Ohms resistor >  GROUND.
The green LED keeps blinking at a normal luminescence, as compared when used at other output frequencies.
I used a external 5 V DC power supply, along with the USB connection on my PC.
If you have any questions just put them here. Thanks and thanks Nick Gammon

Glad it worked for you! The slight discrepancy in frequency could be explained by the fact that the Uno has a resonator rather than a crystal as a frequency source for the main processor.

Also, don't forget that there are alternative methods of toggling outputs.
You can use PORTS to do the job.
Here's a good example. And another here.
And this code is the idea behind it:
void setup()
{
  DDRD = B11111111; // set PORTD (digital 7~0) to outputs
}

void loop()
{
  PORTD = B11111111; // set PORTD pins (digital 7~0) high
  PORTD = B00000000; // set PORTD pins (digital 7~0) low
}

P.S. Don't forget that the port numbering is in reference to the chip pins and not the Arduino pins/legs.


text:
Using digital pin 11 for DMDCon and IR remote
I have a project where I would like to control a countdown clock using a remote with:
Arduino Uno R3 Development Board
Funduino Uno Protoshield Board
Freetronics Dot Matrix Display Connector
Arduino IR Reciever
Both the DMDCon and the IR use digital pin 11. Can these two share the pin 11 or is there a workaround of sorts?

The workaround would be to configure the https://github.com/shirriff/Arduino-IRremote library referenced in your question to any available digital input.

Great Thanks For Your Help! I'll give it a try.

@Kerl Not all pins might be supported, see the documentation about supported pins.


text:
Unable to upload to ESP32 LOLIN D32 board
I'm not able to upload a sketch to this board with the Arduino IDE. This is the error during upload:
Arduino: 1.8.5 (Windows 10), Board: "WEMOS LOLIN32, 80MHz, Default, 512000

Build options changed, rebuilding all
Archiving built core (caching) in: C:\Users\Karanbir\AppData\Local\Temp\arduino_cache_223140\core\core_espressif_esp32_lolin32_FlashFreq_80,PartitionScheme_default,UploadSpeed_512000_6da8d55d0c53c0ebef21ae478b9e06ba.a
Sketch uses 178072 bytes (13%) of program storage space. Maximum is 1310720 bytes.
Global variables use 13880 bytes (4%) of dynamic memory, leaving 313800 bytes for local variables. Maximum is 327680 bytes.
C:\Users\Karanbir\Documents\Arduino\hardware\espressif\esp32/tools/esptool/esptool.exe --chip esp32 --port COM3 --baud 512000 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 C:\Users\Karanbir\Documents\Arduino\hardware\espressif\esp32/tools/partitions/boot_app0.bin 0x1000 C:\Users\Karanbir\Documents\Arduino\hardware\espressif\esp32/tools/sdk/bin/bootloader_dio_80m.bin 0x10000 C:\Users\Karanbir\AppData\Local\Temp\arduino_build_547051/Test.ino.bin 0x8000 C:\Users\Karanbir\AppData\Local\Temp\arduino_build_547051/Test.ino.partitions.bin
esptool.py v2.3.1
Traceback (most recent call last):
  File "esptool.py", line 2637, in <module>
  File "esptool.py", line 2630, in _main
  File "esptool.py", line 2355, in main
  File "esptool.py", line 193, in __init__
  File "site-packages\serial\__init__.py", line 88, in serial_for_url
  File "site-packages\serial\serialwin32.py", line 62, in open
serial.serialutil.SerialException: could not open port 'COM3': WindowsError(5, 'Access is denied.')
Failed to execute script esptool
the selected serial port Failed to execute script esptool
 does not exist or your board is not connected

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

This is displayed on the Arduino IDE's Serial Monitor on pressing the reboot button on the board:
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4436
load:0x40078000,len:0
load:0x40078000,len:11816
entry 0x4007a9fc
[0;32mI (358) cpu_start: Pro cpu up.[0m
[0;32mI (358) cpu_start: Single core mode[0m
[0;32mI (359) heap_init: Initializing. RAM available for dynamic allocation:[0m
[0;32mI (362) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM[0m
[0;32mI (368) heap_init: At 3FFC4E70 len 0001B190 (108 KiB): DRAM[0m
[0;32mI (374) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM[0m
[0;32mI (380) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[0m
[0;32mI (387) heap_init: At 4008DE34 len 000121CC (72 KiB): IRAM[0m
[0;32mI (393) cpu_start: Pro cpu start user code[0m
[0;32mI (187) cpu_start: Starting scheduler on PRO CPU.[0m
OSError: [Errno 2] ENOENT
MicroPython v1.9.3-564-g9254f365 on 2018-04-26; ESP32 module with ESP32
Type "help()" for more information.
>>>

What can be wrong or needs correction?

you might have to connect gpio0 to gnd to flash it, many boards don't have that automated like most of the nodemcus

I will try this and update.

I had the same problems with a USB cable of a length at 30cm
I took an other (10cm) and reduced the upload speed to 512000.
now it works


text:
Programming Attiny45 using Arduino Uno with weird behavior
I bought an Arduino Uno a few days ago.
I programmed an ATtiny45 using an Arduino Uno following "How-To: Shrinkify Your Arduino Projects" video on YouTube.
I uploaded the blink example successfully. I altered the sketch in a way so there is also a blinking on pin 4 (which is ATtiny45 pin 3).
Now, if I connect +5V from the Arduino to ATtiny45 pin 8, ground to pin 4 and the LEDs from pin 2 and 3 to ground everything works as expected.
But if I use 4 AA batteries instead of the power from the Arduino I only get a blinking on ATtiny pin2.
What could be the reason for this behavior? Is it because I use 4 AA -> 6 V instead of 5 V? I tested it also with 3 AA batteries and got the same result.
So why does it work if I use power and ground from the Arduino but not from the batteries?

I just used 2 AA batteries and it worked fine.

6V is no problem for the Uno.  It likes 7-9 volts better (to keep the regulator chip cool) but can go from 5-12 volts.

Welcome to Arduino SE.  Be sure to take the tour at https://arduino.stackexchange.com/Tour

If you take a look at Attiny45 datasheet, you will find at the very first page:

Operating Voltage

1.8 - 5.5V for ATtiny25V/45V/85V

2.7 - 5.5V for ATtiny25/45/85

Your circuit will have unpredictable behavior out of this range. If you want to use four AA cels, you can organize them to have a 3V output or use a step-down voltage regulator.


text:
Issues graduating to AVR-C
I'm trying to make the transition from coding in the Arduino language to AVR-C, but I'm having some issues with my microcontrollers.
I don't have an ISP, so I'm using one of my Arduino UNOs with the ArduinoISP sketch. The problem is that when I try to run avrdude it gives me this error:
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
  Double check connections and try again, or use -F to override
  this check.

However, when I try to run the command with the sugested -F it uploads the code to the Arduino UNO I'm using as an ISP instead of the ATmega328p on my breadboard.
Does anyone have any idea about whats going on here, or how to fix it?

Have you disabled reset on your Arduino?

@Majenko I don't think so, how?

You would know if you had, so you obviously haven't. Add a 10uF capacitor between reset and gnd on the Arduino.

will a 1uF or 50uF capacitor work?

1uF might. 50uF will.

Note that switching to writing in plain C doesn't mean you have to change the method you use to get code into the chip - you can still use the Arduino bootloader.  And of course you can also use ISP to load Arduino sketches - the sources used to generate hex files and the process of loading them into the target are orthogonal subjects.

This does not seem to work, the arduino still resets, and i get the same error. I'v tried with 1uF and 50uF between reset and gnd, and with 120 ohm between reset and 5V

@Majenko ok, so now i tried with a 1000uF, this time there was a difference atleast, now i get the error "avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00" instead...

Note the baud rate of the ISP sketch will probably differ from that of the bootloader (often this is intentional, to make sure that the wrong target will not be programmed).  Your question should really include your full avrdude command line.

avrdude -c avrisp -p atmega328 -P /dev/tty.wchusbserial1410 -U flash:w:main.hex
This one?

THERE IS NO ARDUINO LANGUAGE!!!!!!!!!!!!!!

This is nothing to do with languages. I'm trying to make the transition from coding in the Arduino language to AVR-C, but I'm having some issues with my microcontrollers. You have a problem uploading your code, that is all. Since this question has been abandoned by the OP I'm going to close it.

Just read the arduino source and libraries, they provide an abstraction layer to AVR-C.

"invalid device signature" is due to bad connection or inability to reset the device (RST pin fuse setting for example).


text:
Yun UBoot Prompt Not Showing
I have a Geeetech Iduino Yun Shield. I accidentally flashed the wrong firmware image (not the sysupgrade) to the board. I then tried using the Yun UBoot Reflash method. However, when I open the console monitor from the IDE and restart/reboot the board, I do not get the UBoot prompt. I have attempted to run it at least ten times without receiving any console/serial output.
EDIT: The shield is running on a Leonardo base board.
Is there anything I can do to load the correct firmware onto the board and get it operational or is the board truly bricked? If so, is it possible to obtain a new Atheros AR9331 board to replace the existing one or should I buy a new Yun?
Update: I have tried to get the shield to do an FTP boot, as detailed here by Majenko. I get to the stage where I get the dr_boot> prompt. However, when I type in tftpboot 0x81000000 dragino2-yun-common-v2.0.6-kernel.bin, I get no feedback; it just sits there indefinitely (unless I interupt the process). I can't figure out what I'm doing wrong.

What board is the shield plugged into?

I'm voting to close this question as off-topic because it is about OpenWRT embedded Linux on an AR9331, not Arduino.  TFTPBOOT is a complicated process - you need wired Ethernet connected, need to set up the network details, need to be running a server with the proper image, etc - you need to seek help with this in an OpenWRT forum, not here.   Another option is to hold the ar91k processor in reset and use a tool to re-write the SPI flash chip.

@ChrisStratton Can it not be argued that while the question is to do to the OpenWRT embedded Linux on an AR9331, that happens to be the chip/system used on an Arduino shield, thus making it tangentially relevant and (partially) on topic to Arduino, rather than specific to OpenWRT and an AR9331, therefore completely off-topic? Is there a SE site that would be a better fit for the question?
I'm not stating that your reasoning for closing is flat-out wrong, just that it seems somewhat restrictive/hair-splitting.

The point is that this has nothing to do with the Arduino ecosystem, and everything to do with OpenWRT - the simple solution didn't work according to your comments, so you really need to dig into the OpenWRT documentation from primary OpenWRT sources, rather than depend on the tiny trickle of 3rd hand information that might make it here.  The shield you are working with right now is not an Arduino of any sort - you may be able to plug it into one, but the Arduino has nothing to do with the issue and would be best not connected during this Linux system image repair.

The shield is very different to the real Yun when it comes to serial communication.
Typically the Atheros's UART is mapped to pins 0/1 of the shield for communication with the board it is plugged in to. Those pins are also the pins you use to communicate with the PC, so the normal YunSerialTerminal sketch can't be used.
Instead you will have to lift those pins out of the socket they go into (depending on the shield you may just be able to bend them slightly) and then manually connect them (along with ground) to an external USB to UART adaptor (e.g., FT232) to use for the communication.  Nothing needs to be installed into the Arduino board since that is now just being used as a power supply.
See this answer for which pins to use to run the shield stand-alone.

Thanks; I'll give it a try. Just to clarify that I understand your answer; the base board needn't have the Yun Serial sketch, but it should be loaded onto the shield through the separate UART. (I'm assuming that the shield has a AT Mega chip as found on the Leonardo.)

No, nothing needs loading anywhere. You just plug things together and connect to your USB to UART cable with a terminal program (maybe the serial console). If you have a suitable external power supply you can even do away with the Arduino and power the shield direct.


text:
How to fix: Invalid conversion from 'const char*' to 'char*' [-fpermissive]
I'm trying to upload the code from here to work with an ESP8266. So I copy/pasted the code to the Arduino IDE and I get this error:

C:\Program Files (x86)\Arduino\libraries\WiFi\src/WiFi.h:79:9: error:   initializing argument 1 of 'int WiFiClass::begin(char*, const char*)' [-fpermissive]
int begin(char* ssid, const char *passphrase);
         ^
exit status 1
  invalid conversion from 'const char*' to 'char*' [-fpermissive]

Can anyone help me with this?

This begin() method expects a modifiable character array as its first argument. That's what you should provide:
char ssid[]           = "YOUR_SSID";      // this is changed
const char* password  = "YOUR_PASSWORD";  // this is fine
[...]
WiFi.begin(ssid, password);

When I try to upload it I get: warning: espcomm_sync failed
error: espcomm_open failed. Do you know if it is from the code?

@Physther: I don't know. It's ESP specific and I have no experience with those devices. But see this GitHub issue

Regarding the espcomm_sync failed error, see https://github.com/esp8266/Arduino/blob/master/doc/faq/a01-espcomm_sync-failed.rst

It's more likely that the WiFi library is simply unwise in its declaration.  There's no real need for the ssid argument to be mutable - the ssid and passphrase are in fact treated identically internally.

The location where you are calling the function begin, has as first parameter a parameter of type const char* instead of char* ... remove the const from this argument type.
Probably you have something like
const char* s = ....

...

...begin(s, ...)

Change class s to
char* s = ...

The same question as for Edgar. Can this: warning: espcomm_sync failed
error: espcomm_open failed be caused by the code?

It could be ... I have also no experience with them like Edgar Bonet. Trace back where you call the function that fails and check the parameter values (and compare it to examples).


text:
Extracting data from Arduino MultiWii Flight Controller
I am new to the world of Arduinos but have a new project going with a MultiWii Flight controller. With the MultiWii comes a software for showing all data that is measured from the sensors (acceleration, velocity, roll, pitch, etc) which is nice but I would like to have/extract this data (call raw data or something) from all sensors (i.e. the data plotting everything, in numbers). Maybe it is the simplest thing to do, and I guess I have to set up some serial connection between the controller and tell it to send this data somehow but I do not know where to start so any guidance and help is appreciated.

1. Do you have a link or a more detailed description of the used board / components? When searching for "MultiWii Flight controller" there are various different versions popping up.
2. I assume you want to data in real-time, so getting them from the software through some sort of export functionality is not an option, right?

What have you managed so far? Have you got your Arduino reading anything from the MultiWii yet?

This is the one I have: link

And yes, data in real time is what is needed since the controller will not be connected to a computer when it is supposed to be used but to some sort of buffer (logger, memory or what to say). @PhilipAllgaier

Since you're new to Arduino, I'd suggest beginning with a basic interfacing arduino activity. Once you understand reading and writing digital and analog signals it's pretty much plain sailing from there. You may want to invest some time and a bit of cash in a beginners course on Udemy (try PEter Dalmaris' course https://www.udemy.com/arduino-sbs/) it's a good start. From there, talking to the MultiWii should be a piece of cake. Also, check out http://www.multiwii.com/connecting-elements

that surely made me do some progress! @stav