text:
Code for mapping voltage on a sensor and outputting a value in liters
I got a Resistive sender fuel gauge sketch off the internet that I have adapted.  The Resistive sender is a floating magnet that activates read switches to vary the resistance.  Using a stable 5v power source and 100-ohm resistor I have a voltage bridge that is connected to the sender and pin A1.  The original sketch uses this to get the voltage into liters:
TankValue0 = map(sensorTankValue0, 352, 824, 0, 100);
if (TankValue0 < 0) {
  TankValue0 = 0;
}
if (TankValue0 > 100) {
  TankValue0 = 100;

The lower range is not too far off but as you get to the top it is out to lunch.
I have mapped the segments of MY float sensor's intervals, and have found there to be 17 distinct points-- I measured the voltage at each point and made a table (I mean like on paper) to relate the measured voltage at a given point to a distance in mm, and then converted that to the relevant metric of liters in a tank when the float switch is reading a given voltage.

V
L

4.04
94

3.981
88

3.902
84

3.81
81

3.703
77

3.637
72

3.564
69

3.483
65

3.393
61

3.293
57

3.18
53

3.053
50

2.908
46

2.546
42

2.192
38

1.726
35

How do I get that information into the sketch to give me a read-out of L in my tank?
I have no programming knowledge really. I work with Arduino IDE a lot, but only using sketches other people have written.  So, I have a huge basic knowledge gap.  So, please bare that in mind.
This is the whole sketch:
#include <LiquidCrystal_I2C.h>

int TankValue0;
int TankValue1;

LiquidCrystal_I2C lcd(0x27, 16, 2);   // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup() {
  lcd.init();                          // initialize the lcd
  lcd.init();
  lcd.backlight();
  lcd.setCursor(1, 0);
  lcd.clear();
  lcd.print("WORD");
  lcd.setCursor(0, 1);
  lcd.print("TO");
  delay(1500);
  lcd.clear();
  lcd.print("YO ");
  lcd.setCursor(0, 1);
  lcd.print("MOMMA");
  delay(2000);
  lcd.clear();
  pinMode(A0, INPUT);
  Serial.begin(9600);               // starting the Serial Monitor

}
void loop() {
  int sensorTankValue0 = analogRead(A0);
  int sensorTankValue1 = analogRead(A1);
  TankValue0 = map(sensorTankValue0, 352, 824, 34, 94);
  TankValue1 = map(sensorTankValue1, 785, 310, 0, 100);
  if (TankValue0 < 0) {
    TankValue0 = 0;
  }
  if (TankValue1 < 0) {
    TankValue1 = 0;
  }
  if (TankValue0 > 100) {
    TankValue0 = 100;
  }
  if (TankValue1 > 100) {
    TankValue1 = 100;
  }
  lcd.print("S.V. SAVANNAH");
  lcd.setCursor(0, 1);
  delay(100);
  lcd.print("DAY TANK   ");
  lcd.print(TankValue0);
  lcd.print("%");
  lcd.setCursor(0, 0);

  delay(1000);
  lcd.clear();
}

BTW this tank is square, and hold 100L, the float is not long enough to reach the bottom. Later i want to uses this same Arduino for 2 other tanks that are oddly shaped and hold different amounts.

start by drawing a graph

please post the data table as text, not as a picture

V L
4.04 94
3.981 88
3.902 84
3.81 81
3.703 77
3.637 72
3.564 69
3.483 65
3.393 61
3.293 57
3.18 53
3.053 50
2.908 46
2.546 42
2.192 38
1.726 35

I'd use a lookup table for such tasks. It's probably not worth the effort of modelling.

Curve fitting
Well, a lazy way to do it is just to fit a curve to it, using Excel, or Libreoffice, Google Docs or whatever.  Here's gnuplot being used that way to fit a cubic polynomial to it:
"points.txt" containing your data, tab-delimited:
4.04    94
3.981   88
3.902   84
3.81    81
3.703   77
3.637   72
3.564   69
3.483   65
3.393   61
3.293   57
3.18    53
3.053   50
2.908   46
2.546   42
2.192   38
1.726   35

Gnuplot session:
gnuplot> f(x) = A*(x**3) + B*(x**2) + C*x + D
gnuplot> fit f(x) "points.txt" via A, B, C, D
iter      chisq       delta/lim  lambda   A             B             C             D
   0 1.8323200047e+01   0.00e+00  9.28e+01    2.818423e+00  -1.100151e+01   1.447650e+01   2.873579e+01
   1 1.8323200047e+01  -4.65e-10  9.28e+00    2.818423e+00  -1.100151e+01   1.447650e+01   2.873579e+01
iter      chisq       delta/lim  lambda   A             B             C             D

After 1 iterations the fit converged.
final sum of squares of residuals : 18.3232
rel. change during last iteration : -4.6534e-15

degrees of freedom    (FIT_NDF)                        : 12
rms of residuals      (FIT_STDFIT) = sqrt(WSSR/ndf)    : 1.23569
variance of residuals (reduced chisquare) = WSSR/ndf   : 1.52693

Final set of parameters            Asymptotic Standard Error
=======================            ==========================
A               = 2.81842          +/- 1.156        (41.02%)
B               = -11.0015         +/- 10.22        (92.86%)
C               = 14.4765          +/- 29.11        (201.1%)
D               = 28.7358          +/- 26.52        (92.27%)

correlation matrix of the fit parameters:
                A      B      C      D
A               1.000
B              -0.998  1.000
C               0.990 -0.997  1.000
D              -0.974  0.987 -0.996  1.000

And here's what looks like against the actual data with plot "points.txt" with linespoints, f(x):

So you have a function:
float f(float x) {
  static const float A =   2.81842;
  static const float B = -11.0015 ;
  static const float C =  14.4765 ;
  static const float D =  28.7358 ;
  const float x_squared = x * x;
  const float x_cubed   = x * x_squared;

  return A * x_cubed + B * x_squared + C * x + D;
}

If you don't care about the code size and the slowness of float arithmetic, then that might be okay.
Otherwise you may want to convert that function to something like fixed point arithmetic.
A cubic polynomial may be overkill, but then whole technique may be also.
Peicewise Linear
You can make a table of you points and just do what graphing programs typically do, linear interpolation between the points.
float f(float x) {
  static const struct pt {
    float v;
    int l;
  } points[] = {
    {0.0  ,  0},  // I put this here for testing, but put a better value here.
    {1.726, 35},
    {2.192, 38},
    {2.546, 42},
    {2.908, 46},
    {3.053, 50},
    {3.18 , 53},
    {3.293, 57},
    {3.393, 61},
    {3.483, 65},
    {3.564, 69},
    {3.637, 72},
    {3.703, 77},
    {3.81 , 81},
    {3.902, 84},
    {3.981, 88},
    {4.04 , 94}
    // you should probably have another entry here so that readings up to 5V work.
  };
  static const size_t table_len = sizeof points / sizeof points[0];

  for (size_t i = 0; i < table_len - 1; ++i) {
    if (x >= points[i].v && x < points[i + 1].v) {
      return
            (x - points[i].v)
          / (points[i + 1].v - points[i].v)
          * (points[i + 1].l - points[i].l)
          + points[i].l;
    }
  }

  return -1;
}

Sitting in the center of this in the return statement is basically a crude implementation of Arduino's map(), but for floating point, which again, you don't really need floating point, even if you want to use this piecewise approach.
In short, you find which two entries of the table you're sitting between, and apply what amounts to map() on the line segment formed by the two table entries.
PROGMEM
Either of the curve fitting or piecewise approach could be used to generate a much larger lookup table out of which you could just chose the nearest point.
If you're doing this on an AVR-based Arduino, the table for the piecewise linear approach or a pure lookup table approach could use PROGMEM for the array.
Regarding float and fixed point
Any of these techniques could be adapted to fixed-point math.
Which ever you use, if you're on AVR based Arduino, keep in mind that there's no hardware floating point support at all, and although double exists as a type it is implemented in avr-gcc as a single precision float.
If you're using one of the non-AVR based Arduinos, it may have support for float (and maybe for double), in which case the generated code may not be so bad, though may still be slower than using integers.
If you can do everything with integers, resulting code should be a lot smaller and faster.  I'm guessing for what you're doing, if either of them are more important, it's probably being smaller.
For using integers, you may be able to keep your input "voltage" as an ADC count, not having an intermediate voltage calculation.  And even if you want single digit liters when you're done, the intermediate interpolation, curve fitting, or table lookup may require that you work in something like centiliters, milliliters, so that values like the A constant from the curve-fitting example can be represented as an integer, e.g.  2818 mL  rather than a cruder 3 L.  If you're not using a plain lookup table and finding the nearest entry, that is if you're using the curve or piecewise linear approach, doing everything in integer arithmetic from ADC count to mL.  Although you'll need to run another curve fitting, since the A, B, etc will representing mL-per-ADC-count not L-per-Volt.  Or scale them from the value given.
And there are other options, piecewise cubic splines, etc.

Thank you so much @timemage. This is a great resource. I must admit I don't fully understand all of it;-)  I will do my research and educate myself.  in the mean time I tried inserting the "Float" code into my sketch but I get  "'lcd' does not name a type" error.

I don't know how literal you are about the uppercase 'F' in "Float", but it's lowercase in actual use.  If you need something more interactive than stackexchange, there's a few hundred Arduino users, including me, on freenode.  There's also the official forums.  If you have specific questions about what I wrote, I can try to address them.


text:
Can i make this circuit smaller?
I have an external device and I need to detect voltage high/low on two wires.  The high=12v, low=0v.  I am using an Arduino Zero (3.3v).  I am thinking of using A1 and A2 connected as follows...

link in tinkercad
In which the yellow boxes at the bottom are the A1,A2 and ignore the pushbuttons.
This design uses 4 resistors (2x10k, 2x2.2k) minimal.  Normally both inputs are HIGH.  Each one will go to LOW momentarily.  It is sufficient for me to detect if either one goes LOW. In other words, is there a way for me to map the AND of both inputs to a single analog pin on the Arduino?  Ideally using less resistors? (i.e. I want to avoid more soldering.)

the link is dead

the input is LOW, and goes HIGH when the button is pressed

what functionality are you trying to have? ... please update your post with an explanation

put the two switches in series

You may try this:

simulate this circuit – Schematic created using CircuitLab
This should work as a wired and, provided the diode thresholds are lower than the Arduino's input low threshold.

Thank you for the suggestion.  I tried it, but it doesn't work. It seems the 12v high is much stronger than the low.  If both are low, then the digital input is low. However if either input is high, then digital input is hign.  So it is actually an OR instead of AND.  perhaps my diodes where the wrong kind.

@JohnHenckel if either input is high, then digital input is hign ... that is not the expected behavior of that circuit ... you may have miswired something

source: Stack Exchange

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

sort: votes


text:
How to reduce noise when using a load cell amplifier's 80 Hz mode?
I have four HX711s load cell amplifiers and each one reads one load cell. I was using the 10 Hz mode, however, this was making my application very slow, as I needed to take five readings and take the average.
When I put the 15 RATE in 1 there is a lot of noise, despite having sped up the reading of the weights; sometimes the variation is up to 3 digits at the end.
See the code for reading the modules where I already show the weights in kg:
n = 6;

for (int x=0; x<n; x++) {
  v1[x] = CELL1.read();
  v2[x] = CELL2.read();
  v3[x] = CELL3.read();
  v4[x] = CELL4.read();
}

v1m = 0;
v2m = 0;
v3m = 0;
v4m = 0;

for (int x=1; x<n; x++) { // sum of array
  v1m = v1m+v1[x];
  v2m = v2m+v2[x];
  v3m = v3m+v3[x];
  v4mv= v4m+v4[x];
}

// mean array
v1m = v1m/(n-1);
v2m = v2m/(n-1);
v3m = v3m/(n-1);
v4m = v4m/(n-1);

p1 = p;
p = ((v1m-v10)/(M[1]) + (v2m-v20)/(M[2]) + (v3m-v30)/(M[3]) + (v4m-v40)/(M[4]))/2.5; // show the weight in kg
p = p*o.7+p1*0.3; // convert to kg
// ... i print the p (weight in kg) now...

Please show your complete code, wiring and which deviations you actually get in comparison between 10 and 80SPS setting

I had a very similar problem with 4 load cells.  I ran 10,000+ readings at 80Hz, copied the serial monitor into MS Word to find my string (text) value labels and replace them with nothing. This lets me keep the numbers.  If you copy that into Excel and make a scatter plot graph you can see where your highs and lows are and their magnitudes.  I was able to simply write an IF condition to reject those outliers.  Interestingly the outliers are very large (positive or negative) and they weren't just random values. They were also occurring at a specific frequency that may have more to do with my application rather than being an element to your solution.

Your answer could be made more complete by including the part of your code that does the filtering for outliers, or by describing it in more detail. Did you use some kind of median filter or something different?

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


text:
Properly escaping very large strings
On an ESP8266 I want to create a little webserver that shows me a dashboard with charts and stuff. For this I want to include the echarts-library as it works offline. To access it the only way I can see this working is that I write:
const char libData[784674] PROGMEM = "the entire 700 KB library goes here";

And then deliver it on request with server.on('./echarts.min.js', handleLibRequest) or something like that.
Now my problem is that in this 700KB of text there are ' and " characters all scattered arround. The C++11 way of R("hard escapable '"'''" string") isn't working in my environment. How would one go about this to include this file in my code?
Is there mybe some way utilize the preprocessor for this? Or maybe an online tool that converts "str" to ['s','t','r']?

serve static files from file system

How would I add these static files into the filesystem? Without having to use any c++ code where I would face the same issues mentioned in my question?

with the IDE plugin for esp8266 FS upload. https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html

Its simple, paste all you page between "()" on the below line
const char live_html[] PROGMEM = R"rawliteral(your date here)rawliteral";

You can use "objcopy" to produce an object file from the file's contents, if you declare it as binary.
objcopy -I binary echarts.min.js -O <your-bfd-format> echarts.min.js.o

To find out which BFD format you need, run objdump -t <any object file> and look at its output.
The resulting object file contains an object named after the input file in the .data section. There are 3 symbols in the symbol table:

_binary_echarts_min_js_start
_binary_echarts_min_js_end
_binary_echarts_min_js_size

The "start" symbol marks the beginning of the file's content, and the "end" symbol marks the address after the last byte. The "size" symbol is hard to use in C or C++, because it is an absolute value.
Commonly I just use "start" and "end" like this:
extern const char _binary_x_bin_start[];
extern const char _binary_x_bin_end[];

Instead of objcopy, you can use ld -r -b binary echarts.min.js -o echarts.min.js.o This way you do not need to know the BFD format, provided you use the ld binary appropriate for the target architecture.

You could write a program that escapes all the offending characters and use the output of that in your const char libData[]; see here for a list of escape sequences;
You could serve the library directly from a (pseudo) file system on the ESP8266, without having to copy it "manually" into a variable; you just copy the file to the filesystem;
You could Base64-encode the library and manually copy the result into const char libData[], then Base64-decode before sending;
What I like to do, if there is no file system but enough memory:

Gzip the library;
Base64-encode the .gz file;
Copy the Base-64 encoded result by hand into your const char libData[].

The Base64 encoding allows you to copy/paste without problems.
Despite the Base64 encoding, the gzipping makes the end result smaller than the original, which helps with memory usage and transfer speed, and it will have no "quote problems".
When the libData needs to be served, Base64-decode it, and send the resulting (gzipped) data to the client; all browsers I know will accept that if you add the Content-Encoding: gzip header.
Example code on a raw client without a webserver library: unsigned int sendBase64Page() (mind the content type).

That's like copying it into a variable but unecessarily complicated in my opinion. But thanks for the idea.

I've just written myself now a python-script that creates a char-array with the numbers representing the characters. Maybe it helps someone else:
import sys

def arrayify(sourceFile, targetFile):
    with open(sourceFile, 'rb') as sf:
        contents = sf.read()

        charArray = ""

        for char in contents:
            charArray += str(char) + ","

        # end array

        with open(targetFile, 'w') as tf:
            tf.write(charArray)

if __name__ == "__main__":
    sourceFile = sys.argv[1]
    targetFile = sys.argv[2]

    arrayify(sourceFile, targetFile)


text:
Powering the Arduino with a battery and reading the battery voltage
I am trying to display the battery voltage as it is being used to power the Arduino.
I have tried powering the Arduino through the USB and the battery voltage is read accurately when compared to the multimeter reading.
But when the battery is powering the Arduino and being read, it keeps displaying 5.00 V, which it should not be.
Just wondering what might be happening and how I can go about resolving this issue.
I have been trying to research some answers, and came across something about an 1.1 V reference voltage, but I'm not entirely sure what they mean.
Here is my code for reference:
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10,11);

int battPin = A1;

void setup() {
  pinMode(battPin, INPUT);
  BTserial.begin(9600);
  Serial.begin(9600);
}

void loop() {
  int voltReading = analogRead(battPin);
  float volts = (voltReading/204.6);
  BTserial.print(volts);
  BTserial.print(";");
  Serial.println(volts);
}

I am using a 3.7 V Li-po battery. It is connected to A1 and also to Vin.

AFAIK, Arduinos are set up to use their operating voltage as the analogRead reference voltage by default.
So what I think is happening is that you are trying to measure the battery voltage with the battery itself as a reference voltage.
This will, of course, always show "full scale".
You could use a voltage divider to bring the measured battery voltage down to about 1 V (max) and use the Arduino's internal reference of about 1.1 V for measuring.
Note that the 1.1 V internal reference is stable, but not necessarily exactly 1.1 V. You will have to measure it first.

Oh I see! I will give that a try and see what happens! Thanks!

Also, how can I go about using the internal reference?

See https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/

You need to divide down the battery voltage into the 1.1V max range, and use the Internal bandgap voltage reference for the ADC conversions.
Connect the Battery to VCC, not Vin, you don't want it going thru the regulator.

By "divide down the battery voltage" do you mean with circuitry, such as a voltage divider, or through the code? And what is the internal bandgap voltage reference?

Yes, two resistors, in series between VCC and GND. Connect Ax to the junction.  See the datasheet for more info on the internal source.

connecting the battery to the VCC, means connect to the 5V pin? Is that okay? I read that if you connect the USB while battery is connected to the 5V pin, it could damage stuff.

Maybe. 3.7V into the barrel jack will be overcome by the USB input and the power switching circuit, and USB will be used.


text:
EPS8266 ESP-01: LED manipulation seems to interfere with serial communication
I'm playing around with this udp-example. Both this and the blink-example work perfectly. Now I would like to use the LED to indicate what the ESP is currently doing, as well as reading some data over Serial. My code looks like this:
void setup(){
  Serial.begin(115200);
  Serial.setTimeout(500);
  while(Serial.available()==0){
  }
  String password = Serial.readStringUntil('.');
  Serial.println(password);
  WiFi.begin(ssid.c_str(), password.c_str());
  //pinMode(LED_BUILTIN, OUTPUT);
  while (WiFi.status() != WL_CONNECTED){
    //digitalWrite(LED_BUILTIN, LOW);
    delay(250);
    //digitalWrite(LED_BUILTIN, HIGH);
    delay (250);
  }
  Serial.println("connected");
  Udp.begin(localUdpPort);
}

It works fine, but if I uncomment the led-lines the serial communication doesn't seem to work anymore. All the stuff that is printed on the Serial Monitor is now messed up (missing characters, ...). Is there a problem with my code or what else could be possible going wrong here?
EDIT: I recently tried the same code again, but used an additional power supply (3.3V, 500mA) for the chip. However, this didn't resolve the problem.

Turn the baud rate down to 9600 and see if that helps.  Also not sure about the setTimeout call.

Setting the baud rate to 9600 has no effect when the led stuff is commented out, but if it's not commented I cant see anything on SerialMonitor at all ( setTimeout is also commented out)

Do you have a drivers to the LEDs or are they directly attached to the ESP-01? And have you a extra capacitor as power stabilizer over Vcc and GND?

It is the built in led on the esp I am using. I just connected VCC to VCC of my usb/ftdi- chip (which is plugged in on my notebook).

I'm using this chip from AzDelivery  FTDI Adapter FT232RL

i would suggest you add something to the body of that while loop, just to allow the background activities to continue, even if it's just a short delay or a yield

Do you mean the first one? Why should this change something?

Do you get the same results with another module? Did you enter anything through the serial monitor? Can you place a while (1); after the Serial.println(password) to see if that at least is printed? Maybe also place a yield()  in the while (Serial.available() == 0) { } loop.

I would bet that the built-in LED pin is also the TX pin for the serial interface.
Check here, LED Pin section: http://www.esp8266.com/wiki/doku.php?id=esp8266_gpio_pin_allocations

LED Pin
GPIO1, which is also TX, is wired to the blue LED on many devices.
  Note that the LED is active low (connected to Vcc and sinks through
  the chip to ground) so setting a logical value of 0 will light it up.
  Since GPIO1 is also the TX pin, you won't be able to blink the LED and
  perform Serial communications at thew same time unless you switch
  TX/RX pins.

This would be confirmed if the LED blinks when serial communication is active.
If this is the case you would have to add your own LED on a different pin, or switch the RX/TX pins.

I agree, ref. https://github.com/esp8266/Arduino/issues/3165

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


text:
Run 2 loops side by side
Let's say I have 2 loops LED() and IR() with a print statement in my Arduino loop() function. Basically I want my IR() loop to be always running so that at any point in time I provide a signal to the receiver, it will print something. I currently can only run LED() first and then once LED() is finished, only then the IR() will run. So if I send a signal let's say while LED() is running, nothing is showing up. Thanks!
EDIT: Updated with code
void loop() {
  single_Check(); // delay of 500ms
  if (irrecv.decode(&results)) {   //IR code
     Serial.println(results.value, HEX);
     irrecv.resume();
  }
}

The single_check() function basically turns on 6 LED one by one and check the voltage of the LED and prints them out. However, this code takes time to finish because I put in delay(500). So only after 500ms, the IR code will run.

Run the functions one after the other. If they are fast enough, you should be fine. If they are not, you are probably doing something wrong, (using delay() maybe? Seen Blink Without Delay?).

Maybe you should look into interrupt timer and set to timers for LED and IR http://www.instructables.com/id/Arduino-Timer-Interrupts/

You could use a scheduler and run the 2 loops; https://github.com/mikaelpatel/Arduino-Scheduler

The updated question essentially contains the answer to your problem: you are using delay(). Solution: read the Blink Without Delay tutorial (did you notice I linked to it in my first comment?), then rewrite single_Check() without delay().

Run 2 loops side by side easy: have two arduino, each loaded with one of the loops. put the two arduino side by side and turn on the power. done.

Arduino and like Arduino hardware run only a sequential Flow, Because they usually have only one core.
For running 2 loops side-by-side you have some solutions.

A flow to test flags and execute specific code.
Use a timer
Use a RealTime OS, like FreeRTOS

try never use delay

Your outer loop needs to only decide whether the IR or the LED needs service. If/when one of them does, call a function that services that device. The service functions should be brief and without delay() calls.
If a service function needs to do something/delay/do something else, it should do it by parts; only do the first something and let the main loop decide when it is time to do the something-else.
If this is all you are doing - two devices and their service routines, you may not need anything more. If you need to extending this to n-devices with n or more service routines, and the servicing is time-based (such as the LED probably is), look the SimpleTimer library. Then your outer loop would only call the timers' .run() function frequently, and the timers routine would take care of calling each service routine when necessary.
You'll probably end up with something like:
SimpleTimer Timers;  // set of timers

void setup(){
   // some set-up stuff here
   Timers.setInterval(long 10L, LedService);  // call LedService 100x/sec
}

void loop(){
   Timers.run();
   if( IRTest() )
      IRService();
}

void LedService(void){
   // manage LED here
}

bool IRTest(void){
   // return true if IR needs service
   // or false otherwise
}

void IRService(void){
   // manage IR sensor here
}

On Arduino (and on most other micro controllers for what it matters) you CANNOT do two things at the exact same time, so forget about running two loops in principle.
What you can do is: run two separate piece of code one after the other, fast enough that they look to be running in parallel or run one continuously and run the other when an event occurs.
In your case the first option is not applicable, so you have to revert to the second option and you are lucky because the event we are talking about is actually handled by the Arduino MCU pretty well: it is called an interrupt.
Arduino Uno (actually the MCU at its core, the ATMega328) is capable of handling interrupts on pins 2 and 3 (so you can have 2 interrupt routines attached at the same time).
Using interrupts you can have a piece of code (the IR related part) being enabled only when pin 2 goes LOW (or HIGH).
BEWARE though and use interrupts in the proper way: millis() does NOT work within an interrupt routine and also nothing else will be enabled while executing the interrupt routing, including counting time (that's the reason millis() does not work).
The latter part practically means you should limit your interrupt routine to capture the IR code and return, having the printing being done within the loop() function whenever the IR has been decoded.
Hoping all that makes sense to you, here are some references:
interrupts()
Interrupts
attachInterrupt()

millis() does work inside an ISR, you should just not expect it to increment. Which doesn't matter, because you would never write an ISR that takes a full millisecond to run anyway.

@EdgarBonet well, if millis() keeps returning the same value I wouldn't say it does work, at least functionally speaking, but you are right nonetheless: it technically works but it doesn't report any change. About ISRs, I have seen code using delay() within ISRs, so don't put any limit on the misuse of interrupt routines :-D

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


text:
GPS is not detected on SIM808 module!
I'm trying to get GPS coordinates using my SIM808 module by connecting it with Arduino. When I use this code,
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "gps.h"

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.

//Simple sketch to start a connection as client.

GPSGSM gps;

char lon[15];
char lat[15];
char alt[15];
char time[20];
char vel[15];
char msg1[5];
char msg2[5];

char stat;
char inSerial[20];
int i = 0;
boolean started = false;

void setup() {
  //Serial connection.
  Serial.begin(9600);
  Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  //For http uses it is recommended to use 4800 or slower.
  if (gsm.begin(2400)) {
    Serial.println("\nstatus=READY");
    gsm.forceON(); //To ensure that SIM908 is not only in charge mode
    started = true;
  } else Serial.println("\nstatus=IDLE");
  if (started) {
    //GPS attach
    if (gps.attachGPS())
      Serial.println("status=GPSREADY");
    else Serial.println("status=ERROR");
    delay(20000); //Time for fixing
    stat = gps.getStat();
    if (stat == 1)
      Serial.println("NOT FIXED");
    else if (stat == 0)
      Serial.println("GPS OFF");
    else if (stat == 2)
      Serial.println("2D FIXED");
    else if (stat == 3)
      Serial.println("3D FIXED");
    delay(5000);
    //Get data from GPS
    gps.getPar(lon, lat, alt, time, vel);
    Serial.println(lon);
    Serial.println(lat);
    Serial.println(alt);
    Serial.println(time);
    Serial.println(vel);
  }
};

void loop() {
  //Read for new byte on serial hardware, and write them on NewSoftSerial.
  serialhwread();
  //Read for new byte on NewSoftSerial.
  serialswread();
};

void serialhwread() {
  i = 0;
  if (Serial.available() > 0) {
    while (Serial.available() > 0) {
      inSerial[i] = (Serial.read());
      delay(10);
      i++;
    }
    inSerial[i] = '\0';
    if (!strcmp(inSerial, "/END")) {
      Serial.println("_");
      inSerial[0] = 0x1a;
      inSerial[1] = '\0';
      gsm.SimpleWriteln(inSerial);
    }
    //Send a saved AT command using serial port.
    if (!strcmp(inSerial, "TEST")) {
      stat = gps.getStat();
      if (stat == 1)
        Serial.println("NOT FIXED");
      else if (stat == 0)
        Serial.println("GPS OFF");
      else if (stat == 2)
        Serial.println("2D FIXED");
      else if (stat == 3)
        Serial.println("3D FIXED");
    }
    //Read last message saved.
    if (!strcmp(inSerial, "MSG")) {
      Serial.println(msg1);
    } else {
      Serial.println(inSerial);
      gsm.SimpleWriteln(inSerial);
    }
    inSerial[0] = '\0';
  }
}

void serialswread() {
  gsm.SimpleRead();
}

After some time, I get this error on the Serial Monitor of Arduino:
status=ERROR

The connections are as follows:

TX of Module = Pin 2 of Arduino
RX of Module = Pin 3 of Arduino
GND of Module = GND of Arduino
5V of Module = 5V of Arduino

The Arduino is powered by USB connected to my PC.

Yes. SMS and Call functionalities are working fine. I can send messages to my mobile phone.
And what pins are you talking about? I connected GPS antenna only and nothing else.

I've added images of my GSM/GPS module. Please see for yourself. Thanks.

May I also ask what does pin G SDA SCL 1 2 G G 1 2 does?

Those are just breakout pins for the SIM808's I2C peripheral. Not needed here. Do you have a USB-TTL adapter? You can try communicating with the module directly with the serial monitor, to see if it responds to the GPS commands.

No. Unfortunately I don't.

You can use your Arduino as an adapter. Connect the GSM TX to Arduino TX and GSM RX to Arduino RX, GND to GND, 5V to 5V. Connect the Arduino Reset pin to GND. Then open the serial monitor, set it to "Carriage Return" and send "AT".

That is what I've been doing. But there is no RESET pin?

There is a RESET pin close to the 5V pin. Also this is NOT the same as what you've been doing. Read carefully and compare to your present circuit. Note that by Arduino RX and TX, I'm referring to pins 0 and 1 respectively.

I see a RESET button but no RESET PIN?!

Ok. I get it. I thought of something else. But how do I connect them. Do you just want to connect them on the board itself using jumper wire? Also if I connect TX to TX and RX to RX do I need the change the pins names in GSM.cpp file?

Your problem looks similar to mine. It is possible that your module is a GNSS module and therefore doesn't work with standard AT commands, which are used in "gps.h".
First check that the GPS Module receives enough current, at least 5V -- 2A from an external source like a battery.
Then try sending AT commands in the serial monitor to check if your GPS module works properly:
#include <SoftwareSerial.h>
SoftwareSerial SIM808(2,3); //(RX-Pin,TX-Pin)

void setup() {
  Serial.begin(19200);
  SIM808.begin(19200);
}

void loop() {
  if (SIM808.available())
    Serial.write(SIM808.read());
  if (Serial.available())
    SIM808.write(Serial.read());
}

Upload this to the board an then open the serial monitor and send these commands:
AT+CGNSPWR=1

This should return OK.
After that input:
 AT+CGNSINF

This should return OK and your GPS Location in this format:
1,0,<time>,<your latitude>,<your longitude>,..........

If you get the following output:
1,0,19800106001337.000,,,,0.00,0.0,0,,,,,,0,0,,,,,

It means your GPS is not set. Try to put GPS antenna outside your room, on open space.
For more information about GNSS modules go to  http://www.elecrow.com/wiki/images/0/05/SIM800_Series_GNSS_Application_Note_V1.00.pdf


text:
RFID reader for unknown tag 125kHz
I have an unknown RFID tag and tried to read its value. I bought two readers, RDM6300 125KHZ and RC522 13.56MHz. Each of the readers connected to Arduino works well with the purchased corresponding tags, but not with this tag. According to my information, the tag should be 125kHz tag, but RDM6300 foes not read it. The tag is simply not detected. I am sure that the tag works, I use it to open the door.
So my question is: Is there any other RFID reader for Arduino, which is different than the two that I have, and could work?
Thank you.

It could be something else (in the RFID low freq ~ 125khz) like a HID card.
Also it could be an NFC (high freq 13.56Mhz) that its not compatible with the RC522.
Do you have access to a phone with NFC, to start ruling out what could it be?


text:
Problem reading from GPS
Right now I am working on a project where I need to turn on four LEDs in sequence, 1100 before 12 am and 1010 after 12 am. I am using a GPS in this project and I want to access the time from the GPS. The problem is that I am not getting it. How to make it possible?
GPS module: RoyalTek 4216
CODE:
#include <NMEAGPS.h>
#include <SoftwareSerial.h>
SoftwareSerial gpsPort( 50, 52 );
#define gps_port Serial1
NMEAGPS gps;
gps_fix fix;

void setup() {
  Serial.begin(9600);
  gpsPort.begin(9600);
  for (int thisPin = 2; thisPin <= 13; thisPin++) {
    pinMode(thisPin, OUTPUT);
    int i=0;
    long k;
  }
  for (int n = 22; n <= 52; n++) {
    pinMode(n, OUTPUT);
  }
}
// the loop routine runs over and over again forever:
void loop() {
  while (gps.available(gpsPort)) {
    gps_fix fix = gps.read();
    Serial.print(F("DATE:  "));
    if (fix.valid.date && fix.valid.time) {
      // Shift the date/time to local time
      NeoGPS::clock_t localSeconds;
      NeoGPS::time_t  localTime; {
        using namespace NeoGPS;
        localSeconds = (clock_t) fix.dateTime;
        localSeconds += 5 * SECONDS_PER_HOUR + 30 * SECONDS_PER_MINUTE;
        localTime = localSeconds;
      }
      Serial.print( localTime.date);
      Serial.print( '/' );
      Serial.print( localTime.month);
      Serial.print( '/' );
      Serial.println( localTime.year);
      delay(500);
      Serial.print("\n*************************\n");
      {
        Serial.print( F("TIME:  "));
        Serial.print( localTime.hours );
        Serial.print( ':' );
        Serial.print( localTime.minutes );
        Serial.print( ':' );
        Serial.print( localTime.seconds );
        delay(500);
        Serial.print("\n");
        k=localTime.hours;
        int i=0;
        long k;
        if (k>=0 &&  i==0) {
          digitalWrite(2, HIGH);
          digitalWrite(3, HIGH);
          digitalWrite(4, HIGH);
          digitalWrite(5, HIGH);
          delay(5000);
        } else {
          digitalWrite(2, LOW);
          digitalWrite(3, LOW);
          digitalWrite(4, LOW);
          digitalWrite(5, LOW);
          delay(5000);
        }
      }
    }
  }
}

Guurav .  Please can you fill in the name of the GPS and board you are using (where the ??? are).  People need this information to be able to help you.  Also check the LED connections are correct, I guessed.  You have tagged mega and uno, please remove the one you are NOT using.

So what results are you getting? Your code isn't trying to do much with the LEDs, and you clearly need to read more about variable scopes because at first glance the way you declare the variable k is a wrong. Also avoid using single letter variables unless they only exist for a few lines, variable names should describe them not just be the first letter your fingers hit. Do you get any time displayed or not?

I hate to have to say this and I always try not to, but your code is awful.  Firstly it doesn't compile, and I can say that without even trying because the errors are very obvious.  If you reply is that it does compile then you have posted the wrong code.
In Setup() you are setting loads of pins to output, why?  You are only using 4 pins, 2,3 4 and 5!
Having a using namespace line at the top of your code is bad enough, it negates the purposes of a namespace, but having it in the middle of you code is really bad.  Just type the extra few characters, it will save you a lot of grief in the long run.
Scoping chunks of code can be good, but not in this case, it makes the code harder to read.  It would be better if you wrote a function to factor the date time printing out, i.e.
void PrintDT (char* type, int a, int b, int c, char sep)
{
    Serial.print(type);
    Serial.print( a );
    Serial.print( sep );
    Serial.print( b );
    Serial.print( sep );
    Serial.println( c );
}

And then called it:
PrintDT(F("DATE:  "), localTime.date, localTime.month, local.year, '/');
PrintDT(F("TIME:  "), localTime.hours, localTime.minutes, localTime.seconds, ':');

The less lines of code you have the easier it is to spot bugs.
Here is why I said it won't compile:
    k=localTime.hours;

    int i=0;
    long k;

    if (k>=0 &&  i==0)

You are assigning a value to k before you have declared it, but looking at setup it could be a copy and paste error, because you have similar lines up there.
Also assign meaningful names to your variables.  I'm guessing that k is the hours and i is meant to be minutes?  To be honest in this case I wouldn't use variables at all, just have this code
if (localTime.Hours >= 0 && localTime.Minutes == 0)

But that if statement doesn't do what you say you want to do at the top of the question.  When the time has any number of hours, including zero, and the minutes are zero.  According to you question you want
if (localTime.Hours == 0 && localTime.Minutes == 0)

But that means you will only see the lights on 1100 for 1 minute at midnight.
I hope that helps, There is nothing wrong with the process you are following, just some of the things you doing and the logic.  If it doesn't fix it, clarify what the exact error is and we'll see what we can do.

I have done my code and trust me it actually works. I know I did many common mistakes in my given code but reason is I have combined my two codes that's why. anyways sorry for that and thanks for help :-)

So you don't know how to read the time from a GPS?  Is that the problem?
Since you haven't stated the make and model of GPS and microprocessor I can only give you generic information.
GPS output their data in ASCII format over a serial link usually operating at 9600 BAUD.  So you need to connect you microprocessor to the GPS using a secondary serial port (Not the serial port you upload through).  On something with only one serial port (Uno, ESP8266, etc) you need to use the SoftwareSerial library to do this.
Then read from the serial port as you would do normally and parse the string you read to extract the time portion of the message, this should be quite easy to spot.  Most GPS's pump out two different messages at regular intervals and so you need to filter the message you don't want.
Relying on just a GPS for time is a bad idea, because you will get periods where the azimuth of the satellites is to low and you won't get sufficient coverage.  I would also use an real time clock (RTC) and use the GPS to update the RTC periodically and source the time from the RTC.


text:
Are these components connected correctly?
I intend to use two ultrasonic sensors as input and a vibration motor as its output, is this connected correctly?

As part of my project, I intend to use an ultrasonic sensor to feed in distance data and react through vibration motor. I have to confirm this arrangement will work but I don't own an Arduino.

That diagram is a case in point for why Fritzing should never be used for anything, ever. It really doesn't help people to learn how to do a proper schematic, and when people do use it the results are so meaningless as to be laughable.

in short: Definitely Not.
1 : you do really need to connect the trigger pins of the ultrassonic sensors, or else you will not be able to "trigger" them.
Read the ultrassound library examples, they may help you.
2 : I am pretty sure an analog (or digital for that matter) pin in arduino nano cannot sink the current needed to make the motor spin. You are going to fry that pin/port or even brick the entire arduino.
Read on power mosfets for the solution of that.
Moreover, i don't think the 5v out of the arduino feeding the motor is a good idea as well, as the current given by its internal regulator may not be enough for the motor as well.

Yep, unless it is a 20 mA motor, you need an alternative arrangement. Also, driving the whole thing from a 9V battery is a doubtful proposition. You may also want a snubber diode over the motor pins.

@ Marcus Thanks for replying. The trig pins are definitely connected to the board, just that when using this software(fritzing), I won't be able drag the wire to trig pin (it will relocated to the centre), I don't know whether it is a bug or not.

Regarding the vibration motor, I took reference from link, I just wonder why it will work for that. Here is the schematics for my reference link


text:
"port" is greyed out in 1.6.13, running win 10 for an Uno R3
I am new to this, and my kid got an Elegoo smart robot car kit v2.0 for Christmas. We assembled the car, but after downloading the software, the program always states:

Arduino: 1.6.13 (Windows Store 1.6.13.0) (Windows 10), Board: "Arduino/Genuino Uno"
Sketch uses 2,242 bytes (6%) of program storage space. Maximum is 32,256 bytes.
Global variables use 210 bytes (10%) of dynamic memory, leaving 1,838 bytes for local variables. Maximum is 2,048 bytes.
  avrdude: ser_open(): can't open device "\.\COM1": The system cannot find the file specified.
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
This report would have more information with
  "Show verbose output during compilation"
  option enabled in File -> Preferences.

I don't know what other information is important. Can somebody please help me?
Thank you.

When the port is greyed out its not available (I know you had worked that out) so you have a problem with you serial to USB drivers.
Looking at the kit I think you are connecting the UNO to a USB port on your PC/laptop using a blue cable.
 1. Please can you check that the cable is connected properly.
 2. Can you try a different USB port on the PC (don't use a USB hub - some don't work).
 3. Does Windows recognise a device has been plugged?
 4. Are you running it as administrator, you will need to be to install the drivers.
 5. Can you try connecting it to a different PC?
If these don't fix it then, please comment and well go through looking at the device manager.
Hope it works, it looks like fun.

Matt, thanks for answering.  yes, i've conected the blue USB cable, the device manager sees it as an arduinu Uno.  i changed the com port in device manager to com1. (took me a minute to figure out that the com ports were hidden)   And yes i an running it as administrator.

Why did you change the com port in device manager?  Normally mine show up as 3, 4 and 22.  It's possible you already have something on com1 and this is preventing the ide using it.  Also it's worth rebooting, because this can free a com port that has been locked by a process that's crashed.

it was originally 3 and didn't work.  i changed it to 1 because that is what the error said it was set on.  and since i can't change the port in the arduino IDE, i figured it was worth  shot.  and i definately tried rebooting as well including rebooting with the uno hooked up.

Is it an original uno or a clone? Clones can sometimes be awkward. Have you got a spare cable?  You might want to try uninstalling the drivers, reboot and then try again (I had to do that for one board).  It's possible the cable is dead, the board could be fried (unlikely) or your PC could be being awkward.  The setup you have should work, so it sounds like a fault rather than attempting the impossible.

it is an original board i believe.  i'm going to try to find another cable.  if my computer is identifying the board in device manager then the cable should be working though right?  i'll try a new cable tonight.  i really do appreciate your time.

Yes, the cable is fine, my brain isn't, slight glitch there.


text:
ESP8266 cannot connect to an existing network after using AT command
I followed this tutorial to connect the ESP8266 to a wifi network using AT commands. I used the below schematics (without the connection between ESP's CPIO 0 and Arduino's Ground):

After that, I was able to follow through the tutorial and got this response in the Serial Monitor:

That means my ESP8266 has successfully connected to my Wifi named W3. However, I decided to switch the mode of my ESP8266 from Network Device (mode 1) to Both network device AND Access Point (mode 3) (at this point I called AT+CWJAP? and can still see that it's connected to W3 wifi). I then was able to see the ESP wifi in my wifi list as (AI-THINKER_4C8CF2) but when I connected to it, I cannot connect to the internet. I'm wondering what the problem is and would appreciate any help.
Note: The reason why I switched to mode 3 is because I want to control an Arduino Pro Mini (instead of Arduino Pro) using NodeJS. I followed another tutorial and I figured that I need to connect to an ESP8266 access point.
I uploaded the StandardFirmataSketchPlus to my Arduino Pro Mini, with the baud rate set to 115200 (which is the same baud rate with my ESP8266). The schematic I used is similar to the one below, except I used a 3.3V Pro Mini and a Lipo battery, instead of a 5V:

The nodejs code is below:
var VirtualSerialPort = require('udp-serial').SerialPort;
var firmata = require('firmata');
var five = require("johnny-five");
var sp = new VirtualSerialPort({
  host: '192.168.1.243' //I got this number from the AT command (STAIP above)
 });

var io = new firmata.Board(sp);

io.once('ready', function(){
    io.isReady = true;

    var board = new five.Board({io: io, repl: true});

    board.on('ready', function(){
        var led = new five.Led(12);
        led.blink(3000);
    });
});

This code is to test the connection between Arduino and Nodejs and when I run this file, it doesn't work.

just leave esp and your computer connected to your W3

@ Juraj I tried that. I connected my esp and computer to the W3 wifi and run the javascript code (that I added to my question) and it still can't connect to the internet.

what has internet to do with what you try to do?

you missed this line in the tutorial "I assume you have already flashed standard firmata on your Arduino"

Spend some time researching what each line of your Arduino sketch does. If you're using that sketch with that schematic you clearly don't understand the most basic principles of what it's intended to do. You're just using the Uno as a USB-serial adapter and the sketch on the Uno is doing absolutely nothing useful.

@per1234 sure with reset connected to ground every sketch is useless :-)

@per1234 I actually forgot to add that I used a different sketch for my Arduino Pro Mini. The sketch that I used above (on my Arduino Uno) is only used when I run the AT command to connect my ESP8266 to W3. I used StandardFirmataPlus sketch when I tried to control Arduino using nodejs. So I did flash the standard firmata on my Arduino, with the same baud rate with my ESP8266 (currently 115200).

But I understand that I only used my Arduino Uno as USB-TTL connector so I will edit my question. @Juraj I need the internet to control arduino using nodejs and chrome puppeteer.

ok. so you have Firmata in Atmega, AT firmware in ESP and the 'blink led' js on computer. does the led blink? or where is the error?

@Juraj yes correct. The LED doesn't blink. And the terminal doesn't show any error.

does this io.once() mean that the led blinks only once? I you sure it did not blink?

@Juraj once() function in javascript is executed only once. That means the board variable is only created once. But the function inside board.on('ready',function()) should allow the led to blink infinitely. I only knew this because it works without the esp8266, when I tried to control Arduino using nodejs while the arduino is connected to my laptop

you have Firmata in Atmega, AT firmware in ESP and the 'blink led' js on computer.
you did not follow the tutorial properly. it requires jonny-five firmware in esp8266

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference.  Link-only answers can become invalid if the linked page changes. - From Review

I edited the answer

@Juraj I did upload the johnny-five firmware on my first ESP8266 but then I couldn't connect to an existing wifi network using the method that the author mentioned in the article. I then tried to use AT command but failed. I figured that maybe when I flashed the Johnny-five firmware on the ESP, I wiped the firmware that needed to run the AT command. Then I bought another ESP8266 just to test. This time I used AT commands to connect to an existing network, but as you can see, it cannot connect to the internet, or my arduino.

AT firmware, jonny-five or your sketch. those are only programs in the esp. what you flash there, runs there. I do not know the johnny-five firmware.


text:
DS18B20 oneWire analog vs digital
I just discovered that the Dallas DS18B20 can be read from either digital or analog pins. I never thought analog was an option until I stumbled across an article searching for another issue.
So now I'm wondering, if I have a dozen DS18B20's on about 20 feet of wire with a 4.7k resistor, what would be the better option for reading? Digital or Analog?

the Analog on an Arduino Uno means those pins are analog-capable (not all the GPIO pins are analog-capable), meaning that they can be configured to be an analog input instead of just as digital input/output. 2)DS18B20 is a digital sensor communicating using 1-wire protocol, it is a bus, meaning multiple DB18B20 can share the same bus.

To use multiple DS18B20 devices on the same bus
1/ First get the address of each DS18B20 device by attaching it alone to the Arduino, and calling the discoverOneWireDevices(); function. Write down the address. This is a set of 8 hexadecimal digits, eg 0x28, 0x13, 0x97, 0x9A, 0x0A, 0x00, 0x00, 0x6A
2/ Hard-code the address of each device, e.g. #define TEMP_SENSOR1 {0x28, 0x13, 0x97, 0x9A, 0x0A, 0x00, 0x00, 0x6A} before the call to the setup, and define the corresponding device address: DeviceAddress tempSensor1 = TEMP_SENSOR1;
3/ each time you launch a command to a DS18B20, specify to which you are speaking, eg temperature1 = sensors.getTempC(tempSensor1);

Analog is not an option as the 1-wire is a digital communication bus, however using an analog pin is on many processors to do this is possible. This is achieved on many of the processors because the analog pin can be configured and used for digital I/O.  Arduinos such as the UNO can accomplish this because of the processor they use. Note not all microprocessors are designed use an analog pin for digital I/O.
There is an application note by AMD called "1-Wire Search Algorithm", https://www.analog.com/en/app-notes/1wire-search-algorithm.html. By using this process you can read all of the sensors independently without knowledge of there addresses. Using this method will not guarantee which sensor you are reading but the sequence will repeat and you can simply replace a sensor but the order will probably change. This allows you to change sensors etc when there are not many sensors involved. Here are some links to better explain this.
https://docs.arduino.cc/learn/communication/one-wire
https://www.arduino.cc/reference/en/libraries/onewire/


text:
How do I join two RGB ledPanel 32x64 in order to get one 64x64?
I'm making a project to make a pixelArt of 64x64 using two 64x32 RGB ledMatrix and Arduino MEGA.
This is the RGB Panel I am using.
I use ADAFruit and RGBMatrixPanel libraries in my Arduino Code and if I connect the Arduino pins to the RGB panel it works, but the problem is when I try to connect the output of the first panel to the input of the second, I saw the "same image duplicated" but with different brightness, and if I change the length of the panel seems to print random LEDs.
I know that Adafruit is thought to get a screen with max of height of 32, but I don't care, because for my purpose you can assign each pixel programmatically in order to print the proper image.
I followed this guide in order to make the connection with a panel of 64x32.
I think that I have to change my code and also my physical connections, but I don't know how, can anyone help me?
Other option that I thought was create another matrix2 instance at the same code using different PINS, but this is very weird.
This is the current connections: (I have a power supply of 5v - 10A)

This is the result that I have: (duplicated in both screens with a brighness/weird shadow in the second)

And this is the final result that I'm looking for: (this is made with two Arduino Megas)

Thanks in advance!

please provide a link to the panel datasheet

It looks like a 64x64 will actually be a 128x32.

Hi, I dont have that documentation, i guess that is an standard one?

First off, connecting the 2nd panel to the same output pins as the first one, you are simply sending same data to the 2nd panel, which is why you get the duplicate visuals. I'm guessing you are sending power that same way, which is why you are seeing the brightness dim.
Secondly, it's hard to read on the pics in the AliExpress listing, but the Sparkfun site had a better image, which shows an "Output" connection on the back of the panels.  You need to daisy chain the 2nd panel to the first panel through this "Output" connection. This should prevent you from having to create a 2nd matrix2 and use a 2nd set of pins.
Third, having a 2nd set of pins and controlling the 2nd LED matrix can make updating the image faster. It depends on your library as well as how the LED matrix is made, so it really depends on those factors, but some LED systems are designed so there is a maximum amount of pixels that can be displayed before there's a noticeable delay in LED updated. With this amount of LED pixels, you're probably fine, but if you want fast updates and expect to expand your matrix in the future, you might want to consider driving the panels separately. I'm not saying you have to now, but if you're seeing lag, this might be a good option.

Hi, I added some pictures of the project, as you c an see i have enought power supply for both screens (is not a brighness change, it has also a weird shadow on each character and changes the color a bit)
Thanks for your help!!! I really appreciate it.

@JorgeMartínMartí, are you talking about the diagonal lines on the Link image for the shadows? That could be a slow refresh rate or a mismatch of frame rate between the matrix and your camera. If you're talking about the "fuzz" around the pixel in the letters, that's because you don't have the white screen up against the matrix, allowing the light to bleed a little. It's also likely going to happen anyway, unless it's a polarized sheet. The white sheet will absorb some of the light/wavelengths due it it not being 100% transparent. Hopefully I'm understanding what you're describing.

BTW, that looks really good already!

No, i know that these lines is just in the photograph, but not in real view. You can oberve the differences in the image with text (the color is different), but the programing code is just the same, i mean this kind of changes in person you can see a different brightness and different color, and also a small shadow (fuzz), and this only occurs in the second (bottom) screeen that is replicating the stuff of the previous one, so we can discard the issue with the white sheet (it occurs with the isolated panel too) so should be a problem with the program or the wire connections. TY

I think I see the color difference now, but I'm still missing the shadow. The color difference could be a different random color selected for the letter. Since I can't see the code, it's just a WAG. If it was a loose wire, you wouldn't get a coherent image, since it's a digital, not analog, signal. It either works or it doesn't. The color looks good and consistent on the Link image. You might try solid colors across both panels to see if there really is a color difference. Pick specific colors and see what happens. It could be the LEDs are mis-wired. Good luck fixing that though.

Yeah, the shadow is not clear appreciable on the picture but still there with the color issue..., we can discard a wire failure (because I tried with several wires), also we can discard a random color code issue, because all of the colors are fixed, and if print an image, the same image, the colors on the second screen still different (I tried with another screens so we can discard also a screen failure). So i think that the issue is related with the code or with the wire connection. Thank you very much, i will try making some changes on my code, maybe the arduinoMega is not enough for 64x64

@JorgeMartínMartí, if possible, and if it's generated color values, I'd suggest looking at the output of the code, so you know for sure that the color values are the same. If it's hard coded values, I'd still double-check to make sure nothing got fat-fingered. As far as the shadow goes, try it without the front cover. It may be some weird reflection between that and the LED backing material. Without seeing it IRL, I'm afraid I'm out of suggestions. Good luck!


text:
MAX30102 not working?
I have a project to find the pulse oximetry rate. I used MAX30102 and ESP8266 as shown in the first picture.
Wiring
GND ------> GND
VIN ------> 3.3V
SDA ------> D2
SCL ------> D1

Code
I also used the following code in esp2866 programming:
#include <Wire.h>
#include "MAX30105.h"
#include "spo2_algorithm.h"

MAX30105 particleSensor;

#define MAX_BRIGHTNESS 255

uint32_t irBuffer[100]; //infrared LED sensor data
uint32_t redBuffer[100];  //red LED sensor data

int32_t bufferLength; //data length
int32_t spo2; //SPO2 value
int8_t validSPO2; //indicator to show if the SPO2 calculation is valid
int32_t heartRate; //heart rate value
int8_t validHeartRate; //indicator to show if the heart rate calculation is valid

void setup()
{
  Serial.begin(115200); // initialize serial communication at 115200 bits per second:

  // Initialize sensor
  if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
  {
    Serial.println(F("MAX30102 was not found. Please check wiring/power."));
    while (1);
  }

  Serial.println(F("Attach sensor to finger with rubber band. Press any key to start conversion"));
  while (Serial.available() == 0) ; //wait until user presses a key
  Serial.read();

  byte ledBrightness = 60; //Options: 0=Off to 255=50mA
  byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
  byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
  byte sampleRate = 100; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
  int pulseWidth = 411; //Options: 69, 118, 215, 411
  int adcRange = 4096; //Options: 2048, 4096, 8192, 16384

  particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
}

void loop()
{
  bufferLength = 100; //buffer length of 100 stores 4 seconds of samples running at 25sps

  //read the first 100 samples, and determine the signal range
  for (byte i = 0 ; i < bufferLength ; i++)
  {
    while (particleSensor.available() == false) //do we have new data?
      particleSensor.check(); //Check the sensor for new data

    redBuffer[i] = particleSensor.getRed();
    irBuffer[i] = particleSensor.getIR();
    particleSensor.nextSample(); //We're finished with this sample so move to next sample

    Serial.print(F("red="));
    Serial.print(redBuffer[i], DEC);
    Serial.print(F(", ir="));
    Serial.println(irBuffer[i], DEC);
  }

  //calculate heart rate and SpO2 after first 100 samples (first 4 seconds of samples)
  maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);

  //Continuously taking samples from MAX30102.  Heart rate and SpO2 are calculated every 1 second
  while (1)
  {
    //dumping the first 25 sets of samples in the memory and shift the last 75 sets of samples to the top
    for (byte i = 25; i < 100; i++)
    {
      redBuffer[i - 25] = redBuffer[i];
      irBuffer[i - 25] = irBuffer[i];
    }

    //take 25 sets of samples before calculating the heart rate.
    for (byte i = 75; i < 100; i++)
    {
      while (particleSensor.available() == false) //do we have new data?
        particleSensor.check(); //Check the sensor for new data

      redBuffer[i] = particleSensor.getRed();
      irBuffer[i] = particleSensor.getIR();
      particleSensor.nextSample(); //We're finished with this sample so move to next sample

      //send samples and calculation result to terminal program through UART
      Serial.print(F("red="));
      Serial.print(redBuffer[i], DEC);
      Serial.print(F(", ir="));
      Serial.print(irBuffer[i], DEC);

      Serial.print(F(", HR="));
      Serial.print(heartRate, DEC);

      Serial.print(F(", HRvalid="));
      Serial.print(validHeartRate, DEC);

      Serial.print(F(", SPO2="));
      Serial.print(spo2, DEC);

      Serial.print(F(", SPO2Valid="));
      Serial.println(validSPO2, DEC);
    }

    //After gathering 25 new samples recalculate HR and SP02
    maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
  }
}

Error
When executing, it showed me in the window that:
11:48:31.564 -> MAX30102 was not found. Please check wiring/power.

I have used two of the max30102, but it shows the same result.
The MAX30102 does not turn on and the light also doesn't work. Are there any solutions?

The text and the wiring image show two different connections: The first with SDA to pin D1 and SCL to pin D2, while the image shows them swapped. What do you actually have on your hardware?

Yeah sorry ,I made a mistake , SDA ---->D2    SCL----->D1  I will adjust it.

Can you please try the I2C Scanner sketch and see if there are any devices reported on the I2C bus? It just checks at what addresses there are devices that actually answer on the bus.

Ok,thanks for the reply, . I tried it, but after executing it shows me a window that  "No I2C devices found".

please post a clear, well lit, in focus picture of the wiring

@jsotola ok i added another picture

@chrisl I try agagin the I2C scanner after removed resistors now it display "i2c device found at address 0x57 done " but the led not lit

Before someone pulls the trigger on closing this, please note that they'd added the wiring image requested. It just wasn't displaying owing to a markdown problem (now corrected).

Alright, no one else is going to say it, so I will: You have particleSensor.begin(Wire, I2C_SPEED_FAST).   Switch this to I2C_SPEED_STANDARD and see if it makes a difference and use the configuration you'd seen return 0x57 in the scanner.


text:
NRF24 and Arduino Nano Every usage
Im building an RC car project and using 2 NRF24's for communication. I own an Arduino Uno, Nano and Nano Every. The NRF's work great with the Uno and Nano in any combinations but using a Nano Every either as TX or RX doesn't work.
I have tried the NRF24 and NRFLite and both say "Cannot communicate with radio".
When using the NRFLite library examples Basic_TX on the Uno/Nano and Basic_RX on the Nano Every, the Uno/Nano says transmission was successful even though the Every says "Cannot communicate with radio". This lasts about 1 second before the Uno/Nano says the transmission failed again. This happens every time you reset the Every. It is as if the NRF24 gets powered on but then is unable to communicate with the Every.
I am using power adapters for the NRF's and powering them through the 5v pin. No luck with capacitors either. Have swapped out all the wires and also double checked all connections.
Is there something wrong with the Nano Every? Does it work with a NRF24 for anyone?
I have completely ran out of ideas to fix this.
Thank you in advance

How do you wire the Nano Every and define your pin definition on your sketch? Nano Every has SS pin on D8, not like most of the Arduino AVR-based boards on pin 10.

Hi hcheung! I have the SCK on D13, MISO on D12, MOSI on D11, CE on 7 and CSE on 8. I'm not sure what the SS pin is :(

SS is Slave Select, some called Chip Select (CS), you might want try to use pin 8 as CE, and pick another pin for CSE.

Sadly no luck with that. I bought a new nrf24 and that didnt help either, it worked with the regular Nano tho. Looks like my Nano Every is just broken.

I stucked with the same problem too when use nRF24L01+ and Arduino Nano Every to transmit data to Arduino Uno with nRF24L01+. So I have solved the problem as follows below. I hope it could help you and for somebody else.

First of all you should add Arduino megaAVR Boards in the boards manager.

1.1 It is first necessary to add the URL of their Boards Manager JSON file in: File > Preferences > Additional Boards Manager URLs and Paste the link: https://raw.githubusercontent.com/amperka/iskra-boards/master/package_amperka_index.json
1.2. Then go to Tools>Boards Manager, search Arduino SAMD Boards and install it

1.3. Choose Arduino Nano Every in Tools>Board>Arduino megaAVR Boards>Arduino Nano Every

Upload the library for RF24. It must be compatible for architecture megaavr because  Arduino Nano Every uses Microchip ATmega4809. I use the latest version RF24-1.4.1.
Here is the link to the library: https://www.arduinolibraries.info/libraries/rf24

You should check whether you connected nRF24L01+ and arduino correctly.

The pinout of Arduino Uno is as follows:
5V - VCC if you connect nRF24L01+ via nRF24L01+ adapter (I use adapter)
or 3.3V - VCC without adapter
GND - GND
9 pin - CE
10 pin - CSN
11 pin - MOSI
12 pin - MISO
13 pin - SCK
not connected - IRQ
However, I use another pinout for Arduino Nano Every. When I use the same pinout as Arduino Uno it can't find nRF24L01+. You can check it in Serial Monitor by using a sketch below. If you get zeros in the third line, for example, something like this: RX_ADDR_P0-1 = 0x0000000070 0x0000000000. It means that Arduino Nano Every isn't connected to nRF24L01+ correctly and Arduino Nano Every doesn't see it.
I suppose the problem with the library of RF24 and it should be fixed. Perhaps I'm wrong and the problem with another things.
So I use the following pinouts for Arduino Nano Every:
5V - VCC if you connect nRF24L01+ via nRF24L01+ adapter (I use adapter)
or 3.3V - VCC without adapter
GND - GND
10 pin - CE
A3 - CSN (if you will get zeros in the third line RX_ADDR_P0-1 in Serial Monitor then change A3 to another one. You can vary pin from A5 and so on until A0). do not use A7 and A6 because on some model dev boards, A6 and A7 are analog input only.
11 pin - MOSI
12 pin - MISO
13 pin - SCK
not connected - IRQ
The sketch for checking:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(10,A3);  // for arduino nano every
//RF24 radio(9,10); // for arduino uno

const uint8_t num_channels = 128;
uint8_t values[num_channels];
void setup(void)
{
  Serial.begin(9600);
  printf_begin();
  radio.begin();
  radio.setAutoAck(false);
  radio.startListening();

  radio.printDetails();
  delay(5000);

  radio.stopListening();
  int i = 0;
  while ( i < num_channels )  {
    printf("%x",i>>4);
    ++i;
  }
  printf("\n\r");
  i = 0;
  while ( i < num_channels ) {
    printf("%x",i&0xf);
    ++i;
  }
  printf("\n\r");
}
const int num_reps = 100;

void loop(void)
{
  memset(values,0,sizeof(values));
  int rep_counter = num_reps;
  while (rep_counter--) {
    int i = num_channels;
    while (i--) {
      radio.setChannel(i);
      radio.startListening();
      delayMicroseconds(128);
      radio.stopListening();
      if ( radio.testCarrier() )
        ++values[i];
    }
  }
  int i = 0;
  while ( i < num_channels ) {
    printf("%x",min(0xf,values[i]&0xf));
    ++i;
  }
  printf("\n\r");
}
int serial_putc( char c, FILE * ) {
  Serial.write( c );
  return c;
}

void printf_begin(void) {
  fdevopen( &serial_putc, 0 );
}

Here is the correct output in Serial Monitor
the third line without zeros: RX_ADDR_P0-1  = 0xf0f0f0f0d2 0xc2c2c2c2c2
SPI Speedz  = 10 Mhz
STATUS      = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1    = 0xf0f0f0f0d2 0xc2c2c2c2c2
RX_ADDR_P2-5    = 0xc3 0xc4 0xc5 0xc6
TX_ADDR     = 0xf0f0f0f0d2
RX_PW_P0-6  = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA       = 0x00
EN_RXADDR   = 0x02
RF_CH       = 0x00
RF_SETUP    = 0x14
CONFIG      = 0x0f
DYNPD/FEATURE   = 0x38 0x38
Data Rate   = 1 MBPS
Model       = nRF24L01+
CRC Length  = 16 bits
PA Power    = PA_HIGH
ARC     = 15

the next two lines are a list of available channels that should be read from top to bottom (i.e. we have 127 channels, еру channels are presented in 16-bit version, the first line is the first digit of each of 127 channels, the second line is the second digit of each of 127 channels).
00000000000000001111111111111111222222222222222233333333333333334444444444444444555555555555555566666666666666667777777777777777

0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

then the level of noisiness of the channels is displayed.
There are noise from the channel 09 to the channel 3f approximately.
this noise from my wifi router and some another electronics.
you should choose free channels for your purpose.
00000010114663444533233300000000001000011233544433221100112223212010000000000000000000000000000000000000000000000000000000000000

00200000035575656777697332111321022125625559643632551111000333012000000000100000010001000000001000000000000011010000000000000000

00000001135a9a767767c89a85646565866555645897434644445200121212122000000000000000000000001000000000000000011000000010000000000000

00101000035567667357878a51123341220322335373542222122000112313112000000001010000000001000000020000000010000000000000100000000010

11000011047587577457694521122232111121243247542232210100002222111000000000100002000002000000000000000000000000000010000000000000

Note:

Check Tools. There should be:
Board:Arduino Nano Every;
Registers emulation: "ATMEGA328";
Port:COM#(Arduino Nano Every).

some transmission errors can occur due to poor contacts between wires and pins of arduino, so the wires should be soldered.

If everything is ok, then you can use your sketches for the receiver and transmitter respectively. Good luck!

so you say: pin 9 doesn't work as CE or pin 10 doesn't work as CS if Nano Every is used with ATmega328 emulation? could you try which one is the problem?

The problem is that CSN doesn't work on digital pins of Arduino Nano Every but it works on one of Arduino Uno. CSN works only on analog pins (A5-A0) of Arduino Nano Every. CE works well if you connect it to the 9 or 10 pin of arduino nano every. Actually I have found it accidentally.

UPD: If you use registers emulation "None (ATMEGA4809)" it works too. I mean if you use pinout as shown above. Otherwise it doesn't work.

I have no problem to use pin 10 as CS (for Ethernet) even in 328p emulation mode

Thank you for those excellent instructions.
After days of trying to get this danged Nano Every to work with the nRF24L01+, your guide got it going! I can't think you enough. I hope it's ok to share this URL with others who are also struggling to date...?? Cheers


text:
The Arduino copy of example code for tone() function produces a compile error: 'tone' is not declared in this scope. How can I fix this?
It's 32-bit ARM core processor is SAM3X8E ARM Cortex-M3 CPU.
Error:
sketch_nov16b\sketch_nov16b.ino: In function 'void setup()': sketch_nov16b:49:43: error: 'tone' was not declared in this scope tone(8, melody[thisNote], noteDuration);
^ sketch_nov16b:61:13: error: 'noTone' was not declared in this scope noTone(8);
^ exit status 1 'tone' was not declared in this scope

Code:
/*

  Melody

  Plays a melody

  circuit:

  - 8 ohm speaker on digital pin 8

  created 21 Jan 2010

  modified 30 Aug 2011

  by Tom Igoe

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/Tone

*/

#include "pitches.h"

// notes in the melody:
int melody[] = {

  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {

  4, 8, 8, 4, 4, 4, 4, 4
};

void setup() {

  // iterate over the notes of the melody:

  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second divided by the note type.

    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.

    int noteDuration = 1000 / noteDurations[thisNote];

    tone(8, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.

    // the note's duration + 30% seems to work well:

    int pauseBetweenNotes = noteDuration * 1.30;

    delay(pauseBetweenNotes);

    // stop the tone playing:

    noTone(8);

  }
}

void loop() {

  // no need to repeat the melody.
}

What core are you using?

It's 32-bit ARM core processor is SAM3X8E ARM Cortex-M3 CPU

Does this meet jsotola's request?sketch_nov16b\sketch_nov16b.ino: In function 'void setup()':
sketch_nov16b:49:43: error: 'tone' was not declared in this scope
tone(8, melody[thisNote], noteDuration);
^
sketch_nov16b:61:13: error: 'noTone' was not declared in this scope
noTone(8);
^
exit status 1
'tone' was not declared in this scope

@JohnB I said do not paste into a comment and you pasted into a comment ... this site is not a forum ... it is a question and answer site ... all info must be contained in the question

In short, they just never implemented tone() in the Due/SAM core.
So you're not going to get the normal tone() function working.

The tone.h header is empty.
They probably should done any number of things that would produced a somewhat clearer warning about this.

The counterpart .cpp file has been renamed to .cpp.disabled so that the no attempt is made to compile it and is full of AVR-based code that they'd copied into the project for reference with the intention of replacing it but never did.

There a github issue tracking this. But it hasn't been updated since 2020. That issue references the Arduino forum for apparently working alternative code for producing tones. So maybe try their code.
I don't see any popular alternative packaged as an Arduino library for producing simple tones. However, the chip has a DAC and there is an Audio Library. It's a bit overkill for producing basic tones, but you could modify the example there to fill the buffer with a tone's waveform rather than loading it from an sdcard file.


text:
Problem adding library in the Arduino IDE
Currently, I'm trying to build image processing on ESP32 using OpenCV GitHub - joachimBurket/esp32-opencv: Shrinked OpenCV for ESP32. Then I want to put this library into Arduino IDE.
But, I'm having problem "Specified folder/zip file does not contain a valid library".  Is there a file that must be deleted to be included in the Arduino IDE libraries? And, I previously also tried manual input. But, not everything was detected by the Arduino IDE.
Please give me a way out as I am new in this field.

it is not an Arduino library

As Juraj wrote, this is not an Arduino library. It is meant to be compiled directly with the esp-idf toolchain, outside of the Arduino framework. To use it you would first have to port it to the Arduino framework, which is probably rather tedious.

Thank you for your answer. what if i change or adapt to the arduino libraries and manually input to arduino ide libraries, is it possible?


text:
Nature of the voltage reference instability of internal 1.1V reference of ATmega328P (Nano)
The ATmega328P data sheet in table 29-11 on page 324 notes that the internal 1.1V reference (VBG) may vary between 1.0V and 1.2V. In this answer this is called "not stable or accurate".
Question: Is this "unstable" or "inaccurate" or even both if I define it as

"unstable" if it varies over the day, say with temperature or VCC or or some such.
"inaccurate" if it is a rather stable voltage for a specific Nano-board I have in hand, just not the typical 1.1V.

In the latter case I could measure the value accurately and scale my analog measurements with the measured value instead of the 1.1V.

I would say it was "stable but not accurate". The internal reference uses a bandgap voltage reference, which is pretty stable over the operating temperature range of the IC.
The output of the bandgap reference is fed through an amplifier to buffer it, which may introduce some instability with temperature, but this is not documented so cannot even be estimated.
The inaccuracy comes from minor differences in the manufacturing process. These don't change over time, so once calibrated for a precise value of voltage reference you should not see much in the way of variance in that value for different temperatures or power supply fluctuations.


text:
I'm working on a NodeMCU project and have a small doubt about LEDs and resistors
In my NodeMCU I want a statement to turn on an LED, which is easy, just use pinnumber, HIGH. But, what I'm trying to do here is connect multiple LEDs to one pin like this:
I just wanted to know if this will work and whether all the LEDs will turn on by one command write (pinnumber, high) or do I have to do something else to this circuit?
Please help I'm a noob to electronics.
And also, is the resistor correct(1k ohm) or is it 220ohm, because different places suggest different things.

No! Most likely it will not work.
An LED lights up if the Voltage between the Anode (one side of the LED) and cathode (the other leg) exceeds a so called forward voltage (Vf).
This Vf depends on the creation process and differs between different colors. Vf can be between abt. 1.8 Volt (red LEDs) and abt. 4.2 Volt (blue LEDs). Even if the LEDs would have the same color, they might have different forward voltages. If you arrage 4 LEDs in parallel, like you did above, the Voltage over the 4 LEDS is as low as the Vf of the LED with the lowest Vf among the four. If the four LED would not have equal (Vf)s, only one LED will light up and all others stay dark or just glow a little bit.
The sum of the current that flows through the 4 LEDs must also flow through the resistor. So the resistor must let pass 4 times the current that is required for one LED. An normal 3mm or 5mm LED works best at about 10mA to 20mA. Let's say the LEDs have all the same Vf = abt. 2 Volts, and you choose to drive them with 15 mA.
You need 60 mA in sum for the 4 LEDs, that must pass the resistor. You can compute the required resistance with  Ohms law. R = U / I.

R is the resistance in Ohms.

U is the voltage over the resistor in Volts.

I is the current through the resistor in Ampere.
U = Voltage of the ESP (3.3 Volt) minus
the lowest forward voltage of the LEDs (2 Volt)
I = the wanted current 60mA = 0.06 Ampere
R = (3.3-2) / 0.06 = 140 / 6 = abt. 23 Ohm
(27 Ohm resistors should be available.)

The resistor depends on the Voltage of the ESP, the kind of the LED and the amount of current you need to reliably light up the LEDs. You can not just take values from schematics or discussions the internet. Also 60 mA is very much current for the ESP pin. That might be a problem.
The best way the Light up 4 LEDs from one pin would be to use one resistor for each LED and a MOS FET Transistor that is connected to 5 Volts with its Drain pin, the parallel LED resistor pairs with its Source and to the ESP pin with its Gate. You should also be sure that the MOS FET you use is able to switch with a 3.3 V voltage from the ESP on its Gate.
If you did not understand what I have written, I advice you to learn the basics before experimenting further. The values above are all useless if the conditions change.

Yes, technically your circuit works. But don't do like this.
TLDR;
This applies only to what you are doing

LED is current device. We control brightness by control current flow through it.
Each IO pin (of ESP8266) has current drive capable (source/sink) 12mA only, so calculate it wisely or you risk killing it.
Simplest way to control current of LED is using current limiter or just a resistor in series
Voltage drop across red LED (Vf) is 1.8v
4 LEDs in parallel work just like 1 LED, assuming the same kind, but of course 4 times dimmer
Current goes through each LED = 1/4 of current goes through resistor (kirchhoff law of current)
Equation: 3v3 = 1.8v + V_R hence , V_R = 1.5v
Current goes through resistor I_R = V_R / R
5mm LED has nominal current of 20mA to be considered brightest that last VERY long time.
BUT ESP8266 can only do 12mA. You go 20mA, ESP8266 goes bye bye.
So choose 10mA to be on safe side. Plug 10mA into #8, hence R = 1.5v / 10mA = 150 ohm
You can choose resistor value from 220R up to 1K, no problem. Higher resistance, less current.
You can do rough calculation, ignore voltage drop across LED, just use 3v3 / 10mA = 330R. Hence you will see people usually use resistor 330 ohm regardless 3v3 or 5v, red LED or green LED. Because at 5v it is 15mA, red or green makes only 0.3mA different. Nothing to worry.
But your circuit has 4 LEDs in parallel, hence current through each LED = 10mA/4 = 2.5mA
Fact: Even as low as 0.15mA (R=10k with 3v3 power supply), RED and GREEN LEDs are still bright enough for indication.

Note:

My guess is, you are using LEDs like a torch. More LEDs = more brightness, right? Unfortunately, it won't work like that. You want to use transistor (BJT) or mosfet as a switch to turn on power supply for LED instead of driving LED from IO pin. Google high side switch or low side switch for that matter. Better solution is to use LED driver IC.
Normally for simple indicator, I just whack a 470R resistor in series of a LED regardless voltage to drive it (5v or 3v3). It still gives quite intense brightness when you stare directly on it. Sometime you want to use 1k ohm just to reduce the brightness further or even sanding the LED from crystal clear into translucent white.


text:
L298N motor driver problems
(edited)
So sorry my bad. To make it clear:
From the picture that I posted, I need to press the PBA (as Button1) so that both motors can run in forward (CW-clockwise)  and backward (CCW-counterclockwise) and  a stop.
While on the other hand, PBB (as button2) is for another condition  both motors can run in left, right, and stop.
Problems:

When I run my code, it appears glitching from my LCD display.

I able to achieve for PBB side but for PBA side, both motors don't move at all.

I had use potentiometer to adjust my speed. The potentiometer are doing fine.

I use debounce for both my buttons and I am not sure whether the debounce effect my void setmode(int Mode, int MotorMode1){}

////////////////////////////////////////////////////////////////////////////////[![enter image description here][1]][1]

boolean lastButton=LOW;
boolean currentButton = LOW;

boolean last1Button = LOW;
boolean current1Button = LOW;

boolean debounce(boolean last){
    boolean current = digitalRead(PBA);
    if (last != current) {
      delay(5);
      current = digitalRead(PBA);
      return current;
    }
  }

  boolean debounce1(boolean last1) {
    boolean current1 = digitalRead(PBB);
    if (last1 != current1) {
      delay(5);
      current1 = digitalRead(PBB);
      return current1;
    }
  }

  int Mode = 0;
  int motorMode1 = 0;

  void loop() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("SPEED:");
    lcd.setCursor(0, 1);

    // potentiometer LCD
    float inputValue = analogRead (pot);
    inputValue = map(inputValue, 0, 1023, 0, 100);
    lcd.setCursor(7, 0);
    lcd.print (inputValue);
    lcd.setCursor(12, 0);
    lcd.print ("%");

    //read values from potentiometer
    MotorSpeed = analogRead(SpeedControl);
    MotorSpeed = map(MotorSpeed, 0 , 1023 , 0 , 255);
    // adjust to prevent at low speed
    if (MotorSpeed < 8)MotorSpeed = 0;
    //set the motor speed
    //analogWrite (enA, MotorSpeed);
    //analogWrite (enB, MotorSpeed);
    // MotorLCD
    lcd.setCursor(0, 1);
    lcd.print("MOVE:");

    currentButton = debounce(lastButton);
    if (currentButton == HIGH && lastButton == LOW) {
      Mode++;
    }
    lastButton = currentButton;
    if (Mode == 3){
      Mode = 0;
    }

    current1Button = debounce1(last1Button);
    if (last1Button == HIGH && current1Button == LOW) {
      motorMode1++;

    }
    last1Button = current1Button;
    if (motorMode1 == 3){
      motorMode1 = 0;
    }

  setMode( Mode, motorMode1);

 }

  void setMode(int Mode, int motorMode1) {
    analogWrite (enA, MotorSpeed);
    analogWrite (enB, MotorSpeed);

    if (Mode == 1 ) {
      lcd.setCursor(5, 8);
      lcd.print("Forward");

      //MOTOR_A CLOCKWISE MAX SPEED
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);

      //MOTOR_B CLOCKWISE MAX SPEED
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
    }
    if (Mode == 2) {
      lcd.setCursor(5, 8);
      lcd.print("Reverse");

      //MOTOR_A COUNTERCLOCKWISE MAX SPEED
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);

      //MOTOR_B COUNTERCLOCKWISE MAX SPEED
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);

    }

   if (motorMode1 == 1) {

      lcd.setCursor(5, 8);
      lcd.print("Right");
      //MOTOR_A CLOCKWISE MAX SPEED
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      //MOTOR_B COUNTERCLOCKWISE MAX SPEED
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);

    }
    if (motorMode1 == 2) {
      lcd.setCursor(5, 8);
      lcd.print("Left");
      //MOTOR_A COUNTERCLOCKWISE MAX SPEED
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      //MOTOR_B CLOCKWISE MAX SPEED
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);

    }
     if (Mode == 0 || motorMode1 == 0) {
      lcd.setCursor(5, 8);
      lcd.print("Stop");
      digitalWrite(in1, LOW);
      digitalWrite(in2, LOW);
      digitalWrite(in3, LOW);
      digitalWrite(in4, LOW);
    }
  }

If you want someone to help you, format your code properly and shorten it only to focus on the area where you think potentially  caused the problem.

There's a Tools/Auto Format menu option in the IDE for this.

BTW: What is the question? And, what do you mean with asynchronously and synchron? And, why do you use two names for A0 pin (pot, SpeedControl)? Why do you name output pins "inX"? Why do you set inX in the mode function first depending on the Mode variable and then overwrite it depending on the motorMode1 variable? But the most important question is: What do you want to achieve? Try to explain it, and perhaps you'll see yourself what's going wrong. We might help if we'd know what your goals are. Only looking at the code, I can not say what you are trying to do. ;-)

Hi peter, I had already upload a picture so that you can understand properly.

why do you use two names for A0 pin (pot, SpeedControl)?
I had declared twice with different function and that's cause confusion and I deleted it.

2.Why do you name output pins "inX"? Why do you set inX in the mode function first depending on the Mode variable and then overwrite it depending on the motorMode1 variable?
inX - for the Ln298 motor output
there are 4 inX outputs.
and 2 enX outputs under PWM.
Thanks for the comments. :D

I hope I understood you correctly. The best way would be to tell you how you can use states to get the problem solved. But that would cost me too much time.
I decided to edit your program. I have no hardware to try it. So it is just an example to show you the idea. Perhaps it works as it is.
Please check the comments. If you are really interested in understanding to problem and the solution and things are unclear,  you (or others) can ask with comments below. And of cause, if you find an error, I would be happy to know about it and correct it. ;-)
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// These are the different movement states
#define STATE_STOP 0
#define STATE_LEFT 1
#define STATE_RIGHT 2
#define STATE_FORWARD 3
#define STATE_BACKWARD 4

// always use expressive names

// The pin assignments
//////////////////////////////////////////////

// Analog
int pinPotiSpeed = A0;

// Motor A
int pinEnA = 9;
int pinInA1 = 8;
int pinInA2 = 7;

// Motor B
int pinEnB = 3;
int pinInB1 = 5;
int pinInB2 = 4;

// Buttons
const int pinBtnDir = 10;
const int pinBtnTurn = 11 ;

int stateMotors = STATE_STOP;
boolean flagBtnDirPressed = LOW;
boolean flagBtnTurnPressed = LOW;

int stateMotorsSpeed = 0;
int speedPercent = map( stateMotorsSpeed, 0, 255, 0, 100 );

LiquidCrystal_I2C lcd(0x27, 16, 2);

// I have not the time to think a lot about this debouncing, but
// I have a bad feeling. If the Arduino does not react on button presses
// or the mode change to quick please let me know. I'll have a look on it, if
// necessary. ;-)
boolean readButtonAndDebounce(int btnPin, boolean lastState)
{
    boolean actualState = digitalRead(btnPin);
    if (lastState != actualState)
    {
      delay(15);
      actualState = digitalRead(btnPin);
      return actualState;
    }

    // this return was missing in the original program
    return actualState;
}

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

    pinMode(pinEnA, OUTPUT);
    pinMode(pinInA1, OUTPUT);
    pinMode(pinInA2, OUTPUT);

    pinMode(pinEnB, OUTPUT);
    pinMode(pinInB1, OUTPUT);
    pinMode(pinInB2, OUTPUT);

    pinMode(pinBtnDir, INPUT);
    pinMode(pinBtnTurn, INPUT);

    digitalWrite(pinInA1,LOW);
    digitalWrite(pinInA2,LOW);

    digitalWrite(pinInB1,LOW);
    digitalWrite(pinInB2,LOW);

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

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("SPEED:");
    lcd.setCursor(0, 1);

    lcd.setCursor(7, 0);
    // convert 0-255 to 0%-100%
    lcd.print ("0 %");

    lcd.setCursor(0, 1);
    lcd.print("MOVE: Stop");
}

void loop()
{
    stateMotorsSpeed = map( analogRead( pinPotiSpeed ), 0, 1023, 0, 255 );
    if ( stateMotorsSpeed < 8 ) stateMotorsSpeed = 0;
    speedPercent = map( stateMotorsSpeed, 0, 255, 0, 100 );

    boolean flagBtnDirPressedOld = flagBtnDirPressed;
    flagBtnDirPressed = readButtonAndDebounce( pinBtnDir, flagBtnDirPressed );

    boolean flagBtnTurnPressedOld = flagBtnTurnPressed;
    flagBtnTurnPressed = readButtonAndDebounce( pinBtnTurn, flagBtnTurnPressed );

    // this is a bit tricky, because I don't know if i understood the problem correctly.
    // My problem is, what happens if both button are pressed, I decided to give
    // the Direction button the precedence
    if ( flagBtnDirPressed && ! flagBtnDirPressedOld )
    {
      switch( stateMotors )
      {
        case STATE_STOP:
          stateMotors = STATE_FORWARD;
          break;

        case STATE_FORWARD:
          stateMotors = STATE_BACKWARD;
          break;

        case STATE_BACKWARD:
          stateMotors = STATE_STOP;
          break;

        default:
          // this happens if a state from the other button is active
          // The table does not include a rule what to do in this case.
          // Perhaps you could count button click modulo 3 for each button
          // and then you can switch to the correct state
          stateMotors = STATE_STOP;
      }

    }
    else if ( flagBtnTurnPressed && ! flagBtnTurnPressedOld )
    {
      // this is only entered if press state of the direction button has not changed
      switch( stateMotors )
      {
        case STATE_STOP:
          stateMotors = STATE_RIGHT;
          break;

        case STATE_RIGHT:
          stateMotors = STATE_LEFT;
          break;

        case STATE_LEFT:
          stateMotors = STATE_STOP;
          break;

        default:
          // this happens if a state from the other button is active
          stateMotors = STATE_STOP;
      }
    }

    controlMotorAndUpdateLcd();
}

void setMotorSignals( boolean sigA1 , boolean sigA2, boolean sigB1, boolean sigB2 )
{
      //MOTOR_A
      digitalWrite(pinInA1, sigA1);
      digitalWrite(pinInA2, sigA2);

      //MOTOR_B
      digitalWrite(pinInB1, sigB1);
      digitalWrite(pinInB2, sigB2);
}

void controlMotorAndUpdateLcd()
{
    lcd.clear();
    lcd.setCursor( 0, 0 );
    lcd.print( "SPEED:" );
    lcd.setCursor( 0, 1 );

    // potentiometer LCD
    lcd.setCursor( 7, 0 );
    lcd.print ( speedPercent );
    lcd.setCursor( 12, 0 );
    lcd.print ("%");

    analogWrite ( pinEnA, stateMotorsSpeed );
    analogWrite ( pinEnB, stateMotorsSpeed );

    // MotorLCD
    lcd.setCursor(0, 1);
    lcd.print("MOVE:");

    lcd.setCursor(5, 8);
    switch( stateMotors )
    {
      case STATE_STOP:
        lcd.print("Stop");
        setMotorSignals( LOW, LOW, LOW, LOW);
        break;

      case STATE_FORWARD:
        lcd.print("Forward");
        setMotorSignals( HIGH, LOW, HIGH, LOW);
        break;

      case STATE_BACKWARD:
        lcd.print("Reverse");
        setMotorSignals( LOW, HIGH, LOW, HIGH);
        break;

       case STATE_LEFT:
        lcd.print("Left");
        setMotorSignals( HIGH, LOW, LOW, HIGH);
        break;

      case STATE_RIGHT:
        lcd.print("Right");
        setMotorSignals( LOW, HIGH, HIGH, LOW);
        break;
    }
}

Thanks for the help..
There is still some glitches on the LCD display. Do you have any idea why.? When I run void setup at the " welcome " part is still work fine until it reach the final state part where " Speed" and "Move". The wording is unclear and some have some glitches.

Sorry I don't understand what you mean by "glitches". Do you mean e.g the Speed value changes quickly. I can only help, if I know the error exactly. 2. I can not help you with the wording, but you can use texts that fits better for you.

It's okay Peter. I will try to solve it myself. Thanks a lot, Peter.