text:
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)?

What physical method are you using to determine which feature has been chosen?

@Majenko I'll use a web-based configurator for the customer to chose. Its name is MQTT

So the device will subscribe to an MQTT topic and receive a retained message to get the configuration? I would say you want to implement a Finite State Machine, since the whole "configuration" system is itself another configuration in its own right.

I don’t understand what your teacher is talking about. Seems to me that a switch-case would work just fine.

@Majenko yes that is the idea! I have never heard of a Finite State Machine but I am going to make some research about it.

@Gerben I am going to try this way too then. Just have to figure out how I am going to retrieve the feature chosen by the customer

A Switch-Case usually forms the heart of a Finite State Machine. It's the simplest way of implementing one. https://majenko.co.uk/blog/finite-state-machine

@majenko thanks, I'll give a look to this link! i really thought I could avoid Switch cases thought but I guess I'll have to deal with it

do you really have to call setup after every feature change? or could you just initialize all features at once and just switch what you are using?

@mystery I could indeed Switch the variables i am using!

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

yes that is the idea! thank you very much for helping, this is really helpful! but what do you mean by the void loop() is never reached, why is that? arduino seems much clearer this way

After one of the options in the switch statement matches, and the corresponding setup function is run, the loop# function will be called forever inside a while loop. Therefore it will stay in that loop forever and never reach Arduino's loop() function. The blocks in the switch statement are very similar to how Arduino's setup() and loop() work behind the scenes.

ok that's clear now! thks I'll try this way then

The downside of that method is that it breaks serial event handling. If you don't use serial events, then that's not an issue.

@Majenko i thought about it too as I may have other operations to do. Indeed, after the first Setup(), three others Options setup11(), setup12() and Setup13() with their own Loops should run, depending again on the customer's choice (choice could be 11, 12,13) don't know if that is still clear

@Majenko I also just found an interesting article about Software product line Engineering. If you've heard about it, do you think I could take ideas from this concept?

@Majenko I just updated to add serial event handling

I wish the real world was this simple. The proposed method above requires the total sum of memory resources. If that is available no problem but in most cases the total sum of, for instance, memory for all the global variables is not available. Instead each feature would like to use the memory available, and not need to share with features that are not enabled.

@MikaelPatel The OP wanted to select a feature at runtime. Otherwise this could easily be done with preprocessor defines. The OP didn't mention being memory constrained. Of course there are a multitude of options if one is memory constrained, like dynamically allocating memory (once) when the feature is chosen, storing data in EEPROM, or reusing variables. That's outside the scope of this question.

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) {}


text:
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 table with SPI pins of the MKR  https://www.arduino.cc/en/Guide/MKRMEMShield

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.

source: Stack Exchange

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

sort: votes


text:
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";

If you mean a C++ style string, I think you just need to do this - https://stackoverflow.com/questions/8960087/how-to-convert-a-char-array-to-a-string

No, I want to convert this in Arduino-IDE. That is not work correctly!

I just saw the answer and I had no idea that was even possible. I think that is your answer.

Unfortunately that is not work. Thank you, however.

what does this mean? that is not work  ....   that statement provides no useful information ....  describing the actual error would help

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

That is right, but how do this in loop or another functions?

PROGMEM is always global. and setup() is a function like every other so same way

Absolutely, but when I write this code in loop, the compiler will generate this error:
conflicting declaration 'String s'

Thanks so much. The compiler error was due to another part of my sketch.

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


text:
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:

avrdude: ser_open(): can't set com-state for "\\.\COM2"
avrdude: ser_open(): can't open device "\\.\COM3"?
Can't upload to my Arduino UNO
avrdude: ser_open(): can't 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.

Ch340 drivers solved the problem.

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 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)
And even try to use an usb2 hub...

It was the driver.  For reference, I uninstalled the driver using Device Manager, then plugged the Uno in again and it installed the correct CH430 driver for me automatically, which is exactly what it must have done on the other computer since there has never been an Arduino plugged in to it before.

Worked for me as well, I just uninstalled the driver and scanned for changes

Exactly! A windows update can wipe out the existing CH341 driver, so re-installing it will fix it.  Just 1. uninstall from Device Manager, checking the box to include the driver, then 2. It will be automatically re-installed in a few seconds (or the next time you plug in the Arduino clone).

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 :)

For the records, the default/vanilla drivers should be by FTDI. They can be installed automatically by Windows, but it's not bundled with them out of the box (so you must be online, and have updates enabled).

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

I have the same problem.  I found it related to the card and not the PC.  The offending card uses processor ATMEGA328P_U_TH (Image 1).  The successful card uses a different processor ATMEGA328P_U (Image 2).
I have NOT found a way to use the ATMEGA328P_U_TH card.  It will not correctly connect to a PC and allow code to download from IDE to card.
Image 1

Image 2

the way more important difference is the USB chip. one has a FTDI chip or CH340, the other has Atmega16u2

Juraj, Thank you.  The issue that I am experiencing is that the card with FTDI does not link to any PC.  I made sure the CH340G driver code was loaded.  Still unsuccessful.  I'd like to find out why and make corrections.   But, I do not have the time to go through the troubleshooting steps on my own.


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

Thanks for the advice. I changed the diagram. Hope it makes more sense now. I will check with external power supply (now I am on usb power).

I've connected external power supply. Output 9V 2000mA. But I get the same result. I swapped sensors, so I exclude faulty one. I have connected power supply and USB at the same time because I need to see readings.

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.

I have connected USB, and PSU to Arduino. I still can get only reading from 3 sensors. And I am stuck at 4 sensors. Long way to 50...

Hmmm, if all of the sensors are working correctly, and as Michel implies, only 16 mA are being drawn with 4 sensors, then there must be something else that is causing the failure. Not sure. Sorry. But the link to SE.Electronics in Michel's answer looks interesting.

I've connected power to 3.3V on Arduino board and I got reading from 4th sensor. But now more. Tomorrow I am going to connect another psu for sensors only. As I read 5V is good for that, am I wrong? I should connect also GND from that PSU to GND on Arduino, right?

Yes, the grounds must be connected. What cable are you using from breadboard to Arduino and how long is it? Avoid a star topology. Are the sensors all on the same breadboard (this seems to be good idea to test with)  Here is another link (someone has issues with over 7 sensors), https://www.raspberrypi.org/forums/viewtopic.php?t=64477. Good luck. I would like to know what the solution is to your problem

Thanks for link. Interesting reading. I use generic jumper wires bought on ebay, on the same breadboard. DS1820 sensors are on about 1m long cable. So distance from Arduino to sensor is max 1.4m. After test I need to connect that snesors with 3core cable 0.5mm2.

I connected external PSU to sensors but with no change. Still max 3 sensors were visible. I also have this DS18B20 Adapter Module for Arduino (https://www.amazon.co.uk/Waterproof-DS18B20-Digital-Temperature-Adapter/dp/B06XJH5HLB/ref=sr_1_1?ie=UTF8&qid=1534371709&sr=8-1&keywords=ds18b20+adapter) and when i use this I can see new sensor. I have 3 sensors connected without that adapter and 2 sensors with those adapters. Do I need that adapter for every sensor? Is there any chance I can do this myself? They are quite expensive

That is interesting to know. So now you have 5 devices visible to the Arduino? As to whether you can make the adapter yourself, possibly probably, you'd have to look for a schematic. But whether it is worth doing so, you'll only know once you find the schematic. I may have a fish about for you tomorrow. Keep on plugging away, and keep us posted :-)

I found that link https://info.kmtronic.com/lan-ds18b20-temperature-monitor-resistors-scheme.html , from your experience, do you think that can solve my issues? There is also some link with more details but as I said, I am very newbie and cannot understand that technical language.

That appears to be compensation for very long wires, but you aren't using very long wires (currently) are you? So, that may not be the current problem.  Also, note Gerben's comment below - the additional power supply for the sensors may not be relevant/necessary. I see that you have accepted my answer, does that mean that you have solved the problem?

It's definitely not software issue. It's some wiring problem I have. I don't know where. I got from this question a lot of material I can learn from, and I am quite sure if I study it I can find what I am missing.  I ordered more ds1820 terminal adapters, hoping that can solve the issue. But connecting more sensors with that adapter allowed me to see them, so I think the problem is with the wiring. I don't know where, but I will find out :)

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!

@gerpaick that is great that you got it working and thanks for letting us know. You really should post your comment above as a separate answer as then it will be searchable (the comments aren't searchable). Also, the comments tend to get cleared up eventually, so it would be safer to write it all in an answer :-).

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.

Thanks for the answer. As far as I read about oneWire, I can connect many sensors to one digital pin. For this reason I use DS1820.

@gerpaick yes I just see it (and learnt something), and found a link you might interesting, see end of answer.

That 200mA limit is for the ATMega328. This doesn’t apply to the UNOs power pins, as the current going though the Vcc and GND pins of the UNO never goes through the ATMega.

@Gerben thanks, I didn't know about this, I added a reference to a source that looks ok.


text:
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?

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.

The config "AT + IPSCAN", according to the datasheet of HC-05, sets the time and duration that the device do an inquiry (if is listening) or scan (if is sending "I am here"). So, I understood that if I change these parametres, I'm doing exactly what you said thats it's not adjustable. I can maybe be wrong, but it's make sense in my mind and it's consistent with my previous research of this topic. The problem is that, in practice, it doesn'st really change anything, but would not make sense it has this configuration


text:
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

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.

Thanks, well spotted, I'll research this. Why don't they make I2C devices with a small, on-board, solderable jumper to quickly set the address to something else than the default? Rhetorical question...

Well, they do, it is just not all of them that have this feature :)

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


text:
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

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 :)

Thanks. What does "PB" stand for? Is this a "normal", digital pin, with HIGH and LOW states?

It means port B (PB1 physical pin 15 to PB3 pin 17). Don’t Know how hoddler name the pins :) here you’ll fins the uno schematic https://www.arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf

This is the original ATmega pin naming and stands for Port B, pin 1. all the pins are separated into banks (ports) of 8 pins each. For pin functions, refer to the relevant datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf

It seems that SCK MOSI and MISO correspond to D1, D2 and D3 (https://github.com/NicoHood/HoodLoader2/wiki/Arduino-Uno-Mega-16u2-Pinout) on the 16u2. And yes they are digital « normal ;) » pins


text:
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'

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)


text:
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?

is motorSpeed  declared volatile?

Yep, all the variables in the interrupt handler are volatiles

There is a library for that: https://www.airspayce.com/mikem/arduino/AccelStepper/

I tried that, but had some problems with it and the LCD library I'm using, the two wouldn't co-exist for some reason.

They do not use the same timer, it should work. Perhaps they use too much memory. Which LCD library is it and is that working now?

it's liquidCrystal, I did some initial testing using another library for menus and the accelStepper. But then I ended up developing my own menu class, and learning about both interrupts and C++ classes, so I'm happy.

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.

Thanks. I haven't done much low level programming before, so I wasn't aware of the float issue. I might try changing to a more appropriate data type.

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.

Nice idea, but it still elaves the problem of the comparison in the main loop() which checks the motor state. I've been reading about floats and I undertand the problem better, but what still puzzles me is that it doesn't seem to be deterministic. Since the value of motorSpeed and the value of targetSpeed is constant once the motor reaches a stable state—and in my tests it does report that motorSpeed == targetSpeed, why then after reporting this as true for hundreds of steps does it suddenly switch to false, even though there's nothing in the code that changes the value of either variable?.

Note that motorSpeed is not a measurement, it's the speed the arduino is telling the motor to run at, so it's not a mechanical issue.

I used this technique with ints, which solved the problem of speedIncrement not necessarily being a multiple of targetSpeed, and also the main loop() problem

@stib: Computations with floats are deterministic. If you witness non deterministic behavior, you will have to search somewhere else in your code.

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.


text:
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 as the control interface and GRBL 1.1 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.

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

I'm trying to do the same thing and the answer to your question could save me a lot of time. Did you have to filter the PWM out and run it through another uno to convert the analog signal to a 5 kHz PWM?

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.

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.

The ceramic resonator of the Uno is reliable, if neither accurate nor stable.


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

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.


text:
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
  }

One arduino can do many functions. My asks data over modbus, calculates and sets pwm, makes some http requests, serves web pages from SD card and ajax requests, handles 4 relays, reads a current sensor and a temperature sensors, lights leds, checks a button, calculates consumption, writes events to eeprom, csv log and consumption stats to SC card... https://github.com/jandrassy/Regulator/tree/master/Regulator

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

i just edited the post.. feel free to give a check!

The Arduino should easily be able to do that on its own.

Combine them like this - I moved the duplicate pins to other pins
//define the input/output pins
#define FLOAT_SWITCH_PIN 2
#define PUMP_1_PIN 4
#define LED_PIN 7
#define output1starduino 3

byte motorPin = 11; // motor pengisian (m1)
byte blinkPin = 12; //
byte motor1 = 5;// motor pembuangan
byte motorklorin = 6;// pam topap
byte switch1 = 2;// switch float
byte indicator1 = 13;
byte indicator2 = 8;
byte indicator3 = 9;
byte output1starduino = 10;

//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);

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

}

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

if(digitalRead(output1starduino) == HIGH) // output from 1st Arduino
{
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
}

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

Duplicate pins might need some more cleanup.

Why the downvote?


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

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.


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

Write a sketch with pot and led only.

Well, I did and it works fine. I can change the brightness of the LED. But what I don't understand is why it doesn't do so in the code above. @Juraj

because the analogWrite is conditional to distance sensor reading

Thing is can't I change the brightness while that condition is true? Well, when I make the condition true, (putting some object in front of the sensor) I turn the potentiometer and it still acts like an ON/OFF switch.

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

I'm sorry. I had changed my LED pin to 12 (I'll edit it to 3 now) because I was messing around with it. It was originally a PWM pin when this problem happened

@ArmanSamma: Please make sure that whatever code you post is always relevant to the question.

I don't understand. How and why does the tone() function disable PWM on pin 3? @Juraj

"tone()" in answer is a link. Read the reference of the tone function.


text:
How to print/display next menu item with menubackend.h?
I'm trying to make a navigational menu with sub menus to display on an OLED.  Have managed this OK, however I would like to display the next item on the same level, to encourage scrolling, but I am unable to figure this out.
I want to have it so that the current menu item is displayed, along with the next item one would reach if you scrolled downwards.  I know you can display the previous and current items easily with
  Serial.print(fromFlash(changed.from.getName()));

and
  Serial.println(fromFlash(changed.to.getName()));

respectively - but I would like to display the current and the next (below but on same level) item.  How can I do this?  I played around for most of today on this but am pretty stumped.
I've simplified the example given which is below.  Below that, I've included menubackend.h
Running on an ATMEGA328P chip.
#include "MenuBackend.h"

/*
    This is the structure of the modelled menu

    Settings
        Pin
        Debug
    Options
        Delay (D)
            100 ms
            200 ms
            300 ms
            400 ms
 */

#define TEST_FROMFLASH
#undef TEST_GETITEMNAMEFROMFLASH

const char itemNameSettings[] PROGMEM = "Settings";
const char itemNamePin[] PROGMEM      = "Pin";
const char itemNameDebug[] PROGMEM    = "Debug";
const char itemNameOptions[] PROGMEM  = "Options";
const char itemNameDelay[] PROGMEM    = "Delay";
const char itemName100ms[] PROGMEM    = "100 ms";
const char itemName200ms[] PROGMEM    = "200 ms";
const char itemName300ms[] PROGMEM    = "300 ms";
const char itemName400ms[] PROGMEM    = "400 ms";
const char itemNameshutdown[] PROGMEM = "shutdown";

static void menuChangeEvent(MenuChangeEvent changed);
static void menuUseEvent(MenuUseEvent used);
//this controls the menu backend and the event generation
MenuBackend menu = MenuBackend(menuUseEvent,menuChangeEvent);
//beneath is list of menu items needed to build the menu
MenuItem settings = MenuItem(itemNameSettings);
MenuItem pin = MenuItem(itemNamePin);
MenuItem debug = MenuItem(itemNameDebug);
MenuItem options = MenuItem(itemNameOptions);
MenuItem setDelay = MenuItem(itemNameDelay,'D');
MenuItem d100 = MenuItem(itemName100ms);
MenuItem d200 = MenuItem(itemName200ms);
MenuItem d300 = MenuItem(itemName300ms);
MenuItem d400 = MenuItem(itemName400ms);
MenuItem shutdown1 = MenuItem(itemNameshutdown);

//this function builds the menu and connects the correct items together
void menuSetup()
{
    Serial.println(F("Setting up menu..."));
    //add the file menu to the menu root
    menu.getRoot().add(settings);
    //setup the settings menu item
    settings.addRight(pin);
    //we want looping both up and down
       pin.addBefore(debug);
       pin.addAfter(debug);
       debug.addAfter(pin);
    //we want a left movement to pint to settings from anywhere
       debug.addLeft(shutdown1);
       pin.addLeft(settings);
    settings.addAfter(options);
    shutdown1.addAfter(settings);
    options.addAfter(shutdown1);
      options.addRight(setDelay);
      setDelay.addLeft(options);
      setDelay.addRight(d100);
      d100.addBefore(d100); //loop to d400
      d100.addAfter(d200);
      d200.addAfter(d300);
      d300.addAfter(d400);
      d400.addAfter(d100); //loop back to d100
      //we want left to always be bak to delay
      d100.addLeft(setDelay);
      d200.addLeft(setDelay);
      d300.addLeft(setDelay);
      d400.addLeft(setDelay);

}

#ifdef TEST_FROMFLASH

inline const __FlashStringHelper * fromFlash(const char * pStr)
{
    return reinterpret_cast<const __FlashStringHelper *>(pStr);
}

#endif

#ifdef TEST_GETITEMNAMEFROMFLASH

inline char * getItemNameFromFlash(const MenuItem & item, char * copyToBuffer, size_t bufferSize)
{
    strncpy_P(copyToBuffer, item.getName(), bufferSize);
    copyToBuffer[bufferSize - 1] = '\0'; // Make sure the buffer is null-terminated.

    return copyToBuffer;
}

#endif

/*
    This is an important function
    Here all use events are handled

    This is where you define a behaviour for a menu item
 */
void menuUseEvent(MenuUseEvent used)
{
    Serial.print(F("Menu use "));

#ifdef TEST_FROMFLASH
    Serial.println(fromFlash(used.item.getName()));
#endif

#ifdef TEST_GETITEMNAMEFROMFLASH
    char itemNameBuffer[31]; // 30 chars + '\0';
    Serial.println(getItemNameFromFlash(used.item, itemNameBuffer, sizeof(itemNameBuffer)));
#endif

    if (used.item == setDelay) //comparison against a known item
    {
        Serial.println(F("menuUseEvent found Delay (D)"));
    }
}

/*
    This is an important function
    Here we get a notification whenever the user changes the menu
    That is, when the menu is navigated
 */
void menuChangeEvent(MenuChangeEvent changed)
{
    Serial.print("Menu change ");

#ifdef TEST_FROMFLASH
    Serial.println(fromFlash(changed.to.getName()));

#endif

#ifdef TEST_GETITEMNAMEFROMFLASH
    char itemNameBuffer[31]; // 30 chars + '\0';
    Serial.print(getItemNameFromFlash(changed.from, itemNameBuffer, sizeof(itemNameBuffer)));
    Serial.print(" char is ");
    Serial.println(getItemNameFromFlash(changed.to, itemNameBuffer, sizeof(itemNameBuffer)));
#endif
}

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

    Serial.println(F("Revision 1.0."));

    menuSetup();
    Serial.println(F("Starting navigation:\r\n   Down: s   Left: a   Right: d   Use: e"));
}

void showAllNames()
{
#ifdef TEST_FROMFLASH
    Serial.println(fromFlash(settings.getName()));
    Serial.println(fromFlash(pin.getName()));
    Serial.println(fromFlash(debug.getName()));
    Serial.println(fromFlash(options.getName()));
    Serial.println(fromFlash(setDelay.getName()));
    Serial.println(fromFlash(d100.getName()));
    Serial.println(fromFlash(d200.getName()));
    Serial.println(fromFlash(d300.getName()));
    Serial.println(fromFlash(d400.getName()));
#endif

#ifdef TEST_GETITEMNAMEFROMFLASH
    char itemNameBuffer[31]; // 30 chars + '\0';

    Serial.println(getItemNameFromFlash(settings, itemNameBuffer, sizeof(itemNameBuffer)));
    Serial.println(getItemNameFromFlash(pin, itemNameBuffer, sizeof(itemNameBuffer)));
    Serial.println(getItemNameFromFlash(debug, itemNameBuffer, sizeof(itemNameBuffer)));
    Serial.println(getItemNameFromFlash(options, itemNameBuffer, sizeof(itemNameBuffer)));
    Serial.println(getItemNameFromFlash(setDelay, itemNameBuffer, sizeof(itemNameBuffer)));
    Serial.println(getItemNameFromFlash(d100, itemNameBuffer, sizeof(itemNameBuffer)));
    Serial.println(getItemNameFromFlash(d200, itemNameBuffer, sizeof(itemNameBuffer)));
    Serial.println(getItemNameFromFlash(d300, itemNameBuffer, sizeof(itemNameBuffer)));
    Serial.println(getItemNameFromFlash(d400, itemNameBuffer, sizeof(itemNameBuffer)));
#endif
}

void loop()
{
    if (Serial.available()) {
        byte read = Serial.read();
        switch (read) {
        case 's':
            menu.moveDown();
            break;
        case 'd':
            menu.moveRight();
            break;
        case 'a':
            menu.moveLeft();
            break;
        case 'e':
            menu.use();
            break;
        case 'z':
            showAllNames();
            break;
        }
    }
}

MenuBackend.h
/*
||
|| @file    MenuBackend.h
|| @version 1.4
|| @author  Alexander Brevig
|| @contact alexanderbrevig@gmail.com
|| @contribution Adrian Brzezinski adrb@wp.pl, http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?action=viewprofile;username=vzhang
||
|| @description
|| | Provide an easy way of making menus
|| #
||
|| @license
|| | This library is free software; you can redistribute it and/or
|| | modify it under the terms of the GNU Lesser General Public
|| | License as published by the Free Software Foundation; version
|| | 2.1 of the License.
|| |
|| | This library is distributed in the hope that it will be useful,
|| | but WITHOUT ANY WARRANTY; without even the implied warranty of
|| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
|| | Lesser General Public License for more details.
|| |
|| | You should have received a copy of the GNU Lesser General Public
|| | License along with this library; if not, write to the Free Software
|| | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
|| #
||
*/

#ifndef MenuBackend_h
#define MenuBackend_h

#include <avr/pgmspace.h>

/*
    A menu item will be a container for an item that is a part of a menu
    Each such item has a logical position in the hierarchy as well as a text and maybe a mnemonic shortkey
*/
class MenuItem {
public:
    MenuItem(const char * itemName, char shortKey='\0' ) : name(itemName), shortkey(shortKey) {
        before = right = after = left = 0;
    }

    //void use(){} //update some internal data / statistics
    inline const char * getName() const { return name; }
    inline const char getShortkey() const { return shortkey; }
    inline const bool hasShortkey() const { return (shortkey!='\0'); }
    inline void setBack(MenuItem *b) { back = b; }
    inline MenuItem* getBack() const { return back; }
    inline MenuItem* getBefore() const { return before; }
    inline MenuItem* getRight() const { return right; }
    inline MenuItem* getAfter() const { return after; }
    inline MenuItem* getLeft() const { return left; }

    MenuItem *moveBack() { return back; }

    MenuItem *moveUp() {
        if (before) { before->back = this; }
        return before;
    }

    MenuItem *moveDown() {
        if (after) { after->back = this; }
        return after;
    }

    MenuItem *moveLeft() {
        if (left) { left->back = this; }
        return left;
    }

    MenuItem *moveRight() {
        if (right) { right->back = this; }
        return right;
    }

    //default vertical menu
    MenuItem &add(MenuItem &mi) { return addAfter(mi); }

    MenuItem &addBefore(MenuItem &mi) {
        mi.after = this;
        before = &mi;
        if ( !mi.back ) mi.back = back;
        return mi;
    }
    MenuItem &addRight(MenuItem &mi) {
        mi.left = this;
        right = &mi;
        if ( !mi.back ) mi.back = back;
        return mi;
    }
    MenuItem &addAfter(MenuItem &mi) {
        mi.before = this;
        after = &mi;
        if ( !mi.back ) mi.back = back;
        return mi;
    }
    MenuItem &addLeft(MenuItem &mi) {
        mi.right = this;
        left = &mi;
        if ( !mi.back ) mi.back = back;
        return mi;
    }
protected:

    const char * name;
    const char shortkey;

    MenuItem *before;
    MenuItem *right;
    MenuItem *after;
    MenuItem *left;
    MenuItem *back;
};

//no dependant inclusion of string or cstring
bool menuTestStrings1(const char *a, const char *b) { // a is in flash, b is in SRAM.
    for (uint8_t da = pgm_read_byte_near(a); da; da = pgm_read_byte_near(++a), b++)
    {
        if (da != *b)
            return false;
    }
    return (*b == '\0'); // We reached the end of a.  Strings are equal only if we reached the end of b too.
}
bool menuTestStrings2(const char *a, const char *b) { // a and b are both in flash.
    uint8_t da = pgm_read_byte_near(a); // Dereferenced a.
    uint8_t db = pgm_read_byte_near(b); // Dereferenced b.

    for ( ; da; da = pgm_read_byte_near(++a), db = pgm_read_byte_near(++b))
    {
        if (da != db)
            return false;
    }

    return (db == '\0'); // We reached the end of a.  Strings are equal only if we reached the end of b too.
}
bool operator==(MenuItem &lhs, char* test) {
    return menuTestStrings1(lhs.getName(),test);
}
bool operator==(const MenuItem &lhs, char* test) {
    return menuTestStrings1(lhs.getName(),test);
}
bool operator==(MenuItem &lhs, MenuItem &rhs) {
    return menuTestStrings2(lhs.getName(),rhs.getName());
}
bool operator==(const MenuItem &lhs, MenuItem &rhs) {
    return menuTestStrings2(lhs.getName(),rhs.getName());
}

struct MenuChangeEvent {
    const MenuItem &from;
    const MenuItem &to;
};

struct MenuUseEvent {
    const MenuItem &item;
};

typedef void (*cb_change)(MenuChangeEvent);
typedef void (*cb_use)(MenuUseEvent);

const char itemNameMenuRoot[] PROGMEM = "MenuRoot";

class MenuBackend {
public:

    MenuBackend(cb_use menuUse, cb_change menuChange = 0) : root(itemNameMenuRoot) {
        current = &root;
        cb_menuChange = menuChange;
        cb_menuUse = menuUse;
    }

    MenuItem &getRoot() {
        return root;
    }
    MenuItem &getCurrent() {
        return *current;
    }

    void moveBack() {
        setCurrent(current->getBack());
    }

    void moveUp() {
        setCurrent(current->moveUp());
    }

    void moveDown() {
        setCurrent(current->moveDown());
    }

    void moveLeft() {
        setCurrent(current->moveLeft());
    }

    void moveRight() {
        setCurrent(current->moveRight());
    }

    void use(char shortkey)
    {
        recursiveSearch(shortkey,&root);
        use();
    }

    void use() {
        //current->use();
        if (cb_menuUse) {
            MenuUseEvent mue = { *current };
            cb_menuUse(mue);
        }
    }

private:
    void setCurrent( MenuItem *next ) {
        if (next) {
            if (cb_menuChange) {
                MenuChangeEvent mce = { *current, *next };
                (*cb_menuChange)(mce);
            }
            current = next;
        }
    }
    void foundShortkeyItem(MenuItem *mi) {
        mi->setBack(current);
        current = mi;
    }
    char canSearch(const char shortkey, MenuItem *m) {
        if (m==0) { return 0; }
        else  {
            if (m->getShortkey()==shortkey) {
                foundShortkeyItem(m);
                return 1;
            }
            return -1;
        }
    }
    void rSAfter(const char shortkey, MenuItem *m) {
        if (canSearch(shortkey,m)!=1) {
            rSAfter(shortkey, m->getAfter());
            rSRight(shortkey, m->getRight());
            rSLeft(shortkey, m->getLeft());
        }
    }
    void rSRight(const char shortkey, MenuItem *m) {
        if (canSearch(shortkey,m)!=1) {
            rSAfter(shortkey, m->getAfter());
            rSRight(shortkey, m->getRight());
            rSBefore(shortkey, m->getBefore());
        }
    }
    void rSLeft(const char shortkey, MenuItem *m) {
        if (canSearch(shortkey,m)!=1) {
            rSAfter(shortkey, m->getAfter());
            rSLeft(shortkey, m->getLeft());
            rSBefore(shortkey, m->getBefore());
        }
    }
    void rSBefore(const char shortkey, MenuItem *m) {
        if (canSearch(shortkey,m)!=1) {
            rSRight(shortkey, m->getRight());
            rSLeft(shortkey, m->getLeft());
            rSBefore(shortkey, m->getBefore());
        }
    }
    void recursiveSearch(const char shortkey, MenuItem *m) {
        if (canSearch(shortkey,m)!=1) {
            rSAfter(shortkey, m->getAfter());
            rSRight(shortkey, m->getRight());
            rSLeft(shortkey, m->getLeft());
            rSBefore(shortkey, m->getBefore());
        }
    }

    MenuItem root;
    MenuItem *current;

    cb_change cb_menuChange;
    cb_use cb_menuUse;
};

#endif

You have a global variable menu, which is of type MenuBackend, which contains the structure of your menu system. One of the member functions of MenuBackend is MenuItem getCurrent(), which returns a reference to the currently active menu.
If you look at the class definition of MenuItem, you can see that among the public member functions, you have:
inline MenuItem* getBack() const { return back; }
inline MenuItem* getBefore() const { return before; }
inline MenuItem* getRight() const { return right; }
inline MenuItem* getAfter() const { return after; }
inline MenuItem* getLeft() const { return left; }

Since menu is a global, anywhere in your program, you ought to be able to use:
menu.getCurrent().getAfter();

to access the MenuItem after the current one. Likewise with just menu.getCurrent().

EDIT:
I add the following lines to your showAllNames() function, just to check:
Serial.println(fromFlash(menu.getCurrent().getName()));
Serial.println(fromFlash(menu.getCurrent().getAfter()->getName()));

And it seemed to work fine.

Excellent! I tried what you suggested but realised in my application it was displaying the one after the one I had just changed from.  So I used changed.to.getAfter()->getName())  and it works brilliantly!  Thank you so much for your help, absolutely made my day!


text:
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

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.