text:
How to create and edit fonts for the Adafruit GFX library?
I noticed that the TomThumb.h font included in the Adafruit GFX library has characters that have different widths, which is a problem for me because I'm doing text processing that requires characters to have the same dimensions (width and height).
I also noticed that the TomThumb.h font misses some characters (such as '). I need a way to create/edit fonts for the Adafruit GFX (where I'm using the Adafruit_ST7735 on a 1.8" TFT display). I've looked around the internet but I couldn't find anything decent.

The library comes with a number of fonts. The ones named *Mono* are monospaced, which means that all the characters are the same size.

@Majenko Interesting. I thought that by default all characters are required to take equal dimensions.

Nope. Each character in the font ("glyph") specifies the dimensions and offset of the character, and also the "advance" - how far to move the cursor after printing the character.

@Majenko I'm surprised there isn't an easy way to create fonts for the Adafruit GFX. It's a relatively supported and used library.

I have various utilities for DisplayCore, but DisplayCore doesn't run on an Arduino.

@Majenko My main goal here is to display text of a book. Is there any way I can do that without using a monospaced font? Because I'm preprocessing the text on a phone and I'm doing the whole thing by counting how many characters a line can fit and so on so when a word doesn't fit, it goes to the next line... you get the idea. Is it possible to make the whole when-word-doesn't-fit-goes-on-next-line and with page switching functionality using a non-monospaced font? I suppose I'll have to know how many pixels each character takes so I do calculations...

Split your text into words and use the getTextBounds function to find out how wide it is. Add the width of a space. If it fits on the current line then print it. Otherwise start a new line and print it. You'll have to maintain your own cursor coordinates of course.

@Majenko Sound great! What do you mean about the cursor coordinates?

So that you know where to print your next word.

@Majenko Oh got it. The getTextBounds() requires the starting x and y of the word. Ahh, it's gonna be rather painful but I have no other option. Thank you for helping me out! :-)

@Majenko About the page functionality, do you have an idea of how it can be done? I'm reading the book content from an SD. The issue I have with the paging functionality is that if I'm on page 82, I have to process all pages until 82 and it's starting to lag as I get further into the book. I'm ready to drop the pages as a whole but I need some way to return the person to the place in the book from where he/she left, so he/she can continue reading. What would be the best way to go about this?

@Majenko After researching a bit, I think I can do it with fseek and remembering the last character of the last word... Thank you so much for helping me and suggesting the method above. You're the best!

@Majenko One thing that's unclear is, how would I go about going to previous pages? If I'm on some page and I've processed it and displayed it, how do I go to the previous page not knowing from which character to seek and so on...?

That is a tough one to suggest a solution to. Maybe plain text isn't the best format to store the data in.

@Majenko Hmm, I'm converting PDF to text and sending that from a phone to the Arduino via BT and then I'm displaying the text on a 1.8" TFT display. What else could I store it as when my goal is to make something like an e-reader?

Maybe render the pages on the phone as bitmap images and display those on the screen instead?

@Majenko Good suggestion but the text might not be visible or readable because the TFT display is rather small (1.8") and is 128x160 pixels and I don't think the content of the PDF page would be visible :P

I'm not thinking pages as they are on a PDF, but pre-rendered in your own chosen font.

@Majenko Yes but the issue of characters of fonts having different widths persists. As far as understood, on the phone, I create a bitmap image 128x160 where I overlay the text with the chosen font but I'll still have to do the same text processing as if it was being processed on the Arduino as text. It gets really complicated so I think I'll process the txt on the Arduino with the method you suggested above with getTextBounds...

@Majenko The idea of doing it with bitmap images is good but comparing pros and cos with the on-the-go processing with getTextBounds(), the latter is better because it allows for dynamic font changing, is less complicated and less heavy (because text files are lighter than bitmap images of pages). And also uploading speeds would be much much faster. Tell me what you think :-)

I found an online editor that can parse Adafruit GFX font headers, modify, and export the result to create a new font header.  It works very well.  May be a bit late to help OP, but for anyone else looking...
It uses regexes to extract info from the header files, so it's pretty strict on following the layout of GFX font headers provided by Adafruit.
webpage: https://tchapi.github.io/Adafruit-GFX-Font-Customiser/
github: https://github.com/tchapi/Adafruit-GFX-Font-Customiser

That works nicely, once you figure it out.

I have used truetype2gfx - Converting fonts from TrueType to Adafruit GFX.
It can make various sizes to a complete standard font.

@ocrdu - did you visit the website and try out the "tool"? How did it work for you?

One possible solution you might already have: There’s a small utility called fontconvert that’s part of the Adafruit GFX library. The source code is installed by default together with the Adafruit GFX library in Arduino/libraries/Adafruit_GFX_Library/fontconvert You need Linux to compile it from the provided source code. It also compiles and runs on a Raspberry Pi.
It takes care of converting TrueType fonts (completely or partially) to Adafruit GFX format. There’s some documentation on compiling and using it in the fontconvert directory.

Thanks, I found it. Unfortunately, I don't have a Linux nor a Raspberry Pi. I could install a Linux VM. Isn't there an easier way? Like, some tool where you put the individual pixels for each character.

Well, there’s This. I don’t know how useful this is for you, but you could take a look at it.

Thanks, I'll take a look. I hope it'll do the job

I have used this website to generate various fonts, sizes, etc. with success.
http://oleddisplay.squix.ch/#/home


text:
Turn off Timer1 / Timer1 One-shot
A zero detector crossover sends a pulse to the Arduino, it must start counting x time and then a pulse is sent from the Arduino, once the timer reaches time x, it must stop counting and only start counting again when it receives the new pulse of the zero crossing detector, the idea is to do something like this:

What I don't know is how to keep the timer off all the time toff that appears in the image.

A zero detector crossover sends a pulse to the arduino... How does your code and wiring detect the zero cross-over now? Is the detector external and just sends a signal to Arduino? Wouldn't you just reset the timer any time you detected the cross-over to positive? Or doesn't the detector distinguish between a positive crossing and a negative one? Or are you really wanting to know how to do a cross-over detection for a sinusoidal signal?

@lurker what I get from the zero crossing detector is a train of pulses, which varies from 0 to 5v each time it passes through zero, but that's not the point, create an edge ISR when the signal varies, at that time it should start the counting, stop when it reaches the time x that I need and stay off until the next zero edge, in the examples that I have seen the timer restarts and continues counting, I need it to turn off or stop counting until the next zero crossing

Does this answer your question? Fan regulator control from Arduino

You can trick the timer into doing one-shot, by setting the counter to a value higher than TOP. See https://hackaday.com/2015/03/24/avr-hardware-timer-tricked-into-one-shot/

the way to turn off the Timer is to set the CS12, CS11 and CS10 prescale bits to 0, in this way the CLK signal is disconnected and the timer stops counting, when you want the timer to continue counting, they are set back to 1 the CS12, CS11 and CS10 bits according to the selected prescale.
byte savePrescale

savePrescale = TCCR1B & (0b111<<CS10);
...
TCCR1B &= ~(0b111<<CS10); // Stop Timer1 Clock
...
TCCR1B |= savePrescale;  // Restart Timer1 clock.
...

You can initiate a "One shot" timer at each zero-crossing.
The trick @Gerben mentioned in turn off Timer1 / Timer1 One-shot eventually links to code at https://github.com/bigjosh/TimerShot which does the one-shot functionality on Timer2 by idling the timer at TCNT2=0 with OCR2A=0, and using the TCNT2 space above 0 to operate an adjustable oneshot on OC2B.
This trick can be adapted to Timer1:
// The one shot pulses are output on Digital pin OC1B (Arduino Uno D10, Mega D12, Nano D3)
// Modified by Dave Forrest 2020-01-11 for Timer 1
// Based on Josh Levine's Nov 23, 2015 work at https://github.com/bigjosh/TimerShot/blob/master/TimerShot.ino

#define OSP_SET_WIDTH(cycles) (OCR1B = 0xffff-(cycles-1))

// Setup the one-shot pulse generator and initialize with a pulse width that is (cycles) clock counts long

void osp_setup(uint16_t cycles) {

  TCCR1B =  0;      // Halt counter by setting clock select bits to 0 (No clock source).
              // This keeps anything from happeneing while we get set up

  TCNT1 = 0x00;     // Start counting at bottom.
  OCR1A = 0;      // Set TOP to 0. This effectively keeps us from counting because the counter just keeps reseting back to 0.
          // We break out of this by manually setting the TCNT higher than 0, in which case it will count all the way up to MAX and then overflow back to 0 and get locked up again.
  OSP_SET_WIDTH(cycles);    // This also makes new OCR values get loaded from the buffer on every clock cycle.

  TCCR1A = 0b11<<COM1B0  | 0b11<<WGM10;  // OC1B=Set on Match, clear on BOTTOM. Mode 15 Fast PWM.
  TCCR1B = (0b11<<WGM12)| (0b001<<CS10); // Start counting now. WGM 15=0b1111  to select Fast PWM mode

  //DDRB |= _BV(2);     // Set pin to output (Note that OC1B = GPIO port PB2 = Arduino Uno Digital Pin 10)
  DDRB |= _BV(6);     // Set pin to output (Note that OC1B = GPIO port PB6 = Arduino Mega Digital Pin 12)
  //DDRD |= _BV(3);     // Set pin to output (Note that OC1B = GPIO port PD3 = Arduino Nano Digital Pin 3)
}

// Setup the one-shot pulse generator

void osp_setup() {
  osp_setup(1);
}

// Fire a one-shot pulse. Use the most recently set width.

#define OSP_FIRE() (TCNT1 = OCR1B - 1)

// Test there is currently a pulse still in progress

#define OSP_INPROGRESS() (TCNT1>0)

// Fire a one-shot pulse with the specified width.
// Order of operations in calculating m must avoid overflow of the uint16_t.
// TCNT2 starts one count lower than the match value becuase the chip will block any compare on the cycle after setting a TCNT.

#define OSP_SET_AND_FIRE(cycles) {uint16_t m=0xffff-(cycles-1); OCR1B=m;TCNT1 =m-1;}

void setup()
{
  osp_setup();

}

void loop()
{
  // Step though 0-11 cycle long pulses for demo purposes
  for (uint8_t o = 0; o < 101; o++) {
    OSP_SET_AND_FIRE(o);
    while (OSP_INPROGRESS());         // This just shows how you would wait if necessary - not necessary in this application.
    //_delay_us(1);      // Wait to let the audience clap
  }
}

This code produced pulses with a resolution of 62.5ns, which is on the edge of what my test equipment can measure.  Here's a 6.25us, 100 cycle pulse next to a 1 cycle pulse:

With Timer1's 16 bit range and the /1 prescaler you can do pulses from 62.5ns to 4us.  With the /1024 prescaler, (TCCR1B|=(0b101 <<CS10);) it can do 64us up to 4.194sec.  With /256 prescaler, (TCCR1B|=(0b100 <<CS10);) it can do 16us up to 1.05sec.
For a one shot triggered on a zero-crossing, you might try something like this with the above
void loop()
{
  ...
  int t1_us = 1000000UL/60 /8 ; // 1/8th of a 60Hz cycle

  if(needOneShot){  // Set needOneShot with an interrupt or sensor or something
    OSP_SET_AND_FIRE(t1_us/16);  // 16us ticks with the /256 prescaler
     needOneShot = false;
  }
  ...
}

source: Stack Exchange

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

sort: votes


text:
SPI Temperature sensor interface with Arduino Uno
I want to interface with an AD7314 Temperature Sensor. I want to only read the temperature value from the sensor and output the value on to 8 LEDs connected to the Arduino. But so far I have not been able to read from the sensor. The datasheet says that the temperature readings are in 10 bit 2's complement, so I plan to convert to 8 bit before putting it out on the LEDs. Here is my code so far.
I am new to SPI and clearly don't understand the temperature sensor's datasheet. Please can anyone elaborate or explain where I am going wrong?
Note: I have chosen pin A0 (PIN 23 of ATMEGA328P) as slave select and not pin 10
#include <SPI.h>

byte val;

void setup (void) {
  pinMode(0, OUTPUT); //LED 1
  pinMode(1, OUTPUT); //LED 2
  pinMode(5, OUTPUT); //LED 3
  pinMode(6, OUTPUT); //LED 4
  pinMode(7, OUTPUT); //LED 5
  pinMode(8, OUTPUT); //LED 6
  pinMode(9, OUTPUT); //LED 7
  pinMode(10, OUTPUT);//LED 8
  pinMode(11, OUTPUT); // MOSI
  pinMode(12, INPUT); //MISO
  pinMode(13, OUTPUT); //CLOCK PIN
  digitalWrite(A0, HIGH);  // ensure Slave select stays high
  SPI.begin ();
  Serial.begin(9600);
} // end of setup

void loop (void) {
  // enable Slave Select
  digitalWrite(A0, LOW); // enable communication with slave
  delay (0.425);// wait for conversion
  val = SPI.transfer(0x00);// read from sensor
  Serial.println(val); // display reading on serial monitor
  // disable Slave
  digitalWrite(A0, HIGH);
}

delay (0.425);// wait for conversion

You can't delay a fraction of a millisecond. You can use delayMicroseconds though:
delayMicroseconds(425);

However, you don't need to sleep at all.

The conversion clock for the part is internally generated so no
  external clock is required except when reading from and writing
  to the serial port. In normal mode, an internal clock oscillator
  runs the automatic conversion sequence. A conversion is initiated
  every 400 ms. At this time, the part wakes up and performs
  a temperature conversion. This temperature conversion typically
  takes 25 ms, at which time the part automatically shuts down.
  The result of the most recent temperature conversion is available
  in the serial output register at any time.

You have your chip select pin backwards:

To ensure that the serial port is reset properly
  after power-up, the CE must be at a logic low before the
  first serial port access. The serial clock is active only when CE is
  high. For correct data synchronization, it is important that the
  CE be low when the serial port is not being accessed

So it should start LOW, and be set HIGH before you read, and back to LOW afterwards.
You need to read 2 bytes, not one, then combine them in the right way to make a proper 8-bit value:
digitalWrite(A0, HIGH);
uint8_t b1 = SPI.transfer(0x00);
uint8_t b2 = SPI.transfer(0x00);
digitalWrite(A0, LOW);

int8_t = (b1 << 1) | (b2 >> 7);

The reason for that is that the first bit of the first byte is a "leading zero" so you need to discard it, then add the first bit of the second byte as the last bit of your value, discarding the remainder of the second byte, since you specified only an 8-bit resolution in your question.

Just for my clarification, i have 2 questions: 1) uint8_t SPI.transfer(0x00), does this statement mean that the value being read is an unsigned integer and not a byte why so ?  2) SPI.transfer(0x00), does the 0x00 mean that value being read or transferred is 0 (decimal) regardless ?

@user7187418 uint8_t is an 8 bit unsigned value. Better known as a byte. The 0x00 is the value being sent by SPI which happens (and is ignored) at the same time as receiving. It's how SPI works.

could i replace the 0x00 with an unsigned integer variable, lets say x1 or would that actually discard the value being read ?

You can replace it with whatever you like. It will make no difference. The ADC chip ignores it. With SPI you can only transmit and receive at the same time, so to receive you must send something, even if it's ignored.

If the output was to be changed from 8 bit to 6 bit out, would the bit shift change to (b1<<0) | (b2<<5) ?  (i am new to bit shifting and digital logic, if that helps)

No it would be just b1 >> 1

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


text:
How to call an interrupt when any one of the 12 defined digital inputs go high?
I'm using an Arduino Mega 2560 board. I need to sense 12 digital pins (pins 36-47) coming from another board continuously and display power when they are low.
When any of the 12 pins go HIGH, an interrupt must be created. In the ISR part, I'll be making one new digital pin (PIN 35) go HIGH (this is initialized as low in setup function).
To reset from interrupt, I need to press the "#" key in the keypad. This should make PIN 35 go low again and program should function normally again.
This is my code without using Interrupt.
#include "LiquidCrystal.h"
#include <Keypad.h>

// initialize the library by providing the nuber of pins to it
LiquidCrystal lcd(8,9,4,5,6,7);
 const byte ROWS = 4; // four rows
const byte COLS = 3; // three columns
char keys[ROWS][COLS] = {
 {'1','2','3'},
 {'4','5','6'},
 {'7','8','9'},
 {'*','0','#'}
};
byte rowPins[ROWS] = {22, 24, 26, 28}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {30, 32, 34};     //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
float fwd_voltage = 0.0,rev_voltage = 0.0;
float fpower,rpower;
int sensorValue=0;

void setup() {
  int i;
  for (i=36;i<48;i++) {
    pinMode(i,INPUT);
  }
  pinMode (35, OUTPUT);
  digitalWrite(35,LOW);
}

void reset () {
  while(1) {
    lcd.begin(16,2);
    lcd.setCursor(0,0);
    lcd.print("press # to reset");
    char key = keypad.getKey();
    if (key=='#') {
      digitalWrite(35, LOW);
      break;
    }
  }
}

void process(int pin, char* text) {
  if (digitalRead(pin) == HIGH && digitalRead(35)==LOW) {
    // Use HIGH instead of 1
    lcd.print(text);
    digitalWrite(35, HIGH);
    reset ();
  } else {
    int analog_value = analogRead(A0);//reading forward voltage
    int analog_valuer = analogRead(A1);//reading reverse voltage
    fwd_voltage = (analog_value * 5.0) / 1024.0;
    rev_voltage = (analog_valuer * 5.0) / 1024.0;
    fpower =  ((fwd_voltage)*(fwd_voltage)*10000);
    rpower = ((rev_voltage)*(rev_voltage)*10000);
    lcd.setCursor(0,1);
    lcd.print("REV= ");
    lcd.print(rpower);
    lcd.print("W");
    delay(500);
    lcd.setCursor(0, 0);
    lcd.print("FWD= ");
    lcd.print(fpower);
    lcd.print("W");
    delay(500);
  }
}

void loop() {
  lcd.begin(16,2);
  // set cursor position to start of first line on the LCD
  lcd.setCursor(0,0);
  process(36, "vswr");
  process(37, "thermal");
  process(38, "overdrive");
  process(39, "A1-B1 fault");
  process(40, "A1-B2 fault");
  process(41, "A1-B3 fault");
  process(42, "A1-B4 fault");
  process(43, "A2-B1 fault");
  process(44, "A2-B2 fault");
  process(45, "A2-B3 fault");
  process(46, "A2-B4 fault");
  process(47, "driver fault");
}

How do I modify the program to add an interrupt so that my board works faster and efficiently? BTW I'm new to programming so there might be some mistakes in the program and also I didn't write the program small and efficient.
The interrupt service routine should consist of this part of the above program:
lcd.print(text);
digitalWrite(35, HIGH);
reset ();

My interrupt should detect this part of the program.
if (digitalRead(pin) == HIGH && digitalRead(35)==LOW)

You are kind of unlucky. The ATmega2560 MCU has 32 pins capable of
generating interrupts (counting the INTn and PCINTn, not sure all of
them are routed to board headers), but none of the pins you have chosen
is interrupt-capable.
I suggest you combine your 12 signals, using external logic, into a
single interrupt signal. You would then, in the ISR, sort out which
individual signal triggered the interrupt. A pair of 74HC4075 chips
should be enough to OR together the 12 inputs.

i'll try that. What about PINCHANGEINTERRUPT library? can I use it to use my pin as interrupt pins?

@aparna: You could use pin change interrupts (PCINT) if you can rewire your project and route the 12 relevant signals to PCINT-capable pins. But beware that you get interrupted on both signal edges. If you combine the signals using external logic, a regular interrupt pin would be more convenient, as it allows you to choose either the falling or the rising edge.

Get rid of the 2 delay calls in your process() function. You are just needing to display the error text, so you don’t really need interrupt speed.
You have a 1s delay In total for every time you call the process() function. That doesn’t seem necessary.

i'll get rid of delays but actually I not only need to display error text but also shutdown power of the system i'm controlling. that's why I'm making pin 35 HIGH.

How quickly does your shutdown action need to occur? If it's on the order of tenths or hundredths of a second, you can probably get away with polling. If you require millisecond response time, then you may need to try to solve the interrupt issue.

I think 1/100th second is enough for me. How can I improve the polling speed ? I have already got rid of delays. Moreover removing delay is making the lcd print faster and i'm unable to read. is there any better way?

@aparna: Don't refresh the LCD too often, refresh it only after a certain time has elapsed. Use millis() to know when it's the right time. See the Blink Without Delay Arduino tutorial.

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


text:
Using VS1838B with Arduino
I just bought VS1838B IR module (from here) and I’m trying to make it work. Below you can find the circuit to see how I have connected the 1838B IR receiver:

My Code (Here) :
#include <IRremote.h>

int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
#define CH1 0xFFA25D
#define CH 0xFF629D
#define CH2 0xFFE21D
...
#define BUTON8 0xFF4AB5
#define BUTON9 0xFF52AD

void setup()

{

 Serial.begin(9600);

 irrecv.enableIRIn();

}

void loop() {

 if (irrecv.decode(&results))
  {

 if (results.value == CH1)

 {

 Serial.println("CH-");
 }

 if (results.value == CH)

 {

 Serial.println("CH");

 }

 if (results.value == CH2)

 {

 Serial.println("CH+");

 }

 ...

 if (results.value == BUTON8)

 {

 Serial.println("BUTON8");

 }
if (results.value == BUTON9)

 {

 Serial.println("BUTON9");

 }
 irrecv.resume();

 }

}

But I'm not getting any output from Serial Monitor.
Can you help me for debugging it?

Are you sure you have a proper remote control? How did you get the constant values from?

You should add Serial.println(results.value); after if irrecv.decode(&results)) { to check what codes are really received from your remote.

@jfpoilpret It's not printing anything, it's not going inside of that if() . I'm use I'm using a proper controller because all they came together, as a kit.

Looking further here
http://forum.arduino.cc/index.php/topic,188236.0.h...
I found the following
"Removing
the files - libraries\RobotIRremote\IRremoteTools.cpp and
libraries\RobotIRremote\IRremoteTools.h solved the problem. They are
example files which somehow are getting included. You can move those two
files to some other location as backup."
I went to my libraries
file and did this and can confirm that the example given above then
compiles fine without downloading a new library. Its an Arduino
libraries problem .
Either way will work
answer from here and worked for me
i use this code:
#include <IRremote.h>
int input_pin = 10; //set D10 as input signal pin
IRrecv irrecv(input_pin);
decode_results signals;
void setup()
{
    Serial.begin(9600);
    irrecv.enableIRIn(); // enable input from IR receiver
}
void loop() {
if (irrecv.decode(&signals)) {
        Serial.println(signals.value, HEX);
        irrecv.resume(); // get the next signal
    }
}

Yup, this was my issue as well. On macOS the files are stored in the contents of Arduino.app, so using Finder you need to go to /Applications, then right-click Arduino.app and click "Show Package Contents". Now, navigate to the folder /Applications/Arduino.app/Contents/Java/libraries and delete the folder "RobotIRremote". You can also do this easily from the Terminal using the rm -r /Applications/Arduino.app/Contents/Java/libraries/RobotIRremote command.

i have also bought this IR receiver with a remote controller (as a kit), and i had the same problem, i changed the remote controller and it worked perfectly, so even if the IR and RC came as a kit it doesn't mean they will work, if you don't have another remote controller in hand you can use a lighter just to check if the IR is working.

connect vcc to 5V
connect Gnd to GND
connect In to D11 pin onto Uno, Nano etc.
download the library from here and follow the instructions/where to unzip and removing the other folders/:
http://z3t0.github.io/Arduino-IRremote/
Open the Arduino program and paste this code onto a new Arduino project:
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
  if (irrecv.decode(&results))
    {
     Serial.println(results.value, HEX);
     irrecv.resume(); // Receive the next value
    }
}

Select 'Sketch'/Import Library from Arduino and select IRremote from the drop-down menu.
Upload the sketch
Open Tools/Serial monitor then select 9600 as baud rate
Use a Tv remote, IR car remote or the remote from the module.
You will see the HEX code of each button after pressing it.

I could be wrong, but I believe that this receiver operates at 38kHz (at least that is listed in the specs), so the IR source must be oscillating at that frequency for this receiver to see it. Check out this link to see how to create a circuit to oscillate your IR LED:
http://www.electro-tech-online.com/threads/ir-emitter-at-38khz.94119/

Whilst you link may answer the question, it would be preferable to include the essential parts of the linked here, and provide the link for citation. Thanks!

void loop(void) {
   int numberpulses;

   numberpulses = listenForIR();

   Serial.print("Heard ");
   Serial.print(numberpulses);
   Serial.println("-pulse long IR signal");
   if (IRcompare(numberpulses, ApplePlaySignal)) {
      Serial.println("PLAY");
      if (ledState == LOW)
         ledState = HIGH;
      else
         ledState = LOW;

      // set the LED with the ledState of the variable:
      digitalWrite(ledPin, ledState);

   }
   if (IRcompare(numberpulses, AppleRewindSignal)) {
      Serial.println("REWIND");
   }
   if (IRcompare(numberpulses, AppleForwardSignal)) {
      Serial.println("FORWARD");
   }
}

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


text:
HTTP_GET not clarified in scope
I'm trying to do an async webserver with access point using an ESP32.
It's a little bit of a mix between This tutorial for AP and async and this tutorial since it's also with an async webserver and it uses inputs which I desperately need.
The part I don't understand is I included all the necessary libraries and I still got this error. If I copy-paste the code in one block everything is fine. It was never necessary to declare HTTP_GET since it should be a variable from a library.
So what's wrong?
These are my errors:
    In file included from C:\..\Arduino\libraries\ESPAsyncWebServer-master\src/ESPAsyncWebServer.h:467:0,
                     from C:\..\AppData\Local\Temp\arduino_build_497972\sketch\webserver.h:5,
                     from C:\..\Async Webserver ESP32\main\main.ino:3:
    C:\..\Arduino\libraries\ESPAsyncWebServer-master\src/WebHandlerImpl.h: In constructor 'AsyncCallbackWebHandler::AsyncCallbackWebHandler()':
    C:\..\Arduino\libraries\ESPAsyncWebServer-master\src/WebHandlerImpl.h:76:49: error: 'HTTP_ANY' was not declared in this scope
         AsyncCallbackWebHandler() : _uri(), _method(HTTP_ANY), _onRequest(NULL), _onUpload(NULL), _onBody(NULL), _isRegex(false) {}
                                                     ^
    In file included from C:\..\Arduino\libraries\ESPAsyncWebServer-master\src/ESPAsyncWebServer.h:467:0,
                     from C:\..\AppData\Local\Temp\arduino_build_497972\sketch\webserver.h:5,
                     from C:\..\AppData\Local\Temp\arduino_build_497972\sketch\webserver.cpp:1:
    C:\..\Arduino\libraries\ESPAsyncWebServer-master\src/WebHandlerImpl.h: In constructor 'AsyncCallbackWebHandler::AsyncCallbackWebHandler()':
    C:\..\Arduino\libraries\ESPAsyncWebServer-master\src/WebHandlerImpl.h:76:49: error: 'HTTP_ANY' was not declared in this scope
         AsyncCallbackWebHandler() : _uri(), _method(HTTP_ANY), _onRequest(NULL), _onUpload(NULL), _onBody(NULL), _isRegex(false) {}
                                                     ^
    C:\Users\Valentin\AppData\Local\Temp\arduino_build_497972\sketch\webserver.cpp: In function 'void setup_server(AsyncWebServer)':
    webserver.cpp:6:18: error: 'HTTP_GET' was not declared in this scope
       server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
                      ^
    Multiple libraries were found for "WiFi.h"
     Used: C:\..\Arduino15\packages\firebeetle32\hardware\esp32\0.1.1\libraries\WiFi
     Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
    Using library ESPAsyncWebServer-master at version 1.2.3 in folder: C:\..\Arduino\libraries\ESPAsyncWebServer-master
    Using library FS at version 1.0 in folder: C:\..\Arduino15\packages\firebeetle32\hardware\esp32\0.1.1\libraries\FS
    Using library WiFi at version 1.0 in folder: C:\..\Arduino15\packages\firebeetle32\hardware\esp32\0.1.1\libraries\WiFi
    Using library AsyncTCP-master at version 1.1.1 in folder: C:\..\Arduino\libraries\AsyncTCP-master
    exit status 1
    'HTTP_GET' was not declared in this scope

I already tried to use the standard Arduino WiFi library which resulted just in more errors so I switched it back.
I split up the code into three pieces for better visibility.
main.ino
#include <Arduino.h>
#include "webserver.h"

// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "blabla";
const char* password = "blabla";

void setup() {
  Serial.begin(115200);
  WiFi.softAP(ssid, password);
  IP = WiFi.softAPIP();

  Serial.println();
  Serial.print("IP Address: ");
  Serial.println(IP);

  setup_server(server);
}

void loop() {}

webserver.cpp
#include "webserver.h"

void setup_server(AsyncWebServer server) {
  // Send web page with input fields to client
  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send_P(200, "text/html", index_html);
  });

  // Send a GET request to <ESP_IP>/get?input1=<inputMessage>
  server.on("/get", HTTP_GET, [] (AsyncWebServerRequest * request) {
    // GET input1 value on <ESP_IP>/get?input1=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
    }
    // GET input2 value on <ESP_IP>/get?input2=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
    }
    // GET input3 value on <ESP_IP>/get?input3=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_3)) {
      inputMessage = request->getParam(PARAM_INPUT_3)->value();
      inputParam = PARAM_INPUT_3;
    }
    else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    request->send(200, "text/html", "HTTP GET request sent to your ESP on input field ("
      + inputParam + ") with value: " + inputMessage +
      "
Return to Home Page");
    });
    server.onNotFound(notFound);
    server.begin();
  }

void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

webserver.h
#ifndef WEBSERVER_H
#define WEBSERVER_H

#include "Arduino.h"
#include "ESPAsyncWebServer.h"
#include "AsyncTCP.h"
#include <WiFi.h>

const char* PARAM_INPUT_1 = "input1";
const char* PARAM_INPUT_2 = "input2";
const char* PARAM_INPUT_3 = "input3";

AsyncWebServer server(80);

String music_state;
IPAddress IP;

String inputMessage;
String inputParam;

// HTML web page to handle 3 input fields (input1, input2, input3)
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML>
  <title>ESP Input Form</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <form action="/get">
    input1: <input type="text" name="input1">
    <input type="submit" value="Submit">
  </form>

  <form action="/get">
    input2: <input type="text" name="input2">
    <input type="submit" value="Submit">
  </form>

  <form action="/get">
    input3: <input type="text" name="input3">
    <input type="submit" value="Submit">
  </form>
)rawliteral";

void setup_server(AsyncWebServer server);

void notFound(AsyncWebServerRequest *request);

#endif

Thanks for the input, I will check back tomorrow and answer all questions and test every suggestion.

Macro Conflict
You have two basic problems here.  The more significant one is that your use of SERVER_H in your include guard:
#ifndef WEBSERVER_H
#define WEBSERVER_H

conflicts with a usage in ESPAsyncWebServer.h:
#ifndef WEBSERVER_H
typedef enum {
  HTTP_GET     = 0b00000001,
  HTTP_POST    = 0b00000010,
  HTTP_DELETE  = 0b00000100,
  HTTP_PUT     = 0b00001000,
  HTTP_PATCH   = 0b00010000,
  HTTP_HEAD    = 0b00100000,
  HTTP_OPTIONS = 0b01000000,
  HTTP_ANY     = 0b01111111,
} WebRequestMethod;
#endif

and that explains why your HTTP_GET etc are not found.  They're not being defined because of your include guard macro.
Changing your code to:
#ifndef XENOSHELL_WEBSERVER_H
#define XENOSHELL_WEBSERVER_H

or something similar will get you past that problem.
Multiply Defined Variables
You also have some non-static variables defined in your webserver.h that will also need to be changed somehow.  A simple change just being to make them static:
static const char* PARAM_INPUT_1 = "input1";
static const char* PARAM_INPUT_2 = "input2";
static const char* PARAM_INPUT_3 = "input3";

IPAddress IP; is only used in main.ino, and should be moved there as a local const IPAddress IP = WiFi.softAPIP();  If you leave it in the header you'll get multiple definitions because of that.
String inputMessage; and String inputParam;   Same problem, only these belong inside your lambda expression in server.on("/get", HTTP_GET, [] (AsyncWebServerRequest * request) {
I don't know why your server variable is in the header either.  The simplest thing to do is put it in webserver.cpp instead and don't pass it in to setup_server, in other word remove the parameter and use the variable defined in the same file as the function.

Having done that your code compiles fine.
Whether or not it works is another question.
I am unable to test that.

hello @timemage thanks for your very detailed answer. I got the code to compile too, but when i tried to connect to the wifi from the ESP the IP adress is not reachable. The output i get from serial monitor is " dhcps: send_offer>>udp_sendto result 0 ". Do you maybe know what could be the problem?

As of yet, I don't have an ESP32 board, so I have no way of troubleshooting this.  What you're asking about seems like an entirely new question.  I would say cut down your program to the minimal thing necessary to demonstrate the problem.  Given the message you're quoting, your demo program should not have #include "ESPAsyncWebServer.h" or #include "AsyncTCP.h" in it at all.  If you don't find the problem in the course of making the demo, post it as part of a new question.

Ok still thanks for your answers, right now i settle on the version that works and if i have enough time i will come back to this problem

Thank you! This is a very helpful answer with expert analysis.


text:
Deep sleep hangs when used with gpio 16 when we connect to reset pin
I have a node MCU and it hangs when I used a deep sleep, as shown in the image attached. My code looks like this:
/*
 * ESP8266 Deep sleep mode example
 * Rui Santos
 * Complete Project Details https://randomnerdtutorials.com
 */

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

  // Wait for serial to initialize.
  while(!Serial) { }

  // Deep sleep mode for 30 seconds, the ESP8266 wakes up by itself when GPIO 16 (D0 in NodeMCU board) is connected to the RESET pin
  Serial.println("I'm awake, but I'm going into deep sleep mode for 30 seconds");
  ESP.deepSleep(30e6);

  // Deep sleep mode until RESET pin is connected to a LOW signal (for example pushbutton or magnetic reed switch)
  //Serial.println("I'm awake, but I'm going into deep sleep mode until RESET pin is connected to a LOW signal");
  //ESP.deepSleep(0);
}

void loop() {
}

Please help!

remove while (!Serial) it doesn't do anything here. add delay(500); after Serial.begin. add Serial.flush before sleep

tried the same. No changes. Its still the same.

and what baud rate do you have set in Serial Monitor? do you see the ""I'm awake, but ..." message at first start after upload or at normal reset or power up?

The serial monitor also had the same baud rate as the code and I don't see that message printed through serial.print command

did you do all 3 changes I recommended? could you add the modified sketch as edit to the question

The most important change to implement is the addition of Serial.flush() immediately before sleeping - this allows the serial data time to be transmitted before the MCU goes to sleep.

I had the same issue, and I realized I didn't connect GPIO 16 (or D1) to the RST. Sounds trivial, but happens to me.
Old topic I know, but I tried to figure out my mistake and came across this topic, so this might be helpful to some people.

but the title of the question already has "when used with gpio 16 when we connect to reset pin"


text:
Read serial with header and end marker
I am trying to use Topway display for HMI lcd with Arduino. This display using RS232C protocol at docs it has a "Communication Packet Structure" like this.

So my query should start with AA and end with CC 33 C3 3C.  This sample reading code was taking topway youtube channel.
Serial.write(0xaa); // packet head
Serial.write(0x3e); // VP_N16 read command
Serial.write(0x00); // VP_N16 address
Serial.write(0x08);
Serial.write(0x00);
Serial.write(0x00);
Serial.write(0xcc); // packet tail
Serial.write(0x33); // packet tail
Serial.write(0xc3); // packet tail
Serial.write(0x3c); // packet tail

3E is the command (for reading) code and this is the list of all commands. docs over here

The point is parsing of smart LCD's response at the original. They use this code: (at first comment)
     while (!Serial.available()) {}
     if (Serial.read()==0xaa) {                     // packet head
     packet_OK=1;
     while (!Serial.available()) {}
     if (Serial.read()==0x3e) {                   // packet command
      while (!Serial.available()) {}
      temp_h=Serial.read();                      // read back value high byte
      while (!Serial.available()) {}
      temp_l=Serial.read();                      // read back value low byte
      while (!Serial.available()) {}
      if (!(Serial.read()==0xcc)) {packet_OK=0;} // packet tail
      while (!Serial.available()) {}
      if (!(Serial.read()==0x33)) {packet_OK=0;} // packet tail
      while (!Serial.available()) {}
      if (!(Serial.read()==0xc3)) {packet_OK=0;} // packet tail
      while (!Serial.available()) {}
      if (!(Serial.read()==0x3c)) {packet_OK=0;} // packet tail
      }
      else
      {packet_OK=0;}
     }
     else
     {packet_OK=0;}

It looks nasty and cumbersome because I must write different method for each LCD display commands. Is there any way to read all serial response them as a char array with starting marker "0xAA" and read until finishing marker "0xCC 0x33 0xC3 0x3C" and after that parse it?
You can watch and check this code on youtube

It looks like you've put some effort into the post but, what is the question?

you cannot simply wait for the packet tail ... the data payload could contain the same bytes ... you have to keep track of the number of bytes in the message ... them check if packet tail arrives as expected

@timemage funny :)

The short answer to your question is “yes, there is a way”. Multiple
ways actually. You could write a blocking function, which follows more
or less the logic of the example you show, blocking while waiting for
each new byte. Or you could write a non blocking function, which
always return immediately and, either gives you the complete packet,
or tells you that no full packet has been received so far.
The non-blocking way may be a bit more complicated, but it is more
useful, because you program can do other stuff, and be responsive, while
waiting for a packet. Here is my take at it. It is based on a finite
state machine:
// Return whether the payload of this command is of string type.
bool command_payload_is_string(uint8_t command);

// Return the expected packet length for the provided command,
// excluding header and tail.
int packet_length(uint8_t command);

// Attempt to read a packet, but do not block.
// Return a pointer to a static buffer holding the packet,
// or nullptr if no complete packet was received this time.
uint8_t *read_packet() {
    const uint8_t expected_header = 0xaa;
    const uint8_t expected_tail[4] = {0xcc, 0x33, 0xc3, 0x3c};

    // Return immediately unless we have a byte to process.
    if (Serial.available() == 0) return nullptr;
    uint8_t data = Serial.read();

    static uint8_t buffer[BUFFER_SIZE];
    static int bytes_received, bytes_expected;
    static enum {
        EXPECTING_HEADER, EXPECTING_COMMAND,
        EXPECTING_STRING, EXPECTING_PAYLOAD, EXPECTING_TAIL
    } state = EXPECTING_HEADER;
    switch (state) {
        case EXPECTING_HEADER:
            if (data = expected_header)
                state = EXPECTING_COMMAND;
            break;
        case EXPECTING_COMMAND:
            buffer[0] = data;  // command byte
            bytes_received = 1;
            if (command_payload_is_string(data)) {
                state = EXPECTING_STRING;
                // bytes_expected is not relevant in this case.
            } else {
                state = EXPECTING_PAYLOAD;
                bytes_expected = packet_length(data);
            }
            break;
        case EXPECTING_STRING:
            if (data == '\0') {  // end of string
                buffer[bytes_received++] = '\0';
                state = EXPECTING_TAIL;
                bytes_expected = 4;
                bytes_received = 0;
            } else if (bytes_received < BUFFER_SIZE - 1) {
                buffer[bytes_received++] = data;
            } else {
                // Do nothing. As the string is too long
                // to fit in the buffer, this byte is discarded.
            }
            break;
        case EXPECTING_PAYLOAD:
            buffer[bytes_received++] = data;
            if (bytes_received >= bytes_expected) {
                state = EXPECTING_TAIL;
                bytes_expected = 4;
                bytes_received = 0;
            }
            break;
        case EXPECTING_TAIL:
            // If we don't get the expected tail,
            // give up and wait for a new header.
            if (data != expected_tail[bytes_received++]) {
                state = EXPECTING_HEADER;
                break;
            }
            // If the tail is all right, return the buffer
            // and get ready for the next packet.
            if (bytes_received >= bytes_expected) {
                state = EXPECTING_HEADER;
                return buffer;
            }
    }
    return nullptr;
}

It will be up to you to implement packet_length(). See jstola's
comment on why it is needed.
You would use read_packet() like this:
void loop() {
    uint8_t *packet = read_packet();
    if (packet)
        parse_and_handle(packet);

    // the rest of the program, never blocked by read_packet()...
}

Edit: According to your comment, some commands have a payload which
is a string of unknown length, but seemingly NUL-terminated. I
edited the code, and added an extra EXPECTING_STRING state to handle
this special case. It is up to you to implement the boolean function
command_payload_is_string().

Edgar thanks a lot! for your wise answer, after reading 10 times, I have understood half of them :). I have a last question. Almost all command respons lenght are known before. But only reading string is not known before. it deponds on user. You can think like that keyboard input. at this point what should I do, while reading string for packet_length().

@mehmet: See amended answer. Now packet_length() will not be called if the payload is of string type.


text:
How to run my buzzer for few more seconds after switching off
This is a basic level lazer alarm project. When anyone crosed or kept their hands on the lazer. buzzer starts working but when they took their hand from lazer light buzzer stops. But i want even after taking hands my buzzer should work for few (15-30) seconds .so please help me by giving idea..

Please don’t write answers in the comments. It bypasses our quality measures by not having voting (both up and down) available on comments, as well as having other problems detailed on meta. Comments are for clarifying and improving the question; please don’t use them for other purposes. Existing answers-in-comments have been deleted. I notice a proper answer has been given by DragonflyRobotics.

If you are using a digital buzzer, you can do:
digitalWrite(buzzerPin,HIGH);
delay(1000);
digitalWrite(buzzerPin,LOW);


text:
How to write analog signals to control throttle of the ship?
I am using teensy 2.0 as DAC. I am trying to write signals on rudder and throttle of the ship via relay. How can I write these analog signals? Should I specify voltage for every pin?
Here is my code:
int Rudder_p= 21; //Digital Write
int Rudder_s= 20; //Digital Write
int Throttle_p= 19; //Analog write
int Throttle_s= 18; //Analog write
int Throttle_T= 17; //Digital Write

void setup() {
  Serial.begin(9600);
  pinMode(Realy1,OUTPUT);
  pinMode(Rudder_p,INPUT);
  pinMode(Rudder_s,INPUT);
  pinMode(Throttle_p,OUTPUT);
  pinMode(Throttle_s,OUTPUT);
  pinMode(Throttle_T,INPUT);

  if (Serial.available() > 0) {
    incomingByte = Serial.read();
  }
}

// the loop routine runs over and over again forever:
void loop() {

  //Relay
  digitalWrite(Relay1,HIGH);
  delay(500);
  digitalWrite(Relay1,LOW);
  delay(500);

   //I am missing logic here:

  // read the input on analog pin 21
  int Value = analogWrite(F0);
  delay(1);        // delay in between reads for stability
}

You don't use an analog signal to control a relay.

I am using digital signal to control relay. But I need to be able to write analog write to control throttle and rudders. Each of them has reference voltage 5V and signal voltage between 0.5-4.5 VDC. I don't know how to use analogWrite() while setting up these voltages.

Do you really need an analog voltage, or a PWM signal? Normally throttle and rudders are controlled via servos, which need a PWM like signal, not an analog signal

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


text:
How to compare payload value?
Connecting my ESP8266 device to an IOT cloud service. When I push a button in the dashboard, it sends either 1 or 0. Then my ESP should turn a pin HIGH if signal received was 1 or Low if it was 0. Here is the code of the method in question:
void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message received[");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i<length;i++) {
     Serial.print((char)payload[i]);
  }
  Serial.println();

  if ( (byte)payload[0] == 0) {
    digitalWrite(13, LOW);
    Serial.println("Setting PIN on to LOW");
  } else {
     digitalWrite(13, HIGH);
     Serial.println("Setting PIN off to HIGH");
  }

}

When sending a 1 signal, serial monitor displays:

Message arrived [/v1.6/devices/esp8266/relay/lv] 1
  Setting PIN off to HIGH

When sending a 0 signal, serial monitor displays:

Message arrived [/v1.6/devices/esp8266/relay/lv] 0
  Setting PIN off to HIGH

So it seems like it always goes into the else clause. Similarly, if casting the value as char:
if ( (char *)payload[0] == 0)

Then it will always go into the first condition payload[0] == 0 regardless of the value received.

Is the character you are receiving the number 0 or 1?  Or is it the ascii code for the character '0' or '1'?

I also can't help but notice that the code you posted is NOT the code that produced the output you posted.  Can you please post code and output that actually go together?

You receive the character 0 or 1 but compare it to the value 0 or 1. The two things are very different.
You are sending ASCII but comparing it to decimal.
Instead you need to compare like for like.  Either:
if (payload[0] == '0') {

Or:
if (payload[0] == 48) {

You can find an easy reference for the full ASCII table here.

It may be worth noting that the PubSubClient library that appears to be in use here works with strings for payload data, even though the MQTT protocol sends data un-typed (bitstream). (This is not a criticism of the library, as there is quite limited codespace in Arduinos!)

if (payload[0] == '0') worked out well. Thanks.


text:
New to Arduino building
I am new to Arduino an working with the Uno.  My dream is to activate servos in a perticular order once some type of sensor recognizes a live person near it.  Is their a perticular easy to understand book out there I can read?  There are lots and lots of books but they all get very complex rather quickly.  I'd be curious as to fellow inventors in here telling me how they mastered the Arduino?  Maybe it was not a book but rather a complete course.  Will others please respond to help me.  ps... I do have an electronics degree so I don't need soldering or component understanding.  I know what Vcc is.  I need please some type of course book which will take me now beyond the self blinking light into robotic control if that easy to understand book or course is out there.
Thank you.  Michael in Palm Beach, FL

There are lots of examples on the official Arduino website.
My advice is you follow them, not only by reading, but buy the components you need (they are cheap) and practice and see how to handle them within the Arduino environment.
Do one component at a time (led, switch, Servo, Sensor), and focus on the servo/sensors you want to use.
Than try to combine multiple components, step by step until you have your dream project ready.
Also, try not to just copy sketches (programs), but understand them. And than adapt them a bit, make variations on the component 'tests'.
I have a whole folder where I test each component with Arduino (and for some complicated components multiple sketches). Save them, and add links etc, so you can easily reference back to it.
You can use books, but there is so much information for the Arduino that this forum, the official web site and google should be enough to get you going.
(note: for the Arduino I did not use books, since as above said, there is so much information. I'm now diving in to STM32 which is more complex and a book/PDF is more convenient).


text:
Turn on relay for amount of time by continuous input
I have a project having two input status

first the input is not continuous the output buzzer relay will be on for 10 seconds and then turned off or it can be off directly by push button

the second state if the input is continuous the output buzzer relay will be on for 10 seconds and then turned off or it can be off directly by push button

I made this code but it does not work can anyone suggest an edit without using millis() because it will crash after 49 days and without using delay function.
Note that the device will work 24 hours / 365 days.
const int input1 = 19;
const int input2 = 36;
const int relay1 = 10;
const int relay2 = 21;
const int reset = 40;
const int buzzerreset = 45;
const int buzzerrelay = 46;

int buttonState1 = 0;    //for input1
int buttonState2 = 0;    //for input2
int buttonState3 = 0;    //for pushbutton
int buttonState4 = 0;    //for buzzer reset
int b4 = 0;              //for buzzer reset

void setup() {
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(buzzerrelay, OUTPUT);
  pinMode(input1, INPUT);
  pinMode(input2, INPUT);
  pinMode(reset, INPUT);
  pinMode(buzzerreset, INPUT);

  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);
  digitalWrite(buzzerrelay, LOW);
}

void loop() {
  buttonState1 = digitalRead(input1);
  if (buttonState1 == HIGH) {
    digitalWrite(relay1, HIGH);
    digitalWrite(buzzerrelay, HIGH);
    //delay(10000);
    //digitalWrite(buzzer, LOW);
  }

  buttonState3 = digitalRead(reset);
  if (buttonState3 == HIGH) {
    digitalWrite(relay1, LOW);
    //digitalWrite(buzzer, LOW);
  } else {
    buttonState4 = digitalRead(buzzerreset);

    if ((buttonState4 == HIGH || buttonState1 == HIGH) && b4 == LOW) {
      digitalWrite(buzzerrelay, LOW);
    }
    // while (digitalRead(input1) == HIGH);
    // digitalWrite(buzzerrelay, LOW);

    (buttonState2 = digitalRead(input2));
    if (buttonState2 == HIGH) {
      digitalWrite(relay2, HIGH);
      digitalWrite(buzzerrelay, HIGH);
      //delay(10000);
      //digitalWrite(buzzer, LOW);
    }

    buttonState3 = digitalRead(reset);
    if (buttonState3 == HIGH) {
      digitalWrite(relay2, LOW);
      //digitalWrite(buzzer, LOW);
    } else {
      buttonState4 = digitalRead(buzzerreset);
      if (buttonState4 == HIGH) {
        digitalWrite(buzzerrelay, LOW);
      }
      //while (digitalRead(input2) == HIGH);
      //digitalWrite(buzzerrelay, LOW);
    }
  }
}

millis doesn't crash after 50 days. It just overflows, and starts back at zero. This is only a problem if you compare two timestamps. You can get around this problem all together by calculating the difference of the two timestamps. You can then check if the difference is more that 10000ms in you case. For example if( millis()-buzzerStartTime > 10000){/*stop buzzer*/}

Could you expand on the it does not work  part? What happens when you run your code? What do you expect do happen when you run your code?

why do you bother with states? ... your description says that the buzzer does the same thing in both states ... all you have to do, is to sound the buzzer for 10 seconds

when i run the code if the input not contentious there is no problem with the timer ,but when is the input is contentious the buzzer is also contentious and this is the problem i want the buzzer run for 10 seconds every time one of the inputs go HIGH (i have 25 inputs) even the input is contentious or not .  – Gerben

You say that when you detect an input (continuous or intermittent) you want to turn on a buzzer for 10 seconds, then turn it off again. What should it to once the buzzer is off again? Should it have a "lock-out" period where it ignores the input? Or should it simply wait for another input? Once 10 seconds has passed, should it wait until the input goes to the off sate before looking for a new trigger?

simply the buzzer will turned ON for 10 seconds in all cases( continuous or intermittent input )and wait for another trigger from another input if input is go high the buzzer will go ON for 10 seconds and so on @DuncanC

What if the input turns on and stays on for 5 minutes? How should the buzzer behave then?

the input could be go ON for a month the buzzer should be ON for 10 seconds and then turn of and ignore the input state until the input goes LOW

That's what I thought. You need to update your question to make that clear. My answer explains how to do that. Is there only one buzzer that buzzes if any of your inputs goes on, or does each input have its own buzzer?

yes there is one buzzer in the circuit

I would suggest having a buzzerPlaying state, an oldInput state, and a buzzerOffTime (unsigned long millis when you should turn the buzzer off.
Ignore input if buzzerPlaying == true and just check the buzzerOffTime. When buzzerOffTime passes, turn off the buzzer, set buzzerPlaying to false, and start checking the input again.
If the buzzerPlaying == false and input is high:

check buzzerPlaying. If it's true, do nothing.

If buzzerPlaying is false, check oldInput. If oldInput is high, do nothing (The input has not been reset.) else set buzzerPlaying to true, set oldInput to high, turn on the buzzer, and calculate buzzerOffTime.

If the buzzerPlaying == false and input is low, set oldInput to low (Once the buzzer has stopped playing and the input has dropped low, start looking for more inputs.)

thanks for replay , im new to arduino and i have 25 inputs and 25 outputs i do not think that i could handle adding  this three status to my code put i will try hope it will work @

25 inputs and 25 outputs? That means you need 50 i/o pins. Do you have an Arduino with that many pins?

i will use arduino mega 23 input and 23 output and pin for buzzer and pin for buzzer reset and pin for output reset that will be 49 i/o

Whatever the inputs do, when one of them first goes HIGH you want the buzzer to sound, stopping after 10 seconds or a button-press, whichever comes first?
Then you need something like this:
if any input is HIGH,
   save millis();
   start the buzzer;

   if button is HIGH
      stop the buzzer;
   else if millis() - saved millis() >= 10*1000 millisec),
      stop the buzzer;
end;

thanks for replay i will try this

This pseudocode will have the buzzer play continuously as long as any input is high. The OP wants the buzzer to only play for 10 seconds, whether the input stays on or not. And they said they only want the buzzer to play again if the input goes low again once the buzzer stops. There need to be some state variables as I suggested in my answer.

Yes, that's right. :) And the psuedo-code reflects the problem statement as it had been stated until they clarified it in response to your pointing that out. That was 5 hours after my post.


text:
User configuration file does not exist or is not a regular file, skipping
I am facing issues while uploading sketch to Adafruit Feature 32u4 Bluefruit LE devices. When i try to upload Blink demo it was working fine and my device also blinking, But bellow error i am getting every time when i upload sketch.
   System wide configuration file is "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf"
     User configuration file is "/Users/myMacmnin/.avrduderc"
     User configuration file does not exist or is not a regular file, skipping

I am using Adafruit Feature 32u4 Bluefruit Le device,Arduion 1.8.3 version, MacMini with macOs Sierra(10.12.3).

That's not an error. That's just mentioning that you don't have a custom configuration file (which not many people do have) and it doesn't care.

Are you actually experiencing a problem, or are you just moaning that avrdude is printing messages?

Actually i am trying to uploading Neopixel sketch , I am getting this error, and nothing happen in device side. If you know anything about this please help me.

Select the right port? As I say, that's not an error. If you're not getting anything else out of it then you should maybe look at the debugging output and for the command being run and make sure that it's all correct.

Yes i selected correct Port,Board and programmer and i fallow Adafruit app for uploading sketch.

Finally i found answer for my question, It happen because of uploading sketch in selected pin.
// Neopixel
//#define PIN            6   /* Pin used to drive the NeoPixels */
#define PIN            13   /* Pin used to drive the NeoPixels */

I Changed Pin 6 to 13 , it's worked for me.


text:
what is good practice around initializing variables
Should vars be initialed when declared or in setup fuction?
Safe to assume compiler will initialze?
Boolean x;      --- init to true/false here?
Void setup()
.
.            --- or init here?
.
Void loop()
If (x)       --- x is unknown state if not initialized.

Initializing a global is appropriate if you know in advance that it should always have a given value at startup. The compiler will generate a globals image in ROM that will be copied into RAM before any of your code is executed.

Safe to assume compiler will initialze?

The compiler will initialize to 0, a global not specifically initialized by you. Let's take the case of your Boolean. '0' means 'false', right? So 'x' is pre-initialized to 'false'. But I, as the reader (or yourself, six months later) may not know whether you intended this to be initialized to 'false' (the default value) or forgot to initialize it. Specifying it to be 'false' may not have any different effect on the code, but it does inform me or your future self, that you meant it to be set 'false' at startup. Remember that your code communicates to people as well as to the compiler. Write it so you or I will not only be able to understand it, but won't be able to misunderstand it.
If you initialize it in setup(), the compiler generates code in setup() specifically to do that. If the setup() function needs to decide during startup, what the initial value of that variable should be, then this is the place to do it. Otherwise, the extra code just takes up space in Flash. It's not any more harmful than wasting those few extra bytes of code-space, but it doesn't accomplish anything more than letting the globals image do it.
Whatever you did or didn't do with 'x' at load time or in 'setup()', it will persist into 'loop()', so 'x's state isn't unknown when you get there. (If I misunderstood that part of your question, please edit it in your question.)

I wouldn't be surprised if the compiler is smart enough to see that the variable isn't read before being 'initialized' in your setup function, and skip it's own 0-initialization (that is; producing identical code, whether you initialized globally, or inside the setup function)

I just checked, and initializing a variable inside setup creates a slightly bigger sketch.

Presumably because setup() is just like any other function and may be called at any time. Global initialization is expected to have been done by the time any user code is executed.

There is only one rule to follow, really:
Never read a variable before writing a defined value to it.
You don't need to write explicitly into a variable, because the C++ language distinguishes between two kinds of variables:

Static variables are initialized to all zero bits, if no explicit initialization is done.
Automatic variables are never automatically initialized. Their initial value is that of the memory cells they occupy, if no explicit initialization is done.

Static variables are defined outside any function or method, or with the keyword static.
Automatic variables are all others.
Example:
static int s1; // static, initialized to 0
int s2 = 42; // static, initialized to 42

void setup() {
    int a1; // automatic, has an unknown initial value
    static int s3; // static, initialized to 0
}

void your_function() {
    static int s4 = 23; // static, initialized to 23
    int a2 = 7; // automatic, initialized to 7 each time control flow comes here
}

All static variables are initialized exactly one time, before main() is called. Or in the case of Arduino, before setup() or any other method or function is called.

Oh, another quite important rule: Know, what you are doing, don't guess, be sure.
You might need to read the standard, or at least some good book.
If you use some rare feature, make it explicit or comment.

Additional notes:
The Arduino uses C++. This is a really different language than C.
You can think of main() as:
void main() {
    setup();
    for (;;) {
        loop();
    }
}


text:
leonardo mouse readings
hi there im using arduino uno + usb host shield and i have taken the readings from the usb mouse in this line of code : x =  mi->dX;
and the x output is the speed of the mouse x coordinates
and i wanna make it thru an analog  reading from 0 to 1023 i should do a constrain and a map
then i send the data thru i2c comm and recieve them with a slave code and display them but the mouse on the screen is moving always when i give the mouse a left move the mouse moves always to left and when i gave the mouse roght it moves to the right always without stopping the cursor as if im giving it a speed direction + or - .
this is the master code :

#include<Wire.h>
#include <hidboot.h>
#include <usbhub.h>
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif
int x; // mouse x
int y; // mouse y
int y1;
int x1;
int l,r;
int x11,y11;
class MouseRptParser : public MouseReportParser
{
protected:
void OnMouseMove (MOUSEINFO *mi);
void OnLeftButtonUp (MOUSEINFO *mi);
void OnLeftButtonDown (MOUSEINFO *mi);
void OnRightButtonUp (MOUSEINFO *mi);
void OnRightButtonDown (MOUSEINFO *mi);
void OnMiddleButtonUp (MOUSEINFO *mi);
void OnMiddleButtonDown (MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
x =  mi->dX;
//x = constrain(x, 0, 1023);

Serial.println(x);

y =  mi->dY;
//y = constrain(y, 0, 1023);

Serial.println(y);

};
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
{
Serial.println("L Butt Up");
l=0;
};
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
{
Serial.println("L Butt Dn");
l=1;
};
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
{
Serial.println("R Butt Up");
r=0;
};
void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
{
Serial.println("R Butt Dn");
r=1;
};
void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi)
{
Serial.println("M Butt Up");
};
void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
{
Serial.println("M Butt Dn");
x = 90;
y = 90;
};

USB Usb;
USBHub Hub(&Usb);
HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb);

uint32_t next_time;

MouseRptParser Prs;

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

Wire.begin();       //Begins I2C communication at pin (A4,A5)

Serial.begin(115200);
#if !defined(__MIPSEL__)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
Serial.println("Start");

if (Usb.Init() == -1)
Serial.println("OSC did not start.");

delay( 200 );

next_time = millis() + 5000;

HidMouse.SetReportParser(0, &Prs);
}

void loop()
{
Usb.Task();
Wire.beginTransmission(8);
Wire.write(x);
Wire.write(y);
//Wire.write(l);
//Wire.write(r);

Wire.endTransmission();
delay(10);

}

and the output is speed direction of x and y :
0
0
0
1
1
2
3
4
5
66
66
78
99
102
113
22
3
0
and this is the slave code :
#include<Wire.h>
int x,y,l,r;
#include <Mouse.h>                                                                               // Analog output of vertical joystick pin

void setup() {
Serial.begin( 115200 ); // start serial for output
Wire.begin(8);
Wire.onReceive(receiveEvent);
Mouse.begin(); //Init mouse emulation
}

void receiveEvent( int bytes )
{

x = Wire.read();
y = Wire.read();
//l = Wire.read();
//r = Wire.read();
delay(10);
}

void loop() {

Mouse.move(x, y, 0); // move mouse on y axis
delay(10);
}

anyone could help please i think the problem is i should ask the current position  and the next postion and if it was not zero move the mouse otherwise if it is 0 do not move

Well, you are constantly sending the X and Y coordinates over and over and over again in loop()...

so what to do ?

Don't keep sending them? Only send them when you receive them from the mouse?

you really need to learn how to format your code properly ... it is not a problem when the code is short,  but when the code is more complicated, correct indentation is very important when trying to find missed braces

could you please show me how ?

look at the example code that is included in the Arduino IDE


text:
Can't upload programs to Raspberry Pi Pico with Arduino
I am trying to use a RP2040 Pico with the Arduino IDE. This is a huge uphill battle. Initially I couldn't get the upload serial port to show up, then copied the "hello world" UF2 to the Pico folder (https://datasheets.raspberrypi.com/soft/hello_world.uf2), after which the port showed up in the Arduino ISE 2.0.0 on Windows 10 - but I can't upload any programs. All I get is this error message:
    Traceback (most recent call last):
      File "C:\Users\light\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\1.9.15/tools/uf2conv.py", line 380, in <module>
        main()
      File "C:\Users\light\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\1.9.15/tools/uf2conv.py", line 360, in main
        drives = get_drives()
      File "C:\Users\light\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\1.9.15/tools/uf2conv.py", line 233, in get_drives
        "FileSystem,", "DriveType"])
      File "D:\obj\Windows-Release\37win32_Release\msi_python\zip_win32\subprocess.py", line 395, in check_output
      File "D:\obj\Windows-Release\37win32_Release\msi_python\zip_win32\subprocess.py", line 472, in run
      File "D:\obj\Windows-Release\37win32_Release\msi_python\zip_win32\subprocess.py", line 775, in __init__
      File "D:\obj\Windows-Release\37win32_Release\msi_python\zip_win32\subprocess.py", line 1178, in _execute_child
    FileNotFoundError: [WinError 2] The system cannot find the file specified
    Upload error: Failed uploading: uploading error: exit status 1

This is ultra-weird, because no such folders etc. exist on my drive D:, and I have no idea why it's looking for files on drive D:\ in the first place, because the Arduino IDE is installed on drive C:. And these folders also aren't present on C:.
Does anyone have any ideas on how to fix this? I've Googled everything I can find and have so far found nothing helpful. I'm about ready to give up and would REALLY appreciate any help you can give!

Those paths with the D: drive come from the stacktrace of the library that's used. Whoever built that library did have a D: drive. Nothing to worry about for you.

The serial port is only used for resetting the chip into the bootloader. Once there it presents as a USB MSD device (hard drive) to which the .uf2 file generated to the IDE gets copied to. It looks like it's not finding that drive. When you upload does the board reset to present a hard drive or not? If not then you can force it by connecting the board while holding in the button on the board. Once it's showing a drive hit upload and it should work.

Thanks for the replies. Neither Arduino 1.8.19 nor 2.0.0 can access the RPi Pico via COM. Neither successfully compiles code for it either (maybe it's just me, but if a compilation fails because the IDE can't find a nonexistent file, I do tend to worry about it). Interestingly, the 2.0.0 IDE also can't find the COM port for an ESP32, which appears in the Windows device manager & also in 1.8.19. I'm ditching the RPi Pico in the Arduino ecosystem because I simply don't have more time to waste. Likewise, the Arduino IDE 2.0.0. They are more riddled with bugs than a rotting log in the rainforest.

Installing a generic driver with  https://zadig.akeo.ie/ while the PICO was plugged in solved the issue for me.

It took me two days to fix that mistake!
Who would have thought that this is due to the missing file "C:\Windows\SysWOW64\framedynos.dll".
When I put the file back in place, everything went back to normal.
UPD:
Turn on "Show verbose output" in Preferences and browse several last lines.
There should be a line like this:
C:\Users\light\AppData\Local\Arduino15\packages\rp2040\tools\pqt-python3\1.0.1-base-3a57aed/python3 -I C:\Users\light\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\1.10.0/tools/uf2conv.py --serial COM5 --family RP2040 --deploy C:\Temp\arduino_build_214726/...

Copy and run that line in Terminal (Win-R). There may be bug reports to help you solve your problem.

Welcome to Arduino:SE.  This doesn't actually provide an answer to the question that was asked.  To ask another question, just click Ask Question above. If you wish, include a link to this question to help provide context.


text:
How can I connect an ESP8266-01 to a shift register?
I am connecting this shift register to my ESP8266-01 for more GPIO options.
It appears there is a GPIO 16, but it's tied to a RESET pin.
I checked both datasheets, the ESP8266 datasheet, and I also checked the datasheet for the shift register for more information on what kinds of pins can be hooked to each of the input pins.
I am also thinking whether it's viable to connect one of the other available pins of the ESP8266 and use it for this connection with the shift register (either RX or TX).

My understanding is that I need to connect three pins of the ESP8266 directly to the shift register for its latch, clock, and serial pin.
I am also wondering if I can connect the serial pin of the ESP8266 to the serial pin of the shift register?

buy an esp-12 or a dev board like Wemos D1 mini

It cannot be expanded to more gpio?

It can, but, why complicate it? it is the same esp8266 only more pins are accessible on esp-12. the esp-01 is for use as serial WiFi adapter.

It’s to have use of it now and in the future. I think gpio 16 can be used. Just must be disconnect during sketch upload. Confirmation on this? Going to test later and update . Happy to accept answers

Ahh, interesting. Use as serial WiFi adapter. Exactly as I intend to use it for a separate project.

io 16 is not accessible on esp-01. esp-01 has RX, TX, io 0 and io 2

You have several options. Your drawing shows a 74HC595 which is a serial in parallel output. You need a minimum of two pins to operate it, one for clock and another for data. Adding a third for reset will make it much easier to use. You can use any GPIO pins you like but be cognisant of any other uses those pins may be performing in your system such as boot etc.
The part also has SPI, this will directly interface to the shift register. You can cascade them to as many deep as you want. The SPI operates concurrently input and output at the same time. You actually have to send something to get something, that is what cycles the clock. There technically is no limit to the number of devices but there are practical limitations. Since the data transfer is only one way on a pin you can easily buffer it. This generally is one of the fastest I/O you can get.
The second which only requires is I2C which is a synchronous buss that directly addresses the peripheral devices. Originally it had 7 address bits giving you 127 seperate devices you can access. Each device can have as many individual locations/registers as it needs but normally only one address. A lot of chips have this built in and have a preassigned address or address range. For example there are FRAM chips that are 32K x 8 bits at a single address.
There are a lot more options available but I mentioned these because modules that implement these functions are inexpensive and readily available. You can look up "SPI" and "I2" to get a lot more information. Good luck and enjoy your project.


text:
"previous declaration of 'HTTPMethod HTTP_HEAD'"
I'm getting the following error when I try to compile my code on my  LOLIN(WeMos) D1 R1:
In file included from C:\Users\Administrator\Documents\Arduino\libraries\WiFiManager/WiFiManager.h:17,
                 from C:\Users\Administrator\Desktop\from\from.ino:6:
C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266WebServer\src/ESP8266WebServer.h:47:19: error: 'HTTP_ANY' conflicts with a previous declaration
   47 | enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };
      |                   ^~~~~~~~
In file included from C:\Users\Administrator\Desktop\from\from.ino:5:
C:\Users\Administrator\Documents\Arduino\libraries\ESPAsyncWebServer-master\src/ESPAsyncWebServer.h:69:3: note: previous declaration 'WebRequestMethod HTTP_ANY'
   69 |   HTTP_ANY     = 0b01111111,
      |   ^~~~~~~~
In file included from C:\Users\Administrator\Documents\Arduino\libraries\WiFiManager/WiFiManager.h:17,
                 from C:\Users\Administrator\Desktop\from\from.ino:6:
C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266WebServer\src/ESP8266WebServer.h:47:29: error: 'HTTP_GET' conflicts with a previous declaration
   47 | enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };
      |                             ^~~~~~~~
In file included from C:\Users\Administrator\Desktop\from\from.ino:5:
C:\Users\Administrator\Documents\Arduino\libraries\ESPAsyncWebServer-master\src/ESPAsyncWebServer.h:62:3: note: previous declaration 'WebRequestMethod HTTP_GET'
   62 |   HTTP_GET     = 0b00000001,
      |   ^~~~~~~~
In file included from C:\Users\Administrator\Documents\Arduino\libraries\WiFiManager/WiFiManager.h:17,
                 from C:\Users\Administrator\Desktop\from\from.ino:6:
C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266WebServer\src/ESP8266WebServer.h:47:39: error: 'HTTP_HEAD' conflicts with a previous declaration
   47 | enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };
      |                                       ^~~~~~~~~
In file included from C:\Users\Administrator\Desktop\from\from.ino:5:
C:\Users\Administrator\Documents\Arduino\libraries\ESPAsyncWebServer-master\src/ESPAsyncWebServer.h:67:3: note: previous declaration 'WebRequestMethod HTTP_HEAD'
   67 |   HTTP_HEAD    = 0b00100000,
      |   ^~~~~~~~~
In file included from C:\Users\Administrator\Documents\Arduino\libraries\WiFiManager/WiFiManager.h:17,
                 from C:\Users\Administrator\Desktop\from\from.ino:6:
C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266WebServer\src/ESP8266WebServer.h:47:50: error: 'HTTP_POST' conflicts with a previous declaration
   47 | enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };
      |                                                  ^~~~~~~~~
In file included from C:\Users\Administrator\Desktop\from\from.ino:5:
C:\Users\Administrator\Documents\Arduino\libraries\ESPAsyncWebServer-master\src/ESPAsyncWebServer.h:63:3: note: previous declaration 'WebRequestMethod HTTP_POST'
   63 |   HTTP_POST    = 0b00000010,
      |   ^~~~~~~~~
In file included from C:\Users\Administrator\Documents\Arduino\libraries\WiFiManager/WiFiManager.h:17,
                 from C:\Users\Administrator\Desktop\from\from.ino:6:
C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266WebServer\src/ESP8266WebServer.h:47:61: error: 'HTTP_PUT' conflicts with a previous declaration
   47 | enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };
      |                                                             ^~~~~~~~
In file included from C:\Users\Administrator\Desktop\from\from.ino:5:
C:\Users\Administrator\Documents\Arduino\libraries\ESPAsyncWebServer-master\src/ESPAsyncWebServer.h:65:3: note: previous declaration 'WebRequestMethod HTTP_PUT'
   65 |   HTTP_PUT     = 0b00001000,
      |   ^~~~~~~~
In file included from C:\Users\Administrator\Documents\Arduino\libraries\WiFiManager/WiFiManager.h:17,
                 from C:\Users\Administrator\Desktop\from\from.ino:6:
C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266WebServer\src/ESP8266WebServer.h:47:71: error: 'HTTP_PATCH' conflicts with a previous declaration
   47 | enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };
      |                                                                       ^~~~~~~~~~
In file included from C:\Users\Administrator\Desktop\from\from.ino:5:
C:\Users\Administrator\Documents\Arduino\libraries\ESPAsyncWebServer-master\src/ESPAsyncWebServer.h:66:3: note: previous declaration 'WebRequestMethod HTTP_PATCH'
   66 |   HTTP_PATCH   = 0b00010000,
      |   ^~~~~~~~~~
In file included from C:\Users\Administrator\Documents\Arduino\libraries\WiFiManager/WiFiManager.h:17,
                 from C:\Users\Administrator\Desktop\from\from.ino:6:
C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266WebServer\src/ESP8266WebServer.h:47:83: error: 'HTTP_DELETE' conflicts with a previous declaration
   47 | enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };
      |                                                                                ^~~~~~~~~~~
In file included from C:\Users\Administrator\Desktop\from\from.ino:5:
C:\Users\Administrator\Documents\Arduino\libraries\ESPAsyncWebServer-master\src/ESPAsyncWebServer.h:64:3: note: previous declaration 'WebRequestMethod HTTP_DELETE'
   64 |   HTTP_DELETE  = 0b00000100,
      |   ^~~~~~~~~~~
In file included from C:\Users\Administrator\Documents\Arduino\libraries\WiFiManager/WiFiManager.h:17,
                 from C:\Users\Administrator\Desktop\from\from.ino:6:
C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266WebServer\src/ESP8266WebServer.h:47:96: error: 'HTTP_OPTIONS' conflicts with a previous declaration
   47 | enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };
      |                                                                                ^~~~~~~~~~~~
In file included from C:\Users\Administrator\Desktop\from\from.ino:5:
C:\Users\Administrator\Documents\Arduino\libraries\ESPAsyncWebServer-master\src/ESPAsyncWebServer.h:68:3: note: previous declaration 'WebRequestMethod HTTP_OPTIONS'
   68 |   HTTP_OPTIONS = 0b01000000,
      |   ^~~~~~~~~~~~
exit status 1
Error compiling for board LOLIN(WeMos) D1 R1.

Here is my code:
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <WiFiManager.h>

AsyncWebServer server(80);

const char* PARAM_INPUT_1 = "input1";
const char* PARAM_INPUT_2 = "input2";
const char* PARAM_INPUT_3 = "input3";

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML>
  <title>ESP Input Form</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <form action="/get">
    input1: <input type="text" name="input1" style="background-color: #195B6A; border: none; color: white; padding: 16px 40px;
    text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;">
    <input type="submit" value="Submit">
  </form>

  <form action="/get">
    input2: <input type="text" name="input2">
    <input type="submit" value="Submit">
  </form>

  <form action="/get">
    input3: <input type="text" name="input3">
    <input type="submit" value="Submit">
  </form>

SmartHomeHarris-CoLTD

GPIO 1 - State off

<button class="button">ON</button>

GPIO 2 - State off

<button class="button">ON</button>

GPIO 3 - State off

<button class="button">ON</button>

GPIO 4 - State off

<button class="button">ON</button>

  )rawliteral";

void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFiManager wm;
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("WiFi Failed!");
    return;
  }
  bool res;
  // res = wm.autoConnect(); // auto generated AP name from chipid
  // res = wm.autoConnect("AutoConnectAP"); // anonymous ap
  res = wm.autoConnect("AutoConnectAP","password"); // password protected ap

  if (!res) {
        Serial.println("Failed to connect");
        // ESP.restart();
  }
  else {
        // if you get here you have connected to the WiFi
        Serial.println("connected...yeey :)");
  }
  Serial.println();
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());

  // Send web page with input fields to client
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html);
  });

  // Send a GET request to <ESP_IP>/get?input1=<inputMessage>
  server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;
    // GET input1 value on <ESP_IP>/get?input1=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
    }
    // GET input2 value on <ESP_IP>/get?input2=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
    }
    // GET input3 value on <ESP_IP>/get?input3=<inputMessage>
    else if (request->hasParam(PARAM_INPUT_3)) {
      inputMessage = request->getParam(PARAM_INPUT_3)->value();
      inputParam = PARAM_INPUT_3;
    }
    else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    request->send(200, "text/html", "HTTP GET request sent to your ESP on input field ("
                                     + inputParam + ") with value: " + inputMessage +
                                     "
Return to Home Page");
  });
  server.onNotFound(notFound);
  server.begin();
}

void loop() {

}

I tried different version of WiFiManager but still it doesn't work.

WiFiManager uses the ESP8266WebServer library and you want to use the async version of it. The conflict is between very similar source codes of the two web server libraries. here is an async version of WiFiManager https://github.com/khoih-prog/ESPAsync_WiFiManager . I don't know if it is good

I have the same issue.   THe program used to work. I recently tried to modify the router wifi settings and I get these errors.

As the error messages tell you, there are two declarations of HTTP_OPTIONS via two includes. Apparently you cannot use these at the same time.
"WiFiManager.h" has the enum HTTPMethod that has these constants.
And "ESPAsyncWebServer.h" has another declaration of the same constants.
You might need to read their documentation to learn whether work-arounds are possible.


text:
Can read Serial but cannot write - serial communication Arduino Mega 2560 clone
I am having issues using the following USB to UART module. I am using an Arduino 2560 clone.
I have two connections with the Arduino:

COM7 which consists of the given module, connected to the main Rx0/Tx0 on the Arduino, with yellow to Tx0, orange to Rx0 and ground to the Arduino ground.
COM4 which consists of a usual USB to USB module, connected to the Arduino's USB port.

I can read from the Arduino perfectly fine using either COM4 or COM7, but I cannot send data through the serial or upload a program to it through COM7, only through COM4.
I have tried the following for uploading data with COM7: PuTTY and Arduino Serial.
Once again: The Arduino can correctly receive a program file or read serial input data from COM4, it correctly outputs data to either COM4 or COM7, but I cannot upload data to it from COM7.
Code I am using to test the COM7's ability to send data:
int incomingByte = 0; // for incoming serial data

void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {
  // send data only when you receive data:
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
  }
}

test the USB to UART cable using a PC without an arduino

you can upload over USB while the the external USB Serial adapter is still wired to RX0/TX0?


text:
Where is the Arduino IDE boards.txt file for Nano Every located?
My Arduino Nano Every runs at 16Mhz (but the 4809 can support internal 20Mhz).
I know it may be possible to alter the boards.txt file and set it to build for 20Mhz.
However, I can't find the boards.txt for these new boards (MegaAVR).
Where is the boards.txt located?

I found the boards.txt file at: ~/.arduino15/packages/arduino/hardware/megaavr/1.8.7
The Nano Every portion of the boards.txt looks like the following:
##############################################################

nona4809.name=Arduino Nano Every

nona4809.vid.0=0x2341
nona4809.pid.0=0x0058

nona4809.upload.tool=avrdude
nona4809.upload.protocol=jtag2updi
nona4809.upload.maximum_size=49152
nona4809.upload.maximum_data_size=6144
nona4809.upload.speed=115200
nona4809.upload.use_1200bps_touch=true
nona4809.upload.extra_params=-P{serial.port}

nona4809.build.mcu=atmega4809
nona4809.build.f_cpu=16000000L
nona4809.build.board=AVR_NANO_EVERY
nona4809.build.core=arduino
nona4809.build.variant=nona4809
nona4809.build.text_section_start=.text=0x0
nona4809.build.extra_flags={build.328emulation} -DMILLIS_USE_TIMERB3 -DNO_EXTERNAL_I2C_PULLUP
#nona4809.build.extra_flags=-B{runtime.tools.atpack.path}/gcc/dev/{build.mcu}

nona4809.bootloader.tool=avrdude
nona4809.bootloader.file=atmega4809_uart_bl.hex
nona4809.bootloader.SYSCFG0=0xC9
nona4809.bootloader.BOOTEND=0x00
nona4809.bootloader.OSCCFG=0x01
nona4809.fuses.file=fuses_4809.bin

menu.mode=Registers emulation
nona4809.menu.mode.on=ATMEGA328
nona4809.menu.mode.on.build.328emulation=-DAVR_NANO_4809_328MODE
nona4809.menu.mode.off=None (ATMEGA4809)
nona4809.menu.mode.off.build.328emulation=

##############################################################

If you change the following line from:
nona4809.build.f_cpu=16000000L

to:
nona4809.build.f_cpu=20000000L

Then go in and turn on verbose when you build in the Arduino IDE you will see that avrdude will pass in the following when it builds your sketch:
DF_CPU=20000000L

Will this push the CPU to 20Mhz?  Not sure, but at least you know where this is now.
UPDATE
FYI - Do not set your board to 20Mhz.  Especially if you have Serial Communication going on.  I have software serial set up to communicate with an attached bluetooth device and when you set the CPU to 20Mhz other things are not set properly and the Serial communication fails.

If the intention is to run the Nano Every at 20 MHz, you're probably better off using MCUdude MegaCoreX.

@timemage Very good point. I'm doing some different things.  Using Nano Every board as a prototype. Then, I'm building the HEX file in a Arduino IDE & exporting it.  I then upload it to a raw 40-pin ATMega4089 using Atmel-ICE programmer & Microchip studio.
My 4089 runs on the 20Mhz internal crystal & I was trying to see if I could get Arduino IDE to generate a HEX that is using 20Mhz.  Thanks again for the link

why not upload directly to ATmega?

In addition to set the
nona4809.build.f_cpu=20000000L

you will have to set the corresponding fuse byte to
nona4809.bootloader.OSCCFG=0x02

this enables the 20 MHz clock.


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:
Testing 433MHz Transmitter
Folks,
There is a document named "Complete Guide for RF 433MHz Transmitter.pdf" available in the GitHub.
There is a a connection diagram showing the Data pin of the Transmitter connected to the pin 12 of the Arduino Uno.
The Transmitter sketch given in it is as follows:
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile

RH_ASK driver;

void setup()
{
 Serial.begin(9600); // Debugging only
 if (!driver.init())
 Serial.println("init failed");
}

void loop()
{
 const char *msg = "Hello World!";
 driver.send((uint8_t *)msg, strlen(msg));
 driver.waitPacketSent();
 delay(1000);
}

There is no mention of Pin 12 as part of the sketch. I am not sure how the Arduino knows the Transmitter Data input is connected to the Pin 12? Can someone please help?
Ranjith

In RH_ASK.h is:
RH_ASK(uint16_t speed = 2000, uint8_t rxPin = 11, uint8_t txPin = 12, uint8_t pttPin = 10, bool pttInverted = false);

So the argument has a default value specified here.  If you don't specify it, it assumes that default.

Thanks a lot. Much appreciated.