text:
Issues with Arduino UNO printing repeated "double" on serial monitor
A weird is happening which i can't figure out why. First I had issue communicating with SIM800L.
So i tried checking the USART Hardware to see what UNO sends to SIM800 using small piece attached below.
The sketch is to compares what i send from serial monitor with strings "Hello", "heLLo" and "Hello" expecting to get Found .... or No match found.
each line string i send, the serial monitor prints twice WHY?,
The first says not found and the second say Received == ........ WHY?
**See the output of serial terminal
when i typed "Hello" with quotes.
12:03:46.536 -> Buffer Received= "  No match found
12:03:46.569 ->
12:03:46.569 -> Buffer Received= Hello"
12:03:46.603 ->     Found Hello
when i typed "HELLO" with quotes.
12:03:55.855 -> Buffer Received= "  No match found
12:03:55.888 ->
12:03:55.888 -> Buffer Received= HELLO"
12:03:55.921 ->     Found HELLO**

****when i typed "heLLo" with quotes.
12:04:04.016 -> Buffer Received= "  No match found
12:04:04.049 ->
12:04:04.049 -> Buffer Received= heLLo"
12:04:04.082 ->     Found heLLo
12:04:04.115 ->****

When i typed without quotes, all i get No match found
char buffer[100];
uint8_t index=0;

void setup()
{
  Serial.begin(9600);
  _delay_ms(4000);
}

void loop()
{
  if(Serial.available()>0)
  {
    index=0;
    while(Serial.available())
    {
      buffer[index++]=Serial.read();
    }

    buffer[index]='\0';
    Serial.println(' ');
    Serial.print("Buffer Received");
    Serial.print(buffer);
    Serial.print('\t');
    if(strstr(buffer, "Hello")!=NULL) Serial.println("Found Hello");
    else if(strstr(buffer, "HELLO")!=NULL) Serial.println("Found HELLO");
    else if(strstr(buffer, "heLLo")!=NULL) Serial.println("Found heLLo");
    else Serial.println("No match found");
    Serial.flush();
  }
}

Note: Suspecting my PC hardware and serial driver,
so I tried it in my Ubuntu 20.04 and window 10 installed with Arduino IDE 1.8.13
suspecting it may be crystal, i tried two different boards and used even Atmega328P core.
I also suspected my keyboard "ENTER" key, so i tried the serial monitor "send" button.
with no difference.
I seems to run short is ideas so i am posting to the community. Let me have your advice and experience too.
Thanks.

You have a fundamental misunderstanding of how serial communication works. You can't just read "while available" because that will not be true. You need to "read if available and up until the terminating character".

9600 Bd means 1ms per character. If there's no terminating character to rely on, simply waiting a few ms via delay(10); after the first Serial.available()> 0 is an ugly but doable alternative in this case.

Hello DataFiddler, You great, your suggestion works. it was just a case of delay which ignored. I actually added delay(10) in-between character reads. and no more print duplication. BUT WHY is that necessary? in eclipse i don't think i have that experience. IT WORTH NOTING WHEN USING ARDUINO IDE!

Doesn’t matter what IDE you use to write the code the code is the same.  The problem is that the serial data doesn’t come all at once.  You get one character and read it and then before the next character arrives available is again 0 and you go off to compare your one character you read.  While you’re doing that the rest of the string arrives.  When you get back around you’ve now got the whole string.  With the delay you’re giving the string time to complete arrive one letter at a time on the port.

It’s not necessary to have the delay if you write proper code to handle serial data.  Have it look for an end marker before it does the comparison.  Or have it wait until available returns the full length of the string before you start reading it.

Dear Delta_G OK, i am noting all suggestions. Cheers!

@Delta_G: "Doesn’t matter what IDE you use to write the code" - But it may matter if you use its in-built terminal emulator.

As Majenko and DataFiddler already stated in the comments, you are reading the Serial interface in the wrong way, because you seem to misunderstand a specific point involving the interface.
The Serial (UART) interface knows only of individual bytes, which are send asynchronously over the lines. It does not have any context of a full packet or message. When you type in some data into the Serial Monitor and then press "Send", the data will be send, but not as one big bunch of data. The individual bytes are delayed.
The first delay comes with the nature of the interface itself, as you send with a limited baudrate. With a baudrate of 9600 the Arduino is way faster, than the bytes can arrive. So when you first get a result higher than zero from Serial.available(), the rest of the message is not yet received. Thus with your current code you would only process only the first part of the message.
The second delay comes with the fact, that you and the Serial program on your PC cannot control, when exactly each byte is send. Thats done by the driver. So it might happen, that there is a small gap between 2 bytes somewhere in your message. You cannot mitigate this without writing your own driver and you cannot predict this.
So, what to do now? You should read data, when it is available, and put it into a buffer. And only, when a full message was received, you should process the data. Now you need to know, where the end of a message is. Mostly a delimiting character (like the newline character \n) at the end of the message is used. So you read, if available, and only process the message, when you have read the delimiting character. Something like this:
unsigned int buffer_pos = 0;
char buffer[50]="";

void loop(){
    if(Serial.available()){
        char c = Serial.read();
        if(c == '\n'){
            buffer[buffer_pos] = '\0'; // End the message as C string with a null character
            // process the message here
            buffer_pos = 0;
        } else {
            buffer[buffer_pos] = c;
            buffer_pos++;
        }
    }
}

buffer holds the message. buffer_pos is the current position in the buffer. We terminate the message with the null character, to get a valid C string in the buffer. After processing the message, we set the position back to zero, to receive the next message. When you send data from your PC, you need to make sure, that the message is ended with the newline character.
Now you are independent on when exactly the data is send.

DataFiddler stated in the comments, that without a delimiting character you can simply delay for enough time, so that the data has enough time to arrive. He also stated, that it is ugly. It is a bad coding style. A long delay will impact the responsiveness of your program, while a short delay may give you problems with longer messages. So I suggest, that you directly use the correct way to read the Serial interface. Then you don't have such pitfalls.

Dear chris! you guys are great! THANKS ALOTS. got it resolved first from DataFiddler suggest and next Majenko suggestion. Your explanations is explicit. I enjoy all your contribution. JUST that i was abit careless in handling that. Funny as it will sound. I battle with this for about 22hrs. Just as i stated earlier, i will be more caution next to avoid this kind avoidable stress.

@Avong, please upvote good answers and mark as correct the answer which is best, as this is the best way to thank people for taking the time to write good answers. The upvote button is the little up arrow at the top left of the answer.


text:
What is the over-volt, over-current or over-power limit on a pin to an Arduino Mega 2560
I have an input voltage going to an Arduino pin that could be up to 5.25 V. I have many options on solving the problem but the simplest would be to include an inline resistor that limits the power that the over-voltage can deliver to the board.
I have done some experiments with the board using a pin that is set to INPUT, INPUT_PULLUP, OUTPUT set to low and OUTPUT set to high. I sent a voltage through a 33 kOhm resistor to the pin in those configurations, and swept 0-6V across the resistor. The pin voltage when in OUTPUT mode was very rigid, holding its output perfectly against the resistor.
When in either INPUT mode, the overvoltages seemed to happily pass through the resistor, driving at most 65 uA and 0.15 mW into the pin while it was raised to the 5.5 V value. it seems to me then that the Arduino pins are quite resilient to overvoltage, but this might be an incorrect assessment.

Have you reviewed the Atmel (i.e. Microchip) Datasheet for the ATMega2560?  All of these limits and more are covered there.  Keep in mind that just because a condition doesn't cause an immediate failure, doesn't mean it doesn't cause damage.  Some damage is cumulative and only shows up over time.

If you use that pin for input only, you can just add a voltage divider using two resistors (one to the input line and another to ground).

All inputs have clamping diodes. Combined with your resistor they will prevent the voltage from going too high.

The maximum voltage on any IO pin is VCC+0.5V or 5.5V when powered from 5V.
The maximum "injected" current is not specified in the datasheet, but typically 1mA is a reasonable value to assume.
So 5.25V at 65uA is, while not ideal, at least tolerable.

The ATMega2560 Datasheet is here:
Microchip ATMeta2560 Datasheet
The important section for questions like this is: ABSOLUTE MAXIMUM RATINGS
For this chip we are provided:

Note the Voltage on any Pin... specification that I have highlighted.  This says that under NO circumstances should you allow a pin to go below -0.5V or above (Vcc + 0.5V) or you risk damaging the chip.  So if you are running at 5.0V that means you can safely apply a voltage of +5.5V to the pin.
Your 0-6V signal is over the limit for this device and you will fall into the other section that I highlighted, the "NOTICE".

It is generally not a good idea to go near the Absolute Maximum Ratings, let alone drive a pin at exactly the maximum rating, as only a slight difference will put you over the top. Absolute Maximum Ratings are not design guidelines, which is why the datasheet explicitly states: "Exposure to absolute maximum rating conditions for extended periods may affect device reliability." 5.25V would be acceptable, though not a sign of a good design, but 5.5V is a no-no (all this assuming a supply voltage of 5V).

Yes, that's quite correct.  It's also important to keep in mind the actual Vcc.  If it's a bit low but still within limits, then an otherwise acceptable input voltage could cause damage.

source: Stack Exchange

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

sort: votes


text:
Error conecting raspberry with my arduino in a serial port
Hi i am trying to make a comunication between theses device but when i am trying to run in my raspberry i have the follow error:

Traceback (most recent call last):
    File "serial.py", line 1, in
      import serial
    File "/home/pi/Desktop/serial.py", line 2, in
      ser = serial.Serial('/dev/ttyACM0', 9600)
  AttributeError: 'module' object has no attribute 'Serial'

i have the next code:
import serial

ser = serial.Serial('/dev/ttyACM0', 9600)

while 1:

    if(ser.in_waiting >0):
        line = ser.readline()
        print(line)

If any can help me, i will be thankfull

did you check if a function nsmed Serial actually exists in the serial library?

Don't name your files with the names of modules you're using. Also, why ask a Raspberry question on Arduino site when we have RPi.SE, where the exact same question was already answered?

What's almost certainly happening here is that you've named your file serial.py, so the import is trying to load the library from your file within the current working directory.
To fix this problem, simply rename your serial.py script to something else, for example serial_comms.py or whatever other useful name you want.

you are a genius, that was the problem thank you

@JesusMiguelHerrera You're most welcome. I ran into this when I had to learn Python for a previous job.

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


text:
Arduino transmitter and receiver
hi I am using Arduino transmitter and receiver it works properly with sending and receiving username and password but I would include to check the username if its true open the led , I added this in the code but it seems that the code ignoring it ( the last part) as well as I want it to take the password and username at the same time
this is the recover code
#include <RH_ASK.h>//include radioHead ASK library
#include <SPI.h> // include dependant SPI libray

 RH_ASK rf_driver; // create ASK object
int ledon = 13;
String userid;
String password;
 //RH_ASK ID1; // create ASK object
//RH_ASK pass1; // create ASK object

void setup() {

  rf_driver.init(); //initialize ASK object

  Serial.begin(9600); //setup serial monitor to 9600

  //if(!rf_driver.init())
       //Serial.print("init failed");
}

void loop() {

  // set buffer to size of expected message
  uint8_t buf[9];
  uint8_t buflen =sizeof(buf);

  //check if recevied packet is correct size
  if (rf_driver.recv(buf,&buflen))
  {
    int i;
    // message received with valid checksum
    Serial.print("id: ");
    Serial.println((char*)buf);
      userid =(char*)buf;
        Serial.println(userid);

  }

delay(5000);

   uint8_t buf2[8];
  uint8_t buflen2 = sizeof(buf2);

   if (rf_driver.recv(buf,&buflen))

  {

    int i;
    // message received with valid checksum
    Serial.print("password: ");
    Serial.println((char*)buf);
      password = (char*)buf;
      Serial.println(password);

  }
  delay(5000);

while ( userid =="A00034732" && password == "123456789"){
digitalWrite(ledon, HIGH);
delay(2000);
digitalWrite(ledon, LOW);

}
}

transmitter code ----
//Include RadioHead Amplitidue shift keying library
#include <RH_ASK.h>
// Include dependatnt ISP library
#include <SPI.h>

//create Ampitude shift keying object
RH_ASK rf_driver;

void setup() {
 // intialize ASK objct
rf_driver.init();

Serial.begin(9600);

  //if(!rf_driver.init())
      //Serial.print("init failed");

}

void loop()
{

  const char *pass= "123456789";
rf_driver.send((uint8_t *)pass, strlen(pass));
rf_driver.waitPacketSent();
delay(5000);

const char *ID= "A00034732";

rf_driver.send((uint8_t *)ID, strlen(ID));
rf_driver.waitPacketSent();
delay(5000);

//const char *pass= "12345678";
//rf_driver.send((uint8_t *)pass, strlen(pass));
//rf_driver.waitPacketSent();
//delay(5000);

}

You're not comparing strings - you're comparing addresses of strings.  Use strcmp().
while (
    (strcmp(userid, "A00034732") == 0) &&
    (strcmp(password, "123456789") == 0)
) {

I want to convert it to integer


text:
My code seems to be a train wreck
I am new to programming and I thought a simple project to do would be to create an ammo counter.
I have been troubleshooting this code for several hours now, and can not figure out why my code is riddled with errors. Below is my program. Please give it a glance and let me know what mistake I have made. I will post the error report beneath my program. I apologize for my bad programming in advance and hope that there is still hope for me with the proper tutelage.
The program worked just fine when I ran a test using only one saved function, "twentyBullets()". After I added a 30 additional functions and created a chain of if-else-if conditions, the program began to report all sorts of errors.
 /*
    7-SEGMENT DISPLAY HANDLING CODE!
    The below code handles the 7-segment display for the digital ammo counter.

     A
    ___
  F|   |B
   G---G
  E|___|C
     D

 Above is the alphabet letter assignment for the different segments of
 the B07BMPPNQY display. Digital ammo counter project will use common pins, L3 and L4.
 */
  // Display pin declaration.
  // P_: Where P indicates the pin output for the segment of the display to be illuminated followed by a lower case letter
  // which indicates which specific led in the segment to illuminate.
  // ten: Where ten indicates the ten's place on the 7 segment display.
  // one: Where one indicates the one's place on the 7 segement display.

int Pa = 0;
int Pb = 1;
int Pc = 2;
int Pd = 3;
int Pe = 4;
int Pf = 5;
int Pg = 6;
int ten = 7;
int one = 8;
int ammo = 10;

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

pinMode(Pa, OUTPUT);
pinMode(Pb, OUTPUT);
pinMode(Pc, OUTPUT);
pinMode(Pd, OUTPUT);
pinMode(Pe, OUTPUT);
pinMode(Pf, OUTPUT);
pinMode(Pg, OUTPUT);
pinMode(ten, OUTPUT);
pinMode(one, OUTPUT);

}

void loop(){
  // put your main code here, to run repeatedly:
  if (ammo == 1) {
  oneBullet();
  }
  else if (ammo == 2) {
  twoBullets();
  }
  else if (ammo == 3) {
   threeBullets();
  }
  else if (ammo == 4) {
    fourBullets();
  }
  else if (ammo == 5) {
    fiveBullets();
  }
  else if (ammo == 6) {
    sixBullets();
  }
  else if (ammo == 7) {
    sevenBullets();
  }
  else if (ammo == 8) {
    eightBullets();
  }
  else if (ammo == 9) {
    nineBullets();
  }
  else if (ammo == 10) {
    tenBullets();
  }
  else if (ammo == 11) {
    elevenBullets();
  }
  else if (ammo == 12) {
    twelveBullets();
  }
  else if (ammo == 13) {
    thirteenBullets();
  }
  else if (ammo == 14) {
    fourteenBullets();
  }
  else if (ammo == 15) {
    fifteenBullets();
  }
  else if (ammo == 16) {
    sixteenBullets();
  }
  else if (ammo == 17) {
    seventeenBullets();
  }
  else if (ammo == 18) {
    eighteenBullets();
  }
  else if (ammo == 19) {
    nineteenBullets();
  }
  else if (ammo == 20) {
   twentyBullets();
  }
  else if (ammo == 21) {
   twentyoneBullets();
  }
  else if (ammo == 22) {
    twentytwoBullets();
  }
  else if (ammo == 23) {
    twentythreeBullets();
  }
  else if (ammo == 24) {
    twentyfourBullets();
  }
  else if (ammo == 25) {
    twentyfiveBullets();
  }
  else if (ammo == 26) {
    twentysixBullets();
  }
  else if (ammo == 27) {
   twentysevenBullets();
  }
  else if (ammo == 28) {
   twentyeightBullets();
  }
  else if (ammo == 29) {
   twentynineBullets();
  }
  else if (ammo == 30){
   thirtyBullets();
  }
  else {
    zeroBullets();
  }
}
void zeroBullets()
           //0
{ digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);

        //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void oneBullet()
          //1
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}

void twoBullets()
          //2
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void threeBullets()
          //6
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void fourBullets()
          //4
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void fiveBullets()
          //5
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void sixBullets()
          //6
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void sevenBullets()
          //7
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void eightBullets()
          //8
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void nineBullets()
              //9
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);

          //0
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void tenBullets()
              //0
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void elevenBullets()
              //1
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void twelveBullets()
             //2
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void thirteenBullets()
          //3
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void fourteenBullets()
          //4
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void fifteenBullets()
          //5
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void sixteenBullets()
          //6
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void seventeenBullets()
          //7
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void eighteenBullets()
          //8
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void nineteenBullets()
          //9
{  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //1
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);
}
void twentyBullets()
        //0
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentyoneBullets()
        //1
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentytwoBullets()
        //2
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentythreeBullets()
        //3
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentyfourBullets()
        //4
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, HIGH);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentyfiveBullets()
        //5
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentysixBullets()
        //6
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, HIGH);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentysevenBullets()
        //7
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, HIGH);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentyeightBullets()
        //8
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}
void twentynineBullets()
      //9
{  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, HIGH);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, LOW);
  delay(10);

          //2
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, HIGH);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}

void thirtyBullets()
        //0
  digitalWrite(one, LOW);
  digitalWrite(ten, HIGH);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, LOW);
  digitalWrite(Pf, LOW);
  digitalWrite(Pg, HIGH);
  delay(10);

          //3
  digitalWrite(one, HIGH);
  digitalWrite(ten, LOW);
  digitalWrite(Pa, LOW);
  digitalWrite(Pb, LOW);
  digitalWrite(Pc, LOW);
  digitalWrite(Pd, LOW);
  digitalWrite(Pe, HIGH);
  digitalWrite(Pf, HIGH);
  digitalWrite(Pg, LOW);
  delay(10);
}

THE ERROR REPORT:
Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"

Digital_Ammo_Counter.ino: In function 'void loop()':

sketch_Digital_Ammo_Counter:138:4: error: 'thirtyBullets' was not declared in this scope

    thirtyBullets();

    ^~~~~~~~~~~~~

sketch_Digital_Ammo_Counter.ino:138:4: note: suggested alternative: 'twentyBullets'

    thirtyBullets();

    ^~~~~~~~~~~~~

    twentyBullets

sketch_Digital_Ammo_Counter.ino: At global scope:

sketch_Digital_Ammo_Counter:898:3: error: expected initializer before 'digitalWrite'

   digitalWrite(one, LOW);

   ^~~~~~~~~~~~

sketch_Digital_Ammo_Counter:899:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(ten, HIGH);

               ^

sketch_Digital_Ammo_Counter:900:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pa, LOW);

               ^

sketch_Digital_Ammo_Counter:901:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pb, LOW);

               ^

sketch_Digital_Ammo_Counter:902:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pc, LOW);

               ^

sketch_Digital_Ammo_Counter:903:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pd, LOW);

               ^

sketch_Digital_Ammo_Counter:904:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pe, LOW);

               ^

sketch_Digital_Ammo_Counter:905:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pf, LOW);

               ^

sketch_Digital_Ammo_Counter:906:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pg, HIGH);

               ^

sketch_Digital_Ammo_Counter:907:8: error: expected constructor, destructor, or type conversion before '(' token

   delay(10);

        ^

sketch_Digital_Ammo_Counter:910:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(one, HIGH);

               ^

sketch_Digital_Ammo_Counter:911:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(ten, LOW);

               ^

sketch_Digital_Ammo_Counter:912:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pa, LOW);

               ^

sketch_Digital_Ammo_Counter:913:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pb, LOW);

               ^

sketch_Digital_Ammo_Counter:914:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pc, LOW);

               ^

sketch_Digital_Ammo_Counter:915:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pd, LOW);

               ^

sketch_Digital_Ammo_Counter:916:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pe, HIGH);

               ^

sketch_Digital_Ammo_Counter:917:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pf, HIGH);

               ^

sketch_Digital_Ammo_Counter:918:15: error: expected constructor, destructor, or type conversion before '(' token

   digitalWrite(Pg, LOW);

               ^

sketch_Digital_Ammo_Counter:919:8: error: expected constructor, destructor, or type conversion before '(' token

   delay(10);

        ^

sketch_Digital_Ammo_Counter:920:1: error: expected declaration before '}' token

 }

 ^

exit status 1
'thirtyBullets' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The way this got formatted absolutely screwed up the copy/paste of my program and my error report. If you would like to help me and need to see something that looks more like my actual program and/or error report, I can arrange to email either document.

upvote for checking the format of your posted code ... so many people just don't serm to care if the code is readable .... put three backticks ``` in a line above your code and three backticks in a line after your code

you can also select all of the code and click the {} button

I have formatted the code for you. +1 for caring

Thank you all very much! I'll keep the formatting fixes in mind from now on and thank you, kind person, for taking the liberty to format my code for me.

Don't feel bad about the missing curly brace. That causes most compilers to "lose their minds," generating a whole bunch of very confusing error messages, and can be very hard to track down. I've been programming in C and C-like languages for >30 years, and this exact problem still bites me from time to time.

Haha, thanks! Yeah, I figure we all fall prey to simple oversight from time-to-time. With more experience, I am sure I'll be able to pick up on mistakes like this more quickly. I'm just glad that the community is so good! I have to say, I wasn't expecting all the support I have been getting! It's fantastic and I hope that I too will be of some assistance to the next generation of beginner electronics enthusiasts.

It helps that you provided a complete description of your problem. Lots of beginning posters post post vague "I tried ... but it doesn't work" questions, and then it takes an exhausting game of 20 questions to figure out what "it doesn't work" actually means

While I'm aware a code review isn't what is being asked for, I would strongly urge you to reconsider your approach here. Copy/pasting code should be an immediate red flag to suggest that you need to approach this more cleverly. A basic suggestion that you can tackle as a beginner would be a method that prints a given digit (and then your number logic becomes digit + digit logic). If you work with the bloated and increased code that you have now, any change or bug is going to take up much more time than it should. What happens if you can have up to 99 bullets tomorrow?

Here's some advice I give all of my students: Compilers compile syntactically correct programs, and catch & report basic errors, but they're useless at allowing for the errors they've already seen. One simple error, such as your missing brace, can often cause a whole cascade of error messages that seem unrelated to the original error. Fix the first error (or 2, if you notice that the 2d one is real) and recompile. You'll find that one mistake with "tons of error messages" pretty quickly and save a lot of time over trying to analyze the following, correct, pieces of code.

The best advice that I can give is, once the code compiles (and I personally do not tolerate any warnings, ever), is to learn how to use the debugger. It is your best friend in all the world. Set "breakpoints", run your code and it will stop when it encounters a breakpoints, at which point you can examine the call stack, read and even change the value of variables, and more. It's by  far the best way to et insight into what your code is doing.

The error cascade is caused by the missing opening curly bracket { at the start of the thirtyBullets() function. This causes the function name to be not declared and also the following function calls to digitalWrite() to fail. Putting in this missing opening curly bracket should fix all the errors (though I cannot test it since I don't have a compiler at hand currently).
Besides that, your code can be made way shorter with a trick. Currently you use one function for every number, where you write the corresponding digital pins. So the situation is, that you always need to write to the same pins, just different values depending on a simple unsigned integer number. So I suggest, that you define the pin patterns for the digits in a 2 dimensional array. Then you can use only 1 function to output any of them. I will give you an example:
uint8_t led_pattern[10][7]= {
    {0, 0, 0, 0, 0, 0, 1}, // pattern for the digit 0
    {1, 0, 0, 1, 1, 1, 1}, // pattern for the digit 1
    {0, 0, 1, 0, 0, 1, 0}, // pattern for the digit 2
    ...
    {0, 0, 0, 0, 1, 0, 0}}; // pattern for the digit 9

void display_digit(uint8_t position, uint8_t digit){
    digitalWrite(one, position); // Writes low (aka zero) to pin one, when position is zero, else high
    digitalWrite(ten, !position); // Writes low to pin ten, when position is greater than zero, else high

    for(uint8_t i=0; i<7; i++){
        digitalWrite(i, led_pattern[digit][i]);
    }
    delay(10);
}

void display_number(uint8_t number){
    display_digit(0, number % 10);
    display_digit(1, number / 10);
}

void loop(){
    display_number(ammo);
}

So, what is happening here?
First we define the LED patterns in a 2 dimensional array. It's first index is the digit, that we want to display; it's second index is the number of the LED to light. The value then is the state of the corresponding LED. I wrote 1 and 0, because it is short. You could also write HIGH and LOW (since these are also only defines for 1 and 0). So the pattern {1, 0, 0, 1, 1, 1, 1} means, that only the segments b and c output low, thus are turned on.
Then we define a function to display one digit. It takes the position of the digit and the actual digit (0 to 9) as parameters. We write the two outputs for our position directly with the variable. This is a very short way to do it and it doesn't work, when you have more than 2 digits. If you want to extend your counter one day, you can replace these 2 lines by a different construct (for example a switch case statement). Then we do a for loop from 0 to 6, so that we go through all the digits. In your case you use the pin numbers 0 to 6, so we can directly use i as pin number. (If you want to use other pins, you could save those pins in an array and reference the values in the array with i). In every iteration of the for loop, we write the value for the corresponding digit and LED to the corresponding output pin. After that, we only delay a short time and leave the function.
To make it easier, I also defined the function display_number(), which will display the complete number, by displaying the it's digits successively on the corresponding positions. If you are a beginnner, you might not recognize, what calculations I made there. The modulo operator % returns the rest of an integer division. So if I take 23 % 10 this would return 3 (integer division 23 / 10 is 2 and the rest is 3). This gives us the first (least significant) digit. We can then get the second digit by simply doing an integer division with 10, as it will cut the part after the decimal point. If you want to display numbers greater than 99 one day, you have to change both functions to accomodate for that.
Note, that I used uint8_t as type everywhere. This is just the smallest unsigned number type (8 bit wide). I used the smallest, since you don't need greater numbers here and it saves a bit of memory. When you want to extend your display to show values greater than 255, you need to change the type of the number parameter in the display_number() function to a greater type, for example unsigned int (which is 16 bits wide).
Also note, that I have not tested this code, since I don't have a compiler or Arduino at hand currently.

So now, you can display a number on your digit with just one function call and you don't need nearly 1000 lines of code for it.
When extending your code to do more things, than displaying numbers, you can easily get to the point, where using delay() is a bad thing, since the Arduino cannot do anything else during that time. Then you need to rewrite your code to avoid delay() and use the millis() function instead to make it unblocking. There are tons of tutorials out there for this and I just wanted to mention it.

Good lord! I am kicking myself in the butt hard for forgetting something so humble as a "{"! It has caused me great suffering. I bow down before your Arduino knowledge and thank you for not only finding the error in my code, but also for showing me a much better way to go about the entire process! You have my very most sincere thanks! Wow, I will definitely dig deeper into tutorials on Arduino! Hopefully I will be as knowledgeable as you on the subject at some point!

Thank you, but that's enough of praise. We all started at that point. It's all about the learning experience. You can accept my answer as correct, if you think, it is correct. And maybe you want to come back some day and also answer question yourself. We are always happy to find new contributors :D

Well done, providing both the narrowly focused answer AND guidance on using arrays to solve the problem more elegantly. (voted.) I guess we're not gonna try to walk a beginner through decoding binary using bit masking & shifting...

since I don't have a compiler at hand currently) I suggest https://godbolt.org/, Matt Godbolt's compiler explorer.  It has GCC, Clang, MSVC and ICC installed, including GCC for ARM and for AVR.  With color highlighting to match source lines to asm output lines.  (And languages including C, C++, Rust, Go, Haskell, ...)  Your code compiled as C for ARM cortex M3: https://godbolt.org/z/-K_muB

You've found the bug, but how could you have found it easier?
The most important step mentally is to accept that you did something wrong. We don't know yet what, but it is exceedingly unlikely that the compiler complains about correct code. So the question is: What did you do wrong?
The compiler complained about a function "thirtyBullets". It didn't complain about "twentynineBullets". It doesn't realise that there is a function "thirtyBullets". The first thing is to check the spelling. If you named the function "thirrtyBullets" by mistake, that would explain things. But the name is right.
Then you see that the compiler complains about the line immediately after the start of the function. Hard to figure out what the compiler is complaining about, so something you did just before confused it. So now you check the line "void thirtyBullets()", that's Ok, the next line "digitalWrite(one, LOW);" looks Ok but something MUST be wrong here, and that's where you hopefully figure out the missing "{".

Just to add to the idea of using an array—since C does not care about whitespace you can quite easily format your data like this:
uint8_t led_pattern[10][7]= {
      {0,  // pattern for the digit 0
     0,  0,
       0,
     0,  0,
       0},

      {0, // pattern for the digit 1
     0,  1,
       0,
     0,  1,
       0},

      {1, // pattern for the digit 2
     0,  1,
       1,
     1,  0,
       1},
      ...
};

This is an example of the "good habit" of making your code about your intent rather than about instructing the machine. You can spend 50% more time making your code clear, or spend 500% more time debugging it. As the saying goes,

There are two ways to develop software: Make it so simple that there are obviously no bugs, or so complex that there are no obvious bugs.

Note: The above code will give you your digitalOut values in a different order to your pins (so chrisl's for loop won't work.) You can just manually do 7 digitalWrites to the correct pins when displaying the digit.
digitalWrite( <pin number> , led_pattern[digit][ <led position> ]);


text:
How will I display values from arduino to JTextArea (Java Netbeans)?
I want to display float values in JTextArea but it doesn't show any. It only displays on the systemout. Pls help me out. This is my Java code.
import jssc.SerialPort;
import jssc.SerialPortException;

    public ards() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        jLabel1.setText("jLabel1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextArea1.setEditable(false);
        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(319, 319, 319)
                        .addComponent(jButton1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(154, 154, 154)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(140, 140, 140)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(157, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(74, 74, 74)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addGap(18, 18, 18)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(94, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
         String str;

        //In the constructor pass the name of the port with which we work
        SerialPort serialPort = new SerialPort("COM6");

        try {
            //Open port
            serialPort.openPort();

            //We expose the settings. You can also use this line - serialPort.setParams(9600, 8, 1, 0);
            serialPort.setParams(SerialPort.BAUDRATE_9600,
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);

            Thread.sleep(1000);//Very important !!!

            //Read data from port
            for (int i = 0; i < 1000; i++) {
                str = serialPort.readString();

                if (str != null) {
                    System.out.println(str);
                   jTextArea1.setText(str);
                    jLabel2.setText(str);
                }

                Thread.sleep(500);
            }

            //Closing the port
            serialPort.closePort();

        } catch (SerialPortException ex) {
            System.out.println(ex);
        } catch (InterruptedException ex) {
            System.out.println(ex);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ards.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ards.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ards.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ards.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ards().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration
}

And this is my Arduino code
const int model = 0;
void setup() {
Serial.begin(9600);
}

float sensitivity[] ={
0.185, // for ACS712ELCTR-05B-T
0.100, // for ACS712ELCTR-20A-T
0.066 // for ACS712ELCTR-30A-T } ;

void loop() {
static unsigned long count=0;
static float Vsum=0;
float Vave=0;
int volt = analogRead(A1);
float voltage= map(volt,0,1023, 0, 2500)/100.0;
Vsum=Vsum+voltage;

static float Csum=0;
float Cave=0;
 float milli = pow(10, -3);
 float current = (voltage / sensitivity[model]);
 float current1 = current*milli;
Csum=Csum+current1;
count++;
Vave=Vsum/count;
Cave=Csum/count;

Serial.print("Average voltage: ");
Serial.print(Vave,2);
Serial.println("V");
Serial.print("Average current: ");
Serial.print(Cave,3);
Serial.println("A");
Serial.println("-----");
delay(3000);

}

part of the java code is properly formatted ... please format all of the code

So that means, that the data is correctly received by your java code (because you see it on systemout)? That means, that your Arduino and even your serial read java code is correct and your problem lies purely in setting the textarea. That doesn't have to do anything with Arduino.

In you code : str = serialPort.readString();
Change this as ->   str = serialPort.readStringUntil('\n');


text:
expected unqualified id before token
here is the code.
PROBLEM:- if I use for the loop the error comes "expected unqualified-id before for .......but if I use the void loop instead of for loop...the code is run without any error. Meanwhile, I needed for loop .
long int Distance = 0;  // Record the number of steps we've taken
//LOW LOGIC MOVEMENT BACKWARD and GEARS MOVE clocwise
// PIN 18 FOR DIRECTIRON
// PIN 19 FOR STEP  INPUT
int y= 10^-6;
long int k;
long int h= 1600;
void setup() {
Serial.begin(9600);
  pinMode(18, OUTPUT);
  pinMode(19, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
  digitalWrite(18,LOW);
  digitalWrite(19, LOW);
 digitalWrite(14, LOW);
 digitalWrite(15, LOW);
}
for ( k=0; k<=h; k++)
{
  //if we are at the end of our move
  digitalWrite(19, HIGH);
  delayMicroseconds(100);
  digitalWrite(19, LOW);
  delayMicroseconds(100);
  Distance = Distance + 1;   // record this step
  //k=Distance;
//   Check to see
  if (Distance ==h)
 {
   // We are! Reverse direction (invert DIR signal)
   if (digitalRead(18) == LOW)
    {
     digitalWrite(18, HIGH);
   }
   else
   {
     digitalWrite(18, LOW);
   }
//    Reset our distance back to zero since we're
 //   starting a new move
   Distance = 0;
  //   Now pause for half a second
    delay(1000);
  }
  }
}

It looks like you intended the for-loop to run to completion once. If that is correct, just include it and its entire block of code within and at the end of the setup() function. You will still need to provide a loop() function but it can be empty:
void loop(){
   ;
}

If, instead, you wanted the for() loop to be run repeatedly, enclose it in the loop() function:
void loop(){
   for ( k=0; k<=h; k++ )
   {
   ...
   }
}

The setup() function runs once after a power up or reset. The loop function then gets called repeatedly, forever. Put your functional code in whichever one fits your purpose.
The reason for the error message is that, as you've written the for-loop, it is outside of a function, but executable code (as opposed to defining global variables) is only valid within a function.

You need the void loop() function on your sketch. This function gets called directly after the setup. If it's not there, then the program cannot compile. You cannot put any execution code (means code other than declarations and such) outside of a function.
Depending on what exactly you want to achieve, you have 2 options:

If you want the program to only run once and then stop until the next reset, you can put your code inside the setup() function and leave the void loop() function empty ( with this: void loop(){ } ).
If you want the program to repeat itself indefinitely after the for loop, you can put the code inside the void loop() function.

Whatever you choose, you need the void loop() function.
Note: The void loop() function is part of the Arduino world. In general all programs for microcontroller in C/C++ have a function called main(). It is the function, that starts the execution of the program. Without it no program would actually run. The Arduino framework wraps this main() function up and gives you directly one function to execute the initialization code (void setup()) and one function, that runs after that and loops indefinitely (void loop()). This infinite loop is an important thing, because the microcontroller has no OS or such that he can return to. If you don't have an infinite loop there, the execution can go on to the next address in the program, where you don't know what it contains.

Also the line int y= 10^-6; does not, what you might think it does. In C/C++ the ^ is not the power function, but will do a bitwise OR operation. You will have to use a function for this, for example the pow(value1, value2) function. You can use google to find one of the many examples, how to use it.
And in the same line, (I assume as above) you want to tell Arduino to put a value much smaller than 1 (a value between 0 and 1) into an integer variable. It will contain 0. int means integer and cannot hold decimal numbers (number with something after the decimal point). It can hold numbers like -1,0,1,2,3 in the range from -32768 to 32767 (because it is 16 bits wide on the Arduino UNO and Mega). You will have to use the float type for this.

“10^-6” should be written 1e-6 rather than pow(10, -6).


text:
Compiling Error - exit status 1 for DHT11 using Arduino UNO (code/process/connections same as website given bellow)
https://create.arduino.cc/projecthub/MisterBotBreak/how-to-use-temperature-and-humidity-dht-sensors-9e5975
Copied Error Message:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

In file included from C:\Users\soumy\OneDrive\Documents\Arduino\libraries\DHT-sensor-library-master\DHT_U.cpp:15:0:

C:\Users\soumy\OneDrive\Documents\Arduino\libraries\DHT-sensor-library-master\DHT_U.h:36:10: fatal error: Adafruit_Sensor.h: No such file or directory

 #include <Adafruit_Sensor.h>

          ^~~~~~~~~~~~~~~~~~~

compilation terminated.

exit status 1

Error compiling for board Arduino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The code:
#define DHTPIN 2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {

  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}

what is your question?

The compiler couldn't find the file Adafruit_Sensor.h. Have you installed the Adafruit sensor library correctly?

@chrisl i didnt add the adafruit library, now it's working. Thanks!!

I didn't download the "Adafruit Sensor Library"
https://github.com/adafruit/Adafruit_Sensor
It ran after I added it.


text:
Pool pump man-in-the-middle SDA/SCL with ESP32
Hey all I have found some code on GitHub that works with my pool pump but it seems my model is a little newer than the one they used on on their GitHub. Most things seem to work but what doesn't is that the buttons on the control board do not seem to call out correctly to the main board.
The code for the buttons look to be this:
#define BUTTON_BOOST        0x44
#define BUTTON_TIMER        0x46
#define BUTTON_POWER        0x4C
#define BUTTON_LOCK         0x4E
#define BUTTON_SELF_CLEAN   0x74

The bulk of the data seems to be coming from void IRAM_ATTR Core1( void* p) {...
And perhaps within that is the button code?
if (sendingKeyCode) {
   if (totalBitsSent < 8) {
       digitalWrite(dataPin, (buttonStatus << totalBitsSent) & 0x80 ? HIGH : LOW);
       totalBitsSent++;
   }
   // FALLING edge 8 while sending keycode
   else if (totalBitsSent == 8) {
       // Receive ACK
       pinMode(dataPin, GPIO_MODE_INPUT);
       digitalWrite(dataPin, HIGH);
       totalBitsSent++;
   }
   // FALLING edge 9 while sending keycode
   else {
       sendingKeyCode = false;
       totalBitsSent = 0;
   }
}

I did the rest api call (http://192.168.1.173:8080/api/v1/intex/swg/status) and got this:
{
    "data": {
        "display": {
            "status": "ON",
            "brightness": 3,
            "current_code": "."
        },
        "status": {
            "power": "STANDBY",
            "boost": "OFF",
            "sleep": "OFF",
            "o3_generation": "OFF",
            "pump_low_flow": "OFF",
            "low_salt": "OFF",
            "high_salt": "OFF",
            "service": "OFF"
        },
        "mode": {
            "working": false,
            "programming": false
        }
    }
}

So I know it can communicate with it just fine. And I also did this debug rest api call (http://192.168.1.173:8080/api/v1/intex/swg/debug) and got this back:
{
    "data": {
        "powerStatus": "0x01",
        "statusDigit1": "0x00",
        "statusDigit2": "0x02",
        "statusDigit3": "0x00",
        "displayingDigit1": "0x00",
        "displayingDigit2": "0x02",
        "current_code": ".",
        "readBuffer": "[0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X48, 0X01], [0X68, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6C, 0X00], [0X49, 0XFF], [0X48, 0X01], [0X6A, 0X02], [0X49, 0XFF], [0X48, 0X01], [0X00, 0X00]",
        "compilation_date": "Apr 27 2023",
        "compilation_time": "16:20:36",
        "otaUpdating": false,
        "removeWifiConfig": false,
        "machineON": true,
        "wifiReconnecting": false,
        "readingMaster": true,
        "sendingKeyCode": false
    }
}

Would be great if someone more knowledgeable at binary and SDA/SCL would help me find my buttons binary code so that I can send that code to the pool pumps main controller.
The GitHub> https://github.com/jingsno/intex-swg-iot

do not seem to call out correctly ... they either do, or do not ... there is no seem to ... print the button code that is received and adjust your code to respond to the code that is received


text:
ESP8266 wifi module sending data via jQuery
Hey all I have the ESP8266 module and I have already set it up and it's working good. However, when I run this HTML page code here:
<html>
    <head>
        <title>ESP8266 LED Control</title>
    </head>
    <body>
    <button id="6894" class="led">Toggle Pin 13</button> <!-- button for pin 13 -->

    <script src="jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".led").click(function(){
                var p = $(this).attr('id'); // get id value (i.e. pin13, pin12, or pin11)

                $.get("http://192.168.9.60:80/", {pin:p}); // execute get request
            });
        });
    </script>
    </body>
</html>

I have to send the number 6894 instead of 13 because for some reason its not sending out the correct number. If i send 13 then what it receive is 114. When i send 6894 i receive 689.
My arduino code is this:
*/
//====================================================================================
//                                [The SSDI of the current wifi router]
//                                |              [The password of the current wifi router]
//                                |              |
//                                V              V
String SSIDandPW    = "AT+CWJAP=\"xxxxxxwifi\",\"xxxxxx123\"\r\n";

//                                      [The STATIC IP of the wifi module]
//                                      |                [The main IP of the router]
//                                      |                |              [The default submask]
//                                      |                |              |
//                                      V                V              V
String eIPrIPmask   = "AT+CIPSTA_DEF=\"192.168.9.60\",\"192.168.9.1\",\"255.255.255.0\"\r\n";
const int ledDimmer = 5;         // Used to dim the LED strip (digital Pin 3)

SoftwareSerial esp8266(9,10);    // Pin D10 to=> TX on ESP8266 | Pin D9 to=> RX on ESP8266
//================================= End define WiFi Module =================================
//==========================================================================================

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

  pinMode(13, OUTPUT); //Just for a wifi demo from html page

  //================================ Start Setup WiFi Module =================================
  //==========================================================================================
  esp8266.begin(19200);
  sendData("AT+RST\r\n",                    2000, true); // Reset module
  sendData("AT+CWMODE=1\r\n",               2000, true); // Configure as access point
  sendData(SSIDandPW,                       5000, true); // Pass of current wifi
  sendData("AT+CIPMUX=1\r\n",               2000, true); // Configure for multiple connections
  sendData("AT+UART_DEF=19200,8,1,0,0\r\n", 2000, true); // Set baud of COM
  sendData(eIPrIPmask,                      2000, true); // Default network mask IP
  sendData("AT+CIPSERVER=1,80\r\n",         2000, true); // Turn on server on port 80
  sendData("AT+GMR\r\n",                    2000, true); // Get firmware version
  sendData("AT+CIFSR\r\n",                  2000, true); // Get ip address
  Serial.print("Server is now running!");
  //================================ End Setup WiFi Module ===================================
  //==========================================================================================
}

void loop() {
  //=========================================== Start Loop WiFi Module ===========================================
  //==============================================================================================================
  if(esp8266.available()) {                               // check if the esp is sending a message
    if(esp8266.find("+IPD,")) {
      delay(500);
      int connectionId = esp8266.read() - 48;             // subtract 48 because the read() function returns

      esp8266.find("pin=");                               // advance cursor to "pin="
      int retunedNum = (esp8266.read() - 48) * 100;       // get first number (example: 123.. this would be "1")
      retunedNum += (esp8266.read() - 48) * 10;           // get second number (example: 123.. this would be "2")
      retunedNum += (esp8266.read() - 48);                // get last number (example: 123.. this would be "3")
      String closeCommand = "AT+CIPCLOSE=";               // make close command
      Serial.print("returned: ");
      Serial.print(retunedNum);
      Serial.print("----------");
      closeCommand += connectionId;                       // append connection id
      closeCommand += "\r\n";
      sendData(closeCommand,                250, true);   // close connection
      //digitalWrite(retunedNum, !digitalRead(retunedNum));   // toggle pin
      if (retunedNum == 6894) {
        Serial.print("OFF");
        digitalWrite(ledDimmer, LOW);
      } else if (retunedNum == 6904) {
        Serial.print("ON");
        digitalWrite(ledDimmer, HIGH);
      } else if (retunedNum == 689) {
        digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
        delay(1000);              // wait for a second
        digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
        delay(1000);              // wait for a second
      }
    }
  }
  //============================================ End Loop WiFi Module ============================================
  //==============================================================================================================
}

//                     [The data/command to send]
//                     |                  [The time to wait for a response]
//                     |                  |                [Print to Serial window (true = yes | false = no)]
//                     |                  |                |
//                     V                  V                V
String sendData(String command, const int timeout, boolean debug) {
  String response = "";
  long int time   = millis();

  esp8266.print(command);          // send the read character to the esp8266

  while((time + timeout) > millis()) {
    while(esp8266.available()) {
                                   // The esp has data so display its output to the serial window
        char c = esp8266.read();   // read the next character.
        response += c;
    }
  }

  if (debug) { Serial.print('Returned: ' + response); }
  return response;
}

And the console output is this:
14880AT+RST

OK
14880
"qXÑ{ÂB!É
1Â±þ)ÒBÙa
+ò“H!a5)�#)ÒÂia%YakN‘ J!ÐCÊ!�
÷þˆ2ô
ready
14880AT+CWJAP="xxxxxxwifi","xxxxxx123"

OK
14880AT+CIPMUX=1

OK
14880AT+UART_DEF=19200,8,1,0,0

OK
14880AT+CIPSTA_DEF="192.168.9.60","192.168.9.1","255.255.255.0"

OK
14880AT+CIPSERVER=1,80

OK
14880AT+GMR

AT version:0.22.0.0(Mar 20 2015 10:04:26)
SDK version:1.0.0
compile time:Mar 20 2015 11:00:56

OK
14880AT+CIFSR

+CIFSR:STAIP,"192.168.9.60"
+CIFSR:STAMAC,"18:fe:34:9b:4e:68"

OK
Server is now running!

returned: 689----------148804 HTTP/1.1
Host: 192.168.9.60
Connection: AT+CIPCLOSE=0

0,CLOSED

OK

What I really am wanting to do is have a way to send a 10 charater string to the arduino instead of the limited 3 numbers above. I just am not sure what i need to add/modify in order to make it see letters/numbers and only the first 10 that i send.
Any help would be great!

Just do this straight on the ESP8266 no need for an arduino. You should try it as the ESP8266 is not a Wifi add on for arduino but is a controller with wifi.

  int retunedNum = (esp8266.read() - 48) * 100;       // get first number (example: 123.. this would be "1")
  retunedNum += (esp8266.read() - 48) * 10;           // get second number (example: 123.. this would be "2")
  retunedNum += (esp8266.read() - 48);                // get last number (example: 123.. this would be "3")

Your code always expects the pin number to have 3 digits.
In case of 13, it takes a space character as the last digit.
It reads charachters '1', '3' and ' '. Their ASCII codes are 49, 51 and 32. With this, the calculated number is
(49 - 48) * 100 + (51 - 48) * 10 + (32 - 48) = 114.

With 6894, it just uses the first three digits and ignores the last.
For 1 or 2 digit long number you could just pad it with '0' character i.g. "013".
If you want to read an arbitrary string, you should replace the above code with this code:
String retunedStr = "";
for(;;) {
    char c = esp8266.read();
    if (c == ' ')
        break;
    retunedStr += c;
}

And obviously replace
Serial.print(retunedNum);

with
Serial.print(retunedStr);

With this, you should only use letters (A-Z, a-z), numbers (0-9), dash (-) and an underscore (_) for the string.
If you use other characters, you could have problems with the URL character encoding.

This is what i get when sending "testing123".... returned: 0,298:GET

Actually i take that back. I moved the code to a different part and i do get the correct text from what i sent... but now it takes about 21 seconds to show up when it used to be once i clicked the button 1 second latter it was there in the output. If the code looping too much to cause this?

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


text:
ESP8266 based wifi IR Universal Remote for A/Cs
I have been working on a prototype for a wifi based universal remote controller and i have been using the IR-Remote library for the same. But i have a couple of questions which google couldn't help with.
So, the problem is that there are some remotes like hitachi or some other brands that aren't recognised by the library and the coding type shows "UNKNOWN". The raw dump shows an array of 211 integers like such:
Timestamp : 012012.059
Encoding  : UNKNOWN
Code      : 794B7E67 (106 bits)
Library   : v2.4.0

Raw Timing[211]:
   +  3424, -  3352,    +   378, -  1336,    +   376, -   454,    +   458, -  1254,
   +   378, -  1334,    +   378, -   454,    +   460, -   352,    +   396, -  1336,
   +   460, -   356,    +   394, -  1334,    +   458, -   364,    +   466, -  1256,
   +   458, -   356,    +   392, -  1336,    +   458, -  1258,    +   456, -  1254,
   +   378, -   452,    +   460, -   360,    +   470, -  1256,    +   458, -   298,
   +   532, -   366,    +   466, -  1256,    +   458, -  1256,    +   458, -   358,
   +   472, -  1256,    +   458, -  1254,    +   458, -   358,    +   472, -   304,
   +   526, -  1258,    +   456, -   298,    +   532, -   362,    +   466, -   368,
   +   464, -  1256,    +   456, -  1258,    +   456, -  1258,    +   456, -  1256,
   +   378, -  1336,    +   458, -   360,    +   470, -   304,    +   524, -   364,
   +   466, -   364,    +   464, -   310,    +   522, -  1232,    +   482, -  1256,
   +   456, -   304,    +   526, -   310,    +   520, -   306,    +   524, -   370,
   +   462, -  1256,    +   456, -  1260,    +   454, -  1232,    +   480, -   306,
   +   524, -   366,    +   464, -   312,    +   516, -  1236,    +   478, -   368,
   +   462, -   368,    +   462, -   368,    +   386, -   454,    +   454, -   372,
   +   456, -   374,    +   458, -   372,    +   460, -   306,    +   524, -   372,
   +   458, -   370,    +   460, -   308,    +   520, -   312,    +   444, -   452,
   +   376, -   454,    +   452, -   308,    +   524, -   368,    +   462, -   372,
   +   458, -   306,    +   522, -   374,    +   458, -   368,    +   460, -   306,
   +   524, -   374,    +   458, -   308,    +   522, -   372,    +   460, -   370,
   +   458, -   374,    +   460, -   364,    +   464, -   370,    +   460, -   304,
   +   450, -   454,    +   452, -   308,    +   522, -   370,    +   460, -   368,
   +   386, -   452,    +   452, -   374,    +   456, -   312,    +   520, -  1260,
   +   452, -  1262,    +   452, -   376,    +   456, -   372,    +   458, -   376,
   +   454, -   378,    +   380, -  1334,    +   452, -  1260,    +   452, -  1264,
   +   378, -  1336,    +   378, -  1310,    +   476, -   320,    +   438, -   452,
   +   378, -   428,    +   402

uint16_t rawData[211] = {3424, 3352,  378, 1336,  376, 454,  458, 1254,  378, 1334,  378, 454,  460, 352,  396, 1336,  460, 356,  394, 1334,  458, 364,  466, 1256,  458, 356,  392, 1336,  458, 1258,  456, 1254,  378, 452,  460, 360,  470, 1256,  458, 298,  532, 366,  466, 1256,  458, 1256,  458, 358,  472, 1256,  458, 1254,  458, 358,  472, 304,  526, 1258,  456, 298,  532, 362,  466, 368,  464, 1256,  456, 1258,  456, 1258,  456, 1256,  378, 1336,  458, 360,  470, 304,  524, 364,  466, 364,  464, 310,  522, 1232,  482, 1256,  456, 304,  526, 310,  520, 306,  524, 370,  462, 1256,  456, 1260,  454, 1232,  480, 306,  524, 366,  464, 312,  516, 1236,  478, 368,  462, 368,  462, 368,  386, 454,  454, 372,  456, 374,  458, 372,  460, 306,  524, 372,  458, 370,  460, 308,  520, 312,  444, 452,  376, 454,  452, 308,  524, 368,  462, 372,  458, 306,  522, 374,  458, 368,  460, 306,  524, 374,  458, 308,  522, 372,  460, 370,  458, 374,  460, 364,  464, 370,  460, 304,  450, 454,  452, 308,  522, 370,  460, 368,  386, 452,  452, 374,  456, 312,  520, 1260,  452, 1262,  452, 376,  456, 372,  458, 376,  454, 378,  380, 1334,  452, 1260,  452, 1264,  378, 1336,  378, 1310,  476, 320,  438, 452,  378, 428,  402};  // UNKNOWN 794B7E67

Now for such AC remotes which are unknown, which are more common than i thought would be, it is a matter of best implementation. I know I can save these arrays in variables and send them using .sendRaw(array, sizeof(array, freq) but then I will have to store about 15 such arrays for multiple brands. Even if I save ir codes for five different protocols, i'll be making a table of 5 * 15 = 75 huge arrays. i don't think that is a good practice nor the ESP8266 will be able to store all that.
What can be the best way to do this? What am I missing? Is there a better way to do this?

the SPIFFS file system on flash of the esp8266 can be 3 MB big if the flash has 4MB

By this i think you are suggesting that i can store that huge data without problem, is that it? But is it the best practice? Won't I have to store raw data arrays for all remotes like this?

Also, if i occupy a lot of space, wont that create problem when update the device using OTA?

SPIFFS and sketch are ota updated separate. SPIFFS with IDE plugin from data subfolder

"Best practice" would be to implement the protocol in the library properly. Just because it's not supported doesn't mean it can't be supported.


text:
How to make an arduino wifi repeater?
I am trying to make a wifi repeater. My router's signals don't come to my study and instead of buying a proper wifi repeater I prefer making one.
I want to learn how to make a simple wifi repeater that:

repeats/boosts my existing home wifi network by connecting to it.
Has some kind of a GUI or something that allows me to connect to it first (from some smartphone or PC) to configure it to my home network. It should find and show wifi networks around and then connect to the one I want it to upon my command.

I am new to electronics. Arduino is my preferred platform. If there are other easy to do alternatives that shall work too.
Any kind of help will be appreciated...tutorials, blogs, etc.

"Arduino is my preferred platform." Not for a wifi repeater it isn't.

Get a router that support OpenWRT. That way you can still "hack" the unit.

You can do three things: 1) cheapest and can use arduino 2) use a SBC (raspberry pi or derivatives) 3) hackable router. Solution 1 is to buy a cheap wifi repeater and, if you want an arduino, glue it to the front or back. Ta-da! Arduino wifi repeater... Jokes apart, the other solutions are serious. Using an SBC (like raspberry pi, or I found orange pis to be quite good) and two wifi adapters (or sometimes only one, but depends on the adapter - or if the SBC has one onboard) you can make a repeater. You will have to do all the work, starting from a bare linux environment, or use a ...continue

common distribution for routers (e.g. openwrt or ddwrt) to have almost all of its job done. Maybe the throughput won't be the maximum one, but you will have a simple and cheap solution. The alternative is to buy a router which already have openwrt or ddwrt ready for them. Look at the distribution's help pages to find a list of supported devices. Usually they are more expensive than generic routers, but YMMV...

An arduino wifi repeater would in theory be very slow. Since you need to record the bit stream to the internal memory, then switch the spi to the transmitter, and send the bit stream, im unsure about what would happen if you miss a few bits in the process.
Arduino Wifi Shield - the price of a wifi shield 85 usd
Wifi repeater ebay the price of a wifi repeater 22 usd.
This makes me question why one would go through the troubble of making a wifi repeater of an arduino.
Even investing in a raspberry pi and a wifi dongle would be less expensive.

Indeed - lots of people have bought cheap wifi access points to hack as wifi interfaces for their arduinos, because at points in recent history you have been able to get an entire wifi router for less than the cost of a wifi shield.

Get a very cheap module called ESP8266, particularly the ESP-01, then flash a program called esp_wifi_repeater (which uses the arduino IDE)
https://github.com/martin-ger/esp_wifi_repeater
I have tested it several times it is pretty fast and with a ESP to USB adapter it steps down 5vdc from USB to it's usable 3.3v of the module

Would you need 2 ESP8266 for a repeater? The ESP8266 only appears to have 1 antenna.

I tried flashing this on my esp8266 esp-015 and it wouldnt work for some reason. I got the binaries from the git repo and everything. No clue why it wont start

At this very moment, I'm making a repeater with an ESP01 and it's working great for IoT purposes. I've seen folks on Github saying it would have speed issues for regular browsing but didn't test this myself. @Leonardo, I only managed to flash my chips using esptool.py with -fs detect and -fm dout

the network parts are "owned"by the yun side of the board.
the yun acts like a mini linux pc, who can seperatly connect trough a bridge library to the arduino. so.. i think you could do it or make it a router that would probaply be easier, but this all wouldnt depend on arduino code, more depend on if there are WRT packages who can do this.. i thinks they should exist as this linux variant is in other routers too.
(better route then repeat btw, repeats puts delays on your entire lan)

authors: พี่พีช พัชรพล

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


text:
Arduino + ESP8266 - poll file from a server?
I really need all the help I can get...
It's been a week now and I'm still not able to solve the problem.
I have text file on a server. The whole address is www.example.com/test.txt
I want to read the file using a GET request every 3-5 secs and parse it for further actions. But the arduino codes that I've tried till now use software serial and it keeps misbehaving. Sometimes it skips a few serial-print commands and loops back sometimes it reads the file 3-4 times and then hangs. Basically I'm getting the response only a few times but then it stops working properly.
I want to solve this...I need a working arduino code to work with ESP8266 so that I can successfully poll a text file from server without any problems.
Here is my current code -
 #include<SoftwareSerial.h>

    #define led 13
    SoftwareSerial esp(11, 12);
    String domain = "www.example.com";
    String request = "GET /test.txt HTTP/1.0\r\n\r\n";

    void SerialDo(String command, float time, bool debug) {
      delay(100);
      esp.print(command);

      int i = millis();
      while (millis() - i < (time * 1000)) {
        while ( (esp.available())) {
          if (debug) {
            Serial.print((char)esp.read());
          }
        }
      }

      Serial.flush();
    }

    void setup() {
      // put your setup code here, to run once:
      digitalWrite(led, OUTPUT);
      Serial.begin(9600);
      esp.begin(9600);
      esp.setTimeout(3000);
      digitalWrite(led, LOW);
      Serial.println("Hello");
      //delay(2000);
      SerialDo("AT+RST\r\n", 5, true);
      Serial.flush();
      SerialDo("AT+CWMODE=1\r\n", 0.5, true);

      delay(1000);
      //SerialDo("AT+CWLAP\r\n", 5, true);
      SerialDo("AT+CWJAP=\"Sherlock\",\"Watson@11\"\r\n", 10, true);
      SerialDo("AT+CIPMUX=0\r\n", 0.5, true);

    }

    void loop() {

      delay(1000);
      Serial.print("loop\r\n");

      SerialDo("AT+CIPMUX=0\r\n", 0.5, true);
      SerialDo("AT+CIPSTART=\"TCP\",\"" + domain + "\",80\r\n", 1.5, true);
      esp.flush();

      esp.print("AT+CIPSEND=" + String(request.length()) + "\r\n");
      delay(100);
      esp.print(request);

      String t = "";
      int i = millis();
      while (millis() - i < 1500) {
        while ((esp.available() > 0)) {
          if (true) {
            char c = (char)esp.read();
            t += c;
            Serial.print(c);
          }
        }
      }

      esp.print("AT+CIPCLOSE\r\n");

      if (t.indexOf("hello world") > -1) {
        digitalWrite(led, !digitalRead(led));
      }
  }

Which Serial.print()s are being omitted? By response, you mean the complete text file, right? How large is the text file?

It seems that you're trying to do the same thing:

https://www.youtube.com/watch?v=q02f4sPghSo

Maybe it will help, I'm tryin' to do that (a POST), only that I don't have the server on a text file.

Welcome to Arduino SE. Link-only answers are generally discouraged because it relies on the link's destination staying online. Could you expand your answer to include some of the essential information please? Thanks.

You aren't implementing the timeouts well and I don't see the point of this if:
if (true) {
   char c = (char)esp.read();
   t += c;
   Serial.print(c);
}

It will always be executed. You have allotted 1500 ms to the whole process of reading the whole file, whether the ESP is done or not. Inside the loop, you are calling Serial.print(), as well as concatenating chars to a string, which takes a significant portion of the 1.5 secs. Get rid of the Serial.print() and use the timeout this way:
unsigned long lastRead = millis();
while (millis() - lastRead < 1500) {
    while (esp.available() {
        t += (char)esp.read();
        lastRead = millis();
    }
}
Serial.print(t);

Storing the value of millis() with an int isn't a good idea since after about 33 seconds, it'll overflow. The code above will ensure that the last time a character was read is always stored in lastRead; the end result is that no character is available from the ESP after a continuous 1500ms, we conclude that there's nothing more to be read or some error has occurred. Repeat this for the loop in SerialDo as well. The setTimeout in your setup() is also unneeded, in this case; you didn't call any SoftwareSerial method that makes use of it, so remove the line. Also if your server supports HTTP 1.1, then try this request:
    String request = "GET /test.txt HTTP/1.1\r\nHost: www.example.com\r\n\r\n"