text:
Double Speed Operation for USART on Arduino Mega 2560
I happened to be looking through the HardwareSerial.cpp file that contains the functions used for Serial communication for Arduino.  While looking through the HardwareSerial::begin(baud, config) function, I noticed that the ucsra register has its U2X0 bit set.  When I looked through the datasheet, it says that the U2X0 bit is set to start Double Speed Operation.  From what I'm reading, this means that the baud rate is doubled.
I've been using this Arduino on this computer for a while now with no complaints for the baud rate being at an incorrect speed. What is Double Speed Operation?  Why does it seem to be set in the code by default? I attached the code and section in the manual below.
void HardwareSerial::begin(unsigned long baud, byte config)
{
  // Try u2x mode first
  uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2;
  *_ucsra = 1 << U2X0;

  // hardcoded exception for 57600 for compatibility with the bootloader
  // shipped with the Duemilanove and previous boards and the firmware
  // on the 8U2 on the Uno and Mega 2560. Also, The baud_setting cannot
  // be > 4095, so switch back to non-u2x mode if the baud rate is too
  // low.
  if (((F_CPU == 16000000UL) && (baud == 57600)) || (baud_setting >4095))
  {
    *_ucsra = 0;
    baud_setting = (F_CPU / 8 / baud - 1) / 2;
  }

  // assign the baud_setting, a.k.a. ubrr (USART Baud Rate Register)
  *_ubrrh = baud_setting >> 8;
  *_ubrrl = baud_setting;

  _written = false;

  //set the data bits, parity, and stop bits
  #if defined(__AVR_ATmega8__)
    config |= 0x80; // select UCSRC register (shared with UBRRH)
  #endif
  *_ucsrc = config;

  sbi(*_ucsrb, RXEN0);
  sbi(*_ucsrb, TXEN0);
  sbi(*_ucsrb, RXCIE0);
  cbi(*_ucsrb, UDRIE0);
}

When in double-speed mode, as noted in the manual, fewer samples are used. In Asynchronous serial communication, there is no clock signal, so the clock that keeps the two devices in sync is extrapolated from the data signal. Each end of the communication has it's own clock source (crystal oscillator, ceramic resonator, R-C oscillator, etc.), and you'll rarely find two that are calibrated identically.
The receiver samples the signal at a higher rate than the actual baud rate so that it can better determine where, relative to it's own clock, the data-signal edges go up or down and continually adjusts its offset to compensate for clock drift.
By operating in double-speed mode, the receiver has fewer samples to work with, and so if your transmitter has a clock source that is different enough than the receiver, or is not stable, or you have long or noisy wires or fluctuating temperatures (etc.) then you may experience less stable communication.
If your particular use-case works fine, then stick with it. But if you start to notice errors in communication, the first troubleshooting step would be to disable this mode, since the clock recover is less robust in this mode.

As explained in jose can u c’s answer, in double speed mode the UART has
fewer samples for doing clock and data recovery. But this doesn't help
answering the second question:

Why does it seem to be set in the code by default?

Double speed mode has also an advantage: it enables higher resolution in
setting the baud rate. In normal mode, the bit duration is constrained
to be a multiple of 16 CPU clock cycles, whereas in double speed
mode it is only constrained to a multiple of 8 cycles.
As an example, let's say you want 57600 bps on a 16 MHz
Arduino. Then,
F_CPU ÷ desired_baud_rate = 277.78 = 8 × 34.72 = 16 × 17.36
In single speed mode, this would be rounded to 16 × 17, and the rounding
error would make the baud rate 2.1% too fast. In double speed mode, it
is rounded to 8 × 35, and the baud rate is only 0.8% too slow. Thus you
get better baud rate accuracy in double speed mode. Note that for some
baud rates, like 9600 bps, single speed and double speed yield the
exact same rate.
This is presumably the reason the Arduino core uses double speed mode,
except for a documented compatibility exception and for extremely low
baud rates (double speed cannot work below 488 bps).
It should be noted that this is not the only possible strategy. The
avr-libc, for example, provides some helper macros for baud rate
calculations. These macros give preference to single speed
mode and revert to double speed only if the rounding error exceeds a
specified tolerance, which defaults to 2%.

Thank you very much!  That makes a lot more sense now.  I had no idea how running Double Speed Operation all the time worked for the Arduino.


text:
Using the Arduino compiler, is it possible to use Atmega2560 interrupt pins that are unused by Mega?
Looking into the schematics for the Arduino Mega I noticed that pins PE6 and PE7 are interrupt-enabled (INT6 and INT7 respectively); however, they remain unconnected to any Arduino I/O pin.
I'm designing a custom board based on the Atmega2560 and want to use the Arduino IDE/Compiler to upload my code to it, so I'm pretty much replicating a big part of the Arduino Mega schematic into my board.
However, I would really like to enable these two extra interrupt pins (having 8 interrupt pins in total) in my board, but I'm now sure how to proceed from the software side. How could I enable this new pins in order to use them from the Arduino compiler?

Thanks!

In the original Arduino Mega board variant the unconnected pins aren't defined in it. Just use MegaCore which defines all pins.

Awesome. I didn't know this existed. I'll check it out, so far looks promising. Thank you.

If you are not afraid of getting your hands dirty by touching hardware
registers, you can access those pins bare-metal style, using port
manipulation. You will have to read the datasheet,
specifically the section “External Interrupts” if that's what you are
after.
This works with the stock Arduino core (or even without core), which may
be interesting from a maintenance point of view, but it's not as easy to
use as the Arduino interrupt API.

source: Stack Exchange

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

sort: votes


text:
Why wifiManager.setTimeout(60) is not working?
in this code I am using wifiManager.setTimeout(60); so that when it fails to connect to the wifi it should restart. However, wifiManager.setTimeout(60) is not working at all. It get stuck and display these lines :
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
It never displays this :
"failed to connect and hit timeout"
which means wifiManager.setTimeout(60) is not working . Below is the code:
  #include <ESP8266WiFi.h>

 //needed for library
 #include <DNSServer.h>
 #include <ESP8266WebServer.h>
 #include <WiFiManager.h>

  void setup() {
       // put your setup code here, to run once:
       Serial.begin(115200);

      //WiFiManager
       //Local intialization. Once its business is done, there is no need to
       //keep it around
        WiFiManager wifiManager;
      //reset settings - for testing
      //wifiManager.resetSettings();

     //sets timeout until configuration portal gets turned off
     //useful to make it all retry or go to sleep
      //in seconds

      wifiManager.setTimeout(60);

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
 //here  "AutoConnectAP"
 //and goes into a blocking loop awaiting configuration

  if(!wifiManager.autoConnect("AutoConnectAP")) {
     Serial.println("failed to connect and hit timeout");
     delay(3000);
     //reset and try again, or maybe put it to deep sleep
     //ESP.reset();
     ESP.restart();
     //ESP.deepSleep(20e6, WAKE_RFCAL);
    delay(5000);
   }

   //if you get here you have connected to the WiFi
   Serial.println("connected...yeey :)");

    ESP.deepSleep(20e6, WAKE_RFCAL);
    delay(3000);

 }

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

  }

I am using ESP8266 thing dev board. Can anyone please tell me what is wrong and how to resolve the issue ? Thank You!!

Yes I have corrected it. Time is in seconds. 60 mean 1 minute.

You'll probably need to pursue this with the author of the library.

it must be using the last wifi settings - because Using last saved values means that it has successfully connected to an AP - though, it's surprising that "connected...yeey :)" isn't output

add delay(500) after Serial.begin to see all the output from the beginning

Try using setConfigPortalTimeout(60) instead of setTimeout(60)
Because it has been updated in version 0.10 of WiFiManager library.
see : https://github.com/tzapu/WiFiManager#010

setTimeout just calls setConfigPortalTimeout - so there's no difference

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


text:
Has pt.h library been removed from arduino?
I'm trying to get a program to use protothreading and I've got an error at the include statement for the pt.h library stating that there is no such file or directory. This is how it's written in the program:
#include <pt.h>

Did you install it?

pt.h has never, and will never, be part of the Arduino core distribution.  It is a completely separate third party library that you have to install yourself.
I think the library you want is this one.

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


text:
WS2812 HELP. Need name of Unkown component
https://i.sstatic.net/pbYn6.png
I need to know what the little "thing" that i marked in blue is and how it works.
Thanks.
picture taken here: https://www.sparkfun.com/products/13282

It's most likely a decoupling capacitor meant to smooth out the voltage supply to the internal control chip.
This is standard practice to add to any chip. Power cables create a small bit of parasitic inductance in relation to the area between the lines. This inductance can induce voltage spikes when current draw changes significantly. A capacitor shrinks the effective area between the power lines.
This is also why the general advice for decoupling capacitors is to put them as close to the chip as physically possible.

It's a capacitor. Specifically a decoupling capacitor of somewhere around 100nF to 1uF.
It works by storing an electrical charge in two plates with a dielectric between them. That specific type is a Multi-Layer Ceramic Capacitor and looks to be 0603 in size.

It's a capacitor connected between 5V and GND and it smooths out voltage spikes for a cleaner power supply to the chip. A cleaner power supply means the circuitry in the chip can more easily pick out the data signal (i.e., the reference voltage is more constant, so the actual signal appears more stage.)

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


text:
Batteries and amps in parralel
So, i am about to buy a brushless motor a ESC and a 18650 batteries for my arduino.
The batteries "specs" is 3.7v and 20a, if i would to put 2 and more in parallel would i get 7.4v 20a or 7.4v 40a?
Thanks.

This has nothing to do with Arduino.

where would i then post it?

The electronics stackexchange. Also what is that battery specification? 3.7V is the loaded battery voltage, but 20A? Maximum continuously deliverable current?

In parallel you'd get 3.7V 40A
What I think you mean is in series. That way you get 7.4V 20A.

Series connection of battery adds voltage not current but parallel connection keeps the voltage same. Current may be increased with some condition.  One things should be remembered 20 a current is huge it is not required by arduino. May be for some welding device it needs that current which can be controlled by high current mosfet


text:
How can I differentiate between multiple circuits?
I'm building a puzzle for an escape room. I want to give the user 6 wires and 6 terminals, then confirm that they've connected the correct wires to the correct terminals (one-to-one).
My first (successful) attempt to implement this puzzle was to connect the wires to 6 PWM analog outputs set to different levels, and connect the terminals to 6 analog input pins. By time-averaging the readings on the input pins, I was able to determine which wire(s) are connected to which terminals, if any.
I currently have no resistors in the circuits.
As the puzzle is currently designed, it's possible for the user to do weird things like:

Connect multiple wires to the same terminal.
Connect multiple wires together, without connecting them to any terminal.
Touch multiple exposed wires and/or terminals.

My questions boil down to two:

Is my current approach dangerous, either for the Arduino or my users, and are there recommended precautions I should take?
Is there a better (safer or simpler or more robust) way to implement the puzzle?

I'm a software engineer, but a complete noob when it comes to real electronics and Arduino, so please feel free to assume I know nothing.

First, let's consider the logic of your program. You have two groups of
pins: 6 pins connected to the wires and 6 pins connected to
the terminals. The first thing I would do is forget that these are two
different groups. Consider you just have 12 pins that the user has
to connect in a specific fashion. This way most “weird things” the user
could do, like connecting wires together, are not a special case
anymore. They are just another invalid combination. Now what you have to
do is, for every pair of pins among those 12, determine whether or
not they are connected together. If any pair is connected that shouldn't
be, you have an invalid combination. If any pair is not connected while
it should be, it's again an invalid combination. If every pair is the
expected state (either connected or not connected), then the user did
solve the puzzle.
Now, for the hardware side. A simple way to know whether two pins are
connected together is to set one of them to INPUT_PULLUP and the other
one to OUTPUT LOW. This second pin should be the only one
accessible to the user that outputs a LOW. All other exposed pins
should be set as either INPUT or INPUT_PULLUP. Now, if the first pin
reads LOW, you know have a connection. If it reads HIGH the two pins
are not connected together.
Here is an example program demonstrating that principle. It loops over
the 66 possible pairs to check whether they are connected or not.
You just have to replace the inner if with your code that validates
the combination.
const int PIN_COUNT = 12;
const uint8_t pins[PIN_COUNT] = {...};

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

    // Set all pins to INPUT_PULLUP.
    for (int i = 0; i < PIN_COUNT; i++)
        pinMode(pins[i], INPUT_PULLUP);
}

void loop() {
    // Loop over all pin pairs (pins[i], pins[j]).
    // Set pins[i] to OUTPUT LOW, then read pins[j].
    for (int i = 0; i < PIN_COUNT - 1; i++) {
        pinMode(pins[i], OUTPUT);
        digitalWrite(pins[i], LOW);
        for (int j = i+1; j < PIN_COUNT; j++) {
            if (digitalRead(pins[j]) == LOW) {
                Serial.print("pins ");
                Serial.print(pins[i]);
                Serial.print(" and ");
                Serial.print(pins[j]);
                Serial.println(" are connected together.");
            }
        }
        pinMode(pins[i], INPUT_PULLUP);
    }
}

As for the safety, you should be fine as long as the users do not have
access to any low-impedance ground or voltage source. In particular, the
GND and 5V pins should not be user-accessible. For extra protection, you
could put a 1 kΩ resistor in series with each pin, but then all the
pins that are not actively being tested should be set to INPUT rather
than INPUT_PULLUP, otherwise multiple pullups in parallel may start to
compete with the series resistor.

This is exactly the method I use for testing development boards I make. A shield is attached which links 50% of the pins to the other 50% through 100r resistors. Scanning the pins with one set low checks for both proper continuity as well as shorts to other pins.

Beautiful. This is the paradigm I was missing. It totally hadn't occurred to me that I could actually measure under different configurations in rapid succession. My options for building things just exploded. I'll try it out.

This worked wonderfully. I much prefer it over my analog approach, as I don't need to worry about defining expected voltage ranges for each input. And of course, I didn't need to check all 1211/2 combinations, since I really just need to know which wires are connected to each terminal (66 checks) - if two terminals or two wires were connected, it would necessarily result in the wrong combination of wires connected to a given terminal. It is however important to check for more than the expected 6 connections, to handle the case where the user somehow bridges all the terminals. Thanks!

I would also connect the terminals to the 6 analog input pins and have 6 unique voltages, one per wire. The Arduino will only provide the output when the 6 wires are placed on the correct terminals. In other words, that is when the Arduino sees the correct analog voltage on the respective pins.
I personally would add a RC Low pass filter to the output of the PWMs. More information here. Your PWM output would go into the Vin and the then the Vout would go to your wire (ie the analog input). One filter per channel.

The RC filter will protect the Arduino from shorts to +ve, Gnd and the other pins as well as providing a bit of protection from static. It will also simplify your code.
At the moment you are having to implement fancy code to average out the voltage on those analog pins. The RC filter would essentially make that code not needed.
To calculate the value of the resistor and capacitor you need:
There is a very good article over at All About Circuits that goes into this subject in detail.
To calculate the value we need to know the frequency:

The frequency of the PWM signal on most pins is approximately 490 Hz. On the Uno and similar boards, pins 5 and 6 have a frequency of approximately 980 Hz. - Arduino Analog Write

I used http://sim.okawa-denshi.jp/en/PWMtool.php to calculate the values of R & C needed with a very low ripple ( < 60mV ) using common values. I based my calculations around the 490Hz as the lower frequencies perform worst with low pass filters.
I suggest you use values of R = 10k and C = 4.7uF. You can play with these values until you get the output you desire.
One last thing I would consider is to put some protection on the terminals that connect to the analog pins. This could be a small resistance in series, or a 5.1V zener in parallel (the pin may already have this?) or some capacitance in parallel.

EDIT:
I have just had a brainwave - You don't need to use the PWM's to output the different analog values - you could use a voltage divider circuit instead. No RC filter needed. For example:

simulate this circuit – Schematic created using CircuitLab

Edit #2:

Jonathan Wrote:
  The only minor downside I'm noticing is that if the user has two wires connected to the same terminal, it affects all the voltages read across the other terminals, making it hard to give the user incremental feedback on how many wires are correctly connected.

This can easily be solved by providing 6 individual voltage divider networks, as shown below. Notice how each voltage divider has a different ratio.

simulate this circuit

@sa-leinad Cool idea on the voltage divider circuit.

Cool. So the expectation is that with your second idea, I should be able to see actual different (stable) voltages on the different wires, which eliminates the need for the time averaging, right? I'll try it out.

I tried it out, and this (second idea with the voltage divider circuit) seems to work fine. The only minor downside I'm noticing is that if the user has two wires connected to the same terminal, it affects all the voltages read across the other terminals, making it hard to give the user incremental feedback on how many wires are correctly connected. Thanks again!

Ahhh, I was not aware of the need to provide incremental feedback. In that case you will need 6 different voltage divider networks. I will edit my answer to include this.


text:
Should I use an accelerometer or gyroscope in my project?
A friend and I are working on a sign language translation glove.
Our glove currently successfully uses 5 flex sensors to determine the bend of each finger and can accurately detect letters in the sign language alphabet.
We are now trying to add the functionality to detect one-handed words. Many of these words involve making a letter, but adding some motion. For example, the colour "blue" involves making a B, then shaking/waving your hand in the B position.
We are wondering which type of sensor would be able to handle this. From our research so far, we assume this will either be an accelerometer or a gyroscope, but are not sure which one would be best in the scope of our project.
Any help would be much appreciated!

try each one. that way you can learn how each behaves. that knowledge can be very useful in your future projects.  something like this has both https://www.amazon.com/Makerfocus-MPU-9250-Gyroscope-Accelerometer-Magnetic/dp/B01MU0HV8T/ref=sr_1_1_sspa?ie=UTF8&qid=1512674896&sr=8-1-spons&keywords=gyroscope+module&psc=1

You should use both.

Second both. I'm not even sure if you can get (MEMS) gyroscopes without also an accellerometer within it. For example an MPU-6050

Use both. Accelerometer measure movement in direction of axes when gyroscope measure rotational movement. Being very delicate you can spin accelerometer and sensor won't see any changes, and you can move gyro in one axis without sensor detection. Having both mounted on one board (or in one casing) there is no possibility that motion will be missed by both. Look at the pictures what the sensors do:

There is a plenty of integrated accelerometer-gyro sensors, for example MPU-6050 Accelerometer + Gyro with supporting libraries. Please check here

An accelerometer is a better choice here. For your application, you aren't worried about initial motion but just acceleration. Plus, an accelerometer is cheaper.


text:
Aruino RTC using rtclib not understanding functions
I am missing something fundamental using RTClib.
When I use the rtc.adjust function to change the time in the RTC, I cannot get the updated time from the RTC, just increments a fixed time. I have searched for examples for what I need, and the same few samples of code keep getting quoted.
I want my code to set the RTC at compile to the system time, which it does,
then in the Loop I want to increment the hour.  In reality I will use a button for this, but for now I am just trying to understand how DateTime now = rtc.now and rtc.adjust work.  How to write to the RTC, how to read it back. I am missing something regarding these variables.
Two version of my code.  One with output showing the clock working, and one where the output is static, just increments the hour.
This one works:
#include <RTClib.h>
#include <Wire.h>
int ArduinoHour;
int ArduinoMin;
int ArduinoSec;
RTC_DS1307 rtc;

void setup()
{
  Serial.begin(250000);
  Wire.begin();  //sets up the I2C
  rtc.begin();   //initializes the I2C to the RTC

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
  }
    if (rtc.isrunning()) {
    Serial.println("RTC IS running!");
    rtc.adjust(DateTime(__DATE__, __TIME__));
  }
}
void loop()
{
  DateTime now = rtc.now(); // pings RTC and loads time info into the now variable.

  ArduinoHour = now.hour();
  ArduinoMin = now.minute();
  ArduinoSec = now.second();

  Serial.print("AT TOP");
  Serial.println();
  Serial.print("RTC Time");
  Serial.println();
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();
  Serial.println();
  delay(1000);

  Serial.print("Arduino Time");
  Serial.println();
  Serial.print(ArduinoHour, DEC);
  Serial.print(':');
  Serial.print(ArduinoMin, DEC);
  Serial.print(':');
  Serial.print(ArduinoSec, DEC);
  Serial.println();
  Serial.println();
  delay(1000);

  //RTC increments when these are commented out. Does not when active
  //ArduinoHour = ArduinoHour +1;
  //rtc.adjust(DateTime(now.year(),now.month(),now.day(),ArduinoHour,ArduinoMin,ArduinoSec));

}

Here is the output.  Looks fine:
RTC IS running!
AT TOP
RTC Time
11:38:3

Arduino Time
11:38:3

AT TOP
RTC Time
11:38:5

Arduino Time
11:38:5

AT TOP
RTC Time
11:38:7

Arduino Time
11:38:7

AT TOP
RTC Time
11:38:9

Arduino Time
11:38:9

This one does not Work:
Now I try to simply increment variable ArduinoHour and then write it to the RTC using rtc.adjust. The only change are the two lines at the bottom are uncommented.
#include <RTClib.h>    //https://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/understanding-the-code
#include <Wire.h>

int ArduinoHour;
int ArduinoMin;
int ArduinoSec;

RTC_DS1307 rtc;

void setup()
{
  Serial.begin(250000);
  Wire.begin();  //sets up the I2C
  rtc.begin();   //initializes the I2C to the RTC

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
  }
    if (rtc.isrunning()) {
    Serial.println("RTC IS running!");
    rtc.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop()
{
  DateTime now = rtc.now(); // pings RTC and loads time info into the now variable.

  ArduinoHour = now.hour();
  ArduinoMin = now.minute();
  ArduinoSec = now.second();

  Serial.print("AT TOP");
  Serial.println();
  Serial.print("RTC Time");
  Serial.println();
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();
  Serial.println();
  delay(1000);

  Serial.print("Arduino Time");
  Serial.println();
  Serial.print(ArduinoHour, DEC);
  Serial.print(':');
  Serial.print(ArduinoMin, DEC);
  Serial.print(':');
  Serial.print(ArduinoSec, DEC);
  Serial.println();
  Serial.println();
  delay(1000);

  //RTC increments when these are commented out
  ArduinoHour = ArduinoHour +1;
  rtc.adjust(DateTime(now.year(),now.month(),now.day(),ArduinoHour,ArduinoMin,ArduinoSec));

}

Here is the output, RTC time is not changing. I know I am doing something basically wrong with how I am updating the variables writing/reading from the RTC.  Can't figure it out.
RTC IS running!
AT TOP
RTC Time
11:41:54

Arduino Time
11:41:54

AT TOP
RTC Time
12:41:54

Arduino Time
12:41:54

AT TOP
RTC Time
13:41:54

Arduino Time
13:41:54

AT TOP
RTC Time
14:41:54

Arduino Time
14:41:54

If by "RTC time is not changing" you mean minutes and seconds frozen at the same value, then this is entirely of your doing.
Your sketch spends 99% of the time between the initial rtc.now() request
 DateTime now = rtc.now(); // pings RTC and loads time info into the now variable.

and the final rtc.adjust() call
rtc.adjust(DateTime(now.year(),now.month(),now.day(),ArduinoHour,ArduinoMin,ArduinoSec));

This period is the period when your RTC is supposed to be "ticking", progressing forward.
But you actually store the original minutes and seconds values in ArduinoMin and ArduinoSec at the beginning of this period. And later, at the end of this period, you bash these values back into the clock. By doing this you forcefully erase whatever progress the clock made between these two lines. No wonder your minutes and second do not change.
This problem actually has no perfect solution. RTC_DS1307 class (and, I suspect, the underlying RTC hardware) provide no means to change just the hours value without disrupting minutes and seconds. When you call adjust(), you have to set everything, which means that you will always somehow "disrupt" the whole clock.
In your sketch you can minimize the adverse effects by re-requesting the minutes and seconds values right before doing adjust():
//RTC increments when these are commented out
ArduinoHour = ArduinoHour +1;
now = rtc.now();
rtc.adjust(DateTime(now.year(), now.month(), now.day(), ArduinoHour, now.minute(), now.second()));

Note, that I'm using your updated ArduinoHour values, but everything else comes from a just-refreshed now object.
This is still not perfect, since it still suffers from a race condition against a real-time clock, but it is better than what you had originally.

@ AnT -  Thank you.  That perfectly explains it.

@AnT, there is a suggested edit, which moves ArduinoHour = ArduinoHour +1; after now = rtc.now();. should it be accepted?

@Juraj: I don't see why. The whole idea of the workaround is to place the second now = rtc.now(); call as close as possible to the rtc.adjust call - in order to minimize the time "lost" between these actions. Moving the ArduinoHour = ArduinoHour + 1; after now = rtc.now(); (for what reason?) goes against that idea.

Sorry, it was my mistake. My edits has nothing useful, sorry again.

This is the content of ajust method:
void RTC_DS1307::adjust(const DateTime& dt) {
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire._I2C_WRITE((byte)0); // start at location 0
  Wire._I2C_WRITE(bin2bcd(dt.second()));
  Wire._I2C_WRITE(bin2bcd(dt.minute()));
  Wire._I2C_WRITE(bin2bcd(dt.hour()));
  Wire._I2C_WRITE(bin2bcd(0));
  Wire._I2C_WRITE(bin2bcd(dt.day()));
  Wire._I2C_WRITE(bin2bcd(dt.month()));
  Wire._I2C_WRITE(bin2bcd(dt.year() - 2000));
  Wire.endTransmission();
}

You can write new Hour value directly to the clock without erasing other clock data:
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire._I2C_WRITE((byte)2); // Hour location
  Wire._I2C_WRITE(bin2bcd(ArduinoHour));
  Wire.endTransmission();


text:
Sync of Time Library and RTClib
Trying to understand the two libraries and setSyncProvider(RTC.now).
Using Arduino Uno with Adafruit ChronoDot.  Aduino IDE 1.8.13.
The code below is simply to understand what is happening.
I am getting surprising results which means I do not understand what the libraries are doing.
What I think I am telling it to do:

Set time RTC to 05:10:30
Set Time Library to 09:27:05
In Loop, printing Library time (hour, minute, seconds)
In Loop, printing RTC time (now.hour, now.minute, now.second)
Every 5 seconds sync the Time Library to the RTC.
This is not what it is doing.
The output from serial prints is at the bottom.

Question 1:  Why does Time Library time  hour() minute() second() change from 9:27:9 to 12:43:44 after first sync and then from 12:43:48 to 19:1:20 after second sync, then reseting to  19:1:20 after each subsequent sync?
Question 2:  After the Sync, why is Time Library hour(), minute() and second() not set to RTC values of now.hour(), now.minute() and now.second()?
#include "RTClib.h"
#include <Wire.h>
#include <TimeLib.h>

RTC_DS1307 RTC;
unsigned long LastSyncTime = 0;    //will control when it syncs just to understand

time_t time_provider()

{
    return RTC.now().unixtime();
}

void setup() {
Serial.begin(9600);
Wire.begin();  //sets up the I2C
RTC.begin();   //initializes the I2C to the RTC

//  Set the RTC Time to 5:10:30 Nov 3 2020
RTC.adjust(DateTime(2020,11,3,5,10,30));

//Set Arduino Time Library different than RTC time 9:27:05 so see how sync works
setTime(9, 27, 05, 4, 07, 2015);

}

void loop() {

//Sync time every 5 seconds
if ((millis() - LastSyncTime) > 5000)
  {
  Serial.println("+++++   Sync  ++++++++");
  setSyncProvider(RTC.now);  //sets Time Library to RTC time: hour() set to RTC now.hour (?)
  LastSyncTime = millis();

   }

DateTime now = RTC.now();  // gets RTC time into now Object

//Print Time Lib Times
Serial.print("hour:       ");
Serial.print(hour());
Serial.println();
Serial.print("minute:     ");
Serial.print(minute());
Serial.println();
Serial.print("seconds:    ");
Serial.print(second());
Serial.println();
Serial.println();

//Print RTC time
Serial.print("now.hour:   ");
Serial.print(now.hour());
Serial.println();
Serial.print("now.minute: ");
Serial.print(now.minute());
Serial.println();
Serial.print("now.second: ");
Serial.print(now.second());
Serial.println();
Serial.println("______________________");

delay(1000);
}

OUTPUT
hour:       9
minute:     27
seconds:    8
now.hour:   5
now.minute: 10
now.second: 33
hour:       9
minute:     27
seconds:    9
now.hour:   5
now.minute: 10
now.second: 34
+++++   Sync  ++++++++
hour:       12
minute:     43
seconds:    44
now.hour:   5
now.minute: 10
now.second: 35
hour:       12
minute:     43
seconds:    45
now.hour:   5
now.minute: 10
now.second: 36
hour:       12
minute:     43
seconds:    46
now.hour:   5
now.minute: 10
now.second: 37
hour:       12
minute:     43
seconds:    47
now.hour:   5
now.minute: 10
now.second: 38
hour:       12
minute:     43
seconds:    48
now.hour:   5
now.minute: 10
now.second: 39
+++++   Sync  ++++++++
hour:       19
minute:     1
seconds:    20
now.hour:   5
now.minute: 10
now.second: 40
hour:       19
minute:     1
seconds:    21
now.hour:   5
now.minute: 10
now.second: 41
hour:       19
minute:     1
seconds:    22
now.hour:   5
now.minute: 10
now.second: 42
hour:       19
minute:     1
seconds:    23
now.hour:   5
now.minute: 10
now.second: 43
hour:       19
minute:     1
seconds:    24
now.hour:   5
now.minute: 10
now.second: 44
+++++   Sync  ++++++++
hour:       19
minute:     1
seconds:    20
now.hour:   5
now.minute: 10
now.second: 45
hour:       19
minute:     1
seconds:    21
now.hour:   5
now.minute: 10
now.second: 46
hour:       19
minute:     1
seconds:    22
now.hour:   5
now.minute: 10
now.second: 47
hour:       19
minute:     1
seconds:    23
now.hour:   5
now.minute: 10
now.second: 48
hour:       19
minute:     1
seconds:    24
now.hour:   5
now.minute: 10
now.second: 49
+++++   Sync  ++++++++
hour:       19
minute:     1
seconds:    20
now.hour:   5
now.minute: 10
now.second: 50
hour:       19
minute:     1
seconds:    21
now.hour:   5
now.minute: 10
now.second: 51
hour:       19
minute:     1
seconds:    22
now.hour:   5
now.minute: 10
now.second: 52
hour:       19
minute:     1
seconds:    23
now.hour:   5
now.minute: 10
now.second: 53

−1, as you visibly did not pay attention to an answer to your previous question. I already explained why setSyncProvider(RTC.now) is incorrect and can only result in the Time library giving you garbage.

@EdgarBonet - Sorry I did use your previous information and it did work. Copy paste error here from older code. Thanks for your help and  patience.

Why does Time Library time hour() minute() second() change from 9:27:9 to 12:43:44 after first sync and then from 12:43:48 to 19:1:20 after second sync, then reseting to 19:1:20 after each subsequent sync?

Because:

You keep calling setSyncProvider(). The whole point of the sync system is that you should only call that once to set the sync provider and then it syncs itself automatically.
You are setting the sync provider to a function that returns an object. The sync provider needs a function that returns an unsigned long (time_t).

Your code should be:
setSyncProvider(time_provider);

And it should only be called once from inside setup.

Question 2: After the Sync, why is Time Library hour(), minute() and second() not set to RTC values of now.hour(), now.minute() and now.second()?

Because of all the things I stated above and were also told in your last question.


text:
How to deal with unusual neopixel grid
I have built a custom installation in my home with 896 WS2812 LED driven by an ArduinoMega 2560 and powered by several rails just fine. However, the installation is arranged in a checkerboard-like pattern. There are 14 panels with 8 strips of 8 LED each (64 LED per panel), The strips are soldered in zigzag pattern within a panel, and the tiles are connected via leads in a "column progressive" fashion.
Hooking this up and running it works well but I'm trying to deal with the unusual pattern I've created, and having a hard time scaling with my current solution. I am worried that my solution is not very graceful and will use up a lot of unnecessary RAM. I am currently using Adafruit's NeoMatrix library.
My solution is to "fake" like I have many more pixels and use the setRemapFunction() to throw these fake grid points away. But as I continue to add fake pixels, I assume the overhead RAM is set aside for them and I will max out before getting done. I have 896 real pixels total, but at this rate I'll be declaring that I have 1,792. This is my attempt to deal with the offset, and is a work in progress. This is utilizing about half of my total grid so far:
const int16_t grid[] = {
0,  15,  16,  31,  32,  47,  48,  63,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 256, 271, 272, 287, 288, 303, 304, 319,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
1,  14,  17,  30,  33,  46,  49,  62,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 257, 270, 273, 286, 289, 302, 305, 318,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
2,  13,  18,  29,  34,  45,  50,  61,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 258, 269, 274, 285, 290, 301, 306, 317,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
3,  12,  19,  28,  35,  44,  51,  60,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 259, 268, 275, 284, 291, 300, 307, 316,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
4,  11,  20,  27,  36,  43,  52,  59,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 260, 267, 276, 283, 292, 299, 308, 315,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
5,  10,  21,  26,  37,  42,  53,  58,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 261, 266, 277, 282, 293, 298, 309, 314,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
6,   9,  22,  25,  38,  41,  54,  57,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 262, 265, 278, 281, 294, 297, 310, 313,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
7,   8,  23,  24,  39,  40,  55,  56,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 263, 264, 279, 280, 295, 296, 311, 312,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,

-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 128, 143, 144, 159, 160, 175, 176, 191,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 384, 399, 400, 415, 416, 431, 432, 447,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 129, 142, 145, 158, 161, 174, 177, 190,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 385, 398, 401, 414, 417, 430, 433, 446,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 130, 141, 146, 157, 162, 173, 178, 189,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 386, 397, 402, 413, 418, 429, 434, 445,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 131, 140, 147, 156, 163, 172, 179, 188,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 387, 396, 403, 412, 419, 428, 435, 444,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 132, 139, 148, 155, 164, 171, 180, 187,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 388, 395, 404, 411, 420, 427, 436, 443,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 133, 138, 149, 154, 165, 170, 181, 186,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 389, 394, 405, 410, 421, 426, 437, 442,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 134, 137, 150, 153, 166, 169, 182, 185,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 390, 393, 406, 409, 422, 425, 438, 441,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 135, 136, 151, 152, 167, 168, 183, 184,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 391, 392, 407, 408, 423, 424, 439, 440,

64,  79,  80,  95,  96, 111, 112, 127,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 320, 335, 336, 351, 352, 367, 368, 383,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
65,  78,  81,  94,  97, 110, 113, 126,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 321, 334, 337, 350, 353, 366, 369, 382,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
66,  77,  82,  93,  98, 109, 114, 125,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 322, 333, 338, 349, 354, 365, 370, 381,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
67,  76,  83,  92,  99, 108, 115, 124,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 323, 332, 339, 348, 355, 364, 371, 380,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
68,  75,  84,  91, 100, 107, 116, 123,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 324, 331, 340, 347, 356, 363, 372, 379,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
69,  74,  85,  90, 101, 106, 117, 122,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 325, 330, 341, 346, 357, 362, 373, 378,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
70,  73,  86,  89, 102, 105, 118, 121,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 326, 329, 342, 345, 358, 361, 374, 377,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
71,  72,  87,  88, 103, 104, 119, 120,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 327, 328, 343, 344, 359, 360, 375, 376,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,

-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 192, 207, 208, 223, 224, 239, 240, 255,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 448, 463, 464, 479, 480, 495, 496, 511,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 193, 206, 209, 222, 225, 238, 241, 254,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 449, 462, 465, 478, 481, 494, 497, 510,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 194, 205, 210, 221, 226, 237, 242, 253,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 450, 461, 466, 477, 482, 493, 498, 509,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 195, 204, 211, 220, 227, 236, 243, 252,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 451, 460, 467, 476, 483, 492, 499, 508,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 196, 203, 212, 219, 228, 235, 244, 251,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 452, 459, 468, 475, 484, 491, 500, 507,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 197, 202, 213, 218, 229, 234, 245, 250,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 453, 458, 469, 474, 485, 490, 501, 506,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 198, 201, 214, 217, 230, 233, 246, 249,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 454, 457, 470, 473, 486, 489, 502, 505,
-1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 199, 200, 215, 216, 231, 232, 247, 248,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1, 455, 456, 471, 472, 487, 488, 503, 504,

};

I am using this like so:
#define PIN 6

#define WIDTH 32 // So far. Will be 56 when I finish creating array.
#define HEIGHT 32

/**
 * Setup the lightwall matrix.
 *
 * Each panel is 8x8 pixels. There are 7 columns and 2 rows,
 * but they are arranged in a checkerboard pattern.
 */
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(WIDTH, HEIGHT,PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
  NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
  NEO_GRBW           + NEO_KHZ800
);

uint16_t remapXY(uint16_t x, uint16_t y) {
  y = y * WIDTH + x;
  return grid[y];
}

void setup() {
  matrix.setRemapFunction(remapXY);
  matrix.begin();
}

So the remapXY() returns the correct key of the array, thus the reason for the crazy array pasted above. And that array is only halfway complete (tediously typing it out!)
But so far it is working. I have a pacman animation (not pictured) scrolling across the screen and being "off screen" for a believable  amount of time. That is the whole point of this madness. But am I going about it all wrong? Attached is also a picture of the full visible matrix for visual aid.

Starting from the upper left corner is panel 1, then lower left panel 2. Next column top is panel 3, bottom panel 4. And so on.
So will I need more RAM in order for this to be performant? Or is there a better way to code my way out of this problem? I have a lot of animations and ambient effects planned, not all of which will strictly require this offset.
Is there another way to "mask" or delay some pixels off screen temporarily based on where they should be? Only to put them back where they belong afterward?

that is an absolutely cool prroject

you can use a spreadsheet program, like excel, to generate arrays like the one that you have. ... then cut and past from the range of cells to the  program editor

Your room looks more high-tech than mine, and that's saying something!

break it down into blocks to determine the upper left corner of any 8x8 grid
const int16_t grid[8][8] = {
       {0,  15,  16,  31,  32,  47,  48,  63},
       {1,  14,  17,  30,  33,  46,  49,  62},
       {2,  13,  18,  29,  34,  45,  50,  61},
       {3,  12,  19,  28,  35,  44,  51,  60},
       {4,  11,  20,  27,  36,  43,  52,  59},
       {5,  10,  21,  26,  37,  42,  53,  58},
       {6,   9,  22,  25,  38,  41,  54,  57},
       {7,   8,  23,  24,  39,  40,  55,  56}
};

const int16_t block[7][4] = {
       { 0,  -1,   4,  -1,   8,  -1,  12},
       {-1,   2,  -1,   6,  -1,  10,  -1},
       { 1,  -1,   5,  -1,   9,  -1,  13},
       {-1,   3,  -1,   7,  -1,  11,  -1}
};

blockNumber = block[x/8][y/8];

// some checking for the -1 value

pixelNumber = blockNumber * 64 + grid[x%8][y%8]

//

This looks really promising - I think I understand. I'm going to try this out and get back to you on how it goes. Thank you!

thanks again! this is working. i had to fix a couple minor nuances but this was immensely helpful!

If I add more, I run out of RAM. Each pixel needs 3bytes of RAM. If I make it 10 "boxes" wide, that becomes a grid of 80x32, or 2560 pixels. That's 7680 bytes of RAM, which is just too much for this weak little board.

i would have a serious look at @edgarbonet's answer and accept that one instead of this one if it allows for larger panels

make the grid and block arrays of type uint8_t instead of int16_t for starters .... you could subdivide the grid array into 4 sections horizontally to save a few more bytes ..... you could add more unused blocks to follow the actual layout more closely ..... top row of block array would be { 0, -1,  -1,  -1,  4,  -1,  -1,  -1,  8,  -1,  -1,  -1,  12},

This indeed looks awesome!
I suggest getting rid of the big grid array, and instead generate the
mapping programmatically. Given that it is very regular, the mapping can
be computed instead of stored:
uint16_t remapXY(uint16_t x, uint16_t y) {

    // Compute panel position and offset of pixel within that panel.
    uint8_t pannel_x = x / 8;
    uint8_t offset_x = x % 8;
    uint8_t pannel_y = y / 8;
    uint8_t offset_y = y % 8;

    // Is this a missing panel?
    if ((pannel_x + pannel_y) & 1)
        return -1;

    // Compute panel number.
    uint8_t pannel = pannel_y / 2 + pannel_x * 2;

    // LED index within the panel.
    uint8_t led = 8 * offset_x;

    if (offset_x & 1)  // numbered bottom to top
        led += 7 - offset_y;
    else               // numbered top to bottom
        led += offset_y;

    return pannel * 64 + led;
}

I hope this will save enough memory to make the whole thing work.

This is also a very elegant solution and also works! It doesn't allow me to add even more fake panels as @jsotola hoped, but definitely feels like less overhead (though I wonder if doing the computations repeatedly is savings vs having the constants defined? Suppose it's CPU vs RAM question). The Mega just doesn't have enough RAM to pretend beyond what I've got it doing.

It occurs to me I could store the lookup tables in PROGMEM too and save some SRAM that way. Reading this: https://www.arduino.cc/en/Tutorial/Memory


text:
Reading bitswise for 'FALSE'
In the sketch I'm working on, I'm storing several 1-bit values representing different boolean states in a single byte, trying to save precious RAM.
(example for 5 boolean states: dec10 = b00001010, the five states are 0, 1, 0, 1, 0)
I'm then using an if statement to determine if the relevant bit is TRUE or FALSE:
if ((options>>3) & 1 == 1)
The above will evaluate true when the relevant bit is 1, so if I want to carry out something in that case, great, no problem!
However, if I want my if statement to evaluate TRUE in the event that the relevant bit is 0, I can't work out what code I need.

I thought the problem might be that the other 'non-relevant' bits were interfering, so I tried bit shifting the LSB all the way to MSB position and then shifting back to LSB:
if ((options<<4>>7) & 1 == 0)
but this still isn't doing what I'm trying to achieve (and seems like a lot of work for the processor).
It also feels like I've tried just about every combination of ~&0, !&0, ==0, !=0, ~&1, !&1, ==1, !=1 there is, but I must have missed something...
Can anyone tell me how I get an if statement to evaluate true in the event that the bit is a zero?

Welcome to Arduino:SE. You might find this helpful: How to ask a good question for Arduino Stack Exchange

if ((options>>3) & 1 == 0) or if ((options>>3) & 1 != 1) - if neither of them work, you did something wrong

The simplest thing is just to mask an individual bit, not do any shifting:
if (options & 0x04) {
    // Do something if true
} else {
    // Do something if false
}

Or, to invert it:
if (!(options & 0x04)) {
    // Do something if false
} else {
    // Do something if true.
}

The thing with C is that 0 is false, and anything else is true.  So if your options variable contains 0b00001010 and you AND it with 0x04 (which is HEX for 0b00001000) you end up with 0b00001000.  That is 0x04, which is something other than 0, so it's true.
If options contains 0b00000010 and you AND it with 0x04, you get 0b00000000, which is 0. Since 0 is false the result is false.
You don't care what the actual number is - you only care if it's 0.

This is exactly what I needed, the exclamation mark goes to the left of the statement being evaluated, thanks @Majenko. You've also taught me a much better way of singling out the bit I'm interested in, perfect!

for readibility add a definition like #define myImportantOption  0x04 ..... then use if (options & myImportantOption) {  .......... put all the definitions at the beginning of your program, so that you can easily change them if you use a different arduino that may have status bits in a different location

@jsotola - good advice for code readability and portability. Would this make any difference to what the ATMEGA sees, or are differences such as this all compiled identically before upload?

There is an alternative to doing bit shifts, and that is to use the bit macro which is defined in Arduino.h (and thus is automatically available).
#define bit(b) (1UL << (b))

Now if you want to see if the second bit is set (which as a mask would be 0x04, being 1 shifted left 2 times) you can do this:
if (options & bit (2))
   {
   // bit number 2 is set
   }
else
   {
   // bit number 2 is clear
   }

This is easier to read than:
if (options & (1 << 2))

or:
if (options & 0x04)

And to invert it:
if (!(options & bit (2)))
   {
   // bit number 2 is clear
   }

Or:
if ((options & bit (2)) == 0)
   {
   // bit number 2 is clear
   }

Also, the various processor bits are given as bit numbers in the Atmega include files (rather than bit masks).

So, for example, to set some processor bits you can do this:
WDTCSR |= bit (WDCE) | bit (WDE);

That is easier to read than:
WDTCSR |= (1 << WDCE) |  (1 << WDE);

And much easier than turning them into hex numbers:
WDTCSR |= 0x10 | 0x08;

And in case you are wondering how to clear a bit, you and in the 1s complement:
WDTCSR &= ~bit (WDCE);

What’s wrong with the _BV() macro that’s already included?

@Nick - bit is new to me, makes things very easy to read, thank you

@Gerben Because identifiers starting with an underscore and followed by an uppercase letter are reserved and should not be used. For example Identifiers (C++). Use of two sequential underscore characters ( __ ) at the beginning of an identifier, or a single leading underscore followed by a capital letter, is reserved for C++ implementations in all scopes. You should avoid using one leading underscore followed by a lowercase letter for names with file scope because of possible conflicts with current or future reserved identifiers.

@Gerben As I pointed out the bit() macro is also already included. I quoted the file it is in (Arduino.h) which will be present in all attempts to compile with the IDE.

(I should have read better.) I didn’t know _BV was none standard. But since it’s replaced by the pre-processor the compiler will never see it q-; . So I will switch to using bit. It’s also easier to type, which is a bonus. Thanks.

@Gerben - the compiler may never "see" it, but let's assume that one day the compiler-writers decide to use _BV for some internal construct (as they are permitted to do, as it is reserved), and the macro form of _BV in Arduino.h overrides that. The compiler will see the difference and not work correctly.


text:
Small Baseball Scoreboard using 2 to 3 breadboards
I'm helping my son start an Arduino small baseball scoreboard (roughly 2 or 3 breadboards in size). Im thinking to use qty 2, 2 digit 7 segment LED's (score of each team), an LCD 1602 module (inning tracker), using a serial monitor. Last is 3 individual LED's (controlled with a switch or remote).
My question is: can one arduino drive all of this? What would be a recommended configuration?
Thank you,Dave

which arduino? there's many models to choose from

Codewise that shouldn’t be a problem. But you might run out of pins to connect them. I’d suggest getting the seven segment displays on a breakout with a driver chip on it. Those will make them easier to use, and require less pins.

Actually, you can very easily verify this yourself:

Per item (1602LCD, 7 segment LCD and LEDs check how many pins you need and what type, like e.g. I2C or SPI for the 1602 LCD). The 7 segment displays can have many or less pins, depending on the 'controller', See the reaction of CrossRoads below.
Count them together. If it fits on the Arduino you want to use OK. The Uno is cheapest, so if it fits on it, you use that, otherwise you can go to the Mega.
As alternative, and you need 'generic pins, called GPIOs' (not SPI/I2C) for some, you can use multiplexers like 74HC595 to reduce the number of GPIOs needed, at the cost of some speed (not critical for your project), and some more programming work.
In some cases you can use a MAX7219 driver IC, see (again) the remark of Crossroads below.

Do the 2-digit displays have seperate pins for all the segments? The parts witll have 16 or 18 pins. If they have common segment pins, the parts will have 10 pins; 1 for each segment, and a common anode or common cathode for each digit. The 2nd type will need multiplexing: display data for 1 digit for a short time (like 3-5 milliseconds) with one anode/cathode pin, then display data for the 2nd digit with the other anode/cathode pin.  If the 2 displays are the same, then both units can have their segment pins in parallel, and 4 unique common anode/cathode pins are used to multiplex the digits.

@CrossRoads Thanks for the valuable remark, I refered to your remark in my answer.

If the 7-segment displays are common cathode, you can easily use a MAX7219 to drive them, just write the data to be displayed to 4 registers and it takes care of the multiplexing.  Common anode is also possible,  but you have to do a little data mapping.

@CrossRoads thanks for improving my answer again (updated the answer).


text:
FastLED: "Invalid pin specified"
I have an Adafruit Trinket (5v, 16mhz, based off of the AtTiny85 chip), and am wishing to use it with a strip with 24 3 pin, individually addressable LEDs (WS2812B). When I try to compile my code, I get this error:  static_assert(validpin(), "Invalid pin specified"); I've tried using different pins, but of them are seeming to work. What can I do to fix this issue? Here's my current code:
#include <FastLED.h>
#define LEDCOUNT 24
#define DATAPIN 0

CRGB leds[LEDCOUNT];

void setup() {
  FastLED.addLeds<WS2812B, LEDCOUNT>(leds, LEDCOUNT);
}

void loop() {
  leds[0] = CRGB::Red;
  FastLED.show();
  delay(30);
}

Where is pin 24 on a ATtiny85?

No idea. I am using this:https://www.adafruit.com/product/1501

I think what @IgnacioVazquez-Abrams is getting at is:
void setup() {
  FastLED.addLeds<WS2812B, LEDCOUNT>(leds, LEDCOUNT);
}

Has LEDCOUNT showing up for both the number of LEDs and the data pin identifier.
Try:
void setup() {
  FastLED.addLeds<WS2812B, DATAPIN, GRB>(leds, LEDCOUNT);
}

This puts DATAPIN in the right place, and also adds the color order typical for WS2812B, GRB

Tried this. Still got an error.

"No hardware SPI pins defined.  All SPI access will default to bitbanged output"

Wait.. it worked though.

That's just a warning, not an error. ATTiny doesn't have hardware SPI that FastLED can use.


text:
Solenoid flyback, relayboard switch
I want to open a solenoid valve with an arduino, and have set up the following circuit

The plan is to add solenoids to every relay on the board. I am wondering if this circuit is any useful, or if there are major flaws present. I am worried about frying my components, especially the 12V 2A hooked up with a solenoid of 1A, however i want the 2A, since i want to be able to power multiple solenoids at the same time.
I tried switching the board directly from the arduino, and with its 5V to the VCC, but it was not enough to make the relays switch, maybe a transistor is in line, if so, which one?

12V, has diodes built in, capacity is AC250V 10A, DC30V 10A. Found no other specs.

@LookAlterno and Rasmus  If the relays are 12V, then they should get 12V. The 2A is no problem. What is that 9V doing? Should that be 5V to the logic part of the relay board? Is that for the optocouplers? Is your Arduino board only powered with a usb cable? Can you give a link to your relay board?


text:
Using RTC DS3231 + Arduino UNO to calculate time lapsed
I am a beginner with no coding background.
I am trying to figure out an alarm that tells people how long they have been sitting on their chair.
The concept is very simple when the person would sit in his chair it will trigger an event ( maybe a button press) which should trigger the counting of time. if the time exceeds a limit (let's say an hour) a buzzer will go off. The only way to stop the buzzer is to stay away from the chair for let's say a minute.
I don't know how to start writing this code, especially how do I make this time counter start with this sitting action ( which might press a button).
Its for my class project so any help is highly appriciated.

The concept is very simple when the person would sit in his chair it will trigger an event ( maybe a button press) which should trigger the counting of time. if the time exceeds a limit (let's say an hour) a buzzer will go off.

multiple ways, all conceptually identical to yours ask:
1) when a person sits in the chair, it triggers a piece of code that sets an alarm in the dtc. once the dtc alarm goes off, it triggers a state change on a pin linking the dtc to the mcu, which triggers the buzzer;
2) the 2nd approach is similar except that the mcu pulls the dtc constantly for new time. once the new time passes the trigger time sufficiently, a buzzer sounds.
...
this whole thing can be done without the dtc, btw.

dtc? Do you mean RTC? Does "pulls the dtc" mean "polls the RTC"?

Thanks a ton, "triggers a piece of code that sets an alarm in the RTC" is my roadblock :D. No idea how to write it.

Take a look at the data sheet. Rtcs generally have alarm registers that set the alarm date and time .  What I do is to take current time off the rtc, convert it to Unix time format, add the increment to it, and then convert it back to time and date. The decomposed time and date can be loaded back to the rtc. Then enable the respective interrupts so you MCU can move onto other things.

One idea would be to use force/pressure sensor on chair. You have to find what the sensor outputs when an average person sits on it and calibrate the values accordingly in code. Finally you have to a set threshold value for it. Now if somebody sits on it and if that threshold is exceeded, it means somebody sat on it. So you can now trigger your rtc module or maybe you can use special peripherals called timers , which are inside arduino itself. Both can be used to keep track of time. Tutorials are available for both timers, and ds3231- arduino interfacing. You can easily code. Good luck :-)

Thanks a ton! I am trying to write the code. Hopefully post it here soon :)


text:
No ttyACM0 nor ttyUSB0
I checked several related posts but couldn't solve my problem.
I have Antergos Linux :
# uname -a
Linux biutitude 4.14.11-1-ARCH #1 SMP PREEMPT Wed Jan 3 07:02:42 UTC 2018 x86_64 GNU/Linux

The board is a Seeeduino Lorawan.
The problem is that the menu to select the port is greyed, and when I check in /dev I don't see any new tty when I plug the card. However the card blinks.
I tried :
- adding myself to lock + tty + uucp (and restarted my session)
- created a dialout group because I didn't have one, added myself to it
- loading cdc_acm module but got the following error :
# modprobe cdc_acm
modprobe: FATAL: Module cdc_acm not found in directory /lib/modules/4.14.11-1-ARCH

Thus I tried :
[root@biutitude biu]# depmod -ae
depmod: WARNING: -e needs -E or -F
depmod: ERROR: could not open directory /lib/modules/4.14.11-1-ARCH: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
[root@biutitude biu]# depmod
depmod: ERROR: could not open directory /lib/modules/4.14.11-1-ARCH: No such file or directory
depmod: FATAL: could not search modules: No such file or directory

I'm clearly out of ideas. The weirdest is that a few months ago, I was able to use a RFduino card without any trouble.

Run watch lsusb, then plug in the board. Does it show a new entry in the list? If so, what does it say?

dmesg -w is your friend. Run that, plug in the board, and look what it tells you.

My solution - install linux-modules-extra kernel module on ubuntu 20.04. Solved my problem which was identical.
Get OS details:
uname -a
Linux seeeduino-node 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Install the sudo apt install linux-modules-extra:
sudo apt install linux-modules-extra-<kernel-version>

Example:
sudo apt install linux-modules-extra-5.4.0-91-generic

You need to reboot the machine afterwards it should work.


text:
How can I declare custom pins when using with ESP8266 in MPU9250 library
I want to declare SCL and SCK pins like   Wire.begin(sda_pin, scl_pin); to use with ESP8266 to integrate a MPU 9250/6500 sensor.
I can't figure out a way to declare that in this code exaample provided by https://github.com/bolderflight/MPU9250
in the example of the above it has just passed as Wire to and created object like MPU9250 IMU(Wire,0x68); which was meant to be used with UNO boards(as I think)
And in any case if any of you have seen a library that can be used with the ESP8266 for the MPU 9250/6500 point me on that direction please (I'm trying to get the roll, pitch, yaw)

You can use Wire.pins(sda, scl); before IMU.begin();.
IMU.begin() then calls Wire.begin() without parameters.


text:
Is output pin set to LOW grounded
If I do following:
pinMode(MYPIN, OUTPUT)
digitalWrite(MYPIN, LOW)

What will happen? Will this effectively ground MYPIN or output some low voltage?

This will effectively connect the pin to ground. Note that the connection is
made by a transistor that has a finite resistance. This output resistance is
not really specified, but from the curves on the “typical characteristics”
section of the datasheet you can infer that the typical value is about
26 Ω.
The only hard specification states that the OUTPUT LOW voltage
should be no larger than 0.9 V, as long as the pin is not sinking
more than 20 mA. C.f. the table “DC characteristics” of the
ATmega2560
datasheet.


text:
Code for determining beats per min when timing a wooden clock
I'm new to Arduino and coding but I build wooden clocks.  The biggest problem is timing the clock to the correct beats per min when adjusting pendulum length.  I'm thinking Arduino and an IR sensor?? to detect when the pendulum breaks the beam, then displaying the beats per min real time would be possible.  If not real time then just beats in a variable time period, ie 1 min or 2 or 5 or 10 min.  I've looked for this type of code and circuit but haven't been able to find one.  Any help would sincerely be appreciated.

What kind of accuracy level do you require? Like a few ppm?

No, needs to be down to tenth or hundreth of a min.  What I currently do is use a stopwatch to measure 60 beats (for example) and see what time period that is.  Obviously 60 beats in 1 min would be accurate (however some clocks have 90 beats per min)  If that isn't possible then counting the beats in a 2 or 5 min or 10 min cycle would start narrowing things down.

If the accuracy you require is about 1%, that should be doable with any
Arduino. Much higher accuracies would be hard to achieve because most
Arduinos are clocked off a ceramic resonator, and these have a frequency
tolerance of about 0.5%.
Given that your signal is very slow, the simplest approach may be to
poll the pin connected to the sensor and record the time (using
micros()) of the low → high transition. Then you can compute the
beat frequency as the inverse of the time between consecutive
transitions.
There is, however, the possibility that the sensor is not exactly in
the middle of the swing. Then, for better accuracy, I would measure the
time taken by two beats, i.e. a full swing. This way the pssible
asymmetry will not affect the accuracy.

I'd suggest to have the Arduino send a message to the PC when a 'tick' occurs. Then have the PC do the calculations over a larger number of ticks. You can even have the PC measure it's drift using NTP (PC clocks also aren't extremely accurate, but better that the crystal on the Arduino).
The procedure that I used, I found at https://www.logre.eu/wiki/Horloge_analogique_24h/en#Quartz_calibration I ran it for a few hours. Which might also be useful in your case to see if the swing is consistent.
I used this to calibrate my Arduino clock to within a few seconds per year,

Thanks so much for the info and direction to head.  Now I'll figure out if I understood all this wisdom, like I said, new to coding.  Appreciate the quick response.

At that point you might as well just use the PC to record the ticking sound and process it in software.  Or if you can't work in a quiet environment, couple the sensor the PC audio input with a capacitor.


text:
Arduino and Python
Does anyone know how do I get Arduino and Python talking to each other? I would essentially like to write my code and export it somehow to the arduino-uno.

Other than with pyserial?

No, can I use Pyserial?

For a python interpreter running on a microcontroller you need quite a lot of ressources (flash, SRAM, speed,..). Consider to either change the board to something like an ESP8266, ESP32 or Feather M0, or live with C/C++ and the smaller boards. The Arduino Uno simply can't run it on 2KB RAM and 32kB Flash.

So how would I get Python to interact with Arduino?

'Arduino' is a framework, a set of library functions which you can use to make your microcontroller do something, so to say. When you use the language Python with MicroPython or CircuitPython, you're using that new framework. Then it's not running an Arduino Core anymore.

What do you mean "interact"? Do you mean run Python on an Arduino or Arduino code communicate with Python code on the PC?

Arduino code communicate with Python code.

http://playground.arduino.cc/interfacing/python

Would you have any examples of how Python might be used with Arduino?

You can not run python on an UNO. If you want to use python on a microcontoller you should look into boards supported by MicroPython or Circuit Python

The Arduino communicates with the PC (and vice-versa) normally using Serial.  You can use the PySerial module in your python code to open the Arduino's serial port and read and write data, and the Serial object in your Arduino code likewise.
What that data is, and what it means, though is up to you to decide upon and program.


text:
Why call a USB connection a serial connection?
Does anyone know why Arduino calls a USB connection a serial? When I hear a serial connection I automatically think of a male pin connection and not a USB connection. Also not sure if this a Linux term or just an Arduino thing.

Where did you get the association of "serial" with "male pin connection" from?

Serial Cable, DB9/DB9 Male to Female Cable https://en.wikipedia.org/wiki/D-subminiature

Universal Serial Bus.......................................

universal SERIAL bus

On most Arduinos Serial is not a USB connection. It is a UART (real serial) connection which is used to communicate with a USB to UART adaptor (often made out of another small MCU, the ATMega16U2).  It's only from that chip onwards that it is USB.  Between the main MCU and that USB interface chip it is serial. The same serial you get from pins 0/1 (literally: it's hardwired together).
Indeed, the first Arduino prototype (that grew out of the Wiring project) had no USB at all - only Serial. The USB to UART adaptor was added later. But it still remains a Serial interface.

As @ratchetfreak answered, USB is a Serial bus. But there is more.
The microcontroller on Arduino boards has one or more built-in peripherals called UARTs, which stands for Universal Asynchronous Receiver-Transmitter.
This is what the Arduino core calls a Serial port. It uses the same kind of protocol as the old DB-9 serial ports on PCs and such, but at 5V or 3.3V logic levels. Contrast this 0V to 5V voltage swing to indicate Logic LOW and Logic HIGH with the RS-232 standard for the old PC serial ports, which use a +12V to -12V swing to indicate such.
But PCs today don't often have the old RS-232 serial port. They instead have the new USB - Universal Serial Bus - port. On the Arduino board is chip that communicates on one side via USB with the PC and tells the PC that it provides the equivalent of the old COMPORT or /dev/ttyS* serial device; and on the other side via UART with the microcontroller on the Arduino board.
It's like we are "emulating" the old PC serial ports in software over the new USB bus, which itself is a serial communication system, though much more complex than a plain UART.

and on Atmegas with native USB support the singleton object is called SerialUSB

Almost all the ways protocols used to communicate on arduino are Serial.  USB,UART, I2C, SPI. Serial means one bit at a time, then the other way is Parallel communication which is what printers used to use. This allowed a whole byte to sent at one time(there were 8 data lines). As clock speeds increased there was no longer a need to have these big bulky,expensive cables and connectors. So away went parallel connections from common computer/electronics applications.

MMIO also uses parallel communications.

Yes, and there are many applications were parallel communication is still used, espessically between devices 'inside' a computer where you need to send a lot of data really fast.  And I am sure its still used with external devices to some extent. I was just saying that it went away as a 'normal' way of connecting external devices.


text:
how long should interrupting signal last?
I want to apply the interruption of a program with a RISING signal from a pin. How long should the signal rise to be considered as the interruption?

What microcontroller are you using? Have you looked up its datasheet on minimum rise / glitch rejection times?

If edge or toggle interrupt is selected, pulses that last longer than one clock period will generate an interrupt. Shorter pulses are not recommended to generate an interrupt.

Source (page 91, chapter 17.2.1 "External Interrupt Control Register A")

Thank you very much for your answer and the substantial link.


text:
Arduino Uno with Adafruit CC3000
I am using Arduino Uno with Adafruit CC3000 wifi shield to connect to the internet and get data for Arduino. Everything works fine but I can't figure out how to use HttpClient library. The code is:
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"
#include <HttpClient.h>

#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,    ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,SPI_CLOCK_DIVIDER);

#define WLAN_SSID       "ssid"
#define WLAN_PASS       "pwd"
#define WLAN_SECURITY   WLAN_SEC_WPA2

void setConnection(){

     Serial.println("Initializing...");
     if (!cc3000.begin())
     {
       Serial.println("Couldn't begin()! Check your wiring?");
       while(1);
     }
     Serial.print("Attempting to connect to ");
     Serial.println(WLAN_SSID);
     if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
       Serial.println("Failed!");
       while(1);
     }
     Serial.println("Connected!");
     Serial.println(F("Request DHCP"));
     while (!cc3000.checkDHCP())
      {
          delay(100);
       }
     Serial.println(F("DHCP success!!"));
 }

void dweet(){

  int ctr=0;
  char buff[100];
  int x=0;
  const char* host = "https://dweet.io/get/latest/dweet/for/dunebot";

  Serial.println(F("Initializing dweet client ..."));
  HttpClient client;
  client.get(host);
  Serial.println(F("Client Connected !"));

  while (client.available()) {
    char c = client.read();
    Serial.write(c);
    delay(100);
  }

void setup(){

     Serial.begin(115200);
     while(!Serial);
     Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
     setConnection();

}

void loop(){
dweet();
}

If all worked fine then I should have got a json string which is:
{"this":"succeeded","by":"getting","the":"dweets","with":[{"thing":"dunebot","created":"2018-05-12T13:27:56.106Z","content":{"0001":""}}]}

When I run the code, Arduino connects to the wifi network but afterwards when I observe the Serial monitor all I get are garbage values.

I need a way to read the key 0001 from the json string. Any help would be appreciated.Thanks.

The HttpClient object must be instantiated with a Client object which will handle the underlying connection. Source:

Requires a networking hardware and a library that provides transport specific Client instance, such as:

Refer to the following code:

https://github.com/arduino-libraries/ArduinoHttpClient/blob/master/examples/DweetGet/DweetGet.ino
https://github.com/adafruit/Adafruit_CC3000_Library/blob/master/Adafruit_CC3000.h#L86
https://github.com/arduino-libraries/ArduinoHttpClient/blob/master/src/HttpClient.h#L51

In the above example, it is done like
WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);

Which means that for your code, you might want to pull out client as global object and instantiate it as:
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,    ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,SPI_CLOCK_DIVIDER);
/* Create new Adafruit_CC3000_Client object */
Adafruit_CC3000_Client cc3000_client;
/* Feed this into the client */
HttpClient client (cc3000_client, "dweet.io", 80);

You should also use the example code to see how to print the response after executing client.get():
  // read the status code and body of the response
  statusCode = client.responseStatusCode();
  response = client.responseBody();
  Serial.print("Status code: ");
  Serial.println(statusCode);
  Serial.print("Response: ");
  Serial.println(response);

The example code is pretty much example what you want, you just have to give it a Adafruit_CC3000_Client as the Client.
Full code:
#include <Arduino.h>
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"
#include <HttpClient.h>

#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,    ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,SPI_CLOCK_DIVIDER);
/* Create new Adafruit_CC3000_Client object */
Adafruit_CC3000_Client cc3000_client;
/* Feed this into the client */
HttpClient client (cc3000_client, "dweet.io", 80);

#define WLAN_SSID       "ssid"
#define WLAN_PASS       "pwd"
#define WLAN_SECURITY   WLAN_SEC_WPA2

int statusCode = 0;
String response;

void setConnection(){

    Serial.println("Initializing...");
    if (!cc3000.begin())
    {
        Serial.println("Couldn't begin()! Check your wiring?");
        while(1);
    }
    Serial.print("Attempting to connect to ");
    Serial.println(WLAN_SSID);
    if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
        Serial.println("Failed!");
        while(1);
    }
    Serial.println("Connected!");
    Serial.println(F("Request DHCP"));
    while (!cc3000.checkDHCP())
    {
        delay(100);
    }
    Serial.println(F("DHCP success!!"));
}

void dweet(){

    int ctr=0;
    char buff[100];
    int x=0;
    const char* host = "https://dweet.io/get/latest/dweet/for/dunebot";

    Serial.println(F("Initializing dweet client ..."));

    client.get(host);
    Serial.println(F("Client Connected !"));

    // read the status code and body of the response
    statusCode = client.responseStatusCode();
    response = client.responseBody();
    Serial.print("Status code: ");
    Serial.println(statusCode);
    Serial.print("Response: ");
    Serial.println(response);

    /*
    Typical response is:
    {"this":"succeeded",
    "by":"getting",
    "the":"dweets",
    "with":[{"thing":"my-thing-name",
      "created":"2016-02-16T05:10:36.589Z",
      "content":{"sensorValue":456}}]}
    You want "content": numberValue
    */
    // now parse the response looking for "content":
    int labelStart = response.indexOf("content\":");
    // find the first { after "content":
    int contentStart = response.indexOf("{", labelStart);
    // find the following } and get what's between the braces:
    int contentEnd = response.indexOf("}", labelStart);
    String content = response.substring(contentStart + 1, contentEnd);
    Serial.println(content);

    //There was a missing brace here. Was the code cut off?!
}

void setup(){
    Serial.begin(115200);
    while(!Serial);
    Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
    setConnection();
}

void loop() {
    dweet();
}

So i did what you told but it throws an error no matching function for call to 'HttpClient::HttpClient(Adafruit_CC3000&, const char [9], int)'. Does HttpClient work with Adafruit cc3000?

@AshishKafle in the library code I linked it says that it derives from the class Client. I will test this my self in just a moment.

@AshishKafle Could you retry that again. I referenced the Adafruit_CC3000 class when it should have been the Adafruit_CC3000_Client class.

the code works nice but after Serial.println(F("Client Connected !"));  nothing seems to work for me. After that i get nothing.

Could you try this sketch and post the output on pastebin. https://pastebin.com/2kUqACgB

The output is here https://pastebin.com/5XeVGdZi . The error is client.get returned error: -1.

Oh, there seems to be another mistake: change host to /get/latest/dweet/for/dunebot

@AshishKafle Please find this file in your local Arduino Library repositary and remove the //. Also  find this file and add the line #define LOGGING true at line 7, then re-post output

It says connection failed. The output is here: https://pastebin.com/NMzNr682 .

@AshishKafle and no output from the CC3300 library although you removed the comment? Unfortunetly I don't have the hardware, so remote debugging is hard. Try adding more debug output to https://github.com/adafruit/Adafruit_CC3000_Library/blob/master/Adafruit_CC3000.cpp#L1414 to understand what's happening.

Yes it was all that it showed. Thanks I will do that.


text:
USB Host Shield plus 2 identical joysticks
I'm trying to get two identical joystics (Saitek cyborg 3D) running with the USB-Host-Shield on a Mega 2560 and an USB-Hub.
I already get the event-messages of both of them:
#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>

// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

#include "hidjoystickrptparser.h"

USB Usb;
USBHub Hub(&Usb);
HIDUniversal Hid1(&Usb);    // first Joystick
HIDUniversal Hid2(&Usb);    // second Joystick

JoystickEvents Joy1Events;
JoystickEvents Joy2Events;

JoystickReportParser Joy1(&Joy1Events);
JoystickReportParser Joy2(&Joy2Events);

void setup() {
        Serial.begin(115200);
#if !defined(__MIPSEL__)
        while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
        Serial.println("Start");

        if (Usb.Init() == -1)
                Serial.println("OSC did not start.");

        delay(200);

        if (!Hid1.SetReportParser(0, &Joy1))
                ErrorMessage<uint8_t > (PSTR("SetReportParser1"), 1);
        if (!Hid2.SetReportParser(0, &Joy2))
                ErrorMessage<uint8_t > (PSTR("SetReportParser2"), 1);
}

void loop() {
        Usb.Task();
        Serial.print("\tX1: ");
        PrintHex<uint8_t > (JoystickEvents::mostRecentEvent.X, 0x80);
        Serial.print("\tY1: ");
        PrintHex<uint8_t > (JoystickEvents::mostRecentEvent.Y, 0x80);
        Serial.print("\tX2: ");
        PrintHex<uint8_t > (JoystickEvents::mostRecentEvent.Z1, 0x80);
        Serial.print("\tY2: ");
        PrintHex<uint8_t > (JoystickEvents::mostRecentEvent.Z2, 0x80);
        Serial.print("\tRz: ");
        PrintHex<uint8_t > (JoystickEvents::mostRecentEvent.Rz, 0x80);
        Serial.println("");

}

My question is: How can I distinguish the events from the different joysticks.
I'm trying to get some kind of port-information from the USB-Hub. Unfortunately something like
!hid->GetAddress()

within the JoystickReportParser doesn't do the job as it always returns 0.
Any ideas?

look at the hub demo

That's what I'm doing since several days but I don't get the clue. I get message-events but how do I recognize from which port they do come?
In the hub demo there is this function: PrintAllAddresses() which takes a pointer to the device. But it's called within this statement: Usb.ForEachUsbDevice(&PrintAllAddresses);

In the hub demo there is this function: PrintAllAddresses() which takes a pointer to the device. But it's called within this statement: Usb.ForEachUsbDevice(&PrintAllAddresses);
So how would I call something like this from within the JoytickReportParser or the eventhandler OnGamepadChanged ?

Or how do I get a pointer to the device from which a message-event comes in?

To be honest. I'm not so familiar with all this pointer arithmetic.
All these -> :: ! * .  Is still a little bit wired to me.

i am talking about this demo ... https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/hub_demo/hub_demo.ino  .... it looks like it prints a whole bunch of info about every usb device that is plugged in ..... start with that

the ! is a boolean not statement ... when it is rainy it is !sunny

@jstola I'm afraid you statement is incorrect sometimes it is sunny && rainy at the same time.

logically, that is true, but it was meant as a rough example of the not operator (also my comment is incorrect because the not is really a unary operator, not a statement)

Thank you very much for your help. @jsotola I already ran this hub-demo. So I know that the two Joysticks are attached to two USP-Ports at the hub, which have addresses like A and B. The output of the PrintAdress() Function is something like (0,1,A) and (0,1,B) for the two Joysticks.
What I do not know is. How can I access this information from within the event-handler-function called void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) {} from the Joystick-Demo.

A documentation of the USB-HUB-2.0 Library can be found here: http://felis.github.io/USB_Host_Shield_2.0/inherits.html. (There's a nice class hierarchy at the bottom of the site). From looking there it seems to me that the class USBHID that might be responsible for the Joystickreadouts seems to inherit from the class USBDeviceConfig (or vice versa what would not make sense to me but who knows. Does the direction of the arrows indicate the direction of inheritance in this diagram?)

So my question is: What line of code would I have to add to the event-handler-function void JoystickEvents:: OnGamePadChanged(const GamePadEventData *evt) {} in hidjoystickrptparser.cpp from the USBHIDJoystick.ino-Demo to get these A and B USB-addresses from my previous comment? So when a message-event comes in I know from which Joystick it comes.

Or let me put the question in other words. The void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) {
}-Function gets a pointer to an event-object *evt. This *evt-object must somehow be connected to the USBdevice-object where it comes from. But how can I access this, and how can I figure out which method to call stepping through the inheritance hierarchies to get the address of the USBdevice?

Or maybe like this: In the hub-demo I find the function:
void PrintAllAddresses(UsbDevice *pdev)
{
UsbDeviceAddress adr;
adr.devAddress = pdev->address.devAddress;
Serial.print(adr.bmAddress, HEX);
Serial.println(")");
}
So if I could somehow get this handle *pdev from within the event-handler-function from the Joystickdemo, I could imagine to get this address. But unfortunately I do not know how to get this.

I am trying to solve the same issue. I got already working in the main void loop: Serial.print(Hid1.GetAddress());
But to distinguish the 2 identical joysticks in the event loop, did you already manage -> Palmstroem?

this could be a possible answer:
https://github.com/Bratski/Arduino-2-Joysticks-to-PPM

Not quite the question that was asked but part of the problem.
This is a simple introduction to pointers.
int variable = 42;                              // Create a variable
int* pointer = &variable;                       // Create a pointer to the variable (by getting its address)
*pointer = 99;                                  // Set the address to a new value
printf ("variable has the value %d", variable); // Print 99.

&x get the address of x
*y dereferences the pointer y, which means it 'turns it back to a variable' (this is simplistic view which isn't really true, but will do for now).
So you could, if you wanted (which you wouldn't) do this *&z which would be the same as doing z.
Basically think of & and * as a pair of complimentary operators like - and + or * and /.  (They aren't operators, but to start with it might help).
The next problem is when you do this
SomeFunction(&variable);

All function parameters in C/C++ are passed by value by default.  This means the function gets a copy of them not the actual value.  So if you had:
void FunctionOne (int val)
{
    val = 99;
}
int val = 4;
FunctionOne(val);
printf("val = %d", val);   // You will see 4 printed.

If you pass by reference then you will see 99 printed, to pass by reference you can do it one of two ways.
void FunctionTwo (int& valByRef);
void FunctionThree (int* valPointer);

FunctionTwo only works with C++ (It will work with an Arduino).
FunctionThree might cause a segmentation error if NULL is passed in and the function writes to it.
If it helps in my opinion pointers was one of the hardest concepts to grasp in classic C/C++ so don't worry if you don't understand it just have a play with it and see what you can do.
Calling Methods

object.method() - Call the function method on the instance called
object which is of type X.
object->method() - Call the function method on the instance called
object which is a pointer of type X.
object::method() - call the function method
which is a static member of class object (static means it doesn't
change any data within an instance of a class)
*object->method() - Avoid this like the plague.  It either means *(object->method()) or (*object)->method() to know you would need to look at the type of object and the return type of the function.  Its easier just to bracket it to remove ambiguity.

As for *object.&method() I've never come across that one, but that doesn't mean it doesn't exist. :)

Thank you very much for this explanation. Good explanation! What confuses me is: Sometimes you can access a property by object.method or by object.object.method then by object::method and object->method or object.&method or *object.&object::method and object.@->/!%&wtf$method and so on. These things were not made for human brains to be understood.

Are you saying I'm not human? :)
(See edit)
Its learning a new language, and you just have to remember certain rules, the more you use them the more they become ingrained, there is no short cut :(

Thank you very much. Superhuman!
Any ideas for the original question? I'm inside a signal-handler-function and want to access an attribute of a parent or grand-parent class, but don't know how to find the right method. The documentation at http://felis.github.io/USB_Host_Shield_2.0/class_u_s_b_device_config.html seems to be quite comprehensive. But I don't get the clue.

!Hid->GetAddress() always returns 0. Maybe I need to do something like *evt.HIDDevice.Hid->GetAddress() but all trials like that lead to compile errors.

this could be a possible answer, in Arduino Code, the USB Host Shield 2.0 library is necessary:
#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>

// Logitech Attack 3 HID report
struct GamePadEventData {
    uint8_t X, Y, Z1, Z2, Rz;
} __attribute__((packed));

class JoystickEvents {
    public: virtual void OnGamePadChanged(const GamePadEventData *evt, int joystick);
};

class JoystickReportParser : public HIDReportParser {
    JoystickEvents *joyEvents;
    uint8_t joyId;
    uint8_t oldPad[sizeof(GamePadEventData)];
    public: JoystickReportParser(JoystickEvents *evt, uint8_t id) : joyEvents(evt), joyId(id) {}
    virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};

void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
    if (!is_rpt_id && len == sizeof(GamePadEventData)) {
        // Checking if there are changes in report since the method was last called
        bool match = (sizeof(oldPad) == len) && (memcmp(oldPad, buf, len) == 0);
        if (!match && joyEvents) {
            joyEvents->OnGamePadChanged((const GamePadEventData*)buf, joyId);
            memcpy(oldPad, buf, len);
        }
    }
}

void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt, int joystick) {
    Serial.print("Joystick ");
    Serial.print(joystick);
    Serial.print(": X: "); PrintHex<uint16_t>(evt->X, 0x80);
    Serial.print(" Y: "); PrintHex<uint16_t>(evt->Y, 0x80);
    Serial.print(" Z1: "); PrintHex<uint8_t>(evt->Z1, 0x80);
    Serial.print(" Z2: "); PrintHex<uint8_t>(evt->Z2, 0x80);
    Serial.print(" Rz: "); PrintHex<uint8_t>(evt->Rz, 0x80);
    Serial.println();
}

USB Usb;
USBHub Hub(&Usb);
HIDUniversal Hid1(&Usb); // first Joystick
HIDUniversal Hid2(&Usb); // second Joystick

JoystickEvents JoyEvents;
JoystickReportParser Joy1(&JoyEvents, 1);
JoystickReportParser Joy2(&JoyEvents, 2);

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

    Serial.println("Start");

    if (Usb.Init() == -1) {
        Serial.println("OSC did not start.");
    }

    delay(200);

    if (!Hid1.SetReportParser(0, &Joy1) || !Hid2.SetReportParser(1, &Joy2)) {
        ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1);
    }

}

void loop() {
    Usb.Task();
}


text:
PROGMEM doesn't cause Sketch size to change
I'm trying to pinpoint some strange behaviour involving the use of PROGMEM and the size of a Sketch.
I've written a library that contains a number of functions, in addition to several large global byte arrays and 32-bit uint arrays. These arrays are stored in PROGMEM using the pgmspace library. The library compiles fine, and all code works properly when uploaded to an Arduino.
I'm performing testing on the functions using a testing sketch that in turn uses my library. In order to test the performance, I've been switching between using PROGMEM and not using PROGMEM in the library (all arrays are under 2KB). When using PROGMEM, it drops the Global Variable dynamic memory count by the expected amount... but the the sketch program size remains either constant, or seems to arbitrarily increase or decrease by a very small amount, depending on the function. For example, a uint8_t byte[256] array, when moved to the PROGMEM, causes the Global Variable size to go down by about 256 bytes... but the sketch size only increases by about 12 bytes.
Each entry in the array is unique and is accessed, so the compiler shouldn't be optimizing it away. I tried just using avr-size directly on the ELF file, but the sketch size was the same. I can't tell if the data is being stored in PROGMEM all the time (even when not declared as PROGMEM, due to some sort of issue with PROGMEM in libraries?), or if PROGMEM data simply isn't being counted as part of the sketch size, or ??? I have tried moving the functions directly out of the library into the sketch, changing data types, adding/removing static and const declarations... but the lack of change in sketch size continues to confuse me. Any help would be greatly appreciated.

That is a whole point to not having constant data in the RAM. However they must be stored somewhere, they're just not copied into the RAM.

all constant data are part of the sketch. where else should they be? in runtime they are loaded into RAM. PROGMEM directive prevents the loading into RAM.

Ah, so either way, the storage size required remains constant? Now it makes sense.


text:
What will happen if I set ARef to 3.3V and try to use adc connected to 5V
What will happen, if I try to measure voltage higher than ARef?
For example, my ref is 3.3V, and I try to measure 4.5V. Will it damage adc?

Somewhat similar to my question: https://arduino.stackexchange.com/questions/43459/can-i-connect-a-voltage-higher-that-the-1-1v-bandgap-voltage-to-an-adc-pin

I am using internal VREF 1.1V and measruring throuht a 1Mohm to 3.3V and a phototransistor is connected to GND. If no light is present, I read the value ADC of 1125bit. What is far strange because the maximum is 1023 with zero included.
So I would say it may not damage the chip but creates strange behaviour. A voltage divider is recommended.

The datasheet of the Atmega328P does not give a direct answer to this, but

Single ended channels that exceed V REF will result in codes close to
  0x3FF.

(Datasheet Chapter 24.5.2)
sounds, as it would not destroy the ADC, but only result in a value very close to the maximum. I also found another side, where this is also stated. They linked to the Arduino forum, where a similar question is handled in this thread.
So all in all it should be save to provide more than the reference voltage at the ADC pins, as long as it does not exceed the supply voltage (for the UNO 5V).

As Majenko pointed out in his answer, the datasheet states, that it is safe to provide VCC+0.5V at any pin (except for reset). I just wasn't sure, if this can easily be applied to this special hardware, but it seems, that it can.

Contrary to what @chrisl says, the datasheet does give a direct answer to this:

Voltage on any Pin except RESET with respect to Ground: -0.5V to VCC+0.5V

So when running at 5V anything up to 5.5V is safe - regardless of what VRef has fed into it.
The VRef just sets the range of the ADC when comparing the incoming voltage to a DAC generated voltage, so anything over the VRef voltage will just read as "max" (1023).

As I understand this, the part you quoted does not say anything about the influence of special hardware, that is connected to the pin. For example: If you provide the ADC with the internal reference voltage of 1.1V, you must not connect a different voltage to the pin, or the ADC can be destroyed due to the short. With this reasoning I assumed, that your quote is not a direct answer for this specific case.

That is incorrect. The VRef is what it says - a reference voltage. That is all. It is compared to the incoming voltage through a comparator. It doesn't care if the incoming voltage is above the reference voltage.

@chrisl If you have a 30cm ruler and you try and measure a piece of string that's 50cm long it doesn't break the ruler. All you can say is that it's at least 30cm.

I hang at this sentence from chapter 24.5.2 of the Atmega328P datasheet: "If the user has a fixed voltage source connected to the AREF pin, the user may not use the other reference
voltage options in the application, as they will be shorted to the external voltage." Do I misunderstand something here?

@chrisl Ah, you're talking about something completely different. Nothing to do with anything the OP asked. That's just a warning against a misconfiguration whereby you can select two reference voltages at once, which is bad (and poor design on Atmel's part...).

Ok, I wasn't sure how reliable this statement is, when the voltage on the AREF pin matters on a misconfiguration. Something like when they have bad design there, why not also in another part on the same pin. I will edit my question to point to your answer

It helps to understand how an SAR ADC works and what the role of the VRef is.