text:
printing data from gps on Serial1 and sensors into Serial
I am having some trouble using my gps (on Serial1) with my other sensors.
They both work great independently but when I use them in the same code, it's either the gps or the sensors that get to write on the Serial monitor.
For my gps I am using TinyGPS++, but I have a feeling that's not what's causing this problem here.
To simplify the code I'll be replacing what the sensors are supposed to write with this:
Serial.println("Hello there");

Here is the code
  if (Serial1.available() > 0) {
    gps.encode(Serial1.read());
    if (gps.location.isUpdated()){
      Serial.println("Satellite Count:");
      Serial.println(gps.satellites.value());
      Serial.println("Latitude:");
      Serial.println(gps.location.lat(), 6);
      Serial.println("Longitude:");
      Serial.println(gps.location.lng(), 6);
      Serial.println("Speed KT:");
      Serial.println(gps.speed.knots());
      Serial.println("Altitude Feet:");
      Serial.println(gps.altitude.feet());
      Serial.println("");
    }
  }
  Serial.println("Hello there");

I get this
Hello there
Hello there
Hello there
Hello there
Hello there
Hello there
Hello there
Hello there
Hello there
Hello there
Hello there
Hello there
Hello there
Hello there

If the line is removed, I get this
Satellite Count:
5
Latitude:
xx.xxxxx
Longitude:
-xx.xxxxxx
Speed KT:
0.19
Altitude Feet:
331.69

Thank you

add the sketch to the question? the GPS library returns data only if it is collected while your print in loop is executed in every loop

@Juraj excuse me, I don't understand. Can you please say again in other words ?

print a timestamp inside the if block ... add serial.println ( millis() ); before "Satellite Count:" .... add one also at "Hello there"

@jsotola I changed it to text. My timestamp is actually just the number of seconds since 01 Jan 1970, like this

thank you for removing the pictures, now the program listing is legible .... you are missing the point about the millis() ... print the value of millis() and examine the result .... how often does loop() repeat? ...  how often does if (gps.location.isUpdated()){ repeat?

both repeat to infinity

it looks like my issue is similar to this one https://arduino.stackexchange.com/questions/70269/my-gps-coordinate-does-not-show-only-my-ultrasonic-output-came-out

This looks like another case of serial spam.  I recommend changing to a frame-based approach and controlling that rate with checks to millis.
That limits the spam.  Alternative is to limit it outright to 1:
//a static global:
static int isaidHELLO = 0;

//later in the loop
if (Serial1.available() > 0) {
    gps.encode(Serial1.read());
    if (gps.location.isUpdated()){
      Serial.println("Satellite Count:");
      Serial.println(gps.satellites.value());
      Serial.println("Latitude:");
      Serial.println(gps.location.lat(), 6);
      Serial.println("Longitude:");
      Serial.println(gps.location.lng(), 6);
      Serial.println("Speed KT:");
      Serial.println(gps.speed.knots());
      Serial.println("Altitude Feet:");
      Serial.println(gps.altitude.feet());
      Serial.println("");
      isaidHELLO = 0;
    }
  }
  if(isaidHELLO == 0)
  {
      Serial.println("Hello there");
      isaidHELLO = 1;
  }

Thank you this works great !


text:
Help with code not working
I built a button box, everything is wired up and all of the push buttons work using the code below, but for some reason my rotary encoders are not working, well 3 out of the 4 are not working. Is there something in my code that I messed up? Should rotary encoders not be linked to analog pins? Any guidance would be appreciated.
EDIT - Correct code replacing incorrect code.
#include <Keyboard.h>
#include <SimpleRotary.h>

#define NUMROWS 6
#define NUMCOLS 4

const int ModPin = A0;
int ModState = 0;

//define the symbols on the buttons of the keypads
char buttons[NUMROWS][NUMCOLS] = {
  {'7','5','3','1'},
  {'6','4','2','0'},
  {'r','e','w','q'},
  {'i','u','y','t'},
  {'f','d','s','a'},
  {'p','j','h','g'},
};

char buttonsMod[NUMROWS][NUMCOLS] = {
  {'7','5','3','1'},
  {'6','4','2','0'},
  {0xC9,0xC7,0xC5,0xC3},
  {0xC8,0xC6,0xC4,0xC2},
  {'f','d','s','a'},
  {'p','j','h','g'},
};

byte rowPins[NUMROWS] = {13,12,11,10,9,8}; //connect to the row pinouts of the keypad
byte colPins[NUMCOLS] = {7,6,5,4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
Keypad buttbxMod = Keypad( makeKeymap(buttonsMod), rowPins, colPins, NUMROWS, NUMCOLS);

SimpleRotary RotaryA(1,2,3);
SimpleRotary RotaryB(0,A5,3);
SimpleRotary RotaryC(A4,A3,3);
SimpleRotary RotaryD(A2,A1,3);

void setup() {
  Keyboard.begin();
  pinMode(ModPin, INPUT_PULLUP);
}

void loop() {
ModState = digitalRead(ModPin);
  if (ModState == HIGH) {
    CheckAllButtons();
  } else {
  CheckAllButtonsMod();
  }

byte i;

  // 0 = not turning, 1 = CW, 2 = CCW

  i = RotaryA.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  i = RotaryB.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  i = RotaryC.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  i = RotaryD.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
}

void CheckAllButtons(void) {
  char key = buttbx.getKey();
  if (key != NO_KEY)  {
    Keyboard.press(key);
    delay(150);
    Keyboard.releaseAll();
  }//Keyboard.write(key);
}

void CheckAllButtonsMod(void) {
  char key = buttbxMod.getKey();
  if (key != NO_KEY)  {
    Keyboard.press(key);
    delay(150);
    Keyboard.releaseAll();
  }//Keyboard.write(key);
}

In your loop you only ever check A and B.  You never do anything with C and D.  Were you copy-pasting and forgot to change the B's to C's and D's?  It looks like you read B three times.  Are C & D the ones not working?  If this is for gaming then you're going to find that with all the delay(150) in there it won't be very responsive.  Hope it's a slow game.

One more hint for you, avoid always naming things with single letters.  Single lower case letters just suck to read.  Single upper case letters are often used as macros by the core.  You can end up with some strange errors that are hard to debug when those two clash.  Name them encoderA and encoderB or something.  But just A, B, C, and D is something to avoid.

some of the code lines inside loop() are incorrectly indented ... that makes it difficult to see the end of the loop() block

It seems that copy paste is a bad idea, After correcting that error things seem to be working now, except for the encoder wired to 0/A5, which workes sometimes and other times it triggers the "p" code, I suspect a wiring fault, will have to go hunting.

source: Stack Exchange

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

sort: votes


text:
How to tell if there is a line break from Nextion display to Arduino at Serial
Well I am trying make language page with Nextion display and Arduino Mega. If user enter the language page Nextion display is sending page name with this commend to Arduino for which is current page.

While page preinitializing moment.
print "dil"

If user choice a language and then press the Next button, Nextion sending this comment to Arduino.
if(r0.val==1)
{
  va0.txt="en"
}else if(r1.val==1)
{
  va0.txt="tr"
}else
{
  va0.txt="de"
}
print va0.txt
page 2

Everyting is normal until here. If user press back button at page 2 in a short time. Serial print not only send "tr" or "de" or "en" but also sending "dil" comment all together. Because of that Serial2.readString(); commend return such as "trdil" or "endil" or "dedil". So that program not working properly. Just I want to receive language's 2 letter short code.
There is a comment which is useful if I send data Arduino to Nextion to understand last of the commend line.
  Serial2.write(0xff);
  Serial2.write(0xff);
  Serial2.write(0xff);

How can tell the Arduino there is a line break after sending "tr" or "en" or "de".
Assume that I am using simple Serial receiver commend.
void setup() {
  Serial.begin(9600);
  Serial2.begin(9600);
}

void loop() {
  if (Serial2.available() > 0)
  {
    String Received  = Serial2.readString();
    Serial.println(Received);
  }
}

check for the newline character ... if you receive it, then it is being sent

Can you show me a tutorial

You didn't show your Arduino code

@chrisl I have added simple receiver code

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


text:
Help using an Arduino as as an FTDI with a ESP8266 carrier shield to see an AT response
I have a Duinopeak shield that lets you plug on an ESP-01 and provides a 5V-3.3V regulator and level shifting for the Tx and Rx pins. I cannot get it to work with a setup that has worked with every ESP-01 or Wifi Shield I have used before.
Between the Arduino and the shield I connect Tx/Tx and Rx/Rx. I either load a blank sketch or jumper RST to ground on the Arduino. I use pins 0 and 1 through the shield. When I plug in the USB cable and type AT and "send". Nothing. No light blinks on the ESP sitting on the board. This is the board:
https://alexnld.com/product/duinopeak-esp8266-esp-01-wifi-expansion-board-shield-without-esp8266-module-for-arduino/
I know the ESP and the board works, because if I connect it to a Mega and use Seria1 instead of the main serial(0), rewire Tx/Rx and Rx/Tx, and upload a sketch to echo the USB Serial to Serial1 and back, using Serial Monitor, I can send AT commands and see responses. But when connected to pins 0 and 1, it acts like it isn't connected.
What I have tried:

Tried an Uno and Mega
Tried removing the plastic jumpers and running wires from the rows of Rx and Tx pins to the header directly
Tried different pins on the row (there are 8 Tx pins and 8 Rx pins so you can jumper to D0-D7)
Tested the continuity of each pin with a meter

I thought it must be the level shifter, but then why would it work when using Serial1? I thought the pins might have a cold solder joint, but then I used jumper wires from the pins in both tests and the same pins work (in reverse) when I connect them to Serial1 on the Mega. I thought it might be because of the 2 resistors on the USB path to pins 0 and 1 on an Arduino, but they prefer the pins over the USB. And why would another very similar board work? Tracing and finding an identical looking board shows this schematic. Odd thing is this is identical to a different board that works
:

and you power it from 5 V pin of Uno? on other pins you used SoftwareSerial with the SerialPassthrough sketch?

I have the shield on the Uno or Mega and which takes the 5V from the Arduino and regulates it to 3.3V. I can't use software serial because my sketch will need critical interrupt timing and the softwareSerial library will destroy that. tried to use pins 0/1 with the Uno and Mega for passthrough with no sketch and Tx/Tx, Rx/Rx. I used the "reflector" sketch on a mega to use serial1 or serial3 for the ESP and USB for the serial monitor and that works (Tx/Rx, Rx/Tx). Passthrough works with a bare ESP or a Makerfabs board with identical FETs and resistors for the level shifter circuit.

More info. I put a scope on the signal. My IOREF (that the schematic says it uses is 5.3V. When I jumper to Serial1 on a Mega, I see the Tx and Rx signals at around 4V. When I try to use Serial(0) The Tx to the ESP is only 3V. I suspect something in the Arduino circuit is not allowing enough voltage or current to drive. I'll try writing a sketch to continually send and see if I see 3V pulses that the Arduino can't read.


text:
Trigger ESP8266 reset pin on broken connection
I have an ESP8266 which I wish to place in deep sleep until a reed switch senses a door being opened. The ESP8266 is woken from deep sleep by briefly raising the RESET pin high.
In my original design, I thought that raising the RESET pin would wake the device instantly. Instead raising the pin holds the device in a reset state until it goes low again. This means that the 8266 currently wakes after the door is opened and closed again.
I'm looking for a way to briefly trigger the RESET pin after the reed switch connection is broken with minimal additional hardware, and minimal power drain while in deep sleep. I can use either NC or NO Reed switches.
Any suggestions?

the reset pin is HIGH for normal run, it must be pulled LOW for reset. I don't know what is the state of the pin in deep sleep

A simple capacitor can be used to convert a level change into a short pulse - just like the Arudino UNO etc use for the DTR->RESET signal.

why not power it through the switch and seleep once the message is sent? that uses no power in standby.


text:
Arduino fingerprint Scanner stop loop after enroll or delete
How can I stop the loop when I enroll a fingerprint to the module?
The loop is stuck in enrolling fingerprint even it was already done. The result I want was after the enrollment of fingerprint, it will exit the loop of enrollment and start the default switch command. Thank you in advance.
Here is my loop code.
    void loop() {
//
    if (Serial.available() > 0) {
      // read the incoming byte:
      command = Serial.read();

      // say what you got:
      Serial.print("I received: ");
      Serial.println(command);
    }
    switch (command) {
    case 'A':
    {
      Serial.println("Ready to enroll a fingerprint!");
      Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
      id = readnumber();
      if (id == 0) {// ID #0 not allowed, try again!
         return;
      }
      Serial.print("Enrolling ID #");
      Serial.println(id);

      while (!  getFingerprintEnroll() );
    }
      break;
    case 'B':
    {
      Serial.println("Case 2");
    }
      break;
    default:
    {
        getFingerprintDoorLoob();
        delay(50);
    }
      break;
  }
}

Here is the enroll fingerprint code:
 uint8_t getFingerprintEnroll() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger1.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger1.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger1.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger1.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger1.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  Serial.print("Creating model for #");  Serial.println(id);

  p = finger1.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  Serial.print("ID "); Serial.println(id);
  p = finger1.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");

  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }
}

This was the current result, what I expect was after it was stored the loop will break. please help thank you

you have to give the while loop an exit status

I see the problem here. Now observe the
if(Serial.available>0)
{
//Block of Statements
}
Your closing bracket for that if statement must be after the switch() statement.
For every iteration (void loop()) your command variable runs your switch and calls the enrolling function.
So it should be:
if (Serial.available>0){
//Block of statements
Switch(command){
//Block of statements}
}
}
Hope this helped

that result was the same, what I want was after enrollment loop then it will break but the result was after enrolling a fingerprint , the loop will start again in enrollment loop.


text:
ESP8266 WiFiEspClient Disconnect 3 with GPS
I have recovered an old sketch (2 years ago) in which I used 2 DHT22 sensors and sent the values to an web app to store in database. The sketch works fine with a ES8266 module connected to an arduino uno. In my new project I am trying to do the same action, but sending GPS coordinates obtained with GPS NEO-6m module.
I have write a function that returns a string with the parameters as lat, lng, altitude, and others.
void loop(){
  gps_data = get_gps_data();

  // all code for wifi client sending
  ..........
  client.print("GET /reads/store?"+gps_data);
  .......
  .......
}
String get_gps_data(){
  // GPS capture function
  ...........
}

The function takes 5 second in get GPS information but I always get....
TIMEOUT>>>
Disconecting 3
and none call arrives to to web server
but if I change (for example..)
gps_data = "gps=1&lat=36.125471&lng=-4.478658.....";

the system works fine and send continuously the data, and if I put a delay before and after the gps the system works. If I take a value from DHT22, the code works too, but with the GPS the URL is not sent to the server.
Any idea?
Thank you in advance...

yes, the gps_data is not what you think it is

one is on hw Serial other on SoftwareSerial? do you use the WiFiEsp library? at what baud rate?


text:
FastLED not performing as expected
I'm fairly new to working and programming with arduinos. The project I am working on is a digital clock which uses a string of WS2812 leds to light up the correct numbers. Each digit consists of 7 leds and there are two 'colon' leds between the second and third digits. I am using the FastLED library to try to program the code. I am able to make the leds light up such that all four digits are the same number (four consecutive 5's). However, the second I try to have it display multiple different numbers, everything goes south quickly. Here are some pictures of my current results:

55:55. I can create this with any number 0-9.

Should be 12:34.
Here is the code that I'm working with so far:
#include <RTClib.h>

RTC_DS3231 rtc;
DateTime now;

#define NUM_LEDS 30
#define LED_PIN 6

CRGB leds[NUM_LEDS];

void setup() {
  // put your setup code here, to run once:

  Serial.begin(57600);

  FastLED.addLeds<WS2812, LED_PIN>(leds, NUM_LEDS);

  FastLED.clear();
}

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

  const int ZERO[]={0,1,2,4,5,6};
  const int ONE[]={2,6};
  const int TWO[]={0,1,3,5,6};
  const int THREE[]={1,2,3,5,6};
  const int FOUR[]={2,3,4,6};
  const int FIVE[]={1,2,3,4,5};
  const int SIX[]={0,1,2,3,4,5};
  const int SEVEN[]={2,5,6};
  const int EIGHT[]={0,1,2,3,4,5,6};
  const int NINE[]={2,3,4,5,6};

  for(int i=0; i<sizeof(ONE);i++){
        leds[ONE[i]]=CRGB::Red;
        FastLED.show();
      }

  for(int i=0; i<sizeof(TWO);i++){
        leds[TWO[i]+7]=CRGB::Red;
        FastLED.show();
     }

  for(int i=0; i<sizeof(THREE);i++){
        leds[THREE[i]+16]=CRGB::Red;
        FastLED.show();
      }

  for(int i=0; i<sizeof(FOUR);i++){
        leds[FOUR[i]+23]=CRGB::Red;
        FastLED.show();
      }

Can anyone explain what's going wrong? Any help would be greatly appreciated. Let me know if you need clarification!

what happens if you turn off all LEDs first? ... try putting FastLED.show(); after the last for loop

I did try that and nothing changed. I also have FastLED.clear(); in the set up so it at least gets cleared once when the program is uploaded.

Start by writing a sketch that switches just one segment of one digit on, all others off. Then each second, change to the next segment. You might find the problem, be it in your usage of FastLED or the hardware. (Hardware, because it looks like a multiplexing problem.)

Your problem is your usage of sizeof(). It doesn't do what you think it does.
sizeof() gives you the amount of memory a variable takes up. It does not give you the number of elements in an array.
For example:
const int ONE[]={2,6};

sizeof(ONE) will not give you 2. It will give you 4. An int is two bytes in size (16 bits). An array of 2 ints is, therefore, 2x2 = 4 bytes.
So when you're iterating over a 2 byte array but counting 0-3 you're overflowing your array and reading from the next bits of memory - which happen to be the first two entries of the TWO array in this case.
To get the number of entries in an array you must divide the sizeof() by the size of the variable type the array is made up of.  The most common way of doing that is:
sizeof(ONE) / sizeof(ONE[0])

It's common to set up some macros at the time of array creation so you can easily refer to it later:
const int ONE[]={2,6};
#define ONE_SIZE (sizeof(ONE) / sizeof(ONE[0]))

You should also consider using an array of byte (or better, the standard uint8_t) where the size of one element will be 1 not 2, since you don't need to store any number > 255. It's still good to do the division of the sizeof() even with a 1 byte size in case you should ever need to change the variable type in the future. It's also a good habit to get into.

This explains SO much! It works now. Thank you!


text:
How to remove any previous program from Arduino?
I have a Arduino UNO and I want to remove the previously uploaded code....how to do that?

Why do you want to remove the code?

Just upload a new one. I frequently "blank" an arduino when I'm done with it by uploading "Blink.ino" from the examples included with the IDE. (The only reason I've had to remove old code is to avoid an issue where I might later wire up the Arduino in a way that is dangerously incompatible with the old code running on it.)

examples/01.Basics/BareMinimum would be even better, as it doesn't set pin 13 to OUTPUT. Which would be a problem if your next project has a button connected to pin 13, and you accidentally press the button before uploading new code.

@sniggerfardimungus can I upload the empty sketch that is present when we open the Arduino IDE? I mean ony the void setup and void loop one....

Replacing your sketch with another doesn't actually "remove" the previous one. Is that really necessary? If you're trying to prevent the first one from executing, replacing it, as already suggested by @Juraj, is a simple and proper solution.
If you need to prevent anyone ever being able to read any part of the previous one, you'd need to load another sketch at least as large as the previous one so it over-writes all of it, or create and run a modified "bootloader" program that erases the parts of flash you wish to obscure.
(Your question doesn't address your reason for wanting to "remove" the sketch. I'm adding this for completeness; not because I think it's likely.)

I got it. just upload blank code that is written when you start arduino ide.


text:
I want to stream audio from an Arduino to a device on the wifi
I only started learning Arduino recently. This is my first project.
So the idea for the project is that there will be an Arduino board(Ideally an Uno but I don't know if another board would be better) and when you hold a button down it will transmit what you are saying to a device on the wifi. I know I will have to get a WiFi module and like a microphone and button, so can you help me figure out just the gist of how the project will go and what parts I should get.
Thanks!

You should ditch the Uno here. The wifi module (which is likely an ESP) wil already be a way more powerful microcontroller than the Uno. So just move to a boatd with buildin wifi, like an ESP32 or similar. They also have an I2S interface, where you should be able to connect a good ADC to for audio sampling

An Arduino can do this, but this is a very advanced problem on an Arduino. It sounds like perhaps you need something more plug-and-play. In that case, buy a Raspberry Pi 4 starter kit and a USB microphone, and start working on the problem from there. The Raspberry Pi 4 is a Linux computer, so everything you do will be writing scripts or programs (in any language: it's just a regular computer, so use Python, C, C++, Java, bash, whatever you want) to run on its Raspberry Pi OS (formerly called Raspbian) Linux operating system.
If you go this route, you'll want to ask your questions on the Raspberry Pi Stack Exchange as well.
Keep in mind the question you asked is too broad. You are generally expected to do your own background research and then ask more specific questions, demonstrating what you've already tried.
Getting an Arduino to send out microphone data is, like I said, a very advanced subject and project (think: professional level / expert hobby level) unless you can Google and find pre-made libraries and how-tos on the subject.
Essentially, for the Arduino Uno route you'd need to do some fancy high-rate ADC sampling with a modified ADC clock rate in a special ADC mode which takes repeated samples and then interrupts your code when a sample is ready, rather than just doing normal analogRead() since that is both blocking/polling-based which wastes clock cycles and creates sample jitter which causes audio distortion, and then you'd need to send this data via some Wifi shield (add-on board) or an ESP8266 or something, or via some other technology (wired or wireless) to a computer to pass it on to the internet. This may involve binary packetization/bit-packing, error checking, buffering, etc., all of which is its own special skill to acquire.
Some of my projects have taken me 3+ years to complete them, since I began complicated projects as a beginner. This is one of those multi-year type projects for a beginner for sure.
(Heck, if you give me two LEDs and two resistors and an Arduino Nano, with those items alone, I can send you on your way to work 8 hrs a day for 3 months straight on projects. It's easy to under-estimate the complexity of something until you're neck-deep in it.)
Update: if you want to go the Arduino route, here's some tips to get you on a search route more likely to get you to a solution faster. Again, no doubt an Arduino Uno can do this. It for sure can. But, a faster Arduino can do it easier and better. So:

Google search for projects on Adafruit which may do this. Ex: Google search for "adafruit stream audio". Their tutorials are 2nd to none--the best in the world--and their products top-notch.
Search for projects on Sparkfun which may do this. Ex: Google search for "sparkfun stream audio". They also are excellent and have world-class tutorials.
Search for projects which do this with a Teensy, Zero, Due, or other high-speed 32-bit microcontroller, instead of an Uno. Audio processing is more difficult for a slower 8-bit Uno than for any of those 3 Arduino/Arduino-compatible devices.
Also look on Instructables.com for tutorials and help.
One more thought: Google search for "atmega328 stream audio to wifi" (an Uno uses the ATmega328 microcontroller, so that's a good search term to use)

Update: also take a look at this tutorial by GreatScott (who is also super awesome) (https://www.instructables.com/id/Make-Your-Own-Spy-Bug-Arduino-Voice-Recorder/), which uses this AVR-based (for ATmega328: Arduino Uno, Nano, Pro Mini, etc., or ATmega2560: Mega) advanced audio library for both recording and playing back audio. See:

https://github.com/TMRh20/TMRpcm

Recording Audio
Audio streaming over NRF24L01+ radio link

Would it be easier if you just send an audio file.
So if you click the button it'll just send an audio file.

Yes. That removes the entire complexity of sampling the audio with the ADC.

You'll need to store the file on an SD card or in a non-volatile FRAM.

So the idea is that if my mom is downstairs and I'm in my room playing games or something, she can click the button and it will say, "come downstairs" to me on my headphones or whatever audio I'm using. Is that possible

You can use a ESP32 with built-in WiFi and Bluetooth. Record a wave-File to a SD-card using this library, send it over Blutooth and play it on the PC with a little script.

That link you have to https://www.instructables.com/id/Make-Your-Own-Spy-Bug-Arduino-Voice-Recorder/ relies on libraries built for the ATmega328 microcontroller (https://github.com/TMRh20/TMRpcm), and would likely require significant advanced modifications to run on an ESP32. But, you could always split the project and use 2 microcontrollers: one ATmega328 (Uno, Nano, or Pro Mini), and one ESP32.

Sorry, didn't recognized. Here is a library for the ESP32.

Nice! Please add that link to your answer too (while keeping in the Great Scott Instructables link too). Upvoted.

I just can't figure out how to transfer the file. Some people say that the only solution is transfering it byte by byte, but that could be quiet hard and I didn't find any library for it. You could record some sample files (like in your example "come downstairs"), assign to numbers and send just the numbers the PC so he can find out which file to play.

You can upload a wav to a webserver using the ESP32 and download it over Python. Or you upload a text file and read it over tts, which should be faster with a bad connection.


text:
How do I make LEDs lights up one by one according to how long the button was pressed and hold
In my project, I am trying to create a timer display with LEDs base on how long a button was pressed and hold.
There are 8 LED lights in total, when the toggle button was pressed, 1st LED lights up; keep holding/ pressing the button, the 2nd LED lights up after 1sec, the 3rd LED lights up after 2sec and so on. So 7s after the button was pressed and hold, all 8 LEDs shall light up. When the button was released at anytime, all LEDs would be off.
Something is wrong with my code which the timer seems not working (saving the time when the button was pressed) and calculate the time difference ("current time" - "time when button pressed") in order to lights up the LED.
My codes:
 int current;
 long millis_held;
 long prev_secs_held;
 unsigned long firstTime;
 byte previous = LOW;

 const int buttonPin = 13;

 void setup() {
 pinMode(buttonPin, INPUT);
 pinMode(2,OUTPUT) ;
 pinMode(3,OUTPUT) ;
 pinMode(4,OUTPUT) ;
 }

 void loop() {
 current = digitalRead(buttonPin);

 if (current == HIGH && previous == LOW) {
 firstTime = millis();
 digitalWrite(2, HIGH);

 millis_held = (millis() - firstTime);

 if (millis_held >= 1000 && firstTime <2000){
 digitalWrite(3, HIGH);
 }

  if (millis_held >= 2000){
  digitalWrite(4, HIGH);
 }
 }

 else {
 digitalWrite(2, LOW);
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
 }
 }

Hope you guys can help, thanks a lot.

We can’t help you without seeing your code.

if I waited too long before initiating the 1st button press, same thing happens with all LEDs light up together ... that indicates that you are not waiting for the button to be pressed before starting the timer

Thanks for your reply, I have added the codes I am currently working on for your reference. See id you can help. Thanks!

your code is improperly indented ... that makes the code difficult to read and leads to errors during code development

There are multiple errors in your code.
In the loop, the first if might not have the use you intended it to have. You are checking for previous == low, but you never set previous to high. Therefore this check can be removed entirely, or you could restructure your code a bit and add a previous = high.
Secondly, this if is also flawed:
if (millis_held >= 1000 && firstTime <2000){
    digitalWrite(3, HIGH);
}

You are checking for firstTime < 2000 which means you need to press the button within 2 seconds of the power-up of the Arduino or else this code will not run.
Lastly, for this to run you probably only want to set firstTime = millis() once when you press the button, and not every time the loop() runs thereafter while you keep the button pressed. You would need to move the bracket on line 32 to line 22, that is from just above the else to the line above millis_held = (millis() - firstTime); and then add previous = HIGH; in the first if.
I am leaving it to you to fix your code, since that would be good practice to get some feeling for it. Happy coding!
Lastly you still need to add the last 5 leds, but once the first few work you should be fine.

Thanks a lot for your advise, I think I kinda get it, allow me some time to digest and work on it. I will get back to you soon. Appreciate your help!!!

Great thanks to Ananas_hoi, I was finally able to get my code work accordingly!! The following code only show the 4 LED to be lights up one by one every second when the button was pressed and hold:
int current;
long millis_held;
unsigned long firstTime;
byte previous = LOW;

const int buttonPin = 13;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(2,OUTPUT) ;
  pinMode(3,OUTPUT) ;
  pinMode(4,OUTPUT) ;
  pinMode(5,OUTPUT) ;
}

void loop() {
  current = digitalRead(buttonPin);

  if (current == HIGH && previous == LOW) {
     firstTime = millis();
     digitalWrite(2, HIGH);
     previous = HIGH;
  }

  millis_held = (millis() - firstTime);

  if (millis_held >= 1000 && previous == HIGH) {
      digitalWrite(3, HIGH);
     }

  if (millis_held >= 2000 && previous == HIGH) {
      digitalWrite(4, HIGH);
     }

  if (millis_held >= 3000 && previous == HIGH) {
      digitalWrite(5, HIGH);
     }

  if (current == LOW) {
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  previous = LOW;
 }
}

Thanks for posting the solution. (voted.) Lots of new users don't give back like that. This way others can learn from your project. The indentation in your answer is much better than in your original question, but still needs some cleanup. Could you indent the code inside the braces from the if (current == low) statement? And it would be better for new readers if you cleaned up the indentation of your original question. It's pretty hard to read as is.


text:
SPI slave ISR not being called randomly
So I am trying to have a full-duplex high-speed(I'll be reducing the delay to microseconds once the below problem is solved) comm. between two Arduino Unos. Here is the code below:
Master:
volatile uint8_t rdata;

#define SCK   13  // D13 = pin19 = PortB.5
#define MISO  12  // D12 = pin18 = PortB.4
#define MOSI  11  // D11 = pin17 = PortB.3
#define SS    10  // D10 = pin16 = PortB.2

void SPI_MasterInit(void)
{
  /* Set MOSI and SCK output, all others input */
  //DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK);
  pinMode(MOSI, OUTPUT);
  pinMode(MISO, INPUT);
  pinMode(SCK, OUTPUT);
  pinMode(SS, OUTPUT);
  /* Enable SPI, Master, set clock rate fck/4 */
  SPCR = (1 << SPE) | (1 << MSTR) | (0 << SPI2X) | (0 << SPR1) | (0 << SPR0) ;
  SPCR |= _BV(CPOL);
  //SPCR |= _BV(CPHA);

}

void SPI_MasterTransmit(uint8_t data) {
  PORTB &= ~(1<<2);
  SPDR = data;
  //asm volatile("nop");
  while (!(SPSR & (1 << SPIF)));
  rdata = SPDR;
  PORTB |= 1 << 2;
  Serial.print("data "); Serial.print(data); Serial.print(" rdata "); Serial.println (rdata);

}

void setup (void)
{
  Serial.begin(115200);
  PORTB |= 1 << 2; //digitalWrite(SS, HIGH);
  SPI_MasterInit();
}

void loop (void)
{

  for (byte i = 0; i < 10; i++) {

    SPI_MasterTransmit(i);

    //Serial.print(m);
    delay(100);

  }
}

Slave:
volatile boolean process_it;
volatile byte indx = 129, c = 0;

#define SCK   13  // D13 = pin19 = PortB.5
#define MISO 12  // D12 = pin18 = PortB.4
#define MOSI 11  // D11 = pin17 = PortB.3
#define SS    10  // D10 = pin16 = PortB.2

void SPI_SlaveInit(void)
{
  /* Set MISO output, all others input */
  //DDR_SPI = (1<<DD_MISO);
  pinMode(MOSI, INPUT);
  pinMode(MISO, OUTPUT);
  pinMode(SCK, INPUT);
  pinMode(SS, INPUT);
  /* Enable SPI */
  SPCR |= _BV(SPE); // SPI Enable, sets this Arduino to Slave
  SPCR |= _BV(SPIE); // SPI interrupt enabled
  SPCR |= _BV(CPOL);
  //SPCR |= _BV(CPHA);
}

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

  SPI_SlaveInit();

}

// SPI interrupt routine
ISR (SPI_STC_vect)
{

  SPDR = indx;
  indx--;
  if (indx < 121)
    indx = 129;
  c = SPDR;
  process_it = true;

}

void loop (void)
{
  if (process_it) {

    Serial.println (c);

    process_it = false;

  }

}

Below output shows the o/p of the master on the left and slave one the right:

The master prints the data it has sent(to the slave, "data" variable) followed by the data it has received (from the slave, "rdata" variable). The slave simply prints the received data (from the master).
If you look carefully at the pic you would see that the master sometimes gets the same data (in the next cycle)  it has sent (in the current cycle) (0 and 4 in the pic). At the same time, the slave fails to receive exactly that data (0,4). Also, you can the value of 'indx' is not decremented and the master receives the decremented value in the next cycle. These two things prove that the Slave ISR is not being called randomly (hence the data in the SPDR is not read which is then echoed back to the master plus the index variable is not decremented). Is there a solution to this? I would be really grateful if someone could help me with this.
Edit: I face the exact same problem with the default arduino SPI library, here is the code:
Master:
#include <SPI.h>
volatile byte m=0;
void setup (void)
{
    pinMode(MOSI, OUTPUT);
    pinMode(MISO, INPUT);
    pinMode(SCK, OUTPUT);
    pinMode(SS, OUTPUT);

  Serial.begin (115200);
  Serial.println ();

  digitalWrite(SS, HIGH);

  SPI.begin ();

  SPI.setClockDivider(SPI_CLOCK_DIV4);
}

void loop (void)
{
for(byte i=0; i<10; i++){
  digitalWrite(SS, LOW);
  m = SPI.transfer (i);
  digitalWrite(SS, HIGH);
      Serial.print("data "); Serial.print(i); Serial.print(" rdata "); Serial.println (m);
  delay(100);
}
}

Slave:
#include<SPI.h>

volatile byte c = 0, indx =129;
volatile boolean process_it = false;
void setup (void)
{
  pinMode(MOSI, INPUT);
  pinMode(SCK, INPUT);
  pinMode(SS, INPUT);

  pinMode(MISO, OUTPUT);

  // turn on SPI in slave mode
  SPCR |= _BV(SPE);
  Serial.begin (115200);

 SPI.attachInterrupt();

}  // end of setup

// SPI interrupt routine
ISR (SPI_STC_vect)
{

      SPDR = indx;
      indx--;
      if (indx < 121)
        indx = 129;
      c = SPDR;
      process_it = true;

}  // end of interrupt service routine (ISR) SPI_STC_vect

 void loop (void)
    {
      if (process_it) {

        Serial.println (c);

        process_it = false;

      }

    }

Why not use the SPI library that does all this for you and has examples that are known to work?

@Majenko Two reasons, I have observed the exact same problem with the SPI library and I need a C implementation instead of C++;

Can I suggest, then, for our benefit, that you show us the SPI library based variant (since it's easier for us to follow)? If the two show the same problem it's not your code as such, it's your methodology that is flawed.  Also showing what you expect the outputs to show would help.

@Majenko I have added the SPI equivalent code. The thing is since the SPI interrupt is not getting called sometimes, you can see that the slave is missing data byte from the master (the master is receiving its own data after a cycle since the slave is not clearing/writing the SPDR register). I would like the slave to receive all the data that is being transmitted by the master and vice versa. I wouldn't want the master to receive its own data.

The part where you write indx to SPDR before reading SPDR and put in c, looks odd to me. It probably works because it's internally buffered, but it looks very wrong to me. I can't see anything in the datasheet that suggests this would work. I'd try putting c=SPDR before SPDR=indx

@Gerben I have tried that as well. It doesn't change the situation at all. I am still missing ISR calls at random on the slave side.

I'm stumped. Try using a different Arduino board. Or swapping them.


text:
Transfer analog value via Bluetooth HC-05 (master) to second HC-05 (slave)
II have setup a UNO and a HC-05 Bluetooth module as a 'Slave', and a NANO and an HC-05 Bluetooth module as 'Master', I believe the comm's work ok as I am receiving values and text, but the analog IN via a pot on the 'Master' (NANO) reads fine on the master Serial Screen, but does not read the same on the Slave (UNO)serial screen,the values received are changing from accurate to inaccurate on during data transfer.
I was hoping for a continuous accurate stream as the pot will be replaced with a 'load cell' and I need to capture weight readings and display them on a time base, I used bluetooth as the load cell and 'Slave' will be approx 5m apart. I would appreciate any help and I can send the sketch if you wish?
Regards, Gordon

do you have a question?

and I can send the sketch if you wish? -- It's not a wish - it's a requirement. There's no chance we can have even the slightest clue what is going on unless you show us your sketch (and by "show" I mean edit your question and include the text of the sketch in the question - not a photo, not a link, the text - and format it correctly with three back-ticks on the line before and three on the line after).


text:
Arduino DS3231 error: no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'
I am building a arduino based bicycle speedometer with time and temperature display.
Im currently stuck with the DS3231 (zs-042) chip. I found online a lot of library issues, i tried using
multiple libraries (Rinky-Dink, ds3231-master) but nothing works. I found a simple code online to test the chip but when I upload it the following error shows up: "no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)"
#include <Wire.h>
#include <DS3231.h>
DS3231  rtc(SDA, SCL);

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

  // Initialize the rtc object
  rtc.begin();
  rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014
}

void loop()
{
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");

  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());

  // Wait one second before repeating :)
  delay (1000);
}

The error occurs in the third line (rtc (SDA,SCL)) - I have checked the pins and switched the battery on the chip. I also tried using A4 and A5 instead of SDA and SCL pins...
Any type of help would be awesome.
Best regards,
Marin

Alright I found the problem.
https://www.youtube.com/watch?v=BM3A7w3bhqM&ab_channel=MERTKILIC
In this video at 5:00 you can see the following:
First you have to download the library, unzip it and copy the files inside.
You will have to paste it to your Arduino/Libraries/DS3231 folder.

On the left is the current DS3231 Library which I added through the arduino library manager. Its not the same as the one the right, it should be, but its not, copy the files from the unzipped DS32321 library into the Arduino/library/DS3231.
Works fine now !

Any reason why you did not simply install it via the Library Manager?

I did and it didnt work


text:
Arduino array error
I'm writing a program that has a sub program that saves values to an array, but the sub program that saves the values to the array comes back with an error telling me that the array isnt declared in that scope.
I'm fairly new to this and self taught but even when I try and pass the array into the sub program I get the same error. I'm sure its a fairly simple obvious error I'm making but I just cant get it to work.
If anyone sees any other errors or better ways for me to write any of this any help would be greatly valued as I'm still not confident on what I'm supposed to be doing.
#include <HX711.h>

#include <Wire.h>  // IC2 communication

#include <LiquidCrystal_I2C.h>  //LCD
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD.

int max_load;
int interval;
int max_load_prev;
int interval_prev;
int mode;
int handle_weight;
int tip_weight;
int stop1;
int mode_previous;
int interval_sum;

int mode1 = 53;
int mode2 = 51;
int mode3 = 49;
int start1 = 39;
int start2 = 37;
int increment = 47;
float potentiometer1 = A0;
float potentiometer2 = A1;
int tare_1 = 45;
int tare_2 = 43;

//stepper motor controller
int stepPin = 12;
int dirPin = 13;

//sensor readings
  HX711 tip_read;
  HX711 handle_read;
  int DOUT_tip = 6;
  int DOUT_handle = 5;
  int CLK_tip = 4;
  int CLK_handle = 3;

void setup() {
  // put your setup code here, to run once:

  lcd.init();
  lcd.backlight();

  //saving to array//
  float data_storage_array[600][3];

  pinMode(mode1, INPUT);
  pinMode(mode2, INPUT);
  pinMode(mode3, INPUT);
  pinMode(start1, INPUT);
  pinMode(start2, INPUT);
  pinMode(increment, INPUT);
  pinMode(stop1, INPUT);
  pinMode(potentiometer1, INPUT);
  pinMode(potentiometer2, INPUT);

  //sesnor readings
  tip_read.begin(DOUT_tip, CLK_tip);
  tip_read.set_scale(55);// change to calibration factor
  handle_read.begin(CLK_tip,CLK_handle);
  handle_read.set_scale(55);// change to calibration factor

  pinMode(tare_1, INPUT);
  pinMode(tare_2, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  mode_previous = 0;
  interval = 25;
  max_load_prev = 0;
  interval_prev = 0;
  interval_sum = 0;
  while (digitalRead(start1) == 0) {
    if (digitalRead(mode1) == 1) {
      mode = 1;
    }
    if (digitalRead(mode2) == 1) {
      mode = 2;
    }
    if (digitalRead(mode3) == 1) {
      mode = 3;
    }
    if (mode_previous != mode) {
      Display_mode_set_up(mode);
      mode_previous = mode;
    }
    if (digitalRead(increment) == 1) {
      delay(500);
      if (interval >= 1000) {
         interval = 25;
      }
      else if (interval < 1000) {
        interval = interval + 25;
      }
    }
    max_load = max_load_reading();
    if (max_load_prev != max_load or interval_prev != interval){
      Display_value_set_up(max_load, interval, mode);
      max_load_prev = max_load;
      interval_prev = interval;
    }
    Display_output(handle_weight, tip_weight);

  tare_one();
  }
  if (mode == 1) {
    mode_one(max_load, tip_weight);
  }
  else if (mode == 2) {
    mode_two(max_load, interval, handle_weight, tip_weight);
  }
  else if (mode ==3) {
    mode_three(max_load, interval, handle_weight, tip_weight);
  }
  Pause_stop();
}

//---SUB ROUTINES---

void mode_one(int max_load, int tip_weight) {
  tip_weight = read_tip();
  while (tip_weight < max_load) {
    tip_weight = read_tip();
    turn_motor();
    Pause_stop();
    Display_output(handle_weight, tip_weight);
  }
}

void mode_two(int max_load, int interval, int handle_weight, int tip_weight) {
  int aim_value;
  aim_value = 0 + interval;
  tip_weight = read_tip;
  while (tip_weight < max_load){
    while (tip_weight < aim_value){
      turn_motor();
      Pause_stop();
      Display_output(handle_weight, tip_weight);
      tip_weight = read_tip();
    }
    save_to_array(interval_sum);
    aim_value = aim_value + interval;
    while (digitalRead(start2) == 0) {
      delay(1);
    }
  }
  send_values_to_pc();
}

void mode_three(int max_load, int interval, int handle_weight, int tip_weight) {
  int aim_value;
  aim_value = 0 + interval;
  tip_weight = read_tip();
  while (tip_weight < max_load) {
    while (tip_weight < aim_value) {
      turn_motor();
      Pause_stop();
      Display_output(handle_weight, tip_weight);
      tip_weight = read_tip();
    }
    save_to_array(interval_sum);
    aim_value = aim_value + interval;
    delay(10000);
  }
  send_values_to_pc();
}

void tare_one() {
  if (tare_1 == HIGH) {
    tip_read.tare();
  }
  if (tare_2 == HIGH) {
    handle_read.tare();
  }
}

void turn_motor() {
  digitalWrite(dirPin, HIGH);
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(500);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(500);
}

int read_tip() {
  int weight;
  weight = tip_read.get_units();
  return weight;
}

int read_handle() {
  int weight;
  weight = handle_read.get_units();
  return weight;
}

void save_to_array(int interval_sum) {
  data_storage_array[interval_sum][0] = interval_sum;
  data_storage_array[interval_sum][1] = tip_read.get_units();
  data_storage_array[interval_sum][2] = handle_read.get_units();
  interval_sum = interval_sum + 1;
}

void send_values_to_pc() {
}

int max_load_reading() {
  int KG_value;
  int g_value;
  int load_max;
  KG_value = analogRead(potentiometer1);
  g_value = analogRead(potentiometer2);
  KG_value = KG_value * 2;
  KG_value = KG_value/ 100;
  KG_value = round(KG_value);
  KG_value = KG_value* 100;
  g_value = g_value/ 10;
  g_value = round(g_value);
  if (g_value >= 100){
    g_value = 99;
  }
  load_max = KG_value + g_value;
  return load_max;
}

void Pause_stop() {
  if (digitalRead(stop1) == 1){
    delay(1000);
    while (digitalRead(start1) == 0){
      if (digitalRead(stop1) == 1){
        motor_unwind();
      }
      else{
        delay(100);
        lcd.setCursor(0, 2);
        lcd.print("Program Paused");
      }
    }
    lcd.setCursor(0, 2);
    lcd.print("                    ");
  }
}

void motor_unwind() {
  tip_weight = read_tip();
  while (tip_weight < 100) {
    digitalWrite(dirPin, LOW);
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(500);
  }
  int count = 100;
  while (count > 0) {
    digitalWrite(dirPin, LOW);
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(500);
    count = count -1;
  }
}

void Display_mode_set_up(int mode) {
  lcd.setCursor(0, 0);
  if (mode == 1) {
    lcd.print("Mode: Max           ");
    lcd.setCursor(0, 1);
    lcd.print("MLoad:");
    lcd.setCursor(12, 1);
    lcd.print("inti:---");
  }
  if (mode == 2) {
    lcd.print("Mode: Incrimental    ");
    lcd.setCursor(0, 1);
    lcd.print("MLoad:");
    lcd.setCursor(12, 1);
    lcd.print("inti:   ");
  }
  if (mode == 3) {
    lcd.print("Mode: Automatic      ");
    lcd.setCursor(0, 1);
    lcd.print("MLoad:");
    lcd.setCursor(12, 1);
    lcd.print("inti:   ");
  }
  lcd.setCursor(0, 3);
  lcd.print("Tip:");
  lcd.setCursor(9, 3);
  lcd.print("Handle:");
}

void Display_value_set_up(int max_load, int interval, int mode) {
  if (mode == 1) {
    lcd.setCursor(6, 1);
    lcd.print("      ");
    lcd.setCursor(6, 1);
    lcd.print(max_load);
  }
  if (mode == 2 or mode == 3) {

    lcd.setCursor(6, 1);
    lcd.print("      ");
    lcd.setCursor(6, 1);
    lcd.print(max_load);

    lcd.setCursor(17, 1);
    lcd.print("   ");
    lcd.setCursor(17, 1);
    lcd.print(interval);
  }
}

void Display_output(int handle_weight, int tip_weight) {
  tip_weight = read_tip();
  handle_weight = read_handle();
  lcd.setCursor(4, 3);
  lcd.print(tip_weight);
  lcd.setCursor(16, 3);
  lcd.print(handle_weight);
}

Google “C++ scope” and do some reading about what variable scope means.  It will all make sense pretty quick.

You are declaring float data_storage_array[600][3] in setup(), and using it in another function, that can't "see" it.
The simplest way of making it work is making your array global by declaring it at the top in the section where you declare other variables like max_load.

As others have mentioned, your array is out of scope and can only be used in the setup() function. I have moved this out of the setup() function and into the global variable section.
I am also cautious of how much SRAM you were using with your (600 x 3 =) 1800 float elements. So I have changed it to ints and reduced it to 250 x 3. You have put down that you are using the Arduino Mega, so this could be expanded further if necessary.
Your variable interval_sum was set to increment with no upper limit. This means you would end up going beyond the limits of the array. I have fixed this.
I have reviewed your code briefly and added some fixes and some comments. It is untested. I hope this helps you.
#include <HX711.h>
#include <Wire.h>  // IC2 communication
#include <LiquidCrystal_I2C.h>  //LCD

LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD.

int max_load;
int interval;
int max_load_prev;
int interval_prev;
int mode;
int handle_weight;
int tip_weight;
int stop1;
int mode_previous;
int interval_sum;

const int mode1 = 53;    // <-- added the const keyword to all pin definitions as they dont change
const int mode2 = 51;
const int mode3 = 49;
const int start1 = 39;
const int start2 = 37;
const int increment = 47;
const int potentiometer1 = A0;    // <-- Changed to int as it is only a pin definition
const int potentiometer2 = A1;    // <-- Changed to int as it is only a pin definition
const int tare_1 = 45;
const int tare_2 = 43;

//stepper motor controller
const int stepPin = 12;
const int dirPin = 13;

//sensor readings
HX711 tip_read;
HX711 handle_read;
int DOUT_tip = 6;
int DOUT_handle = 5;
int CLK_tip = 4;
int CLK_handle = 3;

//saving to array//
int data_storage_array[250][3];    // <-- Moved before setup(). Changed to int. Reduced to 250x3 elements.

void setup() {
  // put your setup code here, to run once:
  lcd.init();
  lcd.backlight();

  pinMode(mode1, INPUT);
  pinMode(mode2, INPUT);
  pinMode(mode3, INPUT);
  pinMode(start1, INPUT);
  pinMode(start2, INPUT);
  pinMode(increment, INPUT);
  pinMode(stop1, INPUT);
  pinMode(potentiometer1, INPUT);
  pinMode(potentiometer2, INPUT);

  //sesnor readings
  tip_read.begin(DOUT_tip, CLK_tip);
  tip_read.set_scale(55);// change to calibration factor

  handle_read.begin(CLK_tip,CLK_handle);
  handle_read.set_scale(55);// change to calibration factor

  pinMode(tare_1, INPUT);
  pinMode(tare_2, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  mode_previous = 0;
  interval = 25;
  max_load_prev = 0;
  interval_prev = 0;
  interval_sum = 0;
  while (digitalRead(start1) == 0){
    if (digitalRead(mode1) == 1){
      mode = 1;
    }
    if (digitalRead(mode2) == 1){
      mode = 2;
    }
    if (digitalRead(mode3) == 1){
      mode = 3;
    }
    if (mode_previous != mode){
      Display_mode_set_up(mode);
      mode_previous = mode;
    }
    if (digitalRead(increment) == 1){
      delay(500);
      if (interval >= 1000){
         interval = 25;
      }
      else if (interval < 1000){
        interval = interval + 25;
      }
    }
    max_load = max_load_reading();
    if (max_load_prev != max_load or interval_prev != interval){
      Display_value_set_up(max_load, interval, mode);
      max_load_prev = max_load;
      interval_prev = interval;
    }
    Display_output(handle_weight, tip_weight);
    tare_one();
  }
  if (mode == 1){
    mode_one(max_load, tip_weight);
  }
  else if (mode == 2){
    mode_two(max_load, interval, handle_weight, tip_weight);
  }
  else if (mode ==3){
    mode_three(max_load, interval, handle_weight, tip_weight);
  }
  Pause_stop();
}

//---SUB ROUTINES---

void mode_one(int max_load, int tip_weight){
  tip_weight = read_tip();
  while (tip_weight < max_load){
    tip_weight = read_tip();
    turn_motor();
    Pause_stop();
    Display_output(handle_weight, tip_weight);
  }
}

void mode_two(int max_load, int interval, int handle_weight, int tip_weight){
  int aim_value;
  aim_value = 0 + interval;
  tip_weight = read_tip;
  while (tip_weight < max_load){
    while (tip_weight < aim_value){
      turn_motor();
      Pause_stop();
      Display_output(handle_weight, tip_weight);
      tip_weight = read_tip();
    }
    save_to_array();    // <-- Global variable removed
    aim_value = aim_value + interval;
    while (digitalRead(start2) == 0){
      delay(1);
    }
  }
  send_values_to_pc();
}

void mode_three(int max_load, int interval, int handle_weight, int tip_weight){
  int aim_value;
  aim_value = 0 + interval;
  tip_weight = read_tip();
  while (tip_weight < max_load){
    while (tip_weight < aim_value){
      turn_motor();
      Pause_stop();
      Display_output(handle_weight, tip_weight);
      tip_weight = read_tip();
    }
    save_to_array();    // <-- Global variable removed
    aim_value = aim_value + interval;
    delay(10000);
  }
  send_values_to_pc();
}

void tare_one(){
  if (tare_1 == HIGH) {
    tip_read.tare();
  }
  if (tare_2 == HIGH) {
    handle_read.tare();
  }
}

void turn_motor(){
  digitalWrite(dirPin, HIGH);
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(500);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(500);
}

int read_tip(){
  int weight;
  weight = tip_read.get_units();
  return weight;
}
int read_handle(){
  int weight;
  weight = handle_read.get_units();
  return weight;
}

void save_to_array(){    // <-- Global variable removed
  data_storage_array[interval_sum][0] = interval_sum;
  data_storage_array[interval_sum][1] = tip_read.get_units();
  data_storage_array[interval_sum][2] = handle_read.get_units();
  if (interval_sum >= 249){   // <-- Added this if statement as there was no way to cap this number
      interval_sum = 0;
  }
  else{
      interval_sum = interval_sum + 1;
  }
}

void send_values_to_pc(){

}

int max_load_reading(){
  int KG_value;
  int g_value;
  int load_max;
  KG_value = analogRead(potentiometer1);
  g_value = analogRead(potentiometer2);
  KG_value = KG_value * 2;
  KG_value = KG_value/ 100;
  KG_value = round(KG_value);
  KG_value = KG_value* 100;
  g_value = g_value/ 10;
  g_value = round(g_value);
  if (g_value >= 100){
    g_value = 99;
  }
  load_max = KG_value + g_value;
  return load_max;
}

void Pause_stop(){
  if (digitalRead(stop1) == 1){
    delay(1000);
    while (digitalRead(start1) == 0){
      if (digitalRead(stop1) == 1){
        motor_unwind();
      }
      else{
        delay(100);
        lcd.setCursor(0, 2);
        lcd.print("Program Paused");
      }
    }
    lcd.setCursor(0, 2);
    lcd.print("                    ");
  }
}

void motor_unwind(){
  tip_weight = read_tip();
  while (tip_weight < 100){
    digitalWrite(dirPin, LOW);
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(500);
  }
  int count = 100;
  while (count > 0){
    digitalWrite(dirPin, LOW);
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(500);
    count = count -1;
  }
}

void Display_mode_set_up(int mode){
  lcd.setCursor(0, 0);
  if (mode == 1){
    lcd.print("Mode: Max           ");
    lcd.setCursor(0, 1);
    lcd.print("MLoad:");
    lcd.setCursor(12, 1);
    lcd.print("inti:---");
  }
  if (mode == 2){
    lcd.print("Mode: Incrimental    ");
    lcd.setCursor(0, 1);
    lcd.print("MLoad:");
    lcd.setCursor(12, 1);
    lcd.print("inti:   ");
  }
  if (mode == 3){
    lcd.print("Mode: Automatic      ");
    lcd.setCursor(0, 1);
    lcd.print("MLoad:");
    lcd.setCursor(12, 1);
    lcd.print("inti:   ");
  }
  lcd.setCursor(0, 3);
  lcd.print("Tip:");
  lcd.setCursor(9, 3);
  lcd.print("Handle:");
}

void Display_value_set_up(int max_load, int interval, int mode){
  if (mode == 1){
    lcd.setCursor(6, 1);
    lcd.print("      ");
    lcd.setCursor(6, 1);
    lcd.print(max_load);
  }
  if (mode == 2 or mode == 3){

    lcd.setCursor(6, 1);
    lcd.print("      ");
    lcd.setCursor(6, 1);
    lcd.print(max_load);

    lcd.setCursor(17, 1);
    lcd.print("   ");
    lcd.setCursor(17, 1);
    lcd.print(interval);
  }
}

void Display_output(int handle_weight, int tip_weight){
  tip_weight = read_tip();
  handle_weight = read_handle();
  lcd.setCursor(4, 3);
  lcd.print(tip_weight);
  lcd.setCursor(16, 3);
  lcd.print(handle_weight);
}


text:
Get more PCINT capable pins on Mega 2560
I'm building kinda "ball game" for a total of 6 players based on these per-player specs:

1 stepper motor with 4 pins
2 end stops (start & finish) per motor
1 finish LED
3 holes to score, resulting in slow, medium or fast motor movement

Additionally, there's a "master reset" to move all motors back to their starting end stops.
Because of my initial assumption, 54 pins would be enough, I didn't realize actually requiring 60 pins (24 for motors, 12 for end stops, 6 for LED, 18 for holes). I'm also neither an expert at microelectronics nor C programming language, but my understanding of the Mega's pins is that I need 12 + 18 PCINT capable pins (end stops + holes) while only 16 pins are available.
So far, the only information I could find suggests buying an Arduino Shield to resolve this by providing additional 16 PCINT pins. But being connected via I2C, I suspect delays resulting in unequal treatment of player scores.
How to get at least 30 PCINT capable pins, treated equally by Arduino? In case there's no need for the PCINT requirement, which pins can be used as an alternative?

If you write good code you won’t need an interrupt for any of that.  Do you think that switch can make and break in less than a millisecond?  For comparison blinking your eyes takes about 200ms.  Don’t use delay for timing and you won’t need any interrupt for this.

If you want more PCINT you can do it yourself outside the chip. Just AND or OR (depending on if you want active LOW or HIGH) multiple signals together and feed the result into a single interrupt pin in addition to each signal into its own digital pin, then when the single interrupt occurs poll the other digital pins to see which changed.

@Delta_G How to? The current code within Arduino's loop() actually does use delay between setting e. g. the steppers to allow for kinda "cooldown". It's not that I want 1 ms response time, it's more in terms of "chance equality" between all players.

@Majenko So, you're suggesting me to, e. g. combine all 6 PCINT inputs into 1 and upon the interrupt, poll all 6 to find the right one? What about player #2 hitting the same hole (on his table, not player #1's table)? Wouldn't that be swallowed in vain then?

I wouldn't know. I have no idea what holes you're talking about, nor how a player "hits" them.

@Majenko It's kinda table game where a player needs to throw a ball into 1 out of 3 holes to then let his avatar move forward until any player reaches the finish line.

And...? You still haven't explained your concern in a way that is meaningful to someone that has no clue how your game is intended to work.

@Majenko I'm thinking of this: P1 throws ball into hole A, PCINT for all 6 players's A-hole (no pun intended), or in case all 3 types of holes, i. e. A, B & C, are tied together onto 1 PCINT, their triggering prevents detection of any other player's hit of hole A, B or C at their lane.

I think you missed the bit where I mentioned "in addition to each signal into its own digital pin" (I even had it in italic...). One interrupt fires. That interrupt then looks at other pins to see what is active. Of course the incoming signals have to last long enough for the polling to see them. If they are very very brief then you may want to latch them, maybe with an S-R latch, which is then reset by the MCU when it's been read.

I did read it, it's just that your creating the exact "why can't you see, it's so simple" mood that prevented me from even writing the OP in the first place. I'm a .NET dev in my day job, so working with (from my POV and not meant to be rude in any way) low-level stuff isn't as accessible as I hoped for in order to help my friend (for whom I write/wrote the code as he neither speaks English nor is able to write code). I just want this board to recognize inputs, but I'm near zero with knowledge what (extension) board/chip/etc. I need to buy & put where, get its lib from where & compile.

If you’re that newbie then why are you messing with advanced concepts like interrupts?   Get some experience with the basics first.  Like I said before none of this should require interrupts.  Just don’t use delay for timing.  If you want the code to do nothing then let the loop function run doing nothing.  But you don’t need any interrupt.

Beause I understand the concept of interrupts which is why they're not an advanced concept to me. Getting a LED on/off was as simple as moving stepper motors - but then there's a gap which I blame lack of official docs for as they rather created the new name "shields" instead of giving useful examples. That put aside, I don't understand how you read my words as "loop function shall do nothing in between". Again, please explain how am I supposed to get notified of a changed input without a) a PCINT or b) polling all such inputs every now and then. Maybe you can show an (abstract) code example?

The Atmega2560 has a total of 24 pins associated to the PinChange interrupt. You cannot change that. It is an internal property of the microcontroller.
As you already have seen yourself, you need to use extra chips to extent the available IO pins. There are different options to consider:

IO-Port-Expanders (available for I2C or SPI) (for example the PCF8574. Don't know, if that is the best, just the port expander, that I also used myself)
Shift-In (for inputs) or Shift-Out (for outputs) registers (often used are the 74HC595 (Shift-out register) and the 75HC165 (Shift-In register). I often used this tutorial as reference)

As you don't want to poll these chips all the time, I suggest, that you use one, which provides an additional interrupt pin. That pin will change its value, when one of the input changes. You could then connect this pin to one of the interrupt pins of the Atmega2560. When the interrupt triggers, you can read the states of the input pins.

But being connected via I2C, I suspect delays resulting in unequal treatment of player scores.

Indeed that wouldn't be good. So you should divide the pins up by their purpose, not by their association to a player. For example all end stop inputs, or all outputs for the stepper motors. Then you need to access, what timing requirements each group has. Then you can take the group with the lowest requirements and check, if and which chip would be able to handle the data fast enough. For example the "finish LED". You didn't specify, what exactly it does, but I guess, that it is not really time critical. So you could handle all finish LEDs via a single shift-out register.
Or take the inputs for the holes: I guess here you have some sensor, that triggers, when a ball passes it. Check how long the sensor get's triggered. Most likely (depending on the type of sensor) this depends on the speed of the ball. Take a speed, that you want to consider maximum (for example the pitching speed of a good baseball player, as these are really high), and calculate, how long the resulting pulse will be. The chip, that you choose, might be fast enough for this. So you could handle all ball hole inputs over extra chips (meaning chips providing extra input chips, like a Shift-In register or a port expander).

In case there's no need for the PCINT requirement, which pins can be used as an alternative?

Every pin capable of digital IO. That's nearly every pin on the Arduino Mega. Though that means, that you cannot use interrupts for them and you have to poll then constantly. That might be ok for you. It really depends on your exact timing requirements.

I thought polling was a "avoid where possible"-area?!

Yes and no. First you asked for the possibility of using other pins, so I mentioned that above. Though doing that means using no PinChange interrupt. Generally polling is bad, when

you spend too much time on it, leaving no time for other functions of the code, or
if the events, that you are polling, are too short for your polling code.

That can happen in the cases, that

you use blocking code to poll (like waiting with a while loop for a button press), which blocks all other functions from executing.
your code needs a long enough event to register it (for example the signal from your hole sensors might be very short. If your polling interval is bigger than that, you will loose some events)

If you stay inside of the confinements and use non-blocking code, there is nothing bad with polling.
Let's take the often used Bounce2 library for Arduino. It helps you with reading buttons and handles the debouncing for you. It does not use any interrupts. You are expected to call Bounce.update() often enough to catch all button presses, which is typically a few ms at max. But since the Arduino Mega runs on 16MHz, it is capable of way faster speeds than the few ms. Calling Bounce.update() often enough is easy, when you don't write code, that stays a long time to execute. So no delays, except for maybe very short ones. Instead you can use the coding style of the BlinkWithoutDelay example, that comes with the Arduino IDE. It uses the millis() function as a time base to check repeatedly, if it is time to do something, and only do so, if it really is time for it. Much like you are baking a pizza by putting it into the oven and then regularly watch at your clock, if it is time to get the pizza out of the oven. You don't want to sit in front of the oven waiting for pizza. The analog of doing that is writing blocking code with delay().
So all in all about polling vs interrupts: It depends on your requirements. Fast response times or short events often need interrupts, though you need to cope with limited usable pin numbers and different interrupts (which is a bit more complex to code). Polling - when done right - can give you big freedom and rather easy handling, while saving interrupt sources for more important functions. Though it poses bigger limits on response times and the duration of events. Also it depends strictly on the rest of your code.

Note, that in the above, terms like "time critical", "fast response times" and such are more meant for the region of a low number of microseconds. Timings in the millisecond range can easily be done by using the mentioned non-blocking coding style (either with millis(), or for greater resolution and accuracy at low numbers of milliseconds micros()). The principle is always the same and there are tons of tutorials about it on the web and even many questions and answers on this site. So you can google for this, to get a more detailed tutorial.

Sorry, my obligations prevented a sooner reply.. As I've got zero knowledge about I2C/SPI beyond their basic working, can you please recommand such an IO expander and/or a shift-in/-out register with such an additional interrupt pin? Regarding the "finish LED", the winning player's LED shines after his avatar crosses the finish line (and all 6 LED together upon reset-button press) - so yes, not time-critical at all. :) Yes, hole inputs work via sensor triggers. But I don't get what you mean by "extra chips" :( And regarding polling: I thought polling was a "avoid where possible"-area?!

@Yoda I added more information to my answer, including examples for possible parts (IO expander, Shift-in register, Shift-out register) and a section about polling vs interrupts. With "extra chips" I meant chips like the above, to get more IO pins.

thanks for your help, time and especially your useful explanations! I'll go for polling then, trying millis() & micros() first & falling back to 75HC165/74HC595 or PCF8574 if that doesn't work out. Again, thanks a lot for your valuable help!


text:
Transmitting multiple values to an Arduino, and interpreting them with minimum delay
I am building an underwater robot, which can move up/down and forward/reverse, controlled by a Joystick.
The situation is like this :
A USB joystick is connected to a PC, the PC is connected to an Arduino via a tether cable (Ethernet), and the motors of the robot are connected to the Arduino.
The joystick I am using has two sticks, and I have decided to use one stick to control the up/down movement (actually, I'm using only one axis of that stick for this) and the second stick to control the left/right movement.
Whenever the user manipulates both sticks simultaneously (to achieve diagonal motion, for example), the joystick will send two signals, one after the other, one for each stick.
Keeping in mind the limited receiver buffer size of the Arduino, how do I program the Arduino so that it can understand the difference between the linear motion signal and the diagonal motion signal?
I am highly motivated to program this on my own. I just need an intuition for this.
A thought came to my mind is, to use the following strategy:
For my up/down stick value, I add a character such as U, followed by the integer joystick value, e.g. I send U4 to go up at speed 4. With some twitching, I can even send a down signal with the same preceding character U.
Similarly, for forward/backward, I send F to go forward/backward at speed 3. And for diagonal, I send something like T5 to go diagonally at speed 5.
My concern with this is that I will transmit two characters from the PC to the Arduino. Will the Arduino be able to read these two characters, interpret them and act accordingly, without a noticeable lag? Or is there an other better way?
This also makes me wonder, how commercial robots (such as commercial drones) handle such situations?
The movements the robot will make need to be quick. There should not be "visible" lag, that is, the user should not feel that the robot is responding after a couple of seconds.

How exactly are you transmitting data between PC and Arduino? As I understood, you use ethernet. But how are you sending and receiving the data itself? Simple packets? Web sockets? That can account for the biggest lag in the system

Take a look at CAN, most CAN controllers will have a buffer(s) to hold incoming packets. Each packet can have 8 bytes and you can run at a million bits a second. There are some that will go even faster but that would be good for the Arduino modules like the MPC2515 and they are not expensive.

I don't know about commercial drones, however your 'protocol' seems to be quite efficient, as it uses 4 bytes to send 2 values (e.g. U3F5) for Up with speed 3 and Forward with speed 5.
Let's assume values from 0-7. Then you can send them both in 8 bits/one byte:
H H H H V V V V
Where H is the horizontal speed (from -8 (000) to +7 (111), in total 16 possible values.
For the vertical speed you can do the same.
So within one byte you send both speeds (meaning also there is no lag).
In case you need more accuracy, than send two bytes: one byte with horizontal and one byte with vertical speed. Depending on the sending/receiving speed I doubt there is any lag.
Even with your protocol I doubt there is a lag, but the above is more efficient.
I'm sure even more efficient algorithms can be created, probably by using the difference with the previous value (like sending delta values).
Another algorithm that can be created, assuming there is a big chance that only one of the two directions is changed (either horizontal or vertical is) and having a high accuracy
D V V V V V V V

Where D is the direction (0 = horizontal, 1 = vertical) and V is the value/speed (-64 to +63, 7 remaining bits).

The delta values might be problematic if a byte went missing, but otherwise a very nice idea!

@NickGammon Thanks ... It is also possible reserve another bit for a 'change' vs ''next value is absolute' value ... but that decreases the number of bits for the delta.


text:
Nano Every clone with ATMega4808 not recognized
I've bought an Arduino Nano Every clone/compatible (not a standard Nano V3) that uses an ATMega4808 instead of the ATMega4809 the official Nano Every uses. This rather insignificant change of chip is detected by the Arduino IDE (v. 1.8.13) which tells me that the chip is wrong when I select "Nano Every" from the boards list and try to upload a sketch. The seller (link to the product) does not answer to my help requests. Does anybody own one of these and knows how to make it run?
Below a photo of the board. Note the small difference in pinout (4 extra pin, D22, D23, D24 and UPDI)

Probled solved, it turns out to be a Thinary Nano Every.
Instructions for installing on the Arduino IDE are on Github here: https://github.com/Thinary/ThinaryArduino


text:
Failed HC-05 Bluetooth sketch upload - (port and board correct)
I'm running this project with HC-05 https://create.arduino.cc/projecthub/millerman4487/view-serial-monitor-over-bluetooth-fbb0e5 and I am getting connection error. I have ensured my port selected and board is accurate but no such luck. The Arduino uno is powered by 3.7v batt (output ~8v with reg) so it is simply just a battery connection and BT module, but when uploading the sketch, it fails. I am relatively new to arduino, and am not sure where to begin this debug.
I am using PC windows, and using a BT dongle receiver for connection (maybe this affects port comm?)
Thanks in advance
Here us the error message
Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino Uno"

Sketch uses 1954 bytes (6%) of program storage space. Maximum is 32256 bytes.

Global variables use 250 bytes (12%) of dynamic memory, leaving 1798 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=0x04

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x04

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x04

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x04

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x04

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x04

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x04

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x04

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x04

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x04

when uploading the code, did you ensure disconnecting the Rx, Tx pins from the Arduino? Coz this is a similar error you get when you upload code with your comm pins connected. Try uploading the code with no wires connected.

Ok, disconnected Rx, Tx, and was returned with this error

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x09

Restart your IDE and use a different com port for uploading.

tried, and still no luck


text:
unexpected output
I wrote some arduino code but since I don't have access to an arduino, ran it on a tinkercad circuit, the code is supposed to set all the buttons values to 1 and all the password values to 0 and the output "false password" as per the checkpassword function, but instead is outputting an infinite line of ÿÿÿÿÿÿÿÿÿÿÿÿ.
here is my code:
int i;
int passTrue[9];
int buttons[] {};

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10,INPUT_PULLUP);
  pinMode(13, OUTPUT);
}

int * SetButtons() {
  for (int i = 1; i<=9; ++i) {
    buttons[i] = digitalRead(i);
 }
  return buttons;
}

int * SetPass() {
  i = 0;
  for (i = 1; i<=9; ++i) {
     if(buttons[i] == LOW) {
      passTrue[i] = buttons[i];
     }
  }
return passTrue;
}

  void CheckPass() {
    for(i=1; i<=9; ++i) {
      if(passTrue[i] != buttons[i]) {
        Serial.println("false Password");
      } else {
        Serial.println("correct password");
      }
    }
  }

void Test() {
  for(i=1; i<=9; ++i) {
   buttons[i] = 0;
   passTrue[i] = 1;
  }
}

  void loop() {
SetButtons();
SetPass();
Test();
CheckPass();

  }

it shouldn't be relevant but attached is also my circuit:

int buttons[] {}; - I've got a bad news for you - this is not doing what you think it does

And also passTrue has 9 elements and the first element is on index 0. But you are starting on second element and accessing one element after the array (Welcome to the Buffer overflow world).

ÿÿÿÿÿÿÿÿÿÿÿÿ usually indicates a baud rate mismatch.

Since TinkerCAD handles baud rate matching automatically that is not the problem.  But  your buttons array looks problematic. My hunch is that you are corrupting memory and it's causing weird printing behaviour.

Just take int buttons [9]; instead of int buttons [] {}; and it should work.


text:
Servo motor analog vs digital and AC vs DC
I am little confused with servo motor terminology.
Q1. AC servo motor requires AC power source ?
Q2. DC servo motor requires DC power source ?
If answer to above 2 questions are YES then what does analog servo motor means.
Q3. Can I use arduino uno to control analog RC servo motor ?

Q1. AC servo motor requires AC power source ? Q2. DC servo motor requires DC power source ?

Yes. It's all down to the kind of motor that is used in the servo - an AC synchronous motor (often with VFD), a small DC brushed motor (the most common RC type) or a brushless DC motor.

Q3. Can I use arduino uno to control analog RC servo motor ?

Yes. That's precisely what the bundled Servo.h library is for. All the Arduino servo examples you will find online use analog RC servo motors.
The name "analog" though for those motors is not really 100% correct. They are driven by a PWM signal where the duty cycle is used to control the angle. The signal itself is 100% digital. The "analog" component comes in the form of the duty cycle of the signal.


text:
Use serial communication on Sparkfun SAMD21 mini board
I am working on an economic module to be able to use serial communication with the Sparkfun SAMD21 mini development card. And I have one, the DTR (of my CH340G) do I have to connect it to the reset of my MCU? I mean, to reset the board, do I just have to press the reset button on the module or both (the MCU and the USB / UART module)? I enclose the schematic of how I made the small module, if anyone has suggestions or recommendations, I appreciate them.

It occurred to me to review the diagram of the arduino nano, which has the integrated USB / UART bridge, and from what I see, the DTR connects to the reset of the microcontroller and then to the button.
Regards.

Why would you look at the schematic of the Nano which uses a completely different MCU and bootloader / programming system? You should look at a device that uses the same chip as the one you are using.

i search, but i only found the Arduino Zero, that dont use a USB/UART bridge in this format, that uses a  MCU.

the SAMD21 has native USB and Arduino core listens for 1200 baud short connection to invoke a reset to bootloader. nobody wires a USB chip to SAMD21. or a double reset activates the bootloader. what do you want to do with the CH340? do you have an UART bootloader for SAMD?

I was thinking that the D+ and D- on the SAMD21 are only to programm, (like the JTAG on FPGAs). So, i have a full COM connection with that same usb too?

look at Arduino SAMD21 boards schematics. Zero, MKR or Nano 33 IoT


text:
How to use ADC interrupt on STM32 blue pill
I'm currently using the STM32F1xx boards from http://dan.drown.org/stm32duino/package_STM32duino_index.json
To program my blue pill but I can’t find how to write the interrupt for the ADC. I’ve set the registers to output an interrupt when it finishes but I can’t find how to write the code for the interrupt.
I’ve tried the ”ISR(ADC_vect)” function which works for arduino, but the compiler is complaining that ”ISR” is not recognized. I’ve tried to look for the documentation for the STM32duino, but the little I could find didn’t even mention the ADC or any interrupt routines. I’ve searched though the STM32duino forum without any luck. If anyone knows how to solve this or where to find information about interrupt code for the STM32 boards I would be very happy :)

A quick google gave me void ADC_IRQHandler(){ ... }. Not sure if that's correct though, as I'm not familiar with STM32s.

@Gerben It did not work :(

As you already found, the function to override is __irq_adc() defined weakly here and bound to the interrupt vector table here.
If you've defined it and it's not working, it's probably because you got rid of the attachInterrupt() call entirely, which does more than just assign an interrupt handler; it also enables the interrupt for that ADC. So:
myADC.calibrate();
myADC.setSampleRate(ADC_SMPR_1_5);
adc_enable_irq(ADC1, ADC_EOC);
myADC.setPins(&pin, 1);

extern "C" void __irq_adc() {
// handle the interrupt
// make sure to check statuses and clear flags as shown in the default handler
}

Not sure if the extern "C" will be needed, probably will be, you'll have to check and find out.

This worked, though it only worked if I used the "attachInterrupt" on the ADC, did not seem to work using registers only :/ Maybe the attachInterrupt needs to be called to bind the __irq_adc function to the interrupt vector table? Also, extern "C" was required for it to work.

@BeaconofWierd I don't understand. You're still using the attachInterrupt() instead of overidding __irq_adc() directly? What exactly is working?

I tried to just add the __irq_adc() function, but then it was not called. When I also used the attachInterrupt() the __irq_adc() function was called. I tried to enable and disable intterupts using registers to see if that was the problem, but I was still only able to use __irq_adc() if I first called attachInterrupt() somewhere in the code. I verified that I was using the correct register to turn on interrupts by turning them off after calling attachInterrupt().

@BeaconofWierd That's weird. To be clear, you did add adc_enable_irq(ADC1, ADC_EOC); to replace attachInterrupt(), as I mentioned up there? Because with that in place, I see no difference at all with the existing attachInterrupt() call in STM32ADC.cpp. Also remember that you can't test with an empty __irq_adc(), you need to at least clear the EOC flag as shown in the default handler, else your code will seem hung. Also get rid of every other register-fiddling first.

If it still doesn't work, post your entire sketch. Think I have an STM32 around somewhere...

Ah, adding the adc_enable_ird also made it work :) Probably the better way to go than calling attachInterrupt(), when using that there seemed to be an issue where I couldn't use 1.5 cycles for the sample time, so now that's fixed too:). Worked even with all my register-fiddling ^^ Thanks a lot :) Now my sampling speed is OVER 9000!!! ;D

Ah, great. Was starting to wonder if there was other shenanigans going on in their ADC library.

I couldn't find the function being called directly, but there's a good example explaining how to attach interrupts to the ADC which works well: https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/master/STM32F1/libraries/STM32ADC/examples/SingleConversionInterrupt/SingleConversionInterrupt.ino
If anyone knows the actual function being called directly that would be great to add on here, but until then this example does what I need and will hopefully help others having the same problem.

If you reverse the call stack in that example you end up with ADC1->handlers[ADC_EOC] = yourfunction; , and ADC1egs->CR1 |= (1U<<(ADC_EOC +ADC_CR1_EOCIE_BIT)); to enable the IRQ. As far as I can see.

Yeah, I followed the code back to where the function in ADC1->handlers[ADC_EOC] was run, and it was inside a function called adc_irq if I remember correctly, it was even defined with the __weak keyword, so I was sure I had the right one, but for some reason that function did not work either when I wrote my own version of it :(

first you need to enable the interrupt (I don't know if the stm32 wrapper for arduino does it or not):
NVIC_EnableIRQ(ADC1_IRQn);

then you have to write ISR as gerben said:
extern "C" void ADC1_IRQHandler()
{
    //clear ADC flag
}

extern "C" because [as far as I know] the arduino projects are C++.

Sadly it does not work with the STM32duino library :(
I did however find examples of how to attach interrupts to the ADC, for anyone looking to just to that: https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/master/STM32F1/libraries/STM32ADC/examples/SingleConversionInterrupt/SingleConversionInterrupt.ino
Though I want as much speed as possible for my application so I will have to dig deeper to try to find the function that's called by the ISR itself.


text:
Are breadboads available in EasyEDA?
So far I have been using TinkerCAD which has them but I am unable to find them on EasyEDA Library. Are connectors supposed to do the same thing? I get this empty rectangle in the EasyEDA library which I am unable to make sense of.

look at your arduino board ... do you see connectors for every single pin of every component?

you are supposed to draw a schematic diagram ... here is an example ... https://electronics.stackexchange.com/questions/523839/atmega328p-development-board

@jsotola Thanks for responding! I am still confused. When it comes to the Arduino, where do I type the code in order to simulate (TinkerCAD has a side window to do this)? As for the breadboard issue, do header pins work in the same way (ie do all the header pins on a single header have the same potential, much like a row on a breadboard)?

again, look at the header pins on your arduino board ... do they look connected all together?

I think that EasyEDA can simulate electronic circuits ... it does not simulate programming in devices

I think I get it. So in EasyEDA the "rows" of a breadboard would be redundant as you can just sketch regular parallel wires wherever needed or label the "nodes" which are meant to be at the same potential with the same term (?). But what about the power rails? Would tagging all the nodes which use the same power source as ##V_cc## do the trick?

EasyEDA is not designed for diy prototypes like TinkerCAD is.  EasyEDA's purpose is to simulate electronic circuits and design circuit boards for those circuit designs.  Because of this they don't have a breadboard object because there would be no point in having one, since you can just connect virtual wires in the schematic mode and wire traces in the board design mode.
Furthermore, it doesn't support simulating a full Arduino board with code.

So if a number of wires were to be connected to a node, for a breadboard I would connect them all to each hole in a row as all points in a row have the same potential and are connected to each other. For EasyEDA, would labelling all the points with the same label also work? So if a bunch of components were to be connected in parallel to a voltage source (V1), would labelling the relevant points with a node called V1 be the same as drawing parallel connections with wires? Thank you for helping!

If you are drawing an electrical schematic then the practice of labeling to signify a common connection point is common.  For example you'll see multiple GND labels on schematic diagrams.  On a circuit board layout, however, you wouldn't want to do this because the whole point of a circuit board layout is draw all the physical traces and connection points that will be make the circuit design function when made into a physical circuit board.


text:
How to control baby swing?
I am starting an intresting DIY project of baby swing. My son is 3 month old and we have swing made with ropes in our house where he sleeps. I am looking for any electronic component controlled with arduino to swing it in controlled manner. I thought of servo motor but not sure how will it work. Any suggestions please ?
swing is similer to below

your question is not related to the arduino ... you may get better results elsewhere ... try this for a proof of concept ... tie a length of string to one of the ropes about 30 cm from the ceiling ... gently pull the string repeatedly using small motion ... think about how much a hobby servo would pull the string ... doing that will give you an idea about how much force is needed to get the swing going and what is needed to keep it at a steady swing

sure! Thanks @jsotola

Have you considered a solenoid? The one we used many years ago used a solenoid and a few "D" batteries, a magnet and a reed switch.

A simple DC motor would work. you have to pulse it in the right moment. for finding out the right moment and the pulse length (you don't want to push it so hard !) you need a simple accelerometer sensor to measure acceleration in specific axis.


text:
How do I recover a beetle where I loaded a program that was too large and overwrote the bootloader?
I'm doing on-target unit testing for an industrialized application and my test code is too large to fit everything on the board at the same time. I'm using the Sloeber toolset to develop, and I put something on the board that was over 28K, and the programming failed. Now the beetle does not show up as a serial port, and not even when pushing the reset pins, which I've had to do a number of times in the past.
If I overwrote the bootloader, which seems likely, is there a way to recover it? Do I need to reprogram the bootloader on a Beetle board? I haven't found any way to do that with a Beetle...
Thanks!

the upload didn't overwrite the bootloader. see my answer

Yeah, I tried the double reset--that didn't work either. The behavior that happened is that Sloeber failed when it was writing the image and the blue light stayed on. When I reset it, no port came up. When i hit the reset a hundred times, the LED never pulsed and no com port ever showed up in my device manager. I'm pretty sure this is a Sloeber problem with the gcc tools that the Arduino program probably safeguards against.

not hundred times. only but exactly twice to activate the bootloader.

on ATmega32u4 it is not possible to overwrite the bootloader with serial upload

I don't know the Sloeber toolset, but it seems very unlikely, that it really has overwritten the bootloader. When programming via USB, it is actually the bootloader, which writes the program into the flash memory. So that would mean, that the bootloader had overwritten itself, only because a too large program. Not sure, if this is even possible.
Anyway, you can utilize an ICSP/ISP programmer (or another Arduino, if you don't have one) to burn the bootloader onto the chip again. Google for Arduino ISP to get instructions for it, there are plenty of tutorials.
You need to connect the correct pins on the Beetle with the ISP programmer. According to this site, you should find the ICSP pads at the back of the board (the group of 6 pins in 2 rows). Through these pins you can burn the bootloader.
If that doesn't work either, the problem lies somewhere else. As I already stated, overwriting the bootloader because a program is too big for the MCU should not happen and it is highly unlikely, that this is really your problem. You might have damaged something on your board, though we cannot tell that from the description. So you could just try to burn the bootloader and see what happens.

OP doesn't have to flash the bootloader. the bootloader is protected with fuses

Yes, the icsp pads are there, which is how you perform the reset. It seems like the Sloeber toolset, which uses the atmel gcc/g++ tools, somehow causes a problem with the beetle if the file is too large. It definitely fails to write and tell you so, but either way, the beetle becomes completely unresponsive.

on ATmega32u4 it is not possible to overwrite the bootloader with serial uploaad

Use double reset to activate the bootloader. The LED will pulse while it waits for upload.
The board doesn't show up on USB because USB is handled by the sketch on MCU with native USB. If the sketch doesn't run it doesn't handle the USB.
The bootloader is protected by fuses.
(This happen to me with Sloeber a few days ago.)

Yeah, I tried the double reset--that didn't work either. The behavior that happened is that Sloeber failed when it was writing the image and the blue light stayed on. When I reset it, no port came up. When i hit the reset a hundred times, the LED never pulsed and no com port ever showed up in my device manager.