text:
TSX0108 logic level converter not working
Am trying to setup logic level converter with arduino for eps8266 WiFi module. Am using this logic level converter but it’s not working not sure what am doing am not getting any output.
My circuit
Red wire : 3.3v power source
Orange wire : 5v power source
Blue wire : ground.
Yellow wire : arduino TX1 on B2
White wire : output on A2

Multi meter it red wire : 3.3 v showing on display

Multi meter it orange wire : 4.68 v showing on display

Multi meter it yellow wire : 4.36 v showing on display

**Multi meter it white wire : no voltage showing on display ??? **

Update : have set OE pin to enable and swapped red and orange. Still no output for yellow wire

power the 5 V side with 5 V and the 3.3 V side with 3.3 V (swap orange and red wre)

@Juraj i switched orange and red wire  but no output yet , can u check updated image i added

try with a pin set HIGH

@Juraj ya TX RX  pins of arduino are always high , i can get voltage when on multi meter when connect it with yellow wire, but in front of no voltage on white wire.

datasheet of TXB0108: "The A  port is designed to track VCCA. VCCA accepts any supply voltage from1.2 V to 3.6 V. The B port is designed to track VCCB. VCCB accepts any supply voltage from 1.65V to 5.5 V." "The TXB0108 is designed so that the OE input circuit is supplied by VCCA.". did you damage it with 5 V?

hmmmm seems its burned out , i will buy another one then will try

When the output-enable(OE) input is low, all outputs are placed in the high-impedance (Hi-Z) state.  You must connect the OE pin to logic high to enable the outputs.

hmmmm no success i have set OE to high but no output for yellow wire yet , can you check updated image i added


text:
Non-blocking incrementation with single button pressure
I am looking for a way to increment a variable by one each time a button is pressed. Current approach is the following :
    if (redButton.isPressed())
    {
        a++;
        delay(100);
    }

isPressed() just return true if the pin state is HIGH.
delay(100) is used to compensate the small amount of time the button is being pressed. Otherwise a would be incremented multiple times in a single press. But it's blocking behavior, my program can't do anything else during that delay.
In short I'm looking to add a method in my Button class to detect if the button "has just been released".

Have you seen the Bounce2 library? https://github.com/thomasfredericks/Bounce2

In your approach a button press will be detected every 100ms when you just keep the button pressed. So you have to set a flag when the button is pressed. When the button is not pressed while your flag is set, that's the event you're looking for. In this way you can detect both a button press and a release respectively.
As @JRobert mentioned, there still has to be an amount of time between two calls to such a routine to provide some button debouncing.
bool pressed_flag=false;
bool button_timestamp=millis();
uint16_t button_period=100;

if(millis()-button_timestamp>button_period){
  button_timestamp=millis();
  if(redButton.isPressed() && !pressed_flag){
    // button has just been pressed
    // you can do sth. here
    pressed_flag=true;
  }
  else if(!redButton.isPressed() && pressed_flag){
    // button has just been released
    // you can do sth. here
    pressed_flag=false;
  }
}

Also use either a timer library, or hand-code with millis(), to come back and check the button after a time. That interval defends against contact chatter or bounce (multiple inputs for a single press). Using the flag prevents you "detecting" one long button press multiple times. And your code will still not get blocked.

@JRobert theoratically my code is allready non-blocking. But I aggree: it doesn't include any debouncing and my routine should only be called in a specific period.

Agreed - it doesn't block. I just intended to suggest the addition of chatter removal to your already appropriate solution. (And I got caught accidentally submitting a partially-edited comment! ):

@JRobert you're absolutely right, I added what you suggested!

source: Stack Exchange

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

sort: votes


text:
Creating WebServer with 5000 port with AT command(ESP-01f)
I'm setting webserver with toggle led. I want to create global webserver. I`m mean hat use server with global ip. For it I must use port too. global ip/local ip:port.
I want to create on 5000 port. I'm used for ESP-01f and connect it arduino. Communicating by SoftwareSerial. I used AT+CIPSTA for static ip. When I used AT+CIPSERVER=1,5000 it worked. But when I connect to it, it works, but in second connection it doesn't want to connect itor when I use digitalWrite it doesn't connect to this server. How can I solute this problem?
code:

#include <SoftwareSerial.h>

SoftwareSerial softSerial(10, 11);
String ssid = "ssid";
String ip = "staticip";
String gateway="gateway";
String sub="submask;
String password = "password";
String _response = "";
#define DEBUG true
void setup()
{

  Serial.begin(115200);

pinMode(2,OUTPUT);

  softSerial.begin(115200);
  connectWifi();
}

void connectWifi() {

  do {

    sendData("AT+RESTORE\r\n", 5000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT\r\n", 2000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT+CWMODE=1\r\n", 1000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT+CWJAP=\"" + ssid + "\",\"" + password + "\"\r\n", 5000, DEBUG);
  } while (softSerial.find("OK"));
   do {

    sendData("AT+CIPSTA=\"" + ip + "\",\"" + gateway +"\",\"" + sub + "\"\r\n", 2000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT+CIFSR\r\n", 1000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT+CIPMUX=1\r\n", 1000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT+CIPSERVER=1,5000\r\n", 1000, DEBUG);
  } while (softSerial.find("OK"));

}

String sendData(String command, const int timeout, boolean debug)
{

  String response = "";

  softSerial.print(command);        long int time = millis();
  while ((time + timeout) > millis())
  {
    while (softSerial.available())
    {

      char c = softSerial.read();
      response += c;
    }
  }

  if (debug)
  {
    Serial.print(response);
  }

  return response;
}

void loop()
{

if(softSerial.available()){
  if(softSerial.find("+IPD,"){
   int connectionId = softSerial.read()-48;
softSerial.find("pin/");
int pin = softSerial.read()-48;

String htmlCode = "<label>"+String(pin)+"</label>";
digitalWrite(pin,HIGH);
sendData("AT+CIPSEND="+String(connectionId)+","+htmlCode.length()+"\r\n",1000,DEBUG);
sendData(htmlCode+"\r\n",1000,DEBUG);

sendData("AT+CIPCLOSE="+String(connectionId),3000,DEBUG);

  }
}
}

don't use restore. it clears the settings part of the flash. you wear out the flash. use AT+RST. set AT+CWAUTOCONN=0 if you don't want the esp8266 to start the connection on startup or use _CUR commands to not save the connection to flash

you should read all the request bytes. what is on pin 2?

On pin 2 led...

How can I read all request bytes

And sometimes it write -49. WHY.

use the WiFiEsp library

read() returns -1 if no data are available. you subtract -48

Juraj WIFIEsp Library. How can I use it?

Let us continue this discussion in chat.

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


text:
How to read a text file line by line
I am making an LED controller that reads instructions from a text file on my computer. I need to get the arduino to read this text file line by line and put each line into the appropriate variables. I'm using a sparkfun pro micro which is a knock off arduino pro micro. The pro micro is connected via USB
I've seen people use the SD library, but I don't know if this will work for my situation because I am reading directly from the computer and not an SD card. Is this the correct approach, or is there an additional/alternate library that I need to use?

You have Serial. That's all you have. Read the data, parse it. On the PC use some software to send the file (Putty, for example).

What you can do is:

Read character by character and copy it to a temporary buffer of the maximum length of one line.
When you parsed an end of line symbol, you start parsing the (complete) line in the buffer.
In this line parsing (preferably a separate function), you parse the line, using string to type conversion functions, like atoi (string to an inter) etc. Also you can use the C function strtok to split the string based on a symbol (e.g. comma).
After parsing the line, clear the buffer (you already processed it), and continue filling the buffer again until it is full.
Don't forget to check for end of file.

Can that be done through the SD library?

No. As I mentioned in my comment to your question, all you have is Serial. You can only read what something on the PC happens to send to the Arduino.

As Majenko says, only Serial. The SD library (https://www.arduino.cc/en/Reference/FileRead) has functions to read, either one by one or a predefined amount, in both cases, it's unrelated to the end of a line, so you need the C parsing functions.

The Arduino cannot read data on the PC.
Instead the PC has to send the data to the Arduino, and the Arduino has to parse (interpret) that data.
You need two things:

A piece of software running on the PC that sends the file contents to the Arduino over serial
Software on the Arduino that accepts the stream of data coming in over the serial port and does something with it.

It is no different to handling commands that are manually typed by someone using the Serial Monitor - it's just they tend to come in a lot faster when being sent by the PC from a file.


text:
Arduino is incorrectly reading serial input from C# program
I am trying to create a program to operate my arduino based LED controller. I'm pretty sure that my C# program is outputting to serial port correctly as I double checked the output in Debug.WriteLine(). The program is supposed to send information to the arduino in the following format (newlines included):
mode
number of colors
blend speed
beats until color change
Red   <---
Green <---
Blue  <---
Brightness <---

the last 4 are the only ones that matter for now as I am trying to get the LED's to show up one solid color first before worrying about other modes or patterns. The debug writeline loop output of my last test looks like this
1
1
0
1
209
255
255
219

This should be translating to the relevant arduino variables the same way but instead, I only get white light that seems to randomly brighten or darken when I mess with the color/brightness sliders
My code for the arduino is below. I am very new to this so it's probably not even close to right. getData() at the bottom is the function that most likely is the culprit, but I'll put the rest in just in case:
#include <SPI.h>
#include <Adafruit_DotStar.h>

#define NUMPIXELS 60

Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DOTSTAR_BRG);

// Variables
int mode;
int numColors;
int fadeSpeed;
int BBCC;
int R;
int G;
int B;
int Bright;
String buff;

void setup() {
  strip.begin();
  strip.show();
  //Serial.begin(9600);
}

void loop() {
  getData();

  if (mode == 1)
  {
    //strip.setPixelColor(0, R, G, B);
    strip.setBrightness(Bright);
    strip.show();
  }
}

void getData()
{
 // if (Serial.available() > 0)
 // {
    buff = Serial.read();
    int result = buff.toInt();
   mode = result;
   if (mode != -1)
   {
    buff = Serial.read();
    int result = buff.toInt();
    numColors = result;
    buff = Serial.read();
    result = buff.toInt();
    fadeSpeed = result;
    buff = Serial.read();
    result = buff.toInt();
    BBCC = result;
    buff = Serial.read();
    result = buff.toInt();
    R = result;
    buff = Serial.read();
    result = buff.toInt();
    G = result;
    buff = Serial.read();
    result = buff.toInt();
    B = result;
    buff = Serial.read();
    result = buff.toInt();
    Bright = result;//Serial.read();
    strip.setPixelColor(0, R, 0, 0);
    //strip.setBrightness(Bright);
    strip.show();
   }
   else
   {
    strip.setPixelColor(0, R, 0, 0);
    //strip.setBrightness(Bright);
    strip.show();
   }
//  }
}

You should only read from Serial, when there is actually something to read in the buffer.

How can I check if something is in there?

Serial.read() reads a single character (or -1 if there isn't one there).  https://majenko.co.uk/blog/reading-serial-arduino

Your Serial receive code is not correct in some ways:

You should only read from Serial, if there is really something to read. For the first read, that is not the problem, since you checked against the return value being -1 (which is the return code for "there is no new data in the buffer). But after that, you read without ever checking, if there is something to read. You need to understand, that the data is really send serially. The bytes come in one after another and there is no concept as messages on the Serial interface (which is actually called UART in non-Arduino environments). More over, there might be small pauses somewhere in the transmission, since you cannot foresee, when exactly the PC will send the data (the PC has a bunch of other tasks to do, too). So it might be, that you have received one byte, which will lead you into the if statement, but the rest of the data will arrive later. All data is then read as -1, since there is no data in the buffer.
You have to check, if there is actually data to read, before reading. This can be done with Serial.available(). It will return the number of new data bytes in the buffer. For example, if you want to read 8 bytes, you should wait, until at least 8 bytes are inside the buffer by using if(Serial.available >= 8).
You are sending the data from the PC as ASCII encoded text. That means, that every number above 9 consists of multiple data bytes. The 4 values, that you are interested in, are all over 200, which means, that you need to read 3 bytes to get them. But you only call Serial.read() once for every value. That will give you the first digit, which is a 2 for all values in the shown data. More over, since you only read 1 byte, where there is the whole number (which may be multiple bytes) plus 1 or 2 bytes for the new line (depending on the chosen line ending \n or "\n\r"), The whole reading gets misaligned to the data structure. Now the read data (if there is any) is also dependent on how much data was send for the values before.
Keep in mind, that with ASCII encoded text, you may need multiple Serial.read() calls to actually read a full number. I will describe the way to go here in the next point.
As I already mentioned above, there is no message protocol on the Serial interface. Lost data would lead to misalignment and thus garbled data. But you can impose an own protocol onto the Serial stream of data. It is a good practice, to first receive a full message (maybe with multiple data values inside it) and then process it. For that I would suggest a new data structure
mode|number of colors|blend speed|beats until color change|Red|Green|Blue|Brightness\n

The new line is here realized only with a newline character (\n). The values are separated with a vertical dash. You should put an if(Serial.available()>0) into your loop function. Then inside that if statement, you read one character and add it to a buffer. If you read the \n character, you start to process the buffer. You can then convert one value after another from the buffer and save them into variables. After that, you clear the buffer. You can see this style in the SerialEvent example, that comes with the Arduino IDE. You should also read Majenko's blog article about reading the Serial interface on the Arduino.

That said, you should be cautious with using String object on the Arduino. Sure, Strings are convenient, but they dynamically allocate the needed memory during the runtime. On microcontrollers, which normally have very limited RAM memory, that can lead to heap fragmentation (heap is the memory area for dynamic memory allocation). When using String objects, the underlying buffer get's often recreated. As buffers get allocated and deleted later, that can lead to small memory areas, which are unused, but to small to actually be used by the buffer. You can fill up your RAM very fast with that.
It is better to not use String, but directly a char array with a fixed length. Majenko also wrote an article about the String problem: The Evils of Arduino Strings

First off this is NOT how to read from the serial USART!
buff = Serial.read();
int result = buff.toInt();

Serail.read returns a single byte, you are treating it as a string, then trying to parse it; you will never see anything other than 0-9 if your lucky (its very unlikely that buff contains a valid string, chances are it will just keep going till it finds a \0, and return some random number, or just fail.
EDIT: It seems I was mistaken, the 'read()' returns an int, nominally only a byte is returned, but a 16-bit -1 (0xffff) is returned for an error; the documentation could be clearer here.
Second the arduino serial library has a huge flaw, -1 is used as a failure to read, but -1 (i.e. 255) could be a valid piece of data, this makes the return value useless, as you don't know if 255 is the correct value, or an error. The only way around this is with Serial.available so you must use this to control your code or you won't know whats going on.
Finally, you can write binary data in c# with .Write(byte[] ...) and then read it in binary back, so you don't have to parse it.

the -1 and 255 confusion exists only in 8 bit values ... a 16 bit integer would no longer have the confusion .... -1 = 0xff = 255 .... -1 = 0xffff = 65535

i just confirmed it on an Uno ... defined buff as integer int buff; .... serial.read() returns -1 (0xFFFF) when there is no data ... and returns 255 (0x00FF) correctly when 255 is sent

use Realterm to send 0xff


text:
How do I send multiple variables via stream to Unity?
So I currently have this for arduino.ino:
Serial.println(Variable1);

that does this in Unity:
string variable1 = stream.ReadLine();
float x = float.Parse(variable1);
transform.Rotate (0, -x/1000, 0);

My question is; How would I send 3 variables from the Arduino to Unity so I can put each value into the transform.Rotate function at once?
For example in pseudocode:
Arduino.ino
send(Variable1, Variable2, Variable3);

Unity
transform.Rotate(Variable1,Variable2,Variable3);

I hope this makes sense.
Thank you.

What you need to do is define a communication scheme/protocol. You appear to be using the Serial UART via USB.
Your first example has a simple scheme its simply the ASCII representation of the variable followed by a newline. i.e. :
float x = 123.45;
Serial.println(x);

this simply outputs
"123.45\n"

you could continue this pattern
float x, y, z,
... // assume x, y and z have values in them
Serial.print(x);
Serial.print(' ');
Serial.print(y);
Serial.print(' ');
Serial.println(z);

this outputs something like:
"123.43 23.34, 42.24\n"

then your receiving code will do do something like
string line = stream.ReadLine();
string[] parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries)
float x = float.Parse(parts[0]);
float y = float.Parse(parts[1]);
float z = float.Parse(parts[2]);

but this is very inefficient, since the arduino needs to convert the float to an ASCII string, then transmit that over the serial port, where its read on the other side, then parsed back into a float. One doesn't need to do this, you can do in binary, it won't be human readable, but it will use much less transmission space.
float x, y, z; // assume these are valid
Serial.write(&x, sizeof(float));
Serial.write(&y, sizeof(float));
Serial.write(&z, sizeof(float));
// n.b. one should write an end of message here or something else to frame the data

and on the other side
byte[] data = new byte[12];
stream.Read(data, 0, 12);

float x = BitConverter.ToSingle(data, 0);
float y = BitConverter.ToSingle(data, 4);
float z = BitConverter.ToSingle(data, 8);

You will generally also want some way to frame the data, so you might want to start with a simple message header, i.e.:
struct head
{
  int length;
  int code;
};

and you write it like:
head header; //assume this is valid
Serial.write(&header, sizeof(header));

then you can write you message.
You might also want to implement some sort of checksum, so you can verify that you got the data correctly.
You can create multiple message structures this way, i.e.
struct vect3d
{
  head header;
  float x;
  float y;
  float z;
}

just fill and send
vect3d v3;
v3.head.length = sizeof(vect3d); // one could subtract sizeof(head) off so the reader can always read the first 8 bytes and read the rest of the message from there
v3.head.code = VECT3D; // assume this is defined somewhere
v3.x = 123.5;
v3.y = 23.4;
v3.z = 42.24;

Serial.write(&v3, sizeof(v3));

On the other side one would read in the first 8 bytes, then read in the rest of the message based on the length, and parse it based on the code.


text:
Arduino pro micro crashing
My arduino pro micro started behaving weird. I noticed it had crashed with very simple code on it (basically just two lines of fastled code followed by a delay. Then it didn't appear as a USB device on my macbook anymore. I reset it (pulling the rst pin to gnd) and that then allowed me to upload smaller sketches but not bigger ones. The smaller sketch only works for a short period of time. then the arduino just stalls. (Serial output also stops). Any idea what i can do? Or do i just have to toss the board and get myself a new one?

Could you explain what happens if you try to upload bigger sketches? PS.
please note that the fastLED library is a few hundred lines of code. So that fact that your code is only two lines doesn't actually mean your program is simple or small.

the board doesn't appear via usb anymore. two LEDs on the board light up during the upload process and the board is lost Couldn't find a Board on the selected port. Check that you have the correct port selected.  If it is correct, try pressing the board's reset button after initiating the upload. Board at /dev/cu.usbmodem14101 is not available - Started to happen with smaller sketches too, so i just assume the board is fried.

You could try reflashing the bootloader, but I'm doubtful that would help. Have your tried a different USB port?


text:
MPU6050 Gyroscope does not give reliable readings
It gives reliable readings for a couple of seconds and then it becomes unreliable.
My arduino code is this:
#include<Wire.h>
const int MPU6050_addr=0x68;
int16_t AccX,AccY,AccZ,Temp,GyroX,GyroY,GyroZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU6050_addr);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void sendVector(float x, float y, float z) {
  Serial.print(x, 4);
  Serial.print("|");
  Serial.print(y, 4);
  Serial.print("|");
  Serial.println(z, 4);
}

void loop(){
  Wire.beginTransmission(MPU6050_addr);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050_addr,14,true);
  AccX=Wire.read()<<8|Wire.read();
  AccY=Wire.read()<<8|Wire.read();
  AccZ=Wire.read()<<8|Wire.read();
  Temp=Wire.read()<<8|Wire.read();
  GyroX=Wire.read()<<8|Wire.read();
  GyroY=Wire.read()<<8|Wire.read();
  GyroZ=Wire.read()<<8|Wire.read();
  //Serial.print(AccX);
  //Serial.print(AccY);
  //Serial.print(AccZ);
  //Serial.print(" || Temp = "); Serial.print(Temp/340.00+36.53);
  //Serial.print(" || GyroX = ");
  //Serial.println(GyroX);
  //Serial.print(" || GyroY = ");
  //Serial.println(GyroY);
  //Serial.print(" || GyroZ = ");
  //Serial.println(GyroZ);
  sendVector(GyroX, GyroY, GyroZ);
  delay(100);
}

The above sends data to unity which controls an object. The object works with the gyroscope and then due to the random readings it rotates quickly and randomly.

Have a look at an AHRS sensor fusion alogrithm which gives you quaternions/roll,pitch,yaw values and also makes values more stable.

I don't think you have given enough information to help you debug this, but i can try to give some advice:
First verify that the chip works correctly
Use the arduino plot monitor, and a sample program, to see the behavior of the chip and values over time; make sure its not a problem with the chip
Second verify that you are interpreting the values correctly
The MPU6050 outputs 16-bit data, but doesn't have 16-bit resolution, this means that the lower bits of the data are random, meaningless noise, and should be ignored/discarded.
If you are assuming that all 16 bits contain valid data, and your code is sensitive enough to be affected by those lower bits, then you will see unstable random data.
Third consider other (possible) obstacles
Try increasing the serial BAUD rate, you may be taking too much time and causing problems that way.
Maybe you are getting out of sync while reading from the chip, if there is additional data being sent, you could could build up a backlog in the buffer, and start interpreting messages incorrectly because you are reading part of one and part of another. Try using a library to talk to the chip, one that other people have used and is known to work; this could remove bugs you are blind to, or bugs that everyone will run into, but they have already been fixed in the library!


text:
Parsing HTML GET request with params with WiFiEsp
So I'm Setting up webserver with esp-01f+arduino uno. I'm using WiFiEsp library.
I want to toggle led on. Pin will be given in GET request by url.
Example:
host.com/?ledpin=9
How can I parse it, then get 9 number?
Code:

#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif

char ssid[] = "Twim";            // your network SSID (name)
char pass[] = "12345678";        // your network password
int status = WL_IDLE_STATUS;

int ledStatus = LOW;

WiFiEspServer server(80);

// use a ring buffer to increase speed and reduce memory allocation
RingBuffer buf(8);

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output.
  Serial.begin(115200);   // initialize serial for debugging
  Serial1.begin(9600);    // initialize serial for ESP module
  WiFi.init(&Serial1);    // initialize ESP module

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }

  Serial.println("You're connected to the network");
  printWifiStatus();

  // start the web server on port 80
  server.begin();
}

void loop()
{
  WiFiEspClient client = server.available();  // listen for incoming clients

  if (client) {                               // if you get a client,
    Serial.println("New client");             // print a message out the serial port
    buf.init();                               // initialize the circular buffer
    while (client.connected()) {              // loop while the client's connected
      if (client.available()) {               // if there's bytes to read from the client,
        char c = client.read();               // read a byte, then
        buf.push(c);                          // push it to the ring buffer

        // printing the stream to the serial monitor will slow down
        // the receiving of data from the ESP filling the serial buffer
        //Serial.write(c);

        // you got two newline characters in a row
        // that's the end of the HTTP request, so send a response
        if (buf.endsWith("\r\n\r\n")) {
          sendHttpResponse(client);
          break;
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (buf.endsWith("GET /H")) {
          Serial.println("Turn led ON");
          ledStatus = HIGH;
          digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
        }
        else if (buf.endsWith("GET /L")) {
          Serial.println("Turn led OFF");
          ledStatus = LOW;
          digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
        }
      }
    }

    // close the connection
    client.stop();
    Serial.println("Client disconnected");
  }
}

void sendHttpResponse(WiFiEspClient client)
{
  // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
  // and a content-type so the client knows what's coming, then a blank line:
  client.println("HTTP/1.1 200 OK");
  client.println("Content-type:text/html");
  client.println();

  // the content of the HTTP response follows the header:
  client.print("The LED is ");
  client.print(ledStatus);
  client.println("
");
  client.println("
");

  client.println("Click here turn the LED on
");
  client.println("Click here turn the LED off
");

  // The HTTP response ends with another blank line:
  client.println();
}

void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print where to go in the browser
  Serial.println();
  Serial.print("To see this page in action, open a browser to http://");
  Serial.println(ip);
  Serial.println();
}

Details gives me only this:
GET /favicon.ico HTTP/1.1
Host: 192.168.0.165:5000
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
Accept: image/webp,image/apng,image/*,*/*;q=0.8
Referer: http://192.168.0.165:5000/H
Accept-Encoding: gzip, deflate
Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7

First print to Serial all of the received request. Then look at it and think. How do you know that the payload is 9? What distinguishes it enough that you can always identify it in a request? What do you look for? Once you can answer these, you can then frame a more specific question to know how to implement your algorithm or just use google to find the right functions.

Can you easily say how to parse GET /pin=9?

And one more question how can I write it to serial?

I rolled back the edit. Don't change completlly a Question. Someone is maybe working on an Answer.

OK. Thanks. Juraj

Juraj can you give answer? Or I must explain more

Heey. Is anyone alive?

Where did you copy this code/sketch from? There are several C/C++ standard functions that can help parse the request. Also the Arduino String class contains several member functions for this. Do you want us to write/update the sketch for you?

Here is a tutorial https://techtutorialsx.com/2016/10/22/esp8266-webserver-getting-query-parameters/

Mikael Patel, if you can  please

The tutorial works only on esp8266 flashing

please update my sketch

EEEYYYYYEYEYEYEYEYEYEYEYEYEYEYEYE

HEY please update my sketch please,PLASE,PLASE

HEEY. Anybody . Update my sketch please

The answer is to use indexOf and substring functions of response String


text:
Send HTTP request from Arduino UNO+ESP8266
I am trying to send an HTTP request from from an Arduino UNO through an ESP-01 connected by Serial.
Communication with the ESP and connection to the AP work fine. But when i try to send an HTTP request to a server, it fails with a strange response from the ESP:

What are those strange characters coming from the ESP ?
(Note that other characters are mistaken as well, like the "http://xxx.col" instead of "http://xxx.com")
Here is the code I am using:

#include <SoftwareSerial.h>
#define RX 10
#define TX 11
String AP = "xxx";
String PASS = "xxx";
String HOST = "\"http://xxx.com\"";
String PORT = "80";
String tcp = "\"TCP\"";
String field = "field1";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
int valSensor = 1;
SoftwareSerial esp8266(RX,TX);

void setup() {
  Serial.begin(115200);
  esp8266.begin(115200);
  sendCommand("AT",5,"OK");
  sendCommand("AT+CWMODE=1",5,"OK");
  sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
}
void loop() {
 sendCommand("AT+CIPMUX=1",5,"OK");
 //String connection = "AT+CIPSTART="+ tcp +"," + remoteip + "," + portnum + "\r\n");

 String getData = "GET battery/add.php?RAWVOLT=99&VOLT=99&RAWCURR=99 HTTP/1.0\r\n"; //this is mockup data for testing purpose
 getData += "Host: xxx.000webhostapp.com\r\n"; // add the required header
 getData += "\r\n";

 sendData("AT+CIPSTART="+ tcp +"," + HOST + "," + PORT + "\r\n",150000,true);
 sendData("AT+CIPSEND=0," +String(getData.length()+4),4000,true);

 //sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
 esp8266.println(getData);delay(1500);countTrueCommand++;
 sendCommand("AT+CIPCLOSE=0",5,"OK");
}

 void sendCommand(String command, int maxTime, char readReplay[]) {
   ***similar to sendData below***
 }

 String sendData(String command, const int timeout, boolean debug)
{
    String response = ""; // ESP8266 sendData String
    esp8266.print(command); // send the read character to the esp8266

    long int time = millis();

    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(response);
    }
    return response;
}

use the WiFiEsp library

the hostname can't contain http://

You can't use SoftwareSerial at 115200 baud. The Arduino is not fast enough to keep up. Either switch to a board with a spare hardware UART or work out how to safely change the baud rate on your version of the ESP-01 to 9600.

@Juraj thanks, i removed the http://

@Majenko I changed to 9600 baud rate, still having the same issue :
`AT+CIPST@RT="TCP","app.⸮Kѡ⸮ͅ⸮⸮⸮嵅⸮⸮⸮⸮⸮b⸮⸮j
ERROR
`

did you change the baud rate of the AT firmware with AT+UART command?

When I try with the AT command, it fails: 1. at command => AT+UART=9600 Fail

AT+UART_DEF=9600,8,1,0,0. send it at 115200 baud. the AT firmware will remember it as default. then switch the SoftwareSerial to 9600 baud

@Juraj: Same response as before: 0. at command => AT+UART_DEF=9600,8,1,0,0 Fail

what is 0. at command =>?

it's nothing, just a comment to make the output easier to read. Basically the ESP fails to execute the AT command.

the response to AT+UART is not important. was it applied? btw. you have CIPMUX but you don't specify linkId with CIPSTART


text:
How to control the power of attiny13a via pin change interrupt?
I'm trying controll the power of attity13a and turn off/turn on the led.
I'm going to goals:
After to click on the button0
led will blicking 5 second nad then the attiny13a going to sleep.
After to click on the button1 then wake attiny13a up and then led will shane.

The button0 to sleep and blink the led.
the button1 to wake up and turn on the led.
Could you explain what is wrong in this sketch, please?
thank you for your answers.

code:
    #define F_CPU   1200000UL
    #define LED     PB2 // PB2
    #define BUTTON1 PB1 // PCINT1
    #define BUTTON0 PB0 // PCINT0

    #define HIGH         1
    #define LOW          0
    #define INPUT        0
    #define OUTPUT       1
    #define INPUT_PULLUP 2
    #define FALSE        0
    #define TRUE         1
    #define _BV(bit)    (1 << (bit))

    #include <avr/io.h>
    #include <avr/interrupt.h>
    #include <avr/sleep.h>
    #include <util/delay.h>

    void pinMode(uint8_t pin, uint8_t mode)
    {
        if(mode == OUTPUT) // Pin as output
            DDRB |= _BV(pin);
        else // Pin as input or input pullup
        {
            DDRB &= ~_BV(pin); // Set pin as input
            if(mode == INPUT_PULLUP)
                PORTB |= _BV(pin); // Enable pullup resistors
        }
    }

    void digitalWrite(uint8_t pin, uint8_t val)
    {
      if(val)
        PORTB |= _BV(pin);  // Set pin high
      else
        PORTB &= ~_BV(pin); // Set pin low
    }

    uint8_t digitalRead(uint8_t pin)
    {
      return !!(PINB & _BV(pin));
    }

    // go to sleep
    ISR(PCINT0_vect)
    {
       if(digitalRead(BUTTON0)){
            int i=0;
            while(i<10){
                blink();i=i+1;
            }
            set_sleep_mode(SLEEP_MODE_PWR_DOWN);
            sleep_enable();
            sleep_cpu();
        }
    }

    //wake up
    ISR(PCINT1_vect){
       if(digitalRead(BUTTON1)){
        digitalWrite(LED, HIGH);
       }
    }

    void blink(){
        digitalWrite(LED, LOW);
        _delay_ms(500);
        digitalWrite(LED, HIGH);
        _delay_ms(500);
    }

    int main(void)
    {
        pinMode(BUTTON0, INPUT_PULLUP);
        pinMode(BUTTON1, INPUT_PULLUP);

        pinMode(LED, OUTPUT);
        digitalWrite(LED, LOW);

        // Sets the Pin change interrupt mask PB0, PB1
        PCMSK |= _BV(PCINT0)|_BV(PCINT1);

        //Enables Interrupts globally after setup
        //sei();
        SREG |= _BV(SREG_I);

        while(TRUE){}
    }

Does the program work? If not, what is its behavior?

The led is on and nothing happens when click on the buttons

How is the LED wired?

Note that blink() lacks a delay in the HIGH state, and the tiny13 has no PCINT1_vect.

The short leg of led connected to GND.
The long leg of led connected to the resistor (1kOm) and to PB2

Updated the function of blink.

Could you explain, please, how to correctly go to power saving mode and wake attiny up from power saving mode?

You need to enable PCIE in GIMSK for PCINT interrupts to be recognised. Also all interrupts go through PCINT0_vect and you have to differentiate the pins within that.

Beside the problems stated above, your code also doesn't account for switch-bounce.

is the program actually being loaded into the attiny13a? ... are you able to run a simple program that blinks the LED?

#define F_CPU   1200000UL

#define LED     PB2 // PB2
#define BUTTON1 PB1 // INT0
#define BUTTON0 PB0 // PCINT0

#define HIGH         1
#define LOW          0
#define INPUT        0
#define OUTPUT       1
#define INPUT_PULLUP 2
#define FALSE        0
#define TRUE         1
#define _BV(bit)    (1 << (bit))

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>

void pinMode(uint8_t pin, uint8_t mode){
    if(mode == OUTPUT) // Pin as output
        DDRB |= _BV(pin);
    else // Pin as input or input pullup
    {
        DDRB &= ~_BV(pin); // Set pin as input
        if(mode == INPUT_PULLUP)
            PORTB |= _BV(pin); // Enable pullup resistors
    }
}

void digitalWrite(uint8_t pin, uint8_t val){
  if(val)
    PORTB |= _BV(pin);  // Set pin high
  else
    PORTB &= ~_BV(pin); // Set pin low
}

uint8_t digitalRead(uint8_t pin){
  return !!(PINB & _BV(pin));
}

//wake up
ISR(INT0_vect){
   sleep_disable();
   //cli(); // Turn off global interrupts
   digitalWrite(LED, HIGH);
}

void blink(){
    digitalWrite(LED, LOW);
    _delay_ms(1000);
    digitalWrite(LED, HIGH);
    _delay_ms(1000);
}

// go to sleep
ISR(PCINT0_vect)
{
   //cli(); // Turn off global interrupts
   if(!digitalRead(BUTTON0)){
        cli(); // Turn off global interrupts

        blink();

        digitalWrite(LED, LOW);

        sei(); // Turn on global interrupts
        set_sleep_mode(SLEEP_MODE_PWR_DOWN);
        sleep_enable();
        sleep_cpu();
    }
}

int main(void)
{
    //enabled external interrupt
    MCUCR=0;
    //MCUCR=0b00000000;
    GIMSK|=_BV(INT0); // enabled external interrupt INT0 - PB1

    // Sets the Pin change interrupt mask
    GIMSK|=_BV(PCIE);
    PCMSK|=_BV(PCINT0);//PB0

    pinMode(LED, OUTPUT);
    digitalWrite(LED, LOW);

    pinMode(BUTTON1, INPUT_PULLUP);//INT0 - PB1
    pinMode(BUTTON0, INPUT_PULLUP);//PCINT0 - PB0

    //Enables Interrupts globally after setup
    //SREG |= _BV(SREG_I);
    sei(); // Turn on global interrupts
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    sleep_cpu();

    while(TRUE){}

    return 0;
}


text:
How to use ESPAsyncWebServer with SoftwareSerial communicating ESP01f
I'm creating a web server with using host.com/?ll="some". But I read that I can use for it ESPAsyncWebServer for this things. And how can I use it without flashing esp? If possible give me link to the libraries.

You read wrong. That library is only for running on the ESP8266. You can only use it by directly writing software for, and flashing, the ESP8266. You can't use it by communicating over SoftwareSerial.

OK. Thanks...........


text:
How can I program an ESP 10 module
I buy an ESP-10 module and I want to upload custom room to its flash. The problem is that there is no way to access GPIO 0 pin! Is there some way around it to upload custom room without connecting GPIO 0 to the ground?
How in the earth should I program it without this pin?
here is an address to supplier's page which contains schematic and some other details.
https://www.tindie.com/products/George/esp8266-esp-10-module/#product-description

you can't. io 0 and io 2 are on this board connected and pulled up together

why are they connected? what is the purpose of this module?

for normal operation io 0 and io 2 must be pulled HIGH at startup. for flashing mode mode io 0 must be LOW and io 2 HIGH

You can't.  Not without physical modification to the PCB itself (remove the chip, scratch off a pad and trace, replace pad with fine enamelled copper wire tinned at the end, replace chip).  All you can use is whatever firmware is currently installed in the module.


text:
use of spec sensor in arduino uno
i have been trying to use NO2 spec senor in arduino UNO. how to write the code for it to get the output in terms of 'ppm' and how to give connection.with the helo of cross-sensitivity given in datasheet how to detect the interference gases from this sensor itself..the datasheet URL:
https://www.spec-sensors.com/wp-content/uploads/2016/10/3SP_NO2_5F-C-Package-110-508.pdf

Have you considered the sensor requires additional hardware to interface with an embedded processor?  The development kit sold for this sensor costs about $350.  While you may be able to build your own for a fraction of the price, I doubt you will be able to use this sensor with only a stock Arduino and some code.

In the specification sheet linked to in the post we find this:

-30+/-10nA/ppm

This is a very small amount of current.  The Arduino ADC is a voltage sensing device and (unless modified) has a range of 0 to the operating voltage of the Arduino.  Usually 3.3V or 5V.
Converting nano Amps to that range of voltage will require additional hardware.  A stock Arduino and code are unlikely to make use of such a sensor.
The conversion of such small amounts of current to voltages measurable by a stock Arduino is not trivial. And most answers do not fit into the short format of stack exchange.  Here is an Engineering Design News article on the subject.


text:
led chaser fill color effect
Please help. I am learning a lot about Arduino. Most all in lightning. I am a newbie. I play with nano and LED ws2812 and use fastled library.
What ask is to make effect like fill effect. For example with larson scanner/chaser.
for (int i = 0; i<NUM_LEDS; i++)
{
  leds[i]=CRGB::Red;
  FastLED.show();
  leds[i]=CRGB::Black;
  delay(50);
}

From that code above how to make LED stop and lit up and loop again and stop and lit up.  I want every LED stop the LED lit up even LED looping start again from first LED. It like this:

10000 01000 00100 00010 00001 10001 01001 00101 00011 10011 01011
  00111 10111 01111 11111

I really don't understand your problem description. It seems, that English is not your native language. Maybe you can write a better description or ask someone to help you with it. We need to understand the problem, to be able to help you.

Agree w/@chrisl, there is no "I have this problem" in the post. Assuming you are not seeing a lit LED traveling down the line of LEDs, try swapping the "delay" line of code w/the line above it.

yes you right, iam not native english,iam indonesia.. sorry for my bad english and wrong title.. :).. but thank you all for advice.. i already have answer from @michel keijzers..

You need two counter for this, one to keep track of how far the LED bar is filled, and one about the current 'running' LED to eventually 'touch' the LEDs which are already moved to the right.
Every led (currentLed) will run from index 0 until the last filled index, while the last filled index is decreased with 1 after every loop.
(note: I haven't checked the code).
// Fill from the right, thus count backwards.
for (int filledLedIndex = NUM_LEDS; filledLed >= 0; filledLed--)
{
   // Now let a LED run from 0 upto filedLedIndex;
   for (int currentLed = 0; currentLed < filledLedIndex)
   {
      // Make previous LED black
      if (currentLed > 0)
      {
         leds[i - 1] = CRGB::Black;
      }

      // Make current LED red
      leds[i] = CRGB::Red;

      // Show.
      FastLED.show();
      delay(50);
   }
}

// Clear all LEDs.
for (int led = 0; led < NUM_LEDS; led++)
{
    leds[i] = CRGB::Black;
}

FastLED.show();
delay(50);

thanks you a lot.. from your advice n little edit for my project and it finally work fine..


text:
Increasing range of a DC-offset signal (software)
I am trying to read a signal with a DC offset of 511 (as seen by the ADC). The signal's tiny with regards to the offset, and I'm feeding it to a library that does a Fourier transform on it. It comes from a 3.5mm audio jack with AC coupling and the offset so I can see the full signal.
How may I increase the range of the signal? I am thinking something like the input signal is (490-530) and I want an output of (400-630) or something (numbers solely for example). The issue is that I still need the resulting signal to be centered around 511 AND I don't know the exact amplitude of the input (since it varies based on volume and particular audio going in at the moment).
I can assume that the volume of the audio input is relatively fixed (I need to be able to adjust this gain later, but I'm assuming the volume will be constant at some value per time I'm running the project), so I don't need envelope-following or something, but I'm not sure how to do this even so.

You need to add an op-amp to increase the signal gain before you feed it into the ADC.

This sounds like an XY problem to me. Why do you want to increase the signal range? What problem do you think you will solve by doing this?

I can't feasibly modify the hardware for this project. I need the FFT to register sounds without the audio source being turned to eardrum-rupturing levels, so it needs to be in software. I'm looking for some sort of filter that I can run on the array of samples that, say, doubles the offset each value has from the center. I would actually need it to do a smoother mapping (an example in a non-offset design would be values 0-30 become 0-100, so 15 is now 50. I could handle that, but not with the offset, though the same general idea applies). Would this do anything too weird to the FFT result?

You can't magic more resolution out of thin air (well, you can, but it slows down your sampling - you would "oversample" and average a number of sequential samples).
Instead you need to boost your signal before it gets to the ADC using an op-amp.  The simplest circuit (which also inverts the signal, but you don't really care about that I suspect) is:

simulate this circuit – Schematic created using CircuitLab
That circuit will both invert the signal (if you care, just do a little bit of maths in your program to flip the signal, but for FFT you don't really care) and double the amplitude around the mid-point. The doubling is controlled by the ratio of R1 to R2 (20000:10000 = 2:1 = doubled). The mid-point offset is created by R3/R4 - you don't need to manually add your own offset.

This was my first idea, but I'm trying to fix up a project I've already built that does not have room to add more components. I also have no op-amps on hand. As a result, I'm looking for a way to fudge the input into a larger numeric range via some sort of mapping.


text:
Arduino Micro & Thin polymer lithium batteries
Is this battery:

Polymer Lithium-ion Battery
Model Number: PGEB014461
https://www.powerstream.com/p/PGEB014461.pdf

Producing enough energy to power the following Arduino-micro project:
Battery (thin, flexible) to be worn. It will be safely encased (See below)
I would also be using a micro heart pulse sensor module:

https://pulsesensor.com/
https://cdn-shop.adafruit.com/product-files/1093/Pulse+Sensor+Data+Sheet-2018.pdf

and a transmission module
(bluetooth, WiFi, IR, etc...  whichever is suggested or judged appropriate for an alpha project(Needs to be reliable for short range))
Edit: Clarifications about safety standards applied and "do not bend" comments...

They do not have to be kept flat. The 0.5 mm cells can be flexed or bent into a cylinder, into a hat band, belt, etc.

As previously mentioned, the battery will be safely encased and will not go against these warnings...

Do not immerse the battery in water or seawater, and keep the battery in a cool dry environment during stands by period.
Do not use or leave the battery near a heat source such as fire or heater.
When recharging, use the battery charger specifically for that purpose.
Do not reverse the position (+) and negative (-) terminals.
Do not connect the battery to an electrical outlet.
Do not dispose the battery in fire or heat.
Do not short-circuit the battery by directly connecting the positive (+) and negative (-) terminal with metal objects such as wire.
Do not transport or store the battery together with metal objects such as necklaces, hairpins etc.
Do not strike or throw the battery against hard surface.
Do not directly solder the battery and pierce the battery with a nail or other sharp object.

Comments are not for extended discussion; this conversation has been moved to chat.

The Arduino Micro requires 5V. It runs at 16MHz, and you can't run at 16MHz at voltages below about 4V.
To run off a 3.7V battery you need an Arduino board that runs at 8Mhz, such as the "3.3V Pro Micro" from Sparkfun.
To know if your battery is suitable for your project you need to work out the hourly average current draw. That is the proportion of "active" and "inactive" times for each of the devices (transmission duty cycle for your transmitter, sleep times for your MCU, etc).  Until you know that you can't know the capacity (mAh) you need for your project to run for the desired amount of time between charges.

You can also drop the idea of an Arduino and branch out. A board that is probably tailor made for your project is the Adafruit Feather M0 Bluefruit LE which is designed to run from a Lithium Polymer batter (and even includes the charger) and has bluetooth built in.

In a word, no. You need to provide an Arduino Micro with either > 6.5V unregulated into the barrel connector, or a regulated 5V supply directly to the 5V line.
You could use a buck/boost DC/DC converter to boost your 3.7V battery output to 5V and feed that directly into the 5V line on the Arduino (or better, feed it into the USB connector, since that will use the input switching on the Arduino.)
This one, for example:
https://www.banggood.com/DC-DC-3V-15V-to-5V-Fixed-Output-Automatic-Buck-Boost-Step-Up-Step-Down-Power-Supply-Module-p-1355829.html?gmcCountry=US&currency=USD&createTmp=1&utm_source=googleshopping&utm_medium=cpc_bgs&utm_content=frank&utm_campaign=pla-elc2-us-pc-0720&ad_id=368005069105&gclid=EAIaIQobChMI2pfb0Zj54wIVmeDICh2egQ_iEAQYAyABEgLVgvD_BwE&cur_warehouse=CN
Or this one: https://www.digikey.com/reference-designs/en/ac-dc-and-dc-dc-conversion/dc-dc-smps-single-output/1592?utm_adgroup=Converters&gclid=EAIaIQobChMIvM6-9pf54wIVxMDICh36XAxlEAAYASAAEgJsF_D_BwE
Or this one: https://www.adafruit.com/product/2190

To whoever down-voted my answer, can you explain what you found lacking?

to that person; I'm canceling all your down votes with a up-vote, gl. haha

If somebody thinks my answer was poor then a down-vote is fine. I'd like some feedback on what was wrong with my answer however.

he down-voted Majenko answer too...

"he?" I don't know of any way to tell who's doing the down-voting.


text:
I´m trying to make a kind of videogame with Arduino UNO
it´s a school project, but I'm having some problems to create a menu selection. In the LCD, all the character are overwriting, I'm a beginer, so i dont have any idea of what i was doing wrong (ps.: sorry about my english, i'm a brazilian.
Here goes the code:
//A portable "atari" videogame project, including 3 games
#include <LiquidCrystal.h>
//define os pinos a ser utilizados no arduino uno,etc.
#define btcima 9
#define btbaixo 8
#define bttiro 10
#define menu 11

LiquidCrystal lcd(7,6,5,4,3,2);

int vel=100;
 int pxnave,pynave,pxaste,pyaste,pxtiro,pytiro;//px=posição x, py=posição y, etc
bool game1,game2,game3,vtiro;//vtiro=variavel de tiro
int pontos;
int maxpontos=15;
int vtela;
byte nave[8]={B00000,B01100,B00110,B11111,B00110,B01100,B00000,B00000};
byte asteroide[8]={B01110,B10111,B11111,B11101,B10111,B01110,B00000,B00000};
byte explosao[8]={B10101,B00010,B11000,B10101,B01010,B10110,B01101,B10011};
byte tiro3[8]={B00000,B00000,B11110,B11111,B11111,B11110,B00000,B00000};

int      line[4] = {0,1,2,3},
         line_bk[4],
         index,
         menu_number = 0;

boolean  menu_flag  = 0,
         enter_flag = 0,
         sub_menu = 0;

void readButts();
void list_menu();
void menu_select();

void setup()
{
  //--configuração do menu--
 pinMode(menu,  INPUT_PULLUP);
  pinMode(bttiro, INPUT_PULLUP);

 lcd.begin (16,4);
 //lcd.setBacklight(HIGH);--apenas para lcd i2c
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print(">");

pxnave=pynave=pyaste=pontos=pytiro=0;
pxtiro=-1;
pxaste=12;
vtela=0;
lcd.createChar(1,nave);
lcd.createChar(2,asteroide);
lcd.createChar(4,explosao);
lcd.createChar(6,tiro3);
//lcd.begin(16,2);
//lcd.clear();
game1=-false;
game2=false;
game3=false;
vtiro=false;
}

void loop(){

  if(!sub_menu)
  {
   lcd.clear();
    lcd.setCursor(1,line[0]);
    lcd.print("1) NAVE: THE GaMe       ");
    lcd.setCursor(1,line[1]);
    lcd.print("2) PING PONG       ");
    lcd.setCursor(1,line[2]);
    lcd.print("3) lula & dilma      ");
    lcd.setCursor(1,line[3]);
    lcd.print("4) Creditos     ");

  }

  readButts();

  if(game1){
    lcd.clear();
    vtela=0;

  if (digitalRead(btcima)==1){
    pynave=0;

  }
  if(digitalRead(btbaixo)==1){
    pynave=1;
  }
  if(digitalRead(bttiro)==1){
    pxtiro=1;
    vtiro=true;
pytiro=pynave;
  }
  pxaste-=1;
  desenhaNave(pxnave, pynave);
  desenhaAsteroide(pxaste, pyaste);
  if(vtiro){
    desenhaTiro3(pxtiro, pytiro);
    pxtiro+=1;
  }

  if(pxaste<0){
  pxaste=12;
  pyaste=random(0,2);
  }
  if(pxtiro>16){
    vtiro=false;
    pxtiro-=1;
  }
  if (((pxtiro==pxaste+1)&&(pytiro==pyaste))||((pxtiro==pxaste)&&(pytiro==pyaste))){
  vtiro=false;
  pxtiro=-1;
  desenhaExplosaoAsteroide(pxaste, pyaste);
  pyaste=random(0,2);
  pxaste=12;
  pontos+=5;
  if((pontos>=maxpontos)){
    game1=0;
    vtela=7;//rever
  }
}
if((pxnave==pxaste)&&(pynave==pyaste)){
game1=0;
desenhaExplosaoNave(pxnave, pynave);
vtela=6;
}

  delay(vel);

  }else{
    tela(vtela);
    if(digitalRead(bttiro)==1){
      reset1();
    }
  }
}

  void readButts()
{

   if(!digitalRead(menu))  menu_flag  = 0x01;
   if(!digitalRead(bttiro)) enter_flag = 0x01;

   if(digitalRead(menu) && menu_flag)
   {
       menu_flag = 0x00;
       list_menu();
       menu_number+=1;
       if(menu_number > 5) menu_number = 1;

   }

   if(digitalRead(bttiro) && enter_flag)
   {
      enter_flag = 0x00;
      sub_menu = !sub_menu;
      menu_select();

   }

}

void list_menu()
{
  for(int i=4; i>-1; i--)
  {
     index = i-1;
     line_bk[i] = line[i];

     if(index < 1) line[i] = line_bk[i+4];

     else line[i] = line[i-1];

  }

}

void menu_select()
{

    switch(menu_number)
    {
       case 1:
        vtela==0;
        game1= true;
        game2=false;
        game3=false;

               break;
       case 2:
            vtela==4;
              game1= false;
        game2=true;
        game3=false;
               break;
       case 3:
           vtela==5;
           game1= false;
        game2=false;
        game3=true;
               break;
       case 4:
               vtela==8;
               game1= false;
        game2=false;
        game3=false;
               break;
       //case 5: ---pensar---

    } //end switch

}
  void desenhaNave(int px, int py){
  lcd.setCursor(px,py);
  lcd.write(1);
}
void desenhaAsteroide(int px, int py){
  lcd.setCursor(px,py);
  lcd.write(2);
}

void desenhaTiro3(int px, int py){
  lcd.setCursor(px,py);
  lcd.write(6);
}
void desenhaExplosaoNave(int px, int py){
 lcd.clear();
  lcd.setCursor(px,py);
  lcd.write(4);
  delay(1000);
  lcd.clear();
}
void desenhaExplosaoAsteroide(int px, int py){
  lcd.setCursor(px,py);
  lcd.write(4);
  delay(1000);
  lcd.clear();
}
void reset1(){
  pontos=0;
  game1=true;
  vtela=0;
}
void reset2(){
  pontos=0;
  game2=true;
  vtela=0;
}
void reset3(){
  pontos=0;
  game3=true;
  vtela=0;
}

void tela(int cond){//0=jogo da nave 1=ganhou 2= perdeu 3= menu de seleção 4=jogo pingpong 5=jogo plataforma

if(cond<1){
   lcd.setCursor(3,0);
     lcd.print("Nave: THE GAmE");
     lcd.setCursor(0,1);
lcd.print("PRESSIONE START");
}
if(cond==6){
  lcd.setCursor(9,0);
  lcd.print("pts:");
  lcd.setCursor(13,0);
  lcd.print (pontos);
  lcd.setCursor(1,0);
  lcd.print("Perdeu");
lcd.setCursor(0,1);
lcd.print("PRESSIONE START");
}
if(cond==7){
  lcd.setCursor(9,0);
  lcd.print("pts:");
  lcd.setCursor(13,0);
  lcd.print (pontos);
  lcd.setCursor(1,0);
  lcd.print("Ganhou");
lcd.setCursor(0,1);
lcd.print("PRESSIONE START");
}
if (cond==3){
  sub_menu=true;
  lcd.clear();
}

if(cond==4)
{
  lcd.setCursor(3,0);
  lcd.print ("Ping Pong");
  lcd.setCursor(0,1);
  lcd.print ("PRESSIONE START");

}
if (cond==5)
{
  lcd.setCursor(3,0);
  lcd.print("Lula e Dilma");
  lcd.setCursor (0,1);
  lcd.print ("PRESSIONE START");
}
if (cond==8)
{
  lcd.setCursor(3,0);
  lcd.print("Equipe LULA Livre");
  lcd.setCursor(0,1);
  lcd.print("Obrigado por Jogar");
}
}`enter code here`

Just for inspiration, you may want to take a look at Arduboy and the open source libraries its games are built on.

https://wokwi.com/arduino/projects/297467237377245705 can you check this link

Probably since you set the cursor at a position in the middle of a line, only the new text is overwritten over the old text. But if there are some characters from the previous text, those will stay.
So the easiest way is to either clear the screen (if you can do the updating of the screen from a single place), or rewrite the entire line (and probably having to add spaces before/after the text you want to write to overwrite the old text).
Some other tips:

Write comments and variable names in English (I know it's not your mother
language, but you can learn two languages at once, C and English).
Align your code (make sure each { and } is aligned nicely; this will make life much easier and prevent mistakes.
game1, game2 and game3 are booleans where only one can be true. For this the enum (enumeration) is invented. So make an enum enum Game { game1, game2, game3 }; as a type, and declare a variable Game currentGame = game1;
You use a switch statement for menu_number, but why not for cond?
You use a lot of text, all text also takes up precious SRAM, where you only have 2,048 bytes of. If for each string you add F in front (thus e.g. F("MENU"); this will be stored only in Flash.


text:
About split string
Sorry my English is poor.
I use nodemcu to get a json data.
By this String alldata = client.readString();
But it turn this:
  HTTP/1.1 200 OK
  Server: nginx
  Date: Sat, 10 Aug 2019 04:53:16 GMT
  Content-Type: application/json; charset=utf-8
  Content-Length: 152
  Connection: keep-alive
  X-RateLimit-Limit-day: 20000
  X-RateLimit-Remaining-day: 19968
  Cache-Control: no-cache
  Pragma: no-cache
  Expires: -1
  X-Powered-By: ASP.NET
  Access-Control-Allow-Origin: *
  X-Kong-Upstream-Latency: 23
  X-Kong-Proxy-Latency: 2
  Via: kong/0.14.1
  Strict-Transport-Security: max-age=63072000; includeSubdomains; preload

  [{"Direction":0,"EstimateTime":364,"StopStatus":0,"MessageType":0,"SrcUpdateTime":"2019-08-10T12:53:00+08:00","UpdateTime":"2019-08-10T12:53:05+08:00"}]

I need '364' to display on oled.
Is it possible to split it.Thanks!

yes it is possible to extract the value ... google arduino parsing strings

cut away the HTTP headers (until the empty line). use ArduinoJson library to parse the payload

Thanks I have solve it.


text:
Hx711 is outputting only zero
I am strain guages in a wheatstone bridge along with hx711 . For testing amplifier I used potentiometers to change the input voltage for hx711. It is outputting only zero. Here is my code.
#include "HX711.h"

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;

HX711 scale;

float calibration_factor = 282650.0;

void setup() {
  Serial.begin(57600);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale();
  scale.tare(); //Reset the scale to 0
}

void loop() {
  if (scale.is_ready()) {
    long reading = scale.read();
    Serial.print("HX711 reading: ");
    //Serial.println(reading);
    Serial.println(scale.get_units(), 5);
  } else {
    Serial.println("HX711 not found.");
  }
  delay(1000);
}

calibration_factor is defined but not used?

I did add a line  scale.set_scale(calibration_factor);  in the void loop. But still it is giving zero. Thank you

You are welcome.


text:
Control speed of a dc motor with a 9v battery
Problem:
I want to have a 9v battery that powers a dc motor. I want to control it with a bluetooth remote that has 3 buttons. 1st button is turn the motor with 1.5v, 2nd button is motor off and the 3rd button is full power (9v). Here is the problem normally I will change volt with my arduino using code, but it has a max voltage of 3.6v so I can't control the battery with the arduino. Also I would like the 9v battery to power the arduino and bluetooth module if that is possible, so I have only one battery that powers everything.
What I tried:
I found a lot of different things on the internet. Pwm, Tip120 transistor, L298N and it only confuses me more I have no idea where to start. Spend 8 hours looking for stuff and no step further.
Result:
I hope everything will work with a 9v battery and the bluetooth remote can switch between 3 different speeds.![enter image description here]

Too broad and off-topic, but I suggest you read about pulse-width modulation (PWM) control of DC motors, as well as the power requirements of your DC motor.  Often alkaline 9 V battery won't cut it, try lithium batteries instead.

You have 3 problems here:

Driver circuit the motor: Since you only want to control the motors speed (not changing it's direction, where you would need a H-bridge like the L298N), a very simply driver circuit is sufficient. It can consist of a bipolar transistor or a MOSFET. The Arduino's digital output pin would set the transistor/MOSFET to conductive or non-conductive, which turns the motor on or off. The motor is connected (through the transistor/MOSFET) with the full supply voltage. For the needed circuit, you can google terms like "transistor as switch" or "MOSFET as switch". That should give you plenty of tutorials.
Controlling the motor speed: Normally the speed of a motor is not controlled through the voltage, since the speed behaves not linear with the voltage. Instead we use PWM (Pulse Width Modulation), where a squarewave voltage with a constant frequency is outputted at the Arduino's pin. To change the motor speed, you change the ratio between ON and OFF time of the pin (called "duty cycle"). So the motor basically get's turned on and off very fast. Since the motor is to slow, to follow the fast change, we are basically giving it small pushes very fast. If you only push half of the time (duty cycle 50%), the motor will run with about half the speed. In Arduino code you use analogWrite(pin_number, x) with x between 0 and 255 to output a PWM wave at the specified pin. Refer to the Arduino documentation for details.
Powering the whole device: First: A 9V block battery is actually like the worst choice for most cases (especially for devices with motors). It has a big series resistance, what means, that it cannot provide much current without dropping the voltage radically. They are meant for low-current devices. Better use multiple AA/AAA batteries in series.
You didn't state, what Arduino you actually use, but from the description, it has to be one of the 3.3V boards, like the Arduino Pro Mini 3.3V version. Most Arduino boards also have a small voltage regulator on them. The input for it is mostly marked with Vin. Please refer to the documentation of your Arduino board, to check, which voltages are suitable for that voltage regulator. If you don't have a voltage regulator on your Arduino or your battery voltage doesn't fit, you have to provide the power through your own external voltage regulator. You should use a switching regulator (far more efficient, than linear regulators), which can provide the needed power (depending on the Arduino and the bluetooth device maybe between 50mA and 300mA, difficult to say generally) plus a bit overhead.
You should then provide the motor with the full battery voltage, especially not through the Arduino's voltage regulator. Motors can draw quite much current. If you draw more current through a regulator, than possible, it will overheat, emergency shutdown or even burn out. If the battery voltage is not suitable, you should use a voltage regulator, that can safely provide the needed current.

Note: Depending on the size of the motor and it's load, you might want to add a flyback diode, that would safely let inductive reverse currents flow to ground, so that the inductive voltage is not piling up in the transistor/MOSFET.

Thank you so much! Finally I understand it! I will try this and let you know if it works! :)

Again Thank you, almost everything works! Only thing I don't know is how I can add the diode against the back voltage. I made picture of the diagram that I use and I am not sure if its correct. And I made a picture of the project I am working on.(I post them with the orginal message.) I am not sure if i wired it correctly because my esp gets data from the com3 when the motor is turned(I think it's because of the back voltage). Also this way the diode became extremly hot.

The diode is in the wring place. Currently all the motor current is flowing through it, so it gets hot. The flyback diode should bridge source and drain of the mosfet in the reverse direction, so that in normal operation it is blocking, leaving the operational function to the MOSFET. When the motor gets stopped suddenly, a negative voltage will build up at the MOSFET. The diode will then connect this voltage to ground, so that the voltage dissipates there and cannot ruin the MOSFET

I don't know, what you mean by com3, but this seems due to the motors noise. Shielding from noise can be a complex thing, too complex for this answer. Google about it, to find some fitting measures.

I made a picture again of my setup and also a diagram of the mosfet and it's connections. Is this what you meant? When I tried this I still get a blinking yellow light on my esp8266. (back voltage that probably gets in the board) Also I need to disconnect and reconnect my esp8266 otherwise it won't process any code. Can you see something I am doing wrong? It's a 1n4001 diode and I use PWM, does that make a problem? Thank you in advance!


text:
Measure revolutions per second with reed switch
I'm trying to measure speed of a fly wheel with a reed switch with one magnet (1 pulse per full rotation). I have an 100nf cap connected to switch to help with debounce.

#include <Arduino.h>

int speedPin = 2; // switch is connected to pin 2
int ledPin = 13;

int debounceTime = 7;

long speedPulseTime = 0;
int speedPulseCount = 0;
int speed = 0;
long speedLastSample = 0;

long serialLastReport = 0;
int serialReportFreq = 40;

void speedPulse()
{
  long time = millis();
  if ((speedPulseTime + debounceTime) < time)
  {
    speedPulseCount++;
    speedPulseTime = time;
  }
}

void setup()
{
  pinMode(ledPin, OUTPUT);

  pinMode(speedPin, INPUT_PULLUP);     // Set the switch pin as input
  attachInterrupt(digitalPinToInterrupt(speedPin), speedPulse, HIGH);

  Serial.begin(115200);
  Serial.println("Ready...");
}

void loop()
{
  long time = micros();
  if (speedPulseCount >= 4 || (speedLastSample + 1500000) < time)
  {
    detachInterrupt(speedPin);
    int tempSpeed = 1000000 / ((time - speedLastSample) / speedPulseCount);
    if (tempSpeed < 0)
    {
      speed = 0;
    }
    else
    {
      speed = tempSpeed;
    }

    //reset sample
    speedLastSample = time;
    speedPulseCount = 0;
    attachInterrupt(digitalPinToInterrupt(speedPin), speedPulse, HIGH);
  }

  if ((serialLastReport + serialReportFreq) < millis())
  {
    Serial.print(millis());
    Serial.print(",");
    Serial.println(speed);
    serialLastReport = millis();
  }
}

Here the code I have so far. The problem I have it jumps around a little bit. What could I change to ensure more accurate readings?

Can you state more accurately (by editing your post) what "jumps around a little bit"?  As written, one could assume it was your code that jumped around.

It sounds like occasional "misses". Possible causes include:

the magnet passing far enough from the reed switch to "only just" trigger it [narrow the gap.];
the magnet's passage being too short for the reed switch/capacitor to respond [use a wider magnet or move closer to the center of rotation];
Too much capacitance [reduce it or debounce in software];

Update:

Would it be better to debounce in software and what would be the best way to do it.

If you have an oscilloscope available, you could look at the raw switch signal (no capacitor) to find out how long it bounces. I'm guessing that it will be around 10ms for such a small switch. If the entire [make/break/make/break....] sequence takes less than 50% (being conservative) of the wheel rotation time (1/max_RPS), you can probably count the first pulse and ignore the switch for (0.5/max_RPS), or 1/2 of the fastest rotation. You appear to be doing something like this already. If you want to be a little bit more rigorous, you might do:
see a HIGH;
ignore switch for debounce_time;
if still HIGH,
   count++;

Also, don't forget that variables shared between your Interrupt function and the main-line code need to be:

declared as volatile, to tell the compiler not to expect that this variable has the value it had last time the mainline code read it; and
Turn interrupts off briefly while reading or writing such a variable (if it is multi-byte) in your mainline, to prevent it being changed by the interrupt function between byte-reads/writes by the mainline.

Would it be better to debounce in software and what would be the best way to do it. I already have a little debounce in software, would this do?


text:
Ethernet.begin() conflicts with build-in LED on Arduino Nano
I have Arduino Nano "clone" which I would like to use with Ethernet ENC28J60 shield. I have noticed that when I include/use UIPEthernet.h library, build-in LED does not work properly. I have written the following sketch which I have uploaded to Arduino and run both with and without Ethernet shield with the same result: LED is not blinking. Once I comment out the line Ethernet.begin(mac), LED starts blinking just fine.
Is there any way to overcome this conflict?
#include <UIPEthernet.h>

EthernetClient ethClient;

uint8_t mac[6] = { 0x90, 0xA2, 0xDA, 0x0D, 0xE2, 0xCD };

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

  // If this line is commented, LED starts blinking:
  Ethernet.begin(mac);

  pinMode(LED_BUILTIN, OUTPUT);

  Serial.println(F("setup() done."));
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

No, you can't.
The LED is on pin 13. Pin 13 is the clock pin for SPI. The ENC28J60 is an SPI device.
You either have control over pin 13, or you have SPI. You can't have both.

Thanks for this information! Good to know that. Probably there is some way to "stop" Ethernet and start using LED? Unfortunately, I found no Ethernet.stop() or similar.


text:
Wifi module is not sending the data properly
I wrote a programm in c++ for Arduino Uno which is connected to a wifi module (ESP8266) and sends the calculated data to a server through wifi-Module with a http post request.
The problem is that the programm sends the data only 2 times throuth http and then it stops. I mean it goes to the loop but the http-send-request is not successful.
here is my program:
#include <MySignals.h>
#include "Wire.h"
#include "SPI.h"

unsigned long currentMillis;

const unsigned long period = 10000;

int a=1;

void setup()  {

Serial.begin(115200);

MySignals.begin();
 void httpBase(int); //Enable WiFi ESP8266 Power -> bit1:1           >      bitSet(MySignals.expanderState, EXP_ESP8266_POWER);
 MySignals.expanderWrite(MySignals.expanderState);

 MySignals.initSensorUART();

 MySignals.enableSensorUART(WIFI_ESP8266);   delay(1000);

// Checks if the WiFi module is started   int8_t answer =
sendATcommand("AT", "OK", 6000);   if (answer == 0)   {
MySignals.println("Error");
// waits for an answer from the module
while (answer == 0)
{
  // Send AT every two seconds and wait for the answer
  answer = sendATcommand("AT", "OK", 6000);
}   }   else if (answer == 1)   {

MySignals.println("WiFi succesfully working!");

if (sendATcommand("AT+CWMODE=1", "OK", 6000))
{
  MySignals.println("CWMODE OK");
}
else
{
  MySignals.println("CWMODE Error");

}

//Change here your WIFI_SSID and WIFI_PASSWORD
if (sendATcommand("AT+CWJAP=\"********\",\"****\"",
"OK", 20000))
{
  MySignals.println("Connected!");
}
else
{
  MySignals.println("Error");

}   }

 }

void loop()  {

delay(10);  // wait for a second

a=a+1;

httpBase(a);

 }

 void httpBase(int gsr) {

 String data="value1="+String(gsr); //String
 data="a="+String(gsr);
 String postString="POST /ardu.php HTTP/1.1\r\nHost:
 192.168.178.36\r\nContent-Type: application/x-www-form-
 urlencoded\r\nContent-Length:
 "+String(data.length())+"\r\n\r\n"+data+"\r\n"; char* post = new
 char[postString.length()+1]; strcpy(post,postString.c_str());

 String inf = "AT+CIPSEND="+String(strlen(post)); char *info = new
 char[inf.length() + 1]; strcpy(info, inf.c_str());

 delay(1500); sendATcommand("AT+CIPMUX=0", "OK", 3000);

 //sendATcommand("AT+CIPSERVER=1","OK",1000);

 sendATcommand("AT+CIPSTART=\"TCP\",\"192.168.178.36\",80", "OK",
 2000);

 sendATcommand(info, "OK", 2000); sendATcommand(post, "OK", 2000);

 sendATcommand("AT+CIPCLOSE", "OK", 3000);

 delay(10000); }

int8_t sendATcommand(char* ATcommand, char* expected_answer1,
unsigned
int timeout) {

uint8_t x = 0,  answer = 0;   char response[500];   unsigned long
previous;

memset(response, '\0', sizeof(response));    // Initialize the
string

delay(100);

while ( Serial.available() > 0) Serial.read();   // Clean the
input
buffer

delay(1000);   Serial.println(ATcommand);    // Send the AT   command

 x = 0;   previous = millis();

 // this loop waits for the answer   do   {

 if (Serial.available() != 0)
 {
  response[x] = Serial.read();
  x++;
  // check if the desired answer is in the response of the module
  if (strstr(response, expected_answer1) != NULL)
  {
    answer = 1;
    //MySignals.println(response);

  }
}
// Waits for the asnwer with time out   }   while ((answer == 0) && ((millis() - previous) < timeout));

 return answer; }

the output is:
AT
WiFi succesfully working!
AT+CWMODE=1
CWMODE OK
AT+CWJAP="*******","******"
Connected!
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80
AT+CIPSEND=127
POST /ardu.php HTTP/1.1
Host: 192.168.178.36
Content-Type: application/x-www-form-urlencoded
Content-Length: 8

value1=2

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80
AT+CIPSEND=127
POST /ardu.php HTTP/1.1
Host: 192.168.178.36
Content-Type: application/x-www-form-urlencoded
Content-Length: 8

value1=3

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80
AT+CIPSEND=127
POST /ardu.php HTTP/1.1
Host: 192.168.1
⸮⸮6⸮
AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80
AT+CIPSEND=1
⸮
AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80
AT+CIPSEND=1
⸮
AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80
AT+CIPSEND=1
AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80
AT+CIPSEND=1
⸮
AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80

⸮
AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80
2

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80
2

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80
⸮
⸮
AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80

AT+CIPCLOSE
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.178.36",80

AT+CIPCLOSE

....

what is MySignals.h?

is a plattform which contains sensors.

reduce your code to send and receive a single byte ... was that successful?

don't use String class https://majenko.co.uk/blog/evils-arduino-strings

void httpBase(int); does not ake sense, it's a funcrion declaration instead of a function call.

Hello Navid and welcome to the community. Buddy your code is extremely hard to read.
Now let me see if I can help you archiving your goals. First of all try not to use AT commands at all, you have an ESP8266, that's not just a Wi-Fi module but also a really good micro controller you can actually use, code for it (even using Arduino IDE). I would HIGHLY suggest you to use it if you wanna do POST and GET methods. AT commands do work, but they are not as reliable as they should be, and with your code written in that format, its going to be difficult to help you buddy.
Now if you are calling it a Wi-Fi "Module" I can presume it's a ESP01 you are talking about (those ESP8266 with no usb connection), you can find on the internet a few tutorials on how to upload code to them using your arduino uno's FTDI chip (basicly grounding the reset pin of your Arduino).
With that been said, hopefully you can split your code into those 2 micro controllers if you really need to use the Arduino uno, and do a few functions to trigger based on Serial communication on both sides. I know it sounds a lot of work, but trust me, that's by far the easiest and more reliable solution you will find.
And let me give you an bonus tip, next time you wanna work with Wi-Fi applications, get yourself a Wemos D1, they are small easy to use, reliable, have GPIO's as well as ADC and PWM pins, you can pretty much put your Arduino on a shelf for 4 dollars.
And please remember Navid, code syntax is really important.


text:
I need help programming my arduino in assembly
I am new to using an Arduino and I am trying to program my it to implement a ﬂashing pattern with two LEDs. When one LED is oﬀ, the other must be on. The program needs to be done in assembly. I have a working program in c++ but I need to convert it to assembly. I have an Arduino UNO ATmega 328p
Here is my c++ program:
 const int led = 13;
 const int led2 = 12;

 void setup() {
    pinMode(led, OUTPUT);
    pinMode(led2, OUTPUT);
 }

 void loop() {
   digitalWrite(led, HIGH);
   delay(1000);
   digitalWrite(led, LOW);
   digitalWrite(led2, HIGH);
   delay(1000);
   digitalWrite(led2, LOW);
 }

Why does it "need" to be done in assembly? School project?

And what are you looking for us to do for you? This sounds more like a call for somebody to do the work for you than a question. You'll need to research the different registers that manage the various GPIO lines, as well as the instruction set for your model of Arduino.

Did you try a web-search? Guess not :) https://www.instructables.com/id/Command-Line-Assembly-Language-Programming-for-Ard-2/ Start in Step 3 and modify. This can also be done by writing assembly in C. The Arduino core has a few functions that are written in this style, https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/wiring.c#L120

Of course I searched it, I came here as a last resort

In the case, that this is a school assignment and you actually have to program directly in assembler, you probably don't want to directly convert your C++ sketch. It will generate way more assembler code, than is really necessary for alternatively blinking two LEDs (for example digitalWrite() contains not only the actual writing to the corresponding pin registers, but much more code), and it will be obvious, that you didn't write it yourself.
In this case you have to go the harder way. You should start by looking into existing assembler blink programs. Via google I found this series at github gist, which also has a blink example. You can derive some of the program from there. Also there is a list of assembler command with descriptions.
In the end everything, that is done on a microcontroller, comes down to reading and writing Special Function Registers (SFR). The pins are organized in ports with 8 (or sometimes less) pins. Every port is then represented by one byte in the corresponding SFR (1 bit per pin). For changing the direction of a pin between output and input, the DDRX registers are used (where X is the character of the port used). For actually setting the output state (or enabling/disabling the internal pullup resistor) the PORTX registers are used. The current state (LOW or HIGH; while input or output) can be read from the PINX registers. For these things, the datasheet of the microcontroller (here the Atmega328P) is a must read (meaning: not completely, but enough to feel comfortable getting needed information from it).
Learn how to set single bits in a byte (in a SFR). You can learn it from the linked example, or from tutorials over the internet. Then write code to write the correct value to the corresponding DDRX bits to set the LED pins to output. Then you can use this to write a value to an output pin.
For blinking you need a timer. If you google for something like "arduino assembler blink" you will also find an example, which configures the timer for blinking. Basically it involves setting the Timers SFRs to the wanted values. If you don't want to do this, you might get away with executing a high number of "nop" operations (which does nothing). You would have to write a loop, that will execute a high number of times. ( very "nop" will need 1 clock cycle - credits to Ghanima for searching that up). The clock runs on 16MHz, so you can do the math to calculate, how long 1 "nop" needs, and then calculate, how many of them you need).

It's one cycle per NOP which is for the AVR architecture the most sensible thing to do.

@Ghanima Thanks, I corrected the number in my answer

There are also a couple of ways of including assembler code right inside your Arduino IDE.
By including the assembler in the Arduino IDE, the assembler source is assembled and linked into your project and uploaded to your Arduino from within the IDE - just like any other program.
This makes it easy to get started with Assembler while still retaining the familiarity of the Arduino IDE. Why? Because since you can mix C / C++ code with the Assembler code this means that you do not have to write a complete assembler program that manages all of the hardware initialisation nitty gritty - you can start small and expand your assembler as and when you you feel comfortable or need to do so. Like the example below, you can start with just two lines of assembler that fit into a larger program if you wanted to.
Following are the instructions for creating a mixed C / Assembler program in Arduino. I also give an example of how to pass parameters and get a result from an Assembler function.
To create a mixed C + Assembler program create a new project in the Arduino IDE (call it whatever you like) and enter the following code into the IDE:
extern "C" {
  void myInit();
  void myLoop();
  int myAdd(int, int);
}

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

  // This is just a dummy example showing inline assembler using the asm "directive"
  // Refer to this tutorial, or similar, for details of inline assembler in Arduino:
  // https://ucexperiment.wordpress.com/2016/03/11/arduino-inline-assembly-tutorial-5-2/
  asm(
    "ldi   r26,42"
  );
}

void loop() {
  myLoop();

  int ans = myAdd(240, 25);
  delay(ans);
  Serial.print("Answer: ");
  Serial.println(ans);
  delay(1000);
}

Next click the little down arrow in the top right corner of the IDE as per the following diagram and select "New Tab":

Enter myFunctions.S as the name of the new tab as shown below. Note that the name does not really matter, but, it must end with the extension .S and the "S" must be a capital "S" not a lowercase "s":

Paste the following code into the myFunctions.S tab.
; Example assembler file that blinks an LED.
; and adds two numbers together.

#define __SFR_OFFSET 0

#include "avr/io.h"

// Declare the three function entry points as "globals"
.global myInit
.global myLoop
.global myAdd

myInit:
  sbi   DDRB,5      ; Set PB5 (the built in LED on Arduino Uno) as output
  ret

myLoop:
  ldi   r20,250     ; Set the delay duration in ms. Maximum value is 255.
  call  myDelay_ms
  sbi   PORTB,5     ; Set PB5 HIGH
  ldi   r20,250     ; Delay for another 250 ms.
  call  myDelay_ms
  cbi   PORTB,5     ; Set PB5 LOW
  ret

; These symbols are for internal to this assembler file's use only.
; They are private because they are not listed as a global symbol
; Also, they do not conform to the subroutine calling conventions used
; by the Arduino IDE's compiler. i.e. they are not compatible with
; being called directly from C. However, since we are calling them from
; our own assembler, we can (almost) make up any calling convention we like.
myDelay_ms:
  ; Delay about r20*1ms. Destroys r20, r30, and r31.
  ; One millisecond is about 16000 cycles at 16MHz.
  ; The basic loop takes about 5 cycles, so we need about 16,000,000 / 5 = 3000 loops.
  ; NB: most instructions are 8 bit, so we load the 16 bit counter using
  ;     two 8 bit loads.
  ldi   r31, 3000>>8    ; high(3000)
  ldi   r30, 3000&255   ; low(3000)
delaylp:
  sbiw    r30, 1        ; Decrement our 1 ms counter (this instruction operates on a 16 bit value in R31:R30).
  brne    delaylp       ; If R30 is non zero, loop back
  subi    r20, 1        ; Otherwise we have passed 1 ms so, decrement the high order byte of our counter.
  brne    myDelay_ms    ; If this is non zero, loop back.
  ret                   ; Otherwise, we have counted down from R20 * 3,000 - so return.

; Function to add two integers and return an integer.
; For few parameter functions, the Arduino IDE uses registers built into the
; Microcontroller (i.e. the CPU) to exchange data between subroutine caller and callee.
; Return values are as follows:
;   - single Byte (e.g. char, byte) R24 only
;   - double Byte (e.g. int)        R25:R24 (R25 is the high order byte)
;   - quad Byte   (e.g. long)       R25:R24:R23:R22 (R25 is the high order byte)
; Parameters are passed in similar ways starting with R25 and working down, but exactly
; what is where will depend upon the parameter types.
; Refer to this tutorial for more details or the AVR compiler documentation from ATMEL
;   https://ucexperiment.wordpress.com/2016/04/02/arduino-inline-assembly-tutorial-12-functions/
; In our case, a is passed in R25:R24 and b is passed in R23:R22
myAdd:
  add     r24, r22      ; Add the low order bytes
  adc     r25, r23      ; Add the high order bytes PLUS any value carried from the previous addition.
  ret                   ; The result is in R25:R24 which is where it needs to be to pass back to the C code.

Upload it to your Uno, start the serial monitor and you should see some sum's being ouput (well one sum continuously being output). Feel free to change the values in the main loop to see different results.
I've put loads of comments and a few references into the code to get you started on the path to finding more information.
One other reference that will be useful if you are going to mess with assembler on the UNO is the ATMega-328P reference manual/datasheet (all 662 pages of it) which you can obtain from Microchip's ATmega328p reference page. There are a whole bunch more useful resources there that will likely come in handy from time to time.

It "needs" to be done in assembly as an assignment, right? Otherwise you would "want to learn" assembly.
What I suggest you do is change the C program to use port manipulation, for example:
 void setup() {
   DDRB |= 0b00100000;  // D13 to output mode
 }

 void loop() {
   PORTB |= 0b00100000;  // turn on D13
   delay(2000);
   PORTB &= ~0b00100000;  // turn off D13
   delay(2000);
 }

Now at least you are flashing D13 without using the rather complex digitalWrite and pinMode library functions. The delay is another issue I'll leave you to investigate however my page about timers might help you.
Now you can disassemble the generated code to see what the compiler generated in assembler and use that to help you learn how to do it.
For example, when I compiled the above code and turned on "verbose compiling" I found the location of the generated .elf file.
Running avr-objdump on that file (like this):
avr-objdump -S /tmp/build436d41bc5c0da39afe99cd9c05ac272a.tmp/sketch_aug13a.ino.elf > temp.txt

Gives me the following code for "loop":
00000094 <loop>:
  94:   2d 9a           sbi 0x05, 5 ; 5
  96:   60 ed           ldi r22, 0xD0   ; 208
  98:   77 e0           ldi r23, 0x07   ; 7
  9a:   80 e0           ldi r24, 0x00   ; 0
  9c:   90 e0           ldi r25, 0x00   ; 0
  9e:   0e 94 c5 00     call    0x18a   ; 0x18a <delay>
  a2:   2d 98           cbi 0x05, 5 ; 5
  a4:   60 ed           ldi r22, 0xD0   ; 208
  a6:   77 e0           ldi r23, 0x07   ; 7
  a8:   80 e0           ldi r24, 0x00   ; 0
  aa:   90 e0           ldi r25, 0x00   ; 0
  ac:   0c 94 c5 00     jmp 0x18a   ; 0x18a <delay>

What we basically see there is one "sbi" instruction to turn the LED on and one "cbi" instruction to turn it off.
As for the rest, well I don't want to do your homework for you. Have fun learning how to program in assembler!

Try this method to convert your sketch
https://sourceforge.net/projects/arduino-to-assembly-converter/

I tried that but when I run it there are multiple errors

Also you should check out chrisl's comments about being "way to much generated code" and "obvious you did not do it yourself". Unless you are aiming for an F on your project, automated conversion of the C code is not the answer. Of course it is entirely your choice as to what grade you wish to work for.


text:
how to interrupt the loop function and restart it?
I have a project with some NeoPixels and other LEDs and an Arduino UNO.
Once switched on, the defaultLEDAnimation with colors and blinking, etc. starts.
I want to trigger some other animations, so I connected two buttons to the Arduino. Whenever you press button1, the Arduino should stop everything it is doing and run animation1. The same goes for button2. if you press it, the Arduino should run animation2. All animations are quite complex and run for several seconds and even minutes.
Now for the challenge: How do I use the two buttons to immediately stop every animation happening and display the appropriate animation?
The tried using interrupts and connected the two buttons to pin 2 and 3.
However, when I press the buttons, the animation starts after several seconds delay. Is there any way to restart the loop function immediately after the interrupt has been made? Or is there another way to trigger my animations with those two buttons?
The code looks something like this:
#define button1 2
#define button2 3

volatile bool shouldPerformButton1Action = false;
volatile bool shouldPerformButton2Action = false;

void setup() {
    attachInterrupt(digitalPinToInterrupt(button1), button1Pressed, RISING);
    attachInterrupt(digitalPinToInterrupt(button2), button2Pressed, RISING);
}

void loop() {
    if (shouldPerformButton1Action) {
        doAnimation1();
        shouldPerformButton1Action = false;
    } else if (shouldPerformButton2Action) {
        doAnimation2();
        shouldPerformButton2Action = false;
    } else {
        runDefaultAnimation();
    }
}

void button1Pressed() {
    shouldPerformButton1Action = true;
}

void button2Pressed() {
    shouldPerformbutton2Action = true;
}

void doAnimation1() {
    for(int i=0; i<10; i++){
        neoPixelStrip.setPixelColor(neoPixelArray[i], neoPixelStrip.Color(255, 0, 0, 255));
        neoPixelStrip.show();
        delay(100);
    }
    delay(1000);
    for(int i=0; i<10; i++){
        neoPixelStrip.setPixelColor(neoPixelArray[i], neoPixelStrip.Color(0, 0, 0, 0));
        neoPixelStrip.show();
        delay(100);
    }
}

The function doAnimation1 is just an example. It will be much more complex.

Make the animation functions non-blocking, so that you can react immediately to the buttons. You don't even need interrupts for this. Please show us an example for the animation functions

You have to show us the animation routines, that's where the magic has to take place. Restarting the loop() is not the way something like that is implemented. You probably have another (blocking) loop in the animations and that's where you have to define an exit clause which has to by triggered by the corresponding button press.

The clean solution, as explained in Duncan C's answer, is to make the animation code non blocking. If this is too inconvenient, you may try to longjmp() directly from the ISR to the main loop.

@EdgarBonet: how exactly do you make the animation code non blocking?

See my answer. I outline in some detail how to make the animation code non-blocking.

Basically you have to make the animation loops return if the condition is met, for example:
void doAnimation1() {
    for(int i=0; i<10; i++){
        if (digitalRead (button1) == HIGH)  // Time to stop?
           return;
        neoPixelStrip.setPixelColor(neoPixelArray[i], neoPixelStrip.Color(255, 0, 0, 255));
        neoPixelStrip.show();
        delay(100);
    }
    delay(1000);
    for(int i=0; i<10; i++){
        if (digitalRead (button1) == HIGH)  // Time to stop?
           return;
        neoPixelStrip.setPixelColor(neoPixelArray[i], neoPixelStrip.Color(0, 0, 0, 0));
        neoPixelStrip.show();
        delay(100);
    }
}

If you don't want to wait for the 100 ms delay (or the 1000 ms delay) then you could replace that with code that waits for 100 ms to elapse, but also checks the button.
Interrupts are not the way to do it. Interrupts let you briefly stop doing something, do something else, then go back to what you were doing before. They don't "interrupt" your entire workflow.
For example, you might interrupt your movie watching to answer the phone, you don't "interrupt" your movie watching to go out to dinner with a friend. That is just a case of doing a different thing.

I thought I can avoid asking for the buttonState in every animation step. That makes things very complex.

Well, most of that code of yours could be put into a function. For example, number of loops, starting colour, ending colour, delay inbetween. Then that function is the one that decides whether to stop or not.

I implemented it exactly like that. Thanks.

"How to interrupt the loop function and restart it?"
You don't. That's not how you write Arduino code. You need to have your loop function call a series of non-blocking functions that check to see if it's time to do something, do a very small bit of work if it is time, or just return if it's not time yet.
What I've done is to create a class ArduinoObject that has a setup function,  a start function, a stop function, a loop function, and a boolean property running. My main program has a global variable that holds an array of ArduinoObjects.
Every time through the loop, I check all the ArduinoObjects in the array, and call their loop functions.
The first thing each object does is check its running flag. If running==false, it exits immediately.
Each object uses unsigned long values to track the next millis() time count when it should do something.
Let's say the object does an animation, so it has an unsigned long nextAnimationStepTime. In the loop() function, if nextAnimationStepTime<millis(), it doesn't do anything. If instead nextAnimationStepTime>=millis(), the object advances the animation to the next step, and sets nextAnimationStepTime = millis() + animationStepDuration. That way, next time the object is called, it will wait until it's time to advance the animation yet another step.
Each object is written to only do a tiny bit of work on each pass through the loop, and return as quickly as possible.
With this design, I can add an arbitrary number of objects/tasks to my loop, and all of them get attention on every pass through the loop. Most objects simply decide they're not running, or it's not time to do anything, and return.
You can then add control logic that starts and stops individual objects based on things like button presses.
With this approach you'd have your button 1 press stop animation 2 if it was running and run animation 1. Conversely, pressing button 2 would stop animation 1 if