What features of the Arduino framework will fail if I use my own infinite loop in favor of the standard loop()?

It depends on which "Arduino" you are running it on.

On an Arduino Uno, for example, then the only thing that won't work is the SerialEvent system. Everything else that matters is interrupts.

Here is main() on the Arduino AVR core:

int main(void)
{
    init();

    initVariant();

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

    setup();

    for (;;) {
        loop();
        if (serialEventRun) serialEventRun();
    }

    return 0;
}

As you can see, loop() is run just the same way as your fastLoop(), just not inline, and adding in a call to serialEventRun() if it has been defined.

If no serial event handlers have been defined, then it won't do anything there anyway.

To save clock cycles you would get more benefit (as long as you don't want to use millis(), delay(), serial communication, etc) from disabling interrupts.

However, on an ESP32 or ESP8266 you will find that your watchdog times out and resets the unit. This is because it relies on code being run regularly to manage the WiFi connection that keeps "kicking the dog". Without that being run (which can be called by calling the yield() function) the watchdog times out.


It really depends on the communication range and context required.

If your slaves are within 10-20 meters from the master device and the environment is not polluted (in terms of magnetic field) you can achieve good results with very inexpensive nRF24L01+ modules which operate in the 2.4GHz.

If you need to cover greater distances (in the order of 100 meters) or a polluted environment then you have to resort to shorter wavelengths or more powerful devices, but that brings in the question on how are you powering your slaves: on battery power those ranges get pretty power hungry.

Generally speaking I would say this question should be rejected as it's going to start a debate rather than provide a solution.

You can get some introductions on how to use nRF24L01+ modules simply searching online:

some posts on my blog
the Arduino library I always advice
a pretty valid guide


Wait for serial input otherwise start with preconfigured options

The Serial.available function does NOT block execution. If you want to try, upload this

unsigned long lastTime;
#define LED1 5
#define LED2 13

void setup() {
  Serial.begin(9600);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
}

void loop() {
  if (Serial.available() > 0)
  {
    Serial.read();
    digitalWrite(LED1, !digitalRead(LED1));
  }
  if ((millis() - lastTime) > 500)
  {
    lastTime = millis();
    digitalWrite(LED2, !digitalRead(LED2));
  }
}

You will see led on pin 13 to turn on and off even if the serial port buffer is empty.

Maybe your problem is somewhere else. Anyway what you want can be solved this way:

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

    // Wait for one minute - millis is started at 0, so there's no
    // need to store the initial value of the waiting time
    boolean receivedConfiguration = false;
    while ((!receivedConfiguration) && (millis() < 60000))
    {
        if (Serial.available() > 0)
        {
            // There's some data; parse it

            if (__receivedDataIsComplete)
            {
                __myConfiguration = __configurationFromSerial;

                receivedConfiguration = true;
            }
        }
    }
    if (!receivedConfiguration)
    {
        __myConfiguration = __defaultConfiguration;
    }
}

In this setup function, the microcontroller waits for one minute. If it receives the data it ends the waiting time and uses that configuration, otherwise restores the default one and goes on. In your loop you can then use the configuration.

Please note that the variables starting with a double underscore (__) are false variables, you will have to fill with the proper code and/or variables


Do you mean to repeat num1=0; in loop()?

It is only reading one character per loop() because loop() happens much faster than Serial.available() and Serial.read().

Do the reporting and clearing when you receive some sort of separator/non-digit character.


what ftdi windows driver for arduino nano

The Official Arduino Nano has an FTDI FT232RL.

You want to use the Virtual Com Port(VCP) Driver so the FTDI device appears as a COM port under windows.

See the getting started guide for details.


How to use LCD Screen and IR Remote to broadcast a countdown

How do I do this?

I have no clue how you do that but I do know I would do that.

I know how to ask a question.

Apparently not, your question is far from perfect (and my answer above is technically the only correct answer to that specific question). It doesn't tell us what you've tried, it doesn't tell us what you haven't tried. It not specific nor practical. Doesn't state your experience with Arduino, doesn't state which hardware you (would) be using. (Though I must say your example output thing is quite nice)

I was just in a rush.

Isn't everyone nowadays? And why would we invest time in an answer on a question which has no effort put into it?

You're basically asking "How to do an Arduino project" (or any project), there's many ways but let's dive into it.
0. Split up your project into smaller projects.
Since it sounds as if you have no clue on how to get started or if you feel this project is daunting, it may help to make the 'problem' easier to get started. You can always add more complexity.
Make one Arduino program, which shows "Hello World" on the LCD.
Make one Arduino program, which receives IR codes and depending on which button pressed, shows "Hello" or "World" in your terminal.
1. Research
Search the internet, maybe there's projects like this. Try to google for "Arduino Countdown Timer". Check what design choices they made, what hardware they use and how they work in general.
2. Design
Make a design, not only about the aesthetic part, but also functionally. What happens if the timer depletes? Should it also have a buzzer? Does it need an enclosure?
And technically, how will it be powered?
3. Acquire hardware
As a starter; it can help to buy hardware from stores that also include example code.
Use the example code to test and verify your hardware and connections.
4. Software
If you're asking "How to write software", you're better off starting out with some example projects/tutorials which include the code and explain it.
But basically you should use the example code to drive the hardware, use examples on the internet combined with your own experience to create a program that matches your required behavior.

If, along this path, you have a practical question. We will be much more able to, and happy to, help.


You need to create a folder called "examples" in your library folder. Within there, each in its own folder, you place your examples.

For example:

MyLib/
MyLib/MyLib.h
MyLib/MyLib.cpp
MyLib/examples/
MyLib/examples/Example1/
MyLib/examples/Example1/Example1.ino
MyLib/examples/Example2/
MyLib/examples/Example2/Example2.ino

Be sure to name the example's folder the same as the name of the example.


Per this issue setSPISpeed has to be made after initR like this:
tft.initR(INITR_BLACKTAB);
tft.setSPISpeed(1000000);


Looking for a game application oriented display for Arduino Mega

I'd suggest, if you haven't done it already, to take a look at what is supported by uGFX.

If you find any HW meeting your needs, you can at least be sure that it is supported.


Counter variable gets reset to 0 without resetting it(Mega)

You never reset your b pointer. The first time through it works its way through the memory reserved for buf. The second time through your loop it's already at the end of that memory and you then start incrementing (and filling) past that overwriting other variables - the first of which sounds like it might be n - so *b++=data is writing data (245) to n.

You need to reset b each time you go through loop so it starts at the beginning of the array each time:

b = buf;


I have a page about using switches but since I don't want to give a link-only answer I'll summarize here.

Detect switch changes

What is needed is to detect a transition. That is, either:

It was closed and is now open.

Or:

It was open and is now closed.

To do that you need to "remember" the previous state of the switch and detect a change, like this:

const byte switchPin = 8;
byte oldSwitchState = HIGH;  // assume switch open because of pull-up resistor

void setup ()
  {
  Serial.begin (115200);
  pinMode (switchPin, INPUT_PULLUP);
  }  // end of setup

void loop ()
  {
  // see if switch is open or closed
  byte switchState = digitalRead (switchPin);

  // has it changed since last time?
  if (switchState != oldSwitchState)
    {
    oldSwitchState =  switchState;  // remember for next time
    if (switchState == LOW)
       {
       Serial.println ("Switch closed.");
       }  // end if switchState is LOW
    else
       {
       Serial.println ("Switch opened.");
       }  // end if switchState is HIGH
    }  // end of state change

  // other code here ...

  }  // end of loop

This code looks for changes, and only displays something when the switch changes.

By the way, you should be doing neither delay nor Serial.print inside an interrupt, as both of the rely upon interrupts being active, and interrupts are not active inside an ISR.

Debouncing

A simple technique is just to build in a short delay, for example 10 milliseconds (ms). For example:

const byte switchPin = 8;
byte oldSwitchState = HIGH;  // assume switch open because of pull-up resistor
const unsigned long debounceTime = 10;  // milliseconds

void setup ()
  {
  Serial.begin (115200);
  pinMode (switchPin, INPUT_PULLUP);
  }  // end of setup

void loop ()
  {
  // see if switch is open or closed
  byte switchState = digitalRead (switchPin);

  // has it changed since last time?
  if (switchState != oldSwitchState)
    {
    oldSwitchState =  switchState;  // remember for next time
    delay (debounceTime);   // debounce
    if (switchState == LOW)
       {
       Serial.println ("Switch closed.");
       }  // end if switchState is LOW
    else
       {
       Serial.println ("Switch opened.");
       }  // end if switchState is HIGH
    }  // end of state change

  // other code here ...

  }  // end of loop

In the above code the delay is inside loop (where it is OK to use it) and causes a short pause to allow the switch to stop bouncing.

Debouncing without delay

The above code is fine in simple applications, and if you test it, you should find that the message "Switch closed." and "Switch opened." should only occur once per switch press. But, there's a problem. If you hang around the Arduino forums for a little while you will probably see people telling you "don't use delay". There are various reasons for this, not the least is which that using delay stops your code from doing anything else useful (like testing sensors, controlling motors, flashing LEDs, etc.).

The code below does not use delay, but rather checks for the time that has elapsed after you hit the switch, and sees if the "debounceTime" (in this case 10 ms) has elapsed. If not, it ignores the transition.

const byte switchPin = 8;
byte oldSwitchState = HIGH;  // assume switch open because of pull-up resistor
const unsigned long debounceTime = 10;  // milliseconds
unsigned long switchPressTime;  // when the switch last changed state

void setup ()
  {
  Serial.begin (115200);
  pinMode (switchPin, INPUT_PULLUP);
  }  // end of setup

void loop ()
  {
  // see if switch is open or closed
  byte switchState = digitalRead (switchPin);

  // has it changed since last time?
  if (switchState != oldSwitchState)
    {
    // debounce
    if (millis () - switchPressTime >= debounceTime)
       {
       switchPressTime = millis ();  // when we closed the switch
       oldSwitchState =  switchState;  // remember for next time
       if (switchState == LOW)
          {
          Serial.println ("Switch closed.");
          }  // end if switchState is LOW
       else
          {
          Serial.println ("Switch opened.");
          }  // end if switchState is HIGH

       }  // end if debounce time up

    }  // end of state change

  // other code here ...

  }  // end of loop

More information on the Arduino site: http://arduino.cc/en/Tutorial/Debounce

  It is essential for me to use an interrupt, because I need to be able to pause my entire program, at the push of a button, then resume it when the button is pushed again. I heard from other people that I cannot use any type of delay in the interrupt, is this true?

You don't really pause a program with delay, it is now just doing something else (waiting for a timer to reach a certain time). Timers depend on interrupts to update counters as the hardware timer will overflow (roll over) very rapidly.

I suggest a redesign. In your main loop, for example, you could detect the switch press, and then not do anything until it is pressed again. For example, where I had "other code here" in my example:

static bool switchWasPressed;

if (switchWasPressed)
  {
  // do nothing
  }
else
  {
  // do what you want to do continuously
  }

Now, in the code which detects switch presses you toggle switchWasPressed. So instead of:

Serial.println ("Switch closed.");

You put:

switchWasPressed = !switchWasPressed;  // toggle switch press state


External RAM (23LC1024) and external Flash (W25Q64JVSSIQ) with Sparkfun SAMD21

You are correct, MISO, MOSI and SCK are common to all the SPI devices. Be sure they are all set up for clock polarity etc. The CS\ line is the select line. If the device is not selected it does not matter what goes on with MISO, MOSI and SCK. There are chips such as the 74HC138 that will give you chip selects with just a few additional pins. 1 pin gives you 2 selects 2=4 and 3 gives you 8 selects.


Using multiple HC-SR04: sharing trigger pin and interference between HC-SR04

No, you can't really share the same trigger pin, for the reasons you have already worked out. You can, though, share the same echo pin, since you know which HC-SR04 has been activated by the trigger.

To do that you will need a "wired or" circuit. The simplest method is a diode per ECHO signal and a pull-down resistor:

simulate this circuit – Schematic created using CircuitLab


Why LED light delay is 5 second in arduino?

The problem (likely) isn't in your code. You need to include a pull-down resistor in your electronics, so that when you remove the "high voltage" the residual charge stored in the pin due to its capacitance can be drained. Alternatively you can use the internal pull-up resistors, but then you'd need to invert the logic of the pin (high becomes low and vice versa) and instead of connecting "high voltage" you'd need to connect ground to activate the LED.


NodeMCU: Wiegand not working for one device, while working for another

It's quite cryptic from the little information in that (somewhat chaotic) "manual", but I interpret it that the Wiegand interface is an input port, not an output port.  It is intended to connect that port to an external card reader or keypad as a remote interface (typically the other side of the door to this unit).

For communication with your Arduino you should use the RS-485 interface. For that you need an MAX485 breakout board.


Power a Raspberry Pi 3 from an Arduino Uno

You can't.

The on-board regulator of the Uno, the NCP1117, is only able to supply up to 1A before starting to dropout voltage (hence your undervoltage warning).

Even worse, because the NCP1117 lacks a proper heatsink, it will probably start dropping out voltage before reaching 1A, due to its internal thermal shutdown protection.


Serial.begin(): Why not always use 28800?

Why do people settle?

People settle because it is more than fast enough.  The most common use is just to print some stuff on a terminal for debuggin.  9600 baud is 960 characters per second, or 12 x 80 character lines per second.  How fast can you read? :)

If your program is using the serial port for bulk data transfer, you would choose not to settle.

  What is the limitation...

The limits on serial are high.  Directly you can use 115200 baud in your programs and it will just work.  The Arduino terminal will allow a max of 115200, but other programs such as RealTerm would let you run higher.

Hardware serial will run to 1 M baud.  If you read around you will see people have used up to 1 M by directly controlling the UART.  You might get benefit of high baud rates for uses such as transmitting via a bluetooth chip.  If you are using the hardware serial interface to exchange from chip to chip with just a short distance, then 1 M baud is completely feasible.  Think of all the SPI and I2C devices that operate just fine at 1 MHz clock rate.

Over larger distances, you will start to have problems with noise when using logic level (plain 0 to 5V) signalling.  To use larger distances, you would add a transceiver to provide robust signalling, commonly RS-232 and less commonly RS-485.  With RS-232 you could run a mega bit at distances of 10's of feet.

The microprocessor clock speed will be the real limit.  With a hardware UART, the processor must load one byte to the UART every 10 bits (for N81).  So when you get to 1 M baud it will be a challenge for the 16 MHz processor to keep the UART supplied with data.  A new byte will be sent every 160 clock ticks, which is very few lines of code.  For a short burst of data, you might achieve that rate.  The message is, the processor will run out of speed before the UART is the limit.

Note, this all applies to HardwareSerial, software serial is very different.


Will an Arduino UNO operating at 16mHz communicate with UART / I2C with an STM32 operating at a different frequency?

Tell me, does the difference in clock frequencies of microcontrollers affect the operation of buses between them?

No it doesn't. Or not much any way. It may affect the accuracy of clock generation1, which may have an affect at very high asynchronous baud rates, but other than that, no.

For synchronous communication it's all synchronised to the communication protocol's clock, so processor clocks are irrelevant.

1: Baud rates are usually generated as an integer division of the system clock. Different system clocks give different results for baud rate divisor calculations, yielding marginally different baud rates. Different baud rates will have different error percentages on different system clocks. At low speeds this has no noticeable affect. At high speeds (millions of bits per second) it can cause errors to creep in.


The usual approach for 2.4 GHz is to open the product, identify the radio chip, and use a USB logic analyzer on the SPI bus that usually connects it to the MCU to capture the configuration and data traffic, and figure out what the configuration register accesses mean from the radio chip data sheet.

The occasional appearance of combined MCU/radio parts prevents that approach, but often that is only used on one end of the link and the other will still have a distinct MCU and radio with an SPI bus in between.

This is heavily practiced in the radio control community, as people want to use their nice transmitters to fly cheap toys.  And there is code out there to transmit compatibly with some of the odder chips like the X297, using more common ones like the NRF24L01 or its workalikes from Beken, etc.

A key advantage of SPI sniffing versus over-the-air sniffing is that the usually implemented channel-hopping doesn't mean you loose the signal ever time it moves to a new channel - and you actually get to the see the frequency registers being written.  To capture a hopping scheme over the air, you would need something more like a spectrum analyzer to figure out the sequence, and then have software track the signal while you attempt to figure out the data.  However, a remote which only sends occasional button presses may not use hopping in the way something sending data continuously (like an R/C set, or possibly a keyboard/mouse) would.


How to use potentiometer data from slave to master Arduino?

Start by reading the potentiometer. Add a Wire request service function and that makes the Slave:

#include <Wire.h>

const uint8_t controllerAddress = 8;
const int controllerPin = A0;
volatile int controllerValue = 0;

void setup() {
  Wire.begin(controllerAddress);
  Wire.onRequest(requestEvent);
}

void loop() {
  int value = analogRead(controllerPin);
  noInterrupts();
    controllerValue = value;
  interrupts();
}

void requestEvent() {
  Wire.write((const uint8_t*) &controllerValue, sizeof(controllerValue));
}

This is minor update of the Arduino Wire Master Reader tutorial. The sketch for the Master is left as an exercise.

Cheers!


Can I specify that analog pins be used for digital output?

Yes.

http://arduino.cc/en/Tutorial/AnalogInputPins states

  The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH:

pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH)

There are several caveats on that page regarding this.


Is there a way to set an interrupt to go off after a certain period of time?

The easiest way to achieve your purpose seems to be to configure a
timer to fire every 33 ms, and use this interrupt to wake up the
MCU. For this, you first have to choose what timer to use. On the Mega, I
would rather use the 16-bit timer, but the ATtiny85 only has 8-bit
timers. Next you have to choose a prescaler value (clock frequency
division) among those available for that timer. The prescaler should be
large enough to avoid overflowing your timer, but smaller prescaler
values give better time resolution.

Then you configure the timer to run in “CTC mode” (clear timer on
compare match). In this mode, it counts from zero to the value that you
programmed in the OCRxA register (where x is the number identifying
the timer), and then goes back to zero. This way you can get an
interrupt every OCRxA + 1 timer cycles.

In the example code below, you have to replace x with the appropriate
timer number, and check the datasheet for the bits to set in the control
registers TCCR*:

#include <avr/interrupt.h>

// Interrupt period, in prescaled clock cycles.
const uint16_t PERIOD = ...;  // or uint8_t for an 8-bit timer.

// The timer interrupt is used ONLY to wake the CPU, so there is no job
// to be done inside the interrupt service routine.
EMPTY_INTERRUPT(TIMERx_COMPA_vect);

void setup()
{
    // Disable Timer 0 interrupts.
    // Warning: this will prevent the Arduino from keeping time.
    TIMSK0 = 0;

    // Configure Timer x.
    TCCRxA = 0;            // undo the timer config done...
    TCCRxB = 0;            // ...by the Arduino core library
    TCNTx = 0;             // reset the timer
    OCRxA = PERIOD - 1;    // set the period
    TIMSKx = _BV(OCIExA);  // enable TIMERx_COMPA interrupt
    TCCRxA = ...;          // set the counting mode to CTC...
    TCCRxB = ...;          // ...and set the prescaler
}

void loop()
{
    // Sleep while waiting for the timer interrupt.
    sleep_mode();

    // Now that we have been waken up...
    do_the_job();
}

Edit: As noticed by Gerben, the Arduino core library configures
Timer 0 to send periodic interrupts (one every 1024 µs), which
are used for timekeeping (millis(), delay() and co.). This
interrupts will wake up the MCU and prevent it from sleeping as long as
you want. The simplest solution, which is implemented in the code above,
is to disable the Timer 0 interrupts. The drawback is that the
Arduino timekeeping functions will not work anymore.

If you need those timekeeping functions, then the proper solution is the
one sketched by Gerben in his comment: set a boolean in the interrupt
that can be checked in the main loop. Here is the naive implementation
of this idea: EMPTY_INTERRUPT(TIMERx_COMPA_vect); is replaced by

volatile bool time_elapsed;

ISR(TIMERx_COMPA_vect)
{
    time_elapsed = true;
}

Then, in the main loop you sleep repeatedly until the ISR sets the flag:

void loop()
{
    // Warning: race condition here!
    while (!time_elapsed)
        sleep_mode();
    time_elapsed = false;

    // Now that we have been waken up...
    do_the_job();
}

As stated in the comment, this naive implementation suffers from what is
known as a race condition. The problem is in the following scenario:

The main loop reads the value of time_elapsed and it turns out to
be false
At this point the interrupt fires and the ISR sets that boolean to
true
Returning from the ISR, the main loop does not test the flag again
(since it just did it) and goes straight to sleep_mode();.

At this point the MCU ends up sleeping although it should be performing
the job which is due now.

This race condition may not a be a big deal to you: The MCU will be
eventually woken up by the Timer 0 interrupt no more than 1024 µs
later. In some cases it is an issue, but fortunately there is a proper
solution. It is described in the page about sleeping of the avr-libc
documentation. It relies on the fact that when interrupts are
disabled, then enabled again with sei(), the machine instruction right
after the sei() is guaranteed to be executed before any interrupt is
serviced. Then the proper way to test the flag and sleep is:

void loop()
{
    while (!time_elapsed) {
        cli();
        if (!time_elapsed) {
            sleep_enable();
            sei();          // interrupts enabled
            sleep_cpu();    // this will be executed before any ISR
            sleep_disable();
        }
        sei();
    }
    time_elapsed = false;

    // Now that we have been waken up...
    do_the_job();
}

With this version, if the interrupt fires right after the test
if (!time_elapsed), it will be serviced after sleep_cpu(), which
will have the effect of waking the MCU right away.


The proper method of receiving this kind of data is to use a sliding window. That is you visualise the stream of bytes as just that - a stream of bytes (think letters on paper tape).  You then have a conceptual "window" on that data which is the width of the packet (10 bytes in this case).  As the data passes behind the window you see just 10 bytes of it. When that 10 bytes is in the "right" format (that is, it starts with 0xAA, ends with 0xAB and the checksum is valid) then you have a valid packet and can read the values from it.

The simplest method of implementing that is with a 10-byte array. As a byte arrives on the serial port you shuffle all the bytes down the array to make room for the new byte at the top of the array.  Once 10 bytes have arrived that first byte should now have made its way to the bottom of the array.

For instance:

uint8_t window[10];

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

void loop() {
    if (Serial.available()) {
        // Slide the window
        for (uint8_t i = 0; i < 9; i++) {
            window[i] = window[i + 1];
        }
        // Add the new character
        window[9] = Serial.read();

        // Output the current window data for debugging
        dumpWin();

        // Check the framing characters
        if ((window[0] == 0xAA) && (window[9] == 0xAC)) {
            // Calculate the checksum
            uint8_t cs = 0;
            for (uint8_t i = 2; i < 8; i++) {
                cs += window[i];
            }
            // If the checksum matches...
            if (cs == window[8]) {
                // ...we have a valid packet!
            }
        }
    }
}

void dumpWin() {
    for (int i = 0; i < 10; i++) {
        Serial.print(window[i], HEX);
        Serial.print(" ");
    }
    Serial.println();
}

Getting the data out of the valid packet is now a case of combining bytes into 16-bit integers then dividing them into floats.  For instance the PM2.5 would be:

uint16_t pm25i = (window[3] << 8) | window[2];
float pm25 = (float)pm25i / 10.0;

The PM10 would be the same but with window[5] and window[4] of course.

Since you can't really use the hardware UART for both communication with your sensor and communication with the PC you may want to investigate the use of SoftwareSerial instead of the hardware UART pins for communicating with the sensor.


Making the speaker play a certain frequency of sound

Have you looked at the Tone library?  That does what you want, with some other niceties besides.

Anyway, the (or at least "a") problem with your code is that you are leaving the signal LOW almost all the time. You want it to spend half the time high, half the time low:

digitalWrite(buzzer, LOW);
delayMicroseconds(500000 / frequency);
digitalWrite(buzzer, HIGH);
delayMicroseconds(500000 / frequency);


Note: While looking at specifications can infer compatibility, there is no substitute for prototyping.  It is always better to try something then ask for suggestions if it does not work as expected.

That said, I would suggest to look at the LCD you specified.  The LCD's physical shape appears to lock you into a legacy Arduino Uno layout.

On the LCD's web page is a list of pins used.

On the HX711 sparkfun.com web page is a diagram of pins used when using their HX711 software.

Check if there are any conflicts.  Even if there are none, it does not mean there will be no conflicts within the software you will need to run the LCD and the HX711.  You will have to either find someone who has successfully done exactly what you want to do or examine all the software involved your self.  Of course you could simply prototype the project to see if it works.


Read signal from USB mouse on an Arduino ?

This would be possible only if the mouse actually supports PS/2. USB to PS/2 adapters are entirely passive, and in order to function it requires that the controller in the mouse is designed to communicate in both protocols. Modern mice, especially wireless ones don't tend to have this capability anymore as PS/2 is all but a dead standard.


Following on ESP8266 Board pins, how do they map on the motor shield?

You see the pins marked PWMA, PWMB, DA and DB? Those are the pins that control the motors (PWMx is the speed, Dx is the direction). Whatever pins on your ESP8266 board plug into those holes are the pins you need to use in your code. How those pins map to names and numbers in the Arduino API depends entirely on what the board is you're plugging in and what the author of the board definition files was thinking at the time.

In short, look at your board (which we cannot see) and see what GPIO pins are in the same location as the pins I pointed out. Then control those pins in your software.


log STK500v2 commands while flashing a Mega

Add the flag -vvvv to the avrdude command. That will show you the flow of data between the computer and the Arduino.
You can copy and paste the executed command from the IDE and run it in a terminal / command window adding the flag manually. Or you could modify the platform.txt file for the AVR core.


Your whole code can be replaced with one line:

digitalWrite(output_pin, digitalRead(inputA_pin) && digitalRead(inputB_pin));

That is, write out the results of a boolean AND on the state of the two inputs.


SPIFFS (SPI Flash File System)  is also know as FS(File system) . so What you are seeing as FS is basically SPIFFS .The OTA partition on esp8266 is compulsory so you cant get rid of it .
Hope this helps


You are repeatedly overwriting the ssid property of the same object.
Instead, you want to write different properties, like

wifiJsonObject["ssid" + String(i+1)] = WiFi.SSID(i);

Then, only serialize the document once, when it is complete.

That being said, I strongly concur with Juraj in that the correct way to
represent a list in JSON (and wifiList is clearly meant to be a list)
is by using an array:

void scanWifiNetworks() {
    DynamicJsonDocument jsonDoc(1024);
    JsonArray wifiList = jsonDoc.createNestedArray("wifiList");
    int n = WiFi.scanNetworks();
    for (int i = 0; i < n; ++i) {
        JsonObject wifiNet = wifiList.createNestedObject();
        wifiNet["ssid"] = WiFi.SSID(i);
    }
    serializeJsonPretty(jsonDoc, SerialBT);
    serializeJsonPretty(jsonDoc, Serial);
}

This should produce a JSON document that looks like this:

{
  "wifiList": [
    { "ssid": "quark" },
    { "ssid": "Airtel_Zerotouch" },
    { "ssid": "NETGEAR77" },
    { "ssid": "Itobuz-technologies" },
    { "ssid": "Nokia 6.1" }
  ]
}

Edit: Note that, if it's clear from the context (e.g. a request URL)
that you are transmitting a list of WiFi networks, then you can get rid
of the outer object and the "wifiList" label, and use the array as the
JSON document:

[
  { "ssid": "quark" },
  { "ssid": "Airtel_Zerotouch" },
  { "ssid": "NETGEAR77" },
  { "ssid": "Itobuz-technologies" },
  { "ssid": "Nokia 6.1" }
]

As suggested by Jaromanda X, if you are never going to extend the inner
objects with extra information, you can further simplify the document by
removing those objects and just listing the SSIDs in the array:

[
  "quark",
  "Airtel_Zerotouch",
  "NETGEAR77",
  "Itobuz-technologies",
  "Nokia 6.1"
]


Arduino car on bluetooth remote appears to crash when motors started

it sounds like the motors are pulling down the battery voltage enough to reboot the Arduino; and the USB-port is able to supply enough current without as much voltage drop.

We'd need to see a schematic, but check that the power supplied to your Arduino and power supplied to the motors are completely independent; that the Arduino only supplies current to a switch or a relay in the motors' power circuit but not to the motors themselves.


Have a look at my Temperature and humidity sensor - battery powered. That works from 3 x AA batteries, and has been going for a few years. I think I replaced the batteries once. It keeps track of the time, and logs data to the disk (SD card).

I don't have room to describe the whole project here, but the general idea is that the processor sleeps most of the time (consuming around 6 µA). Now this particular project doesn't turn on a motor, but adding a solid-state relay should be all you need to do that.

  Be able to connect to a phone using a usb cable. The phone would act as a UI to change settings and water flush times on the Arduino (via a custom app)

I think this will take a lot of power, keeping the phone active. One possible thing to try would be to power up the phone (eg. using another relay) during a certain "window" of time (eg. 6 pm to 7 pm). Then you would know to try to configure the device during that time.


The I2C pins on the V3 shield are just copies of A4 & A5 - so just run a jumper wire some way.

BTW that Motion shield looks like it only uses 1 interrupt pin in addition to I2C, so you may be ok.

The motor board does have a library at https://learn.adafruit.com/adafruit-motor-shield/downloads and you can look at the code to see what it uses.

I personally use the mpu6050 - same kind of thing, I2C one interrupt but only 6DoF (which is plenty).  The 6050 has been superseded with the 9150, 9DoF.  6050 break out boards sell for $6 (or less).  Actually I put all this together on one piece (http://www.spiked3.com/new-products/)


How to externally power HC-05 module with Arduino Pro Mini?

The HC-05 (the PCB that is mounted on the PCB of the module) itself runs on 3.3V. Many microcontrollers run on 5V, so people are selling the HC-05 mounted on a PCB with extra components, for example a voltage regulator from 5V to 3.3V.

Voltage regulators have a minimum input voltage for which they can hold the output voltage at the specified value. Refer to this question for more information about this. So supplying the module with 3.3V instead of 5V will result in a supply voltage for the HC-05, that is significantly lower than 3.3V, so it most likely won't work correctly.

If you want to use the HC-05 module as it is, you have to provide 5V supply voltage from another source. In this case be sure to connect the grounds of both power supplies, so that they have a common ground.

If you don't want to use an extra power supply, than you may bridge the voltage regulator on your modules PCB and provide the 3.3V as supply voltage, that are used by the Arduino. Doing so would not be an easy task for a beginner, since you would have to solder small SMD components. Also the outlay of the modules PCBs are very different (depending on manufacturer). Note that in this case you should never ever put 5V on the Vcc pin of the module again, since it is then directly passed on to the HC-05 chip, which would be destroyed from the 5V supply.


How to power Arduino externally for long term?

There are several options for Arduino power in an external environment.

Wall wart: Connects to a wall socket, provides a great long-term source of power
Rechargeable battery: Doesn't last long, but they can be recharged and monitored with a low cost board
Alkaline Battery: Last longer, there are some monitoring systems available.
Solar: Only works when the sun is out, unless you combine it with a rechargable battery (example)
Nuclear power: NOT RECOMMENDED!!!


Does blinking an LED with no resistor for a few seconds harm my Arduino?

If you try it again with the proper resistor in place, and the pin still works, then no, you probably haven't damaged it. It may have stressed the pin driver some but if it passes the above test, I think you're still good to go.


Provided that the voltage specs of the motor are not violated, no. However, the inductance of the motor stands a very good chance of destroying the switch unless an appropriately-rated flyback diode is used.


DS18B20 sending variable via Enthernet shield

Having re-read the question just before posting this answer, I find it odd that the DHT temp and humidity (also floats) work for you - how odd

Use dtostrf

char tStr[9] = { 0 }; // buffer to store the string - length 9, because at most you need 8 chars "-23.5678" , plus null terminator
dtostrf(sensors.getTempCByIndex(0), 7, 3, tStr)

Note: dtostrf returns char pointer to tStr

The 7, 3 is ... 7 = total length of string, 3 = number of decimal digits - So depending on your resolution, you can change those values

Resolution     Arguments to dtostrf
 9             5, 1                  -nn.n
10             6, 2                  -nn.nn
11             7, 3                  -nn.nnn
12             8, 4                  -nn.nnnn

Of course, you can use any arguments for any resolution, the table just shows what you would need if you wanted to show the exact data coming in

For example, I use resolution 12, but I'm not really interested in displaying more than tenths of a degree - so I use 5,1 for the format


sizeof() gives the number of bytes. You are looking for membersof(). It is often defined as:

#define membersof(x) (sizeof(x) / sizeof(x[0]))

And in the example above:

for (int i = 0; i < membersof(neighbourSet); i++) {
     //do something for each PEER.
     delay(50);
}

For more practical C/C++ macro and type extensions please see the Cosa Types.h file.


Long to Integer conversion will overflow the value and you'll get values in negative numbers.

Define the pauseLength as unsigned long to make it work.


Bluetooth module is neither sending nor receiving data at baudrate(115200)

Software serial is really limited because it needs relatively precise timing, full attention of CPU and there can't be any interruptions from other sources.

You can see source code for better understanding how it works.

And if you need faster communication, you should get board with more hardware serials.


Check to see that String only contains .csv style numbers

There is a better way, which is called regular expressions (or regexp). However, afaik these are not supported by Arduino by default.

However, I'm sure you can find some 'generic C++' class that can handle them.

For that, it's best to check on StackOverflow.com probably.

After a short check, on the Arduino forum there is a library available for regexp:

library

It is created by Nick Gammon, so all credits are for him.


First collect all of the characters up to the new-line (`\n' or line-feed) into an array of characters, and put a zero byte after the last one.

Since It looks like all of the strings you need to parse consist of one a single letter followed by the value you want, value = atoi(inputArray[1]; will return the value as a 16-bit int. If it could be larger than 32767 but less than 65536 (probably not if you're driving a servo with it), then cast the value to unsigned.

If there might be an unknown number of characters (non-digits) preceeding the value, the C function size_t strcspn(const char *string, const char *cset) will return the length of the leading sub-string of string that does not contain characters in cset. So value = atoi(inputArray[strcspn(inputArray, "0123456789")]); will do the same thing, but calculating the array index of the first digit in the string.

(For completeness, note there is a companion function, size_t strspn(const char *str, const char *cset);, that returns the leading sub-string of 'string' consisting only of characters in cset).


How to rsync my node.js project to my intel edison board, through ssh?

rsync works by talking to the rsync executable running on the remote target; without said executable you will need to drop to either scp or a tar pipe.


Reading Multiple MPU 9250 Sensors using TCA9548A Multiplexer

You need to adapt the example you're following to follow how the MPU library does its construction and setup.
Looking at the documentation for the MPU library you are using, you should change the definitions to:

MPU9250 mpu_0(Wire, 0x68);  // 0x69 if you pulled AD0 high

Then if you read further to the "Common Setup Functions" section, you'll see that this library's setup function has this behavior:

This function returns a positive value on a successful initialization and returns a negative value on an unsuccesful initialization

So you need to adapt that too:
Serial.print(F("MPU.1 detected?\t"));
if (mpu_0.begin() < 0) { // the examples assume zero is ok too
  Serial.println(F("No"));
} else {
  Serial.println(F("Yes"));
}

You'll save yourself some trouble if you use an array for your sensors too.
MPU9250 mpus[] = { MPU9250(Wire, 0x68), MPU9250(Wire, 0x68) };
const int num_mpus = sizeof(mpus)/sizeof(mpus[0]);

Then your initialization can be done with a loop:
for (int i = 0; i < num_mpus; ++i) {
   tcaselect(i);
   if (mpus[i].begin() < 0) {
     // ...
   }
 }

And you can do similar things for interacting with the sensor. e.g.:
for (int i = 0; i < num_mpus; ++i) {
   tcaselect(i);
   mpus[i].readSensor();
   Serial.println(mpus[i].getAccelX_mss());
   // ...
 }


Is EEPROM persisted across program flashes?

Only if the EESAVE fuse is programmed (it is unprogrammed by default). If not then the EEPROM will be erased when a chip erase command is performed.


Object Sensor on conveyor belt (want to record the data in EEPROM for testing)

You can use the EEPROM.write() function. There is a useful tutorial on the Arduino site.

The sample code from that tutorial is shown below:

/*
 * EEPROM Write
 *
 * Stores values read from analog input 0 into the EEPROM.
 * These values will stay in the EEPROM when the board is
 * turned off and may be retrieved later by another sketch.
 */

#include <EEPROM.h>

/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int addr = 0;

void setup() {
  /** Empty setup. **/
}

void loop() {
  /***
    Need to divide by 4 because analog inputs range from
    0 to 1023 and each byte of the EEPROM can only hold a
    value from 0 to 255.
  ***/

  int val = analogRead(0) / 4;

  /***
    Write the value to the appropriate byte of the EEPROM.
    these values will remain there when the board is
    turned off.
  ***/

  EEPROM.write(addr, val);

  /***
    Advance to the next address, when at the end restart at the beginning.

    Larger AVR processors have larger EEPROM sizes, E.g:
    - Arduno Duemilanove: 512b EEPROM storage.
    - Arduino Uno:        1kb EEPROM storage.
    - Arduino Mega:       4kb EEPROM storage.

    Rather than hard-coding the length, you should use the pre-provided length function.
    This will make your code portable to all AVR processors.
  ***/
  addr = addr + 1;
  if (addr == EEPROM.length()) {
    addr = 0;
  }

  /***
    As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
    EEPROM address is also doable by a bitwise and of the length - 1.

    ++addr &= EEPROM.length() - 1;
  ***/

  delay(100);
}


Is there a way to remove the 8.3 filename limitation on the SD.h library?

The 8.3 "limit" is not a "limit" that can be removed. It is how FAT filesystems work.  Longer filenames are a "fudge" extension overlaid on top of that fileststem structure. To be able to use them you would need to implement that extension.

Simpler to switch to a more modern implementation.  FatFS is your friend:

LFN support, including UTF
Faster device access
More efficient
Can handle more devices than just SD cards
Can handle multiple devices at once

There is an implementation here though I don't know how good it is (I use it on chipKIT where it is bundled by default).

If you can't get FatFs then basically anything is better than the SD library to be brutally honest.


all of your problem can be solved through a simple trick ... Just follow it...

Use Sdfat library insted of SD
just follow SPI datasheet..

follow below code ... it works with LORA AND SD both together

...

#include <SdFat.h>
#include <SPI.h>
#include <RHReliableDatagram.h>
#include <RH_RF95.h>

SdFat sd;
SdFile myFile;

#define chipSelect 4

#define RFM95_CS 10 //
#define RFM95_RST 9
#define RFM95_INT 2

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS,RFM95_INT);
//RH_RF95 driver(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W

// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(rf95, 2);

void setup() {

  Serial.begin(9600);
  while (!Serial) {}  // wait for Leonardo

  delay(100);

  // Initialize SdFat or print a detailed error message and halt
  // Use half speed like the native library.
  // change to SPI_FULL_SPEED for more performance.
  pinMode(RFM95_CS, OUTPUT);
  digitalWrite(RFM95_CS, HIGH);
  digitalWrite(4, LOW);

  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();

/*

/*
 * //Open file and write  ...
 *
  // open the file for write at end like the Native SD library
  if (!myFile.open("mrinmoy.txt", O_RDWR | O_CREAT | O_AT_END)) {
    sd.errorHalt("opening test.txt for write failed");
  }

  // if the file opened okay, write to it:
  Serial.print("Writing to test.txt...");
  myFile.println("testing 1, 2, 3.");

  // close the file:
  myFile.close();
  Serial.println("done.");
  */

  /*
  // open the file for reading....

  if (!myFile.open("mrinmoy.txt", O_READ))
  {
    sd.errorHalt("opening test.txt for read failed");
  }

  Serial.println("mrinmoy.txt:");

  // read from the file until there's nothing else in it:
  int data;

  while ((data = myFile.read()) >= 0) Serial.write(data);
  // close the file:
  myFile.close();
  */

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  digitalWrite(RFM95_CS, LOW);
  digitalWrite(4,HIGH);

  while (!manager.init()) {
    Serial.println("LoRa radio init failed");
    while (1);
  }
  Serial.println("LoRa radio init OK!");

 // digitalWrite(RFM95_CS, LOW);

}

void loop()
{
   uint8_t data[] = " Hi.. This is node 1.";
 //   unsigned char sd_data[50];
// Dont put this on the stack:
 // uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
   uint8_t buf[50];
  // nothing happens after setup

  //LoRa.setPins( LoRa_CS, LoRa_RST, DI0 );
  digitalWrite(4,HIGH);    //  deselet SD Card SPI
  digitalWrite(RFM95_CS, LOW);    //  SELECT (low) LoRa SPI
  SPI.begin();

  // Send a message to manager_client
  if (manager.sendtoWait((uint8_t*)data,sizeof(data),1))
  {
    Serial.print("successfully sent to: ");
    Serial.println(1);
  }
  else
  {
    Serial.println("send failed");
  }

  // receiver ....

   // Now wait for a reply from the server
   uint8_t len = sizeof(buf);
   uint8_t from;

   if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
    {
      Serial.print("Got Response From : 0x");
      Serial.print(from, HEX);
      Serial.print(": ");
      Serial.println((char*)buf);
    }
    else
    {

    }
 //   digitalWrite(4, LOW);
   SPI.end();

   digitalWrite(4, LOW);    //  deselet SD Card SPI
   digitalWrite(RFM95_CS,HIGH);    //  SELECT (low) LoRa SPI
   SPI.begin();

 if (!myFile.open("mrinmoy.txt", O_READ))
  {
    sd.errorHalt("opening test.txt for read failed");
  }

  Serial.println("mrinmoy.txt:");
  char ch;
  String str;
  int i=0;
  uint8_t sd_data[50];

  while (myFile.available()>0)
  {
    ch= myFile.read();
    str+=ch;
  }

  String str2=str;
  Serial.println(str2);
  Serial.println(str2.length());

  myFile.close();
  SPI.end();

  delay(500);
}

use this trick ... your system will work perfectly ...


You connected 5V to the base of the transistor inside, so the transistor is turned on all the time.

Move the 5v pin one to the right (middle pin on the 4N35, i.e. the collector), and it should work.


Read Multiple Sensors Data from a text file located in SD Card in Arduino/ESP32

Function file.parseInt(), will skip non numeric characters and then parse the number stopping on non numering character. So you need only call file.parseInt() for every value in row, process the data and then loop to next row.

Y1 = file.parseInt();
S1 = file.parseInt();
S2 = file.parseInt();
S3 = file.parseInt();
S4 = file.parseInt();


Why do I need to include libraries used in other libraries?

If I remember correctly this is in fact a limitation of the Arduino IDE.

If you use a better IDE (personally I use Eclipse with the Arduino plugin) it works as it should, i.e. if you include a library A that includes another library B, then in the end you won't get compile-time errors and both B and A will be included in the final binary.


What sensor do I use to measure the intensity of direct sunlight?

You can use a photo resistor. It is also known as an  LDR (Light dependent resistors) and here is a great tutorial to do just that. You can also find a conversion from the 8-bit analog value to lumens if you wish. Here is a tutorial:
https://www.instructables.com/id/Measuring-Light-Using-Light-Sensor/
You can also use a LUX which is the advanced version of a LDR. Here is a tutorial:
https://www.instructables.com/id/How-to-Measure-LUX-With-Arduino/


If you want to read 3 values of a object that you don't know the names of the key, you can use an iterator as shown in the ArduinoJson library's docs.

And as already mentioned in the comments, you can also replace all the serial reading code with just Serial passed into the jsonBuffer.parseObject function.

#include <LiquidCrystal.h>
#include <ArduinoJson.h>

const struct LCDPos {
  uint8_t x;
  uint8_t y;
} lcd_pos[] = {
  {0, 0},
  {8, 0},
  {0, 1},
};

LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

void setup() {
  Serial.begin(115200);
  lcd.begin(16, 2);
}

void loop() {
  StaticJsonBuffer<100> jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(Serial);
  if (root == JsonObject::invalid())
    return;

  uint8_t i = 0;
  for (JsonObject::iterator it = root.begin(); it != root.end() && i<(sizeof(lcd_pos)/sizeof(lcd_pos[0])); ++it, i++)
  {
    lcd.setCursor(lcd_pos[i].x, lcd_pos[i].y);
    lcd.print(it->value.asString());
  }
}

You will need to make sure, that the values are sent in the order that you want them on your LCD.

EDIT:
I don't have an LCD screen, so I didn't test the code with an LCD, but the code that just dumps the parsed data back to serial works.

//#include <LiquidCrystal.h>
#include <ArduinoJson.h>

const struct LCDPos {
  uint8_t x;
  uint8_t y;
} lcd_pos[] = {
  {0, 0},
  {8, 0},
  {0, 1},
};

//LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

void setup() {
  Serial.begin(115200);
  //lcd.begin(16, 2);
}

void loop() {
  StaticJsonBuffer<100> jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(Serial);
  if (root == JsonObject::invalid())
    return;

  Serial.println("JSON received");
  uint8_t i = 0;
  for (JsonObject::iterator it = root.begin(); it != root.end() && i < (sizeof(lcd_pos) / sizeof(lcd_pos[0])); ++it, i++)
  {
    //lcd.setCursor(lcd_pos[i].x, lcd_pos[i].y);
    //lcd.print(it->value.asString());
    Serial.print(i);
    Serial.print(':');
    Serial.print(lcd_pos[i].x);
    Serial.print(',');
    Serial.print(lcd_pos[i].y);
    Serial.print(' ');
    Serial.println(it->value.asString());
  }
  Serial.println();
}

If I send

{"TPS":"0.40","MAP":"0.95","LOAD":"14"}{"LOAD":"2.40","RPM":"4200","INJECTION_TIME":"4.87"}

over the serial, it returns

JSON received
0:0,0 0.40
1:8,0 0.95
2:0,1 14

JSON received
0:0,0 2.40
1:8,0 4200
2:0,1 4.87


Good tips for how to connect cables into Mux Shield II?

Solder 100-mil male headers onto the board, then use 100-mil crimp terminals to connect the wires.


It is because the rail in the middle breaks the vertical connections.
So the positive leg in the first example is not connected to the negative leg of the LED.

In your second example both the negative leg and the positive leg are connected on the same rail, because of the that the power is not flowing through the LED but directly back to the GND pin of your arduino.

Same for the resistor. Since both legs are connected to the same rail, the resistor has no effect.


Intermittent LOW reading from input pin set to INPUT_PULLUP

My guess would be that you're getting noise interference on the line and it's too much for the Arduino's little internal pullup.  Try adding an external pullup resistor - say 5k-10k (exact value is not critical).


about receiving float on matlab from ATmega32 Avr

i found the solution for this problem, i set a header before sending the data from ATmega32,and on Matlab i check the frame ,if it received correctly,i receive the data

//ATmega32 code
    float x =215.5;
    unsigned char *ptrx;
    int main(void)
    {   usart_init();
        //data.fo=12.85;

        ptrx=( unsigned char *) &x;
          while(1)
       {
        uart_send(0xAA);//equals to 170
        for(int i=0;i<4;i++){
        uart_send(*(ptrx+i));}

        x++;}}
    //on Matlab
    s=serial('COM1','BaudRate',9600);
    fopen(s);
     i=1;
    while i<1000
        header =fread(s,1,'uint8');

        if header==170//equal to 0xAA

     out=fread(s,1,'float');
    data(i)=out;

     i=i+1;
        end
     end
    fclose(s);


How can I control the speed and direction of dc motor at the same time (through Bluetooth

Use delimiters to separate the two values you are sending over bluetooth.

Something like

"30,5\n"

instead of

"30\n"
"5\n"

On the Arduino side, read the the incoming string into a char array and add a \0 after the last read character to make it a C string. The use strtok() to parse the C string and atoi() or atof() to convert the parsed C strings to an int or float.

See this answer for more information about parsing a string.


Do I need an external power supply for the SG90 micro servo?

I'm not sure if the data sheet for every SG90 servo is the same, but if you look at this one, SG90 Specifications, you'll see the "stall current" can be between 570mA and 730mA. You may want to test your servo under this condition before deciding to power it with an Uno.


Galileo Positioning System signal receiving

You need the hardware and a library. Most GPS modules use a serial communication, and I think that also the Galileo compatible boards use serial communication. That makes them compatible with most microcontrollers and also with Arduino boards.

I could find a few shields that can be attached to an Arduino board.
This one is in development at the moment: Kickstarter shield with Galileo
This one is compatible via the serial pins: GA-001 Multi GNSS Ublox
There is a "NEO-M8N" shield and maybe one or two others.

All those boards are very new, and I don't know if they come with a library for an Arduino. Perhaps you have to wait a few months and then it should be a lot easier to buy a complete functioning module with a library.

Before buying a module, confirm that there is a library for Arduino or good documentation to write your own library.


It is actually possible, but not easy.

The main MCU on the Uno, the ATmega328, is not capable of using the USB connection at a low enough level to make this possible. The other MCU on the Uno R3, the ATmega16U2, is. You can reprogram it to act as almost any arbitrary USB device.

Since the '16U2 has no connection to digital pins 2 and up or to any of the analog pins, you would have to program it to communicate with the '328 (or an external chip) via UART, and then have another program running on the '328 that would communicate with the other pins.

Note that you will need an external programmer for this, since once the '16U2 is reprogrammed you will lose the ability to program the '328 until you restore the original programming. Using another board running ArduinoISP will work for this.


Throughput and BER test with nRF24L01+ radio and Teensy microcontroller

@Gerben remarked:

  You can't send the ACK manually. The module itself sends the ACK
  automatically (if enabled that is), once it receives the package. This
  way the sending module only need to be listening for the ACK for the
  shortest amount of time, reducing power usage. To attach data to the
  ACK package you need the writeAckPayload function. But you have to
  prepare this before any package is received


Reading multiple NTC temperature sensors with Arduino

As I understand, you have multiple analog sensors you want to read. So your code should look something like this:

// assuming sensors are on A0, A1, A2, Ax

sensorPins [] = {A0, A1, A2};
int sensorNum = 3;

for(int x = 0; x < sensorNum; x++){
  readSensor(x);
}

Something like that should work for you.


How to set a timer for a function and be able to reset it in the middle of the process?

Below code is an example of what you described; pressing the button will turn on the LED and it will only turn off if 10 minutes passed or button is pressed again.

Read the comments in the code:

#define btn 5
#define rly 6

bool btnState;
bool ledState;
unsigned long timer = 0;

void setup() {
  pinMode(btn, INPUT_PULLUP);
  pinMode(rly, OUTPUT);
}

void loop() {
  btnState = digitalRead(btn); // Read the button status (default is 1)

  if (!btnState) { // If button state == 0 (pressed)
    ledState = !ledState; // Toggle this boolean
    timer = millis(); // and reset the timer
  }

  if (ledState) { // If LED state == 1
    digitalWrite(rly, HIGH); // Turn on the Relay
  } else { // Otherwise turn it off
    digitalWrite(rly, LOW);
  }

  if (ledState && millis() - timer > 600000) { // If 10 minutes passed turn off the relay
    digitalWrite(rly, LOW);
    ledState = !ledState;
  }
}

You should also de-bounce the button and you may want to turn on/off the LED when button is pressed and released, not just when it's pressed.


Can anyone help me spot where my buffer overflow might be occuring?

The problem with using "simplified code" is that your 'simplification' may not have captured your problem. But I will take your code as given and assume that it's correct (which I'm afraid it isn't).

var
    char buffer[6]  // Won't compile - no semicolon (';')
    float X;        // Uninitialised value - could be 1000000000000
    float thingposition = X * .0064 // No ';', and .0064 of 10000000000 is huge!

void loop(){
    Camera.Get_X(); // Should this be "X = Camera.Get_X();" ?
    dtostrf(buffer, 5, 2, thingposition)  // No ';'. You NEED to recalculate thingposition!

If the above code is a good representation of what you've got, you seem to be assuming that you define the formula once (in the thingposition line), and it automatically applies that formula, like Excel, when you change its input, X. Sorry, programs don't work that way.

Once you calculate thingposition, it becomes independent of where it came from. If you change other variables, thingposition kees its value until you explicitly change it.

How do you fix it? You recalculate thingposition every time:

var
    char buffer[6];      // Hopefully big enough - see below
    float X;             // Used by Camera.Get_X()
    float thingposition;

void loop(){
    X = Camera.Get_X();        // Get X from Camera
    thingposition = X * .0064; // Calculate thingposition
    dtostrf(buffer, 5, 2, thingposition);

Note that dtostrf() will try to obey your size parameters, BUT. If the float is larger than your maximum size, it WILL print out the full number anyway. That is, if thingposition is 1000, it will produce 5 characters all right: "1000.". But if it's 1000000, it will produce "1000000" which is seven characters. You need to ensure that buffer is big enough to handle larger numbers than you expect.

Do the maths. If X is guaranteed to be between 0 and 255, then multiplying it by 0.0064 will result in a maximum value of 1.632, so the above dtostrf() woud produce " 1.63". No problem!


Using a RH and Temp Calibrator I had access to I was able to get better results by all lines to adjust the RH and Temp to a better value. Basically a correction equation.


Why the SoftwareSerial is not working properly on Arduino Pro Mini 3v3?

You may get better results if you do not nest the read and write function calls as you did.  That is, read everything then write everything.

The reason for this is that softwareserial.read() returns 1 character.  If you immediately turn around and pass that character to softwareserial.write() you will devote the resources of the processor to sending that character.  In the meantime if another character is sent to the processor the processor will not see it or will only see part of it.

That said, you will likely get better results if you use a better embedded processor with dedicated serial port hardware for each port your project requires. Such as the Mega 2560 processor on the Arduino Mega.

Moving away from a cheap processor to one with enough hardware is a valid solution. Because, with another hardware serial port, the processor is only needed to read & write a character to & from the hardware using one command for each of these operations, not waste time reading & waiting each bit of a charater.  A hardware serial port or UART can cut the effort of receiving & sending a character by the processor by more than an order of magnitude.


Arduino loop over a function is always displaying 0 as final values

There's a couple of things wrong here:

You are just getting the last read value doubled:

x_offset += x_offset;

However x_offset is always replaced with the lates reading.  You're not summing anything.

To get anything other than 0 out of dividing an integer by 2000 the value stored in the integer would have to be > 2000. But since you can only store a maximum of 32767 in your int16_t variables, even if you didn't have the problem in point 1, the variables would overflow and the results would be meaningless.

You need to:

Use a second variable per axis to store your total
Ensure that it is big enough to store the maximum reading × 2000.  I'd suggest a long or int32_t.

For instance:

int16_t x_offset = 0;
int16_t y_offset = 0;
int16_t z_offset = 0;
int32_t x_total = 0;
int32_t y_total = 0;
int32_t z_total = 0;

And inside setup():

for(int i=0; i<2000;i++)
  {
    GetXYZ(x_offset, y_offset, z_offset);
    x_total += x_offset;
    y_total += y_offset;
    z_total += z_offset;
    Serial.println(x_offset);
    delay(3);
  }
  x_total /= 2000;
  y_total /= 2000;
  z_total /= 2000;
  Serial.println(x_total);Serial.println("...");Serial.println(y_total);Serial.println("...");
Serial.println(z_total);Serial.println("...");


You would need to create a buffer which will populate over each loop so you dont block the main loop while waiting the all string.

When you get the string or your buffer is full, just check whatever is the response, and based on that you can make your decision.


Arduino Uno and Arduino Yun software. Which version of the IDE works with both best?

The Yun startup was written when the normal IDE didn't support the yun, so you had to use a release candidate of a future version.

Those days are long gone.

Always use the latest version of the IDE.


Can AccelStepper accelerate non-linearly?

I appreciate the votes for exposure! Here is the answer I got from Mike, the creator of AccelStepper himself: link
Short answer: no!
I've posted the program I'm using now, which accelerates nonlinearly using pulse timing variation, in the linked thread.
Happy stepping!


I don't see any code for making new nodes or linking them into a list. A linked-list needs a root (a known variable that points to the first member of the list); a way to make or acquire new nodes and link them onto the list as the number of items grows; and a way to unlink a node and "discard" it - return its memory - once it is no longer useful.

I'll offer a couple of suggestions for linked-lists, especially in processors like the Uno with limited memory:

Don't be tempted to use malloc() and free() or new and delete for a system that must run continuously. Allocating and deallocating small pieces of memory, especially when interspersed with other allocation & deallocations, will lead to fragmentation of the heap (that portion of memory used for allocating memory at run-time). The result is that the heap will end up with lots of separate pieces of memory that are free but too small for other allocation requests, so the heap has to acquire more memory to satisfy the larger allocations. It does this by reducing the stack space! Eventually the stack will grow into the heap space, and the program will fail.My solution is to define a global array of node structs; enough of them for the program's greatest conceivable need, plus a few more for safety; link them into a list of free nodes; and give new nodes to the application by deallocating one from the free list. A You need link() and unlink() functions for a linked-list anyway, so it takes very little more code to do this.
Because we're talking about memory limited processors, If I don't need more than 255 nodes, I link with array indices instead of pointers, saving one byte per node. This costs a little bit more code to index into an array than to de-reference a pointer but compilers have gotten pretty smart about minimizing even that overhead.


Which is a better? GPRS SIM800L or GPRS SIM900?

SIM900 is older type. SIM800L has FM build it and it uses same AT cmds as SIM900.
Also, they are in same quadband. I guess both will work just fine.


Short answer: Yes.

At the end of a successful compilation (not upload), at least in ArduinoIDE 1.6.9, the final 2 messages look like:

  Sketch uses 23,442 bytes (72%) of program storage space. Maximum is
  32,256 bytes. Global variables use 1,093 bytes (53%) of dynamic
  memory, leaving 955 bytes for local variables. Maximum is 2,048 bytes.

In this case, 8814 bytes of flash remain unused, and 955 bytes remain for the use of the stack and the heap, combined.


Using a 3V latching relay to power up ESP8266

You use a latching relay of this form in the exact same way as a normal relay - it's just there's two of them.

One coil you want to control with a button (power on) and the other with a transistor (and possibly an "off" button as well).

simulate this circuit – Schematic created using CircuitLab

Press ON to latch the relay into the ON position (NO -> COM). Activate M1 or press OFF to latch the relay into the OFF position (NC -> COM).


How do i send ads1115 data over spi to master arduino

Implementing SPI slave mode is a little more tricky than you may think.  The most important thing to remember is that it's not a "Give me X" -> "Ok, here is X" kind of protocol.  It's actually a "Here's X" <=> "Here's Y" protocol.

That is, at the same time that the master sends X to the slave, the slave sends "Y" to the master.

The way you have it is that the master sends "a" as a command and discards what it receives.  The slave remembers that "a" as the "command". Then the master sends 0, and remembers what it receives. The slave receives that 0 and thinks "Ah, I got the command last time, so it must want the value" and queues up the value to be sent the next time a transaction occurs.  That then gets thrown away, since that occurs when the next "command" is sent.

You need to be a little more cunning, and implement a finite state machine to work out where in the stream you are.

When SS falls set a "byte counter" to 0.
When a byte is received examine the "byte counter":

Byte 0: If it's an "a" then place the first byte of the value in SPDR.
Byte 1: Place the second byte of the value in SPDR
Byte 3: Do nothing (or place 0 in SPDR)

Increment the byte counter

So the transaction goes something like this (1570 is 0x622 in hex, and I choose "little endian" since the AVR is naturally little endian):

Master Sends        Slave Queues          Master Receives
'a'                 0x22                  Rubbish
0                   0x06                  0x22
0                   0x00                  0x06

'a'                 0x22                  0x00
0                   0x06                  0x22
0                   0x00                  0x06

The important thing to remember is that the master receives what the slave queued on the next transfer.


Detailed instructions on how to shorten the bootloader time of Leonardo etc. are explained [here] (as stated by @Chris Stratton).

The crux of the matter was to redefine the timeout period

/* ./arduino/hardware/arduino/bootloaders/caterina/Caterina.c */
#define TIMEOUT_PERIOD 8000

to a lower value.

However I do not have such issues with Leonardo it boots very fast.
So this issue depends on your environment.

There is also OptiBoot, an alternative bootloader that really boots faster link:


The void in front of the function definition just tells what type the function returns.  In the case of void it means the function returns nothing.  If the function returned an int then it would be defined with int instead of void.

eg:

int addNumbers(int num1, int num2){
    int retval = num1 + num2;
    return retval;
}

int sum = addNumbers(3, 4);
Serial.print(sum);  // prints 7

No, the loop only loops because main (see main.cpp in the core) is the "real" program that is running on your micro and it calls loop over and over.  It's not that the loop function on it's own repeats.  It is literally being called repeatedly by the main function.

That example also gets to what the parenthesis are for.  That's where the arguments that the function takes go.  In the function definition you tell it what types they'll be and give them names.  In the function call you put in whatever values you want to function to use.  In the case of void loop(), it takes no arguments so the parenthesis are empty.

I would suggest you look at a basic tutorial on C++.  There are many good ones on the web.  The concept of functions isn't something that you can reason your way through by doing.  Go read a little and you'll get it pretty quick.


i586-poky-linux-g++: no such file or directory Error compiling for board Intel® Edison

The problem here is that Intel, in their infinite wisdom* have lots of hard-coded paths to libraries in the binaries (why, heaven only knows) and then a set of scripts that munge those binaries to sort out where the libraries really are.

That script uses an option to find that was deprecated 13 years ago.

Way to keep up with the times, Intel...

So you need to make some fixes to get the toolchain to install properly.

I have created "fix" scripts for both the Edison and the Galileo that you can use to replace your broken toolchain.

https://github.com/majenkotech/IntelFixes

*i.e., sheer incompetence


Using SoftwareSerial along with FastLED library to control WS2812 LEDs

The FastLED and NeoPixel libraries turn off interrupts for the specific timing of the WS2812. The Adafruit NeoPixel has a few extra options to be able to still handle some interrupts. The FastLED has a wiki that describes the problem with interrupts: FastLED wiki interrupts

The SoftwareSerial requires interrupts. When the SoftwareSerial is busy, the Arduino is occupied.

To me it seems impossible to make both libraries work at the same time. I think you have to change something. For example use a Arduino Micro or Pro Micro and use the spare hardware serial port. Or use a ledstrip with leds that have a clock signal and don't need specific timing.

If that is not possible, you might have to use pin 0 (RX) and pin 1 (TX), which are also used by the serial monitor and to upload a sketch.
It is possible to split RX and TX. The only thing that RX and TX have in common is the baudrate, but you can use them for seperate tasks.
For example, use TX to send (debug) messages to the serial monitor, and use the RX to receive commands from another Arduino board. Disconnect that other Arduino board to upload a sketch.

[ADDED] After reading the answer by @Andrew and the FastLED wiki about interrupts, I think that my answer and @Andrew's answer are equally good answers. Perhaps the best way is to do it all: faster Arduino board, hardware serial port for commands, do one thing at a time, implement some kind of XON/XOFF in software, and if possible use other leds.


Why/when to use IoT publish/subscribe protocols rather then RESTful HTTP?

In my experience ReST is good for real-time data transfer and processing but has a lot of overhead for simple message passing. Plus, there's no queuing in it so store-forward configurations are troublesome.

MQTT is a message queue transport system where the message can be placed on the channel by the publisher and will stay there until the subscriber picks it up. So you can have some rudimentary store-forward capabilities with this. Also MQTT is more transparent and multicast so communicating to many nodes is no different than communicating to one.

With that, each have their place and use and ReST is great for sending large items (JSON blobs), sending data for calculation and getting it back, and for requesting a specific dataset. MQTT is more for "here's my sensor data every second, enjoy".


Is it possible to read-write the memory of a Gikfun ISD1820 voice recording module?

No. You can't. That module can only record and play.

The only possible thing you could do is record onto the chip then play it back recording it on to the Arduino (at ridiculously low quality) - in which case, what would the point of the chip be?

If you want some quality to your recordings you need a powerful microcontroller with an I2S interface and a CODEC chip.  However any powerful MCU (such as the ARM chip on the Due, or the Teensy, or the PIC32 chip on the chipKIT boards) can sample at a reasonable quality through the ADC inputs.

The Arduino Uno can record very short bursts at very low quality (due to lack of memory) without any external hardware (except a suitable microphone preamplifier). The Mega can record slightly more, but the quality will still be very low.


0x63 is the correct address - the module is at 0xC6 which is the 8-bit equivalent of 0x63 (0x63 shifted left once for the read/write bit to be added).

The LCD03 uses its own custom I2C protocol, not compatible with the "normal" I2C LCD library. Instead you have to use their own special commands.

The commands are detailed here: http://www.robot-electronics.co.uk/htm/Lcd03tech.htm

There may be a library available that wraps those commands, I don't know, but you can just use the Wire library to send the commands you need to send.


Arduino Ethernet shield cannot establish connection

The W5100 chip doesn't have a mac address by itself. You can assign any mac address to it that you want. With Ethernet.begin(mac); you assign the mac address to the W5100 chip.
The official Arduino Ethernet shield comes with a paper with a unique mac address. That is a nice service, but that is just a number, the Ethernet shield hardware is without any mac address.

There has been complaints about wrong resistor values near the ethernet connector. Can you read the numbers on those resistors ? They should be labeled as "510" and not as "511" : Arduino forum about ethernet resistors.

The Ethernet Shield uses more power than most other shields, and the W5100 can get pretty hot. Do you have enough power ? Is the 5V pin still above 4.5V ?

It is possible that your router does not accept the old W5100.

If the resistors are okay, I suggest to try an example with both mac and ip: Ethernet.begin(mac, ip);


SPI.h library by default only support Master mode, the SPI.begin() will automatically set slave select (ss) pin to HIGH whether you have pinMode(ss, OUTPUT) in your setup() code or not and set the Arduino as an SPI master. This can be see on SPI library source code.
As the SPI library does not contain the functionality for slave mode, in order to use Arduino as a Slave, you will need to do some customised setup, mainly on 1) setting MISO as OUTPUT for slave to send data; 2) enable slave mode by setting the SPCR register; 3) enable interrupt when data is received. Here is an example for an SPI slave on Arduino.
#include<SPI.h>

volatile boolean received;
volatile byte receivedData;

ISR (SPI_STC_vect)        //Inerrrput routine function
{
  receivedData = SPDR;   // Get the received data from SPDR register
  received = true;       // Sets received as True
}

void setup()
{
  Serial.begin(115200);

  pinMode(MISO,OUTPUT);   //Sets MISO as OUTPUT
  SPCR |= _BV(SPE);       //Turn on SPI in Slave Mode
  received = false;
  SPI.attachInterrupt();  //Activate SPI Interuupt
}

void loop()
{
  if(received) {
    SPDR = receivedData;    // send back the received data, this is not necessary, only for demo purpose
    received = false;
    Serial.print(receivedData, HEX);
  }
}


Can you connect an output pin from one Arduino to the input pin of another?

Yes, you can. That is indeed the most easy way of communication.

And like you said, you have to connect the grounds of both arduino's.

Optionally you could add a pull-up of pull-down resistor, so the countdown doesn't accidentally start if the first arduino is still starting up, or is disconnected.


Connect Arduino Uno RX/TX to 3.3v NEO-M8N gps module

Buy some of these, it's a simple hardware solution to your problem then.

https://www.amazon.co.uk/gp/product/B0148BLZGE/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1

I know you said you don't want to use a level converter but it's the simplest way around the problem.
You stated that you're an electronics beginner AS AM I, which is exactly why when I came up against the same problem i just spent the money.
It was only £3.99 for 5 of them and as far as I'm aware you should be able to buy single ones off amazon too, haven't searched but i'd have thought you'd be able to.

Or if you need to do it with resistors you can use this calculator here

http://www.ohmslawcalculator.com/voltage-divider-calculator


Using a analog multiplexer to use 9 serial input sensors?

No. Not unless you can change your communication protocol to be a "call-and-response" protocol.

Basically, the problem is this: when do you switch to which serial device? Unless all the devices have their timing synchronised there is no way of knowing - so how do you control your analogue multiplexer in that situation...?  You can't.

You would need to have some method of the master switching the multiplexer to a specific peripheral, then send a message to that peripheral saying "Send me your data now".

You would be better off investigating other boards with more UART ports, such as the Mega2560, and having multiple boards.

The Mega2560 has 4 UART ports. You can have 4 sensors per board (5, if you want to use SoftwareSerial or, better, AltSoftSerial), so you could get away with two boards.

One board acts as normal, communicating on the UART ports to 4 sensors, and also acts as an I2C or SPI master (the choice is yours). The second board communicates to 4 more sensors on UARTs and one further on using AltSoftSerial etc. It also acts as an I2C or SPI slave device.

The "slave" board just runs autonomously gathering data from the sensors it is directly connected to and storing those values.  The "master" then periodically asks the "slave" board for the latest data.


I usually recommend against using delay()s, but if this system will only ever have to do what you've described, using delay()s is the simplest way to implement it.
I would suggest sending key-1, possibly several times, maybe a half second apart, delay for the 20 seconds you suggested, then send key-2, definitely several times for security.


Easiest would be to use 2 arduino's, which are connected in some way.
One of them should tell the other one what to do. I suggest you make the one reading the buttons the "master" and the other one it's "slave" device.

You could use 8 inputs, for each column and 10 outputs for each row.
Then you check all 8 inputs per column (pretty rapidly) and then you'll be able to read every button.

You could choose to either send changes or just every value to the slave device.

The slave device would have to do something similiar, but with 2 outputs, to address the right LED's/segments.

Alternatively you could use shift-registers.

There actually are a lot of tutorials on this to be found on the web.
You should check out "Arduino multiplexing" or "Arduino led cube" tutorials.


RS-232 etc mean different things in different contexts.  More specifically it is called TIA/EIA-232.

It refers to both the electrical characteristics of an NRZ signalling system, and at the same time it refers to the packet format for the transmission of data through such a system.

It also refers to the connectors that are used with such a system and, by extension, the cables that have those connectors on them.

  The standard defines the electrical characteristics and timing of signals, the meaning of signals, and the physical size and pinout of connectors. The current version of the standard is TIA-232-F Interface Between Data Terminal Equipment and Data Circuit-Terminating Equipment Employing Serial Binary Data Interchange, issued in 1997.

RS-485, or TIA/EIA-485, in contrast only specifies the electrical characteristics and not the data that is sent down the line. It doesn't specify any connectors to use, nor what format the data should take. For instance you can use RS-232 formatted packets, or you could use a MODBUS-RTU format that uses completely different packets. It only refers to the drivers and voltages used.

  TIA-485-A, also known as ANSI/TIA/EIA-485, TIA/EIA-485, EIA-485 or RS-485, is a standard defining the electrical characteristics of drivers and receivers for use in balanced digital multipoint systems.


Multiple definition of "..." Compiler Error

Although the motor (global) variables are defined in a header files, they are included in both cpp files, thus defined twice.

Make them extern, and than define them in the motor.cpp file.

In motor.h, change

Servo motor1, motor2, motor3, motor4;
Servo motorArray[4] = {motor1, motor2, motor3, motor4};

to

extern Servo motor1, motor2, motor3, motor4;
extern Servo motorArray[4];

In motor.cpp, add:

Servo motor1, motor2, motor3, motor4;
Servo motorArray[4] = {motor1, motor2, motor3, motor4};

As a side note, use consts for values 4 and 2000.


The VIN pin outputs 5V approximately (dependent on USB input voltage) from the NodeMCU board.


Is it possible to output a variable clock using Fast PWM?

I'm not sure whether this is the real issue you have, but I spot an issue which can be the issue you have.

You wrote something like this:

if (pulseFromEncoder)
  if (direction1)
    OCR1A -= 100;
  else
    OCR1A += 100;

Now, the OCR1A is a unsigned 16 bit integer. A value of 100 corresponds to 1.6ms of delay on the timer (see comment from Edgar Bonet below). This is what happens when you rotate in direction 2:

        OCR1A  Time delay
Rotate:   300      4.8ms
Rotate:   200      3.2ms
Rotate:   100      1.6ms
Rotate:     0      0ms
Rotate: 65436   1047ms

See? The value rolls over and the time completely changes.

Now, maybe the issues are other (for instance changing the mode to 15 instead of 4 like EdgarBonet said (no idea on what this means, you should double check the differences on the atmega datasheet), but I strongly suggest you to fix this issue, for instance this way:

const uint16_t OCR1A_Min = 0
const uint16_t OCR1A_Max = 20000
const uint16_t OCR1A_Step = 100

...

if (pulseFromEncoder)
  if (direction1)
  {
    if (OCR1A > OCR1A_Min + OCR1A_Step)
      OCR1A -= OCR1A_Step;
    else
      OCR1A = OCR1A_Min;
  }
  else
  {
    if (OCR1A < OCR1A_Max - OCR1A_Step)
      OCR1A += OCR1A_Step;
    else
      OCR1A = OCR1A_Max;
  }

Sidenote: doesn't your encoder need debounce?


cannot connect ESP8266 web server after some time

The esp8266 enters modem sleep in STA mode without WiFi traffic. You can turn off the sleep mode with WiFi.setSleepMode. The possible parameters are WIFI_NONE_SLEEP, WIFI_LIGHT_SLEEP or WIFI_MODEM_SLEEP.

After some longer time the servers on esp8266 with arduino core usually get inaccessible even it the esp8266 connects as client to other servers or still sends UDP messages. It is a known issue with some possible workaround documented.


How do send sketch updates to devices without the editor?

In general, yes.

The compile routine creates a .hex file in a temporary directory that contains the flash image for the device. One can use AVRDUDE to upload this .hex file to the Arduino from the command line. It is simply a matter of getting the command arguments correct in order to tell it where and how to upload the image. Enabling verbose output in the IDE will tell you both exactly where the .hex file is located and what arguments are required for the board selected.


The Arduino isn't a computer. It is a programmable microprocessor / microcontroller.

Generally a computer can run multiple applications where most programmed devices like the Arduino are running only one program. This is not an official definition but it is one way to differentiate.

It can be difficult to draw a line where it is one but not the other.

  (4) Arduino has some bootloader code to load the program through USB.
  Isn't it kinda like OS, I admit it's not giving some nice api for h/w
  usage but is it all?

No that isn't like an operating system. The Arduino does not have a real operating system when compared to a computer system. And someone being able to load in a new program is just changing the current single program that is runnable.

  An operating system (OS) is system software that manages computer
  hardware and software resources and provides common services for
  computer programs.

I think the programs being plural is an important factor, but this is only my opinion.

There is no one definition so you will get a number of different opinions. And most will be reasonable.


How to discard same string received at Arduino

Only print the string when he has changed?

String previousString = "";
String newString = "";

if(newString != previousString){
   println(newString);
   previousString = newString;
}

I'm not sure if it's applicable in your situation, just the first thing that came to my mind. You (kinda) should make a function of it, so that you don't have to copy/paste it all the time and it'll look way better.

EDIT:

A fuction could be made like so:

String previousString = ""; //Put this above your setup code (global variables)

void NoSpamString(String input){ //Put this block before the setup
   if(input != previousString){
      println(input);
      previousString = input;
   }
}

You can then use: NoSpamString("text"); to print a line withouth spamming it.


The Arduino core library configures the Timer 1 for phase-correct PWM at
about 490 Hz. Then you are setting some configuration bits in the
timer's control registers without clearing the bits that had previously
been set by the Arduino core. If you want to use the timer for your own
purposes, and configure it by yourself, you should completely overwrite
the core's configuration with your own. For that, use the = operator
rather than |=, as in:

OCR1A  = 99;                         //Count to 400us
TIMSK1 = (1 << OCIE1A);              //Enable interrupt
TCCR1A = 0;
TCCR1B = (1 << WGM12)                //Mode 4, CTC
       | (1 << CS11) | (1 << CS10);  //Prescaler 64


making power harmonics analyser which will measure the amplitudes of the fundamental and its multiples (like 50hz, 100hz, 150hz,200 hz,...) there are)

The general idea of your code looks OK, but consider using a hardware timer rather than the for loop for data acquisition.  The sampling rate will be much more accurate and uniform because you eliminate (possibly cumulative) errors in timing.  See this post for an example.

Do you know how the FFT.MajorPeak function works?  If it simply finds the frequency of the largest point in the magnitude spectrum, this may not be a good measure of the 50 Hz peak etc.  Instead, consider taking the area under the curve around the frequency of interest f_0, say f_0 - 2 Hz to f_0 + 2 Hz.  The same code should be usable to measure the spectral power around any of the harmonics.

Also note that the mains electricity frequency is not exactly 50 Hz / 60 Hz.  The short-term variation is around plus/minus 1 Hz.  The above approach will also help make reliable readings.


How can I connect multiple different sensors that uses the same pins?

You are lucky, the two devices creating the conflict both use the same pins because they both use the same interface, SPI to be precise, which allows to have multiple devices connected using different Chip Select pins, abbreviated as CS.

Of the two libraries, one allows to define the CS pin (RFID module), the other has it hardcoded (ePaper). So, when declaring your RFID library, you should use the constructor that allows to define the chip select pin:

void PCD_Init(byte chipSelectPin, byte resetPowerDownPin);

This means in your code you should use:

PCD_Init(6,8) rfid;

The above also implies one of your RFID connections must be changed: what was previously SDA --> Digital 10 is now going to be SDA --> Digital 6. Please note I picked pin 6 randomly among the pins that seem unused by your code, but any other unused pin will be a good choice, including analog pins.

BTW, the web page about the RFID module uses a pin naming which causes a lot of confusion because it mixes up SDA with MISO and MOSI: those names are used in two different types of interface, the former is called I2C or TWI, the latter SPI. On Arduino the two interfaces share a couple of pins, but they are very different in many different ways.

In your case both modules use SPI, which is good for you.


For doing:

shared_ptr<Base_class> b_ptr;
shared_ptr<Child_class> ptr(b_ptr);

you have to use another constructor. If you take a look on this Example of shared_ptr implementation, you can see:

template<class U> shared_ptr(const shared_ptr<U>& s) ...

That's exactly the constructor, that takes shared_ptr of different type .

And similarly for assigment operator.


Fading the brightness of LEDs using MAX7219 and PWM

This is possible in two ways:

The MAX72xx has its own internal intensity control register. From the datasheet:

  Digital control of display brightness is provided by an internal pulse-width modulator [...]. The modulator scales the average segment current in 16 steps from a maximum of 31/32 down to 1/32 of the peak current set by RSET [...].

This of course requires no extra components or effort, but you are limited slightly by only a 4-bit intensity resolution. Also, there is no 'off' so you'd have to either manually blank the displays or put the ICs into shutdown mode.

Your suggested way is possible. However, the low frequency of the Arduino's PWM may lead to flickering if the MAX7219's internal segment current reference driver needs a steady voltage. You'll have to consider smoothing the PWM output through a low pass filter - the TL072/TL082 has two op-amps so you can use one for colour A and the other for colour B. I'd choose an op-amp over passive filtering because the current drawn from the Arduino will be negligible and the stability of the current into the MAX7219 will be improved.


The above comments are spot on.  It sounds to me like you are new to the Arduino, so the very first thing to do is go to the Arduino Reference page https://www.arduino.cc/reference/en/.  That shows you the basic tools you will need to work with.  It's not obvious from that page, but analogWrite() is what you use for the PWM, as explained if you click on that topic.  Note that it only works on certain pins.  Don't worry about controlling a motor at first, just control the brightness of an LED until everything is debugged.
You mention 3 different intervals.  Are each of these to give equal on and off times, and just keep repeating until you turn the stirrer off?  Or will you have a separate fixed run time and the buttons selects one of 3 different off times per cycle?  Or is there only one cycle, and the buttons just select how long it will be before automatically shutting off?  The answer will determine how you set up the timing.  Assuming that the UNO doesn't need to do anything other than control the stirrer, you can probably do all timing with the delay() function.
You can start with the famous "blink" code.  Once you get that working, change it to use one of the pins that supports PWM (not the built-in LED on pin 13).  The code has separate delay() values for on and off times, which you can set for one of your 3 intervals.  Then change the digitalWrite() commands to analogWrite(), of course with the proper parameters. Now you have the basic system, and can work on the switching logic.


How to create jumping wire using fritzing tool

Draw the wires
press and hold control button (mouse pointer will appear with a curve symbol)
drag the wire using mouse


Why serial communication does not work on atmega168/328p?

The problem you have is that your baud rate is not being set right.

You only have part of the settings you need.  There is a third macro in the setbaud.h file that you need to take account of:  USE_U2X.

That defines whether or not you need to set or clear the U2X0 bit of UCSRA0.  If that is set wrong then your baud rate will be either twice or half what you want it to be - in this case it's coming out as twice.

Modify your code to assign the baud rate like this:

#include <util/setbaud.h>
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
#if USE_U2X
UCSR0A |= (1<<U2X0);
#else
UCSR0A &= ~(1<<U2X0);
#endif
UCSR0B |= (1<<RXEN0);
UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00);

Then you should be able to receive characters.

In the actual header file in question there is a large number of comments and instructions, including this:

  Assuming that the requested BAUD is valid for the given F_CPU then
     the macro UBRR_VALUE is set to the required prescaler value.  Two
     additional macros are provided for the low and high bytes of the
     prescaler, respectively: UBRRL_VALUE is set to the lower byte of
     the UBRR_VALUE and UBRRH_VALUE is set to the upper byte.  An
     additional macro USE_2X will be defined.  Its value is set to 1 if
     the desired BAUD rate within the given tolerance could only be
     achieved by setting the U2X bit in the UART configuration.  It will
     be defined to 0 if U2X is not needed.

My resulting UART configuration, which may be being affected by the bootloader, is:

UBRR0H: 0x00
UBRR0L: 0x67
UCSR0A: 0x20
UCSR0B: 0x10
UCSR0C: 0x06

That equates to data register empty, RX enabled, 8-bit.

To my mind that is equal to the values being manually set in the code, so shouldn't be a problem.


I am making an easy game but something in my code is wrong

Don't use delay(), since nothing can happen (not even reading a button) while that delay is running.

Instead use millis() as in the BlinkWithoutDelay example sketch.


Arduino LED flashes with one button press

Because the digital writes only apply on if (digitalRead(button)==HIGH). If you don't press the button, then the code goes:

void loop() {
}

Essentially doing nothing. Your code needs a bit more to keep track of the button press. Pseudo Code:

if button == pressed {
    int tracker=1;
}
if tracker == 1 {
    led on;
    wait;
    led off;
    wait;
}
loop


Bootloader on Atmega328p overwrites whenever it gets programmed

Almost certainly your fuses are wrong. The fuses tells it whether or not to run the bootloader. With an empty PROGMEM (ie. no sketch) the processor probably skips over all the 0xFF bytes until it hits the bootloader. Once you have a sketch there it will run the sketch.

On my Uno (which is an Atmega328P) running at 16 MHz from a crystal, my fuses are:

Low = FF High = DE Ext = FD Lock = EF

I suggest you visit http://www.engbedded.com/fusecalc to work out fuse settings.

You want the BOOTRST fuse set (that is, the high fuse should be 0xDE or something with the low-order bit clear). On the AVR chips, having a bit clear (0) means the fuse is set.

I have a bootloader programmer sketch which not only puts the bootloader there, it sets the correct fuse bit.

I also have a chip detector sketch which will tell you the current fuse settings.


This answer contains a few debugging guidelines, as I don't know what the problem is and don't see how one could tell without a good deal more of information.

I suggest creating a Minimal, Complete, and Verifiable example (MCaVe) of your code, not just snippets, so that other people can compile and run the code, thus being able to observe what happens in more detail and perhaps with added debugging output.

I'm presuming your callback is triggered as a consequence of an interrupt occurring.  I suggest you write the MCaVe to depend on a pin-change interrupt, rather than a motor-controller interrupt, to allow testing on a system consisting of no more than an Arduino with a button, a serial interface, and perhaps a few LED indicators.  Pressing the button would change pin voltage and cause an interrupt; your ISR would turn on an LED to signal it handled the interrupt, then trigger the callback.  The callback routine would turn on another LED as its signal.  The main loop would read the pin register bits for the two LEDs, record and report the times they came on, and turn them off after a second or two.  If you get a simple setup like this to work, the technique probably would carry over to your motor-controller case; or if not, probably being a smaller program and setup should be easier to debug and figure out why not.