message:
Unable to Configure MQTT Client ID using Adafruit MQTT Library

I am utilizing the MQTT library that Adafruit has created, located [here][3], and the library itself works wonderfully - however I am finding myself unable to edit the Client ID or configure the PINGRESP. The code that I am currently using can be seen below -

    WiFiClient client;
    Adafruit_MQTT_Client mqtt(&client, "10.116.10.191", 1883);

When the client connects to the MQTT Broker the client ID turns into a random string of letters, numbers, and symbols, as seen below -

    1534023607: Client ]7llG5K6J4=^tPHJHqgTUFc<Ep^m3vJ`4vSL2oB<cO[^_chw[GBp]v3smagpOqWS has exceeded timeout, disconnecting.
    1534023608: New connection from 10.116.7.21 on port 1883.
    1534023608: New client connected from 10.116.7.21 as ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu (c1, k300).
    1534023608: Sending CONNACK to ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu (0)
    1534023608: Received SUBSCRIBE from ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu
    1534023608:  quantity (QoS 0)
    1534023608: ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu 0 quantity
    1534023608: Sending SUBACK to ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu

After a duration of time has passed the client exceeds the time out and disconnects.. Any advice on overcoming this obstacle would be greatly appreciated. I've tried the following for changing the ClientID, per the client constructor to the MQTT broker -

    Adafruit_MQTT_Client(Client *client, const char *server, uint16_t port,
       const char *cid, const char *user, const char *pass):

----

    WiFiClient client;
    Adafruit_MQTT_Client mqtt(&client, "10.116.10.191", 1883, "Rear-Controller");

This was the result of adding the clientID, ("Rear-Controller"), after the MQTT Broker port # -

     New client connected from 10.116.7.21 as GFONMktFXFSG1rARE@JWCRv@P^XwLifdo<rCg]YFs4Ndf_>2_XIsjFsAtS08Cf\: (c1, k300, uRear-Controller)

  [3]: https://github.com/adafruit/Adafruit_MQTT_Library

body:
The Client ID is expected to be stored in flash memory (it is read using `pgm_read_byte`). However, on the Arduino, unless told otherwise it first copies the string literal into RAM.  That means that the function is getting the address of the string in RAM, not in flash, and using it as if it were the address in flash, and that gets gibberish.

You need to force it to be in flash by creating a PROGMEM string:

    const char clientid[] PROGMEM = "clientfoo";
    Adafruit_MQTT_Client mqtt(&client, "10.116.10.191", 1883, clientid);


sender: user

message:
Regain WIFI connectivity

I wrote a code to be implemented in a SONOFF device (ESP8266 chip).
My question is regarding disconnection due to failure/ power fail in wifi network - when such event happens, does wifi connectivity try to reconnect or to over come this possibility - should I enter  inside `void loop ()` to verify wifi connectivity ?

    #include <ESP8266WiFi.h>
    #include <PubSubClient.h>

    // GPIOs on SONOFF board
    int LED_SONOFF = 13;
    int REL_SONOFF = 12;
    int PIN_SW = 14;

    const char* ssid = "Home";
    const char* password = "12345678";
    const char* mqtt_server = "192.168.2.113";
    int last_sw_state = 0;

    WiFiClient espClient;
    PubSubClient client(espClient);

    char msg[50];
    const char* clientID = "Sonoff";
    char *client_temp = "HomePi/Dvir/Windows/";
    const char* outTopic = "HomePi/Dvir/Messages";
    const char* outTopic2 = "HomePi/Dvir/Windows/ESP32";
    const char* inTopic [strlen(client_temp) + 3];
    const char* inTopic2 = "HomePi/Dvir/Windows/All";

    String clock;

    void start_wifi() {
      WiFi.mode(WIFI_STA);
      WiFi.begin(ssid, password);

      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }

      Serial.println("");
      Serial.println("WiFi connected");
      Serial.print("IP address: ");
      Serial.println(WiFi.localIP());

      for (int i=0; i<3; i++){
        digitalWrite(LED_SONOFF,LOW);
        delay(50);
        digitalWrite(LED_SONOFF,HIGH);
        delay(50);
      }
    }

sender: assistant

body:
> My question is regarding disconnection due to failure/ power fail in
> wifi network - when such event happens, does wifi connectivity try to
> reconnect or to over come this possibility

use `WiFi.setAutoReconnect(true);` when initializing WiFi

other useful option is `WiFi.setAutoConnect()`. It controls if the esp8266 next time starts the WiFi connection with remembered setting, before your sketch starts.


message:
Doubt using character array

I'm trying to make a led sign with a WS2812b ledstrip, using the [FastLed][1] library (by the way, this is a great library!), I'm already able to show a text (so far only one, which I leave saved in an array of characters at the beginning of the program), but I would like to be able to change this text using the serial port of the Arduino, and here is the problem:

When setting the text to be displayed in the array of LEDs, the function that I should use is:

    ScrollingMsg.SetText ((unsigned char *) TxtDemo, sizeof (TxtDemo) - 1);}

Where ***TxtDemo*** is a variable type char array.

Until here all is right, as I commented I can show the text, but at the time of receiving the data from the serial port and save them in the char array TxtDemo, when I use the function `sizeof(TxtDemo)`, the value I get remains with the original size (quite understandable) of this array.

For example: If the initial text was (saved in TxtDemo):
*"Hello world"*, the `sizeof()` function, returns *"11"*,
But when I pick up what I want to show on the serial port and store it in the variable **TxtDemo**, there's no way I can alter the size of that array. So ... what can I do? What do you recommend me to do?

  [1]: http://fastled.io/

body:
Arrays in C are fixed. `sizeof()` will always give the amount of allocated memory for the array.

Instead, you should be using `strlen()` to get the number of characters up to (but not including) the terminating NULL character at the end of the string.

    ScrollingMsg.SetText ((unsigned char *) TxtDemo, strlen(TxtDemo));

Make sure that you have enough space in your initial array to store the longest string you will want to send - *it will not grow beyond your initial allocation*. Also be sure to get the NULL character at the end of your valid text. It's too easy to forget you need to insert that after your last received character.


message:
How do I change the default LED pin for displaying uploading

I made a board for my project based on Arduino Pro Mini. The problem is, that I had to put the LED on pin 4 instead of pin 13.

What setting do I have to change to make pin 4 the default one? Or do I have to write my own Board Library?

body:
The blinking while uploading makes the bootloader. Arduino Mini uses Optiboot. The source codes are [on GitHub][1]. You would need to change the pin in pin_defs.h and make the bootloader. Then flash it to the 328p with a programmer over ICSP.

Details what to change are in [Greenonline's answer][2].

  [1]: https://github.com/Optiboot/optiboot/blob/master/optiboot/bootloaders/optiboot/pin_defs.h
  [2]: https://arduino.stackexchange.com/questions/55279/how-do-i-change-the-default-led-pin-for-displaying-uploading#answer-55282


body:
Following on from [Juraj's answer][1]:

> The blinking while uploading makes the bootloader. Arduino Mini uses
> Optiboot. The source codes are [on GitHub][2]. You would need to
> change the pin in pin_defs.h and make the bootloader. Then flash it to
> the 328p with a programmer over ICSP.

The line that you need to change in [`pin_defs.h`][2] is [line number 27][3]:

    #define LED B5

As you can see it is currently set to `B5`. This is the fifth bit in port B which corresponds to pin 13

Pin 4 corresponds to `PORTD` bit 4, so the line would become

    #define LED D4

The Arduino digital pins are connected to three different banks of 8 bits, known as *ports* (`PORTD`, `PORTB` and PORTC`). To see their relation, refer to this table from [Arduino Playground - Pins][4]

> [![Ports to Pins table][5]][5]

  [1]: https://arduino.stackexchange.com/questions/55279/how-do-i-change-the-default-led-pin-for-displaying-uploading#answer-55280
  [2]: https://github.com/Optiboot/optiboot/blob/master/optiboot/bootloaders/optiboot/pin_defs.h
  [3]: https://github.com/Optiboot/optiboot/blob/master/optiboot/bootloaders/optiboot/pin_defs.h#L27
  [4]: https://playground.arduino.cc/Learning/Pins
  [5]: https://i.stack.imgur.com/Jccjt.png "Ports to Pins table"


message:
How can I make a power button for my project powered by a USB powerbank?

I've solved the battery power supply issue for my Arduino project by simply connecting a USB powerbank. However, I just realised that I can't come up with a good way to add an on/off button! There doesn't seem to be a way to turn the Arduino off using software. My second solution would be to cut up the USB cable (or an extension chord) and solder a switch onto the 5V wire.

Is there a more convenient solution that I'm missing?

body:
You could put the microcontroller into sleep-mode. Then use a button (connected to one of the interrupt pins) to wake it up.

But depending on what Arduino board you are using, and what other sensors etc you've connected to the board, this might not save that much current. For example on the UNO board the usb-to-serial converter is always on, so while your MCU is sleeping and trying to save power, the usb-to-serial continues to draw current.

But adding a switch to a usb-cable would be a lot simpler.

PS doesn't the powerbank have an on-off switch?


message:
Is SRAM erased when putting Arduino into sleep_mode_pwr_down?

# Question
In the interest of reducing power consumption, I am putting the Arduino into sleep mode between taking sensor readings. However, the data from readings are stored in arrays, and must not be erased when the device enters sleep mode.

For clarity, I am using sleep_mode_pwr_down, and triggering an interrupt using the Watchdog Timer on the ATMega328 chip. See this post for a description of the different sleep modes: https://arduino.stackexchange.com/questions/6/what-are-or-how-do-i-use-the-power-saving-options-of-the-arduino-to-extend-bat/31#31

It would be possible to address this issue by writing data to the EEPROM, however, I am unsure whether this is necessary. **The question is whether putting the device into sleep_mode_pwr_down erases the dynamic memory?**

___
### Specs / Context:
Arduino Uno (ATMega328 chip)

body:
Generally, Atmega sleep modes **do not erase RAM**. Their memory is static and as long as voltage (above 2.7V I believe) is applied, data is held.

However, this also depends on how you plan to wake up the device.
If it receives a RESET, RAM is cleared and program execution starts from the beginning.

> If an enabled interrupt occurs while the MCU is in a sleep mode, the MCU wakes up. The MCU is then halted for four cycles in addition to the start-up time, executes the interrupt routine, and resumes execution from the instruction following SLEEP. The contents of the Register File and SRAM are unaltered when the device wakes up from sleep.

Check out the [AVR's sleep modes][1] to see which fits your application best and how to safely wake it up again

  [1]: http://microchipdeveloper.com/8avr:avrsleep


message:
Arduino fingerprint verification from server

I am thinking to do a hobby project related to fingerprint verification. The flow which I wanted to implement is something like below:

 1. A user can register a fingerprint using an Arduino device
 2. This fingerprint will be saved on a remote server so that user can be verified on some other Arduino devices
 3. When a user tries to verify, the fingerprint will be matched against the fingerprint stored on the server

For this, I am thinking to use the Go language on the server side as an API server, MySQL/SQLite as a database system. Further, in the future, I will build a mobile application to perform some query with the server like running devices, the number of registered users, revoke users etc.

For now, I am planning to buy the following devices:

 1. [Arduino UNO][1]
 2. [A wifi shield][2]
 3. [A fingerprint sensor][3]
 4. [An LCD screen][4]

Now the question is, will the devices mentioned above will work for my setup, or I need to buy something else (Are they compatible?)

Also, is there a way to store the fingerprint on a server? I am thinking to store some kind of hash (probably RSA encrypted) of a fingerprint on a server, will it work?

Any relevant example of storing fingerprint on a server?

  [1]: https://www.amazon.in/Generic-Arduino-UNO-Robotic-Projects/dp/B01121OB8C/ref=sr_1_5?s=industrial&ie=UTF8&qid=1534249728&sr=1-5&keywords=arduino uno
  [2]: https://www.amazon.in/Generic-PZIN51000059-Esp8266-Serial-Wireless/dp/B01EM11EU2/ref=sr_1_5?s=industrial&ie=UTF8&qid=1534249778&sr=1-5&keywords=arduino uno wifi shield
  [3]: https://www.amazon.in/Fingerprint-Reader-Optical-Attendance-Scanner/dp/B07C6ZYFRN/ref=sr_1_1?s=industrial&ie=UTF8&qid=1534249833&sr=1-1&keywords=arduino uno fingerprint
  [4]: https://www.amazon.in/Robotbanao-Display-Shield-240X320-Arduino/dp/B07CVWBP21/ref=sr_1_15?ie=UTF8&qid=1534250088&sr=8-15&keywords=arduino uno lcd

body:
According to the [adafruit driver's code][1], it is capable of loading and storing fingerprint templates (256byte each) from and to its flash

      uint8_t emptyDatabase(void);
      uint8_t storeModel(uint16_t id);
      uint8_t loadModel(uint16_t id);
      uint8_t getModel(void);

These functions would allow you to sync the local database of each device with a server for example or even download and test for each template individually, which would obviously be pretty slow and only viable, if you had to store more templates than the flash itself can.

You can encrypt this data before transmitting in whatever way you wish but that is a topic on its own.

Other than that your components seem to be compatible.

**An idea for syncing:**

Every unit should check on a fixed interval of 1 second for instance, whether the online database has changed. This may be represented by a simple counter i.e. version that increments with each change and is copied to local storage after downloading the latest changes.

So whenever an Arduino uploads a new fingerprint model or your mobile app removes a fingerprint, the counter on the server is incremented and every other device knows to update its database in case the local version is lower.

**Another tip if changes happen very frequently:**

Every flash memory just has so many write cycles before it dies.
If you happen to update the database a lot, you should try to minimize the stress on each fingerprint sensor's memory by assigning an arbitrary, unique id to each fingerprint and storing a local 'map' where you have stored which id on this specific device.
This way you can update only the fingerprint(s) that have actually changed.

Good luck.

  [1]: https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library


message:
Return a char concatenation

My goal is to create a function that concatenate 2 chars into 1, and return it as MQTT subscribe. I get a difference between the results inside and outside the function ( I'm new to Arduino ), and I can't find why:

Code:

    // Update variable below:
    const char *direction = "up";
    const char* clientID = "Sonoff";

    //Consts
    const char *client_temp = "HomePi/Dvir/Windows/";
    const char* outTopic = "HomePi/Dvir/Messages";
    //const char* outTopic2 = "HomePi/Dvir/Windows/ESP32";
    const char* inTopic2 = "HomePi/Dvir/Windows/All";
    char *inTopic;

    void setup() {
      Serial.begin(9600);
    //  len(create_topic(client_temp, clientID));
      inTopic = create_topic(client_temp, clientID);
      Serial.println(inTopic);
    }

    char *create_topic(char *chr1, char *chr2){ .   // added *
      char topic[strlen(chr1) +strlen(chr2)+1];
      sprintf(topic,"%s%s",chr1,chr2);
      Serial.println(topic);
      return topic;
    }

    void loop() {
      // put your main code here, to run repeatedly:

    }

Result ( both line should have been same):

    HomePi/Dvir/Windows/Sonoff
    ⸮⸮,茗⸮;⸮_⸮%⸮l?⸮az⸮z⸮%⸮⸮⸮\;⸮m⸮

body:
The concatenation is working fine in both instances.

What is wrong, though, is that you can't return a pointer to a locally declared array from a function. That array no longer exists when you leave the function.

The thing to remember with arrays is that you never pass the actual array to or from a function. All you pass is a pointer to the memory address where the array is.  If you allocate an array in a function that memory is allocated on the stack. When you return the array from the function you return an address that is (currently) within the stack.  When you leave the function all memory allocated on the stack by that function is removed, and that includes your array.

There are four ways of solving the problem - all of them have their pitfalls.

1. Use a global "scratch pad" array that is big enough for any concatenating you may want to do. Do your concatenation in there.
2. Declare your array `static`, which means it's allocated only once and can be returned from the function - but like the global one you have to have a fixed size.
3. Pass a pointer to a suitably sized array to your function to have that array used for the concatenation, and
4. Allocate memory on the heap using `malloc()`.

My normal method is number 3. It's the safest and most flexible:

    const char *a = "part a";
    const char *b = " part b";

    char all[14];
    doConcat(a, b, all);

    void doConcat(const char *a, const char *b, char *out) {
        strcpy(out, a);
        strcat(out, b);
    }


message:
Pointer memory allocation in function

I would like to know how Arduino allocate memory for pointers in function arguments.

For instance. I have this code that use 192 bytes (Arduino IDE compiler:
Global variables use 192 bytes (9%) of dynamic memory).

    char alph [] = {'a', 'b', 'c','\0'}; // 4 bytes
    int numb [] = {1, 2, 3, 4}; // 8 bytes
    float flo [] = {1.1, 2.2, 3.3}; // 12 bytes

    void fn(){
      Serial.println(alph);
      Serial.println(numb[1]);
      Serial.println(flo[1]);
    }

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

    void loop(){}

The following code is the same of above, but I'm using pointer to variables in arguments, that use 234 bytes (Arduino IDE compiller: Global variables use 234 bytes (11%) of dynamic memory).

    char alph [] = {'a', 'b', 'c','\0'}; // 4 bytes
    int numb [] = {1, 2, 3, 4}; // 8 bytes
    float flo [] = {1.1, 2.2, 3.3}; // 12 bytes

    void fn(char * _alph, int * _numb, float * _flo){
      Serial.println(_alph);
      Serial.println(_numb[1]);
      Serial.println(_flo[1]);
    }

    void setup()
      Serial.begin(9600);
      fn(alph, numb, flo);
    }

    void loop(){}

There is a difference of 42 bytes to use three pointers. Why? A char pointer is 1 byte, a int pointer is 2 bytes and a float pointer is 4 byte length. Do the difference must be 7 bytes?

body:
When you ask: "why?". The cheapest answer is: "why not?".

The compiler can do clever optimizations as @Majenko wrote. That is what this is about.

Even for such a small sketch, the compiler has many optimization methods to choose from. Changing a single line or adding a variable can make the compiler to choose other optimizations. It is therefor impossible to link the increased number of bytes to those extra pointers.

Sometimes the compiler can decide to keep a variable in a register instead of storing it in a memory location. Sometimes the compiler understands that a variable has a constant value and is used only once, then the compiler might not even use dynamic ram for it.

The used dynamic ram by the sketch is even more trivial, since Arduino sets the compiler to use the minimal size for the code.

Optimizing a sketch is best done with a large sketch. Your small sketch uses the Serial library, and that is the main part of the compiled code. Your own functions and pointers is just some code on the side.

For beginners, the compiler optimizations can be magical Abracadabra. However, using arrays will prevent the compiler to do extreme optimizations. There might even be a logical explanation for the number of increased bytes if the assembly code is studied as @Gerben wrote.


message:
Run piece of code based on a feature

I am an engineering student completely new at using Arduino so my following question might be silly but still. I do not think you'll need to get the entire code so I am only going to expose the idea.
So basically, I would like a customer to choose a feature between three of them (let's name them 1, 2, 3). Depending on the feature he chose, the corresponding `setup()` and the corresponding `loop()` have to run. For example, if he chooses the second feature, in the main `setup()`, the `setup2()` has to run and in the main `loop()`, the `loop2()` has to run only. The other `setup()` functions and `loop()` functions have to do nothing. I first thought I could do this using switch cases but I am looking for another way to implement that as a teacher told me this method would take too much time.

    void setup() {

          setup1(); //only runs if 1st feature chosen
          setup2();
          setup3();
    }

    void loop() {

          loop1(); //only runs if 1st feature chosen
          loop2();
          loop3();
    }

And also, I wrote the three `setup()` and the three `loop()` in different files (of course, `setup1()` is in the same file as a `loop1()`, etc., ...). Is it possible to include them in the main file (for instance, like `<#include nameoffile.h`)?

body:
You probably want to do something like this:

    typedef enum { FEATURE1, FEATURE2, FEATURE3 } Feature;

    //implement these
    Feature getFeatureFromUser(){}
    void setup1(){}
    void setup2(){}
    void setup3(){}
    void loop1(){}
    void loop2(){}
    void loop3(){}

    void setup() {
      Feature f = getFeatureFromUser();

      switch (f) {
        case FEATURE1:
          setup1();
          while (true) {
            loop1();
            if (serialEventRun) serialEventRun();
          }
        case FEATURE2:
          setup2();
          while (true) {
            loop2();
            if (serialEventRun) serialEventRun();
          }
        case FEATURE3:
          setup3();
          while (true) {
            loop3();
            if (serialEventRun) serialEventRun();
          }
      }
    }

    //never reached
    void loop() {}

It's good to know that there's no hard rules about how the Arduino functions should be used. Examples like this demonstrate how Arduino's standard requirements of `void setup()` and `void loop()` don't quite match every use case.

**EDIT**: The serialEventRun lines are normally called behind the scenes after each execution of Arduino's normal `loop()`, so adding them here will result in the standard behavior of serial events


body:
If the feature selection is not at runtime but is at compile time you could do it like this:

    #define FEATURE1 true   // Feature 1 is enabled

    void setup() {
        #if FEATURE1
        setup1(); //only runs if 1st feature chosen
        #endif
        setup2();
        setup3();
    }

    void loop() {
        #if FEATURE1
        loop1(); //only runs if 1st feature chosen
        #endif
        loop2();
        loop3();
    }

    void setup1(void) {}
    void setup2(void) {}
    void setup3(void) {}

    void loop1(void) {}
    void loop2(void) {}
    void loop3(void) {}


message:
Use SD-Card module in combination with MKR GSM 1400

I have bought a SD Module with the following Pin-Names: VCC,GND,MOSO,MOSI,CS,SCK. I've found many tutorials on how to use it with the Arduino Uno. But haven't found any on how to wire it with the MKR GSM 1400. Most of these Pin Names are written on the Board itself, but the CS-port isn't marked. (VCC and GND are obvious). So is there any tutorial on how to use them together or any more specific documentation?

Here is a Picture of the SD-Adapter I am using :
[![Here is a Picture of the SD-Adapter I am using][1]][1]

  [1]: https://i.stack.imgur.com/5w42q.jpg

body:
You can free choose pins used by SPI master to select slaves, but if possible use the default expected by the library.

With MKR and other SAMD Arduino boards use the same default SPI slave select pins as for AVR boards, because same libraries are used.

Ethernet library has default SS pin 10 and SD library pin 4.


message:
How to convert char array to String in arduino?

I want to convert const char array in PROGMEM to String. How do I do this?

    const char charArray[] PROGMEM = "Some text";

body:
you can use a cast to `__FlashStringHelper` to invoke the right constructor of the String class. It is the constructor which copies the char array from PROGMEM. `__FlashStringHelper` is intended as return type for the F() macro.

    const char charArray[] PROGMEM = "Some text";

    void setup() {

      Serial.begin(115200);

      String s((const __FlashStringHelper*) charArray);

      Serial.println(s);
    }

    void loop() {
    }


message:
avrdude ser_open() can't set com-state

When trying to upload the blink sketch to my (unofficial) Arduino Uno, I get the following error:

    avrdude ser_open() can't set com-state for "\\.\COM3"

I have programmed this Arduino before using this same laptop, but not for quite some time.  I have not changed anything in the Arduino IDE in this time.

I have tried the following:

* Reading answers for the following related questions:
  * https://arduino.stackexchange.com/questions/25137/avrdude-ser-open-cant-set-com-state-for-com2
  * https://arduino.stackexchange.com/questions/15867/avrdude-ser-open-cant-open-device-com3
  * https://arduino.stackexchange.com/questions/29143/cant-upload-to-my-arduino-uno
  * https://arduino.stackexchange.com/questions/17493/avrdude-ser-open-cant-open-device-com4-access-denied
* Confirmed that COM3 was the correct port by going to device manager. I have only one port listed here, COM3, and it disappears when I unplug my Uno and reappears when I plug it back in again.  One strange thing to point out is that it is called RAMPS for some reason?
* Tried 3 different USB cables
* Tried 3 different USB ports
* Restarting the computer
* Uninstalled and reinstalled the Arduino IDE
* Uninstalled the device from Device Manager
* Tried a (previously untested) (also unofficial) Arduino Nano.  When I looked up this in Device Manager, it was also reported as RAMPS on COM3 (strange?)

None of the above fixed the issue and all gave the same error as shown above (except when trying different USB ports which showed the error just for different COM ports).

EDIT: Just tried both the Uno and Nano on another computer and both worked fine. This confirms that both the arduinos and cables I'm using are working properly.

body:
Maybe a Windows driver problem.
Do your uno and nano use a ch340? (It is the component translating USB to uart (serial pins of atmega328).
Windows has no software way to differenciate boards using this component. It is a common use on cheap clones to lower price.
Official arduinos use a second atmega (atmega16u2 natively supporting usb) instead of the ch340. Allowing windows to identify the arduino model.

You should try to update your ch340 driver as you have the same problem with the 2 boards. [here][1] is the download page of the manufacturer (ch341ser.exe is the package you want)

You can also try to connect your board to an usb2 port as some problems (and solutions to try) are posted [here (arduino forum)][2]
And even try to use an usb2 hub...

  [1]: http://www.wch.cn/download/CH341SER_EXE.html
  [2]: https://forum.arduino.cc/index.php?topic=397368.30


body:
I had the same problem, open the port under COM and LPT in your device manager.
Then roll back driver so the PC uninstalls all updates to the driver. At this point uploading the code will give the "Windows does not recognize driver" or some error like that. Now just unplug and plug the UNO back in and update driver.
This solved the problem for me.
Hope this helps :)


body:
I had the same problem. I was able to upload a simple Blink example, but not my own program. And I thought there's no problem in my program, since I successfully tested it on other Arduino before. But actually, that was the problem. I had this in my program (for console logs):

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

Then I read that different Arduinos use different baud rates. Originally I tested it on Arduino Mega, but this time I wanted to upload it to "unofficial" Arduino Nano (for which you have to use ``ATmega328P (Old Bootloader)`` option when uploading).

Since I didn't need debug logs in my program anymore, I removed these 'Serial' commands completely. Then it got uploaded without problems.

[A short article on this topic][1]

  [1]: https://www.programmingelectronics.com/serial-begin-9600/


message:
DS1820 bad reading from 4th sensor

I am very new to Arduino. I want to add about 50 sensors to Arduino R3. I get good readings from 3 sensors, but when I connect 4th one, I get 'No devices found'.

Here is a diagram:
[![enter image description here][1]][1]

and here is the code I use:

    #include <OneWire.h>
    #include <DallasTemperature.h>

    // Data wire is plugged into port 2 on the Arduino
    #define ONE_WIRE_BUS 2
    #define TEMPERATURE_PRECISION 8
    #define BAUD_RATE 9600

    // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    OneWire oneWire(ONE_WIRE_BUS);

    // Pass our oneWire reference to Dallas Temperature.
    DallasTemperature sensors(&oneWire);

    // arrays to hold device addresses
    DeviceAddress devices[10];
    int devicesFound = 0;

    void setup(void)
    {
      // start serial port
      Serial.begin(BAUD_RATE);

      sensors.begin();

      devicesFound = sensors.getDeviceCount();

      // locate devices on the bus
      Serial.print("Locating devices...");
      Serial.print("Found ");
      Serial.print(devicesFound, DEC);
      Serial.println(" devices.");

      // report parasite power requirements
      Serial.print("Parasite power is: ");
      if (sensors.isParasitePowerMode()) Serial.println("ON");
      else Serial.println("OFF");

      for (int i = 0; i < devicesFound; i++)
        if (!sensors.getAddress(devices[i], i))
          Serial.println("Unable to find address for Device" + i);

      // show the addresses we found on the bus
      for (int i = 0; i < devicesFound; i++)
      {
        Serial.print("Device " + (String)i + " Address: ");
        printAddress(devices[i]);
        Serial.println();
      }

      for (int i = 0; i < devicesFound; i++)
        sensors.setResolution(devices[i], TEMPERATURE_PRECISION);
    }

    // function to print a device address
    void printAddress(DeviceAddress deviceAddress)
    {
      for (uint8_t i = 0; i < 8; i++)
      {
        // zero pad the address if necessary
        if (deviceAddress[i] < 16) Serial.print("0");
        Serial.print(deviceAddress[i], HEX);
      }
    }

    // function to print the temperature for a device
    void printTemperature(DeviceAddress deviceAddress)
    {
      float tempC = sensors.getTempC(deviceAddress);
      if (tempC < 10)
        Serial.print("0");

      Serial.print(tempC);
    }

    // function to print a device's resolution
    void printResolution(DeviceAddress deviceAddress)
    {
      Serial.print("Resolution: ");
      Serial.print(sensors.getResolution(deviceAddress));
      Serial.println();
    }

    // main function to print information about a device
    void printData(DeviceAddress deviceAddress)
    {
      Serial.print("Device Address: ");
      printAddress(deviceAddress);
      Serial.print(" ");
      printTemperature(deviceAddress);
      Serial.println();
    }

    void loop(void)
    {
      if (devicesFound == 0)
      {
         Serial.println("No devices found.");
         return;
      }

      int start=millis();
      sensors.requestTemperatures();

      // print the device information
      for (int i = 0; i < devicesFound; i++)
      {
        printTemperature(devices[i]);
        if (i != devicesFound - 1)
          Serial.print(" ");
      }

      Serial.println();

      Serial.print(millis() - start);
      Serial.println(" ms passed.");
    }

The resistor I use is 4.7 kΩ. What should I change to get good readings? And is it a problem to get reading from about 50 sensors?

UPDATE
------
So after a few trials, I managed to get readings for 18 sensors. I managed to have a mixed topology. What I did is I added close to sensors I didn't get reading a resistor (mainly 4.7k, but also few 100, 1k). At the moment I get occasionally -127 reading from some sensors, but I think I will fix that with CRC check in the program. Thanks for your help! –

  [1]: https://i.stack.imgur.com/Dw6SZ.png

body:
**Max current**

For 4 sensors I wouldn't expect problem, however, for 50 it will.
The VCC/GND pin has a maximum of 200 mA, see [Arduino Pin Current Limitations][1].

(Update after remark of Gerben, thanks!):
However, these are for the ATMega, not the Arduino R3. See [Arduino Voltage and Current][2]. It's not an official document, but made by Gabriel Staples). It contains a lot of references. But the VCC can handle 0.5 or 1A depending on USB or battery power.

This means:
The DS1820 uses 4 mA (checking a random datasheet), so 50 * 4 = 200 mA, which is way within 500 mA/1000 mA).

**Non one wire sensors (not your case)**

Since you have one wire sensors the following is not applicable (just leave it here for others):

None one-wire sensors use their own GPIO pin mostly. Since the Arduino doesn't have 50 GPIO pins, especially not for analog input, you need to have external IC(s), ADCs (Analog Digital Converters) or analog multiplexers, see also [connecting more than 6 analog input pins to Arduino][3].

**One wire sensors (your case)**

You might find [how many ds18b20 temperature sensors can I connect to one bus][4] interesting.

  [1]: http://playground.arduino.cc/Main/ArduinoPinCurrentLimitations
  [2]: https://www.electricrcaircraftguy.com/2014/02/arduino-power-current-and-voltage.html
  [3]: https://robotics.stackexchange.com/questions/1227/connecting-more-than-six-analog-input-pins-to-arduino
  [4]: https://electronics.stackexchange.com/questions/242816/how-many-ds18b20-temperature-sensors-can-i-connect-to-one-bus-arduino


body:
### First check the sensors

To check that the fourth sensor isn't broken and causing everything to fail, swap them around and then see if it still fails when adding the fourth sensor (although this time it will be a different fourth sensor).

That is to say, if your current fourth sensor becomes the second (and the second becomes the fourth), does it now fail on two sensors..? Or does it still fail on four?

If two (and three) work then the (previously) fourth sensor isn't broken.

### Current supply issues

In that case, it *could* be that your power supply from the Arduino lacks sufficient current and you need to power the sensors with a separate external power supply - separate to the Arduino external PSU (especially when you start to use 50 sensors)1. If you do, don't forget to connect the GND of the Arduino (i.e. the GND of the Arduino PSU) to the external PSU for the sensors. However, for four sensors the current required would only be 4 x 4 mA = 16 mA so it shouldn't be a problem.

If you are using the USB port as your only power supply, then that will most likely cause problems. Make sure that you have an external power supply for the Arduino other than relying only on the USB. Also, again, 16 mA draw for 4 sensors should not be a problem.

### Addtional links

There is a similar link to Michel's link to SE.Electronics, on SE.RPi: [What is the maximum number of DS18B20 probes that can attached to one input port?](https://raspberrypi.stackexchange.com/questions/23701/what-is-the-maximum-number-of-ds18b20-probes-that-can-attached-to-one-input-port)

On the Arduino forum, there is this thread, [Problem with DS18B20 OneWire and long cables][1]:

> I've done more with 1-Wire using dedicated interfaces rather than
> connecting the device to my Arduino, but I suspect the same principles
> will apply....
>
> a) You are better off NOT using parasitic mode. The modest extra
> "trouble" is well worth it.
>
> b) Use cat-5 cable
>
> c) The "magic resistor" (mentioned above) often helps. The right
> value? Use a little trial and error!
>
> d) Be sure to put multiple 1-Wire chips in a daisy chain, not a
> "star"... i.e. ONE run of two wires, with 1-wire chips across it, like
> the rungs of a ladder.... do NOT have several wires leading out from
> where your Arduino is, with 1-Wire chips on each of the several "rays"
> of the "star".
>
> I have tested strings of three or four 1-Wire temperature sensors on
> cat-5 cables of up to... umm, from memory... 40m? They WILL work! But
> as I said... this was with 1-Wire adapters.

But cable length does not seem to be your problem, if your Fritzing diagram is an accurate portrayal...

In this long thread, someone has issues with over seven sensors, which seems similar to your issue, see [Multiple DS18B20 reading isues][2]. In summary, cable length and quality is important, and avoid a **star** topology.

----

1 To clarify, you will need two PSU. One for the Arduino, and one for the 50 sensors.

  [1]: https://forum.arduino.cc/index.php?topic=20574.0
  [2]: https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=64477&sid=89ab9086e703d216699b0b4d96f633c3


message:
Problems improving the inquiry speed of Bluetooth HC-05

I'm buiding a project with the Arduino and Bluetooth HC-05 module that receives the MACs of Bluetooth devices around (does not connect, just inquiry). It works, but I want a better performance in detecting devices, because it doesn't find devices that stay less than 2 seconds in the area. So, I want it to work faster, detecting even if the device stays for 1 second (or maybe less) in the range of the HC-05.

-First, I tried to select the baud-rate (from 9600 to 1382400) of USART, but I tested it, and it did not change anything.

-Then, I tried to config the period and the duration of the inquiry process by "AT+IPSCAN", but, for any value I adjust, also results in anything.

Thought maybe I did not configure parameters, but I tested "AT + IPSCAN?" and "AT + UART?" and the values are those that I set.

This is strange, but I could not find a solution. Does anyone know what it could be?

body:
You can't change how fast Bluetooth devices report their presence.

Bluetooth works the opposite way that you expect. An inquiry doesn't actively request what devices are there. Instead it sits and listens passively for devices to announce that they are there.

If a device enters the target zone and then leaves again before it has broadcast it's "I am here" signal there is nothing you can do.

That is why inquiries take so long. They wait enough time for devices nearby to announce that they are here.

I am not familiar with that specific module, so I don't know if it is always listening in the background and maintaining a list, or just listening during and enquiry, but either way the onus is on the remote device to announce that it is there.


message:
Arduino Uno 2 I2C devices problem

I have two I2C devices connected to an Arduino Uno: an RTC and an OBD interface (see links below). The SCL/SDA of both devices connect parallel to SCL/SDA (respectively) of the Uno. My problem: when I set the time on the RTC (either using the autoset option, or explicitly) it reports back odd readings, like the date set back by 4 days, the hour set back by 2 hours etc. This happens even with the default bare-bones RTC sample sketch.

I tried two RTCs (one DS1307, and the one linked below): both show the same strange behavior. I tried 2 configurations: 1) NO pull-up resistors on either device, 2) two 10K pull-up resistors on BOTH devices. Both situations produce RTC errors. If I detach the OBD sensor from SCL/SDA, the RTC shows the proper time. If I remove the RTC, the OBD by itself (works fine. Before I spend more time experimenting: any advice how to solve this pull-up resistor situation (if this is what it is)?

[Adafruit DS3231 Precision RTC][1]

[OBD Freematics interface][2]

  [1]: https://www.adafruit.com/product/3013
  [2]: https://freematics.com/pages/products/arduino-obd-adapter/

body:
I imagine you are using the [Adafruit Library][1], since thats the URL of the product you posted.

If so, in RTClib.h:

    #define DS1307_ADDRESS  0x68
    #define DS3231_ADDRESS  0x68

And in the OBDs product page:

    OBD I2C Address: 0x68

    MEMS I2C Address: 0x62

Which obviously causes a conflict.

It seems that they have a fixed I2C address (some devices are configurable via software, others with external pins). So the solution would be to use other RTC, other OBD (or change its address) or use a bus splitter, or use a MCU with more than one I2C bus.

  [1]: https://github.com/adafruit/RTClib


body:
If anyone has the same problem: turns out Adafruit has a multiplexer just for this purpose. Also, there's LTC4316 which (supposedly) converts I2C addresses on the fly.

[Adafruit TCA9548A I2C multiplexer][1]

[LTC4316][2]

  [1]: https://www.adafruit.com/product/2717
  [2]: http://www.analog.com/media/en/technical-documentation/data-sheets/4316fa.pdf


message:
Uno pin connection: Atmega16u2 & ATmega328P

On my Uno, I set up the HoodLoader2 (link below) so I can program both the ATMega16u2 and the ATmega328P. I can communicate between the two using the serial port. However, I need the serial port to communicate between the Uno and the PC. Can I communicate between the 328 and 16u2 using a common digital pin? All I need to communicate is a simple yes/no state, preferably in both directions. In other words: can I connect a digital pin (say 12) on the Uno to, say, PB1 pin on the 16u2's ICSP header, set pin 12 value to HIGH on the 328P, then read that state on the 16u2 via PB1? And vice versa, via another pair of pins? There's a Q that's close to what I want (link below) and the user there (@jsotola) seems to have the knowledge, but I can't comment under his comment, as I don't have 50 reputation.

[HoodLoader2][1]

[Accessing digital pins from the ATMega16u2][2]

  [1]: https://github.com/NicoHood/HoodLoader2/wiki
  [2]: https://arduino.stackexchange.com/questions/48276/accessing-digital-pins-from-the-atmega-16u2-on-the-uno

body:
You could use from PB1 to PB3 from 16u2 (SCK, MOSI, MISO) wich are exposed to its ICSP.
Add a wire from one of them to your atmega328 :)


message:
Arduino DDS IOT ESP8266 controlling AD9834

first post, having probs with uploading sketches on win10, blink sketch loads but when I try either of 2 sketches which have been specifically coded for this duino I get the following error: **redefinition of 'const byte dds_data'**
I have it on good faith that it works on other operating systems. I would also appreciate any advice about how to make a similar one using shields joined together, afaics I just need to join 2 boards readily available on ebay with the 8366 controlling the DDS Ad9834, many thanks in advance, for some reason **the com port is grayed out** in tools menu, https://sites.google.com/site/addsontheinternetofthings/home code below...

    Arduino: 1.8.5 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, Flash, nodemcu, 26 MHz, 40MHz, QIO, 512K (no SPIFFS), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

    ...some code removed so it will fit on this post...

    C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFi.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFiAP.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFiGeneric.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFiMulti.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFiScan.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiClient.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiClientSecureAxTLS.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiClientSecureBearSSL.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiServer.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiServerSecureAxTLS.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiServerSecureBearSSL.cpp" -o "nul"
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiUdp.cpp" -o "nul"
    Generating function prototypes...
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Temp\arduino_build_458317\sketch\ESP_WiFi_VFO.ino.cpp" -o "C:\Users\Ewan\AppData\Local\Temp\arduino_build_458317\preproc\ctags_target_for_gcc_minus_e.cpp"
    "C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\Ewan\AppData\Local\Temp\arduino_build_458317\preproc\ctags_target_for_gcc_minus_e.cpp"
    Compiling sketch...
    "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Temp\arduino_build_458317\sketch\ESP_WiFi_VFO.ino.cpp" -o "C:\Users\Ewan\AppData\Local\Temp\arduino_build_458317\sketch\ESP_WiFi_VFO.ino.cpp.o"
    AD9834_Test:20: error: redefinition of 'const byte DDS_data'

     const byte DDS_data = 13;

                ^

    ESP_WiFi_VFO:25: error: 'const byte DDS_data' previously defined here

     const byte DDS_data=13;

                ^

    AD9834_Test:21: error: redefinition of 'const byte DDS_clck'

     const byte DDS_clck = 14;

                ^

    ESP_WiFi_VFO:26: error: 'const byte DDS_clck' previously defined here

     const byte DDS_clck=14;

                ^

    AD9834_Test:22: error: redefinition of 'const byte DDS_fsync'

     const byte DDS_fsync = 16;

                ^

    ESP_WiFi_VFO:27: error: 'const byte DDS_fsync' previously defined here

     const byte DDS_fsync=16;

                ^

    AD9834_Test:26: error: redefinition of 'long unsigned int m'

     unsigned long m;

                   ^

    ESP_WiFi_VFO:30: error: 'long unsigned int m' previously declared here

     unsigned long m;

                   ^

    AD9834_Test:27: error: redefinition of 'unsigned int m1a'

     unsigned int m1a, m2, m3;

                  ^

    ESP_WiFi_VFO:31: error: 'unsigned int m1a' previously declared here

     unsigned int m1a,m2,m3;

                  ^

    AD9834_Test:27: error: redefinition of 'unsigned int m2'

     unsigned int m1a, m2, m3;

                       ^

    ESP_WiFi_VFO:31: error: 'unsigned int m2' previously declared here

     unsigned int m1a,m2,m3;

                      ^

    AD9834_Test:27: error: redefinition of 'unsigned int m3'

     unsigned int m1a, m2, m3;

                           ^

    ESP_WiFi_VFO:31: error: 'unsigned int m3' previously declared here

     unsigned int m1a,m2,m3;

                         ^

    AD9834_Test:29: error: redefinition of 'const long unsigned int M_Clk'

     const unsigned long M_Clk = 60000000L;

                         ^

    ESP_WiFi_VFO:33: error: 'const long unsigned int M_Clk' previously defined here

     const unsigned long M_Clk = 60000000L;

                         ^

    AD9834_Test:30: error: redefinition of 'const long unsigned int TwoE28'

     const unsigned long TwoE28 = 268435456L;

                         ^

    ESP_WiFi_VFO:34: error: 'const long unsigned int TwoE28' previously defined here

     const unsigned long TwoE28 = 268435456L;

                         ^

    C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void setup()':

    AD9834_Test:36: error: redefinition of 'void setup()'

     void setup() {

          ^

    ESP_WiFi_VFO:50: error: 'void setup()' previously defined here

     void setup()

          ^

    C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void loop()':

    AD9834_Test:42: error: redefinition of 'void loop()'

     void loop() {

          ^

    ESP_WiFi_VFO:60: error: 'void loop()' previously defined here

     void loop()

          ^

    C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void sendFrequency(double)':

    AD9834_Test:49: error: redefinition of 'void sendFrequency(double)'

     void sendFrequency(double frequency) {

          ^

    ESP_WiFi_VFO:224: error: 'void sendFrequency(double)' previously defined here

     void sendFrequency(double frequency) {

          ^

    C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void setFreq(double)':

    AD9834_Test:55: error: redefinition of 'void setFreq(double)'

     void setFreq(double(f)) {

          ^

    ESP_WiFi_VFO:231: error: 'void setFreq(double)' previously defined here

     void setFreq(double(f)){

          ^

    C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void setFreqFloat(float)':

    AD9834_Test:66: error: redefinition of 'void setFreqFloat(float)'

     void setFreqFloat(float f) {

          ^

    ESP_WiFi_VFO:242: error: 'void setFreqFloat(float)' previously defined here

     void setFreqFloat(float f){

          ^

    C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void writeFreq()':

    AD9834_Test:77: error: redefinition of 'void writeFreq()'

     void writeFreq() {

          ^

    ESP_WiFi_VFO:253: error: 'void writeFreq()' previously defined here

     void writeFreq(){

          ^

    Using library ESP8266WiFi at version 1.0 in folder: C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi
    exit status 1
    redefinition of 'const byte DDS_data'

body:
You have two sketches in the project folder ESP_WiFi_VFO.  First is ESP_WiFi_VFO.ino and second is AD9834_Test.ino. Booth sketches have defined same functions, constants and variables so the final program can't be build.

Delete AD9834_Test.ino from the sketch folder ESP_WiFi_VFO (Delete C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino)


message:
Is the strange problem I'm having to do with comparing floats?

I have a timer interrupt that controls a stepper motor, on an UNO board. In the interrupt handler it checks the speed of the motor and compares it to the target speed. This allows the motor to accelerate to the target speed in a non-blocking way.

This is the relevant part of the interrupt handler:

<!-- language: lang-cpp -->

    ISR(TIMER1_COMPA_vect){
        if (targetSpeed > 0 || motorSpeed > 0){
            // leading edge of the step cycle
            if (leadingEdge){
                digitalWrite(STEP_PIN, HIGH);
                stepNumber++;
                // check speed and adjust if necesary
                if (motorSpeed < targetSpeed){
                    motorSpeed += speedIncrement;
                }
                else if (motorSpeed > targetSpeed){
                    motorSpeed -= speedIncrement;
                }

                leadingEdge = false;
            }
            // trailing edge
            else{
                digitalWrite(STEP_PIN, LOW);
                leadingEdge = true;
            }
        }
        OCR1A = minInteruptsPerStep + (minInteruptsPerStep * (1 - motorSpeed));
    }

In the `loop()` I have a function that checks the state of `motorSpeed` to control other functions

<!-- language: lang-cpp -->

    if (motorSpeed == targetSpeed) {
        motorState = RUNNING;
    } else if (motorSpeed < targetSpeed) {
        motorState  = ACCELERATING;
    } else if (motorSpeed > targetSpeed) {
        motorState  = DECELERATING;
    }

`motorSpeed` and `targetSpeed` are floats and range from 0-1, in steps of 0.1 `speedIncrement` is 0.001 As far I can see that should ramp the speed up until `motorSpeed == targetSpeed`, in 100 steps. And this mostly what happens. The speed gets to `targetSpeed` and motorState switches from `ACCELERATING` to `RUNNING`, as expected.. mostly. The problem is that it occasionally starts flipping between the three states, for no reason I can see--there is nothing that should modify the value of `motorSpeed` outside the interrupt handler, so once it stops accelerating it should be stable.

Is this because I'm using and comparing floats? Should I scale the speed variables up and use an int or even a byte?

body:
You should never compare two floats with == or != directly. The reason is that floats are not accurate, so maybe 1.0 can be 0.99999999999, and the other value 1.0 might be 1.00000000001 (simplification).

Instead, use a 'range', like:

    if (fabs(motorSpeed - targetSpeed) < 0.001)
    {
       // Equal
    }

This means the difference should be smaller than 0.001. fabs means the absolute value of a float (mathematic symbol |x| for the absolute value).

If you make more compares this way, make 0.001 a #define or const.


body:
The biggest problem here is that floats don't compare well.  The issue is that a float isn't an exact number. It is, to a large extent, an approximation.

Some numbers cannot be represented by floats, so your "100" may be actually "100.00001", or "99.999999".

It is better to use integers whenever possible. Do your calculations using larger numbers, and then scale down the results when you need to use them.

If you're working in steps of 0.1 between 0 and 100, you should really be working instead in steps of 1 between 0 and 1000, and then divide by 10 later on when you need to use the value (if you even really need to do that).

Here's a little example I knocked up on Linux:

    #include <stdio.h>

    void main() {
        float f = 0;
        while (f < 100) {
            f += 0.1;
        }
        printf("%.6f\n",f);
    }

You'd expect it to give "100.000000" as the answer. It doesn't. Instead you end up with 100.099045. That's because the closest it gets to 100 is actually the previous iteration: 99.999046.

If you do want to compare floats the best way is to use a "within X" operation.  Here's a little macro:

    #define WITHIN(A,B,DIFF) (fabs((A) - (B)) <= (DIFF))

Then you can:

    if (WITHIN(motorSpeed, targetSpeed, 0.1)) {
        ...
    }

That should give you TRUE if the motorSpeed and targetSpeed are within 0.1 of each other.


body:
You already know, from previous answers, why the comparison doesn't give
you the result you expect: you assumed that any multiple of 0.1 is also
a multiple of 0.001, which is true for real numbers but nor for floats.

To fix the issue, it has been suggested to you to allow for some
fussiness in the comparison. I would suggest a different approach: keep
your comparisons as they are, and instead change the way the speed is
updated in the ISR:

<!-- language-all: lang-c++ -->

    if (motorSpeed < targetSpeed) {
        motorSpeed = min(motorSpeed + speedIncrement, targetSpeed);
    }
    else if (motorSpeed > targetSpeed) {
        motorSpeed = max(motorSpeed - speedIncrement, targetSpeed);
    }

With this logic, `motorSpeed` will always end up being _exactly_ equal
to `targetSpeed`, irrespective of whether the speed change is a multiple
of the increment or not.

A common misconception about floating point numbers has it that they are
not exact. Truth is, most floating point calculations involve rounding
errors, but the floating point numbers themselves are _exact numbers_,
if not the numbers you expect¹. Then, when you do the assignment

    motorSpeed = targetSpeed;

which the code above ends up doing at some point, you can test

    if (motorSpeed == targetSpeed) ...

and it will be true.

¹ When you write “0.1” in the source code, you get the `float` which is
closest to 0.1, which happens to be 0.100000001490116119384765625
_exactly_.


message:
How close to 5 kHz can I set the PWM frequency on an UNO pin 11?

I'm rebuilding a laser CNC machine and using [LaserWeb4](https://github.com/LaserWeb/LaserWeb4/wiki) as the control interface and [GRBL 1.1](https://github.com/gnea/grbl/wiki/Connecting-Grbl) as the low-level interface to the stepper motors, limit switches and the laser. I have all the motion sorted out and am working on the laser control.

[![enter image description here][1]][1]

*Figure 1. The GRBL 1.1 pinout. Pin 11 is used for spindle (cutter) speed on a milling machine or laser power control on a laser cutter.*

The machine is using a [Synrad 48 Series](https://www.synrad.com/sites/default/files/2017-07/Operators Manual 48 Series.pdf) laser module which requires a 5 kHz PWM frequency (page 45 - 46).

The GRBL 1.1 sketch can be configured for a variety of PWM frequencies. See [cpu_map.h](https://github.com/gnea/grbl/blob/master/grbl/cpu_map.h).

      // Prescaled, 8-bit Fast PWM mode.
      #define SPINDLE_TCCRA_INIT_MASK   ((1<<WGM20) | (1<<WGM21))  // Configures fast PWM mode.
      // #define SPINDLE_TCCRB_INIT_MASK   (1<<CS20)               // Disable prescaler -> 62.5kHz
      // #define SPINDLE_TCCRB_INIT_MASK   (1<<CS21)               // 1/8 prescaler -> 7.8kHz (Used in v0.9)
      // #define SPINDLE_TCCRB_INIT_MASK   ((1<<CS21) | (1<<CS20)) // 1/32 prescaler -> 1.96kHz
      #define SPINDLE_TCCRB_INIT_MASK      (1<<CS22)               // 1/64 prescaler -> 0.98kHz (J-tech laser)

      // NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings.
      #define SPINDLE_PWM_DDR     DDRB
      #define SPINDLE_PWM_PORT  PORTB
      #define SPINDLE_PWM_BIT     3    // Uno Digital Pin 11

It seems that my options are 62.5 kHz, 7.8 kHz, 1.96 kHz or 0.98 kHz.

Why does it matter? Two excerpts from the Synrad manual:

>Tickle frequencies [a 'keep-awake' signal at zero power] lower than 4.5 kHz may compromise laser performance, ..., and stress the RF [radio frequency] electronics thereby reducing long term reliability while tickle frequencies greater than 5 kHz may cause unintended lasing.
>
>Because laser output follows PWM input with a rise and fall time constant of ~100 µs, the laser cannot precisely follow Command signal frequencies over t kHz with duty cycles greater than 50%.

Can anyone see a workaround for this within the constraints of the GRBL configuration?

I can only think of a hardware solution to filter the PWM out and run it through another device to convert the analog signal to a 5 kHz PWM.

Many thanks.

  [1]: https://i.stack.imgur.com/jb1Sn.png

body:
The simple way, which may interfere with the timing of your other digital outputs:  https://playground.arduino.cc/Code/PwmFrequency

Or, if you are willing to put the PWM output on pin 9/10 and manipulate the AVR registers directly:

Digital pins 9 (`OC1A`) and 10 (`OC1B`) are outputs of the AVR 16-bit timer (TIMER1) on 328p.  With those you can get a PWM signal at 5.000 kHz, but if you need reliability then an Arduino with external crystal resonator may be needed.   You will need to set the registers `TCCR1A`, `TCCR1B` and `OCR1A`,`OCR1B`,`ICR1`,`TIFR1` appropriately, details can be found in the AVR datasheet.


body:
No, you cannot have hardware PWM at 5 kHz on pin 11 of an Arduino
Uno. The closest you can get is 3.92 kHz. You get that by setting
the prescaler to 8 and configuring the timer for phase correct PWM,
instead of the fast PWM mode usually used by GRBL. Your options for
getting 5 kHz are to use either software PWM or change the pinout.

You can get a quite accurate 5 kHz PWM signal on pins 3, 9
and 10. You can do software PWM at 5 kHz on any pin, but this
is prone to have significant jitter, which your laser may well not like.


message:
Can I use GSM and Data Logger Shield at the same time on one Arduino?

Me and my classmates are trying to make an arduino base project where we will be using sensors, GSM, and Data logger shield. We want the arduino to store the data collected and at the same time send a message to the user if significant data are collected.My is question is above.

body:
It depends, but high likely yes.

The sensors, GSM and Data Logger may use the I2C, SPI, analog pins or UART (last not likely).

For I2C, the Arduino can handle many of such devices, because it is part of the protocol.

For SPI it is similar, although some cheap SD card reader for Arduino are notorious not being compatible with other SPI devices. And the Arduino has only one SPI port (but can handle many SPI devices, as long as they all are capable to allow other SPI devices).

For analog pins, these are likely only used by sensors, the Arduino has 5. But there are some ways to use more sensors by polling, using multiplexers etc.


message:
Sending arduino signal to another arduino

I'm working on a project which consists of 2 different function. since the arduino only can do 1 function so i decide to use 2 arduino instead. my idea is 1st arduino will give a output and the sketch on the 2nd arduino will run Only after the input given from the 1st arduino. So can i make a digital output which will be send to the input of 2nd arduino?

if it could be, i already make a code for the 2nd arduino which will be run after there was an input from the 1t arduino:

    //define the input/output pins
    #define FLOAT_SWITCH_PIN 2
    #define PUMP_1_PIN 4
    #define LED_PIN 7
    #define output1starduino 3
    //setup runs once
    void setup()
    {

      pinMode(FLOAT_SWITCH_PIN, INPUT_PULLUP);
      pinMode(output1starduino, INPUT_PULLUP);

      //setup output pins for relays/pumping station and LED board
      pinMode(PUMP_1_PIN, OUTPUT);
      pinMode(LED_PIN, OUTPUT);

    }

    //loop() runs indefinitely
    void loop()
    {

      if(digitalRead(output1starduino) == HIGH) // output from 1st arduino
      if(digitalRead(FLOAT_SWITCH_PIN) == LOW)
      {
         digitalWrite(PUMP_1_PIN, HIGH); //turn on the pump
         digitalWrite(LED_PIN, HIGH);    //turn on the LED
      }

      {
         digitalWrite(PUMP_1_PIN, LOW); //turn off the pump
         digitalWrite(LED_PIN, LOW);    //turn off the LED
      }
    }

as i write on the line, the "output1starduino" which an digital output from the first arduino. Is this the right way for me to write if i want the program here to run only right after the output from 1st arduino given?

*** this is the code of first arduino which will be sent to the 2nd arduino

    int motorPin = 3; // motor pengisian (m1)
    int blinkPin = 4; //
    int motor1 = 5;// motor pembuangan
    int motorklorin = 6;// pam topap
    int switch1 = 2;// switch float
    int indicator1 = 7;
    int indicator2 = 8;
    int indicator3 = 9;
    int output1starduino = 2;
    void setup()
    {
      pinMode(motorPin, OUTPUT);
      pinMode(blinkPin, OUTPUT); // penujuk fasa pengisian
      pinMode(motor1, OUTPUT);
      pinMode(motorklorin, OUTPUT); // MOTOR UNTUK topap
      pinMode(switch1, INPUT_PULLUP);// PELAMPONG
      pinMode(indicator1, OUTPUT);// lampu penunjuk fasa pembuangan
      pinMode(indicator2, OUTPUT);// lampu penunjuk topap
      pinMode(indicator3, OUTPUT);// lampu menunggu
      pinMode(output1starduino, OUTPUT); // KELUARAN KE ARDUINO 2
    }

    void loop()

    {
      digitalWrite(motorPin, HIGH); // turn on the motor
      digitalWrite(blinkPin, HIGH); // turn on the LED
      digitalWrite(motor1, HIGH);// on lampu
      digitalWrite(motorklorin,HIGH);
      delay(1000);        //

      digitalWrite(motorPin, HIGH);  //
      digitalWrite(blinkPin, HIGH);  // penunjuk fasa pembuangan hidup
      digitalWrite(motor1, LOW);// motor pembuangan jalan (air start turun/pembuangan
      digitalWrite(motorklorin,HIGH);
      delay(180000);        //tempoh pembuangan

      digitalWrite(motorPin, LOW); // turn on the motor (motorisi balik air jalan/pengisian
      digitalWrite(blinkPin, LOW); //
      digitalWrite(motor1, HIGH);// filling motor on
      digitalWrite(indicator1, HIGH); //indicator
      delay(150000);        // duration filling

      digitalWrite(motorPin, HIGH);  // turn off the motor
      digitalWrite(blinkPin,HIGH);  // turn off the LED
      digitalWrite(motor1, HIGH);//
      digitalWrite(output1starduino, HIGH);
      delay(100000);        // multiply by 60000 to translate minutes to milliseconds
      }

body:
An arduino may not be as fast as a PC or phone, but it is VERY fast indeed (16,000,000 operations /sec). Unless the code for arduino #1 is incredibly complex, the one arduino should be able to do it all on its own.
P.S. Please post the code for Arduino #1


message:
Compile Error for Arduino Sketch

I am attempting to increase the volume of a Max9744 20 watt amplifier from Adafruit using an Arduino sketch. I am just a very beginner and working with my grandson, this may be more than I am capable of doing.

Our project is to have music play when a sensor determines a door is opened.

I wonder if someone can help with this compile error.  I stripped the code of any code not related to issue - basically the sensor code.

Thanks in advance for any help you can provide.

exit status 1
'VS1053_CONTROL_SPI_SETTING' was not declared in this scope

Here is the code

    #include <SPI.h>[code][/code]
    #include <Adafruit_VS1053.h>
    #include <SD.h>
    #include <Wire.h> // Amp Code

    #define BREAKOUT_RESET 9 // VS1053 reset pin (output)
    #define BREAKOUT_CS 10 // VS1053 chip select pin (output)
    #define BREAKOUT_DCS 8 // VS1053 Data/command select pin (output)
    // These are the pins used for the music maker shield
    #define SHIELD_RESET -1 // VS1053 reset pin (unused!)
    #define SHIELD_CS 7 // VS1053 chip select pin (output)
    #define SHIELD_DCS 6 // VS1053 Data/command select pin (output)

    // These are common pins between breakout and shield
    #define CARDCS 4 // Card chip select pin
    // DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
    #define DREQ 3 // VS1053 Data request, ideally an Interrupt pin

    #define MAX9744_I2CADDR 0x4B

    int8_t thevol = 63; // I want Max Volume Always

    Adafruit_VS1053_FilePlayer musicPlayer =
    Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

    void setup() {
    SD.begin(CARDCS);

    Wire.begin();
    if (! setvolume(thevol)) {
    Serial.println("Failed to set volume, MAX9744 not found!");
    while (1);
    }
    }

    boolean setvolume(int8_t v) {
    // cant be higher than 63 or lower than 0
    if (v > 63) v = 63;
    if (v < 0) v = 0;

    Serial.print("Setting volume to ");
    Serial.println(v);
    Wire.beginTransmission(MAX9744_I2CADDR);
    Wire.write(v);
    if (Wire.endTransmission() == 0)
    return true;
    else
    return false;
    }
    void Adafruit_VS1053::setVolume(uint8_t left, uint8_t right) {
    uint16_t v;
    v = left;
    v <<= 8;
    v |= right;

    noInterrupts(); //cli();
    sciWrite(VS1053_REG_VOLUME, v);
    interrupts(); //sei();
    }

    void Adafruit_VS1053::sciWrite(uint8_t addr, uint16_t data) {
    #ifdef SPI_HAS_TRANSACTION
    if (useHardwareSPI) SPI.beginTransaction(VS1053_CONTROL_SPI_SETTING);
    #endif
    digitalWrite(_cs, LOW);
    spiwrite(VS1053_SCI_WRITE);
    spiwrite(addr);
    spiwrite(data >> 8);
    spiwrite(data & 0xFF);
    digitalWrite(_cs, HIGH);
    #ifdef SPI_HAS_TRANSACTION
    if (useHardwareSPI) SPI.endTransaction();
    #endif
    }
    void loop() {

    while (counter < 3) {
    musicPlayer.begin();
    Serial.println(F("Playing track 001"));
    musicPlayer.playFullFile("track001.mp3");
    delay (100);
    }

    delay(1000);

    musicPlayer.stopped();
    }

body:
The functions `Adafruit_VS1053::sciWrite` and `Adafruit_VS1053::setVolume` are functions from the library. They are in the [Adafruit_VS1053.cpp file][1].

You should not copy those functions to your own sketch.

The library has a few examples. Try to stay close to those examples.

  [1]: https://github.com/adafruit/Adafruit_VS1053_Library/blob/master/Adafruit_VS1053.cpp


message:
Why does the potentiometer act as an on/off switch in my program?

I'm using an HC-SRO4 Ultrasonic Sensor and a D10K Potentiometer. So, I was just messing around with the potentiometer in the program and then tried to change the brightness of the LED which turns on if a certain condition is met, but the potentiometer acts like an ON/OFF switch instead. I'd like to know why this happens and how can I change the LED's brightness normally in this situation.

    long duration;
    int distance;
    int trigPin = 9;
    int echoPin = 10;
    int buzzer = 11;
    int LED = 3;
    boolean detected = false;
    #define pot 0
    int val = 0;

    void setup() {
      pinMode(LED, OUTPUT);
      pinMode(trigPin,OUTPUT);
      pinMode(echoPin,INPUT);
      pinMode(buzzer,OUTPUT);
      Serial.begin(9600);
    }

    void loop() {
      digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance= duration*0.034/2;
    val  = analogRead(pot);
    val  = map(val, 0, 1023, 0, 255);
    Serial.println  (distance);

    if(distance < 50 && distance != 0){ // distance != 0  because sometimes the distance's first value is sometimes 0 which ruins the purpose of
     // the program
      analogWrite(LED, val);
      alarm();
      detected = true;
    }
    else if(detected){
      digitalWrite(LED,LOW);
      alarm();
    }
    }

    void alarm(){
      tone(buzzer, 450);
      delay(100);
      tone(buzzer, 1000);
      delay(100);
      }

body:
The answer is very simple. You use pin 12 for LED. Pin 12 can't do [analogWrite()][1]. This pin doesn't support PWM on Arduino UNO (Atmega 328)

Pin 3 is not OK either. Use of [tone()][2] function disables PWM on pin 3. From reference: "Use of the tone() function will interfere with PWM output on pins 3 and 11".

  [1]: https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/
  [2]: https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/