# Question
Title: Unable to Configure MQTT Client ID using Adafruit MQTT Library
I am utilizing the MQTT library that Adafruit has created, located here, 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)

```

# Answer
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);

```
> 1 votes

---
Tags: adafruit, mqtt
---


# Question
Title: How do I connect this SPI serial display to an Arduino?
I've recently purchased a screen on DX without really thinking about it, because I have no idea how to connect it to my Arduino.

It is this screen:

The description says that it uses the SPI serial protocol but I don't know how to connect that ribbon to my Arduino, is soldering cables to it the only way?

# Answer
That kind of connector is most commonly directly soldered on to a PCB. You can buy adaptor boards with the various different pitch pads on them for soldering it to.

Also there is no mention of what chip the screen uses (I am unfamiliar with "XS057" as a chip, so that is probably the model of the screen not the chip). At that resolution it's probably an ILI9163, but without being sure all you can do is stab wildly in the dark and try different drivers.
> 1 votes

# Answer
if you have the pinout you should be able to solder the hookup wires directly to the pins if you know how to use solder paste and a heat gun and skill if you are a beginner you need to put it in a box and order something from other suppliers more friendly to newbes.
> 0 votes

---
Tags: arduino-uno, lcd, display
---


title: Regain WIFI connectivity

text:
# Question
Title: 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);
  }
}

```

# Answer
> 1 votes
> 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.

---
Tags: wifi, networking
---


# Question
Title: Nema 17, Arduino Uno and stepper motor drive ~2H42B
I tried running Nema 17 stepper motor using the drive in the pic below (not the basic L298N drive, which BTW I successfully used to rotate the motor) .

Could any of you review my existing connections and guide me to complete the remaining ones?

Existing Arduino Uno, Nema 17 motor and drive setup:

Existing connections to Drive from left to right:

1. Thick yellow wire (0v) from power adapter along with a thin black wire (Ground) from Arduino
2. Thick red wire (12v +) from power adapter
3. Green wire (A+) from stepper motor
4. Black wire (A-) from stepper motor
5. Red wire (B+) from stepper motor
6. Blue wire (B-) from stepper motor

What I am missing is connections to PUL, DIR, VCC and ENA. I could put the 4 wires from Arduino D8 to D11 respectively but is that enough? Is there an Arduino sketch I could refer to after the connections are ready?

# Answer
> -1 votes
Connect:

* VCC to Arduino 5 V
* `ENA` either directly to VCC or to an Arduino pin (for optional enable driver software control - active high).

Pulse (steps) and direction to Arduino GPIO.

Have a look here Arduino forum Simple Stepper Program \- I think you will find what you are looking for.

# Answer
> -1 votes
Here is the user manual for the BH-MSD-2A Micro stepping driver.

Page 5 shows the two tables giving the connections:

>

You have already connected P2, and that leaves P1 remaining.

The timing diagram below shows the state of the, `PUL`, `DIR` and `ENA` signals required

.

So, the `ENA` input can either be held high, by connecting to VCC or connected to a digital output pin of the Arduino, to provide basic ON/OFF control.

This thread, arduino uno with stepper motor, the OP is using a very similar controller to yours, except that theirs is the 6 A version (BH-MSD-6A). Their code, in the thread has a lot of unnecessary code, and apparently has a number of issues. A stripped down version, of the same code, is as follows:

```
//arduino code
//
#include <TimerOne.h>
#include <EEPROM.h>

int rpm;
int initial_rpm;
int dutycycle_time=0;
int stepper_Enable=5; //STEPPER MOTOR  ENABLE PIN : PUL-
int stepper_Pulse=6;  // STEPPER MOTOR PULSE PIN :  PUL-

int address_eeprom=0;

void displayNumber(int);
void lightNumber(int);

void setup()
{

  Timer1.attachInterrupt( timerIsr ); // attach the service routine here
  pinMode(stepper_Pulse,OUTPUT); // Analog pin A2 is used for ENABLING the steeper motor
  pinMode(stepper_Enable,OUTPUT); // Analog pin A2 is used for DIRECTION the steeper motor
  digitalWrite(stepper_Pulse,HIGH);
  digitalWrite(stepper_Enable,LOW);

  rpm=EEPROM.read(address_eeprom);
}

void loop()
{

  while(digitalRead(stepper_Enable)==HIGH){
     int cycle_freq=(1600/60)*rpm;
     int dutycycle_freq=2*cycle_freq;
     int dutycycle_time=1000000/dutycycle_freq;
      Timer1.initialize(dutycycle_time); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
      if(analogRead(A3)==LOW )  // STOPPING THE STEPPER MOTOR
       {
         digitalWrite(stepper_Enable,LOW);

       }

  }

  while(digitalRead(stepper_Enable)==LOW)
  {
    int initial_rpm=rpm;
     EEPROM.write(address_eeprom,rpm);

      if(analogRead(A0)==LOW && rpm<300 ) ///increasing speed of stepper motor
    {
          rpm=rpm+1;
         // delay(100);
     }
    if(analogRead(A1)==LOW && rpm>0) ///decreasing speed of stepper motor
    {
          rpm=rpm-1;
         // delay(100);
    }
    if(analogRead(A2)==LOW ) //STARTING THE STEPPER MOTOR
    {
     digitalWrite(stepper_Enable,HIGH);
    }
  }
  if(initial_rpm!=rpm){
    address_eeprom=address_eeprom+1;
  }

}

void timerIsr()
{
  // Toggle LED
  digitalWrite( stepper_Pulse, !digitalRead( stepper_Pulse ));
}

```

Note that while this should get you started, as the OP states in the thread there are issues with it, that will need fixing.

---

*(I have to go now to fix some Marlin firmware, but I'll come back to this answer later)*

---
Tags: arduino-uno, stepper
---


title: Doubt using character array

text:
# Question
Title: Doubt using character array
I'm trying to make a led sign with a WS2812b ledstrip, using the FastLed 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?

# Answer
> 4 votes
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.

---
Tags: serial, string, array
---


title: Device Security - EEPROM data

text:
# Question
Title: Device Security - EEPROM data
I'm writing code for Arduino that I plan to distribute. But I worry about piracy (the .HEX can extracted from the board and reuploaded to another).

With that in mind, I am storing data to the EEPROM.

Since I am storing data to the EEPROM, can the data be extracted in some way?

# Answer
Nothing is 100% secure. For example, EEPROM and flash can be read using techniques like Scanning Probe Microscopy & Scanning Electron Microscope, even if the security bit is set. IMO, the goal to safely securing your data is to make it extremely hard. You should take a look at the ATAES132a from MicroChip.

> The first device in the AES family, the ATAES132A, is a high-speed, high-security, 32K Serial EEPROM that enables authentication and confidential nonvolatile data storage

It also boast a tamper resistant hardware

> The ATAES132A device contains physical security features to prevent an attacker from determining the internal secrets. ATAES132A includes tamper detectors for voltage, temperature, frequency, and light, as well as an active metal shield over the circuitry, internal memory encryption, and other various features. The ATAES132A physical design and cryptographic protocol are designed to prevent or significantly complicate most algorithmic, timing, and side-channel attacks.
> 0 votes

---
Tags: arduino-uno, eeprom
---


# Question
Title: 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?

# Answer
> 3 votes
The blinking while uploading makes the bootloader. Arduino Mini uses Optiboot. The source codes are on GitHub. 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.

# Answer
> 2 votes
Following on from Juraj's answer:

> The blinking while uploading makes the bootloader. Arduino Mini uses Optiboot. The source codes are on GitHub. 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` is line number 27:

```
#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

>

---
Tags: arduino-ide, led
---


title: Setting up Huzzah ESP8266

text:
# Question
Title: Setting up Huzzah ESP8266
I am trying to set up a Huzzah ESP8266 and can not get it to work. I have scoured the internet for help and to no avail. I have the board loaded with a baud rate of 115200 and am transmitting at 80 MHz. When I try and upload the sketch it successfully uploads and after a second or two it sends me this error.

> Sketch uses 222,209 bytes (21%) of program storage space. Maximum is 1,044,464 bytes. Global variables use 31,576 bytes (38%) of dynamic memory, leaving 50,344 bytes for local variables. Maximum is 81,920 bytes.
>
> warning: espcomm\_sync failed
>
> error: espcomm\_open failed
>
> error: espcomm\_upload\_mem failed
>
> error: espcomm\_upload\_mem failed

Here is my code:

```
 void setup() {
pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
 void loop() {
digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the    voltage level
                                // but actually the LED is on; this is     because
                                // it is acive low on the ESP-01)
delay(1000);                      // Wait for a second
digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}

```

Does anyone know what I'm doing wrong or can anyone help me out.

# Answer
If you´re working with a development board, they (usually) come with tow buttons: *Reset* and *Flash*. If this is the case **before** start to upload your code you **must** press the *Flash* button, this error is common when the *Flash* button it's not pressed.

If you're working with an ESP8266-01 (this is the "naked" esp8266) you **must** read this tutorials: GreatScott vid on youtube, and for the connections: a good Hackster.io tutorial.

Hope you can make it run!!!
> 1 votes

# Answer
When using a serial cable (4 wires, only works on windows), you need to press the 2 buttons in the sequence described here (https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide): gpio0 down, reset down, reset up, gpio0 up. The red led should be dim now. This means the huzzah is ready to bootload.
> 0 votes

---
Tags: esp8266
---


# Question
Title: 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
2. A wifi shield
3. A fingerprint sensor
4. An LCD screen

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?

# Answer
According to the adafruit driver's code, 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.
> 2 votes

---
Tags: arduino-uno
---


# Question
Title: 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: What are (or how do I use) the power saving options of the Arduino to extend battery life?

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)

# Answer
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 to see which fits your application best and how to safely wake it up again
> 4 votes

---
Tags: arduino-uno, power, sleep, memory, sram
---


title: Return a char concatenation

text:
# Question
Title: 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⸮

```

# Answer
> 4 votes
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);
}

```

---
Tags: string
---


# Question
Title: 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?

# Answer
> 0 votes
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?

---
Tags: power, switch
---


# Question
Title: 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";

```

# Answer
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() {
}

```
> 5 votes

---
Tags: arduino-ide, c++
---


title: Pointer memory allocation in function

text:
# Question
Title: 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?

# Answer
> 1 votes
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.

---
Tags: arduino-uno, memory-usage, pointer
---


title: DS1820 bad reading from 4th sensor

text:
# Question
Title: 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:

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! –

# Answer
> 2 votes
### 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?

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

> 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. 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.

# Answer
> 4 votes
**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.

(Update after remark of Gerben, thanks!): However, these are for the ATMega, not the Arduino R3. See Arduino Voltage and Current. 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.

**One wire sensors (your case)**

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

---
Tags: ds18b20, 1-wire
---


# Question
Title: 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 :

# Answer
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.
> 1 votes

---
Tags: sd-card, wires, mkr1000
---


# Question
Title: 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

Accessing digital pins from the ATMega16u2

# Answer
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 :)
> 3 votes

---
Tags: arduino-uno, pins, atmega16u2
---


# Question
Title: 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?

# Answer
> 1 votes
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.

---
Tags: arduino-uno, bluetooth
---


# Question
Title: 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'

```

# Answer
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)
> 1 votes

---
Tags: iot
---


# Question
Title: 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:

```
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

```
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?

# Answer
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.
> 2 votes

# Answer
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:

```
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*.
> 3 votes

# Answer
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.
> 1 votes

---
Tags: interrupt, data-type, float
---


# Question
Title: 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.

# Answer
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.
> 1 votes

---
Tags: arduino-uno, arduino-mega, programming, gsm, sd-card
---


# Question
Title: How to share/Reassign analog pin for two Adafruit libraries for two adafruit hardware
I'm attempting to use the Adafruit BMP180 and Adafruit 16x2 RGB LCD Display together on the same Arduino Uno R1. Both the pieces of hardware and their libraries use Analog Pin 4 and 5. Is there any way to reassign the pins for one of the libraries so I can use both of the parts together?

Here are the libraries I am using:

Adafruit BMP180/BMP085: https://github.com/adafruit/Adafruit\_BMP085\_Unified and https://github.com/adafruit/Adafruit-BMP085-Library

Adafruit 16x2 RGB LCD Display: https://github.com/adafruit/Adafruit-RGB-LCD-Shield-Library

# Answer
> 2 votes
If they are using I2C (which i think they are), then it doesn't matter, because I2C is just a transfer protocol. In theory, you could have hundreds of devices using those pins, and have everything working fine. Just try using both, and tell me if anything doesn't work.

---
Tags: arduino-uno, adafruit
---


# Question
Title: Microphone Data on Arduino to Wav File on RaspPi
Working on an Arduino + Raspberry Pi project and hoping that this question fits into this category. I'm recording audio using a MEMS microphone on the Arduino and transmitting it over to the Pi to store in a playable file (WAV).

What I currently have setup is TCP transmission from the Arduino to the RaspPi. This part is fine and dandy for the purpose of seeing the data transmission that I am looking for.

Where my issue lies, is the audio data being recorded on the Arduino. At the moment, I see data from my `analogRead()` function displaying like the following:

```
2035
2046
2030
2031
2044
2038
2034
2031
2034
2019
2028
2030
2024
2032
2028

```

My question is, what does this mean? How would I translate this, preferably on the Pi, as usable data that I can store in a WAV file?

Any libraries or hints/clues that can steer me in the right direction would be great.

# Answer
> 1 votes
Why use the arduino, when you can use the Pi directly? I would get a high quality ADC, connect the mic to it, and then make the Pi write the value from the ADC directly to file. The arduino simply isn't fast enough for good quality audio recording - the ADC is 10-bit, 9.6 khz. At best you could get a stereo 8-bit 8khz wav file. With a good ADC on the Pi, you would be able to go up to stereo, 16-bit(maybe even 24-bit), 44.1 khz. Also, the Arduino would be massively slowed down by sending the data, so the actual sample rate would be much lower.

# Answer
> -1 votes
It's difficult to answer this without seeing any code, but I will take a wild guess and assume you are not using any sort of FFT processing on the input. You could try looking into this library. Alternately, people seem to have good luck with this one too.

---
Tags: audio
---


# Question
Title: 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);
  }

```

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

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

---
Tags: arduino-uno, arduino-ide
---


title: Compile Error for Arduino Sketch

text:
# Question
Title: 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();
}

```

# Answer
The functions `Adafruit_VS1053::sciWrite` and `Adafruit_VS1053::setVolume` are functions from the library. They are in the Adafruit\_VS1053.cpp file.

You should not copy those functions to your own sketch.

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

---
Tags: code-review
---


title: Arduino Nano PWM pin not functioning

text:
# Question
Title: Arduino Nano PWM pin not functioning
I am building a project using an Arduino Nano. In it, I am using pin 3 as PWM output. However, If I supply values lower than 255 to it, the pin does not output any voltage at all.

According to this diagram, pin 3 is PWM:

I have tested it on two boards, it doesn't function on either one. It's not my sketch, either (I tested it with a simple `analogWrite();`).

This is the code:

```
void setup() {
  // put your setup code here, to run once:
  #define E1 3  // Enable Pin for motor 1
  #define E2 10  // Enable Pin for motor 2
  #define I1 4  // Control pin 1 for motor 1
  #define I2 2  // Control pin 2 for motor 1
  #define I3 A1  // Control pin 1 for motor 2
  #define I4 A0  // Control pin 2 for motor 2
}

void loop() {
  // put your main code here, to run repeatedly:
  // I use differential steering, speed is important
  analogWrite(E1, 100); // Run in full speed
  analogWrite(E2, 100); // Run in full speed

  // always go forward
  digitalWrite(I1, LOW);
  digitalWrite(I2, HIGH);
  digitalWrite(I3, LOW);
  digitalWrite(I4, HIGH);
}

```

What could be the reason of this?

# Answer
Try to replace `#define E1 3` with `#define E1 PD3` and see if that helps.

The `PBx`, `PCx` and `PDx` designations are unambiguous, so using those are pretty much a safe bet.
> 1 votes

# Answer
The third pin (pin 3) is not a PWM pin, it is the `RESET` pin.

The PWM pins are 6, 8, 9, 12, 13 and 14 (for Arduino Nano).

See this image:
> 0 votes

# Answer
Replace digitalWrite with analogWrite(pin, value)
> -1 votes

# Answer
Use `pinMode(NNN, OUTPUT)` at `setup()`?
> -1 votes

---
Tags: pwm
---


title: Arduino Uno 2 I2C devices problem

text:
# Question
Title: 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

OBD Freematics interface

# Answer
> 5 votes
I imagine you are using the Adafruit Library, 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.

# Answer
> 0 votes
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

LTC4316

---
Tags: i2c
---


title: Arduino Serial Writing Array Problem

text:
# Question
Title: Arduino Serial Writing Array Problem
I am trying to communicate Pc - Arduino Uno.

My Arduino code is here: (It is working as below)

```
int ndx = 0;
char pack[12];
void setup() {
Serial.begin(9600);
while(!Serial){;}
}

  void loop() {

   while(Serial.available() ){
    char rb = Serial.read();
    pack[ndx] = rb;
    ndx++;
    Serial.write(rb);
    if(ndx == 12){
        ndx=0;
      }
    }
    }

```

If I try in

```
Serial.write(rb);

```

Like that:

```
Serial.write(pack[ndx]);

```

Program is acting weird, I mean sending weird bytes. I do not know what is the reason. Can you help me, please? What is going on in code? My python code: https://github.com/mucahitkayadan/Python

# Answer
> 0 votes
you replace `Serial.write(rb);` to `Serial.write(pack[ndx]);` and get?:

```
char rb = Serial.read();
pack[ndx] = rb;
ndx++;
Serial.write(pack[ndx]);

```

then you read an uninitialized array item on the next index

# Answer
> 0 votes
The sequence:

```
pack[ndx] = rb;
ndx++;
Serial.write(rb);

```

modifies ndx before printing. So in your first case - printing 'rb' - you'll print the value you just stored in the array; in the second case printing 'pack\[ndx\]' - you'll print whatever happens to be in the *following* member of the array. Swapping the second and third statements in my excerpt will fix it.

---
Tags: serial, communication, array
---