text:
Problem when using PROGMEM on array holding notes for speaker on Arduino
The problem I've been having is a little weird. I'm trying to set up audio for my Arduino project and have been playing around with the example included in the IDE. The problem is whenever I try to make the array of notes go into PROGMEM, it makes the outputted note higher than the one I put in. I don't want it to do that.
In case it is relevant, the code I have is as follows:
    #define tuneSize 2
    // notes in the melody:
    const int melody[tuneSize] PROGMEM /*This is what's screwing it up*/= {
      NOTE_AS3, 0
    };

    // note durations: 4 = quarter note, 8 = eighth note, etc.:
    int noteDurations[tuneSize] = {
      6, 16
    };

    void setup() {
      // no need to repeat the melody.
      // iterate over the notes of the melody:
      for (int thisNote = 0; thisNote < tuneSize; thisNote++) {

        // to calculate the note duration, take one second
        // divided by the note type.
        //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
        int noteDuration = 1000 / noteDurations[thisNote];
        tone(8, melody[thisNote], noteDuration);

        // to distinguish the notes, set a minimum time between them.
        // the note's duration + 30% seems to work well:
        int pauseBetweenNotes = noteDuration * 1.30;
        delay(pauseBetweenNotes);
        // stop the tone playing:
        noTone(8);
    }
}

(Pitch.h can be found in the Arduino example tab under digital)
My circuit has an 8 ohm resistor on pin 8. That's it.
The only thing I can think is that since the PROGMEM is slower, the data doesn't get to the speakers as fast thus making the output weird. Does anyone know how to fix this issue? Also, just having it on SRAM is not ideal because I'm working with a display and the lib it uses uses a lot of SRAM.

You can not directly dereference something ("access an array") that is in flash memory. You have to use pgm_read_xxx functions from <avr/pgmspace.h> .
In your case you should probably write something like this:
tone(8, pgm_read_word(&melody[thisNote]), noteDuration);

Pgm_read_word reads two bytes. You could also call that inside your tone() function, the function would take the pointer in flash as an argument.
I would also recommend you using integer types from <stdint.h>, because they have defined sizes. Pure int is most likely 32-bit on your PC, but 16-bit on the AVR (I have learned this the hard way when my algorithm ran fine on the PC but gave totally junk output on the AVR).

authors: Алексей Гаврилов


text:
Count fuel liters with Arduino
We have created a fuel sensor in our lab with Arduino in order to get fuel data from vehicles. Regarding the code below, I receive an error

PARSE ERROR: 'attachInterrupt': this function needs to be defined.

Could you please advice?
int pin = 2;
volatile unsigned int pulse;
float volume = 0;
float flow_rate =0;
const int pulses_per_litre = 2000;
int count_pulse;

void setup()
{
    Serial.begin(9600);
    pinMode(pin, INPUT);
    attachInterrupt(0, count_pulse, RISING);

}

void loop()
{
    pulse=0;
    interrupts();
    delay(1000);
    noInterrupts();

    Serial.print("Pulses per second: ");
    Serial.println(pulse);

    flow_rate = pulse * 1000/pulses_per_litre; //

    Serial.print("FUEL FLOW rate: ");
    Serial.print(flow_rate);
    Serial.println(" milliliters per second");

    volume = volume + flow_rate * 0.1; //Time Interval is 0.1 second

    Serial.print("Volume: ");
    Serial.print(volume);
    Serial.println(" milliliters");
}

void count_pulse()
{
pulse++;}

You have a int count_pulse and a function count_pulse, that confuses the compiler.

and add forward declaration line void count_pulse(); before setup()

@Juraj Doesn't the Arduino IDE do that for you?

there is some problem for function as parameter

You have declared count_pulse as a variable and NOT as function prototype.
int pin = 2;
volatile unsigned int pulse;
float volume = 0;
float flow_rate =0;
const int pulses_per_litre = 2000;

void count_pulse(); \\ <--- Function prototype

void setup()
{
    Serial.begin(9600);
    pinMode(pin, INPUT);
    attachInterrupt(0, count_pulse, RISING);
}

Just initialize pulse to zero in its definition at line 2.
The message "'pulse': used without being explicitly initialized" is due to the count_pulse() function: The compiler can't analyze the run-time behavior of the code, nor your intentions. Some interrupts could arrive before loop() runs, so in fact, pulse could very well get incremented without having been initialized. You may not care about and can discard the first few readings, but the compiler doesn't (and shouldn't!) guess that.

source: Stack Exchange

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

sort: votes


text:
How to use a potentiometer to access data within a 2 dimensional array?
I'm trying to create a 2D array of notes that are split into 3 scales. There are 3 notes in each scale. There are 3 buttons to play each note and I want to use an available potentiometer to select each of the scales to be played.
Despite my searching I cannot understand how to achieve this correctly. So far this is what I have.
Using an Arduino Uno:
// musical notes
int C = 1046;
int D = 1175;
int E = 1319;
int F = 1397;
int G = 1598;
int A = 1760;
int B = 1976;
int C1 = 2093;
int D1 = 2349;

const int numScales = 3;
const int numNotesPerScale = 3;

const int  notes[numScales][numNotesPerScale] = {
  {C, D, E},
  {F, G, A},
  {B, C1, D1}
};

const int numberOfButtons = 3;
int buttonPin[numberOfButtons] = {2, 7, 4};
//int notes[numberOfButtons] = {C, D, E};
int ledPin[numberOfButtons] = {11, 10, 9};

int buttonState = 0;         // variable for reading the pushbutton status
int speaker = 3;                 // name of the speaker key

void setup() {

  for (int i = 0; i < numberOfButtons; i++) {
    pinMode(buttonPin[i], INPUT);
    pinMode(ledPin[i], OUTPUT);
  }
  pinMode(speaker, OUTPUT);     // set speaker to be an output
}

void loop() {
  int numScales = map(analogRead(A2), 0, 1023, 0, 2);
  //int numScales = analogRead(A2 / 341);

  for (int i = 0; i < numberOfButtons; i++) {
    checkButton(buttonPin[i], notes[i], ledPin[i]);
  }
}

void checkButton(int buttonPin, int note, int ledPin)
{
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH){
    digitalWrite(ledPin, HIGH);
    tone(speaker, note);                 // play the note
    delay(100);                       // wait for 1/10th of a second
  }  } else {
    digitalWrite(ledPin, LOW);
    noTone(speaker);                  // stop playing the note
  }
}

what is it that you are unable to understand? ... create 2d array, read button status, read pot position, or something else? ... you need to determine what is the actual problem ... nobody can help you until you know what you need help with

I think my pot is not being recognised and that my 2d array is being accessed like a single array instead. This is why I'm not getting any true sequence of notes. My question is how should I take "int numScales = map(analogRead(A2), 0, 1023, 0, 2);" and use it to access the scales?

Using the Arduino map() function seems a reasonable approach to this, however you have a problem with the indexing.
if (numScales == 3); {

Is probably not what you want, as that condition can never be true since you set it to something in the range of 0-2 before you reach this check.
Considering only the relevant dimension, you a 3-element array, which will have legal elements numbers 0, 1, and 2
You call map(analogRead(A2), 0, 1023, 0, 2); which can produce an output in the range of 0-2, so far so good.
But then check for a value 3 which is not only illegal as in index to a 3-element array, but unable to be produced by your code.
Additionally you should probably stop trying to use the numScales variable to do double duty holding both the initial size and later also the current index.  And you should probably pass that as an argument, rather than make it a global variable.
You are also failing to ever use the current scale as an index into the notes array.  The syntax of double array indexing would be notes[x][y] but of course this should only be done with indicies to elements that exist.
It would probably also be a good idea to add some debug output of the internal logic, for example print both the raw ADC reading and the result of mapping that to the selected "scale".

I'm afraid being crap at programming isn't really allowing me to absorb some of these answers correctly. If I remove "int numScales = map(analogRead(A2), 0, 1023, 0, 2);" and uncomment "//int notes[numberOfButtons] = {C, D, E};" then each button will play a C, D or E. This works fine until my decision to add a way of changing scales. Is a 2d array the best way to do this and is this a very difficult issue?

A 2d array isn't unreasonable, use the indexing syntax given in this post and make sure your indicies are legal though.  Maybe first make a version which print out the indicies it would use, but doesn't actually use them.  Experiment with your buttons and knob and see that what it would do is reasonable.  Then add making it actually do it.

You could also flatten an array[x][y] to something like array[x+(3*y)]

The mere mention of reasonableness scares me!!!!

How do I add my updated code for analysis and further comment please?

// musical notes
int C = 1046;
int D = 1175;
int E = 1319;
int F = 1397;
int G = 1598;
int A = 1760;
int B = 1976;
int C1 = 2093;
int D1 = 2349;

const int columns = 3;
const int scales = 3;
int potVal = 0;
const int  notes[scales][columns] = {
  {C, D, E},
  {F, G, A},
  {B, C1, D1}
};

const int numberOfButtons = 3;
int buttonPin[numberOfButtons] = {2, 7, 4};
int ledPin[numberOfButtons] = {11, 10, 9};

int buttonState = 0;         // variable for reading the pushbutton status
int speaker = 3;                 // name of the speaker key

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

  for (int i = 0; i < numberOfButtons; i++) {
    pinMode(buttonPin[i], INPUT);
    pinMode(ledPin[i], OUTPUT);
  }
  pinMode(speaker, OUTPUT);     // set speaker to be an output
}

void loop() {
  int potVal = map(analogRead(A2), 0, 1024, 0, 3);
  Serial.println(notes[2][2]);
  for (int i = 0; i < numberOfButtons; i++) {
    //checkButton(buttonPin[i], notes[scales][columns], ledPin[i]);
    checkButton(potVal,i);
  }
}

void checkButton(int scaleNum, int buttonNum)
{
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin[buttonNum]);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    digitalWrite(ledPin[buttonNum], HIGH);
    tone(speaker, notes[scaleNum][buttonNum]);                 // play the     note
    delay(100);                       // wait for 1/10th of a second
  } else {
    digitalWrite(ledPin[buttonNum], LOW);
    noTone(speaker);                  // stop playing the note
  }
}

Ok, thank you everyone for your help! Here is the completed and functioning code for anyone that may find it useful. Why is it so hard to upload code on this site?

This code is incorrect.  As previously explained, 3 is not a legal index into a 3 element array.  You must return the maximum of your map function to 2 as it was before, not 3.

Sorry Chris, I keep getting stick for that one but it was pointed out to me recently that doing this creates an even spread across the pot range and in actual fact never produces a value of 3. I had it the old way mapped to 2 using a maximum of 1023 and it creates problems because 1 extends almost right to the end of the pots range and keeps alternating with 2 so no stability. ......."1023/1024 is 2.9999 something and so gets rounded down to 2. Mapping to 0 to 2 would mean that only the very last position would map to 2".

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


text:
Is it possible to start audio playback when headphones gets plugged in?
I want to have 6 audio jacks IN waiting for connection to start some WAV/OGG playback as soon as a headphone plugs in. In fact, I'd like to have simultaneous playback in 6 lines.
I've seen in the market some stuff that you can add buttons to different actions (play, pause, stop, etc). So far I believe this might be possible and affordable with Adafruit's Audio FX (which are stand-alone, Arduino-programmable WAV/OGG decoder circuits).
But,

Is it possible to start audio playback when headphones gets plugged
  in? HOW?

Is that an event? like pressing a button?
Does it need some "hacking" between GND lines maybe?

You can detect when a headphone is plugged in because the connector closes a switch within the body of the audio jack when its fully plugged in (assuming you're using a 3.5mm jack). If you have a function for starting playback, you can call it as soon as the MCU detects the switch has been closed.

@TisteAndii - You should turn your comment into an answer... I'd give it an upvote :-)

@Greenonline thanks...was waiting for some feedback from the OP to know if its what they want

@TisteAndii - I would think that it is the best [only?] and most obvious way to go... it was the first thing that came to my mind, when I saw the question.

A lot of 3.5mm jacks come with built-in normally-closed contacts, and their state can be tested through the pins of the jack with a multimeter or sensed by your MCU like any other switch. There are usually 2 pins each for the ring (pins 2 and 4 below) and the tip (pins 3 and 5), each pair connected to the other and one pin for the sleeve. The insertion of the headphones' connector breaks the connection between each pair, so that only one pin of each pair is actually connected to the connector's tip and ring.

You can connect the tip (pin 3) of each jack to digital input pins and connect the other pin of the pair (pin 5) to Vcc; you only need to read the tip because if the tip contacts are closed, it means nothing is fully plugged in yet. When no connector is plugged in, input pin reads HIGH from the tip since it is connected to Vcc through pin 5. When the headphones are plugged in, it breaks the 3-5 connection, and the tip now floats. Its voltage is indeterminate; it will probably sit somewhere near the middle of the 0-5V range, but we can't be sure.
To remedy this, there are 2 possible approaches I can see:

You use an analog input pin, instead of a digital pin. This way, you can read the very voltage at the tip; if its ADC value is above 900 perhaps, you can conclude that its HIGH and therefore nothing is plugged in, whereas if its below 600, you can conclude that the tip is floating and a headphone is plugged in. However, this method will require an input pin per headphone. The Uno has 6 analog pins, so this will take up all of them. If you aren't already using any of them, this method may be good enough. You could also use an analog GPIO expander.
You can use a digital input pin for the tip (pin 3) but instead of pulling pin 5 to Vcc, you connect it to a digital output pin. You can connect the pin 5 of each headphone set to this common output pin. To test if a particular jack has headphones plugged into it, you read the associated input pin and check if this is the same as the current value of the common output pin (saved to some variable). If it is, you toggle the output pin and again check the input pin to see if it mirrors the new value of the output pin; just additional confirmation. If everything checks out, then nothing is connected to the jack yet. If either test fails, you can reasonably conclude that headphones are plugged in.

Now that you know headphones are plugged in, you can call the appropriate function to begin playback through the right jack. Of course, all this assumes you'll be working with the jacks directly and not through some module. If you use the Adafruit Soundboard, you can check out the L (Left Channel) pin, which corresponds to the tip. I don't know if it's actually connected to the jack so you'll have to experiment and find out.

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


text:
Arduino onboard LED pin number as a constant
To use the onboard LED on an Arduino one usually has to know the pin number (13 in most cases), but is there a constant in the Arduino IDE one can use as well?
So is it possible to use something like int LED = ONBOARDLED; instead of using int LED = 13;?

#define LED_BUILTIN 13

(source)

Try LED_BUILTIN:
pins_arduino.h:static const uint8_t LED_BUILTIN = 13;

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


text:
A good water flow meter to monitor home usage with Arduino
I'm searching for a good water flow meter to add to my home controller project with Arduino. I have been searching in several pages and I only found some devices that work for low flow.  I need to control the water usage in my home and I thought to add a flow meter at the point where the water enters my home, and view the data with Arduino.
Do you have experience with any flow meter with good quality?

Don't you have a water meter in your house. These units can be read quite easily. Some have a rotating magnets, or like mine, a rotating dial with a large reflective surface.

I have, but not in my house. I'm living in a flat and flow meters they are in a room  that I don't have access easy.

I have a similar situation with my power meter not being in my apartment. I have an Arduino running on batteries, and sending the data wireless to an arduino in my apartment. If this isn't possible, I'd just buy a second water meter, similar to the one outside your apartment. Those units are made exactly for your purpose. I wouldn't want to risk having a water leak.

It would help to know more about the meter that you need – can you tell us the size of the pipe going into your flat where you would attach the meter and give us a rough idea of the flow rate that you need?

I don't know how is the size of pipe, but I think that it isn't too significant. I always can buy an adapter. But the most important, the flow rate, well, I don't know how to size this. This is a normal house, we have only a bathroom.
I found a project in the net in which  some guys uses this flow meter: Koolance INS-FM17N. His flow rate range is 1.0-15LPM. I think that 15 litres per minutes is quite and enough, but i don't sure. What do you think?

I've not used anything like it, but maybe http://forum.thethingsnetwork.org/t/smart-water-measurement/160 can give some ideas (and if it does, then I guess you'll know what to quote here as an answer). Success!

I've used an arduino with an irrigation flow meter.
I think I'm getting accurate results, but I haven't checked against a bill. It can handle high flow, and the sensors will attach to any size pvc line. The sensor are a bit expensive, however. $150 for the sensor and $35 for the T junction that it plugs into.
However, as you are living in an apartment, you'll probably need a non-invasive sensor. Perhaps an acoustic one.


text:
NTP Client Library. Set sync provider pointing to public class function. Possible?
I am trying to develop a NTP client library for ESP8266/Arduino to make adding NTP sync an easier task.
Basically, I've thought about a constructor as NTPClient(String host, int interval); and a NTPClient.begin() function to register sync function.
My problem is with that registering.
I have a public function: time_t ntpClient::getNtpTime() that connects to NTP server, decodes the response and returns a time_t variable.
Then, inside boolean ntpClient::begin() function I try to run setSyncProvider(ntpClient::getNtpTime). I've also tried to use setSyncProvider(this->getNtpTime).
I get a compile error here:
ntpClient.cpp:In member function 'boolean ntpClient::begin()
ntpClient.cpp:79:39: error: cannot convert 'ntpClient::getNtpTime' from type 'time_t (ntpClient::)() {aka long int (ntpClient::)()}' to type 'getExternalTime {aka long int (*)()}
  setSyncProvider(ntpClient*:getNtpTime)
Error compiling project sources

What could I do to allow registering this function as sync provider to hide NTP internals to my sketches?

Perhaps you should show us your code...?

What could I do to allow registering this function as sync provider to hide NTP internals to my sketches?

The function should be a static member function. A "normal" member function does not have the right prototype as there is a hidden parameter ("this").
static time_t getNtpTime();

To solve this you need a single-ton (an instance of the client class) that the static function can use.
class NTPClient {
public:
   NTPClient() ...
   {
     ...
     s_client = this;
   }
   time_t getNtpTime();
   ...
   static time_t getNtpTime() ( return (s_client->getNtpTime()); }
   ...
protected:
   static NTPClient* s_client;
   ...
};
...
NTPClient::s_client = NULL;
...
NTPClient ntpClient;
...
setSyncProvider(NTPClient::getNtpTime)

Alternatively a global function and a known instance:
class NTPClient { ... };
extern NTPClient ntpClient;
...
time_t getNtpTime() { return (ntpClient.getNtpTime()); }
...
setSyncProvider(getNtpTime)

Cheers!

It was that, thank you. I've tried to change getNtpTime() to static but doing that makes impossible to access variables and non static funcions. So, the only possibility I see is adding a static funcion in main program that wraps a non static ntpClient.getNtpTime().  I'm not an expert C++ programmer at all. Do you think there is any other possibility? I'll upload my code to github and publish here the link.

That is what the last line was all about. You need an instance that the static member function may use. For instance, add a static ntpClient pointer to the class and assign it in the constructor. The static member function can then use that to call the implementation.

I've uploaded my code to https://github.com/gmag11/NtpClient. I'll check the link about single-ton design pattern.

Please see the update code example above. Cheers!

I got it working finally. I've done sync provider registering in setup() function. I will try to add a begin member function in a later moment. Last version is on GitHub. Thank you for your recommendation about singleton.

Great! Here is a link to my own implementation of NTP for Cosa. It uses a Socket interface so there is no need to implement it again for WiFi or other IP devices as long as the device driver implements the Socket interface. https://github.com/mikaelpatel/Cosa-NTP. Please note that it does not implement clock synchronization. That would be done by the Cosa Clock class.


text:
Issues with a basic circuit
I am having some issues with a simple circuit. I would expect this circuit to light up this LED constantly when the Arduino is plugged in. I have the Blink tutorial sketch loaded, but I don't think that should matter with the pins I am using.
This is what I think I have going on: Arduino 5V Power --> BB power --> 100 Ohm resistor --> BB line 25 --> this LED --> BB line 30 --> BB Ground --> Arduino Ground
Please check out this picture for confirmation:

Thanks in advance for any help that you can provide!

How is the Arduino powered?

Powered by USB.

If the Arduino is powered, then the LED should either always be lit since it is always between 5V and GND, or never if it was mounted reverse (that is not visible in the picture you posted). It won't ever blink if you wire it this way!

The long leg of the LED is on the positive side - the left. Your first comment made me go back to the Uno spec and I read: "The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable." So maybe that is my issue since USB is only 5V.

No, USB is fine for Arduino. The problem is that you did not connect your LED to a digital output of Arduino. Please take a careful look at the circuit in the blink tutorial you referred to.

Figured it out - stupid mistake as expected. The power and ground lines on my bread board don't go all the way across. They break right in the middle, as the lines show. I moved my ground connection to the left a few slots and it worked. Thanks for working through it with me jfpoilpret!

How couldn't I figure that one first? I have been bitten by the same stupid mistake on a few occasions already :-) That's why I have put staples to connect halves of power lines of all my breadboards now! Staples work great for that.

Don't feel bad, we've all made this mistake more than once. I like the staples idea!

What I usually do is just place jumpers to connect the two sides of the power/ground rails. This way they're connected by default and if I need to separate them, I can just remove that wire.


text:
Frequency will not change
I am working on a project where I am trying to get an input signal filtered according to its frequency. I checked the signal before it went into my DSP algorithm to see where the problem was and I found that the frequency was remaining the same no matter if I put in 30Hz 120Hz or 58kHz. This leads me to think I have a problem with the sampling rate. Does that sound like it is the actual issue? Or am I barking up the wrong tree?
I was just using the readADC command to read in the data
void setup()          //Setup Function to intialise ADC and Serial Communication
{
DDRC=0x00;            //PORTC as INPUT
DDRD=0xFF;            //PORTD is OUTPUT
DDRD=0xFF;
for(i=0;i<N;i++)
  {
    InitADC();
    a=ReadADC(4);
    x[i]=a;
  }
  Serial.begin(9600);
}

How exactly are you sampling the signal? It would help if you can show the circuit and source code.

post your entire code

Could you trim down your program to a short program that demonstrates the issue, and then post the complete program? I see you posted a "setup()" routine, but a complete Arduino program also has a "loop()" routine.

I am not sure how you are sampling the frequency because you have not shown us your code.
At work we use a ATMega328P to sample frequency. This is done in 2 different ways:

We use the pin that counts (using an internal counter) every time it transitions (ie from low to high and from high to low). After 1 second that counter is read and then that counter is cleared. With the number read in, it is divided by 2 to get the frequency.
We use another pin that counts every time it transitions from low to high. From memory the counter is not very large so we count the number of times it overflows. When the 1 second interrupt fires we multiply out the number of overflows by the counters capacity. Lastly the remainder from the counter is added to the result to get the frequency. Again the counter is cleared.

The above examples use the AVR's internal counters. A less efficient way of getting the frequency is to have an interrupt to count the number of times a pin changes. Again this can be read and reset at one second intervals. This slows the overall execution of the program down when very high frequencies ( > 40K Hz) are being presented on the input.


text:
How to count the time until the next day of the week?
I wants to do in Arduino countdown that shows how many days, hours and minutes remaining to Friday 12:00.
In my program I used a function in php strtotime('next friday') which thus could calculate differential timestamp and show how much time is left until Friday 12:00.
Is there a function strtotime('next friday') in Arduino?
I have RTC which gives me just the current date and time, but does not show the current day of the week.
EDIT:
I have a solution
We have day of week. We multiplied by 86400.
We have an hour. We multiply by 3600.
We have a minute. We multiplied by 60.
Add everything.
Subtract this from 604800.
nextFriday  = 604800-((dayofweek * 86400)+(now.hour()*3600)+(now.minute()*60)+now.second());
Important, Friday is the number of the week "0". Friday = 0; Saturday = 1; etc...

Mosts RTCs have a dayOfWeek field.

In C/C++ it is strtotime("next friday") - note the double quotes. Single quotes do something quite different.

The key to working with time is to have a known "base" time to calculate everything relative to.  This is called the epoch.  Different systems use different epochs, and each has advantages and disadvantages.
I generally use the UNIX epoch in my programming (chiefly because I am a UNIX nut), which is the first of January, 1970 (01/01/1970).  This is year, month, day, hour, minute and second 0.
From that you can then calculate the number of seconds between the epoch and any other time you choose as long as it is later than the epoch.
To calculate the day of the week for any given date you first need to know the day of the week for the epoch (for UNIX that's a Thursday) then work out how many days there are between the epoch and the target time.
Calculating real times in terms of seconds can be somewhat tricky due to leap years and daylight savings, but there are plenty of algorithms in the public domain, and many RTC libraries include functions to convert to/from epoch times.
For instance, the Arduino Time Library has functions to calculate weekdays, and to convert to "time_t" format (seconds since epoch) which can be used to work out differences in times.  For instance, if you know that it's Tuesday and you want next Friday then you know that Friday is 3 days in the future - so you can get the current time in seconds from the epoch then add to that 3 days' worth of seconds (3 × 60 × 60 × 24) to that time to get the same time of day next Friday.

There are generic examples, e.g. Determination of the day of the week - Wikipedia.

In the C language expressions below, y, m and d are, respectively, integer variables representing the year (e.g., 1988), month (1-12) and day of the month (1-31).

        (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7

Also see StackOverflow - C Program to find day of week given date.


text:
Can't upload to arduino boards anymore
I have been working on several projects recently an made hundreds of uploads to several different boards.  I haven't had any issues to speak of.  Now I cannot upload. I have tried:

Disconnect all inputs and output from analog a digital ports - This is a board, nothing connected except USB.
Changing cables
Changing USB ports on my computer
Using a brand new out of the box Arduino Uno
Using example sketches, and even BareMinimum
Serial Loopback test - FAILED
Updating the driver with the one from the arduino folder
Using an unsigned driver
Manually setting the windows driver speed, parity, etc.
Uninstalling and re-installed Arduino IDE
Rolling back the board manager for AVR boards to 1.20 and 1.19
Change programmer to AVR ISP

Here is the output:
Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xc7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xc7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xc7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xc7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xc7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xc7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xc7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xc7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xc7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xc7
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Here is the verbose output:
Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
C:\Users\kanan\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/bin/avrdude -CC:\Users\kanan\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf -v -patmega328p -carduino -PCOM5 -b115200 -D -Uflash:w:C:\Users\kanan\AppData\Local\Temp\arduino_build_835373/BareMinimum.ino.hex:i

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\kanan\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xd5
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xd5
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xd5
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xd5
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xd5
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xd5
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xd5
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xd5
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xd5
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xd5

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I am not attempting to install the beta version of the arduino ide, but I am not betting this will work.
I feel like I have tried everything that is reasonable, and more than most people would think to try, what am I missing?
-------------  UPDATES --------------
I have now moved away from the arduino IDE and am working directly with avrdude.  Still no luck.  Running:
avrdude.exe -p m328p -c arduino -P COM6

fails.
I also tried it on my Fedora 27 box.  Here is dmesg output:
[349004.632101] usb 2-1.5: new full-speed USB device number 5 using ehci-pci
[349004.711497] usb 2-1.5: New USB device found, idVendor=1a86, idProduct=7523
[349004.711503] usb 2-1.5: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[349004.711507] usb 2-1.5: Product: USB2.0-Serial
[349004.713405] ch341 2-1.5:1.0: ch341-uart converter detected
[349004.714652] usb 2-1.5: ch341-uart converter now attached to ttyUSB0

then I ran this:
$ dmesg | grep tty

And got this:
[    0.000000] console [tty0] enabled
[    0.781927] 00:06: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[   14.034377] usb 2-1.5: ch341-uart converter now attached to ttyUSB0

I then run this:
$ avrdude -p m328p -c arduino -P /dev/ttyS0

and get this:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

avrdude done.  Thank you.

At this point I also tried
$ avrdude -p m328p -c arduino -P /dev/ttyUSB0

Same result.  At this point it seems to me I have a few fried arduinos.  They were fine yesterday, but today, they're toast.  Three computers, three cables, three arduinos, all the same result.
So, from here.  Has anyone heard of a bad cable frying an arduino?

You've tried swapping everything I can think of. Does "Using a brand new out of the box Arduino Uno" mean you've swapped that too? And if not, can you? When you swapped ports, did you correct the port-assignment in Tools | Port? "Change programmer to AVR ISP" - ? this is what it should be if you're trying to program via USB cable.

You can't upload the blink sketch too?

did you try a different computer?

Interestingly I did try a different computer, with a different cable and the new mega I had just opened.  Strangely, I got the same error.  I'm feeling a bit cursed at the moment.

test on the other computer with Arduino IDE. on Windows make sure that CH340 driver is installed (your linux outputs indicate CH340). on linux make sure you are in dialout group

I'm an idiot.
I should have looked more carefully.
Because I have used these boards so extensively, I figured that I knew the dip switches by heart.  Everything started to go wrong when I got confused switching from the Uno to the ESP.
Here is the reference from https://robotdyn.com/uno-wifi-r3-atmega328p-esp8266-32mb-flash-usb-ttl-ch340g-micro-usb.html:

Meaning this DIP switch pattern is for the ESP:
And This is for the UNO:

THANK YOU ALL FOR THE TIME AND EFFORT YOU PUT IN TRYING TO HELP ME!!!
tldr: Check your DIP switches.

add to tl;dr: mention DIP switches in OP...

Touché my friend

Since your USB ports likely work for other things (like your keyboard) and you have tried several arduinos, cables etc, now try Knoppix - it has both Arduino IDE (not the most recent version) and avrdude.
https://unetbootin.github.io or
https://www.pendrivelinux.com/install-knoppix-6-to-a-usb-flash-drive-in-windows
and
http://www.knopper.net/knoppix-mirrors/index-en.html
If it does not work, have a look through the boot log, or more quickly dmesg after plugging your arduino in and trying an upload.
Worth noting: the 328p target is not correct for mega, use e.g.: avrdude -vv -p atmega2560 -b115200 -c wiring -P COM3 or avrdude -vv -p atmega2560 -c wiring -P /dev/ttyUSB0. Omitting -b115200 should be no problem with the mega. Try this before torturing yourself further...
If you still get errors, and have not fiddled with clockspeed or anything else, it will be very strange indeed.

I actually have Fedora box here, let me try it on there.

@Beachhouse What if you connect using putty/minicom and punch in a string of characters? Does the RX led blink? Is it a different PC? Have you tried burning a fresh bootloader to the arduino? Have you played with the fuses? Have you tried manual reset of the board just before upload?

If you have an FTDI chip, try setting it to 5V (3V3 works for me on 5V boards, though), and connect RX to TX, TX to RX. Then press reset before upload.

@Beachhouse Don’t use 328p target with avrdude; use atmega2560. See my edited answer.

Scratch my last comment.  TX does blink when I send data from serial monitor. @user2497 I saw your comment, I had been adjusting the chip for the direct commands, but thank you.

@Beachhouse So you use a mega2560, and not a 328p target?

Correct.  Ran: avrdud -vv -p atmega2560 -b115200 -c arduino -P COM5 and got: avrdude.exe: stk500_getsync(): not in sync: resp=0x00

@Beachhouse That’s weird. Have no idea, then... apart from the clockspeed being off... try 12MHz in arduino-mk project Makefile, if it’s a clone. What is engraved on the crystal on the board? 16.000 or something else?

it is a clone.  https://robotdyn.com/uno-wifi-r3-atmega328p-esp8266-32mb-flash-usb-ttl-ch340g-micro-usb.html

@Beachhouse All bought at the same time? What is engraved on the crystal container?


text:
GPS Module Outputting Question Marks in Serial Window
I've got a uBlox Neo 7N GPS Module and configured it so if theres is no incoming data print no location but if there is print the latitude and longitude. However it's printing ?,?.
So I'm assuming it's wired correctly as I'm getting an output however maybe my code is preventing it from printing the two long numbers hence converting it to a ? instead.
  char buf[128];
  if (gps.location.isValid()) {
    snprintf(buf, sizeof(buf), "%lf,%lf", gps.location.lat(), gps.location.lng());
    Serial.println(buf);
  }

EDIT I know that Im getting a read as I set two variables of type double lat and long to equal gps.location.lat() and gps.location.lng() respectively and I'm getting a number. How do I fix up this snprintf line so it prints properly?

When arduino boards used the atmega8, there was so little memory they decided to take out the floating point support for s(n)printf. Instead of letting the users decide to use sprintf or not, they just took it out. That caused a lot of troubles. In 2018 it is still not there, which is outrageous. Sorry that you bumped into this problem. You have to make a workaround. It can be cast to a unsigned long or the dstrtof function can be used and the Serial.println itself supports float variables. The uno does not support 64 bit double, only 32 bit float variables.

Oh wow, well that makes sense. Thank you for replying, will try your recommendation!

Oops, it is "dtostrf".

I would try adjusting the baud rate your arduino or MCU is reading the GPS data stream at.  My guess is that the stream is being misinterpreted.

No floating point for sprintf, it prints a '?'.
The functions sprintf, sscanf and the alike functions (snprintf and others) do not have floating point support for avr microcontrollers.
History
One of the first Arduino boards used the Atmega8 microcontroller with only 8k flash and 1k sram. It was important to be very memory efficient.
The gcc compiler did not automatically include the floating point support libraries for the sprintf functions, however it was easy to include them. Arduino decided not to include those extra libraries because they use extra memory.
Arduino has a preprocessor, compiler and linker that tries to only use code that is actually used. The sprintf does not know at compile time if floating point will be used, so it would have to include those extra floating point support libraries whether they were used or not.
Now it is 2018 and it is sadly still not included.
Workaround

The Serial.println functions can print floating point variables. They can however not print the output in scientific notation. It rounds the value that is printed to the nearest number.
The dtostrf() and dtostre() convert a float variable to text. The dtostre() is for scientific notation.
A variable of the float type can be cast to a integer.
The Arduino String object can handle a float.

Only float for avr microcontrollers, no double.
The avr microcontrollers are 8-bit microcontrollers. There is no floating point library for 64-bit double variables, only a library for 32-bit float variables.
That library is according to the IEEE standard and is extremely fast and optimized.


text:
My verbose appears "unable to cache built core"
At early morning i have accidentally the error of GNOME for my OS, so I was forced reinstall my OS couse i don't have any backup for my packages and my database. i'm installed Arduino-IDE 1.8.7, Arduino AVR Boards 1.6.23 and Esp8266 Boards 2.4.2 . when i trying to upload my sketch, i get this error:
...
Unable to cache built core, please tell esp8266 maintainers to follow http://goo.gl/QdCUjo
...

I see the link, but i cannot see where my archive variable in platform file for my cores.
...
## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}"
...

See my verbose log !!!.
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/spiffs_api.cpp.o
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/spiffs_hal.cpp.o
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/time.c.o
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/uart.c.o
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/umm_malloc/umm_malloc.c.o
Unable to cache built core, please tell esp8266 maintainers to follow http://goo.gl/QdCUjo
Linking everything together...
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-gcc -CC -E -P -DVTABLES_IN_FLASH /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld/eagle.app.v6.common.ld.h -o /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld/eagle.app.v6.common.ld
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-gcc -Wl,-Map -Wl,/tmp/arduino_build_988288/tesHC139.ino.map -g -w -Os -nostdlib -Wl,--no-check-sections -u app_entry -u _printf_float -u _scanf_float -Wl,-static -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/lib -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/libc/xtensa-lx106-elf/lib -Teagle.flash.4m1m.ld -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read -o /tmp/arduino_build_988288/tesHC139.ino.elf -Wl,--start-group /tmp/arduino_build_988288/sketch/tesHC139.ino.cpp.o /tmp/arduino_build_988288/libraries/SPI/SPI.cpp.o /tmp/arduino_build_988288/libraries/Adafruit_BME280_Library-master/Adafruit_BME280.cpp.o /tmp/arduino_build_988288/libraries/Wire/Wire.cpp.o /tmp/arduino_build_988288/arduino.ar -lhal -lphy -lpp -lnet80211 -llwip2 -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc -Wl,--end-group -L/tmp/arduino_build_988288
/home/praz/.arduino15/packages/esp8266/tools/esptool/0.4.13/esptool -eo /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/bootloaders/eboot/eboot.elf -bo /tmp/arduino_build_988288/tesHC139.ino.bin -bm dio -bf 40 -bz 4M -bs .text -bp 4096 -ec -eo /tmp/arduino_build_988288/tesHC139.ino.elf -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
Using library SPI at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/SPI
Using library Adafruit_Sensor-master at version 1.0.2 in folder: /home/praz/Arduino/libraries/Adafruit_Sensor-master
Using library Adafruit_BME280_Library-master at version 1.0.7 in folder: /home/praz/Arduino/libraries/Adafruit_BME280_Library-master
Using library Wire at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/Wire
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-size -A /tmp/arduino_build_988288/tesHC139.ino.elf
Sketch uses 259408 bytes (24%) of program storage space. Maximum is 1044464 bytes.
Global variables use 28352 bytes (34%) of dynamic memory, leaving 53568 bytes for local variables. Maximum is 81920 bytes.
/home/praz/.arduino15/packages/esp8266/tools/esptool/0.4.13/esptool -vv -cd nodemcu -cb 115200 -cp /dev/ttyUSB0 -ca 0x00000 -cf /tmp/arduino_build_988288/tesHC139.ino.bin

I don't think so if i have permissions issue, it seems my boards is fine about my permissions.
total 388
drwxrwxr-x  8 praz praz   4096 Okt 11 00:14 ./
drwxrwxr-x  3 praz praz   4096 Okt 11 00:13 ../
-rw-rw-r--  1 praz praz 293575 Agu  3 14:19 boards.txt
drwxrwxr-x  3 praz praz   4096 Agu  3 14:19 bootloaders/
drwxrwxr-x  3 praz praz   4096 Agu  3 14:19 cores/
-rw-rw-r--  1 praz praz    235 Agu  3 14:19 .gitmodules
-rw-rw-r--  1 praz praz   2831 Agu  3 14:19 ISSUE_TEMPLATE.md
-rw-rw-r--  1 praz praz    553 Agu  3 14:19 keywords.txt
drwxrwxr-x 28 praz praz   4096 Agu  3 14:19 libraries/
-rw-rw-r--  1 praz praz  26529 Agu  3 14:19 LICENSE
-rw-rw-r--  1 praz praz    194 Agu  3 14:19 package.json
-rw-rw-r--  1 praz praz   6844 Agu  3 14:19 platform.txt
-rw-rw-r--  1 praz praz   7136 Agu  3 14:19 POLICY.md
-rw-rw-r--  1 praz praz      0 Agu  3 14:19 programmers.txt
-rw-rw-r--  1 praz praz   7722 Agu  3 14:19 README.md
drwxrwxr-x  4 praz praz   4096 Agu  3 14:19 tests/
drwxrwxr-x  3 praz praz   4096 Agu  3 14:19 tools/
drwxrwxr-x 25 praz praz   4096 Agu  3 14:19 variants/

Solved
I think when i installed Esp8266 Boards 2.4.2 latest version is fine, i uploaded my sketch and i cannot make cache to my built core, Majenko is right, my the snippet of config are difference between my 74hc139 issue and my verbose log issue.
when i installed fresh Esp8266 Boards using boards manager, that automatically downloads source code of esp8266 core on this Github, i don't understand why my snippet of config not updated like this commit. so i updated my config of boards with copy/paste on tree links of  Github, and that's works.
See my verbose below or see at this :
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/sqrt32.c.o
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/time.c.o
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/uart.c.o
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/umm_malloc/umm_malloc.c.o
Archiving built core (caching) in: /tmp/arduino_cache_39139/core/core_8e365e854c5bfceaa27f4c371ba290d0.a
Linking everything together...
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -CC -E -P -DVTABLES_IN_FLASH /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld/eagle.app.v6.common.ld.h -o /tmp/arduino_build_979295/local.eagle.app.v6.common.ld
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -Wl,-Map -Wl,/tmp/arduino_build_979295/tesHC139.ino.map -g -Wall -Wextra -Os -nostdlib -Wl,--no-check-sections -u app_entry -u _printf_float -u _scanf_float -Wl,-static -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/lib -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/libc/xtensa-lx106-elf/lib -Teagle.flash.4m.ld -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read -o /tmp/arduino_build_979295/tesHC139.ino.elf -Wl,--start-group /tmp/arduino_build_979295/sketch/tesHC139.ino.cpp.o /tmp/arduino_build_979295/libraries/SPI/SPI.cpp.o /tmp/arduino_build_979295/libraries/Adafruit_BME280_Library-master/Adafruit_BME280.cpp.o /tmp/arduino_build_979295/libraries/Wire/Wire.cpp.o /tmp/arduino_build_979295/core/core.a -lhal -lphy -lpp -lnet80211 -llwip2-536-feat -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc -Wl,--end-group -L/tmp/arduino_build_979295
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/esptool/esptool -eo /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/bootloaders/eboot/eboot.elf -bo /tmp/arduino_build_979295/tesHC139.ino.bin -bm dio -bf 40 -bz 4M -bs .text -bp 4096 -ec -eo /tmp/arduino_build_979295/tesHC139.ino.elf -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
Using library SPI at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/SPI
Using library Adafruit_Sensor-master at version 1.0.2 in folder: /home/praz/Arduino/libraries/Adafruit_Sensor-master
Using library Adafruit_BME280_Library-master at version 1.0.7 in folder: /home/praz/Arduino/libraries/Adafruit_BME280_Library-master
Using library Wire at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/Wire
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-size -A /tmp/arduino_build_979295/tesHC139.ino.elf
Sketch uses 265524 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 28236 bytes (34%) of dynamic memory, leaving 53684 bytes for local variables. Maximum is 81920 bytes.
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/esptool/esptool -vv -cd nodemcu -cb 115200 -cp /dev/ttyUSB0 -ca 0x00000 -cf /tmp/arduino_build_979295/tesHC139.ino.bin

Hope anyone can solve my issue, Thanks in advance.

turn on in Preferences the verbose output for console. you will see the path

@Juraj i turn on at my command line absolutely.

You may have some file permission errors in tour home directory. Check ownership.

Juraj i'm on my Ubuntu, Majenko i don't think so i have permissions issue.

Juraj Majenko see my verbose http://paste.ubuntu.com/p/2n6GVkgM3m/

The snippet of config you show doesn't match with what is currently in the Github repo for the ESP8266 core. Make sure you have the latest version of the core installed.

@Majenko you're right, i see my verbose on 74h138 chip issue and this verbose have difference xtensa tools, i just update my source code of tools.

This was fixed on the 20th August in this commit. Make sure you have the latest version of the ESP8266 core installed. If there hasn't been a release since that fix, you can pull the github version of the config file and use that instead of the one bundled with the core.
However, it's not a fatal error - it merely means that compilation will be slower than it should be.

Thanks, i think so, i found it too, i still editing before.


text:
How do I select Sensor using chip 74HC138 on Wemos D1 Mini?
I have a project for my graduate degree.
It's about Monitoring Temperature and Humidity using Message Queuing Telemetry Transport on Serial NodeJS. To get sensor data to Wemos D1 Mini and NodeJS had done, also on my MQTT had done. My lecturer wants to get data from two sensors at the edges of the room, he suggests using a 74HC138. I'm using this 74HC138 Datasheet and I'm using this BME280 Library.
This is my schematic:

This is my code:
#include <BME280.h>

const uint32_t SERIAL_SPEED = 115200;
const uint8_t SCK_PIN = D5;
const uint8_t MISO_PIN = D6;
const uint8_t MOSI_PIN = D7;
const uint8_t SPI_CS1_PIN = 15;
const uint8_t SPI_CS2_PIN = 14;
const uint8_t GPIO[3] = {D1, D2, D3};

static int32_t temperature, humidity, pressure;
int i;

BME280_Class   BME280;

void setup() {
  Serial.begin(SERIAL_SPEED);
  pinMode(SCK_PIN, OUTPUT);
  pinMode(MOSI_PIN, OUTPUT);
  pinMode(MISO_PIN, INPUT);

  SPI.begin();
  SPI.setBitOrder(LSBFIRST);

  Serial.println(F("condition before loop = "));
  //status_pin();
  for (i = 0; i < 3; i++) {
    pinMode(GPIO[i], INPUT);
    digitalWrite(GPIO[i], HIGH);
  }
  pinMode(SPI_CS1_PIN, OUTPUT);
  pinMode(SPI_CS2_PIN, OUTPUT);

  Serial.println(F("Starting Hardware SPIDemo example program for BME280"));
  Serial.print(F("- Initializing BME280 sensor\n"));

  if ( (!BME280.begin(SPI_CS1_PIN) && (!BME280.begin(SPI_CS2_PIN) ) {
    Serial.println(F("-  Unable to find BME280. Waiting 3 seconds."));
    delay(3000);
  }

  BME280.mode(SleepMode);
  Serial.print(F("- Sensor detected in operating mode \""));
  Serial.print(BME280.mode());
  Serial.println(F("\"."));
  if (BME280.mode() == 0) {
    Serial.print(F("- Turning sensor to normal mode, mode is now \""));
    Serial.print(BME280.mode(NormalMode));
    Serial.println("\"");
  }
  Serial.println(F("- Setting 16x oversampling for all sensors"));
  BME280.setOversampling(TemperatureSensor, Oversample16);
  BME280.setOversampling(HumiditySensor,   Oversample16);
  BME280.setOversampling(PressureSensor,   Oversample16);
  Serial.println(F("- Setting IIR filter to maximum value of 16 samples"));
  BME280.iirFilter(IIR16);
  Serial.println(F("- Setting time between measurements to 1 second"));
  BME280.inactiveTime(inactive1000ms);
  Serial.print(F("- Each measurement cycle will take "));
  Serial.print(BME280.measurementTime(MaximumMeasure) / 1000);
  Serial.println(F("ms.\n\n"));
}

void loop() {
  static uint8_t loopCounter = 0;
  byte pin1 = 0x74;
  byte pin2 = 0x71;

  if ( BME280.begin(SPI_CS1_PIN) == 1 ) {
    selpin(pin1);
    Serial.println(F(" Data Bme = "));
  } else if ( BME280.begin(SPI_CS2_PIN) == 1 ) {
    selpin(pin2);
    Serial.println(F(" Data Bme = "));
    printdata();
  }

  if (++loopCounter % 10 == 0) {
    Serial.print(F("\n- Turning "));
    if (BME280.getOversampling(HumiditySensor) == 0) {
      BME280.setOversampling(HumiditySensor, Oversample16);
      Serial.print(F("ON"));
    } else  {
      BME280.setOversampling(HumiditySensor, SensorOff);
      Serial.print(F("OFF"));
    }
    Serial.println(F(" humidity sensing"));
    Serial.print(F("- Each measurement cycle will now take "));
    Serial.print(BME280.measurementTime(MaximumMeasure) / 1000.0);
    Serial.println(F("ms.\n"));
  }

  Serial.println(F("condition after loop = "));
  //status_pin();
  Serial.println();

}

float altitude(const float seaLevel = 1013.25) {
  int32_t temp, hum, press;
  BME280.getSensorData(temp, hum, press);
  float Altitude = 44330.0 * (1.0 - pow(((float)press / 100.0) / seaLevel, 0.1903));
  return (Altitude);
}

void printdata () {
  BME280.getSensorData(temperature, humidity, pressure);
  Serial.print(F("Temperature : "));
  Serial.print(temperature / 100.0);
  Serial.println(F(" *C"));
  if (BME280.getOversampling(HumiditySensor) != 0) {
    Serial.print(F("Humidity : "));
    Serial.print(humidity / 100.0);
    Serial.println(F(" %"));
  }
  Serial.print(F("Pressure : "));
  Serial.print(pressure / 100.0);
  Serial.println(F(" hPa"));
  Serial.print(F("Altitude : "));
  Serial.print(altitude());
  Serial.println(F(" m"));
  Serial.println();
  delay(5000);
}

Serial output always says Unable to find BME280. Waiting 3 seconds. I know it's because CS pin cannot detect. I think something is missing my code.
SOLVED
Thanks to my pal @Majenko, I'm out of the 74HC138 stock but i have 74HC139, i think that's same to me, i tried advice from @Majenko early morning after i make assembly of my board own for define Chip Select Wemos to my enable pin and get back my missing code whom not understand me.
See below for verbose log of uploading my sketch.

See below for serial monitor.

Thanks.

Using a 74HC138 in this situation is both pointless and wasteful. You're using 3 pins (or 4 - see below) to drive a chip to select between 2 pins. That's wasting one more pin than you would by directly driving the CS pins.
The only time it would make sense would be if you were wanting to connect with 5 or more devices, in which case you would get a saving in the number of pins used.
Anyway - what you are missing from your code is absolutely everything to do with the 74HC138. First off, you're using a library which assumes the CS pins are directly connected to the MCU. Second, there is no code to set the A/B/C pins to the right state to select an output.
If you really must use the 74HC138 I would suggest:

Use the same CS pin in your code for every BMS280 instance.
Connect that CS pin to G2A on the 74HC138
Use the following procedure to access a sensor:

Select the correct output on the 74HC138 by setting the A/B/C pins to the binary representation of the output you want
Perform the BME280 operations you want on the relevant instance

simulate this circuit – Schematic created using CircuitLab
The CS pin you passed to the BME280 instances will control the state of the currently selected output on the 74HC138, turning it into a demultiplexer controlled by the A/B/C pins.  Using multiple instances of the BME280 class associated with each selected output will allow proper tracking of any internal state and data associated with the device connected to that output.
Or, and this is just throwing ideas out there, don't use the 74HC138 and tell your "lecturer" that it's a stupid idea to use 3 pins (4 including the chip select pin) to control a pair of devices that need a total of 2 pins.

i'm still little confuse sir, your mean "Connect that CS pin to Q2A on the 74HC138" i must connect CS to enable input pin and where i must connect Y1-Y2 output pin? where i can find example of send the binary representation to chip. i really noob about chip gate sir

Sorry, that's a G on your little picture, not a Q.  Looks the same to me.  You don't "send" the binary representation to the chip. You set your three pins connected to A/B/C to that binary representation. Output 0 is LOW/LOW/LOW.  Output 1 is HIGH/LOW/LOW. Output 2 is LOW/HIGH/LOW, Output 3 is HIGH/HIGH/LOW, etc.  Outputs go as they are now.

yes that's G, it's fine, ok i can see what do you mean on your picture, to set A/B/C pin what i must using pinMode or digitalWrite sir?

Both. pinMode to set them as outputs, and digitalWrite to set the logic levels.

hello again my pal, if my lecture want to set enable pin as low, which one i do declare CS pin to my 74hc139 sir? i didn't get option anything.

I don't understand what you're asking (language barrier).

sorry my bad, if my lecturer want to connect enable pin to gnd as active low, how i do connect cs pin in wemos to IC 74hc139 sir?

With a wire? I still don't understand what you want.

yes with a wire, if GA pin to GND pin as active low , how i do initialize CS pin in wemos to IC ?

The bme280 library should be doing all that for you

if i define D8 pin, where i must connect to 74hc138 in order to get data?

G2A as I have shown in my schematic.

if i connect D8 pin to G2A pin whether it is active low

G2A and G2B are active low. G1 is active high. All three need to be active for the chip to operate.

is it D8 pin becomes active low?

Outputs don't have a concept of "active", only a currently selected level. If you use D8 in the begin function to a BME280 object then the BME280 code will drive it low for you when it needs to.

if i connect G2A pin to GND pin as active low, how i use D8 pin to make the begin function?

The wemos connects it to ground for you. You don't connect it to ground. D8, when low, connects the pin to ground.

i see now, a voted for you!!


text:
How fast is an Arduino?
Can an Arduino Uno calculate the time that an assembly instruction will take in nanoseconds, not microseconds? I don't want to use a PC, because the calculation will be more accurate using an Arduino, as the processor won't be running other tasks.
If the Arduino can't, is there any way to improve it, or any other open source hardware that can do?

Hardware timers might help

I just want to know how much time (in nanosecond example: 14 microsecond and 145 nanosecond ) it'll take for a CMP instruction comparing 2 strings, because in theory it will take less time if the two strings doesn't match.

You can set up a hardware timer (eg. Timer 1) with a prescaler of one, so that each "tick" counts one clock cycle. Thus it can time to a resolution of 62.5 ns if running at 16 MHz.
Then you could read the timer, do your target instruction (eg. compare two strings) and then read the timer again. The difference in counts will be the time (in units of 62.5 ns).
I have a page about timers which might help you get started.

... calculate the time that an assembly instruction will take ...

Generally speaking the C++ compiler does a good job of generating code. You won't necessarily make things faster by writing in assembler and you might make it slower, because compiler-writers know various tricks which you might not.

How fast is an Arduino?

Arduino Uno is based on AVR MCU and run at 16 MHz. Due to the processor architecture it can execute almost 1 instruction per clock cycles (62.5 ns). It uses a simple two step pipeline which may require restart if a branch is taken. There are some instructions such as memory access that take more than one clock cycle.

Can an Arduino Uno calculate the time that an assembly instruction will take in nanoseconds, not microseconds?

It is possible to measure the execution time with a resolution of 4 us with micros(). Please describe what you want to calculate/measure.
For more details on ATmega328p please see the data-sheet, chap. 6.6 Instruction Execution Timing.

i just want to know how much time (in nanosecond example: 14 microsecond and 145 nanosecond ) it'll take for a CMP instruction comparing 2 strings, because in theory it will take less time if the two strings doesn't match.
thank you

Could you provide a list of some functions that you would like to know the execution time for? With the assemble listing for the functions (written in C/C++ I assume), the number of clock cycles per instruction, and the clock frequency it is possible to calculate the execution time accurately given specific parameters e.g. to explicit strings.

Here are some benchmarks that might help answer your question(s): http://www.nongnu.org/avr-libc/user-manual/benchmarks.html

If you're asking "can an AVR measure how long it works on a task" then the answer is yes, but I don't think that's what you're looking for.
If you're asking "can I craft a program that takes a specific amount of time to run" then the answer is also yes. The trick is to look in the datasheet or in the AVR Assembly Instruction manual to see how long each instruction takes in cycles and then multiply that by the MCU's clock period.


text:
What Arduino data type allows decimals?
This probably sounds dumb, but I am not getting any clear answer for this. What data type allows a reasonable amount of decimals?

What does "reasonable" mean?

At least 2 or 3, just the type smallest amount above this so I can save processing power on my Trinket board

You can use a float but you might also consider multiplying your values by as scale factor in order to use integer arithmetic which will be much more efficient if you do not need a wider range.

If you need to represent numbers that are not integers, the simplest
solution is to use floating point variables, also known as “floats”. A
float is declared with the float keyword. A numeric constant is
automatically a float if it has a decimal point :

42 is an integer (int type)
42.0 is a float

If you combine an int and a float in an arithmetic operation, the int is
implicitly promoted to float, and the result is a float.
A float gives you a precision of 24 significant bits. “Significant”
means that we are counting both the bits before and after the binary
point. Then, a small number will have many fractional bits, whereas a
large number will have only a few, and any number larger than
223 = 8388608 will have no fractional bits at all.
This precision is almost always better that 7 significant decimals and
worse than 8 significant decimals. For example, the following two
numbers are consecutive: any computation that yields a result in
between them will be rounded to either of them (usually the closest):
    binary (24 bits)          decimal
101010.000000000000000000  42.0
101010.000000000000000001  42.000003814697265625

The issue with floats is that they are expensive. Unlike a desktop
computer, the Trinket has no hardware support for floats (it's an
ATtiny: it doesn't even have a hardware multiplier!). Then every
computation is done by software. Even the simplest things, like adding
two numbers, can take quite a few CPU cycles and a lot of flash space.
That's why on very small devices people sometimes prefer fixed point
arithmetic. In a nutshell, fixed point is all about choosing appropriate
units of measurement in order to achieve the required precision using
only integers. For example, the ADC converter in the Trinket gives you
the voltage readings in units of
5 V ÷ 1024 = 4.8828125 mV

That unit may seem unpractical, but it allows a reasonable precision
using only integers. If you can avoid converting to volts, you will be
able to write integer-only code which is smaller and faster.
I would suggest you first try using floats, as it's the simplest
solution. If that leads to code with is either too large or too slow,
then try to rewrite with fixed-point (i.e. integer only) arithmetic.

At least 2 or 3 [digits], just the type smallest amount above this so I can
  save processing power on my Trinket board

Processors (computers) do not normally store values in Binary Coded Decimal (BCD) (as in base 10) because such storage wast valuable space.  Rather, processors usually use Binary numbers (as in base 2).
Most processors deal with binary values in multiples of 8 bits.  So, values are usually represented by 8 bits, 16 bits, 32 bits, ect.  An 8 bit binary number can have 2^8 possible values or 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 or 256. That is to say, an 8 bit binary number can have values between 0 and 255 inclusive.
If your requirement of "reasonable amount of decimals" falls within that range, then the type you are looking for is "uint8_t" or "char".  Both are normally 8 bits in the C / C++ language.  If you need more the next binary number has 16 bits or 2^16 or values between 0 and 65535.  Then the type you are looking for is "uint16_t" or "unsigned int".

While the facts you state are mostly true, this does not address the question asked in any practical way.  As a result your final recommendations are wrong.  The questions concerns non-integers, so an integer type cannot, by itself be a solution, though as already mentioned it could be one by use of a scaling factor.

Another option that Edgar doesn't mention (mainly because it's a more esoteric and tricky system to use) is fixed point values. These values, also known as Q values, are often used in digital signal processing (DSP) since they give predictable resolution and high speed processing.
A Q value is simply an integer where you split the bits within that integer into two portions - the integer portion and the numerator portion.
For instance, you may choose to implement a Q4.11 format. That gives 4 bits of integer value (it can store 0-15) and 11 bits of numerator (that is a decimal resolution of 1/(2^11) or 0.000488281). The 16th bit (4+11 = 15, in a 16-bit integer there is one more bit to account for) is the implicit sign bit. Some implementations have that, some don't - it's entirely up to you. If you only want positive values you can include the 16th bit in your value to increase resolution or integer size, etc.
You're not limited to 16 bit of course - you could use 8 bit for smaller numbers and lower precision, or 32 bit for bigger numbers and higher precision.
The disadvantage to using Q values compared to using floats is that floats can arbitrarily exchange decimal precision for integer size. With fixed point you have limited yourself to the range of integers you can represent. But that sacrifice can be worth it if you have a limited range in the first place (0-5V, say) and you need extra speed.
To work with fixed point it is first necessary to convert a floating point number to and from your target Q value. This is quite simple - just multiply (or divide to convert from Q to float) the value by the Q value of 1. That is, for a Q4.11 you would use the value of the 12th bit (the first of the integer bits), or 1<<11 (start counting from 0, so the 12th bit is 11).
Once you have your Q values adding and subtracting is just that - exactly as normal, using the + and - operators. Multiplying and dividing though is slightly more involved, but the resultant code is considerably more efficient. The whole lot can be done using just left and right shifts. For instance, some functions which I use in a small library of mine for Q15 values (more specifically Q0.15), which store values between ±1 with 15 bit resolution, look like:
typedef int16_t Q15;

static inline int16_t __satQ15(int32_t x)
{
    if (x > 0x7FFFL) return 0x7FFF;
    else if (x < -0x8000L) return -0x8000;
    else return (int16_t)x;
}

static inline Q15 Q15_mul_Q15(Q15 a, Q15 b) {
    int16_t result;
    int32_t temp;

    temp = (int32_t)a * (int32_t)b; // result type is operand's type
    // Rounding; mid values are rounded up
    temp += (1 << 14);;
    // Correct by dividing by base and saturate result
    result = __satQ15(temp >> 15);
    return result;
}

static inline Q15 Q15_div_Q15(Q15 a, Q15 b)
{
    int16_t result;
    int32_t temp;

    // pre-multiply by the base (Upscale to Q16 so that the result will be in Q8 format)
    temp = (int32_t)a << 15;
    // Rounding: mid values are rounded up (down for negative values).
    if ((temp >= 0 && b >= 0) || (temp < 0 && b < 0))
        temp += b / 2;
    else
        temp -= b / 2;
    result = (int16_t)(temp / b);

    return result;
}

You can learn more about Q numbers here:

https://en.wikipedia.org/wiki/Q_(number_format)

Note that Q0.15 is natively supported by gcc as _Fract. I haven't yet experimented with that type though.

@EdgarBonet Only if the version of GCC you use has that option compiled in - not all do. I don't know off hand if the Arduino's compilation of avr-gcc has it or not.


text:
Extrapolate require MCU from Arduino MEGA2560 performance
I am running a control program for an ebike on an Arduino MEGA2560 which uses this MCU: http://www.atmel.com/devices/atmega2560.aspx. Currently, the program loops every 100ms which gives me a sample rate of 10Hz for measurements and control signal. I would like at least 10 times that so 100Hz. How can I work out which specs I need based on the arduino MEGA2560 and the perf it's giving me?
Thanks!
Here is my code, it basically calculates battery capacity, range as well as controls and smooths the throttle inputs:
#include <EEPROM.h>
#include <memorysaver.h>
//#include <TFT_HX8357.h> // Hardware-specific library
#include <URTouch.h>
#include <URTouchCD.h>
#include <memorysaver.h>
#include <UTFT.h>

//TFT_HX8357 myGLCD = TFT_HX8357();       // Invoke custom library#include <TFT_HX8357.h> // Hardware-specific library
//
//TFT_HX8357 myGLCD = TFT_HX8357();       // Invoke custom library

UTFT myGLCD(ILI9481,38,39,40,41);
URTouch myTouch(6, 5, 4, 3, 2);

int buttonst, horn=5, throttle=8, powermode=1, alarmsystem=1, xtouch, ytouch, k1=0, k2=0,modechange,ncycles, p=9, divider=12, addresstd=0;
float pushed, pushedt, timesp, timespm1, powtimesm, factor, powtimesp, start, elapsed, powtime, powresttime, shuntvoltage, batvoltage,  internresistance=0.00112, current, power, consumah, capacstore, consumwh, consumbatper, consumbatrange, distance, distanceint, throttlein, throttleout, distancedisp, Totaldist, velocity, Totaldistcheck;
float throttlesmooth, capaccheck, capacactual,consumahstore, kpow[3]={0,0,0}, kcur[3]={0,0,0}, ksp[3]={0,0,0}, errorpower[2], errorpoweri, errorpowerli, errorcuri, errorcurrent[2], errorpowerl[2], diff, errorspeed[2], errorisp, outspeed, outcurrentctl, outspeedctl, elapsedtot, errorsmooth[2];

float batteryspec[6][56]={{4.2,4,3.94,3.90,3.876,3.86,3.852,3.844,3.826,3.809,3.795,3.783,3.765,3.744,3.728, 3.710,3.692,3.672,3.650,3.631,3.613,3.591,3.573,3.556,3.532,3.508,3.488,3.463,3.439,3.417,3.399,3.380,3.366,3.352,3.332,3.312,3.291,3.273,3.253,3.237,3.217,3.196,3.176,3.150,3.123,3.087,3.051,2.994,2.929,2.868,2.796,2.727,2.650,5.261,2.502},//5A discharge 18650GA SPEC
  {0.001,0.002,0.015,0.047,0.085,0.133,0.186,0.244,0.309,0.383,0.447,0.506,0.554,0.612,0.681,0.735,0.793,0.852,0.921,1.007,1.081,1.150,1.236,1.300,1.358,1.438,1.518,1.587,1.667,1.747,1.822,1.888,1.955,2.014,2.072,2.152,2.232,2.317,2.389,2.466,2.524,2.594,2.658,2.722,2.786,2.847,2.925,2.983,3.063,3.133,3.186,3.245,3.293,3.330,3.357,3.368},
  {4.20,4.02,3.980,3.945,3.927,3.914,3.904,3.890,3.874,3.860,3.843,3.821,3.797,3.776,3.756,3.734,3.713,3.695,3.675,3.652,3.634,3.614,3.593,3.569,3.543,3.522,3.5,3.480,3.459,3.441,3.419,3.398,3.378,3.360,3.339,3.321,3.301,3.278,3.254,3.230,3.199,3.164,3.128,3.085,3.037,2.990,2.937,2.878,2.837,2.795,2.746,2.693,2.648,2.598,2.549,2.496},
  {0,0.007,0.033,0.084,0.151,0.223,0.294,0.377,0.457,0.521,0.574,0.646,0.718,0.785,0.851,0.931,1.011,1.091,1.171,1.251,1.323,1.397,1.469,1.547,1.632,1.701,1.778,1.853,1.928,1.994,2.088,2.175,2.258,2.333,2.413,2.487,2.562,2.634,2.706,2.775,2.842,2.908,2.697,3.023,3.074,3.116,3.159,3.205,3.234,3.261,3.287,3.314,3.333,3.352,3.365,3.379},//3A discharge 18650GA SPEC
  {4.2,4.131,4.094,4.073,4.054,4.038,4.028,4.015,4.003,3.985,3.965,3.945,3.921,3.894,3.870,3.850,3.830,3.811,3.795,3.775,3.759,3.739,3.716,3.692,3.674,3.648,3.623,3.601,3.578,3.561,3.542,3.522,3.502,3.486,3.467,3.445,3.423,3.401,3.374,3.350,3.324,3.291,3.253,3.210,3.168,3.123,3.075,3.026,2.964,2.897,2.838,2.781,2.715,2.652,2.585,2.502},
  {0,0,0.036,0.084,0.154,0.223,0.289,0.356,0.420,0.489,0.553,0.620,0.686,0.761,0.838,0.908,0.985,1.054,1.134,1.214,1.283,1.358,1.438,1.523,1.584,1.667,1.755,1.835,1.920,2.002,2.085,2.170,2.255,2.327,2.402,2.482,2.567,2.644,2.724,2.791,2.850,2.908,2.964,3.015,3.058,3.095,3.132,3.167,3.207,3.245,3.271,3.295,3.320,3.336,3.354,3.365}}; //1A discharge 18650GA SPEC

float cyclicspec[2][44]={{0,0.894,7.151,16.09,26.4,37.5,50.95,61.68,74.19,85.36,96.54,107.26,118.88,130.95,142.12,154.64,168.04,182.35,194.86,208.27,219.89,234.2,246.7,262.8,276.2,291.4,303.9,317.3,327.15,341.5,354,364,374.5,383.46,395.08,405.8,418.3,431.7,444,455.9,468.8,481.9,491.6,499.7},
  {3441.3,3435.7,3342.9,3292.9,3235.7,3178.6,3121.4,3078.6,3014.28,2957.1,2921.4,2892.9,2842.9,2792.9,2750,2721.4,2678.6,2642.9,2607.1,2564.3,2542.9,2507.1,2478.6,2435.7,2407.1,2378.6,2357.1,2335.7,2335.7,2335.7,2335.7,2335.7,2335.7,2321.4,2300,2278.6,2271.4,2242.9,2228.6,2214.3,2192.9,2178.6,2164.3,2157.1}};

extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

void EEPROMWritelong(int address, long value)
      {
      //Decomposition from a long to 4 bytes by using bitshift.
      //One = Most significant -> Four = Least significant byte
      byte four = (value & 0xFF);
      byte three = ((value >> 8) & 0xFF);
      byte two = ((value >> 16) & 0xFF);
      byte one = ((value >> 24) & 0xFF);

      //Write the 4 bytes into the eeprom memory.
      EEPROM.write(address, four);
      EEPROM.write(address + 1, three);
      EEPROM.write(address + 2, two);
      EEPROM.write(address + 3, one);
      }

float EEPROMReadlong(int address)
      {
      //Read the 4 bytes from the eeprom memory.
      long four = EEPROM.read(address);
      long three = EEPROM.read(address + 1);
      long two = EEPROM.read(address + 2);
      long one = EEPROM.read(address + 3);

      //Return the recomposed long by using bitshift.
      return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
      }

float pidcurrent_control() {
 float dt, outcurrent=0, outpower=0;
 int i=0, descurrent, despower;
 i++;
 dt=millis()-powtime;
 powtime = millis();
 if (powermode==1) { //Furo default mode
  if (current>40) {
    descurrent=40;
    errorcurrent[1]=descurrent-current;
    if (i>=2) {
      //Integrate the error
    errorcuri+=errorcurrent[1]*dt;

    outcurrent=(kcur[0]*errorcurrent[1]+kcur[1]*errorcuri+kcur[2]*((errorcurrent[1]-errorcurrent[0])/dt));
    }
    errorcurrent[0]=errorcurrent[1];
    return outcurrent;
    }
    if ((batvoltage*current)>2000) {
     despower=2000;
      errorpower[1]=despower-batvoltage*current;
      if (i>=2) {
    //Integrate the error
    errorpoweri+=errorpower[1]*dt;
    outpower=kpow[0]*errorpower[1]+kpow[1]*errorpoweri+kpow[2]*((errorpower[1]-errorpower[0])/dt);
    }
    errorpower[0]=errorpower[1];
    return outpower;
    }
    }
  else { //Eco mode
   despower=550;
   errorpowerl[1]=despower-batvoltage*current;
      if (i>=2) {
      //Integrate the error
      errorpowerli+=errorpowerl[1]*dt;
      outpower=kpow[0]*errorpowerl[1]+kpow[1]*errorpowerli+kpow[2]*((errorpowerl[1]-errorpowerl[0])/dt);
    }
    errorpowerl[0]=errorpowerl[1];
    return outpower;
    }
    }

void cyclescaling() {
int j=1;
 if (ncycles<=499) {
 while ((ncycles<cyclicspec[0][j-1])||(ncycles>cyclicspec[0][j])){
           j++;
    }
    factor=(cyclicspec[1][j-1]+(ncycles-cyclicspec[0][j-1])*(cyclicspec[1][j]-cyclicspec[1][j-1])/(cyclicspec[0][j]-cyclicspec[0][j-1]))/cyclicspec[1][0];
}
else {
    factor=(cyclicspec[1][41]+(ncycles-cyclicspec[0][41])*(cyclicspec[1][42]-cyclicspec[1][41])/(cyclicspec[0][42]-cyclicspec[0][41]))/cyclicspec[1][0];
}
}

float pidspeed_control() {
int isp, dtsp;
isp++;
dtsp=millis()-powtimesp;
powtimesp = millis();
errorspeed[1]=46-velocity;
if (isp>=2) {
    errorisp+=errorspeed[1]*dtsp;
    outspeed=(ksp[0]*errorspeed[1]+ksp[1]*errorisp+ksp[2]*((errorspeed[1]-errorspeed[0])/dtsp));
    }
    errorspeed[0]=errorspeed[1];
    return outspeed;
}

void throttlesmoothing() {
 int i=0, dtsm;
 i++;
 float currentmap=map(throttlein,0.8,3.6,0,40);
 dtsm=millis()-powtimesm;
 powtimesm = millis();
 errorsmooth[1]=currentmap-current;
      if (i>=2) {
      //Integrate the error
      throttlesmooth=kcur[0]*errorsmooth[1]+kcur[2]*((errorsmooth[1]-errorsmooth[0])/dtsm);
    }
    errorsmooth[0]=errorsmooth[1];
}

void SOC() {
  float currentref=current/p;
  int j=1,l=1;
  float stateofc1=0, stateofc2=0;

  if (currentref<=1){
    while (((batvoltage/14)>batteryspec[0][j-1])||((batvoltage/14)<batteryspec[0][j])){
           j++;
    }
    capacactual=(batteryspec[1][55]-(batteryspec[1][j-1]+(batvoltage/14-batteryspec[0][j-1])*(batteryspec[1][j]-batteryspec[1][j-1])/(batteryspec[0][j]-batteryspec[0][j-1])))*p;

  }

 if ((currentref>1)&&(currentref<=3)){
    while (((batvoltage/14)>batteryspec[0][j-1])||((batvoltage/14)<batteryspec[0][j])){
           j++;
    }
    stateofc1=(batteryspec[1][55]-(batteryspec[1][j-1]+(batvoltage/14-batteryspec[0][j-1])*(batteryspec[1][j]-batteryspec[1][j-1])/(batteryspec[0][j]-batteryspec[0][j-1])))*p;

     while (((batvoltage/14)>batteryspec[2][l-1])||((batvoltage/14)<batteryspec[2][l])){
           l++;
    }
    stateofc2=(batteryspec[3][55]-(batteryspec[3][l-1]+(batvoltage/14-batteryspec[2][l-1])*(batteryspec[3][l]-batteryspec[3][l-1])/(batteryspec[2][l]-batteryspec[2][l-1])))*p;
    capacactual=stateofc1+(currentref-1)*(stateofc2-stateofc1)/(3-1);
  }

   if ((currentref>3)&&(currentref<=5)){
    while (((batvoltage/14)>batteryspec[2][j-1])||((batvoltage/14)<batteryspec[2][j])){
           j++;
    }
//    stateofc1=(batteryspec[3][55]-(batteryspec[3][j-1]+(batvoltage/14-batteryspec[2][j-1])*(batteryspec[3][j]-batteryspec[3][j-1])/(batteryspec[2][j]-batteryspec[2][j-1])))*p;

     while (((batvoltage/14)>batteryspec[2][l-1])||((batvoltage/14)<batteryspec[2][l])){
           l++;
    }
//    stateofc2=(batteryspec[3][55]-(batteryspec[3][l-1]+(batvoltage/14-batteryspec[2][l-1])*(batteryspec[3][l]-batteryspec[3][l-1])/(batteryspec[2][l]-batteryspec[2][l-1])))*p;
    capacactual=(batteryspec[3][55]-(batteryspec[3][j-1]+(batvoltage/14-batteryspec[2][j-1])*(batteryspec[3][j]-batteryspec[3][j-1])/(batteryspec[2][j]-batteryspec[2][j-1])))*p+(currentref-1)*((batteryspec[5][55]-(batteryspec[5][l-1]+(batvoltage/14-batteryspec[4][l-1])*(batteryspec[5][l]-batteryspec[5][l-1])/(batteryspec[4][l]-batteryspec[4][l-1])))*p-(batteryspec[3][55]-(batteryspec[3][j-1]+(batvoltage/14-batteryspec[2][j-1])*(batteryspec[3][j]-batteryspec[3][j-1])/(batteryspec[2][j]-batteryspec[2][j-1])))*p)/(5-3);

  }

if (currentref>5) {
   while (((batvoltage/14)>batteryspec[4][j-1])||((batvoltage/14)<batteryspec[4][j])){
           j++;
    }
    capacactual=(batteryspec[5][55]-(batteryspec[5][j-1]+(batvoltage/14-batteryspec[4][j-1])*(batteryspec[5][j]-batteryspec[5][j-1])/(batteryspec[4][j]-batteryspec[4][j-1])))*p;
}

}

void autonomy() {

  if (modechange==1) {
   consumah=0;
  }

    power=batvoltage*current;
    SOC();
    if (capacactual!=capaccheck) {
      capaccheck=(capacactual+capaccheck)/2;
    }

  if (abs(capacactual-capacstore)>=0.1){
     EEPROMWritelong(8,roundf(capacactual*1000));
     capacstore=capacactual;
  }

  consumah += current*elapsed/1000/3600;
  capaccheck -= current*elapsed/1000/3600;
  consumwh += current*elapsed/1000/3600*batvoltage;
  elapsedtot += elapsed;
  consumbatper = (capaccheck)/(batteryspec[1][55]*p)*100;
  if (distance==0) {
    switch (powermode) {
      case 1: consumbatrange=45*batvoltage*capaccheck/980;
      break;
      case 2: consumbatrange=35*batvoltage*capaccheck/550;
      break;
    }

  } else {
  consumbatrange = distance/consumah*(capaccheck);
  }
  myGLCD.printNumF(consumbatrange, 2, 350,275);
  myGLCD.printNumF(power, 2, 350,205);
  myGLCD.printNumF(current, 1, 30,50);
  myGLCD.printNumF(ncycles, 1, 30,50+16*2);
  myGLCD.printNumF(consumbatper,1,350,50);
  myGLCD.printNumF(batvoltage,1,350,50+16*2);

  return 0;

}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  start=millis();
  pinMode(43, OUTPUT);//Speedo power
  pinMode(46, INPUT);//Speedometer
  pinMode(A2, INPUT);//Throttle in
  pinMode(A7, INPUT);//Battery voltage
  pinMode(A4, INPUT);//Shunt
  pinMode(throttle, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(47, INPUT);

  analogWrite(10,255);
  analogWrite(11,255);

  myGLCD.InitLCD(LANDSCAPE);
  myTouch.InitTouch(LANDSCAPE);
  myGLCD.fillScr(0,0,0);
  myGLCD.setColor(VGA_WHITE);
  myGLCD.setBackColor(0,0,0);
  myGLCD.setFont(BigFont);
  myGLCD.print("FURO SYSTEMS",(480-16*12)/2,16);
  myGLCD.print("WELCOME",(480-16*7)/2,(320-16)/2);
  myGLCD.setDisplayPage(0);
  delay(2000);
  myGLCD.clrScr();
  myGLCD.print("FURO SYSTEMS",(480-16*12)/2,16);
  myGLCD.fillRoundRect((480-3*16-8)/2,320-16*2-4,(480-3*16-8)/2+3*16+6,228);
  myGLCD.print("ECO", (480-3*16)/2, 320-16*5);
//  EEPROMWritelong(4,1);
  ncycles=EEPROMReadlong(4);
  cyclescaling();

  for (int m=1; m<=5;m+=2) {
  for (int n=0; n<=55;n++) {
    batteryspec[m][n]*=factor;
    }
  }

  current=analogRead(A4);
  current=current/internresistance*5/1023/75;;

  batvoltage=analogRead(A7);
  batvoltage=batvoltage*5*divider/1023;

  SOC();
  capaccheck=capacactual;
  capacstore=EEPROMReadlong(8)/1000;

  if (capacactual>capacstore) {
  ncycles++;
  EEPROMWritelong(4,ncycles);
  EEPROMWritelong(8,roundf(capacactual*1000));
  }

  if (capacactual<0.5) {
    powermode=2;
    myGLCD.fillRoundRect((480-4*16-8)/2,320-16*2-4,(480-4*16-8)/2+4*16+6,228);
    myGLCD.print("FURO", (480-4*16)/2, 320-16*5);
  }//3.21V per cell
  EEPROMReadlong(addresstd);
  Totaldist=EEPROMReadlong(addresstd);
  Totaldistcheck=Totaldist;
  digitalWrite(43,HIGH);
}

void loop() {

   throttlein=analogRead(A2);
   throttlein=throttlein*5/1023;
   throttlesmoothing();
   throttleout=round((0.4+throttlein)*255/5);
   analogWrite(8,throttleout);

   modechange=0;
    if (digitalRead(47)==LOW)
    {
      if (buttonst==1) {
      pushed = millis();
      }
      buttonst=0;

      if ((millis()-pushed)>=2000)
      {
       distancedisp=0;
      }
      }

     if (digitalRead(47)==HIGH) {
      if (buttonst==0) {
        modechange=1;
        pushedt=millis()-pushed;
        if (pushedt<1900){
       if (powermode==1)
      { powermode=2;
       myGLCD.clrScr();
       myGLCD.print("FURO SYSTEMS",(480-16*12)/2,16);
       myGLCD.fillRoundRect((480-4*16-8)/2,320-16*2-4,(480-4*16-8)/2+4*16+6,228);
       myGLCD.print("FURO", (480-4*16)/2, 320-16*5);
      }
      else
      {
        powermode=1;
        myGLCD.clrScr();
        myGLCD.print("FURO SYSTEMS",(480-16*12)/2,16);
        myGLCD.fillRoundRect((480-3*16-8)/2,320-16*2-4,(480-3*16-8)/2+3*16+6,228);
        myGLCD.print("ECO", (480-3*16)/2, 320-16*5);
      }
      }
      }
      buttonst=1;
     }

batvoltage=analogRead(A7);
batvoltage=batvoltage*5*divider/1023;
current=analogRead(A4);
current=current/internresistance*5/1023/75;
elapsed = millis() - start;
start = millis();

if (modechange==1) {
   distance=0;
}
distanceint = (velocity/3.6*elapsed*0.001)/1000;
distance += distanceint;
distancedisp += distanceint;
Totaldist += distanceint;

if (abs(Totaldist-Totaldistcheck)>=0.1) { //later do it upon switch off
  EEPROMWritelong(addresstd,round(Totaldist));
  Totaldistcheck=Totaldist;
}

autonomy();

if (velocity>45) {
outspeedctl=pidspeed_control();
outcurrentctl=pidcurrent_control();
float throttleout1=min(outspeedctl,outcurrentctl);
throttleout=min(throttleout1,throttlesmooth);
analogWrite(throttle, map(throttleout, 0,5,0,255));
} else{
outcurrentctl=5;
outcurrentctl=pidcurrent_control();
throttleout=min(throttlesmooth,outcurrentctl);
analogWrite(throttle, map(throttleout, 0,5,0,255));
}

myGLCD.setFont(SevenSegNumFont);
myGLCD.printNumI(velocity, (480-32*3)/2, (320-50)/2);
myGLCD.setFont(BigFont);
myGLCD.printNumF(distancedisp, 1, 30,175);
myGLCD.printNumI(Totaldist, 30,175+2*16);

}

Why is your loop so slow?

I have 3 PIDs running, complicated calculations, as well as multiple circuits to sample. I edited my question to display my code.

Stop using floating point math! Just scale your numbers into integers of whatever precision you need. The AVR processors don't have an FPU so all float math is implmented in software. A simple addition takes many, many clock cycles as opposed just a few for integers.

There are three things that i can see that are holding your code back.
AnalogRead in Arduino is very slow. The ADC in the chip is not the greatest but also the AnalogRead function will hold you there until a full read and conversion are complete. It may be possible to trigger a sample and conversion and read the answer later. Look for a chip that can sample multiple ADC channels without processor intervention. A digital signal processor (DSP) such as a dspic33epxxxxxx could be of great service. They have very high analog sampling capability.
Also EEPROM writes are very slow. Finding a way around them or using external memory could help increase your speed. The EEPROM write has to hold your code until the write is complete. This is very similar the the ADC.
Float calculations inside a processor that has no float math core is like shooting yourself in the foot, all you can do from there is limp. Find the minimum number of decimal places that you can live with and push them into the integer world. For example 12.7325 X 10000, could instead be 127325. Then scale all your other calculation with that scale factor in mind. The math is more tricky but 10 to 15 cycles to multiply an integer is better then 200 to over a 1000 cycles to multiply a float. By properly including some other scale factor the ADC reading can be used directly without a conversion.

Thank you! I'll do that! If I timed my floats by a thousand and then used the round function to get an integer would that be useful or would the round function be very computationally expensive too?

Do all processors require this? I want to move away from Arduino later and do my own platform, are there processors that would allow me to use float points, write faster to the EEPROM, sample without processor intervention, etc?

You almost never want to use floats in an embedded environment; the investment for a MCU with a FPU is rarely worth it. Writing to EEPROM is always slow. AVRs can sample without busying out the CPU; your problem is the Arduino libraries, not the MCU. Most likely the ATmega2560 is just fine for this application.


text:
WebSocket message with Arduino MKR 1010 using WiFiNINA and ArduinoHttpClient libraries
I am trying to send a WebSocket message to a server. The example for the ArduinoHttpClient library uses WiFi101 but that will not work for the MKR 1010. So I am trying to use WifiNINA instead. The WiFi part works fine but is seems the WebSocket cannot "begin".
#include <SPI.h>
#include <WiFiNINA.h>
#include <ArduinoHttpClient.h> /*Need to implement*/
//https://github.com/arduino-libraries/ArduinoHttpClient/blob/master/examples/SimpleWebSocket/SimpleWebSocket.ino
//https://www.arduino.cc/en/Tutorial/WiFiNINAConnectWithWPA

char ssid[] = "SSID_NAME";        // your network SSID (name)
char pass[] = "WPA2_Password";    // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;     // the Wifi radio's status
char serverAddress[] = "192.168.0.195";  // server address
int port = 3652;

WiFiClient wifi;

WebSocketClient client = WebSocketClient(wifi, serverAddress, port);

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < "1.0.0") {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
  printCurrentNet();
  printWifiData();

}

void loop() {
  // check the network connection once every 10 seconds:
  delay(10000);
  //printCurrentNet();

    Serial.println("starting WebSocket client");
    client.begin();
    Serial.print("Is client connected? -> ");
    Serial.println(client.connected());

      client.beginMessage(TYPE_TEXT);
      client.print("Fire alarm from arduino mkr1010 - sensor1 ");
      client.endMessage();

    while (client.connected()) {
      Serial.print("Sending fire alarm ");
      // send fire alarm
      client.beginMessage(TYPE_TEXT);
      client.print("Fire alarm from arduino mkr1010 - sensor1 ");
      client.endMessage();
    }
    /*
      // check if a message is available to be received
      int messageSize = client.parseMessage();

      if (messageSize > 0) {
        Serial.println("Received a message:");
        Serial.println(client.readString());
      }*/

}

void printWifiData() {
  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.println(ip);
}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(rssi);

  // print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print("Encryption Type:");
  Serial.println(encryption, HEX);
  Serial.println();
}

Could it be that there are compatibility issues between the ArduinoHttpClient library and the Arduino MKR1010? I am thinking of getting an ESP32 instead since there seem to be more WebSocket libraries built around it.

doesn't firewall on server block the port?

Good point @Juraj, will have to look into it, there is a firewall

I needed to use port 80.
I got a hint from wikipedia:

The communications are done over TCP port number 80 (or 443 in the case of TLS-encrypted connections), which is of benefit for those environments which block non-web Internet connections using a firewall.

https://en.wikipedia.org/wiki/WebSocket
Switched to port 80 and it works!


text:
Serial monitor shows repeated CIPSEND and CIPCLOSE
I'm trying to build a heart rate monitor using ESP-01. The code compiles and uploads well but once uploaded, in the serial monitor it shows the following. It keeps repeat CIPSEND and CIPCLOSE over and over.
What could cause this?
Could it be faulty hardware or is it a problem with the code?
 AT+CIPSTART="TCP","184.106.153.149",80
 AT+CIPSEND=29
 AT+CIPCLOSE
 AT+CIPSTART="TCP","184.106.153.149",80
 AT+CIPSEND=29
 AT+CIPCLOSE
 AT+CIPSTART="TCP","184.106.153.149",80
 AT+CIPSEND=29
 AT+CIPCLOSE
 AT+CIPSTART="TCP","184.106.153.149",80

A problem with the code.

The code is at the end of the webpage. I dont know if theres anything wrong with the code. Could it be faulty hardware?    https://www.how2electronics.com/pulse-rate-monitoring-over-internet-using-thingspeak/

the code on that web page is improperly formatted ... it is a really bad example to beginner programmers ..... i would not be surprised if it contains bugs

The reason that you are seeing those messages on the serial monitor is because the code is telling it to print those messages on the serial monitor.
Every time a message is sent to the ESP8266 it is also sent (for debugging purposes) to the Serial.