text:
String to persistent memory (EEPROM?)
I am creating a server node that I want to be able to save the wifi SSID and the password into persistent memory so that when it starts ups it can connect to the network. I have looked for several hours and found just a few bits of information. One bit I found here http://playground.arduino.cc/Code/EEPROMWriteAnything
#include <EEPROM.h>
#include <Arduino.h>  // for type definitions

template <class T> int EEPROM_writeAnything(int ee, const T& value) {
    const byte* p = (const byte*)(const void*)&value;
    unsigned int i;
    for (i = 0; i < sizeof(value); i++)
          EEPROM.write(ee++, *p++);
    return i;
}

template <class T> int EEPROM_readAnything(int ee, T& value) {
    byte* p = (byte*)(void*)&value;
    unsigned int i;
    for (i = 0; i < sizeof(value); i++)
          *p++ = EEPROM.read(ee++);
    return i;
}

This code will not store String values to the EEPROM. So as I thought I would ask for advice from the Stack Exchange geniuses.
Thanks!

I dont think Arduino.h has a string typedef. perhaps you can use a character array instead.

String is a type that exists in C++, so it doesn't need to exist in Arduino.h. Arduino uses C++, not C.

EEPROM library has two functions put and get , which can help you store character array of any size, not exceeding the size of internal EEPROM size of Arduino. Please see the examples provided in the link above.
Here is a sample code to get you going.
int address = 10;
char arrayToStore[20];                    // Must be greater than the length of string.
String testString = "hello there";

testString.toCharArray(arrayToStore, testString.length()+1);  // Convert string to array.

EEPROM.put(address, arrayToStore);                 // To store data
EEPROM.get(address, arrayToStore);                 // To read data

So this kept bugging me, if I want to get a value from the address how come I have to put a value that I want to store there as well?  What if I want to just read the values there?

I didn't get you, buddy. This is just an example sketch to show you how to store and read data in EEPROM locations. You have to make your own sketch for your requirement based upon this.

This is how I store my configuration data: I have a function to store the configuration, which will execute only occasionally whenever there is a config change. This mode is controlled by a jumper connection on my PCB. When the program restarts in regular execution mode, it just keeps reading the config data. The behavior is controlled by a check flag in  the startup code.


text:
SD test is taking long answer when it fails
I am working on an Arduino application that logs sensors values into SD files. It is essential that the SD is inserted and working when a test is started, thus I need to check the presence of the SD regularly (every 2 seconds or so) to prevent launching a test without SD inserted by the user.
When I run the following code, it runs very fast when the SD test succeeds (<10ms), but it takes more than 2000ms when the test fails. Is there another test I could run that does not takes 2 seconds to indicate that the SD is not inserted (or not working)? All my buttons are frozen and they do not trigger any action while checking if no SD is inserted.
Here is my code (both loops have the same issue):
#define csSD   53
#include <SD.h>

Sd2Card card;

void setup() {
  Serial.begin(57600);
  bool SDOK = SD.begin(csSD);
  if(SDOK) {
    Serial.println("SD.Begin Setup OK");
  } else {
    Serial.println("SD.Begin Setup Fail");
  }
}

unsigned long t;
//void loop() {
//  t=millis();
//  if(SD.begin(csSD)){ // SD.Begin test runs fast when there is a SD, even though it return true when you try to begin SD a second time
//    Serial.print("SD.Begin loop OK : ");
//  }else {
//    Serial.print("SD.Begin loop Fail : ");
//  }
//  Serial.println(String(millis()-t)+"ms");
//  delay(500);
//}

void loop() {
  t=millis();
  if(card.init(SPI_HALF_SPEED, csSD)) {
    // card.init test returns true as it should (when SD is present and working), but runs fast only when SD is working
    Serial.print("card.init loop OK : ");
  } else {
    Serial.print("SD.Begin loop Fail : ");
  }
  Serial.println(String(millis()-t)+"ms");
  delay(500);
}

Many SD card sockets have a presence detect switch, of course something in the socket which activates that is not necessarily a functional SD card.

What if you attempt to read from a card if it's not inserted. Maybe this can return the state of the SD card faster.

The SD library builds on the sdfatlib library, in which SD_INIT_TIMEOUT is defined as 2000 ms, which gives your 2 second timeout. You could try lowering that number to get a faster response, although that may run the risk of timing out even when a card is present.
Four different timeout periods are defined in the sdfatlib source:
/** init timeout ms */
uint16_t const SD_INIT_TIMEOUT = 2000;
/** erase timeout ms */
uint16_t const SD_ERASE_TIMEOUT = 10000;
/** read timeout ms */
uint16_t const SD_READ_TIMEOUT = 300;
/** write time out ms */
uint16_t const SD_WRITE_TIMEOUT = 600;

The 300 ms read timeout is faster, as @Paul suggests in his comment, so you could just use a card read as the test rather than an initialisation, or try setting the init timeout to 300 instead. A read test would be simpler, as it doesn't involve modifying library files. It might not cope with a re-inserted card, though - I suspect that requires reinitialisation each time.
Note: the version of sdfatlib included with the SDlib in my Arduino install appears rather older than the current version. The included version defines the timeouts in Sd2Card.h, while the latest has is in SdInfo.h. The snippet above is from the older, included code.

You could always try this very simple sketch. I have never measured how quick it runs, but it is pretty quick.
Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

Just make sure to change 4 in !SD.begin(4) to whatever your ChipSelect pin happens to be for your component.
Furthermore, you could add a return statement after your "initilization fails" loop because that will immediately stop the program, after all you do not want to run it if the SD card is not reading data! And last thing, it may be a little overkill to check the SD card after initial initilization, after all, it will be highly unlikely for an error to occur once everything is working fine unless you mess with the SD card alot while it is running, which I am sure you won't.

This sketch is not working as I would like it to : if placed in setup, it works fine, but as soon as it is run a second time, it returns false.
See : http://arduino.stackexchange.com/questions/3850/sd-begin-fails-second-time
Also, when no SD is inserted, this test takes 2000 to 2300ms on my device.

Have you tried removing the verification from the loop itslef. Like I mentioned before, you should not need to verify the SD card every time you run through the loop, that is a bit overkill.

If you perform the check out of the loop, it would work.
However, in my application, I need to check the SD regularly as the Arduino board will be embedded into a package and will not be able to reset if not by shutting down the power of the whole machine. Also, the user will want to remove the SD to transfer the file onto the computer while the board is on. I would like to prevent a test start if no SD is detected. Thus, I would prefer regular checks on the SD.

If you will have interaction with the SD Card while it is reading, you could potentially have the SD Card detection happen once every 30 seconds or so to prevent from constant button freezing. Or, you could have a manual check at the push of a button or input from the Serial Monitor, so that will allow you to check the SD at you disgression.

source: Stack Exchange

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

sort: votes


text:
Atmega 2560 IR receiver returning random values with using NeoPixels
I am using atmega 2560 to control 590 LED lights with NeoPixels library.
I also got an IR receiver connected so I could control the LED properties and it does work but only when the LEDs are not engaged, the moment the code for LED's goes off the IR receiver keep returning random rubish.
Pressing the same button on a remote:
11:48:18.394 -> FF3AC5
11:48:19.550 -> D53AFF52
11:48:58.586 -> 24AE7D4E
11:48:59.341 -> 4CB0FADF
11:48:59.742 -> 4CB0FADF
11:49:00.491 -> 6BDBBF60
11:49:09.462 -> A8E05FBB
11:49:10.612 -> 40892F89
11:49:11.067 -> 3AD8A119
11:49:11.515 -> 2C1330B0
11:49:14.176 -> DDE32E9D
11:49:16.597 -> FF1AE5
11:49:17.445 -> A8E05FBB
11:49:17.499 -> FFFFFFFF
11:49:18.502 -> FF1AE5
11:49:18.548 -> FFFFFFFF
11:49:19.350 -> FF1AE5

IR connection diagram below:

My code below:
#include <IRremote.h>
#include <Adafruit_NeoPixel.h>

int LED_pin = 6;
int PIR_pin_D = 4;
int PIR_pin_U = 3;
int IR_pin = 2;

int LDR_pin = A0;

int pirInputU = LOW;
int pirInputD = LOW;
int ldrInput =  0;
int irInput = 0;

bool goignDown = false;
bool goingUp = false;

//states
bool lights = true;
bool constantMode = false;
byte ledBrightness = 50;
byte mode = 0;

int lightDuration = 8000;
int sensorDelay = 1500;

#define NUM_LEDS 590
#define NUM_STEPS 14

int numOfLEDs[NUM_STEPS] {41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 57, 41};

Adafruit_NeoPixel strip(NUM_LEDS, LED_pin, NEO_GRB + NEO_KHZ800);
int32_t currentColour = strip.Color(255, 255, 255);

IRrecv irrecv(IR_pin);
decode_results results;

void setup()
{
  strip.begin();
  strip.setBrightness(ledBrightness);

  irrecv.enableIRIn();

  pinMode(LDR_pin, INPUT);    // declare sensor as input
  pinMode(IR_pin, INPUT);    // declare sensor as input
  pinMode(PIR_pin_U, INPUT_PULLUP);  // declare sensor as input
  pinMode(PIR_pin_D, INPUT_PULLUP);  // declare sensor as input

  strip.clear();
  strip.show();

  delay(10000);
  Serial.begin(9600);
}

void loop()
{
  ldrInput = analogRead(LDR_pin);    // read input value

  checkIrInput();

  if (ldrInput < 60 && lights)
  {
    pirInputU = digitalRead(PIR_pin_U); // read input value
    pirInputD = digitalRead(PIR_pin_D); // read input value
    checkIrInput();
    //UPSTAIRS SENSOR
    if (pirInputU == HIGH && pirInputD == LOW) // check if the input is HIGH
    {
      moveDown(currentColour);
      delay(lightDuration);
      moveDown(strip.Color(0, 0, 0));
      delay(sensorDelay);
      pirInputD = digitalRead(PIR_pin_D); // read input value
    }

    //DOWNSTAIRS
    if (pirInputD == HIGH && pirInputU == LOW) // check if the input is HIGH
    {
      moveUp(currentColour);
      delay(lightDuration);
      moveUp(strip.Color(0, 0, 0));
      delay(sensorDelay);
      pirInputU = digitalRead(PIR_pin_U); // read input value
    }
  }
}

void clearLedStrip()
{
  strip.clear();
  strip.show();
}

void checkIrInput()
{
  //Serial.println("pooling");

  while (!irrecv.isIdle());  // if not idle, wait till complete

  if (irrecv.decode(&results))
  {
    Serial.println(results.value, HEX);

    switch (results.value)
    {
      case 0xFF1AE5: //red
        {
          currentColour = strip.Color(255, 10, 10);
          break;
        }
      case 0xFF9A65: //green
        {
          currentColour = strip.Color(10, 255, 10);
          break;
        }
      case 0xFFA25D: //blue
        {
          currentColour = strip.Color(10, 10, 255);
          break;
        }
      case 0xFF22DD: //white
        {
          currentColour = strip.Color(255, 255, 255);
          break;
        }
      case 0xFF18E7: //yellow
        {
          currentColour = strip.Color(255, 255, 0);
          break;
        }
      case 0xFF58A7: //purple
        {
          currentColour = strip.Color(186,85,211);
          break;
        }
      case 0xFF02FD:
        {
          lights = !lights;
          break;
        }
      case 0xFF827D:
        {
          constantMode = !constantMode;
          break;
        }
      case 0xFF3AC5:
        {
          ledBrightness += 10;
          if (ledBrightness > 100)
            ledBrightness = 100;
          strip.setBrightness(ledBrightness);
          break;
        }
      case 0xFFBA45:
        {
          ledBrightness -= 10;
          if (ledBrightness < 10)
            ledBrightness = 10;
          strip.setBrightness(ledBrightness);
          break;
        }
    }
    irrecv.resume();
  }
}

void moveDown(uint32_t colour)
{
  int start = 0;

  for (int step = 0; step < NUM_STEPS; step++)
  {
    int end = (start + numOfLEDs[step]) - 1;
    int midPoint = start + numOfLEDs[step] * 0.5;

    checkIrInput();

    for (int led = start, temp = 0; led <= midPoint; led++, temp++)
    {
      strip.setPixelColor(led, colour);
      strip.setPixelColor(end - temp, colour);
      strip.show();
    }
    checkIrInput();
    start += numOfLEDs[step];
  }
}

void moveUp(uint32_t colour)
{
  int start = NUM_LEDS - numOfLEDs[NUM_STEPS - 1];

  for (int step = NUM_STEPS - 1; step >= 0; step--)
  {
    int end = (start + numOfLEDs[step]) - 1;
    int midPoint = start + numOfLEDs[step] * 0.5;

    checkIrInput();

    for (int led = start, temp = 0; led <= midPoint; led++, temp++)
    {
      strip.setPixelColor(led, colour);
      strip.setPixelColor(end - temp, colour);
      strip.show();
    }
    checkIrInput();
    start -= numOfLEDs[step];
  }
}

Is atmega 2560 not powerfull enough? Or is there something that I am doing wrong?
Any feedback welcome, thank you.

start with example IR receive code ... that will confirm the module functionality

Hi as mentioned in my question I got the IR receiver working but the moment the NeoPixel code get's run to turn on the LED lights the IR receiver starts returning random values and once LEDs stop changing the IR values go back to normal

then shield the IR receiver from the neopixels

you think it's a physical problem rathe than software?

no, i do not think that ... i have no preconceived opinion about the source of the problem ... shielding the IR receiver is the easiest troubleshooting step

you problem is that both libraries are accessing the same pin interrupt. But only one can use it. I never found a solution for the problem but your code is not working this way.

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


text:
Relay + Arduino uses too much power for battery to handle. Which solution is best?
You can see in my crumby schematic that I am using a Non-latching relay to turn on a 3A circuit (one of them arc lighters), which is powered by a 25C (supposedly) lipo battery. That same battery also powers an Arduino through a TP4056. This works fine when I first turn it all on, but once the relay is activated by the Arduino, the lighter + Relay only turn on for a split second before stopping (when the Arduino is powered via USB, it works fine). I am thinking that the Arduino+Relay+Lighter is too much for the battery, even though it claims to be 25C. It is just strange because the Arduino+Activated Relay consume what, like 200 mA?
Notes:
When I manually turn on the lighter, the light on the Arduino dims a fair bit, but stays on.
The Arduino is running at logic level of 3.3V so that I didn't need a booster.

As for fixes, I was thinking about trying to use a transistor or SSR instead of the chunky relay I have now (which would be good, I need this to be compact). Or maybe the TP4056 is failing to provide enough output despite a decent input?
I am FAR from an electrical engineer so if anyone has any pro tips for improving this it would be much appreciated.

what is the voltage output of the battery when the lighter is energized?

When you put power to the LED lighters the current is high for a short time. You can't compare this value to the continuous current that you can detect with a multimeter. The best way is to use another power supply for the Arduino. The relais I used hat two different circuits: logic and power.

The TP4056 is a battery charger not a power supply.

The TP4056 is a battery charger, not a voltage regulator. It cannot be used to supply power to a device like an Arduino. It is designed for charging the Lithium Ion battery from a 5V (e.g., USB) source.
By trying to use it as a power supply you're asking for trouble. It thinks it's trying to charge a battery (from a 3.7V nominal source) and will be doing things like:

Running constant current making the voltage fluctuate wildly as current demands change
Running constant voltage with limited current causing starving of power
Shutting off when it thinks it sees the non-existent battery being fully charged.

The TP4056 should be connected to a 5V USB power source and to the battery for charging it. The battery should be then through a (very) low-dropout regulator (ideally a switching regulator with zero dropout bypass ability) to power the Arduino at 3.3V.
Alternatively, if you don't need a (reasonably) precise 3.3V then you can power the Arduino directly from the battery.

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


text:
Things stop working if I use Serial.println(tt) and when I use display.drawPixel(i - ii, 64 - Harray[ii], SSD1306_WHITE);
Things stop working if I use line 131 Serial.println(tt); and when I use line 145 display.drawPixel(i - ii, 64 - Harray[ii], SSD1306_WHITE); Also Serial Monitor gives very strange reading. Serial monitor is 9600 baud.
//Kamil Mambetov
//Feb 17 2023
//sht31 with display and plot on it.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_SHT31.h"

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64

uint8_t loopCnt = 0;
uint8_t i = 0;
int Tarray[128] = {};
int Harray[128] = {};
float tmax = 0;
float tmin = 0;
float hmax = 0;
float hmin = 0;

Adafruit_SHT31 sht31 = Adafruit_SHT31();

// Declaration for SSD1306 display connected using software SPI (default case):
#define OLED_MOSI 11
#define OLED_CLK 13
#define OLED_DC 9
#define OLED_CS 10
#define OLED_RESET 8
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
                        OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC);
  //u8g2_for_adafruit_gfx.begin(display);  // connect u8g2 procedures to Adafruit GFX

  Serial.begin(9600);

  while (!Serial)
    delay(10);  // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("SHT31 test");
  if (!sht31.begin(0x44)) {  // Set to 0x45 for alternate i2c addr
    Serial.println("Couldn't find SHT31");
    while (1) delay(1);
  }
}

void loop() {
  display.clearDisplay();
  display.setTextSize(1);               // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);  // Draw white text
  display.setCursor(0, 0);              // Start at top-left corner
  display.cp437(true);                  // Use full 256 char 'Code Page 437' font

  float t = sht31.readTemperature();
  float h = sht31.readHumidity();

  if (t > tmax or tmax == 0) {
    tmax = t;
  } else if (t < tmin or tmin == 0) {
    tmin = t;
  }

  if (h > hmax or hmax == 0) {
    hmax = h;
  } else if (h < hmin or hmin == 0) {
    hmin = h;
  }

  char *Tchar = "";
  char *Hchar = "";
  char *Tmaxchar = "";
  char *Hmaxchar = "";
  char *Tminchar = "";
  char *Hminchar = "";

  display.setCursor(0, 0);  // start writing at this position
  //display.print("t:");
  //display.setCursor(12, 0);
  dtostrf(t, 4, 1, Tchar);
  display.print(Tchar);

  display.setCursor(30, 0);
  display.print("max:");
  display.setCursor(52, 0);
  dtostrf(tmax, 4, 1, Tmaxchar);
  display.print(Tmaxchar);

  display.setCursor(78, 0);
  display.print("min:");
  display.setCursor(100, 0);
  dtostrf(tmin, 4, 1, Tminchar);
  display.print(Tminchar);

  display.setCursor(0, 8);
  //display.print("h:");
  //display.setCursor(12, 8);
  dtostrf(h, 4, 1, Hchar);
  display.print(Hchar);

  display.setCursor(30, 8);
  display.print("max:");
  display.setCursor(52, 8);
  dtostrf(hmax, 4, 1, Hmaxchar);
  display.print(Hmaxchar);

  display.setCursor(78, 8);
  display.print("min:");
  display.setCursor(100, 8);
  dtostrf(hmin, 4, 1, Hminchar);
  display.print(Hminchar);

  // display.drawPixel(x, t, SSD1306_WHITE); //draw single pixel
  //Serial.println(h);
  // Serial.print("aaa");
  //Serial.println(t);
  // Serial.print("ttt");
  //float to int conversion
  int tt = 0;
  int hh = 0;
  tt = int(t);
  float c = 0;
  c = h/2;
  hh = int(c);
  //Serial.println(c);
  Serial.println(tt);

  //plot
  i++;
  loopCnt++;

  Tarray[i] = tt;
  Harray[i] = hh;
  //Serial.println(Harray[i]);

  int ii = 0;
  while (ii < i) {
    ii++;
    display.drawPixel(i - ii, 64 - Tarray[ii], SSD1306_WHITE);
    //display.drawPixel(i - ii, 64 - Harray[ii], SSD1306_WHITE);
  }

  if (i == 128) {
    i = 0;
  }

  display.display();  // make everything visible
  delay(2000);
}

Regarding your question about code formatting, you can see what I did in the side-by-side markdown view in the revisions on the question. In short triple-back-tics before and after the code. The editor has help under the question mark in the circle in the upper right. You can also indent the code with spaces, but that's somewhat more painful to work with and the language used cannot be hinted.


text:
FastLED with WS2812B 241228
Hello Arduino Stack Exchange forum,
Learning how to use the FastLED to control a string of 150 WS2812B LEDs
Code copied herewith below compiles and operates as expected.
Trying to figure out how to turn on LEDs with different colors,
say, alternating green and red.
Thanks.
Allen Pitts
Dallas TX
PS What is the CRGB suffix before the three three-digit numbers that specify the color?
/*
from How To Control WS2812B Individually Addressable LEDs using Arduino
https://howtomechatronics.com/tutorials/arduino/how-to-control-ws2812b-individually-addressable-leds-using-arduino/
In this sketch first learned how to turn on twenty LEDs using statements for
each LED. Then figured out how to turn them off: "leds[i] = (0, 0, 0);"
The learned how to turn them on using FOR staement.
Next step Learn how to turn the LEDs on having different colors.

Last change:  NUM_LEDS to 150 and
 for (int i = 0; i < 150; i++) {
    // turn off
This works on the LED strip marked "Alito WS2812B"

*/

#include <FastLED.h>

#define LED_PIN     3
#define NUM_LEDS    150

CRGB leds[NUM_LEDS];

void setup() {

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

}

void loop() {
 /*
  leds[0] = CRGB(255, 0, 0);
  FastLED.show();
  delay(100);
  leds[1] = CRGB(0, 255, 0);
  FastLED.show();
  delay(100);
  leds[2] = CRGB(0, 0, 255);
  FastLED.show();
  delay(100);
  leds[3] = CRGB(150, 0, 255);
  FastLED.show();
  delay(100);
  leds[4] = CRGB(255, 200, 20);
  FastLED.show();
  delay(100);
  leds[5] = CRGB(85, 60, 180);
  FastLED.show();
  delay(100);
  leds[6] = CRGB(50, 255, 20);
  FastLED.show();
  leds[7] = CRGB(255, 0, 0);
  FastLED.show();
  delay(100);
  leds[8] = CRGB(0, 255, 0);
  FastLED.show();
  delay(100);
  leds[9] = CRGB(0, 0, 255);
  FastLED.show();
  delay(100);
  leds[10] = CRGB(150, 0, 255);
  FastLED.show();
  delay(100);
  leds[11] = CRGB(255, 200, 20);
  FastLED.show();
  delay(100);
  leds[12] = CRGB(85, 60, 180);
  FastLED.show();
  delay(100);
  leds[13] = CRGB(50, 255, 20);
  FastLED.show();
  leds[14] = CRGB(0, 255, 0);
  FastLED.show();
  delay(100);
  leds[15] = CRGB(0, 0, 255);
  FastLED.show();
  delay(100);
  leds[16] = CRGB(150, 0, 255);
  FastLED.show();
  delay(100);
  leds[17] = CRGB(255, 200, 20);
  FastLED.show();
  delay(100);
  leds[18] = CRGB(85, 60, 180);
  FastLED.show();
  delay(100);
  leds[19] = CRGB(50, 255, 20);
  FastLED.show();
  */

  for (int i = 0; i < 60; i++) {
    // turn on
    leds[i] = CRGB(0, 255, 0);
    // Show the leds
    FastLED.show();
    delay(50);
  }
  for (int i = 0; i < 150; i++) {
    // turn off
    leds[i] = CRGB(0, 0, 0);
    // Show the leds
    FastLED.show();
    delay(10);

  }
}

What happens when you run your code?

the leds[] array is an in-memory representation of the actual LEDs ... fill the array with color values and then call FastLED.show(); to copy the array into the LED strip ... your question is not about the Arduino ... it is a general programming question

research the for (int i = 0; i < 150; i++) { ... learn what it does ... it is in the C++ programming world

CRGB seems to be a struct which basically holds a value for Red, Green, and Blue values for a pixel.
From pixeltypes.h in the FastLED library:
/// Representation of an RGB pixel (Red, Green, Blue)
struct CRGB {
    union {
        struct {
            union {
                uint8_t r;
                uint8_t red;
            };
            union {
                uint8_t g;
                uint8_t green;
            };
            union {
                uint8_t b;
                uint8_t blue;
            };
        };
        uint8_t raw[3];
    };

As for the rest of your question, there isn't really a question there. To get an answer you need to post a question, stating:

What you attempted
What you expected to happen
What actually happened

You said:

Code copied herewith below compiles and operates as expected.

So it is hard to progress from there. The code compiles and works, so what is the problem?


text:
False interrupt triggering Arduino Mega
I am using Arduino mega with 4 interrupts to find the rotation speed of 4 motors . For this I have used INT2, INT3, INT4, INT5 and the code for the same is given below
struct Pulse {
  uint32_t last_toggle;
  uint32_t width;
  bool stateHigh;
  uint32_t get_width() {
    noInterrupts();
    uint32_t width_copy = width;
    interrupts();
    return width_copy;
  }
};

Pulse ch1, ch2, ch3, ch4;

void pin_initialization() {
  // Four engine configuration
  pinMode(19, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);

}

volatile uint32_t ovfCount = 0;
ISR(TIMER3_OVF_vect) {
  ovfCount++;
}

void timer3_initialization() {
  TCCR3A = 0x00;

  TCNT3 = 0x1FF; // from datasheet
  TIFR3 = _BV(TOV3);
  TIMSK3 = _BV(TOIE3); // overflow enable
  TCCR3B = B00000011; // 64 prescaling
}

void pulseWidthCalculator(Pulse *channel){
  unsigned char sreg;
  sreg = SREG;
  cli();
  uint16_t tcnt3 = TCNT3;
  SREG = sreg;
  uint32_t ovf_count = ovfCount;

  if (bit_is_set(TIFR3, TOV3) && tcnt3 < 32768) {
    ovf_count++;
  }

  uint32_t time = ovf_count << 16 | tcnt3;

  if (!channel->stateHigh) {  // first high
    channel->stateHigh = true;
  } else if ( channel->stateHigh) {  // second High
    channel->width = time - channel->last_toggle;
    channel->stateHigh = false;
  }
  channel->last_toggle = time;
}

ISR(INT2_vect) {
  pulseWidthCalculator(&ch1);
}

ISR(INT3_vect) {
  pulseWidthCalculator(&ch2);
}

ISR(INT4_vect) {
  pulseWidthCalculator(&ch3);
}

ISR(INT5_vect) {
  pulseWidthCalculator(&ch4);
}

void externalInterrputInitialization() {
  EIFR = _BV(INTF2) | _BV(INTF3) | _BV(INTF4) | _BV(INTF5);
  EICRA = 0; EICRB = 0;
  EICRA = B10100000;
  EICRB = B00001010;
  EIMSK = B00111100;
}

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

  pin_initialization();
  delayMicroseconds(10);

  externalInterrputInitialization();
  delayMicroseconds(10);

  timer3_initialization();
  delayMicroseconds(10);

}

void loop() {
  String a = String(15e6/ch1.get_width());
  a += " ";
  a += String(15e6/ch2.get_width());
  a += " ";
  a += String(15e6/ch3.get_width());
  a += " ";
  a += String(15e6/ch4.get_width());

  Serial.println(a);

}

The issue I am facing is , whenever I give a signal to INT2, INT3 is also getting triggered, same with INT4, INT5 also getting triggered without signal .
What I am I missing here, ?
Should I make my channels ch1, ch2 , ch3, ch4 to volatile or not.? like
volatile Pulse ch1, ch2, ch3, ch4

Any thing wrong with OUTPUT_PULLUP

volatile is necessary to be sure changes made are observable between the ISR and non-ISR contexts.  That said, it doesn't seem like it would completely account for what you're seeing.  You should make them volatile an let us know what the behaviour in that case is though.

why do you believe that it is a programming problem?

@timemage, changing to volatile is not helping.

In that case, it's probably a good idea to just make the variables volatile in your code  and remove the part where ask about doing that, to remove the distraction from the primary question.

This has nothing to do with your question as such, but your Serial stream concatenates things for you as a matter of course.  All of your assignments and appends to String a are an inefficient and bug-prone alternative to a series of print/println calls.

You have the right idea to atomically obtain a copy of the data that is updated by the interrupt:
  unsigned char sreg;
  sreg = SREG;
  cli();
  uint16_t tcnt3 = TCNT3;
  SREG = sreg;
  uint32_t ovf_count = ovfCount;

...but the last two lines should be swapped to keep the copying operation within the non-interrupt section:
  unsigned char sreg;
  sreg = SREG;                    // Save interrupt state.
  cli();                          // Disable interrupts.
  uint16_t tcnt3 = TCNT3;         // Atomic operations.
  uint32_t ovf_count = ovfCount;
  SREG = sreg;                    // Restore interrupt state.

Though I notice you are calling that code from within an interrupt service routine so interrupts should already be disabled unless you are intending to use nested interrupts.
The false interrupt could be caused by crosstalk between INT2 and INT3. You could confirm this by using an oscilloscope. Keep the signal wires separate to avoid crosstalk.
You could also try stronger external pull-ups such as 10K or 1K. The Arduino internal pull-ups are weaker at about 20-50K Ohms.

Thanks Tim , from oscilloscope I understood its an issue of INPUT_PULLUP, I will do external PULLUPs.

used 1K resistor and its working. Is there any issue with using external pull-up  along with INPUT_PULLUP.?


text:
NodeMCU unable to communicate with MFRC522 RFID reader even though the nodeMCU is successfully connected to a mobile hotspot
I am replicating a project that will read the RFID card or tag data, store that into a mysql database and display the data via PHP.
I am using NodeMCU, RC522 RFID reader and Ardunio IDE to do that.
Below is the Arduino code. It successfully connects with WiFi (that I can see via serial monitor) but gives no response when I touch the RFID card to the reader and there is no display of the card UID in the PHP web app.
I can't find the error.
The owner of the project suggested that the nodeMCU might be faulty which isn't the case and now i am at loss. Please help.
//NodeMCU and RFID libraries--------------------------
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN  D2  //D2
#define RST_PIN D1  //D1

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

/* Set these to your desired credentials. */
const char *ssid = "TECNO CAMON 15";
const char *password = "d6364e300f59";
const char* device_token  = " 4c9fc9995e7f9c6d ";

String URL = "http://192.168.43.40/school_project/getdata.php"; //computer IP or the server domain
String getData, Link;
String OldCardID = "";
unsigned long previousMillis = 0;

void setup() {
  Serial.begin(115200);
  SPI.begin();  // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522 card
  WiFi.mode(WIFI_OFF);        //Prevents reconnection issue (taking too long to connect)
    delay(1000);
    WiFi.mode(WIFI_STA);
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("");
    Serial.println("Connected");

    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());  //IP address assigned to your ESP

    delay(1000);
}
//************************************************************************
void loop() {

  if (millis() - previousMillis >= 15000) {
    previousMillis = millis();
    OldCardID="";
  }
  delay(50);
  //---------------------------------------------
  //look for new card
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;//got to start of loop if there is no card present
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;//if read card serial(0) returns 1, the uid struct contians the ID of the read card.
  }
  String CardID ="";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    CardID += mfrc522.uid.uidByte[i];
  }
  //---------------------------------------------
  if( CardID == OldCardID ){
    return;
  }
  else{
    OldCardID = CardID;
  }
  //---------------------------------------------
//  Serial.println(CardID);
  SendCardID(CardID);
  delay(1000);
}
//************send the Card UID to the website*************
void SendCardID( String Card_uid ){
  Serial.println("Sending the Card ID");
  if(WiFi.isConnected()){
    HTTPClient http;    //Declare object of class HTTPClient
    //GET Data
    getData = "?card_uid=" + String(Card_uid) + "&device_token=" + String(device_token); // Add the Card ID to the GET array in order to send it
    //GET methode
    Link = URL + getData;
    http.begin(Link); //initiate HTTP request   //Specify content-type header

    int httpCode = http.GET();   //Send the request
    String payload = http.getString();    //Get the response payload

//    Serial.println(Link);   //Print HTTP return code
    Serial.println(httpCode);   //Print HTTP return code
    Serial.println(Card_uid);     //Print Card ID
    Serial.println(payload);    //Print request response payload

    if (httpCode == 200) {
      if (payload.substring(0, 5) == "login") {
        String user_name = payload.substring(5);
    //  Serial.println(user_name);

      }
      else if (payload.substring(0, 6) == "logout") {
        String user_name = payload.substring(6);
    //  Serial.println(user_name);

      }
      else if (payload == "succesful") {

      }
      else if (payload == "available") {

      }
      delay(100);
      http.end();  //Close connection
    }
  }
  }
//=======================================================================`

Can you get RFID to work without all the Wifi stuff? If you haven't tried, simplify everything down to a "blink"-like sketch for RFID, and debug that.

I have done the blink sketch and it works. The problem is when I connect it to the NODEMCU and want to scan the rfid card so that it registers on the php web app, nothing happens

@Wayne254 please add the serial monitor messages to your post

@jsotola I have added the serial monitor showing the connected network

thanks  ... no picture of text please ... some of us cannot see the picture ... add the actual text

In tutorial of developer i remember a mistake in descrition wiring mosi miso sck on mcu. Verify wiring schema with standards


text:
Why doesn't LCD 16x2 work with fingerprint sensor code?
When I separate fingerprint code and LCD code it works fine. sensor read 6 templates which I already stored 6 fingers ID. When I combine the code it read 0 templates.
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include<LiquidCrystal.h>

int Contrast=100;
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

// pin #7 is IN from sensor (GREEN wire)
// pin #6 is OUT from arduino  (WHITE wire)
SoftwareSerial mySerial(6,7);

uint8_t id;
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

#define S1 14 //Button candidate A
#define S2 15 // Button candidate B
#define S3 16 // Button candidate c
#define S4 17 // Button candidate D
#define S5 18 // Button Result
#define S6 2 // Button Add unregistered voter
#define S7 4 // Button to cast vote
int can1=0;
int can2=0;
int can3=0;
int can4=0;

void setup()
{
  pinMode(S1, INPUT);
  pinMode(S2,INPUT);
  pinMode(S3,INPUT);
  pinMode(S4,INPUT);
  pinMode(S5,INPUT);
  pinMode(S6,INPUT);
  pinMode(S7,INPUT);

  digitalWrite(S1, HIGH);
  digitalWrite(S2, HIGH);
  digitalWrite(S3, HIGH);
  digitalWrite(S4, HIGH);
  digitalWrite(S5, HIGH);
  digitalWrite(S6, HIGH);
  digitalWrite(S7, HIGH);

  analogWrite(6,Contrast);
  lcd.begin(16, 2);
  lcd.print("  Polling Day  ");
  lcd.setCursor(0,1);
  lcd.print("      UPM      ");
  delay(4000);

  Serial.begin(57600);
    lcd.clear();
    lcd.print("Finding Module");
    lcd.setCursor(0,1);
    delay(1000);
    if (finger.verifyPassword())
    {
      //Serial.println("Found fingerprint sensor!");
      lcd.clear();
      lcd.print("Found Module ");
      delay(1000);
    }
    else
    {
    //Serial.println("Did not find fingerprint sensor :(");
    lcd.clear();
    lcd.print("module not Found");
    lcd.setCursor(0,1);
    lcd.print("Check Connections");
    while (1);
    }

    finger.getTemplateCount();
    lcd.clear();
    lcd.print("contains");
    lcd.setCursor(0,1);
    lcd.print(finger.templateCount);
    delay (4000);
}

uint8_t readnumber(void) {
  uint8_t num = 0;

  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

void loop(){
  lcd.clear();
  lcd.setCursor(1,0);
  lcd.print("Place Your");
  lcd.setCursor(0,1);
  lcd.print("Finger");
  delay(4000);
  getFingerprintIDez();
  delay(50);

    if(digitalRead(S5)==0) // To view the result for admin only
    {
      int total=can1+can2+can3+can4;
    if(total)
    {
      if((can1 > can2 && can1 > can3 && can1 > can4))
    {
      lcd.clear();
      lcd.print("Can A is Winner");
      delay(3000);
      lcd.clear();
    }
    else if((can2 > can1 && can2 > can3 && can2 > can4))
    {
      lcd.clear();
      lcd.print("Can B is Winner");
      delay(3000);
      lcd.clear();
    }
    else if((can3 > can1 && can3 > can2 && can3 > can4))
    {
      lcd.clear();
      lcd.print("Can C is Winner");
      delay(3000);
      lcd.clear();
    }
    else if(can4 > can1 && can4 > can2 && can4 > can3)
    {
        lcd.setCursor(0,0);
        lcd.clear();
        lcd.print("Can D is Winner");
        delay(3000);
        lcd.clear();
    }

    else if(can4 > can1 && can4 > can2 && can4 > can3)
    {
        lcd.setCursor(0,0);
        lcd.clear();
        lcd.print("Can D is Winner");
        delay(3000);
        lcd.clear();
    }

    else
    {
        lcd.clear();
        lcd.print(" Tie Up Or ");
        lcd.setCursor(0,1);
        lcd.print(" No Result ");
        delay(3000);
        lcd.clear();
    }

    }
    else
    {
        lcd.clear();
        lcd.print("No Voting....");
        delay(3000);
        lcd.clear();
    }
        can1=0;can2=0;can3=0;can4=0,total=0;
        lcd.clear();
    }

    if(digitalRead(S7)==0){ //To cast avote for user
        voterpage();
    }

    if(digitalRead(S6)==0){
      Serial.println("Ready to enroll a fingerprint!");
      Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
      lcd.clear();
      lcd.print("ENTER ID:");
      delay(2000);
      id = readnumber();
      if (id == 0) {// ID #0 not allowed, try again!
      return;
      }
      Serial.print("Enrolling ID #");
      lcd.print(id);

      while (!  getFingerprintEnroll() );
      }
  }

    void voterpage(){
      lcd.clear();
      lcd.setCursor(1,0);
      lcd.print("A");
      lcd.setCursor(5,0);
      lcd.print("B");
      lcd.setCursor(9,0);
      lcd.print("C");
      lcd.setCursor(13,0);
      lcd.print("D");

      if(digitalRead(S1)==0){
      can1++;
      votereceived();
      }
        while(digitalRead(S1)==0);
      if(digitalRead(S2)==0){
      can2++;
      votereceived();
      }
        while(digitalRead(S2)==0);
      if(digitalRead(S3)==0){
      can3++;
      votereceived();
      }
        while(digitalRead(S3)==0);
      if(digitalRead(S4)==0){
      can4++;
      votereceived();
      }
        while(digitalRead(S4)==0);
}

void votereceived(){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Vote Received");
      lcd.setCursor(2,1);
      lcd.print("Thank You :)");
      delay(2000);
}

uint8_t getFingerprintEnroll() {

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

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

  // OK success!

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

  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }
}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
    // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
    lcd.clear();
    lcd.setCursor(3,0);
    lcd.print("ID");
    lcd.setCursor(1,1);
    lcd.print(finger.fingerID);
    delay(4000);
    return finger.fingerID;
    if(finger.fingerID==26 ;finger.confidence>100){
      lcd.clear();
      lcd.setCursor(3,0);
      lcd.print("1");
      lcd.setCursor(1,1);
      lcd.print("Result");
      lcd.setCursor(11,0);
      lcd.print("2");
      lcd.setCursor(8,1);
      lcd.print("Register");
      delay(4000);
  }

}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;

  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  return finger.fingerID;
}

we aren't a code review. strip down the code to the minimal example that still has the problem. often times, you'll find the problem just cleaning it up to post on stack...

@dandavis but I dont know which part of it I got it wrong.

dupe your sketch, start removing code, re-test until there's nothing left to take away (then post that) or the problem goes away (in which case you don't need us anymore).

Can you please share the schematic also and also which fingerprint sensor you are using.

What part "doesn't work"? That is an incredibly vague description. What shows on the LCD display? What appears in the serial monitor?

Also in setup finger.begin(baudrate) is missing add this and I guess it will help you out

@NickGammon Hi I already add the pic of lcd dislpay and serial monitor. Serial reads 6 templates but if I add lcd code it showed 0 templates. Hope you can help thank you :)

@MaazSk hi I dont have the schematic yet but i used JM101 fingerprint. And also I already add the finger.begin(baudrate) still shows the same result on the lcd as I shown in the picture.

@SASHASYAZANA can you try this int m = 0; m = finger.getTemplateCount(); lcd.print(m); this will print the tempelate count for you

@MaazSk I tried using the code. It works! but unfortunately it just contains 1 templates only. supposedly it have 6 templates. And I tried place my fingerprint all of 6 finger not even one works.

Need to check will get back soon


text:
Adafruit Neopixel Individual Addressable LEDs issue - Any and every code make LEDs go "crazy"
Hi everyone I have an issue with getting these LEDs to cooperate.
I'm using a 470ohm resistor on the data port and a capacitor for the power. I complied and uploaded the "strandtest"(I changed the variables NUM_LED & LED_PIN) and this occurs [10s Video: https://drive.google.com/file/d/1xabkHW1xgFo9kh3YnGwIsaS5tSfFCsrb/view?usp=sharing]
This happens to all code in a loop. If I send no signals (aka put an empty pin and run) then the lights that were last on stay lit. If I try to clear the LED nothing happens. If I try to set a specific LED to a specific color/brightness nothing happens.
I'm at my wit's end; help a brother out!
LEDs Used:https://www.amazon.com/gp/product/B00ZHB9M6A/ref=ppx_yo_dt_b_asin_title_o02_s01?ie=UTF8&th=1
AC to DC 5V 5A: https://www.amazon.com/ALITOVE-Converter-5-5x2-1mm-100V-240V-Security/dp/B078RT3ZPS/ref=pd_bxgy_img_2/143-9706163-2199558?_encoding=UTF8&pd_rd_i=B078RT3ZPS&pd_rd_r=4133e781-45a6-4112-a571-c311f45e0720&pd_rd_w=t0bs4&pd_rd_wg=TIEcS&pf_rd_p=f325d01c-4658-4593-be83-3e12ca663f0e&pf_rd_r=PPCEVPJVY8N6XFTY1AD4&psc=1&refRID=PPCEVPJVY8N6XFTY1AD4
#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 150

// For led chips like WS2812, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define DATA_PIN 3
#define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() {
    // Uncomment/edit one of the following lines for your leds arrangement.
    // ## Clockless types ##
    //FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
    // FastLED.addLeds<SM16703, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<TM1829, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<TM1812, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<UCS1904, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<UCS2903, DATA_PIN, RGB>(leds, NUM_LEDS);
     //FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
    // FastLED.addLeds<WS2852, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical

  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical

    // FastLED.addLeds<GS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<SK6812, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
    // FastLED.addLeds<SK6822, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<APA106, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<PL9823, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<SK6822, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<WS2813, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<WS2811_400, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<GE8822, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<LPD1886, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<LPD1886_8BIT, DATA_PIN, RGB>(leds, NUM_LEDS);
    // ## Clocked (SPI) types ##
    // FastLED.addLeds<LPD6803, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
    // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
    // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<WS2803, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical
    // FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical
    // FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical
    // FastLED.addLeds<SK9822, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical
}

void loop() {
  // Turn the LED on, then pause
  leds[0] = CRGB::Red;
  FastLED.show();
  delay(500);
  // Now turn the LED off, then pause
  leds[0] = CRGB::Black;
  FastLED.show();
  delay(500);
}

Please also describe with words, what is actually happening and how that doesn't fit your expectations. Not everybody wants to first watch your video and the link might go dead in some time, making the question not understandable. And please share your code. If you used an example code, please link to it. Also exactly describe what you have changed how.

Of course the last LED state stay, when you send no signals. Thats how these LEDs work. They keep their state, until you send them new data or power cycle them. What do you mean with "If I try to clear the LED nothing happens"? Are you trying while the strip is on an unused pin? If not, how and where in the code exactly are you trying to clear it?

Did you connect the ground of the LEDs to the ground of your Arduino? I can't really see from your video but I suspect you did not. BTW it's much better to describe how everything is connected together instead of showing a video in which you really can't see much except for flashing LEDs. A schematic would be even better.

@StarCat I can see a ground connection from the Arduino to the breadboard. If the breadboard's ground is continuous, though, I can't quite tell.

@Alex try this library: https://github.com/FastLED/FastLED instead of the Adafruit Neopixel, the FastLED library is very handy and very powerful, I prefer it over the Neopixel. Just for you to know there are other options.

Ok so i'm using the basic blink example on FastLed library and updated the post to include the code. However, after uploading the LED strip, it's giving the random results again. This time only the first 10 LED are flashing random colors about 1-2 a second, the rest of the LEDs are off.

I attached a new photo of my wiring plan as well as what I actually did (the 5V power supply is out of the photo)

Don't use the Neopixel library. for LEDs that have WS2812B the FastLED is the best option. I also had issues with the LEDs flashing on and off randomly but using this library and then changing the driver to W2812B made it work. Your power supply is plenty strong.


text:
Programming ESP32-S3 WROOM with a flexy pin board
I am using ESP32-S3-WROOM-1-N8 module https://www.digikey.de/de/products/detail/espressif-systems/ESP32-S3-WROOM-1-N8/15200089 .
I have compared pinout of all Wroom modules ESP32 ESP32-S3 as well as ESP32-WROVER have all the programming pins in exactly same positions so I was expecting this programmer to work for any of these modules. I am looking at GND, 3v3, EN, RX, TX, GPIO0.
I am using this flexy pin board from aliexpress https://de.aliexpress.com/item/1005004605613498.html?spm=a2g0o.order_list.order_list_main.91.21ef5c5f6R74vM&gatewayAdapt=glo2deu
When Uploading sketch I am getting following error:
StopIteration
[6848] Failed to execute script 'esptool' due to unhandled exception!

Chip is ESP32-S3
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:ec:d1:f0
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Failed uploading: uploading error: exit status 1

Looks like it failed while configuring flash memory, I have gone through esptool's codebase on Github it seems to fail at this function https://github.com/espressif/esptool/blob/master/esptool/loader.py#L1167
I am not experienced with all this so can't figure out what is the issue.
On board config, I have set
Flash mode: QIO 80MHz
Flash size: 8MB

I have selected ESP32S3 Dev Module as the board
ESP32 Library v2.0.6
Update: When I opened the serial monitor, it is showing following
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x7 (TG0WDT_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40049b21
invalid header: 0xa5ff005a

Am I wrong in assuming all these modules can be programmed with this programmer?
Thanks in advance
Update 2:
Changing upload speed from 921600 to 115200 fixed it, but the module still errored when running it.
Serial monitor shows following:
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbec
load:0x403cc700,len:0x2920
entry 0x403c98d8
[    81][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): XTAL: 40 / 1 = 40 Mhz, APB: 80000000 Hz
E (491) psram: PSRAM ID read error: 0x00ffffff
[    83][W][esp32-hal-psram.c:71] psramInit(): PSRAM init failed!
[   120][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 0 - 1 RAM Blocks - pin 48

Which went away after I disabled PSRAM in upload setting.
Now I seem to be able to program and run it but the serial monitor is only showing debug messages, the message I am trying to print to serial is not showing up.
Also blink sketch is also not working for BUILTIN_LED as well as GPIO1

try lower baud rate

I've never used these programming adapters, but to me it looks like the ESP32 module is supposed to be placed with the WiFi antenna to the left. What does the documentation say?

There is no documentation. That WIFI antenna is from ESP-12 module socket. I have checked continuity for few pins and they confirm that is the way the module is mounted.

@Juraj that actually helped, though it was already in lowest 921600 I increased it to 115200
Now I was able to upload the sketch but it failed while running it. I ll update the Question

921600 is almost 1 mega

did you select S3 version in Tools menu?

Yes. and the PSRAM error went away when I disable the PSRAM option in the upload config.

ever get this working @AnilMaharjan

@NightWolf yes I did.


text:
Transfer 10-bit via Arduino-to-Arduino SPI protocol
The task I need to accomplish is as follows:
I have an analog/digital converter that sends out a 10-bit signal. This signal needs to be transferred to an Arduino Uno using the SPI protocol. Because the SPI protocol works with a 16 bit pattern I need to expand the incoming signal. The slave Arduino then needs to put out the transferred number in decimal.
I imitated the ADC with another Arduino Uno, setting it as master, but unfortunately at the time I only had one Arduino so I couldn't test my code. Furthermore, I don't really have a clue how to "expand" a 10-bit signal to a 16-bit one. Can someone please explain it to me and have a look at my code?
Code for the master Arduino:
#include <SPI.h>
#define SS 10
#define MOSI 11

void setup() {
  pinMode(SS, OUTPUT);
  pinMode(MOSI, OUTPUT);
  SPI.beginTransaction(SPISettings(62500, LSBFIRST, SPI_MODE0));
}

void loop() {
  byte x=0000001101;
  byte y=0011111111;
  digitalWrite(SS,LOW);
  SPI.transfer(x,y);
  digitalWrite(SS,HIGH);
  delay(1000);
}

Code for the slave Arduino:
#include <SPI.h>
#define SS 10
#define MOSI 11

void setup() {
  pinMode(SS, INPUT);
  pinMode(MOSI, INPUT);
}

void loop() {
  byte x=SPDR;
  byte y=SPDR;
  printf(x,DEC);
  printf(y,DEC);
  delay(1000);
}

A byte is only 8 bits, so your code:
  byte x=0000001101;
  byte y=0011111111;

won't do what you think it does.
A 10 bit value will be stored as an int (which is 16 bits) or 2 bytes.
Assuming it is an int then this will convert it to two bytes.
 const int adcData = 0x03FF;  // From ADC
 byte dataToSend[2] = {0, 0}; // Initialise it to zeros
 dataToSend[0] = (adcData & 0xFF00) >> 8;  // didn't really need the bit mask just to make it clearer.
 dataToSend[1] = (adcData & 0x00FF);
 // Now send dataToSend via the SPI bus.

To reassemble the data on the otherside:
 byte dataReadFromSPI[2];  // Filled with the data read from the SPI
 int adcData = 0;
 adcData = (dataReadFromSPI[0] << 8) | (dataReadFromSPI[1]);

Please note that 0000001101 is not a binary number in C/C++. It is actually octal (577). GCC allow an extension of number literal syntax for binary numbers. 0b0000001101 or the Arduino style B0000001101.

Could you please also explain how to transfer a whole array over the SPI protocol. I struggle a bit with that one...

I haven't used SPI, but you should be able to find some example code.  There will be a function that writes some data to the SPI bus, it will probably accept a single byte, so it may well be as simple as calling it twice.  There is usually some start transmission and end transmission functions, make sure you call this write function between these two calls.

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


text:
References (e.g, libraries and tutorials) for connecting the 24-bit ADS1256 ADC to arduino
The ADS1256 chip is a high precision 24bit, 8 channel, analog digital converter based on SPI communication that is suitable for biomedical applications and perfect for sensing ECG and EEG signals. I want to hook it up to an arduino, e.g., an arduino mega or an arduino due.
Similar ADCs from analog devices are: ADS1248, ADS1251, ADS1252, ADS1252U, ADS1253, ADS1255, ADS1259, ADS1278, ADS1298, ADS1299, etc.
It’s nice that there are [tiny, coin sized breakout boards]  available for the ADS1256 that include basic components like an 8mhz quartz crystal and cost only around 25 USD.
Several people have in the past struggled to get ADC readings using Arduino. Working only with the data sheet it took them several days or even weeks. I have a logic analyzer, multi channel oscilloscope and bus pirate ready, but I still would prefer adapting an existing library or working with a good tutorial as a starting point.
I searched for code and tutorial not only for the ADS1256 but also for similar analog devices ADC chips.
Here are the tutorials, libraries and information I found so far:
Main Links (working solution):
-- ADS1213 Arduino library (seems to be working!!!)
--  ADS1213 Arduino tutorial (includes above library)
Further Information:

Arduino due ADS129X tools(ADS1299, ADS1298, ADS1294, ADS1296)
ADS1252 Arduino Tutorial
ADS1252 Troubleshooting information
ADS1255 Troubleshooting information
ADS 1298 Troubleshooting information
ADS 1248 and arduino (german)

Q:
Is there a working library for the ADS1256 (or similar chip) and is there a current, up-to-date tutorial available for arduino?

(Update with my notes.)
Next steps (to get a working library that should be put on github):

Search for more relevant Information online (existing libraries, etc.)
Ask in AVR specific forum, if question is unanswered here. Possibly contact people via e-mail that could know more
Get familiar with Chip and Datasheet
Decide on available codebase as the starting point
Define the minimalistic testcase (This would check that some for of communication works with the chip, i.e., write register that changes the logic level of a bin of the ADC chip)
Implement the minimalistic testcase (i.e., possibly use different codebase as starting point if it fails to implement)
Expand and test the code to get a full implementation

Risks: Eittle experience with electronic design the microcontroller at hand, might miss important details that costs a lot of time. Can't be sure that my chip/PCB actually works, can be faulty hardware.
Time Estimate: 3 days of work doing 8 hours a day (total 24 hours). Exremly high variance (could be a matter of a few hours in the best case to a few weeks worst case).

Welcome to the wacky world of electronic design, where things can take days or even weeks to get done.

@Ignacio Vazquez-Abrams Thanks for your comment. I really have already worked from only the datat sheet, but as it might take long this is really a waste of time if there are prior works or libraries availiable. I am comming from computer science and I am not an expert in electronic design.

If you are interested in this question please comment (and don't write an answer to get in constact, as this gets obviously deleted as happend today). So please write comment instead!!

Have you had a chance to look at getting SPI working with it?

You are lucky. Looks like there is an Arduino library available for the ADS1256. You should give it a shot: https://github.com/Flydroid/ADS12xx-Library .
I haven't tested it but checked the registers and functions from the datasheet and it does look good.


text:
How do I read a sub-degree angle?
I need to measure (and record changes over a short time) the angle of a lever at a sub-degree resolution (The fulcrum can be the sensor) using an Arduino.
I've looked at rotary encoders, but even those with no detents have about 24 pulses per rotation. I need to measure only across a 90 degree arc. 24 pulses per rotation is 15 degrees per pulse. Which I guess results in a measurable resolution of 7.5 degrees!
I could add gears to increase the turns on the encoder, but that would increase the force required to move the lever.
Is there an option I'm not thinking of?

I've looked at rotary encoders, but even those with no detents have about 24 pulses per rotation.

It sounds like you have been looking at encoders intended for user input controls.
Optical Rotary Encoders for machinery applications are readily available with up to several thousand pulses per revolution.  Prices vary depending on if the wheel is glass or plastic, mounting options, brand, etc.
Do be aware that especially at the high resolutions, getting the encoder disk mounted perfectly concentric to the shaft being measured in important.  You would either need to buy a a wheel which already has a bushing of the same diameter as your shaft, have access to a lathe, or have something custom made.  (This is probably a case where a 3d printer is not accurate enough)
Also keep in mind that encoder wheels are often specified in cycles per revolution; with the typical two channel read head and quadrature decoding, there will be four times as many distinct state transitions.  So a mere 300 CPR wheel would give you 1200 counts per revolution.

Try a spirit level (also called bubble level) app on your phone or tablet. It can get to sub-degree accuracy, but it is relative and not absolute accuracy. If that is good enough for you, then you could buy a modern accurate accelerometer and average the values.
It might even be possible to have more than one accelerometer for more accuracy.
Good quality (calibrated) digital spirit levels are very accurate. They use a accelerometer.
It will measure the angle with the earth gravity, and it is sensitive for vibrations.
There are more ways to measure the angle, but it depends on the mechanical construction of the lever. For example a IR distance sensor for short distances at the end of the lever. Maybe a magnet and hall sensor. There are probably more ways to measure the angle.

Is there an option I'm not thinking of?

a ruler would be the simplest solution.
a capacitive pad could sense it as well.
a lever + a linear encoder.
...


text:
Can I use a spare Darlington Pair on my ULN2003A to drive a DC motor?
I'm successfully running a stepper from my Arduino via a ULN2003A and a secondary power supply. It uses the first four of the seven Darlington Pairs on the chip, leaving three spare.
A) Is there any reason I wouldn't be able to use one of the remaining pairs to drive a standard DC hobby motor? (For the sake of helping future visitors .. what about running three motors off the remaining three pairs?)
B) Do I need anything other than to connect the motor to the chip? (The chip's board has LEDs and resistors on each of pins 1 - 4, but I don't believe they're in series and thus my guess is they can be left off.)
C) The DC motor is on a PWM Pin. Is that the correct way to control its speed?
The image attached shows the setup in case I haven't been clear.

(I could probably just build it and see, but I'm new to Arduino and still scared of the blue smoke if I get something wrong!)

Low karma on this SE. Suggest adding tags: "ULN2003A" and "Darlington"

Is the COM connection of the chip available anywhere?

@IgnacioVazquez-Abrams: Yes, I believe the COM of the chip is the GND pin where the black wire connects it to the negative rail

I hope not, because that's not what it's for at all.

Also, what piece is that and why aren't you using a schematic?

@IgnacioVazquez-Abrams: The piece is this: http://www.lctech-inc.com/Hardware/Detail.aspx?id=f8364b6f-346b-48dd-af91-0fed4d56dd6c .. and I'm not using a schematic for it as I can't find one. And because I'm relatively new to this. I made my own Fritzing part for it.

Should work just fine. But you'd have to connect the motor to the positive rail, and since the ULN2003 can only sink current.
Normally when connecting a motor, you'd add a flyback diode. But the ULN2003 already has those inside the chip.
PWM is the easiest way to (somewhat) control the speed of a DC motor.

So I should just move the black wire connecting the yellow side of the motor from the ground to the positive?

Yes, assuming the motor isn't polar. (otherwise, purple to positive, black to the ULN2003)


text:
How to reset the count/data after HTTP.POST?
I have a project that records interrupts from a reed switch to nodemcu.
It records like this: 0.3,0.6,0.9,1.2 Then what I want to happen is to go back to zero when it successfully HTTP.POST to a webserver.
How can I do it? Thanks!
volatile float rainrate = 0.3;
volatile float total;

void count {
  total += rainrate;
}

So how do you set a variable to zero?

are micros() effective for this?

You are missing a lot of context on this question. Can you post the entire program?

Yea sorry, got it working already, after HTTP.POST, I put total = 0;

Try putting your total variable to 0, like this:
total = 0;
It should work like this.

yea got it already, btw thanks for answering :)


text:
How to put a condition on HTTP.POST?
I set my code to if it executes HTTP.POST, the count will reset / back to zero, but I noticed that even it returns other http code than 201 (-1 or 500), the count still resets.
How to put a condition here that if httpResponseCode = 201 (successful), then reset (total = 0;) else http.end().
Thanks!
void loop () {
  if ((millis() - lastTime) > timerDelay) {
    if (WiFi.status() == WL_CONNECTED) {
      HTTPClient http;
      http.begin(serverName);

      http.addHeader("Content-Type", "application/json");
      char temp[32];
      snprintf(temp, 32, "{\"amount\":\"%.2f\"}", total);
      int httpResponseCode = http.POST(temp);

      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
      Serial.println(total);
      total = 0;

      http.end();
    }

void count () {
  total += rainrate;
}

You mean something like this?
if( httpResponseCode==201 )
  total = 0;

Your entire code would then become:
void loop () {

  if ((millis() - lastTime) > timerDelay) {

    if(WiFi.status()== WL_CONNECTED){
      HTTPClient http;

      http.begin(serverName);

      http.addHeader("Content-Type", "application/json");

      char temp[32];
      snprintf(temp, 32, "{\"amount\":\"%.2f\"}", total);
      int httpResponseCode = http.POST(temp);

      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
      Serial.println(total);

      if( httpResponseCode==201 )
        total = 0;

      http.end();
    }

void count () {
 total += rainrate;
}

I'm trying that earlier, I'm just missing == lol. btw Thank you! :)

@Giddsec That's a mistake I still occasionally make. Glad you got it working now. Cheers.


text:
How to shorten this code (because my sensor reads slowly)?
I'm making a fare meter for our school project. I have too much lcd.print code. This code is not finished yet. My only concern is how to minimize the usage of lcd.print. I think it's the one that makes my sensor reading slow.
I'm new at Arduino; sorry if I have too many mistakes. I appreciate any of your answers. Thank you!
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <virtuabotixRTC.h>

virtuabotixRTC myRTC(6, 7, 8);
float d[4] = {};
int x = 0;
int f = 0;
int dis = 0;
const uint8_t disBut = 13;
int input = A0;
int state = 0;
int disF = 0;
int buttonstate = 0;
LiquidCrystal_I2C lcd(0x27, 20, 4);
LiquidCrystal_I2C lcd1(0x26, 20, 4);

void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  lcd1.init();
  lcd1.backlight();
  pinMode(disBut, INPUT);
  pinMode(buttonstate, OUTPUT);
}

void loop() {
  myRTC.setDS1302Time(18, 10, 10, 7, 18, 9, 2020);

  Serial.print("Current Date / Time: ");
  Serial.print(myRTC.dayofmonth);
  Serial.print("/");
  Serial.print(myRTC.month);
  Serial.print("/");
  Serial.print(myRTC.year);
  Serial.print("  ");
  Serial.print(myRTC.hours);
  Serial.print(":");
  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.println(myRTC.seconds);
  delay(500);

  d[0] = (x * 1.73);
  d[1] = (x * 1.73);
  d[2] = (x * 1.73);
  d[3] = (x * 1.73);

  lcd.setCursor(8, 0);
  lcd.print(d[0]);
  lcd.setCursor(8, 1);
  lcd.print(d[1]);
  lcd.setCursor(8, 2);
  lcd.print(d[2]);
  lcd.setCursor(8, 3);
  lcd.print(d[3]);

  lcd.setCursor(0, 0);
  lcd.print(F("P1"));
  lcd.setCursor(0, 1);
  lcd.print(F("P1"));
  lcd.setCursor(0, 2);
  lcd.print(F("P1"));
  lcd.setCursor(0, 3);
  lcd.print(F("P1"));

  lcd.setCursor(6, 0);
  lcd.print(F("D="));
  lcd.setCursor(6, 1);
  lcd.print(F("D="));
  lcd.setCursor(6, 2);
  lcd.print(F("D="));
  lcd.setCursor(6, 3);
  lcd.print(F("D="));

  lcd1.setCursor(0, 0);
  lcd1.print(F("W="));
  lcd1.setCursor(0, 1);
  lcd1.print(F("W="));
  lcd1.setCursor(0, 2);
  lcd1.print(F("W="));
  lcd1.setCursor(0, 3);
  lcd1.print(F("W="));

  lcd1.setCursor(6, 0);
  lcd1.print(F("dscnt="));
  lcd1.setCursor(6, 1);
  lcd1.print(F("dscnt="));
  lcd1.setCursor(6, 2);
  lcd1.print(F("dscnt="));
  lcd1.setCursor(6, 3);
  lcd1.print(F("dscnt="));

  lcd1.setCursor(15, 0);
  lcd1.print(F("F="));
  lcd1.setCursor(15, 1);
  lcd1.print(F("F="));
  lcd1.setCursor(15, 2);
  lcd1.print(F("F="));
  lcd1.setCursor(15, 3);
  lcd1.print(F("F="));

  int counter=digitalRead(A0);
  if (state == 0) {
    switch (counter) {
      case 1:
        state = 1;
        lcd.setCursor(11, 0);
        x = x + 1; lcd.print(x);
        break;
      case 0:
        state = 0;
        break;
    }
  }

  if (counter == LOW)
    state = 0;
  if (state == 0) {
    switch (counter) {
      case 1:
        state = 1;
        x = x + 1;
        break;
      case 0:
        state = 0;
        break;
    }
  }

 if (counter == LOW)
   state = 0;
}

remove the Serial prints or at least use a higher baud rate

Why do you think the sensor reading is slow? Do the measurement values update to slowly? How fast do you need it? Note that if the display updates too fast, you cannot read it.

Only print to the display things that change. Put in the static text once and once only in setup, and only display the changing values when they actually change, rather than every single iteration of loop.

Your slowness is because on every single iteration of loop() you are updating the entirety of the display.  That's bad and wasteful.
You need to do two things:

Only display static information (the labels) once. Do that in setup().
Only display the variable data if it actually changes.

The first is simple: move any static text to setup(). That means things like lcd1.print(F("dscnt="));. It never changes, and the display doesn't "forget" it, so doesn't need constantly reminding.
The second is slightly harder. You need to keep two copies of the data. One that is the data at this moment, and one that is the data that is being displayed. Then you compare one with the other and for any items where they differ display them and update your saved copy.
So something like:
if (d[0] != d_saved[0]) {
    d_saved[0] = d[0];
    lcd.setCursor(8, 0);
    lcd.print(d[0]);
}

You can of course make that easier to program with a loop:
for (uint8_t i = 0; i < 4; i++) {
    if (d[i] != d_saved[i]) {
        d_saved[i] = d[i];
        lcd.setCursor(8, i);
        lcd.print(d[i]);
    }
}

Of course d_saved[4] needs creating in either the global scope or as a local static variable and initialising with some suitable "can never be" values (like -1 or something) so that the first time through it will always be different from the real values and display everything properly.


text:
HC-12 AT Commands not working
I'm currently working on HC-12 transceivers. Normal operations are fine and I was able to successfully transmit basic strings between an Arduino UNO and and Arduino Nano, both of which use HC-12s.
However, when I'm trying to configure the HC-12s using AT commands, the commands that I send through the serial monitor, like the basic "AT" or "AT+VERSION" return no response.
Here's my wiring setup

HC-12 VCC to Arduino 5V
HC-12 GND to Arduino GND
HC-12 RXD to Arduino D11
HC-12 TXD to Arduino D10
HC-12 SET to Arduino GND

And here's my arduino code fore sending AT commands
#include <SoftwareSerial.h>

#define RX 11 //Connect to the TX pin of the HC-12
#define TX 10 //Connect to the RX pin of the HC-12

SoftwareSerial mySerial(RX, TX);

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

  while(!Serial);

  Serial.println("Input AT commands");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

Things I've already tried include switching to different baud rates from 300 to 9600. I've also tried the HC-12 GUI configuration tool, but that one returns an error "Serial I/O error: CreateFile failed"
Is there any way to find out if this is a problem of the HC-12 itself, or just a configuration issue?

You need to connect Arduino's Rx (pin 11) to HC-12 Tx, and Arduino's Tx(pin 10) to HC-12 Rx.

This worked. Thanks!


text:
Arduino SD card module failure
I am recieving SD card failuer and I did everything I could.
I use the correct SPI pins;
CS > 10
MOSI > 11
MISO > 12
SCK > 13
VCC > 5v
GND > GND

I did format my SD card to FAT32
I did write;
pinMode(csPin, OUTPUT);
digitalWrite(csPin, HIGH);

and I did add a blank file to sd card.
pls make harambe live ;-;
here is my code;
#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>
#include <SD.h>
#define sd_pin 10
TMRpcm tmr;

int speaker_pin = 3;
int trig_pin = 8;
int echo_pin = 9;
int buzzer_pin = 6;
long cm;
long lecture_echo;

void setup()
{
  Serial.begin(9600);
  Serial.println("active");

  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

  if(!SD.begin(sd_pin)){
    Serial.println("harambe is dead");
    return;
  }
  else{
    Serial.println("harambe is alive");
  }

  tmr.speakerPin = speaker_pin;

  pinMode(echo_pin, INPUT);
  digitalWrite(trig_pin, LOW);
  pinMode(trig_pin, OUTPUT);

  pinMode(buzzer_pin, OUTPUT);

}

void loop()
{
  digitalWrite(trig_pin, HIGH);
  delay(100);
  digitalWrite(trig_pin, LOW);

  lecture_echo = pulseIn(echo_pin, HIGH);
  cm = lecture_echo / 58;

  Serial.println(cm);
  delay(500);

  if(cm < 4)
    {

    }
  else
    {
      tmr.setVolume(5);
      tmr.play("test");
    }
}

run the SDCardInfo example

k wait, it failed

What hardware are you using? How is it wired?

laptop, is normaly wired

it is not a magic fix, but is a diagnostic tool. it prints what failed.  so what did it print?

it just diagnoses if it failed or not so it printed harambe is dead

what did you not understand on "run the SDCardInfo example"?

you talk about this right? https://www.arduino.cc/en/Tutorial/CardInfo i have this on my code already and it fails.


text:
Why are ATTiny so expensive compared to ESP modules compared to features they offer?
I was looking for a cheap MCU solution for a project, apart from being compact, ATTiny doesn't seem to provide much value. I was hoping it is cheaper but nope, They are mostly above 1.5 USD in any shop. Whereas I can easily get an ESP module for a comparable price if not cheaper, added WiFi, and optionally Bluetooth, and they are not too huge for my use cases. Am I missing something?

$1.50 is very cheap

I gave a comparison with an ESP module, which can be bought for around the same price, with a hell lot of more features and speed and everything superior.

manufacturer pricing questions are not on topic here ... prices are set to whatever the buyers will pay

Understandable why the question might seem out of scope for the community, but I really struggled to get an answer to the question. And The first answer actually solved my problem, good that it got in before the question was closed. Hope this thread will help others too.

You can get ATTINYs for much less than $1.50.
For example, right now you can order the ATTINY202 from stock in single unit quantiles from Microchip for $0.48 each. They drop to $0.35 each at 5K units (also in stock).
https://www.microchipdirect.com/product/search/all/ATTINY202
If you are really price sensitive then you can sometimes get the smaller ATTINYs for even less when buying in reels at a time, but you have to shop around.
Anytime you pick a part you have to trade-off purchase price, availability (both now and in the future), and suitability. The AVR parts can often be the best choice- but all depends on what you are using it for!

Thanks @bigjosh that was really helpful. I was looking at older versions like attiny85/84 etc which is probably expensive because they are no more in production. I started looking for new ones and ended up in Digikey website where I could find lots of 0, 1 and 2 series ATTinys. Thanks a lot for the answer.

Just FYI if other folks find themselves here from Google looking for attiny85 alternatives: As far as I can tell, the newer chips (the 0, 1, and 2 series) aren't available in PDIP packaging, so they may not be an appropriate replacement for the attiny85 if someone were looking for a breadboard-compatible device.


text:
LVGL v8.2 on ESP32-S3 colour issue ILI9341 TFT LCD Arduino IDE
I have ILI9341 320x240px TFT LCD screen which I am using with ESP32-S3-wroom-1 module.
I have tested with TFT_eSPI and works fine, but when using LVGL, I am seeing weird artefacts on the edges.

I am using Arduino IDE
Started off the sketch from
https://github.com/lvgl/lvgl/blob/master/examples/arduino/LVGL_Arduino/LVGL_Arduino.ino
Havent changed sketch file much.
I am using LVGL latest v8.2.0
/*====================
   COLOR SETTINGS
 *====================*/

/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
#define LV_COLOR_DEPTH 16

/*Swap the 2 bytes of RGB565 color. Useful if the display has an 8-bit interface (e.g. SPI)*/
#define LV_COLOR_16_SWAP 1

/*Enable features to draw on transparent background.
 *It's required if opa, and transform_* style properties are used.
 *Can be also used if the UI is above another layer, e.g. an OSD menu or video player.*/
#define LV_COLOR_SCREEN_TRANSP 1

/* Adjust color mix functions rounding. GPUs might calculate color mix (blending) differently.
 * 0: round down, 64: round up from x.75, 128: round up from half, 192: round up from x.25, 254: round up */
#define LV_COLOR_MIX_ROUND_OFS 0

/*Images pixels with this color will not be drawn if they are chroma keyed)*/
#define LV_COLOR_CHROMA_KEY lv_color_hex(0x00ff00)         /*pure green*/

LV_COLOR_SCREEN_TRANSP 1 was originally 0 changing it did not change anything.
I am following the FAQ which mentions

1.6.7 Why I see nonsense colors on the screen?
Probably LVGL's color format is not compatible with your displays color format. Check LV_COLOR_DEPTH in
lv_conf.h.
If you are using 16 bit colors with SPI (or other byte-oriented interface) probably you need to set LV_COLOR_16_SWAP
1 in lv_conf.h. It swaps the upper and lower bytes of the pixels.

as you can see above in the config, the values are as recommended.
Any help will be greatly appreciated.

Turns out, I had to disable LV_COLOR_16_SWAP
I had been trying with different colour depths and everything else, I still cannot see gradients drawn properly, but the colours seem to be correct now.

I am encountering the exact same problem, using the same ESP32-S3, but using ESP-IDF framework; not Arduino. My solution was exactly the same as yours; comment out the LV_COLOR_16_SWAP in the generated ui.c. BTW, the project I am working on is here: https://github.com/smeisner/smart-thermostat I am hoping this gets fixed sometime soon!

BTW, I found this on the SquareLine Studio forum: http://forum.squareline.io/t/when-exporting-let-us-choose-if-we-want-lv-color-16-swap-or-not/1750?u=meisner

Thanks @SteveMeisner for sharing the link


text:
Serial Communication to Control Stepper
**I wanted to add an updated code after I have finished it to help others in the future if they are ever looking for it.
EDIT AT END OF QUESTION AFTER ANSWER AND CODE UPDATE.**
I currently have an Uno with a CNCBoard Hat.
I am running a program on my RPi and sending a value through serial to the Arduino. I am receiving what I believe is a string, converting it to an int using toInt() (I found this solution somewhere). I then want to write that value to the stepper I have connected.
I know the stepper works, because if I run a simple test program such as this one:
const int stepX = 2;
const int dirX  = 5;

const int stepY = 3;
const int dirY  = 6;

const int stepZ = 4;
const int dirZ  = 7;

const int enPin = 8;

void setup() {
  // Sets the two pins as Outputs
  pinMode(stepX, OUTPUT);
  pinMode(dirX, OUTPUT);
  pinMode(enPin, OUTPUT);

  digitalWrite(enPin, LOW);
  digitalWrite(dirX, HIGH);
  digitalWrite(dirY, LOW);
  digitalWrite(dirZ, HIGH);
}

void loop() {
  // Enables the motor to move in a particular direction
  // Makes 200 pulses for making one full cycle rotation
  for (int x = 0; x < 200; x++) {
    digitalWrite(stepX,HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepX, LOW);
    delayMicroseconds(1000);
  }
   delay(1000); // One second delay
}

The stepper rotates as the program describes. Where 200 is the pulse count.
The program I am currently trying to use is:
// defines pins numbers
//Front left wheel
const int stepX = 2;
const int dirX  = 5;

//Front right wheel
const int stepY = 3;
const int dirY  = 6;

//Back left wheel
const int stepZ = 4;
const int dirZ  = 7;

//Back right wheel
const int stepA = 12;
const int dirA  = 13;

const int enPin = 8;

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

  // Sets the two pins as Outputs
  pinMode(stepX, OUTPUT);
  pinMode(dirX, OUTPUT);

  pinMode(stepY, OUTPUT);
  pinMode(dirY, OUTPUT);

  pinMode(stepZ, OUTPUT);
  pinMode(dirZ, OUTPUT);

  pinMode(enPin, OUTPUT);

  digitalWrite(enPin, LOW);
  digitalWrite(dirX, HIGH);
  digitalWrite(dirY, LOW);
  digitalWrite(dirZ, HIGH);
  digitalWrite(dirA, HIGH);
}

void loop() {
  String YpulseEncode;
  if (Serial.available() > 0) {
    YpulseEncode = Serial.readStringUntil('\n');
    int yMove1 = YpulseEncode.toInt();
    //XpulseCalc = Serial.read();

    //Serial.print("YpulseCalc: ");
    Serial.println(yMove1 * (-1));
    //Serial.print("YpulseCalc +: ");
    //Serial.println(YpulseCalc
    //Serial.print("XpulseCalc: ");
    //Serial.println(XpulseCalc);
    delay(5000);
    Serial.end();
    if (yMove1 != 0) {
      // Enables the motor to move in a particular direction
      // Makes 200 pulses for making one full cycle rotation
      for (int x = 0; x < (yMove1); x++) {
        digitalWrite(stepX, HIGH);
        delayMicroseconds(1000);
        digitalWrite(stepX, LOW);
      }
    }
  }
}

The number I am receiving from the RPi is -267. So when the serial monitor shows it, it is 267. I want to send the number 267 pulses to the stepper motor.
EDIT - UPDATED CODE

AccelStepper yStepper(AccelStepper::DRIVER, 2, 5);

// defines pins numbers
//Front left wheel
const int stepX = 2;
const int dirX  = 5;

//Front right wheel
const int stepY = 3;
const int dirY  = 6;

//Back left wheel
const int stepZ = 4;
const int dirZ  = 7;

//Back right wheel
const int stepA = 12;
const int dirA  = 13;

const int enPin = 8;

void setup() {
  yStepper.setMaxSpeed(800);
  yStepper.setAcceleration(400);

  Serial.begin(9600);

  // Sets the pins as Outputs
  pinMode(stepX, OUTPUT);
  pinMode(dirX, OUTPUT);

  pinMode(stepY, OUTPUT);
  pinMode(dirY, OUTPUT);

  pinMode(stepZ, OUTPUT);
  pinMode(dirZ, OUTPUT);

  pinMode(enPin, OUTPUT);

  digitalWrite(enPin, LOW);
  digitalWrite(dirX, HIGH);
  digitalWrite(dirY, LOW);
  digitalWrite(dirZ, HIGH);
  digitalWrite(dirA, HIGH);
}

void loop() {

  String YpulseEncode;
  if (Serial.available() > 0) {
    YpulseEncode = Serial.readStringUntil('\n');
    int yMove1 = YpulseEncode.toInt();

if (yMove1 < 0) {
    int yMoveNew = yMove1 * (-1);

    //XpulseCalc = Serial.read();
    //Serial.print("YpulseCalc: ");
    Serial.println(yMove1 * (-1));
    //Serial.print("YpulseCalc +: ");
    //Serial.println(YpulseCalc
    //Serial.print("XpulseCalc: ");
    //Serial.println(XpulseCalc);
    delay(2000);

      // Enables the motor to move in a particular direction
      // Makes 200 pulses for making one full cycle rotation
      //for (int x = 0; x < yMoveNew; x++) {
      yStepper.move(yMoveNew);
      yStepper.runToPosition();
        //digitalWrite(stepX, HIGH);
        delayMicroseconds(1000);
        //digitalWrite(stepX, LOW);
      //}
    }
  }
}

so, what is your question? ... do you have some problem that you are seeing?

Well I assume what I am inputting into the "for(int x = 0; x < (yMove1); x++)" for yMove1 is not actually an int because it doesn't move the stepper.

Based on my code, does it seem to be sending an int?

Assuming that you have the Arduino IDE on the RPi, that you send the number (which one?) from its serial monitor, and that you see the output of Serial.print(yMove1 * (-1)); as "267" in the serial monitor, your sketch receives "-267", as you think. -- But the for loop tries to count up from 0 to -267, giving you a lot of steps, until x overflows from the maximum integer to the minimum integer, which makes the condition x < yMove1 true. (You don't need the parentheses.) Is this your problem?

Oh, and why do you call Serial.end() in loop()?

You have 2 problems, which are already mentioned in the comments:

You call Serial.end() after you received one line. That will stop the Serial hardware. Thus the code will only receive one line and then ignore any data from Serial. I don't think, that you want this. So just remove the Serial.end().

yMove1 is negative, while your for loop has the condition int x = 0; x < (yMove1); x++. But zero is always higher than a negative number. Thus the for does not run at all (the condition x < yMove1 is false, when yMove1 is negative). I don't quite understand, why you want to provide a negative number. You don't have any code for direction reversing. In the current state I would suggest just not sending a negative number. I cannot say more, because it is unclear, what exactly you want here.

Note:

The parentheses around yMove1 inside the for loop condition is not needed.
The if statement if (yMove1 != 0) is not needed. If yMove1 is zero, the for loop  will just not run, because it starts with zero.

I'm sure there are other ways to do it and what I'm doing is probably not the right way but I was just testing this portion of the code and I only wanted it to send 1 value. Due to how I have my RPi code written, it will continue to send the number/ the arduino will continue to receive the number, so that's why I had serial.end(). And I do see now that my yMove1 would be negative. I am currently at work but will test it later with some new code and try fixing it. Thanks for the help!

Thanks again!
I actually made quite a few changes tonight as once I figured out the receiving and running the stepper, I wanted to control the speed of the stepper as well.