text:
D1 mini esp8266 error: esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
I am pretty sure this device worked yesterday. I tried to short GPIO0 to ground (flash), nothing.
I have a second ESP that uploads fine, but this one does not.
Is their another way to get this bootloader to open up? Or am I the owner of a brand new door stop?

show the complete wiring. is it a board or a basic module?

"doorstop", heh; maybe for a dollhouse ;) Does serial monitor show anything, like garbage, when you reset it attached?

@Juraj It's USB. I should have been more specific. There is no way to screw it up.

@dandavis Yes, I see a single line of garbage going across the screen in the serial monitor.

sorry I missed D1 mini in the tile. is something wired to the board?

@Juraj Nope. My friend. Just the USB

I'm not sure if this will help EVERYONE, but I hope it at least helps someone.  I had the same issue with several different boards (3 Nano's, 2 NodeMCU ESP8266's, and 1 Uno).  I searched and searched for an answer and I kept reading about this pin or that pin being "pulled low" or "pulled hi" interfering with uploading sketches.  Well, since I couldn't find a solid answer anywhere I decided to disconnect all of the peripherals hooked to my board (except for powers and grounds) and Wah Laa!!!  The sketch uploaded like it was supposed to.  So, I believe if you just unhook all of the sending and receiving pins from all of your peripherals during upload, the sketch should upload just fine.  I hope this helps you.

I would just like to thank you for the surprising solution. I was on the verge of going bonkers searching for a solution.

You're welcome!  I'm glad it helped.  It is definitely tied to one of the I/O pins.  It depends on what board you're using, but these boards usually have at least one pin that will not let any code upload if "pulled" up or down (depending on what it's expecting).  I believe you can look these pins up through the board data sheets/specs.

You must use the Arduino only as a pass-thru! -> So  for programming the the esp8266, you need  to BRIDGE  the Arduino-RESET to GROUND!

why? it is enough to not have Serial activated in the ATmega


text:
16x2LCD Display serial read extra character
I get extra character (frowning face) when sending a text over the serial monitor(see attached image)

When empty string is sent over the serial monitor, the LCD display still shows the extra character of frowning face.
How do I get rid of the extra character?
I use the tutorial code below and change nothing in the code.
https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalSerialDisplay/
#include <LiquidCrystal.h>

    // initialize the library by associating any needed LCD interface pin
    // with the arduino pin number it is connected to
    const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
    LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

    void setup() {
      // set up the LCD's number of columns and rows:
      lcd.begin(16, 2);
      // initialize the serial communications:
      Serial.begin(9600);
    }

    void loop() {
      // when characters arrive over the serial port...
      if (Serial.available()) {
        // wait a bit for the entire message to arrive
        delay(100);
        // clear the screen
        lcd.clear();
        // read all the available characters
        while (Serial.available() > 0) {
          // display each character to the LCD
          lcd.write(Serial.read());
        }
      }
    }

Change "Newline" to "No Line Ending", or handle the termination manually (not a bad idea).

I don't see that character in the common character sets for HD44780 type drivers.  What exact display is it? And have you been playing round with character generator ram (custom characters)?

The LCD display acts a bit different to a normal console. For instance, it does not recognize the newline character and uses the corresponding ASCII code (10) like a normal letter. Depending on the letter map of your display (for which there are several variants on the market) this will print a more or less random character. To avoid this, you have to strip the last letter from the input string before sending it to the display.
For the same reason, sending an empty string does nothing, since an empty string sends no letters. To clear individual characters in the display, you have to overwrite them with a space.

source: Stack Exchange

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

sort: votes


text:
BLE HM10 - Set Password - Android Pairing Problem
I have developed an application on Android, which connects to a Bluetooth HM10, launches commands, and turns LEDs on and off through my Arduino. All of this works properly.
So, I want to make Bluetooth secure, so that nobody can connect to it, and keep it busy and I can't connect myself.
To do this, from my Serial Monitor I execute the corresponding configuration commands, but I never get it to link correctly on my Android.
I have tried many options, to no avail:
OPTION 1)

AT+ROLE? = Ok+Get:0 (Slave or Periphe)
AT+TYPE2 = Ok+Set:2 (Auth with PIN)
AT+PASS123456
AT+RESET

OPTION 2)

AT+ROLE? = Ok+Get:0 (Slave or Periphe)
AT+TYPE3 = Ok+Set:3 (Auth and bond)
AT+PASS123456
AT+RESET

In both cases (and more failed tests), I see the BLE device on my Android Bluetooth.
I give it to connect and the window to enter the password pops up.
I introduce 123456
And it always tells me that it could not be linked.
Any ideas for why?
Thank you.

I'm not an expert but the AT commands seems a bit strange. e.g. I would expect to enter a new PIN with AT+PASS123456. Perhaps the space is part of the PIN in your case. Just a guess. Also, the question mark after PASS is used (AFAIK) to read the PIN, not to set it. Just some guesses, without knowing much about AT commands. Perhaps it works. Cheers.

The ROLE command also has a question mark. But as 0 is the default it is not a problem. PASS is just an alias for PIN so the official AT-command to set a new PIN is AT+PIN123456.

As you set the type to 3, the module requires authentication, but (I guess) the password/PIN is still 000000.

@PeterPaulKiefer I have modified the initial message, because yes, I put it wrong. The password setting is without "?"
And, no, I am not putting any spaces after the password. I have made sure they are only 6 digits, clean, with no spaces.

@PeterPaulKiefer
AT+PIN? it never gives me a value of OK, with the default pin.
And AT+PIN123456 does not react the Bluetooh module for that command.

@PeterPaulKiefer I have tried AT+TYPE1, AT+TYPE2 and AT+TYPE3 right now, with Pin 000000 and I cannot link it

I wrote about the space before the PIN. I don't know if AT commands may have spaces between their parts. I only know the compact versions. ATPIN? does not respond? What about the other commands? Do they respond? Have you tried AT+RENEW before the other commands? That would reset to the factory setup.

For the HM10 model, the AT commands above do not respond. They are not supported. Its specification in the DataSheet (https://people.ece.cornell.edu/land/courses/ece4760/PIC32/uart/HM10/DSD%20TECH%20HM-10%20datasheet.pdf) defines that the commands are AT+. They never have spaces between the command and the values to assign. The commands and the values to be assigned are continuous. And the AT+RENEW command, effectively, resets to factory values, which, I have tried many times.

ATPIN? was a typo I made in a text I repeated from your comment. I know that AT+ is the AT-command prefix. I also know he spec. But I was not sure if spaces are allowed, sometimes specs and reality differ ;-).  Your last comment lets me think, that the communication between the Arduino and the HM10 does not work. I have no idea, why. You could edit your question and add the code that runs on the Arduino. And a schematic of you setup would also be helpful.

Don't say that the setup works without authentication. In this case the Module communicates with the arduino. When you try to configure the HM10 from the serial monitor that's the other direction. Or do you configure the HM10 direct from your PC/Laptop without a Arduino between?

@PeterPaulKiefer The communication between Arduino and HM10 works perfectly because if I run AT+PASS123456 and then turn off the arduino, turn on the arduino and do an AT+PASS? returns Ok:Get:123456. So the communication is correct. In addition, without securing the HM10, I can send commands from Android, I turn off LEDs and turn on LEDs on my protoboard, via bluetooth. So it works. It only fails to secure the HM10

When I say that the communication works without authentication, I mean that from my Android application, I pair with the HM10 (automatically, from programming, without password or anything), I launch commands, the arduino picks them up, and I turn LEDs off and on. At the moment that I secure HM10 (by setting it with an authentication configuration), I cannot pair with the HM10 from the Android application because it asks me for a password and the password never works.

I configure HM10 from Arduino, using the Serial Monitor (as I mentioned in my initial post).

You could use the Serial monitor with the Arduino in between the PC and the HM10 or you can connect the HM10 direct to the PC. That's what I asked for. You also commented that the AT+PASS? does not respond. Now you comment that it responsed with the correct PIN. What is true? --- I'll stop this discussion now. Sorry, but I have not the time to guess what you might want to say. And my english is not good enough to correct yours. --- One final tip: perhaps the bluetoth authenticaten mechanism differs between the peers.

I can't connect my HM10 to my computer, because it's a Mac, and Macs can only connect to factory Bluetooth.
At all times I have said that the execution of AT+PASS commands both to obtain the password and to define a new one, have always worked well. And when I say that they have worked well, it means that the HM10 module has answered "Ok" for all cases.
The problem, as the post describes, is that from an Android device, I cannot pair the HM10.

I live similar problem.
http://kio4.com/arduino/161_HM10_BLE_Actualizar.htm
Your page is very very successful.All the instructions are working.
I will use the pio for opening the door of my car.
Thank you very very much for you help. I have a problem but.I give password to module and give the typr 3 or 2 .I try this but iphone asks for paşrşng password.I wrote wrong password but system connects and works.Beaceuse of this issue I can not use on my car because, if I wrote wrong pin it connects also.There is no password protection on the car than.so I cannot solve the password problem.What must I

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


text:
Cannot detect Bluetooth device when connected to female receiver with PS4 Joystick
I am trying to connect the Bluetooth transmitter to a female receiver via an Arduino Uno. The button blinks, but the Bluetooth is not visible in any device.
i want to connect PS4 controller using HC05
I am sharing my code below:
#include<SoftwareSerial.h>

/* Create object named bt of the class SoftwareSerial */
SoftwareSerial bt(2,3); /* (Rx,Tx) */

void setup() {
  bt.begin(9600); /* Define baud rate for software serial communication */
  Serial.begin(9600); /* Define baud rate for serial communication */
}

void loop() {
  if (bt.available()) { /* If data is available on serial port */
    Serial.write(bt.read()); /* Print character received on to the serial monitor */
  }
}

Can anyone help me out with this ?

There is no "female" with bluetooth, just master and slave. Maybe you need to first configure the HC-05 to work as a slave device. Did you try that?

@chrisl Perhaps he has the same experience like me. Master = female, slave = male (me). Sorry I couldn't resist. :-) I'm also curirous about the button that blinks.  And now seriously: (Karan wagh) The HC05 has to be configured. Here is a link that might help: https://create.arduino.cc/projecthub/electropeak/getting-started-with-hc-05-bluetooth-module-arduino-e0ca81

I tried that but got no success @chrisl

Then please also explain what you tried and how it didn't work. We need more information, or we are not able to help

we followed this https://www.instructables.com/Connecting-HC-05-Bluetooth-Module-to-Arduino/  @chrisl


text:
Is there a 3.3V and 12V 18650 circuit?
Is there an all in one circuit which regulates charging, protects and steps up/down an 18650 battery to 12V and 3.3V at the same time, so I can power a sensor and my ESP32?

Are you asking for a ready to use module, or for a circuit, that you can build yourself?

@chrisl preferably a ready to use module

there probably is such a module ... asking where to get one is an off topic shopping question

in all ways but convenience, it would be better to use an LDO to take the battery voltage down to 3.3 and use a 12v-only controller.

@dandavis can I even use an LDO safely? Won't I need some protection against over discharge?

I would suggest using a 12V controller, and then adding a 3.3V switching regulator using the 12V supply. That would be 2 off-the shelf components and you're done.

You MIGHT be able to find a battery controller that has both 12V and 3.3V outputs, but if not, a 3.3V switching regulator that can convert 12V to 3.3V efficiently is very easy to come by.


text:
What's wrong with the ACS712 sensor?
I have two ACS712 sensors, one rated for 5A, another—for 20A.
I wanted to test how precise they are, and played with different devices (in my case, old PC fans). I copy-pasted the source code from here, and changed only the Vref value as expected, so that I get a measurement of zero when there is no current. I double-checked, the value remains zero for both ACS712 sensors. The sensor (or the multimeter) is connected in series. Only one sensor (or multimeter) is connected at the same time.
Here's the data I get. Values in parenthesis correspond to the percentage of the value compared to the one got with a multimeter.

Setup
Measured bya multimeter
Measured byACS712 5A
Measured byACS712 20A

Old CPU fan
87 mA
73 mA (84%)
49 mA (56%)

UPS fan rated 1.9 W
174 mA
170 mA (97%)
97 mA (55%)

Two fans together
0.25 A
244 mA (98%)
146 mA (55%)

Server fan rated at 0.6 A
0.49 A
463 mA (95%)
268 mA (55%)

Three server fans
1.35 A
1,293 mA (96%)
683 mA (51%)

While the 5A variant seems to be slightly off (another possibility would be that the multimeter is off and the ACS712 measurements are exact), things are very different for the 20A-rated counterpart: its values are wrong initially, and for higher current, they are getting wronger.
Why is it so? Is it broken, or have I missed something?

nothing's wrong with it. Those values actually look very consistent, just double them for better accuracy. Remember that your 20A one can only sense to the nearest 40ma value (20A / 512 levels) where there is no error whatsoever (0LSBs), which is why they are about useless for hobby applications.

Your problem is that you are trying to measure motes of dust with a yard stick. The yard stick is great at measuring things in inches and feet, but when you want to find the size of something that's around 1mm in size all you can say is "it's less than an inch" or "smaller than an eighth of an inch".
You have to remember that a 20A sensor has to fit that whole range of 0-20A - that's 0-20,000mA into half the range of the ADC. That's at most 512 graduations on an Arduino, and since you can usually count on "±1 LSB quantisation noise" you really only get half that as a usable value. So you're looking at a resolution of about 40mA at best with an accuracy of  ±40mA. When you want to measure small currents they're just going to get lost in the lack of resolution. At 100mA you're still only in the range of just "There might be a current there, somewhere".
For measuring current you need to size your sensor / shunt appropriately to the range of the currents you're sensing. If you're working with small variations in a large DC current then pre-conditioning the sensing to change the offset and amplify the interesting part of the signal is required, so that the signal isn't swamped by the underlying offset. If you're working with small currents then you require a sensor / shunt that gives you an appropriate signal for that current range.
Additionally, different variants of the sensor have different sensitivity: 185 mV/A for the 5A model, and 100 mV/A for the 20A model. The code you are using doesn't take this in account. Using the correct sensitivity, the last value in your table, 683 mA, becomes 1,264 mA (683×185/100=1264). This is close enough, if you consider the ±40mA accuracy.


text:
ESP send string to Arduino
I'm trying to send a string from an ESP32 to an Arduino. I'm using a level shifter, where the Uno is now the Mega (since I couldn't get the Uno to work).

RX0 is now RX1, connected to UART2 of ESP32.
// Master sender ESP32

#include <HardwareSerial.h>

void setup() {
  // Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, 16, 17);
  delay(100);
}

void loop() {
  String shape = "1,2,3";
  Serial2.println(shape);
  delay(500);
}

//Receiver Mega

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial1.begin(9600);
  Serial.begin(19200);
  delay(100);
}

void loop() {
  if (Serial1.available()) {
    String received = "";
    received = Serial1.readString();
    Serial.println(received);
  }
}

Is there something in either sketch that should be changed?

did you connect the correct pins? ... do not use pin 0 and pin 1 for software serial

@jsotola In this setup, I'm not using software serial. The pinout is displayed with the exception of RX0 now being RX1 on the Mega.

are you missing the GND connection of the LV side of the level shifter?

@hcheung They're internally connected.

readStringUntil('\n')
//Receiver Mega

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial1.begin(9600);
  Serial.begin(19200);
  delay(100);
}

void loop() {
  if (Serial1.available()) {
    String received = "";
    received = Serial1.readStringUntil('\n');
    Serial.println(received);
  }
}

It's about how Serial.readString() works: it reads from the serial port forever in this case. It stops reading if the serial interface is given a time-out. There are two possibilities:

use readStringUntil() on the receiver
call mySerial.setTimeout(300); (from setup()) to set a 300ms (for instance, as long as it's significantly less than 1000) time out on the receiver — it defaults to one second!


text:
How do I set up bluetooth to wirelessly control servo's connected to an arduino from my PC?
I have been working on a project that includes two servos, one is on X axis the other is Y, the Arduino takes my cursor's X,Y coordinates over a Visual C# program and translates them through the Arduino and to the two servos in order to effectively control both servo's via my mouse. The problem is that I want this to be a wireless connection from the PC to the Arduino, I've been having so many issues with it, the Arduino has a wireless signal and will connect to my PC, but once I connect the output port to the Arduino serial monitor, tera term, or any other program used in similar ways; the Arduino doesn't receive any output commands from the terminal.
Here's the source code without any bluetooth:
#include<Servo.h>

Servo serX;
Servo serY;

String serialData;

void setup() {

  serX.attach(11);
  serY.attach(10);
  Serial.begin(9600);
  Serial.setTimeout(10);
}

void loop() {
}

void serialEvent() {
  serialData = Serial.readString();
  serX.write(parseDataX(serialData));
  serY.write(parseDataY(serialData));
}

int parseDataX(String data){
  data.remove(data.indexOf("Y"));
  data.remove(data.indexOf("X"), 1);
  return data.toInt();
}

int parseDataY(String data){
  data.remove(0,data.indexOf("Y") + 1);
  return data.toInt();
}

I've tried so many different source codes to set up bluetooth, I'm not sure which one I should put on here. I feel like it could be something with the visual C# application, I don't know if it is properly communicating with the Arduino either.

Does the program you added to the question, work well? I mean, does it works without bluetooth? If yes C# wouldn't be the problem. 2. What Bluetoth device do you use with the Arduino and what with the PC? Show us at least one code where you attempt to use bluetoth. And what are the error coming up with that code? How can we help, when you say "I've tried so many ways, but none of them worked"? We have no glue what happend. 3. The method String::remove() needs a count at the second argument; not a position. I don't think this code works at all.

The program I added does work pretty well, it could be faster but it works without bluetooth. I used a basic HC-05 bluetooth module, I don't have any of the full source codes where I tried bluetooth with this code saved. I tried to simply get my computer to light up an LED through bluetooth with 0 and 1 console commands and that didn't work either, I just need help with setting it up so that my PC can communicate with my Arduino, I'm okay with using something other than bluetooth if thats possible, I don't know what I should do in this kind of situation. Also the code works in practice so idk.

If your PC supports bluetooth, and the distance of the PC and the arduino wouldn't be more than - let's say - 3 meters, then bluetooth is a viable solution. This forum is not meant to provide a solution for you. You have to try youself, or search the internet for solutions. If you have tried something and there are errors, then post here what you've done, what you expect from it and what is not working. Then we could help. This is not a programming service. Tip: If  the serial connection is too slow, it might help if you use a higher baud rate (115200) should work.


text:
Which Arduino for many analogue sensors (and WiFi)?
For context, I come from a very software-heavy background so I know very little about hardware.
I'm looking to build a system that requires at least 6 sensors (pH, electrical conductivity, humidity, temperature, light intensity, flow rate), and I want to send all of this input over WiFi at ~10 minute intervals. Most of these sensors will be analogue.
I noticed that for example the Arduino Uno only has 6 analogue inputs. Plus from research, I would need to connect a WiFi module to the Uno which seems too much of a hassle and added cost.
I'm looking at the ARDUINO NANO 33 IOT right now. It seems perfect for what I want to do since it's cheap, has 8 analogue pins, and has WiFi out-of-the-box. Is my reasoning correct in choosing this Arduino? I'm wondering why something with WiFi capability and more pins is cheaper than the Uno.
Thanks in advance!

Some of the types of sensors you mention are available with a digital interface (I2C or SPI) and do not require an analog interface. If you need more analog inputs than you have analog pins available, you could also use an external I2C ADC which are available with 8 or more channels and 12 or more bits of resolution.

You can get around a limited number of analog pins by multiplexing sensors on a single one. Power each sensor with a different digital pin, and have all of their outputs go to the same analog pin. On each poll, power up one sensor at a time, read its output on the analog pin, power down the sensor, power up the next one, read etc etc. This is one technique I use in my indoor grow rooms. I use NodeMCU-12e or Wemos D1 minis.

In short, Uno is over-engineered with 20-year old technology. Many of the things needed can be done with a single silicon nowadays. Based on what you want to do, I would say Nano 33 IoT is a good choice.

The ESP32's ADC, while not perfect, is far more capable than the UNO's. No onboard ADC is really worth a darn compared to something cheap and awesome like a $2 ADS1115 4 port 15bit ADC.  I would use a nodeMCU and one of those; $5, done. For the cost of one NANO33, you can get 4 or 5 of that setup. Nobody buys actual Arduino boards, unless they don't know any better.

For short answer: Just use NodeMCU ESP32 or any ESP32 dev board.
TLDR;

ESP32 is actually a wifi module but has very powerful processor (240MHz max), way more faster than Arduino Uno (atmega328 @16MHz). Because of this, wifi comes as natural for ESP32.
You can even buy ESP32 dev board around US$10 (include shipping) while the esp32 module itself costs only $5
Arduino UNO 33 IOT is simply SAMD21 (@48MHz) with external wifi module. This wifi module alone costs about US$10. This configuration is similar to Arduino UNO + wifi shield but of course cheaper because you don't need an extra costly shield for wifi.
The expensive wifi shield is actually HDG204 wifi SIP (system in package) + 32-bit AVR AT32UC3C1512C (66MHz max). Pretty much the wifi shield piggy back on Arduino UNO is 4 times faster than 8-bit micro atmega328 of Arduino UNO. So... it's pricey.
Edit:
ESP32 has 2x 12-bit ADC with 16 channels exposed out to IO pin on most of ESP32 dev board.
If you just read some temperature sensors, range finder sensors, humidity sensors... You are good with most of ADC inside microcontrollers these days. Unless you are building instrumentational device, well, this is a whole different story.

Could you explain how this answers the question?

According to me this almost answers the whole question except why is it   cheaper .

the WiFi module on Nano 33 IoT is an ESP32

One of the issues in the question was the number of analog ports available. You did not mention them in your answer.

OP is looking for interfacing with a lot of analog sensor. ESP-32 won't be a good choice if you want to use ADC, it is noisy, non-linear...

To hcheung, I don't have much experience with ESP32's ADC, but if I want low noise ADC, I rather roll external ADC with it's dedicated low noise PSU. I've been using ADC from a few Arm M0/M0+, not really happy with them.

To StarCat, can you read the pinout picture? OP wants something that doesn't cost much, has plenty of ADC channel and works out of the box without extra addon. Are you trying to say, I have to give answer on strictly arduino board from arduino.cc only? I edit my answer to just answer what OP wants as in the question.

Based on this chart https://github.com/thehookup/ESP32_Ceiling_Light/blob/master/PinModes_ESP32_NodeMCU.jpg , it looks like the NodeMCU ESP32 only has 6 analog input pins. Am I misunderstanding something?

ESP32 D0WD datasheet, page 15 https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf , shows the ADC pin matrix. All of those pins are exposed in the pinout picture from TheHookUp's guide. I don't trust 100% those tutorials on the internet. It is good in its own context but sometime wrong in different context.

I have been considering the AdaFruit Huzzah32 Feather ESP32… 16 analog inputs (2 DACs); built-in Wi-Fi, Bluetooth and USB; LiPo battery source/charger built-in; and compatible with Arduino IDE, all for $20. (WipperSnapper IoT compatible.) Seems like this part might satisfy the original question.

Doesn't matter the number of analog pins if you're doing 10 minute polls.
Run the power to each sensor from its own digital pin. Connect the sensor outputs to a single analog pin. Note that any analog pin can be used as a digital pin, but not vice-versa.
Start with all sensors turned off (ie. the individual digital power pins turned LOW). When you poll, turn HIGH a single sensor's digital pin, read the output on the analog pin, and then power back down the sensor. Move on to sensor two, sensor three etc.
This is pretty much multiplexing the analog pin. I do this all the time in my indoor grow room environment automation systems.
Typically I use Wemos D1 minis for the task, or NodeMCU-12e devices. The last batch of D1 minis I paid less than $10 for five of them, shipping and taxes included. Both devices I mentioned have wifi and bluetooth inherent. I even reprogram them over the air (OTA).

:-O how do you turn off power to an analog sensor circuit? for example LDR, CT, temperature sensor circuits would interfere with each other

You do that on your Wemos D1 which has only one mediocre ADC?

For 10K LDR, 10K thermistor or some low power sensors (under 10mA), those can be powered using an IO pin for each sensor without problem. Just turn one on when needed then turn off when done


text:
Programming AT24C16 EEPROM with Arduino Nano
I have been trying to program an AT24C16 EEPROM and have set up a circuit as per the attached image.

I have been using the following Arduino code:
#include <Wire.h>

#define disk1 0x50    //Address of 24LC256 eeprom chip

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

  unsigned int address = 10;

  writeEEPROM(disk1, address, 72);
  Serial.println(readEEPROM(disk1, address), DEC);
}

void loop(){}

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Serial.println(Wire.endTransmission());

  delay(5);
}

byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
  byte rdata = 0xFF;

  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Serial.println(Wire.endTransmission());

  Wire.requestFrom(deviceaddress,1);

  if (Wire.available()) rdata = Wire.read();

  return rdata;
}

Unfortunately I only ever receive '255' in the serial monitor suggesting that no data has been written.
The code was from this tutorial which explains how the wiring on pins 1-3 governs the address of the chip.

See what values your .endTransmission() calls are returning.  You may want to use the I2CScanner sketch to at least make sure it is showing up on the bus.

Hi have updated code so it prints out the .endTransmission()  calls and get a '2' returned from both which according to wire doc is '2:received NACK on transmit of address'

I thought I should print the endTransmission call for both writeEEPROM() and readEEPROM() ? - will update question when i know where to put print statement...

Ok, the updated code returns '0' for the read and write endTransmission calls.

What happens if you use unsigned int address = 0; instead?

Same thing. Ive tried different addresses and different values and they always seem to be the same result..

Well, I think I see part of what is happening.  I'm not sure to what degree this is an Arduino problem, but it may be of some use to someone wanting to interface this chip with an Arduino.  So, here's what I see:
You're writing to the chip just fine so far as I2C is concerned.  But the content of what you're writing is not exactly correct to the chip itself.
You have:
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8));   // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB

Which is intuitive, but unfortunately not how the AT24C16 apparently works.   To be clear, the tutorial you've referenced uses the 24LC256, which does use the addressing scheme above.  But you're not using that chip.
The chips in the series covered by the AT24LC16 datasheet need progressively larger EEPROM addresses for the larger memory sizes.  As the size of the chip increases they are effectively stealing configurable bits from the A0, A1, A2 pins and repurposing them as part of the EEPROM address encoded into the I2C address.  You'll see that the for up to the 2Kbit/256byte/8-bit addressable EEPROM, all of A0, A1, A2 can be used to set the I2C address (to have multiple of these chips).  By the time you work your way up to the 16kbit/2kbyte/11-bit addressable chip, all of the A0, A1, A2 are specified as no connect; the datasheet says that can be connected to ground.  The reason for doing this probably just for controlling noise.
The chip expects only the lower 8 bits of the EEPROM word address to be sent in the data portion of the I2C write (or "dummy" write).  But the bits in excess of 8-bits, the upper 3-bits for your 11-bit addressable, are expected to be encoded into the I2C address itself, like so:
const uint8_t i2c_base_address = 0x50;
const uint8_t upper_three_eeprom_adress_bits = (eeaddress >> 8) & 0x7;
const uint8_t i2c_address = i2c_base_address | upper_three_eeprom_adress_bits;
Wire.beginTransmission(i2c_address);
Wire.write(eeaddress & 0xFF); // address LSB

The datasheet speaks of "BYTE WRITE" where single bytes per I2C write transactions are written to EEPROM.  And it speaks of "PAGE WRITE" where an entire page payload is sent, 16-bytes for your model.  Because you are sending two bytes as part of data portion of the I2C write, you are doing neither of these things.  The chip's notion of "current address" is updated differently for "byte" vs "page" writes.
If I had guess, they didn't want there to be a qualitative difference in handling 1 vs 2 byte I2C write transactions or alternately between 15 (page size minus one) vs 16 (page size) byte I2C write transactions.  So, they just decided anything in the middle ground between a single byte write and an entire page write should be ignored, so no EEPROM write operation carried out.

Thank you so much for taking the time to respond in such depth and clarity. I have updated my code and it appears to work! Shall I post my code as another answer? The comment section wont allow it...

That sounds reasonable to me.  Yeah, comments aren't really intended for answer material anyway, let alone code of any significant size.

In response to the answer from @timemage I updated my code which now allows me to read and write to the EEPROM chip as intended. Here is the code just in case anyone else wants it quickly:
#include <Wire.h>

#define disk1 0x50    //Address of eeprom chip

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

  unsigned int address0 = 0;

  writeEEPROM(disk1, address0, 1);

  Serial.println(readEEPROM(disk1, address0), DEC);
}

void loop() {}

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{

  const uint8_t i2c_base_address = 0x50;
  const uint8_t upper_three_eeprom_adress_bits = (eeaddress >> 8) & 0x7;
  const uint8_t i2c_address = i2c_base_address | upper_three_eeprom_adress_bits;
  Wire.beginTransmission(i2c_address);
  Wire.write(eeaddress & 0xFF); // address LSB

  Wire.write(data);
  Wire.endTransmission();

  delay(5);
}

byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
  byte rdata = 0xFF;

  const uint8_t i2c_base_address = 0x50;
  const uint8_t upper_three_eeprom_adress_bits = (eeaddress >> 8) & 0x7;
  const uint8_t i2c_address = i2c_base_address | upper_three_eeprom_adress_bits;
  Wire.beginTransmission(i2c_address);
  Wire.write(eeaddress & 0xFF); // address LSB

  Wire.endTransmission();

  Wire.requestFrom(deviceaddress, 1);

  if (Wire.available()) rdata = Wire.read();

  return rdata;
}


text:
Is there something like a Virtual Environment for Arduino?
I'm using Arduino IDE for a variety of projects.
The libraries and boards used in different projects are different and I would like to have a customized environment for each project.
Eg: In a project involving an Arduino, I don't want all the ESP boards or Adafruit libraries that I might use on another project.
Python has something called Virtual Environments, where you can switch between environments and have a different setup of libraries and configurations for each project.
Is there something like this I can configure for Arduino?

Development environment like PlatformIO allow you to have your dependency libraries installed on per-project basis. It can be installed on Atom Editor or VSCode as a plug-in.

in Arduino IDE you can set the sketchbook folder

you can use GIT; all the config is "rest"ful; lives in files.

Has someone ever tried to run the Arduino-cli in a docker container? Just one crazy thought

Sorry, but in Arduino IDE no such functionality as virtual enviroment. To add your own version of libraries to each projects you may only add it (libraries) directly to a project dir.

in Arduino IDE you can select the sketchbook folder. it contains the sketches, libraries, custom hardware specs. that is a much cleaner solution then adding libraries to sketch.


text:
HX711 arduino Scale offset drift
I am working around with HX711 ADC and a 5kg load cell, it seems the HX711 library is some sort of mystery no one wants to reveal!
Please someone explain me, I promise to keep the secret ;)
Anyone here can suggest a coding trick to compensate drifting in the reading values?
Actually the slope is ok, but the offset is not stable, also I don't know the difference between these two:
scale.set_offset();
scale.get_offset();

How these two actually do the job and shall I use them in the void loop() function?
Also that would be really helpful to suggest me a code for averaging readings beside what the library pre-used, like scale.get_units()
Thanks

Have you tried auto zero, that works very well if the circuit is stable.

@Gil can you please explain more, no I don't know what is auto zero

Zero the reading when there is no load on the scale. this goes into great detail: https://www.analog.com/en/analog-dialogue/articles/demystifying-auto-zero-amplifiers-part-1.html I do not know your system but a guess would be a low reading would be no load, save that and use it when you get a quick increase in weight use that as your correction factor.

@Gil thanks man you helped a lot

You are welcome!


text:
Using Arduino as a standalone compiler
I mostly program in C/C++ so I conviniently have a GCC compiler for all my compilations. I was wondering if there is a special compiler for Arduino that can be used just like the GCC Compiler? Because just taking a .ino sketch and passing it to the comiler with a few arguments will be a lot easier for me that all those things in the IDE, and furthermore I use Sublime Text as my text editor. And making a C program work in Sublime is as simple as providing it a path to the compiler. So I would like a portable smaller version of the Arduino Compiler that is NOT the whole IDE folder. Hope I get nice answers!! Thanks in advance.

Do you want to use Arduino libraries and other "Arduino enhancements", or are you OK with just using plain C/C++ and AVR headers?

I use it for mostly robotics applications and use atleast 10 sensors at once so libraries are a must...

First of all: The Arduino IDE brings its own GCC compiler. It is a version, that can compile for the AVR platform (don't know, if the standard version is capable of that).
When you activate verbose output for compilation in the preferences of your Arduino IDE, you can actually see, what calls to GCC the IDE is doing. You could use that to replicate it.
If you only want to use the sublime text editor for programming and not rebuilding the compilation environment of Arduino for fun (which I wouldn't able to help with), you might wanna have a look at the Arduino-cli. It gives you a tool to invoke important function, that normally the IDE does, via commandline (like installing cores and libraries, compiling and uploading). Thats what I'm currently using with sublime for programming in Arduino. It allows me to invoke building an uploading from sublime without having the Arduino IDE open.
If you want to go that way, here are the sublime-build files, that I use for my Arduino Nanos and ATtiny84s. Maybe you can adapt them for your needs. (Note: I omitted multiple variants, that I use to upload on different com ports, because the com port is the only thing, that changes there. Also I'm on Ubuntu, so on Windows or Mac it might look a bit different)
For the Nano:
{
    "cmd" : ["arduino-cli compile --fqbn arduino:avr:nano"],
    "working_dir": "$file_path",
    "shell":true,
    "file_patterns":["*.ino"],
    "variants": [
        {
            "cmd" : ["arduino-cli compile --fqbn arduino:avr:nano && arduino-cli upload -v --fqbn arduino:avr:nano:cpu=atmega328old --port /dev/ttyUSB0"],
            "working_dir": "$file_path",
            "shell":true,
            "name": "Compile & Upload ttyUSB0"
        }
    ]
}

For the ATtiny84:
{
    "cmd" : ["arduino-cli compile --fqbn ATTinyCore:avr:attinyx4:chip=84"],
    "working_dir": "$file_path",
    "shell":true,
    "file_patterns":["*.ino"],
    "variants": [
        {
            "cmd" : ["arduino-cli compile --fqbn ATTinyCore:avr:attinyx4:chip=84 && arduino-cli upload -v --fqbn ATTinyCore:avr:attinyx4:chip=84 --programmer arduinoasisp --port /dev/ttyUSB0"],
            "working_dir": "$file_path",
            "shell":true,
            "name": "ATtiny84: Compile & Upload ttyUSB0"
        }
    ]
}

Thank you @chrisl I am positive that Arduino-CLI will be of great use to me, I checked it out and maybe that is more or less what I wanted, the idea of carrying around 500mbs of files in form of arduino ide is very bad for me and so I wanted a small compiler like interface. The folks at Arduino have done a good job at the CLI version so that might help. Thanks again!!

This is also available as a package for Sublime Text 3!!

This is not an answer that fully meets what you ask, but it is too big for a comment, and it helps you somewhat, at least using your Sublime editor.
What annoys me most in the Arduino IDE is the lack of supporting multiple files (having horizontal tabs make the number of files to see max 6 or 7, and using .h/.cpp files easily goes most beyond that number).
My preference is using Visual Studio as editor and I do. In your case you can use Sublime editor. Make sure that the .ino file doesn't change (i.e. only make a forward to your C++ classes or code in other classes). This is to prevent synchronization problems between the Arduino IDE and Visual Studio.
Simultaneously start up the Arduino IDE, and do the compilation from here. Only read the .ino file, while the other files are in the same directory (structure), and can be edited by Sublime editor.
So it doesn't use GCC, but the Arduino IDE is only used for compiling/running, and all editing work is done on your editor.
Besides that, in Visual Studio I created (at least for one project) stubs so I can run it on the PC as well as 'test' project. For this you can use your gcc compiler.

I tried using the "Use external editor" in the Arduino IDE but that is not what I wanted. I looked into the Arduino-CLI projest on github and maybe thats what I was looking for. Thanks for the effort though.

No problem, I upvote chrisl's answer which seems more suitable for you.

Yes that would be great, thanks

If you are working in Windows, I recommend VS2019 Community Edition (free) plus the Visual Micro extension.  Gives you all the intellisense features of VS, tabbed edit windows, the works.  I came to the Arduino world from Windows programming with C++ & C#, so I was already familiar with the Visual Studio line of IDE's, but I wouldn't have it any other way now.


text:
Is my 8x8 led matrix module broken?
I have an Arduino Mega set up with an 8x8 led matrix as laid out in this circuito.io project: https://www.circuito.io/static/reply/index.html?solutionId=6013e67aeaa9ed0030f668fb&solutionPath=storage.circuito.io

But when I plug in the usb cable, it looks like this:

I'm using the default code supplied by circuito.io (this was just meant to be a "hello world" jumping off point)
When I run the code, some of the leds flicker on and off, but the ones that are on in the image tend to stay on regardless.

Did you open a serial monitor and choose an option? The code waits for input over the serial connection.

@PeterPaulKiefer Yes I did, I also tried adding an option that would simply clear the screen (to no effect)

Some guesses: The module is not correctly wired. Show a picture where I can see the connections, the arduino and the matrix completely then, I could check it for you. - A wire is broken. I think you have checked this already. -- The Module is broken. That's possible!. Have you a second one to try? The chip seems to be replacable. Have you another MAX7219 chip to replace it? -- You could have a typo in the code, by accident: add your code (ino-file; the one you use) to the question. I would check that for you.

What happens if you only connect Vcc and GND to the module? Could you post a photo of the underside of the module? It might be a bad solder connection. Try wiggling all the connections to make sure they make proper contact. I've had breadboards that sometimes didn't make a proper connection with the wires that I inserted.

So I've tried wiring the MAX7219 chip up myself following this as a guide: http://wayoda.github.io/LedControl/pages/hardware
I only wired up the first column because my breadboard is only so big (plus, I just need to see what's up)
I seemed to have the exact same problem with the example code from circuito.io, but - when I loaded up the LCDemoMatrix example, which uses the http://wayoda.github.io/LedControl/ library instead, it works!
I'm not sure what was wrong with the first demo I used, possibly the modification I used to just turn on a single led was wrong.

@Gerben - Plugging in just VCC and GND still results in the same pattern

VCC, Ground, and Din are connected together per your frizzy drawing. This cannot be as the leds light. A schematic, of what you have, would be much easier to read and follow. The information all we can do is take a SWAG at it. FYI the Frizzy thing at circuit IO has the same problem.

In that case there is a problem with your matrix module.

It's likely that it is just the orientation of the module is wrong. Pull out the LED module, rotate 180 degrees, put it back in and it should work. The dot point should be on the bottom right.


text:
Can Arduino uno adjust input square wave duty, phase and frequency with just timer-counter?
Requirement:

I have input 4KHz pulse input
Divide it's frequency in half
Arbitrarily adjust phase
Arbitrarily adjust duty
Out put the modified pulse

My solution (CPU):
uint8_t cnt = 0;
uint16_t t1 = 235;
uint16_t t2 = 5;
String cmd;

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

  Serial.begin(9600);
  delay(500);
  attachInterrupt(digitalPinToInterrupt(2), rising_edge, RISING);
  Serial.println("PWM init");
}

void loop() {
  if (Serial.available() > 0) {
    cmd = Serial.readString();

    if (cmd.substring(0,8) == "setdelay"){
      t1 = cmd.substring(9).toInt();
      Serial.print("setting delay to ");
      Serial.print(t1);
      Serial.println(" us");
    }
    else if (cmd.substring(0,7) == "sethigh"){
      t2 = cmd.substring(8).toInt();
      Serial.print("setting high time to ");
      Serial.print(t2);
      Serial.println(" us");
    }
  Serial.flush();
  }
}
void rising_edge() {
  cnt = cnt + 1;
  if (cnt >= 2) {                           //divide by 2
    delayMicroseconds(t1);
    digitalWrite(3,HIGH);
    delayMicroseconds(t2);
    digitalWrite(3,LOW);
    cnt = 0;
  }
}

However this makes heavy use of CPU, and I need to use CPU for something else.Is it possible to implement all this with TC ?
Thanks in Advance !

You could use the incoming clock pulses as an external (asynchronous) clock source for timer2. See the ASSR register in the datasheet, for starters. You can't change the duty cycle with only this method. Though you use use an additional timer in "one-shot mode", but that would still require interrupts.

this makes heavy use of CPU, and I need to use CPU for something else

The issue with this code is that is heavily uses the CPU for busy
waiting rather than for doing useful work. You should try to get rid of
those waiting loops:

Serial.readString(): see Majenko's blog post Reading Serial on the
Arduino

delayMicroseconds(): for this, you can indeed use a timer.

For the pulse generation, you can keep roughly the same logic as your
existing code: output a single pulse every other time a rising edge is
sensed on the input. This pulse can be conveniently generated by
Timer 1 on pin 9 by using a PWM mode and stopping the timer
after a single cycle. I would use inverting PWM mode, with the timer
starting at zero on the input pulse:

at t1 microseconds, a compare match sets the output HIGH

at t1+t2 microseconds, the timer overflow sets the output LOW, and
the overflow interrupt stops and resets the timer

Here is a tentative, untested implementation:
// Set the pulse timings. To be called from loop() on user's request.
void set_timings(uint16_t t1, uint16_t t2)
{
    uint16_t ocr1a = t1 * 16 - 1;        // initial time in LOW state
    uint16_t icr1 = (t1 + t2) * 16 - 1;  // timer period
    noInterrupts();  // protect critical section
    OCR1A = ocr1a;
    ICR1 = icr1;
    interrupts();
}

// Configure Timer 1. To be called from setup().
void setup_timer() {
    DDRB  |= _BV(PB1);    // set pin digital 9 = PB1 = OC1A as output
    TCCR1A = _BV(COM1A0)  // PWM on OC1A, inverting mode
           | _BV(COM1A1)  // ditto
           | _BV(WGM11);  // mode 14: fast PWM, top = ICR1
    TCCR1B = _BV(WGM12)   // ditto
           | _BV(WGM13)   // ditto
           | 0;           // stopped
    TCNT1  = 0;           // reset
    TIFR1  = _BV(TOV1);   // clear overflow flag
    TIMSK1 = _BV(TOIE1);  // enable overflow interrupt
    set_timings(235, 5);  // initial timings
}

// Interrupt triggered by a rising edge of the input.
void on_rising_edge() {
    static uint8_t count;
    if (++count % 2) return;   // divide by 2
    TCCR1B |= _BV(CS10);       // start timer, clock @ F_CPU
}

// Stop and reset the timer when it overflows.
ISR(TIMER1_OVF_vect) {
    TCCR1B = 0;  // stop
    TCNT1  = 0;  // reset
}


text:
ESP32 SD writes but doesn't append
I've got a microSD module adapter from the far east, and so far so good, and although it can create files using writeFile, it does not append messages. It returns true, i.e: message appended successfully but when you read the file on the computer or when ESP32 reads on reboot, it's blank.
This is how I call the function:
char* sdFileName = "/v.ea";
if (appendFile(SD, sdFileName, "Heyy")) {
//success
} else {
//failed
}

This is the modified, appendFile function:
bool appendFile(fs::FS &fs, const char * path, const char * message) {
  bool appendSuccess = false;
  if (DEBUG == 1) {
    Serial.print("Appending to the file: ");
    Serial.println(path);
  }
  File file = fs.open(path, FILE_APPEND);
  if (!file) {
    appendSuccess = false;
    if (DEBUG == 1) {
      Serial.println("Failed opening the file.");
    }
  }
  if (file.print(message)) {
    appendSuccess = true;
    if (DEBUG == 1) {
      Serial.println("Appended succesfully.");
    }
  } else {
    appendSuccess = false;
    if (DEBUG == 1) {
      Serial.println("Appending failed.");
    }
  }
  file.close();
  if (appendSuccess) {
    return true;
  } else {
    return false;
  }
}

I've even tried the writeFile function with file.seek(EOF) but no luck.
When calling appendFile for the first time, this appears:
[W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x17
Appending succesfully.

When the appendFile is called for the second time, this appears in serial monitor:
[W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x17
[W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x5
[W][sd_diskio.cpp:149] sdCommand(): token error [17] 0x5
[E][vfs_api.cpp:265] VFSFileImpl(): fopen(/sd/v.ea) failed
Appending failed.

I am using two SPI devices: MFRC522, and before calling SD's functions, I do a digitalWrite(SD_SS, LOW) to "enable" the SD functions till it completes its operations and returns back to HIGH to disable it.
The example in SD(esp32) works fine - writing, appending, deleting, renaming, etc. all work well.

Did you initialize SD with SD.begin()?  How do you handle the MFRC522? You have to disabled it, when the SD reader is active on the SPI bus. Where do you use writeFile? From the code I see, there's is nothing wrong, beside it is too complex. If there is a problem with the code, then you missed to show us the part where the problem is located. When you said the SD(esp32) works fine, do you mean example code for ESP32 where you don't use additional hardware?

@PeterPaulKiefer, yes, it is obvious, otherwise, even the writeFile would fail, and it'd report that SD mount failed first and foremost. Also yes, as I said, when I disable MFRC522, I enable SD, complete operations, then disable SD and enable MFRC522. The problem, as I suspect is in appendFile, as Serial monitor shows the [W] and [E], respectively. And also yes, SD(esp32) from File > Examples works well for all operations.

P.S.: I use writeFile if readFile returns false, that is, when the file does not exist, it invokes writeFile(SD, sdFileName, ""). Specifically, when fs.open(path) returns false, I instruct to create a new file by invoking writeFile.


text:
Ok to Connect 2.9V Stepper to 3.3V pin?
So I have a stepper motor that's rated for 2.9V and 0.8A and I connected it to a L9110 Driver and I wanted to drive it with my arduino. But I don't know how to drive it safely without damaging the motor. I am using the stepper.h library and thought of connecting it to 3.3V pin on the Arduino but I am a bit concerned.. is it Ok to power it with 3.3V if no then What can I do?
Edit: the L9110 module I am using is a dual H Bridge.
Edit2: I was Indead Powering the Stepper and the Module directly from the arduino.. luckily the arduino survived.
Edit3: So I didn't have a 3V power supply so I used a Voltage Divider with a 9V battery and connected the L9110s module with the battery (after its voltage divided) and the module powers on.. but when the arduino starts driving the stepper the module's led starts Flickering instead of staying on and the stepper doesn't turn... I don't know what is the problem.

I don't think the motor will be your problem. I think the arduino is in danger. If the motor is powered 0.4V higher than specified, who cares. But you try to draw 800 mA from the arduino 3.3V output. That's too much. Just use an external power to drive the motor, not the arduino. BTW: I assume you' ll use a L9110 Module with two driver chips. One L9110 alone is only useful for DC motor; not for steppers.

It may just because I'm not completely awake, but I'm finding it difficult to follow your wiring description.  A diagram or schematic would be better.

It is unclear from your description / question if you are connecting a stepping motor directly to the pins on an Arduino.  Further, we do not know which Arduino you are using.  But, in general, an Arduino's outputs are likely directly connected to the processor.  And there are no (or very few) processors that can survive getting 800mA pulled from one of their output pins.  So do be very careful or you may burn out the processor.

Oops... I powered it directly from the arduino... but it's still alive(I think)

Is it fine if I used a 1n4007 diode to "protect" The Arduino UNO from The Motor? Or it will be useless??

"I didn't have a 3V power supply so I used a Voltage Divider" - You cannot use a voltage divider to power a circuit, because the voltage will be dependent on how much current your circuit draws. There is no cheaping out there. You should really buy a fitting voltage regulator. They are not that expensive. And if your circuit is dtationary, you could get stable and powerfull 5V from typical USB phone chargers. Then buy a voltage regulator for getting from 5 to 3V, which also can provide enough current.

There are very cheap dcdc converters with an onboard potentiometer to adjust outout voltage. The only cheaper (and very dirty) solution could be to use a 5V usb charger and put 3 Si diodes in series. The diodes will drop the voltage to 5V-3×0.7V=2.9V. The diodes should be rated for 1W power dissipation, just to be save

use two AA cells in series ... use C or D cells for more capacity

@jsotola, Doesn't a motor driver have solid state circuitry that needs a regulated power source? Or is it just an H-bridge built with MOSFETs that can tolerate a wide range of input voltages?

@Duncan the  L9110 datasheet specifies a wide power supply voltage range

Motors draw a LOT of current compared to CMOS circuits.
The 3.3V output on most Arduinos can only provide a very small amount of current. The Arduino Uno, for example, says it only provides a max of 50mA from its 3.3V regulator. Your motor driver probably needs >10X more than that.
The overload protection on the Arduino's voltage regulator will probably kick in and cause it to shut off. It might take a while to cool down before 3.3V output comes back. I've heard that the protection on Arduino knockoffs doesn't always work, so you could also fry the voltage regulator if you try to draw too much from it.
Bottom line: Don't do that.
Get a high current supply for your motor driver.

I was powering the driver directly from the arduino. Thankfully the Arduino isn't Dead (yet) so I decided to Use a 9V battery with a Voltage divider to power the driver and the motor But now when the arduino Starts driving the stepper the driver's led starts flickering instead of staying constant. And now the motor doesn't turn (see my last edit for more details)

If you're talking about one of those little square 9V batteries, forget it. Those don't have enough juice to power an Arduino for long, never mind a motor. They have very low total energy storage (measured in mAh, 500 mAh is common) and very low peak current. (A little googling said "Estimate 350 mA peak for 10 minutes".) If your motor needs 800 mA, you have less than half the current you need to even run the thing. It might work for a few seconds when the battery is completely fresh, but it might not.

Do you have any recommendation for any Readily Available power source for that Motor?

Nope. Look at the current requirements, and find a switching supply that provides at least 20% more current (so you have some "wiggle room".)


text:
unable to modify NTPClient to use static IP address
I tried the example  File > Examples > ESP8266WiFi > NTPClient which requests the current time and it worked fine.  Then I tried to modify it so that the ESP8266 would have a static IP address on my home network.  I added the following lines before  void setup()
IPAddress staticIP(192, 168,   0, 159);
IPAddress  gateway(192, 168,   0,   1);
IPAddress   subnet(255, 255, 255,   0);

Then, in  void setup()     I added a line and commented out the original line like this
//  WiFi.mode(WIFI_STA);
WiFi.config(staticIP, gateway, subnet);

After running the sketch after I did this, it connected to my home network without any problems (as it did before).  But this time, after it prints the message sending NTP packet... to the serial monitor, it just says no packet yet.  This process is repeated every 10 seconds, but it never comes back with the time.
My troubleshooting efforts have been to uncomment the original line and comment out the line I added above.  This restores the sketch to its working condition.  I have done this several times over the past three days and the same thing always happens.
If I subscribed to conspiracy theories, I might think that some DHCP zealots are behind this.  Unfortunately, I can't come up with a better explanation.  So to ask just one question, "How can I get my ESP8266-01, flashed with Arduino 1.8.10, running on a Windows 8.1 laptop, to have a static IP on my home network and fetch current NTP timestamps from the internet?
(for reference, this is the sketch in question)
/*

  Udp NTP Client

  Get the time from a Network Time Protocol (NTP) time server
  Demonstrates use of UDP sendPacket and ReceivePacket
  For more on NTP time servers and the messages needed to communicate with them,
  see http://en.wikipedia.org/wiki/Network_Time_Protocol

  created 4 Sep 2010
  by Michael Margolis
  modified 9 Apr 2012
  by Tom Igoe
  updated for the ESP8266 12 Apr 2015
  by Ivan Grokhotkov

  This code is in the public domain.

*/

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

#ifndef STASSID
#define STASSID "peopleMightFreakIfIuseMyRealInfo"
#define STAPSK  "dontHaveAsecurityPanicAttack"
#endif

const char * ssid = STASSID; // your network SSID (name)
const char * pass = STAPSK;  // your network password

IPAddress staticIP(192, 168,   0, 159);
IPAddress  gateway(192, 168,   0,   1);
IPAddress   subnet(255, 255, 255,   0);

unsigned int localPort = 2390;      // local port to listen for UDP packets

/* Don't hardwire the IP address or we won't get the benefits of the pool.
    Lookup the IP address for the host name instead */
//IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server
IPAddress timeServerIP; // time.nist.gov NTP server address
const char* ntpServerName = "time.nist.gov";

const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message

byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets

// A UDP instance to let us send and receive packets over UDP
WiFiUDP udp;

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

  // We start by connecting to a WiFi network
  Serial.print("Connecting to ");
  Serial.println(ssid);
//  WiFi.mode(WIFI_STA);
  WiFi.config(staticIP, gateway, subnet);
  WiFi.begin(ssid, pass);

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

  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  Serial.println("Starting UDP");
  udp.begin(localPort);
  Serial.print("Local port: ");
  Serial.println(udp.localPort());
}

void loop() {
  //get a random server from the pool
  WiFi.hostByName(ntpServerName, timeServerIP);

  sendNTPpacket(timeServerIP); // send an NTP packet to a time server
  // wait to see if a reply is available
  delay(1000);

  int cb = udp.parsePacket();
  if (!cb) {
    Serial.println("no packet yet");
  } else {
    Serial.print("packet received, length=");
    Serial.println(cb);
    // We've received a packet, read the data from it
    udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer

    //the timestamp starts at byte 40 of the received packet and is four bytes,
    // or two words, long. First, esxtract the two words:

    unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
    unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
    // combine the four bytes (two words) into a long integer
    // this is NTP time (seconds since Jan 1 1900):
    unsigned long secsSince1900 = highWord << 16 | lowWord;
    Serial.print("Seconds since Jan 1 1900 = ");
    Serial.println(secsSince1900);

    // now convert NTP time into everyday time:
    Serial.print("Unix time = ");
    // Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
    const unsigned long seventyYears = 2208988800UL;
    // subtract seventy years:
    unsigned long epoch = secsSince1900 - seventyYears;
    // print Unix time:
    Serial.println(epoch);

    // print the hour, minute and second:
    Serial.print("The UTC time is ");       // UTC is the time at Greenwich Meridian (GMT)
    Serial.print((epoch  % 86400L) / 3600); // print the hour (86400 equals secs per day)
    Serial.print(':');
    if (((epoch % 3600) / 60) < 10) {
      // In the first 10 minutes of each hour, we'll want a leading '0'
      Serial.print('0');
    }
    Serial.print((epoch  % 3600) / 60); // print the minute (3600 equals secs per minute)
    Serial.print(':');
    if ((epoch % 60) < 10) {
      // In the first 10 seconds of each minute, we'll want a leading '0'
      Serial.print('0');
    }
    Serial.println(epoch % 60); // print the second
  }
  // wait ten seconds before asking for the time again
  delay(10000);
}

// send an NTP request to the time server at the given address
void sendNTPpacket(IPAddress& address) {
  Serial.println("sending NTP packet...");
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  // Initialize values needed to form NTP request
  // (see URL above for details on the packets)
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12]  = 49;
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;

  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:
  udp.beginPacket(address, 123); //NTP requests are to port 123
  udp.write(packetBuffer, NTP_PACKET_SIZE);
  udp.endPacket();
}

I suspect you also need to specify your DNS server (usually the same as your gateway, or use 8.8.8.8 or 8.8.4.4 for the google public DNS servers)

@Majenko  THANK YOU!!! THANK YOU!!! THANK YOU!!! THANK YOU!!!                 That did the trick!  I added the gateway as dns1 and used 8.8.8.8 as dns2   Do you want to post your comment as an answer?  I'll accept it for sure, If not, should I add [SOLVED] to my question or answer my own question?

As well as specifying your IP address and gateway you also have to provide DNS server addresses. These are normally provided by DHCP, and the ESP8266 doesn't assume that it's the same as your gateway address when using a static IP address.
Normally you would use your router's IP address as your DNS server address, but you can also use the Google public DNS servers on 8.8.8.8 and 8.8.4.4.
The full format of the config function is:
  WiFi.config(staticIP, gateway, subnet, dns);

where dns is, like the other parameters, an IPAddress.

If you use Arduino IDE with <ESP8266WiFi.h> there is a different order for the arguments in the config-statement See the comment in the source code: //ESP argument order is: ip, gateway, subnet, dns1
//Arduino arg order is: ip, dns, gateway, subnet.
So after lots of trouble i changed my config in WiFi.config(STATICIP, DNS1, GATEWAY, SUBNET) and everything works smooth now. The comment means that if you use ESP-IDE (?) the argument order is: ip, gateway, subnet, dns1. When you use Aduino IDE (for ESP8266) the argument order is: ip, dns, gateway, subnet._

ESP-IDE? ESP WiFi library! the esp8266 WiFi library has the order of config parameters different than all other WiFi libraries and Ethernet libraries. but the esp8266 WiFi library's config function can detect the parameters and works with the common ordering too


text:
Printing vairable with U8GLib
I have this code that takes temperature and humidity values from a DHT11 sensor and number of faces from an external python code and prints them on an OLED screen but instead of values of variables it keeps printing 0, how can I solve it? (Sorry some parts are not in English but just consider them as random variable names.)
//dht11 kodu için ayarlamalar
#include <dht.h>
dht DHT;
#define DHT11_PIN 7

//ekran için ayarlamalar
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0);
char bufferX [20];
char bufferY [20];
char bufferZ [20];

//fan kodu için ayarlamalar
int mot1 = 8;
int mot2 = 9;
int en1 = 10;
int dir = 6;
bool state = true;
int nob = A0;
int val = 0;
int fan_hizi = 0;
String faces_str;
int faces;
float sicaklik;
float nem;

void draw(void)
{
  u8g.setFont(u8g_font_unifont);
  u8g.drawStr( 0, 15, bufferX);
  u8g.drawStr( 0, 30, bufferX);
  u8g.drawStr( 0, 45, bufferY);
  u8g.drawStr( 0, 60, bufferZ);
}

void setup() {
  Serial.begin(9600); //iletişim ve dht11 verisi

  // pin ayarları
  pinMode(mot1,OUTPUT);
  pinMode(mot2,OUTPUT);
  pinMode(en1,OUTPUT);
  pinMode(dir,INPUT_PULLUP);
}

void loop() {
  //dht11 kodu
  sicaklik = DHT.temperature;
  nem = DHT.humidity;
  delay(1000);

  //iletişim kodu
  if(Serial.available() > 0) {
    faces_str = Serial.readString();
    faces = faces_str.toInt();
  }

  Serial.print(faces);

  //sınırlar
  if(faces == 0 && sicaklik < 25 && nem < 65) {
    fan_hizi = 50;
    digitalWrite(13, HIGH);
    digitalWrite(12, LOW);
  }
  if(faces >= 1 || sicaklik >= 25 || nem >= 65) {
    fan_hizi = 250;
    digitalWrite(13, LOW);
    digitalWrite(12, HIGH);
  }

  //ekran
  sprintf(bufferX, "Yuzler: %d", faces);
  sprintf(bufferY, "Sicaklik: %d", sicaklik);
  sprintf(bufferZ, "Nem: %d", nem);
   u8g.firstPage();
  do {
  draw();
    }
  while ( u8g.nextPage() );
  delay(10);

  //fan kodu
  analogWrite(en1, fan_hizi);
  digitalWrite(mot1, HIGH);
  digitalWrite(mot2, LOW);
  delay(1000);
  digitalWrite(mot1, LOW);
  }

maybe it is printing a 0 because it is receiving a 0 ... do some debugging

I do not understand, how you initialize the DHT sensor object.
(I wonder why this compiles at all.)
Your way:
//dht11 kodu için ayarlamalar
#include <dht.h>
dht DHT;
#define DHT11_PIN 7

I would use:
//dht11 kodu için ayarlamalar
#include <DHT.h>
#define DHT11_PIN 7

DHT dht( DHT11_PIN, DHT11 );

Don't forget to start the DHT object with:
void setup() {
  // ... code removed for brevity
  dht.begin();
}

Now use the dht object instad of the DHT class.
sicaklik = dht.readTemperature();
nem = dht.readHumidity();

You did not specify what libraries you have used. But I tried all DHT libs I could find and none of them compiled with your code without errors.
The following code compiles on my IDE for an arduino UNO having olivers ug8lib and adafruits DHT sensor library installed. BTW: You even did not mention the Arduino/ESP you used. So I guess it is an UNO.
//dht11 kodu için ayarlamalar
#include "DHT.h"
#define DHT11_PIN 7
DHT dht( DHT11_PIN, DHT11 );

//ekran için ayarlamalar
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0);
char bufferX [20];
char bufferY [20];
char bufferZ [20];

//fan kodu için ayarlamalar
int mot1 = 8;
int m ot2 = 9;
int en1 = 10;
int dir = 6;
bool state = true;
int nob = A0;
int val = 0;
int fan_hizi = 0;
String faces_str;
int faces;
float sicaklik;
float nem;

void draw(void)
{
  u8g.setFont(u8g_font_unifont);
  u8g.drawStr( 0, 15, bufferX);
  u8g.drawStr( 0, 30, bufferX);
  u8g.drawStr( 0, 45, bufferY);
  u8g.drawStr( 0, 60, bufferZ);
}

void setup()
{
  Serial.begin(9600); //iletişim ve dht11 verisi

  // pin ayarları
  pinMode(mot1,OUTPUT);
  pinMode(mot2,OUTPUT);
  pinMode(en1,OUTPUT);
  pinMode(dir,INPUT_PULLUP);
}

void loop()
{
  //dht11 kodu
  sicaklik = dht.readTemperature();
  nem = dht.readHumidity();
  delay(1000);

  //iletişim kodu
  if(Serial.available() > 0)
  {
    faces_str = Serial.readString();
    faces = faces_str.toInt();
  }

  Serial.print(faces);

  //sınırlar
  if(faces == 0 && sicaklik < 25 && nem < 65)
  {
    fan_hizi = 50;
    digitalWrite(13, HIGH);
    digitalWrite(12, LOW);
  }

  if(faces >= 1 || sicaklik >= 25 || nem >= 65)
  {
    fan_hizi = 250;
    digitalWrite(13, LOW);
    digitalWrite(12, HIGH);
  }

  //ekran
  sprintf(bufferX, "Yuzler: %d", faces);
  sprintf(bufferY, "Sicaklik: %d", sicaklik);
  sprintf(bufferZ, "Nem: %d", nem);
  u8g.firstPage();

  do
  {
    draw();
  }  while ( u8g.nextPage() );

  delay(10);

  //fan kodu
  analogWrite(en1, fan_hizi);
  digitalWrite(mot1, HIGH);
  digitalWrite(mot2, LOW);
  delay(1000);
  digitalWrite(mot1, LOW);
}

I do not have the time to assemble the hardware to try it.
So I can say it compiles, but I can not say it works.
EDIT:
Now I found adidax "DHT11 lib". your code compiles with this library. But you forgott to read the values from the sensor, before you read them from the variables.
The following line is missing:
void loop() {
  //dht11 kodu
  DHT.read( DHT11_PIN ); // <-- this line is missing
  sicaklik = DHT.temperature;
  nem = DHT.humidity;
...

thank you for your answer. i'm pretty new in arduino. yes, i used a uno board. and about dht11, i used a code i found online. i don't know how exactly it works.


text:
Connecting MPU6050 to Arduino Due but using Jeff Rowbergs Library
I am working on a personal project in which I need to collect accurate data from the MPU6050 using an Arduino Due.
I can interface and read data from the MPU using the SLC and SDA pins and the "Adafruit Library" or the "MPU6050_Light" library. However I have been told that the Jeff Rowberg library combines both accelerometer data and gyroscope data to get a more accurate measurement of roll, yaw, and pitch. Every time I've tried using the library I get the error below:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Due (Programming Port)"
...
exit status 1
Is there anything I can do to get this to work on the Due's processor (which I know has a different architecture). If not what can I do to get accurate reading on the Due. I should note that the code works perfectly fine on the Uno.

Turn on verbose mode and see if anything more useful shows in the listing.


text:
Library for working with a 4-digit 7-segment indicator SH5461AS
Good day. Tell me an excellent library for working with a 4-digit 7-segment indicator.
I am currently using #include <fDigitsSegtPin.h>
But it does not allow you to display letters, does not allow you to put dots in the right place.
I think it is not flexible.
I want it to be easy enough to control the indicator and have sufficient freedom to choose segments (numbers, letters, dots, dashes). I tend to use the library: "SevenSeg library".
Tell me a really good option for my goal, and so that, as always, this library does not slow down all the code
I am using an indicator of the form:

This one  tm1637 sounds good. I was thinking to use it next time.
Edit 1:
Lately posted image suggests that it is without a separate display controller chip, then this library should work.
Edit 2:
This library specific to the SH5461AS display: Library
Include these three libraries:
#include "Segment.h"
#include "Digit.h"
#include "Display.h"

Print needs to be in the loop:
void loop() {
  d.print("1.234"); // Must be looped!
}

For disabling decimal points:
#define DISABLE_DP

The library's Github has very good documentation too

Oh yes, but it doesn't suit me, I forgot to clarify, I have an indicator like the one in the picture in the post above

that requires a display with TM1637 IC

@Антон I put that in the answer because I can't initiate comments. Do we have any markings on it? Looks like 12-pin 0.56", like this

Yes, exactly like that

I have SH5461AS

Thank you, @Антон, I updated the answer.


text:
Send data from one NodeMCU to another NodeMCU using Serial Communication
i am using NodeMCU (ESP8266) to communicate with another NodeMCU (ESP8266) using Serial Communication. Because i am using ESP-NOW to communicate and ESP-NOW and WiFi can not work together very well so trying with this serial communication option.
Here is how i connected the pins:
   Slave ->   Master
    D1    ->   D2
    D2    ->   D1
    GND   ->   GND

Here is how my sketch looks like:
Sender.ino
#include <Wire.h>

void setup() {
  Serial.begin(115200);
  Wire.begin(D1, D2); /* join i2c bus with SDA=D1 and SCL=D2 of NodeMCU */
}

void loop() {
  // put your main code here, to run repeatedly:
   Wire.beginTransmission(5); /* begin with device address 8 */
   Wire.write("Hello ESP 2");  /* sends hello string */
   Wire.endTransmission();    /* stop transmitting */

   Wire.requestFrom(5, 4); /* request & read data of size 13 from slave */
   while(Wire.available()){
      char c = Wire.read();
    Serial.print(c);
   }
   Serial.println();
   delay(1000);
}

Receiver.ino
#include <Wire.h>

void setup() {
 Wire.begin(5);
 Wire.onReceive(receiveEvent); /* register receive event */
 Serial.begin(115200);           /* start serial for debug */
}

void loop() {
 delay(100);
}

// function that executes whenever data is received from master
void receiveEvent(int howMany) {
 while (0 <Wire.available()) {
    char c = Wire.read();      /* receive byte as a character */
    Serial.print(c);           /* print the character */
  }
 Serial.println();             /* to newline */
}

But the communication is not working at all, not sure where i am wrong. It can code wise or may be via connection wise or it might be possible that NodeMCU to NodeMCU connection is not possible at all!
Thank you!

Your code does not reflect your hardware setup. I2C (Wire) communication over SDA/SCL pins is not the same as serial communication over crossed RX/TX pins. First you should decide what you really want. Serial communication or I2C. Then search the internet for examples. As you already use Serial for debugging (SerialMonitor?), you might want to use I2C to connect the two ESPs together. But that's not that easy, I2C uses a special electrical trasmission mode. You can not simply connect the  pin pairs crossed to each other. You also must not use the same address for both devices.

You also used Wire.begin(D2,D3) for Sender and  Wire.begin(5) for Receiver. I suspect that's wrong.

@Juraj actually i have send send data to my MQTT server connected in my LAN network. Which need wifi access and with ESP-NOW i can not do both.

@Peter can you suggest how can i fix this?

esp8266 Wire library doesn't work as slave

@Juraj Ohk so i want to send data from one nodemcu to another, with wired connection how can i do that! Any suggestions?

use only one esp8266 if they are so close to each other

@Juraj The problem seems to be, that the OP wants to use ESP-Now, which from the description sounds like a different 2.4GHz protocol by espressif, that also uses the Wifi hardware. So the first NodeMCU cannot connect to the Wifi network, since its already occupied by the ESP-Now protocol.

@chrisl, thank you. now I understand. the solution is to use only WiFi

As already stated, your code uses the I2C interface (via the Wire library) and not the Serial interface (which is an Arduino term for UART). They work fundamentally different.
As you only communicate between 2 devices, which you both can program yourself. I would ditch the I2C interface. It doesn't give you any advantage here, but some disadvantages (for example, that you can't have real bidirectional communication, as the slave cannot do anything by its own, only, if the master asks for it).
Instead you should use a Serial (UART) interface. As the NodeMCU only has 1 full hardware Serial interface, which you already use for debugging, you could use the ESPSoftwareSerial library to create an extra Serial interface via software. It has limitations (in how many interfaces can listen at a time and how fast the communication can go), but most likely this will solve your problem. Also Serial is easier for beginners, than I2C.

So can you please suggest what is much better to process faster and easy to do communication two way?

Also is there any example you can suggest with code and wire diagram for nodemcu to nodemcu so i can have better understanding


text:
Using lambdas as callback functions
Using the Ticker library for the ESP32, how can I use a lambda as an argument to the attach method?
tickerSystemManager.attach(1000, [&](){
  systemManager->sync();
});

Attempting to use the above, I get the following error:
Matrx.cpp:11:4: error: no matching function for call to 'Ticker::attach(int, Matrx::setup()::<lambda()>)'
...
Ticker.h:40:8: note: candidate: void Ticker::attach(float, Ticker::callback_t)

How can I capp a lambda into this method?

Lambda expressions that take have no captures generate some implementation type that is implicitly convertible to a basic pointer to function type.  Lambda expressions that have a capture group don't qualify for that and are generally speaking not going to be compatible, because in practice what the compiler generates is a class whose members represent the captures, which makes the pointer into a pointer to class member function and therefore incompatible with regular pointer to function.

So what can I do to call the sync method of my object? It seems as if every attempt to do so give me some error or another.

If systemManager is a global, just remove the & from the capture.

As @timemage explains in a comment, you cannot pass a capturing lambda
to a function that expects a plain pointer to function. There is,
however, a way out of this: the Ticker class provides an overload of
the attach() method that allows you to provide a parameter of any type
to tour callback:
template<typename TArg>
void attach(float seconds, void (*callback)(TArg), TArg arg)

You can use this version of attach() and provide it both

a non-capturing lambda that gets a pointer to systemManager
that pointer as a third argument.

Edit: I did a few tests, and it seems my compiler cannot properly
perform template argument deduction in this case, but the approach works
if you explicitly specialize the template. Namely:
tickerSystemManager.attach<typeof systemManager>(
    1000,
    [](typeof systemManager p){ p->sync(); },
    systemManager);

You've managed to make this on topic.  Might as well go a step further and show the user-data-capable overload in the context of a lambda expression.

@timemage: Good  suggestion. I updated the answer.

I really appreciate the answer, this compiled and seems to run as expected! I am still trying to learn Cpp while setting up an ESP project and you are definitely giving me more to look into!


text:
What's wrong with this code..?
I want to make an 8*8 led matrix. I found this code on the web:

    int latchPin = 12;  //Pin connected to ST_CP of 1st 74595
    int clockPin = 13;  //Pin connected to SH_CP of 1st 74595
    int dataPin = 11;   //Pin connected to DS of 1st 74595

    int latchPin2 = 6;  //Pin connected to ST_CP of 2nd 74595
    int clockPin2 = 7;  //Pin connected to SH_CP of 2nd 74595
    int dataPin2 = 5;   //Pin connected to DS of 2nd 74595

    void setup() {
      //set pins to output so you can control the shift register
      pinMode(latchPin, OUTPUT);
      pinMode(clockPin, OUTPUT);
      pinMode(dataPin, OUTPUT);

      pinMode(latchPin2, OUTPUT);
      pinMode(clockPin2, OUTPUT);
      pinMode(dataPin2, OUTPUT);
    }

    void loop() {
      /************** Send HIGH to first Anode pin (16th pin) and LOW to all
      other anode pins (15, 11, 3, 10, 5, 6, 13) of LED matrix *************/

      // take the latchPin low so the LEDs don't change while you're sending in bits:
      digitalWrite(latchPin, LOW);
      //Send 0 0 0 0 0 0 0 1 (1) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595
      shiftOut(dataPin, clockPin, MSBFIRST, 1);
      // shift out the bits:
      digitalWrite(latchPin, HIGH);

      /**************** Send LOW to the first cathode pin (4th pin) and HIGH to all
        other cathode pins (7, 2, 8, 12, 1, 14 and 9) of LED matrix *****************/

      // take the latchPin low so the LEDs don't change while you're sending in bits:
      digitalWrite(latchPin2, LOW);
      // Send 1 1 1 1 1 1 1 0 (254) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595
      shiftOut(dataPin2, clockPin2, MSBFIRST, 254);
      // shift out the bits:
      digitalWrite(latchPin2, HIGH);
    }

I expected this code to turn on the first LED, but when I uploaded this code nothing lights up. I checked my rows and colum connections.
Also, I want to ask if a 74hc595 can output sink current?

what's a first LED? ... what is it connected to?

In reverse order, yes about 20ma or so sink and source. If you look on the data sheet it will give you the answer. As far as the first part simple connect this to that and that should fix it. That is about as helpful as the schematic, not a frizzy drawing, you included. You have both hardware and software and knowledge of both is normally required to solve the problem. Show all power and ground connections on the schematic.

Have you connected the 5V from the schematic to an external power supply? If yes, did you connect the GND of the power supply to the GND shown in the schematic too?

Did saprate power supply needed for this...

I can't add comment to your question so I post as an answer even though this is not much an answer. This is just a hint to solve your problem.
8x8 led matrix and 595s are pretty low-level stuff, so I assume you have some knowledge about electronics and programming in general.
I think your wiring is OK but I also think you misunderstand how 595 works.
Here is the flow taken from a library (ESP32) for 64x64 RBG LED panel using bunch of 595s:
uint8_t data[8]; // data for one row

digitalWrite(OE_PIN, HIGH); // disable output, 595 outputs go into high impedance state

for (int i=0; i<8; i++)
  shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, data[i]);  // dump data out

digitalWrite(LATCH_PIN, LOW);  // pulse 1 clock
delayMicroseconds(1); // note 2*
digitalWrite(LATCH_PIN, HIGH); // latch is active high

digitalWrite(OE_PIN, LOW); // Enable output

I think now you know how to fix your code.
Note 1: I find those names SER, SRCLK, RCLK (on TI's datasheet) are confusing. I prefer the names SERIAL DATA INPUT, SHIFT CLOCK, LATCH CLOCK (on ONSEMI MC74HC595 datasheet) or better DATA, CLK, LATCH, OE, RESET.
Note 2: Check 74HC595 datasheet to see clock pulse width limit and speed limit. And if you are using UNO or MEGA (@16MHz), you are good without stretching the clock (data clock and latch clock). If you use higher speed MCU, e.g: ESP32@240MHz or STM32@72MHz, you have to consider clock stretching there and also inside shiftOut() function.
To improve your circuit, you should wire both OE of 595s to a Digital pin. You can also connect both latch pin into one digital pin. Every time you latch, botch 595 latch, and every time you enable output, both enable output.
So with your configuration, just shiftOut data normally for the 595 on the left and invert data for the 595 on the right, like this
#define DATA_COL_PIN 11
#define DATA_ROW_PIN 5
#define CLOCK_COL_PIN 13
#define CLOCK_ROW_PIN 7

#define OE_PIN 4 //use digital pin 4 to enable output on both 595s
#define LATCH_PIN 6 // or 12, but you must connect both latch inputs of both 595s together

uint8_t col = 0b00000001; // for the left 595
uint8_t row = 0b00000001; // for the right 595

digitalWrite(OE_PIN, HIGH);
shiftOut(DATA_COL_PIN, CLOCK_COL_PIN, MSBFIRST, col);
shiftOut(DATA_ROW_PIN, CLOCK_ROW_PIN, MSBFIRST, ~row); // ~row = 0b11111110 = invert_bits(row)
digitalWrite(LATCH_PIN, LOW);
digitalWrite(LATCH_PIN, HIGH);
digitalWrite(OE_PIN, LOW);

The code above is just for you to understand how it works. Normally, they would work on a buffer such as
uint8_t row[8]; // each byte is one row

And they do row scanning, turn one row ON at a time and just flip each column ON and OFF following the byte data of that row.
I stop here as this is going off-topic. You just ask what is wrong with your code right?
BTW, 595 can sink/source 35mA on each pin (70mA in total). So if you want to light up one row at a time with your setup, you should choose each current limiter carefully so that not to exceed 70mA in total.

70mA / 8xLED = 8.75mA for each LED (assume red LED)
(5v - 1v7) / 8.75mA = 377R

It's likely the resistors should be at least 377 ohm or 470 ohm for safety.

Sry i didn't get it... Are u trying to say instead of putting 8bit value in decimal... I have to make array for it...

I'm probably ahead of myself on how people do write a graphic driver for these LED panel by answering like that. It's doesn't matter if a number is written in binary or decimal or hexadecimal. I just use binary because it's straight forward reflecting each bit as a single LED on the matrix. The array of eight 8-bit number has 8x 8-bit = 64-bit, which represents all 64 LEDs on your 8x8 led panel. So you have 2 functions, one to read this array and spit out data to 595s, the other function to modify this array so you have visual effect or animation or changing a static image after some time.


text:
I am trying to control a continuous servo (MG996R) with an RF remote but it's not working
I am trying to control a continuous servo (MG996R) with an RF remote, but it's not working; the servo just spins in one direction.
I am new to Arduino so I don't really know if the code is correct.
This is my code:
#include <Servo.h>

Servo servothumb;
Servo servoindex;
Servo servomiddle;
Servo servoring;
Servo servopinky;

void setup() {
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  pinMode(4,INPUT);
  pinMode(5,INPUT);
  Serial.begin(9600); // setting baud rate
  Serial.println(" Data 4 Ch Remote Control");
  servothumb.attach(9);
  servoindex.attach(10);
  servopinky.attach(11);
  servoring.attach(12);
  servomiddle.attach(13);
}

void loop() {
  if (digitalRead(2) == HIGH) { // Button B pressed
    Serial.println("B");
    servothumb.write(90);
    servoindex.write(90);
    servopinky.write(90);
    servoring.write(90);
    servomiddle.write(90);
  } else {
    servothumb.write(90);
    servoindex.write(90);
    servopinky.write(90);
    servoring.write(90);
    servomiddle.write(90);
  }

  if (digitalRead(3) == HIGH) { // Button D pressed
    Serial.println("D");
  }
  if (digitalRead(4) == HIGH) { // Button A pressed
    Serial.println("A");
    servothumb.write(0);
    servoindex.write(0);
    servopinky.write(0);
    servoring.write(0);
    servomiddle.write(0);
  } else {
    servothumb.write(90);
    servoindex.write(90);
    servopinky.write(90);
    servoring.write(90);
    servomiddle.write(90);
  }
  if (digitalRead(5)== HIGH) { // Button C pressed
    Serial.println("C");
    servothumb.write(180);
    servoindex.write(180);
    servopinky.write(180);
    servoring.write(180);
    servomiddle.write(180);
  } else {
    servothumb.write(90);
    servoindex.write(90);
    servopinky.write(90);
    servoring.write(90);
    servomiddle.write(90);
  }
}

the servo doesn't stop or go the other way if i use the rf remote it just spins clockwise

is it the servo or the RF remote? ... you really need to do some debugging by using the simplest code to test only one thing

Your code does not control a servo, but 5 of them. In the loop, the if statements do not exclude each other. That means either the if or the else branch is executed for each if block. That means you switch the speed values for the servos very fast, again and again, if one or more buttons are pressed.  If no button is pressed, then only the three else branches are executed and your servos stay at value 90. How this value is interpreted depends on the servo; some stop, some need another value to stop, some do not stop at all. BTW: The  mg996r is not a continous servo, did you modify it?

how do you add a stop statement for a continuous servo?
i didn't modify it I bought one online it was already continuous

If you bought a modified version, ask the vendor, how to stop it. This is not specified for the original. I do not know how it is modified. How could I? ;-) Modification is normally achieved with just removing the mechanical connection of the motor and the potentiometer that senses the position of the motor. It depends on the resistance of the potentionmeter that's now fix. You could try to write a program that iterates over all values from 0 to 180, sends this value  to the servo and also prints it to the Serial monitor. Then, with luck, you'll see the motor stop, and the monitored value.

If the motor does not stop, you could open the servo and try to turn the poti screw/wheel, perhaps it is in a unfortunate position. What I told you in the last comment can be achieved with a modified Servotester. Here is a link; a starting point. https://create.arduino.cc/projecthub/bbil40/automatic-servo-tester-with-arduino-nano-c694e0 . I assume that's really hard for you, but as you have the hardware, I can only advice you what to do.

If you had not already bought the servos, I would advice you to use Geared DC motors and H-BridgeDrivers. There are reliably stoppable and can change direction and speed.

What I still not understand: Where comes the RF remote control into play? I'm just curious why you mentioned it ;-).


text:
Why NVIC_EnableIRQ handler function only run once?
I have a code that spit out random number when the ISR register is ready:
#define TRNG_KEY  0x524E47
uint8_t lut[10] = {0xF6, 0x12, 0xAE, 0xEC, 0xD8, 0x7C, 0x7E, 0xE0, 0xFE, 0xFC};
uint32_t msk = 0x1FE;

void setup()
{
  Serial.begin(9600);
  PIOC->PIO_PER = msk;
  PIOC->PIO_OER = msk;
  PIOC->PIO_OWDR = ~msk;

  PMC->PMC_PCER1 = PMC_PCER1_PID41;
  TRNG->TRNG_CR = TRNG_CR_ENABLE | TRNG_CR_KEY(TRNG_KEY);
  TRNG->TRNG_IER = 1 << 0;
}

void loop()
{
  if (TRNG->TRNG_ISR == 1) {
  PIOC->PIO_ODSR = lut[REG_TRNG_ODATA % 10];
  }
  delay(500);
}

The code above works. However, when I tried to switch to internal interrupt:
#define TRNG_KEY  0x524E47
uint8_t lut[10] = {0xF6, 0x12, 0xAE, 0xEC, 0xD8, 0x7C, 0x7E, 0xE0, 0xFE, 0xFC};
uint32_t msk = 0x1FE;

void setup()
{
  Serial.begin(9600);
  PIOC->PIO_PER = msk;
  PIOC->PIO_OER = msk;
  PIOC->PIO_OWDR = ~msk;

  PMC->PMC_PCER1 = PMC_PCER1_PID41;
  TRNG->TRNG_CR = TRNG_CR_ENABLE | TRNG_CR_KEY(TRNG_KEY);
  TRNG->TRNG_IER = 1 << 0;

  NVIC_EnableIRQ(TRNG_IRQn);
}

void loop()
{

}

void TRNG_Handler(void) {
  PIOC->PIO_ODSR = lut[REG_TRNG_ODATA % 10];
}

The code only spit out one random number and then freezes, indicating TRNG_Handler(void) was only executed once. I cannot figure out why.
Thanks in Advance !

I presume delay will internally wait on some millisecond variable to be incremented, and that only happens in some timer ISR, that you may be blocking by delaying in the first place. You might want to setup a hardware timer in the needed interval or use a flag inside loop to toggle a boolean "it's okay to update" value every 500ms, that is then reset in the TRNG_Handler.

Hm actually I may be partially wrong. The datasheet says This interrupt is set when a new random value is available and is cleared when the status register is read(TRNG_SR register). The SR is probably a typo and means ISR. Can you try and read the status register the same as in https://github.com/davecheney/trng/blob/master/arduino-due-trng/arduino-due-trng.ino#L16 ?

That delay() was a typo, sorry. It's not in my actual code.

Two things:

Never use delay() inside an ISR. On some systems it may work, but on most it will just block. It's bad practice to have your ISRs run for more time that absolutely needed anyway.
You need to read the status register for the TRNG to clear the interrupt flag. You're doing that in your first code sample with if (TRNG->TRNG_ISR == 1) {.

Isn't if (TRNG->TRNG_ISR = 1) {. an assignment?  TRNG->TRNG_ISR is not read -   1 is assigned to it. I think it is intended to be a comparisson. That's an error in the first example. But the condition was always true, and the generator is fast enough to gnerate a number every 500ms  it seems ;-).

@PeterPaulKiefer You might be right...  The end result would probably be reading the register before writing the changed content back.


text:
Is this circuit connected right?
I want to create something similar to an article I read a few months ago about the effects of Dopamine. Dopamine is known as the feel-good neurotransmitter; the brain releases it when we eat food that we crave, contributing to pleasure and satisfaction as part of the reward system. I want to use this reward method for breaking habits and creating new ones. I saw someone on youtube make a Dopamine box, very similar to what I was thinking (I left it down below), but I think it had a few design flaws.
So how it works, the lights will be dimmed (so it’s not annoying) and default red, the screen in the center will read the list of activities you have set for yourself that you want to be completed. When you complete a task, you will flip a switch on the housing side; this will toggle some lights to go from red to green and give you the reward system. Along with the lights turning green, the box will play a sound, similar to when you win a game or get a kill, again triggering the dopamine release.
The LCD will display a message, something like "keep going"  or "Don't quit."
The LED is for the green and red lights mentioned above, and the piezo is for a buzzer to play a sound to congratulate you for finishing a task.
Down below, I left a circuit I made in TinkerCad. I am very new to this, and I would like if someone could look at my connections and tell me if I have connected them correctly.
TinkerCad Link- https://www.tinkercad.com/things/9EYfcPv1XsX

Please provide a normal link to your tinkercad circuit, not an embed link. Also please put an image of the circuit directly in your question. That way the question will stay valid, even when the link becomes invalid

Have you tested the circuit in tinkercad? Does it work? If everything works as intended, then the circuit should be correct

if the circuit works, then it is probably connected correctly

Ah, I see 1 problem: Your code doesn't use the Neopixel ring, but why did you connect its data pin to D2 together with the LCD. The data pin of the Neopixel ring needs an own digital output pin.

@chrisl sorry, I added the link in the post, and I left it down below in this reply. Thanks again!
link- https://www.tinkercad.com/things/9EYfcPv1XsX

@chrisl I am very new with TinkerCad; how do I test it?