message:
Stuck reading an XBM image from JSON (U8g2lib)

What I'm trying to achieve is very simple, I'm using ArduinoJson lib to load a JSON from SPIFFS and trying to inject the image values in an Array to feed the small Oled display of the ESP32:

    // This is the format the library expects
    static const unsigned char image[] U8X8_PROGMEM  = {
    0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x17 }

This is the JSON File:
   https://github.com/martinberlin/esp/blob/master/oled-128x64-xbm/data/1.json

The goal is to be able to generate little thumbnails after uploading an image for example, and display them in this Monochrome small display.

The problem is to convert this Json array into the format the library expects. And I tried many different ways and readed about it, without finding the right way to do it. So I though to share this here as a challenge and see if someone is also interested to get dynamic image thumbnails working in this display.

This is my sketch: (Needs /data upload since json example is there)

https://github.com/martinberlin/esp/tree/master/oled-128x64-xbm

    #include "FS.h"
    #include "SPIFFS.h"
    #include <U8g2lib.h>
    #include <ArduinoJson.h>
    #include <Wire.h>

    /*
      U8glib Example Overview:
        Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
        Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
        U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.

    */
    U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16);

    static const unsigned char image[] U8X8_PROGMEM  = {
      0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x17,
      0xFC, 0xFF, 0xFF, 0xFF, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00,
      0xFF, 0xFF, 0xFF, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF0, 0xFF, 0xFF,
      0xFF, 0x7F, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x14, 0xFD, 0xFF, 0xFF, 0xFF,
      0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x8F, 0xFF, 0x10,
      0x7E, 0xFF, 0xFF, 0xFF, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00,
      0xFE, 0x8F, 0xFF, 0x90, 0x7F, 0xFF, 0xFF, 0xFF, 0x00, 0xFE, 0xFF, 0xFF,
      0xFF, 0xFF, 0x03, 0x00, 0xFC, 0x0F, 0xFF, 0x90, 0xFF, 0xEE, 0xFF, 0xFF,
      0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0xFF, 0x0F, 0xFF, 0x90,
      0xFF, 0xCC, 0xFF, 0xFF, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x00,
      0xFF, 0x0F, 0xFF, 0x92, 0xFF, 0xC0, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0xFF, 0xFF, 0xFF, 0xFE,
      0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x00,
      0xFC, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0x7F, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0xF8, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x00,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0x3F, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF,
      0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0xFC, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00,
      0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0x3F, 0x00, 0xFC, 0xC7, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF,
      0x00, 0xFF, 0xF7, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0xFE, 0xE7, 0xFF, 0xFF,
      0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xF7, 0xFF, 0xFF, 0xFF, 0x3F, 0x00,
      0xFC, 0xE7, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xF7, 0xFF,
      0xFF, 0xFF, 0x3F, 0x00, 0xFC, 0xE7, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF,
      0x00, 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0xFE, 0xC7, 0xFF, 0xFF,
      0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0x0F, 0xFF, 0xFF, 0xFF, 0x0F, 0x00,
      0xFE, 0xCF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0x03, 0x07, 0xFF,
      0xFF, 0xFF, 0x0F, 0x00, 0xFC, 0xEF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF,
      0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0xFE, 0xEF, 0xFF, 0xFF,
      0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x1F, 0x00,
      0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xA6, 0xFF,
      0xFF, 0xFF, 0x1F, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0x06, 0xEE, 0xFF, 0xFF, 0x7F, 0x3F, 0x80, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x0E, 0xEF, 0xFF, 0xFF, 0xFF, 0x1E, 0x80,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFE, 0xFF, 0xFF,
      0xFF, 0xFF, 0x5E, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF,
      0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFD, 0xFF, 0xFF, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0xFD,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0x00, 0xFC, 0xFF, 0xFF,
      0xFF, 0xFF, 0x5F, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF,
      0x00, 0xF9, 0xFF, 0xFF, 0x7F, 0x80, 0xC6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFA, 0xFF, 0xFF, 0x7F, 0x80, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF0, 0xFF, 0xFF,
      0x6F, 0x80, 0xD1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0xF0, 0xFF, 0xFF, 0x2F, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF1, 0xFF, 0xFF, 0x27, 0x00, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF1, 0xFF, 0xFF,
      0x23, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0xF2, 0xFF, 0xFF, 0x31, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFD, 0xFF, 0xFF, 0x00, 0xF2, 0xFF, 0xFF, 0x10, 0x00, 0x74, 0xF8,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0x00, 0xF6, 0x7F, 0xFE,
      0x10, 0x00, 0xFC, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF,
      0x00, 0xF6, 0x3F, 0x00, 0x10, 0x00, 0xF4, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xB4, 0x0F, 0x00, 0x18, 0x00, 0xF0, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xB4, 0x07, 0x00,
      0x08, 0x00, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0xBC, 0x03, 0x00, 0x08, 0x00, 0xFD, 0xF3, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFB, 0xFF, 0xFF, 0x00, 0x38, 0x01, 0x00, 0x08, 0x00, 0xF9, 0xF9,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF, 0x00, 0x3C, 0x00, 0x00,
      0x0C, 0x90, 0xFF, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF,
      0x00, 0x3C, 0x00, 0x00, 0x04, 0x00, 0xE3, 0x78, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFB, 0xFF, 0xFF, 0x00, 0x38, 0x00, 0x00, 0x06, 0x00, 0xC3, 0x31,
      0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF, 0x00, 0x3C, 0x00, 0x00,
      0x06, 0x80, 0xE3, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF,
      0x7F, 0x1C, 0x00, 0x00, 0x03, 0x80, 0x60, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFB, 0xFF, 0xFF, 0xFF, 0x19, 0x00, 0x80, 0x01, 0x08, 0xF0, 0x00,
      0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0xC0,
      0x00, 0x08, 0xF0, 0x83, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF,
      0xFF, 0x1F, 0x00, 0xC0, 0x00, 0x28, 0xF8, 0xE3, 0xFF, 0xF7, 0xFF, 0xFF,
      0xFF, 0xFB, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x60, 0x00, 0x08, 0xFC, 0xE6,
      0xFF, 0xCD, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF, 0xFF, 0x1B, 0x00, 0x30,
      0x00, 0x04, 0x3C, 0xF8, 0xFF, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0x79, 0x40, 0x18, 0x00, 0x1C, 0x9E, 0xFC, 0xFF, 0x03, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1C, 0x00, 0x0C, 0x00, 0x0C, 0x4E, 0xFE,
      0xFF, 0x33, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3C, 0x00, 0x06,
      0x00, 0x0C, 0x77, 0xFF, 0xFF, 0x33, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x7F, 0x7F, 0x00, 0x23, 0x00, 0xCE, 0xFF, 0xFF, 0xFF, 0x16, 0xF8, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x85, 0x01, 0x00, 0x1E, 0xFE, 0xFF,
      0x7F, 0x10, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC7, 0x01,
      0x80, 0x0F, 0xFF, 0xFF, 0x3F, 0x10, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0x67, 0x00, 0xD8, 0x1F, 0xFF, 0xFF, 0x7F, 0x10, 0xFE, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF};

    const char* xtemp[1024]; // Temporary array to store JSON incoming Hex as string
    const unsigned char* xbm[1024] U8X8_PROGMEM;

    void setup(void) {
      Serial.begin(115200);
      // Read xbm from  json
      SPIFFS.begin();

       if (SPIFFS.exists("/1.json")) {
        Serial.println("1.json found in SPIFFS");
        File configFile = SPIFFS.open("/1.json", FILE_READ);
          if (configFile) {
            size_t size = configFile.size();
            // Allocate a buffer to store contents of the file.
            std::unique_ptr<char[]> buf(new char[size]);

            configFile.readBytes(buf.get(), size);
            DynamicJsonBuffer jsonBuffer;
            JsonObject& json = jsonBuffer.parseObject(buf.get());
            //json.printTo(Serial);

            if (json.success()) {
              Serial.println("json.success");
              JsonArray& arr = json["xbm"];

              // using C++11 syntax (preferred):
              int c=0;

              for (auto value : arr) {
                // Assign the json array to xtemp
                xtemp[c] = value.as<char*>();

                //Serial.println(String(c)+":"+value.as<char*>()); // Right value
                c++;
              }

            } else {
              Serial.println("ERR load config");
            }

            configFile.close();
          }
       }
      u8g2.begin();
      u8g2.setDrawColor(0);
      u8g2.clearBuffer();

      Serial.println("cross_block_bits size:");
      Serial.print(sizeof(image));
      Serial.println(image[1]);

      //xbm = xtemp;

      Serial.println("xbm:");
      Serial.println(xtemp[1]);

     // Should be xbm (coming from json)   xbm
     // u8g2.drawXBM( 0, 0, 128, 64, xtemp); // Does not work since requires  'const uint8_t* {aka const unsigned char*}
      u8g2.drawXBM( 0, 0, 128, 64, image);

      u8g2.sendBuffer();
    }

    void loop(void) {

    }

body:
Thanks and credits to Majenko. Sorted it out, still I don't know why addressing an existing image works but targeting a new array doesn't. Anyways as proof-of-concept that an XBM Icon can be loaded from JSON it works. For anyone wanting to achieve this, here is the code, make sure to upload [some JSON to Spiffs][2] first:

    /*
      GraphicsTest.ino
      Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
    */
    #include "FS.h"
    #include "SPIFFS.h"
    #include <U8g2lib.h>
    #include <ArduinoJson.h>
    #include <Wire.h>

    /*
      U8glib Example Overview:
        Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
        Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
        U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.

    */
    U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16);

    static unsigned char image[] U8X8_PROGMEM  = {
      0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x17,
      0xFC, 0xFF, 0xFF, 0xFF, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00,
      0xFF, 0xFF, 0xFF, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF0, 0xFF, 0xFF,
      0xFF, 0x7F, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x14, 0xFD, 0xFF, 0xFF, 0xFF,
      0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x8F, 0xFF, 0x10,
      0x7E, 0xFF, 0xFF, 0xFF, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00,
      0xFE, 0x8F, 0xFF, 0x90, 0x7F, 0xFF, 0xFF, 0xFF, 0x00, 0xFE, 0xFF, 0xFF,
      0xFF, 0xFF, 0x03, 0x00, 0xFC, 0x0F, 0xFF, 0x90, 0xFF, 0xEE, 0xFF, 0xFF,
      0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0xFF, 0x0F, 0xFF, 0x90,
      0xFF, 0xCC, 0xFF, 0xFF, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x00,
      0xFF, 0x0F, 0xFF, 0x92, 0xFF, 0xC0, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0x1F, 0x00, 0xFF, 0x1F, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0xFF, 0xFF, 0xFF, 0xFE,
      0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x00,
      0xFC, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0x7F, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0xF8, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x00,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0x3F, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF,
      0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0xFC, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00,
      0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0x3F, 0x00, 0xFC, 0xC7, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF,
      0x00, 0xFF, 0xF7, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0xFE, 0xE7, 0xFF, 0xFF,
      0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xF7, 0xFF, 0xFF, 0xFF, 0x3F, 0x00,
      0xFC, 0xE7, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0xF7, 0xFF,
      0xFF, 0xFF, 0x3F, 0x00, 0xFC, 0xE7, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF,
      0x00, 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0xFE, 0xC7, 0xFF, 0xFF,
      0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0xFF, 0x0F, 0xFF, 0xFF, 0xFF, 0x0F, 0x00,
      0xFE, 0xCF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0x03, 0x07, 0xFF,
      0xFF, 0xFF, 0x0F, 0x00, 0xFC, 0xEF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF,
      0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0xFE, 0xEF, 0xFF, 0xFF,
      0xFF, 0xFE, 0xFF, 0xFF, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x1F, 0x00,
      0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xA6, 0xFF,
      0xFF, 0xFF, 0x1F, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0x06, 0xEE, 0xFF, 0xFF, 0x7F, 0x3F, 0x80, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x0E, 0xEF, 0xFF, 0xFF, 0xFF, 0x1E, 0x80,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFE, 0xFF, 0xFF,
      0xFF, 0xFF, 0x5E, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF,
      0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFD, 0xFF, 0xFF, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0xFD,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0x00, 0xFC, 0xFF, 0xFF,
      0xFF, 0xFF, 0x5F, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF,
      0x00, 0xF9, 0xFF, 0xFF, 0x7F, 0x80, 0xC6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFA, 0xFF, 0xFF, 0x7F, 0x80, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF0, 0xFF, 0xFF,
      0x6F, 0x80, 0xD1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0xF0, 0xFF, 0xFF, 0x2F, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF1, 0xFF, 0xFF, 0x27, 0x00, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF1, 0xFF, 0xFF,
      0x23, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0xF2, 0xFF, 0xFF, 0x31, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFD, 0xFF, 0xFF, 0x00, 0xF2, 0xFF, 0xFF, 0x10, 0x00, 0x74, 0xF8,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0x00, 0xF6, 0x7F, 0xFE,
      0x10, 0x00, 0xFC, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF,
      0x00, 0xF6, 0x3F, 0x00, 0x10, 0x00, 0xF4, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xB4, 0x0F, 0x00, 0x18, 0x00, 0xF0, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xB4, 0x07, 0x00,
      0x08, 0x00, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x00, 0xBC, 0x03, 0x00, 0x08, 0x00, 0xFD, 0xF3, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFB, 0xFF, 0xFF, 0x00, 0x38, 0x01, 0x00, 0x08, 0x00, 0xF9, 0xF9,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF, 0x00, 0x3C, 0x00, 0x00,
      0x0C, 0x90, 0xFF, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF,
      0x00, 0x3C, 0x00, 0x00, 0x04, 0x00, 0xE3, 0x78, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFB, 0xFF, 0xFF, 0x00, 0x38, 0x00, 0x00, 0x06, 0x00, 0xC3, 0x31,
      0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF, 0x00, 0x3C, 0x00, 0x00,
      0x06, 0x80, 0xE3, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF,
      0x7F, 0x1C, 0x00, 0x00, 0x03, 0x80, 0x60, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFB, 0xFF, 0xFF, 0xFF, 0x19, 0x00, 0x80, 0x01, 0x08, 0xF0, 0x00,
      0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0xC0,
      0x00, 0x08, 0xF0, 0x83, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF,
      0xFF, 0x1F, 0x00, 0xC0, 0x00, 0x28, 0xF8, 0xE3, 0xFF, 0xF7, 0xFF, 0xFF,
      0xFF, 0xFB, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x60, 0x00, 0x08, 0xFC, 0xE6,
      0xFF, 0xCD, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF, 0xFF, 0x1B, 0x00, 0x30,
      0x00, 0x04, 0x3C, 0xF8, 0xFF, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0x79, 0x40, 0x18, 0x00, 0x1C, 0x9E, 0xFC, 0xFF, 0x03, 0xFF, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1C, 0x00, 0x0C, 0x00, 0x0C, 0x4E, 0xFE,
      0xFF, 0x33, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3C, 0x00, 0x06,
      0x00, 0x0C, 0x77, 0xFF, 0xFF, 0x33, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0x7F, 0x7F, 0x00, 0x23, 0x00, 0xCE, 0xFF, 0xFF, 0xFF, 0x16, 0xF8, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x85, 0x01, 0x00, 0x1E, 0xFE, 0xFF,
      0x7F, 0x10, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC7, 0x01,
      0x80, 0x0F, 0xFF, 0xFF, 0x3F, 0x10, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
      0xFF, 0xFF, 0x67, 0x00, 0xD8, 0x1F, 0xFF, 0xFF, 0x7F, 0x10, 0xFE, 0xFF,
      0xFF, 0xFF, 0xFF, 0xFF};

    // Using this new array I could not get it work. Rewriting image works
    long unsigned int xbm[1024];

    void setup(void) {
      Serial.begin(115200);
      // Read xbm from  json
      SPIFFS.begin();

       if (SPIFFS.exists("/1.json")) {
        Serial.println("1.json found in SPIFFS");
        File configFile = SPIFFS.open("/2.json", FILE_READ);
          if (configFile) {
            size_t size = configFile.size();
            // Allocate a buffer to store contents of the file.
            std::unique_ptr<char[]> buf(new char[size]);

            configFile.readBytes(buf.get(), size);
            DynamicJsonBuffer jsonBuffer;
            JsonObject& json = jsonBuffer.parseObject(buf.get());
            //json.printTo(Serial);

            if (json.success()) {
              Serial.println("json.success Size of xbm array");

              JsonArray& arr = json["xbm"];

            Serial.print(sizeof(arr));
              // using C++11 syntax (preferred):
              int c=0;
              const char* tempx;
              for (auto value : arr) {
                // Assign the json array to xtemp
                tempx = value.as<char*>();

                image[c] = strtol(tempx, NULL, 16);

                  //Serial.print(strtol(tempx, NULL, 16)); //Thx. Majenko
                  if (c<10) {
                  Serial.print("i:");Serial.print(image[c]);Serial.print(" ");
                  }
                c++;
              }
              Serial.print("Final c count:"+String(c));

            } else {
              Serial.println("ERR loading JSON");
            }

            configFile.close();
          }
       }
      u8g2.begin();
      u8g2.setDrawColor(0);
      u8g2.clearBuffer();

      Serial.print("image size:");
      Serial.print(sizeof(image));Serial.println();  // Here is 4096 also 4 times bigger, if I use a new array (WHY?)
      // Send the JSON array to oled display
      u8g2.drawXBM( 0, 0, 128, 64, (const uint8_t *)image);
      u8g2.sendBuffer();
    }

    void loop(void) {

    }

[![XBM picture from Json: Proof of concept][1]][1]

  [1]: https://i.stack.imgur.com/QSc0J.jpg
  [2]: https://github.com/martinberlin/esp/tree/master/oled-128x64-xbm/data


sender: user

message:
Running ESP8266 at 3.78V to work with ATMEGA328P at 16 MHz

I have a project that is powered by 2x 18650 battery and feeds it to a step down switching voltage regulator that is configured to give a steady output of 3.78V to both esp8266 and atmega328p.

The esp8266 only sends an HTTP post request to an API every 30 mins and on standby mode whenever it does not do anything.
I have tested it for 1 hour and the esp8266 seems to work fine and does not warm. I intend to use the esp8266 in an airconditioned office 24/7 or until the battery runs out. I know it is not safe to give 3.78V because its supposed to have only a maximum of 3.6V but I am asking if anyone has ever had the same application and did not experience any problems?

sender: assistant

body:
Other possibilities include:

 - Running the Atmega328p at 8MHz and powering at 3.3v. Both devices would be operating within spec.

 - Running the whole system at 3.3v but without changing the clock on the '328. The advantage here is you'll get the full throughput from the '328, assuming you need it. The disadvantage (assuming a 16MHz Atmega328p) is that it will be running out of spec (overclocked) but they seem to be conservatively enough speced that most chips do fine. I have built two boards this way for the same reason: to put both a 328p and an ESP8226-01 on one board. I ran some rather rudimentary tests on the Atmega chips I put on those boards to find out if they would work at that voltage. I didn't see any issues and I haven't discovered any since.

Update:

> Would it be possible to run the ATmega at 8 MHz using a 16 MHz
> external oscillator by simply uploading a new sketch?

It may be possible to use its internal resonator and ignore the connected crystal; I haven't tried this. Could you clip off the external crystal if you needed to?

[This article][1] talks about setting the fuses that control the clock frequency. One thing to keep in mind is you'll need to replace the bootloader with one appropriate for the new clock frequency. You may find an 8Mz bootloader ready to upload, or recompile it yourself from source. [Optiboot][2] is a good choice: open source, has a small footprint, and you can set its upload baud-rate. You can upload a new bootloader using another Arduino as an ISP programmer - there are lots of articles about doing this and the code for the Arduino-as-programmer is one of the Arduino IDE example-programs.

  [1]: http://www.martyncurrey.com/arduino-atmega-328p-fuse-settings/
  [2]: https://github.com/Optiboot/optiboot


message:
How to send an integer through pyserial with Python to an Arduino and get back the same result?

There has been similar questions all over the internet but none of them seem to answer my question, so can anybody tell me what is wrong with this code and how I can fix it?

Python code:

    import serial

    arduino_linux=serial.Serial("/dev/ttyACM0",9600)
    while True:
        print('write:',str.encode('90')) #print the sent value through the serial to check it with the readed value
        arduino_linux.write(str.encode('90'))#send the following value
        print('readed:',arduino_linux.read())#read the same value back from the arduino

my arduino code is as follows

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

    }

    void loop() {
      Serial.write(Serial.read());

    }

this is a simple sample of a project, my aim from this code is to send the integer number 90 from the pyserial and make sure the value the Arduino is reading is the same integer.

In case if necessary my project is an object follower with object detector and after calculating all the angles and everything it sends them to the Arduino so the Arduino can act up on the servo's.

This is the result I am getting:

[![enter image description here][1]][1]

But I would like something like:

    write:b '90'

`readed:b '90'`, not `b'9'` or `b'0'`

I would also like to know how I can change these bytes to integers before I write them to a servo.

  [1]: https://i.stack.imgur.com/vrSJZ.png

body:
Use `Serial.write()` on Arduino to send raw bytes. `print` converts them to text.

`read` is not blocking, it doesn't wait for a byte and returns -1 if the receive buffer is empty. Check if read returned -1 or use `Serial.available()` to get the number of bytes in the RX buffer.

Serial 'echo':

    void loop() {
      if (Serial.available()) {
        Serial.write(Serial.read());
      }
    }

  [1]: https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial.read


message:
ESP8266 GET method error

I am working on ESP8266 and I want to send a GET request with AT command to my localhost but I failed every time. Can you help me solve this problem please? Thank you for interest!
I attached my terminal code and my code:
<!-- language-all: lang-cpp -->

    #define ag_ismi "SUPERONLINE_WiFi_8022"
    #define ag_sifresi "rC5YGNYebuCf"
    #define IP "192.168.1.9"

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

      Serial.begin(115200);
      Serial.println("AT");
      delay(3000);
      if(Serial.find("OK")){
        Serial.println("AT+CWMODE=1");
        delay(2000);
        String baglantiKomutu=String("AT+CWJAP=\"")+ag_ismi+"\",\""+ag_sifresi+"\"";
        Serial.println(baglantiKomutu);
        delay(5000);
      }
    }

    void loop() {
      // put your main code here, to run repeatedly:
      delay(60000);
      Serial.println("AT+CIPMUX=1");
      Serial.println("AT+CIPSTART=\"TCP\",\"192.168.1.9\",8000");
      delay(1000);
      String model = "GET /kanbanDB/arduino?model=1 HTTP/1.1";
      //model+="Host: 192.168.1.9:8000\r\n\r\n";
      model+="r\n\r\n";
      Serial.println("AT+CIPSEND=" + String(model.length()));
      Serial.println("\r\n\r\n");
      delay(1000);
      Serial.println(model);
      Serial.println("\r\n\r\n");
      delay(1000);
      Serial.println("");
    }

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/Zop7L.jpg

body:
It should be

    String model = "GET /kanbanDB/arduino?model=1 HTTP/1.1\r\n";
    model+="Host: 192.168.1.9\r\n\r\n";

remove `Serial.println("\r\n\r\n");` before `Serial.println(model);` it is send before GET line

    Serial.println("AT+CIPSTART=\"TCP\",\"192.168.1.9\",8000");
    String model = "GET /kanbanDB/arduino?model=1 HTTP/1.1\r\n";
    model+= "Host: 192.168.1.9\r\n\r\n";
    Serial.print("AT+CIPSEND=");
    Serial.println(model.length());
    delay(1000);
    Serial.print(model);
    delay(1000);

EDIT:
Remove debug prints to Serial or use SoftwareSerial to connect the esp8266 to Uno. Now the debug prints are sent to esp8266 mixed with AT commands and data. For SoftwareSerial [change the default baud rate of the AT firmware][1].

  [1]: https://arduino.stackexchange.com/questions/57496/arduino-uno-with-esp8266-01-with-at/57507#57507


message:
I have the code printing the data I need but don't know how to connect the data on ESP8266 IP web server

[![enter image description here][1]][1][![enter image description here][2]][2][![enter image description here][3]][3]

       #include "DHT.h"
       #include "NewPing.h"
       #include <SoftwareSerial.h>

       #define DEBUG true
       SoftwareSerial esp8266(11,10);
       #define DHTPIN 2        // DHT-11 Output Pin connection
       #define DHTTYPE DHT11   // DHT Type is DHT 11 (AM2302)
       #define TRIGGER_PIN 4
       #define ECHO_PIN 3
       #define MAX_DISTANCE 400

        NewPing sonar(TRIGGER_PIN,ECHO_PIN,MAX_DISTANCE);
    float hum;
    float temp;
        DHT dht(DHTPIN, DHTTYPE);

    void setup() {

       Serial.begin (9600);
       dht.begin();

       pinMode(TRIGGER_PIN, OUTPUT);
       pinMode(ECHO_PIN, INPUT);

       sendData("AT+RST\r\n",2000,DEBUG);
       sendData("AT+CWMODE=2\r\n",1000,DEBUG);
       sendData("AT+CIFSR\r\n",1000,DEBUG);
       sendData("AT+CIPMUX=1\r\n",1000,DEBUG);
       sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG);

     }

     void loop()

     {

     delay(2000);  // Delay so DHT-11 sensor can stabalize

       hum = dht.readHumidity();  // Get Humidity value
       temp= dht.readTemperature();  // Get Temperature value

     digitalWrite(TRIGGER_PIN, LOW);
     delayMicroseconds(2);
     digitalWrite(TRIGGER_PIN, HIGH);
     delayMicroseconds(10);
     digitalWrite(TRIGGER_PIN, LOW);

       long duration,distance;
       duration= pulseIn(ECHO_PIN,HIGH);
       distance = duration/58.2;

       Serial.print("Humid: ");
       Serial.print(hum);
       Serial.print(" %, Temp: ");
       Serial.print(temp);
       Serial.print(" C, ");
       Serial.print("Distance: ");
       Serial.print(distance);
       Serial.println(" cm");

       delay(50);

      if(esp8266.available())

       is sending a message
     {
       if(esp8266.find("+IPD,"))
     {
     delay(1000);

     int connectionId = esp8266.read()-48;

      /* We are subtracting 48 from the
      output because the read() function returns
      the ASCII decimal value and the
      first decimal number which is 0 starts at 48*/

      String webpage = "
IOT Garbage Monitoring System
";
      webpage += "

";

      if (distance<5)
     {
      webpage+= " Trash can is Full";
     }
       else{
       webpage+= " Trash can is Empty";
        }
       webpage += "

";
       String cipSend = "AT+CIPSEND=";
       cipSend += connectionId;
       cipSend += ",";
       cipSend +=webpage.length();
       cipSend +="\r\n";

       sendData(cipSend,1000,DEBUG);
       sendData(webpage,1000,DEBUG);

       String closeCommand = "AT+CIPCLOSE=";
       closeCommand+=connectionId;
       closeCommand+="\r\n";
       sendData(closeCommand,3000,DEBUG);

       }
       }
       }

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

       {

       String response = "";
       esp8266.print(command);
       long int time = millis();

       while( (time+timeout) > millis())
       {
       while(esp8266.available())
       {
       char c = esp8266.read();
       response+=c;
       }
       }
       if(debug)
          {
         Serial.print(response);
          }
         return response;
          }

  [1]: https://i.stack.imgur.com/jGzhC.png
  [2]: https://i.stack.imgur.com/HohXi.png
  [3]: https://i.stack.imgur.com/BhIbr.png

body:
The esp-01 is in AP mode. To access the web page on the IP address 192.168.4.1 show in Serial Monitor you must connect to the WiFi network created by the esp-01.

If you click the WiFi icon in the bottom right corner of Windows, you will see a list of WiFi networks.


message:
Synchronous communication between two Arduino boards using two ESP8266 modules

I am trying to establish communication between two Arduino boards to send data from sensors through a WIFI module. The problem is that I need them to connect to each other whenever they are in range of each other and send the sensor data.

body:
The esp8266 [WiFiMulti][1] system allows to configure more access points and with the rigth code in loop it always searches the best AP.

Configure one of the esp8266 as AP and setup the other with WiFi Multi only for this one  access point.

You can then use events like `onStationModeConnected` to handle data exchange if the connection is established.

  [1]: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiMulti/WiFiMulti.ino


message:
ESP8266-12F accelstepper wont boot

If I use 9, 10, 7, 6 , 8, 11 pins for accelstepper, ESP8266 wont boot
If I use other pins, all good.

What is the problem?

I use accelstepper and Arduino latest versions.

sketch which won't boot -

        #include <AccelStepper.h>
    #include <MultiStepper.h>

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

    const char* ssid = "wiflya";
    const char* password = ".........";

    #define HALFSTEP 8

    // Определение пинов для управления двигателем
    #define motorPin1  13 // IN1 на 1-м драйвере ULN2003
    #define motorPin2  12 // IN2 на 1-м драйвере ULN2003
    #define motorPin3  14 // IN3 на 1-м драйвере ULN2003
    #define motorPin4  16 // IN4 на 1-м драйвере ULN2003

    // Определение пинов для управления двигателем
    #define motor2Pin1  6 // IN1 на 2-м драйвере ULN2003
    #define motor2Pin2  3 // IN2 на 2-м драйвере ULN2003
    #define motor2Pin3  5 // IN3 на 2-м драйвере ULN2003
    #define motor2Pin4  4 // IN4 на 2-м драйвере ULN2003

    // Инициализируемся с последовательностью выводов IN1-IN3-IN2-IN4
    // для использования AccelStepper с 28BYJ-48
    AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
    AccelStepper stepper2(HALFSTEP, motor2Pin1, motor2Pin3, motor2Pin2, motor2Pin4);

    void setup() {
      //Serial.begin(115200);
      //Serial.println("Booting");
      WiFi.mode(WIFI_STA);
      WiFi.begin(ssid, password);
      while (WiFi.waitForConnectResult() != WL_CONNECTED) {
        //Serial.println("Connection Failed! Rebooting...");
        delay(5000);
        ESP.restart();
      }

      stepper1.setMaxSpeed(1300.0);
      stepper1.setAcceleration(400.0);
      stepper1.setSpeed(1300.0);

      stepper2.setMaxSpeed(1300.0);
      stepper2.setAcceleration(400.0);
      stepper2.setSpeed(1300.0);

      //stepper1.moveTo(20000);

      // Port defaults to 8266
      // ArduinoOTA.setPort(8266);

      // Hostname defaults to esp8266-[ChipID]
      // ArduinoOTA.setHostname("myesp8266");

      // No authentication by default
      // ArduinoOTA.setPassword("admin");

      // Password can be set with it's md5 value as well
      // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
      // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");

      ArduinoOTA.begin();
    }

    void loop() {
        // Изменяем направление, если шаговик достигает заданного положения
      //if(stepper1.distanceToGo()==0)
      //  stepper1.moveTo(-stepper1.currentPosition());
      stepper2.runSpeed();
      stepper1.runSpeed();
      //stepper2.runSpeed();

      ArduinoOTA.handle();
    }

body: Pins 6 to 11 of the esp8266 are QIO SPI pins connected to flash memory of the esp8266. You can't use them.


message:
ESP8266 is not responding to AT commands and showing mem_failed on every code

I was using Arduino Uno with ESP8266-12E. Today I was reading an article to blink LED using Webpage. The code wasn't uploading so I connected all the pins connected to 3.3V to 5V. Then the code was uploaded successfully. After that I switched off my laptop and Arduino. After 2-3 hours when I got back to work, the module wasn't responding to AT commands even after reconnecting it to 3.3V. The wifi is working fine since it automatically connects to the WiFi I have configured earlier. I used same settings and connections prior to that messing up. Also on every code upload it shows mem_failed. So, how can I get my WiFi to work?

body:
Buy a little development board and learn how to use the ESP8266. Either a NodeMCU or a WEMOS board. They have a USB to serial adapter on the board and a proper regulator.

The initial problem you encountered was most likely caused by insufficient power for the ESP8266. The power supply must be capable of supplying a minimum of 400mA. It needs to have close short wires to the Vcc and ground on the ESP module. It helps to also have a capacitor across Vcc and ground of the ESP module with short leads.

There are some horrible examples on the internet that show the ESP being powered from and Uno's 3.3v power connection. This will never be reliable if it does even work. There is not enough power.

The ESP8266 typically uses about 80mA. This is an average value. When transmitting the peak current is a lot hight. The worst case happens to be when the ESP starts after a reset. I then does an analog power calibration. (for the RF section) Expressif states this, plus the digital power requirements, will equal above 500mA.

The GPIO pins are not 5 volt compatible. A lot of internet examples show the ESP rx and tx lines connected to the rx and tx of a 5 volt Arduino board, without level converters. This is not acceptable. The RX line of the ESP8266 can be damaged.

Powering the ESP module with 5 volts can damage all or parts of the two chips on the module. (the CPU and the external Flash memory chip) Other sections may still work. That is likely what you are seeing.


message:
Arduino pow() making 9's

I am having a temporary lapse of judgement, or not understanding how the power method works, but when I put 10 to the power of a number, it is that value -1.  So:

    10*10 = 100

Then I would assume, `10^2 = 100`

So if I had a variable `i`, that was equal to `2`, and I asked arduino for `10` to the power of `i`, I would expect it to do `10^2`, and then give me `100`, but instead I get `99`.  What am I missing?

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

    void loop() {
    for (int i =0; i<5; i++){
       int power = i;
       Serial.print(power);
       Serial.print(":");

       int multiplier = pow(10,power);
       Serial.println(multiplier);

      }

    }

body:
`pow()` works with floating point numbers.

Floating point numbers are just an approximation.  You will very rarely get precise results using floating point numbers.

Instead you could write your own little [integer-based `ipow()` function.](https://stackoverflow.com/questions/101439/the-most-efficient-way-to-implement-an-integer-based-power-function-powint-int)


body:
I put this code into the IDE, and for n>=2, I got 99, 999, 9999 etc. The catch is that Arduino uses floating point arithmetic to implement the pow() function, and some of your values are being truncated as ints. If you change:

       int multiplier = pow(10,power);

to

       float multiplier = pow(10,power);

The results should be as expected.

(The brief reason why floats are used is related to the fact that it is very easy to calculate the pow() function using logs, and this makes it easy to pow() non-integers too. This also means that it may not be as exact as you would hope).


message:
Using timer classes within classes

I am trying to develop a class for a pump that works on a stepper motor, it should be simple but its not working the way I thought it would. Once I move the timer object into the class the code wont compile I have tried a lot of things but nothing seems to work correctly. The goal of this whole thing is getting the stepper motor to step on its own based off of the calls from the timer object.

pump.h

    #include "TimerObject.h"`
    #ifndef Pump_h
    #define Pump_h

    class Pump
    {
      public:
      Pump(char pin_, char dir_);
     void pumpstep(void);
      private:
        char pin;
     char dir;
     TimerObject *pumptimer;
    };

    #endif

pump.cpp

    Pump::Pump(char pin_, char dir_)
    {
     pin = pin_;
     dir = dir_;
     pumptimer = new TimerObject(100, &this->pumpStep); //PROBLEM IS HERE

      pinMode(pin, OUTPUT);
      pinMode(dir, OUTPUT);
    }

    void Pump::pumpstep(void) {
         Serial.println("Stepping");
    }

my .ino simply creates the class passing in the needed parameters but everything binds up when I try to compile because of the callback in the constructor for the timer, for some reason It wont let me use the address of a non-static method here but I cant make the method static each pumpstep() method must be separate depending on which pump is running.
I have tried using &Pump::pumpstep, &(Pump::pumpstep) and many more pointers but cant seem to get the one I need.

outside this class the timer was working great I used this line below:

    pumptimer = new TimerObject(100, &pumpStep);

The library for the timer can be found here:
https://playground.arduino.cc/Code/ArduinoTimerObject

Any help would be greatly appreciated.

body:
The function prototype of a member function is completely different to that of a global function. The two are not interchangeable.

There are ways of working around it, such as "bouncing" your callback through a global function, but they're messy.

However, in this situation you are better off just ditching TimerObjects.h and doing it manually - it's not exactly difficult:

    #ifndef Pump_h
    #define Pump_h

    class Pump
    {
      public:
         Pump(char pin_, char dir_);
         void pumpstep(void);
         uint32_t ts;
         void run()
      private:
        char pin;
        char dir;
    };

    #endif

----

    Pump::Pump(char pin_, char dir_)
    {
        pin = pin_;
        dir = dir_;
        ts = 0;
        pinMode(pin, OUTPUT);
        pinMode(dir, OUTPUT);
    }

    void Pump::pumpstep(void) {
         Serial.println("Stepping");
    }

    void Pump::run() {
        if (millis() - ts >= 100) {
            ts += 100;
            pumpStep();
        }
    }

Then in loop call:

    myPump.run();

You can, of course, just combine `run()` and `pumpstep()` into one single function.


message:
Programming stepper motor move a fixed step till it reach the target

I have a stepper motor and try to program it like this but I kinda stuck since I'm new to Arduino.
1. The target is set to 2048, means motor have to move 2048 steps.
2. I program the motor to run 200 steps each time, every 200 steps will stop for a sec until it reach 2048.

I've been using AccelStepper library to program my motor, I found out it is very hard for me to program like this. I'm not asking to do my homework but I dunno where to start. Just wanted to ask what method can I use to program the motor to work like this. Thank you.

body:
I would start with the Blocking example provided with the library. Add the delays you need, the steps/distance you want. The following is simple but crude. It is call blocking code. It can only do the following sequence, but sometimes that is good enough.

A bit better would be to have a conditional loop to get to the final target. The loop would move 200, then delay 1 second, subtract the amount moved. Loop until you use up all the required distance. But initially I suggest to keep it simple and just make it work with inline sequences.

    #include <AccelStepper.h>
    // Define a stepper and the pins it will use
    AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
    void setup()
    {
        stepper.setMaxSpeed(200.0);
        stepper.setAcceleration(100.0);
    }
    void loop()
    {
        stepper.runToNewPosition(0);
        delay(1000);
        stepper.runToNewPosition(200);
        delay(1000);
        stepper.runToNewPosition(200);
        delay(1000);
        stepper.runToNewPosition(200);
    }


message:
Unable to get output on Arduino serial communication with ESP8266 and M6E RFID reader

I am unable to get the output on NODEMCU serial. NODEMCU is connected with Arduino Uno, and Uno is connected with M6E Nano RFID reader. Currently I am unable to understand that am i doing any mistake. Please let me know if any other thing you require.

NodeMCU and M6E Nano RFID reader pin configuration with Arduino Uno

    NodeMCU         UNO
    Vin             Vin
    GND             GND
    D2              2
    D3              3

Code for Arduino Uno+M6E Nano RFID Reader

    #include <SoftwareSerial.h>
    SoftwareSerial softSerial(2, 3);

    #include "SparkFun_UHF_RFID_Reader.h"
    RFID nano;

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

      while (!Serial);
      Serial.println();
      Serial.println("Initializing...");
    }

    void loop()
    {
      byte response;
      byte myTID[20]; //TIDs are 20 bytes
      char str[sizeof(myTID) * 2 + 1];
      const char* hex = "0123456789ABCDEF";

      //Read unique ID of tag
      response = nano.readTID(myTID, sizeof(myTID));
      if (response == RESPONSE_SUCCESS)
      {
        for (int i = 0; i < sizeof(myTID); i++)
        {
          str[i * 2] = hex[(myTID[i] >> 4)];
          str[i * 2 + 1] = hex[(myTID[i] & 0x0F)];
          }
        str[sizeof(str)] = 0;
        Serial.println(str);
       }
      else
        Serial.println("Failed read");
    }

Code for NODEMCU

    #include <ESP8266WiFi.h>
    #include <SoftwareSerial.h>
    SoftwareSerial NodeMCU(D3,D2);

    void setup()
    {
      Serial.begin(9600);
      NodeMCU.begin(4800);
      pinMode(D2,OUTPUT);
      pinMode(D3,INPUT);
    }

    void loop(){
      String str = 0;        // stores received byte

      if(NodeMCU.available())
      {
        // get byte from USB serial port
        str = Serial.read();
        NodeMCU.write(str);
      }
    delay(30);
    }

Unable to find where i am doing the mistake! Thanks in advance

body:
 1. You have not the same baud rate on both ends.
 2. SoftwareSerial is not reliable at 115200. use 9600 baud
 3. SoftwareSerial on esp8266 is not reliable.

remove Uno from the project and connect the reader to NodeMcu


message:
Using 2 piezo buzzers to emit the same tone with phase difference

For a physics project, I want to record the effect of 2 speakers emitting 100hz at different phase differences. Trouble is, the Arduino can only send one tone() signal at a time. How do I create a phase difference effect using one Arduino?

body:
Since the frequency is so low, you can generate the signals in software.
That would not be as clean as timer-generated signals, but it will be
much easier. And probably clean enough for the intended purpose.

In order to generate a tone, you have to repeatedly switch the pin
connected to the piezo. This is very similar to blinking an LED, only
somewhat faster. Blinking an LED is the very first thing you learn to do
with an Arduino, but you may notice that blinking **two** LEDs is a
little bit trickier. The problem – and the solution – is
discussed in the Arduino tutorial [Blink Without Delay][]. Building on
that tutorial, here is an example program that generates two 100 Hz
signals in quadrature:

    const uint8_t PIN_A = 8;
    const uint8_t PIN_B = 9;
    const uint32_t HALF_PERIOD = 5000;  // 5000 us
    const float PHASE_SHIFT = 0.25;     // 1/4 period

    uint8_t state_A = LOW;
    uint8_t state_B = LOW;

    uint32_t last_A_toggle = 0;
    uint32_t last_B_toggle = - 2 * HALF_PERIOD * PHASE_SHIFT;

    void setup() {
        pinMode(PIN_A, OUTPUT);
        pinMode(PIN_B, OUTPUT);
    }

    void loop() {
        uint32_t now = micros();
        if (now - last_A_toggle >= HALF_PERIOD) {
            last_A_toggle += HALF_PERIOD;
            state_A = !state_A;
            digitalWrite(PIN_A, state_A);
        }
        if (now - last_B_toggle >= HALF_PERIOD) {
            last_B_toggle += HALF_PERIOD;
            state_B = !state_B;
            digitalWrite(PIN_B, state_B);
        }
    }

If you compare this with the above mentioned tutorial, there are a
couple of differences worth noticing:

- The timings are measured using microseconds rather than milliseconds,
  for getting a better accuracy
- The variables holding the times of last toggle are updated like
  `last_A_toggle += HALF_PERIOD` rather than `last_A_toggle = now` (the
  equivalent of `previousMillis = currentMillis`). This is needed to
  keep an accurate average frequency. Otherwise the time taken to
  execute the code would make the frequency slightly off.

There is a little trickery in the initialization of `last_B_toggle`,
which is an unsigned number initialized to a negative value. The
initialization is valid and works modulo 232. Using a small
positive value would have the ill effect of `now - last_B_toggle`
overflowing to a very large positive number on the first run of
`loop()`, putting `last_B_toggle` effectively in the distant past.

[Blink Without Delay]: https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay


body:
For a very simple example you can do something like this:

    #define SPEAKER1_PIN 5
    #define SPEAKER2_PIN 6

    void setup() {
      pinMode(SPEAKER1_PIN, OUTPUT);
      pinMode(SPEAKER2_PIN, OUTPUT);
    }

    void loop() {
      int phase_delay = 1000;   // Phase delay (in us)
      int freq_delay = 5000; // Half of square wave at 100Hz (5000us)

      // Generate 2 square waves (out of phase)
      while(1) {
        digitalWrite(SPEAKER1_PIN, HIGH);
        delayMicroseconds(phase_delay);
        digitalWrite(SPEAKER2_PIN, HIGH);
        delayMicroseconds(freq_delay - phase_delay);
        digitalWrite(SPEAKER1_PIN, LOW);
        delayMicroseconds(phase_delay);
        digitalWrite(SPEAKER2_PIN, LOW);
        delayMicroseconds(freq_delay - phase_delay);
        }
    }

By the way, 100Hz may be to low of a frequency to get much sound out of a Piezo speaker.  You'll likely have better success by using higher frequencies.


message:
GMS send SMS text messages many times

The GSM sends many SMS text messages and does not stop. How to send only one SMS?
This is my code:
<!-- language-all: lang-cpp -->

    #include <SoftwareSerial.h>
    SoftwareSerial mySerial(9, 10);
    char msg;
    int vibr_pin = 7;

    void setup() {
      mySerial.begin(9600);   // Setting the baud rate of GSM Module
      Serial.begin(9600);   // Setting the baud rate of Serial Monitor (Arduino)
      pinMode(vibr_pin, INPUT);
      delay(100);
    }

    void loop() {
      int a;
      a = digitalRead(vibr_pin);
      if (a == 0) {
        mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
        delay(1000);  // Delay of 1000 milli seconds or 1 second
        mySerial.println("AT+CMGS=\"+60125456758\"\r"); // Replace x with mobile number
        delay(1000);
        mySerial.println("test 1,2,3"); // The SMS text you want to send
        delay(100);
        mySerial.println((char) 26); // ASCII code of CTRL+Z
        delay(1000);
      }
    }

**EDIT:**
After I change `if (a==0)` to `if(a!=0)`, it only sends message when the vibration sensor is moving. How to send sms when sensor is not moving?

body:
    int a;
    a = digitalRead(vibr_pin);
    if (a == 0) {

This sends an SMS text message every time a is 0. I'm not sure what vibr_pin does, but maybe you want to check only for a trigger (from `a != 0` to `a == 0`).

In that case, use a boolean to check if the SMS text message has been sent, and reset the boolean when a goes from `!=0` to `0`.


message:
Using Serial Plotter with Visual Studio Code

I'm using the [Visual Studio Code extension](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino) to develop for Arduino which works great.

It doesn't have a Serial Plotter like the regular Arduino IDE, which I need to debug this project. I can run the Arduino IDE's Serial Plotter alongside Visual Studio Code without too much of a problem.

However, if I try to compile and upload from Visual Studio Code while the Arduino IDE is running, the port is busy (not a surprise):

    avrdude: ser_open(): can't open device "/dev/cu.usbmodem14201": Resource busy
    An error occurred while uploading the sketch

So I have to keep exiting and relaunching the Arduino IDE every time I build.

Anyone have a suggestion for how to work around this? Using an iMac as development environment.

body:
Without very specialized software that can create two new devices with the correct "teeing" policy, it's not going to be possible.  Only one program can open a serial port at a time (certainly and have it get anything intelligible out of it...)

I would suggest you may want to add a second serial port.  Use an FT232 adaptor to communicate on another serial connection (or a SoftwareSerial connection at a pinch) for your debugging information.  You really want a board with more than one serial port for this - or a board with a native USB for programming and a hardware serial port for data communication.

Another alternative is to ditch the serial for programming altogether and program your board through a dedicated programmer, thus leaving your serial port free for data communication.


message:
Board Updating problems

I have updated Arduino AVR Boards in IDE and before I updated, ESP8266 boards were working, now after I updated, it says "Error downloading "URL for esp"" and no matter which website I listed inside the preference:

    http://arduino.esp8266.com/stable/package_esp8266com_index.json
    https://github.com/esp8266/Arduino/releases/download/2.3.0/package_esp8266com_index.json

None of them are being downloaded and I cannot program ESP8266. Can I get some help? Thank you.

body:
If you are using windows 10 try installing from git followimg the instruction here.

https://arduino-esp8266.readthedocs.io/en/latest/installing.html

That was how I get it to work when I found updating it through the ide didn't work


message:
Arduino Pro Micro TX and RX leds flash quikly while power drawn from VCC pin

I just got a 5V Arduino Pro Micro, which I connected to an RC RX powered from the VCC and GND pins of the board.

However, whenever I do so and power on the board from a computer USB connection or a wall adapter USB connection, the board goes into an odd mode where the red RX and TX leds flash rapidly (*~0.5s on and ~0.5s off*) and USB serial ceases functionality. (*presumably, because the MCU isn't on anymore*)

If I remove the load and power the board again, everything works as normal.

This is an odd behavior, especially since I read online that the VCC pin is rated for ~150ma max and my device ([FS-iA6b][1]) isn't a very high power device, tested by me to draw 30-50ma max.

What is happening here? I haven't even connected the 5v signal pin yet!

  [1]: http://img.banggood.com/file/products/20151222032156FS-i6S User Manual.pdf

body:
Aah, I figured it out! @JeffWahaus was correct, the RC RX was placing too great a strain on the Arduino Pro Micro. My latest working theory is that when the RC RX is in communication with the RC TX, it has current spikes that allow the system current draw to exceed that required to drop the voltage coming out of the 5V regulator below that required to shut off the ATmega32U4 MCU.

The solution I found, upon recommendation, was to move the RC RX voltage source from the `VCC` pin to the `RAW` pin which taps power from ahead of the 5V regulator and add a 10uf capacitor in parallel with the RC RX to smooth out any current spikes.

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/EJG7a.png)

<!-- End schematic -->


message:
What makes this library work exclusively with Atmega328P boards?

I've been looking into libraries that read CPPM signals that I can use on my Arduino Pro Micro, and [this one looked promising][1] ([github.com/jmparatte/CPPM][1]) until I read that it only works on Atmega328P chips. Sure enough, I tried it, and it doesn't function on the Pro Micro as it does on my Arduino Uno. Why is this the case, *i.e. what does it have that the Atmega32u4 doesn't*?

> **Implementation**
>
> This library works only on ATmega328 implementation of Arduino UNO,
> Duemillanove and similar, also Leonardo. It uses the 16bit Timer1. So
> PWM analogWrite() on pin 9 and 10 are unavailable. The library Servo
> is not compatible because it also uses Timer1.

I tried to do some research on my own, to no avail:

- [`Timer1` isn't specific to 328P, 32u4 has it][2]
- For all I can tell, there isn't any difference in the interrupt capabilities of the 32u4...
- [`ICR1` and `TCNT` are, again, features that the 32u4 has][2]
- [My signal is connected to the `OC1A` pin that is used as the CPPM source (*pin 9, `PB5`*)][3]

I'm new to this kind of thing and really stumped as to what could be the issue here.

  [1]: https://github.com/jmparatte/CPPM
  [2]: https://alliance.seas.upenn.edu/~medesign/wiki/index.php/Guides/MaEvArM-timer1
  [3]: https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/ProMicro16MHzv1.pdf

body:
That library relies mostly on Timer 1 and, as you already noticed,
the Timer 1 of the ATmega32U4 is very similar, if not identical, to
the one of the 328P. At least similar enough to expect the library to
work identically.

I took a look at both datasheets and the only difference I can see that
can possibly affect the library is the pinout. The pins relevant to the
library are:

           328P  32U4
    ICP1 =  PB0   PD4
    OC1A =  PB1   PB5

The pinout of the 328P is hardcoded into the library. [CPPM.h contains
these lines][CPPM.h]:

<!-- language-all: lang-c++ -->

    #define CPPM_ICP1 8 // Input Capture Pin of Arduino UNO is pin 8 - ICP1 (Atmega328 PB0)
    #define CPPM_OC1A 9 // Output Compare Pin of Arduino UNO is pin 9 - OC1A (Atmega328 PB1)

CPPM.cpp has two instances ([here][CPPM.cpp-1] and [here][CPPM.cpp-2])
of this:

    if ((PINB & _BV(PINB1))) // rising edge ?

If you change the code in these three places to match the pinout of the
32U4, I would expect the library to work for you.

You could also change that conditionally as

    #ifdef __AVR_ATmega32U4__
        ...
    #else // assume ATmega328P
        ...
    #endif

in order to make the library compatible with both MCUs, and then submit
a pull request to the original author.

[CPPM.h]: https://github.com/jmparatte/CPPM/blob/master/CPPM.h#L109-L110
[CPPM.cpp-1]: https://github.com/jmparatte/CPPM/blob/master/CPPM.cpp#L311
[CPPM.cpp-2]: https://github.com/jmparatte/CPPM/blob/master/CPPM.cpp#L328


message:
Keyboard.h not found

I keep getting this error message:

    "'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?"

... when I have already included `Keyboard.h`.

    #include <Keyboard.h>

    void setup() {
      pinMode(3,INPUT_PULLUP);
      pinMode(4,INPUT_PULLUP);

     Serial.begin(9600);    //begin seral comms for debugging
    }

    void loop() {
      Keyboard.begin();
      if (digitalRead(3) == 0) //if button 3 is pushed
       {
    Keyboard.write('z');
    delay(200);
    }
       else if (digitalRead(4) == 0) //if button 3 is pushed
    {
      Keyboard.write('x');
      delay(200);
    }
      Keyboard.end();
    }

`Keyboard.h` is already included as a default library in Arduino so I'm not sure what's wrong

body:
If you have **Arduino/Genuino Uno** selected as your board in the **Tools ► Board ►** menu, then you get the error. If you select **Arduino Leonardo** it compiles correctly.

From [Can't seem to be able use Keyboard.h library][1], [this post][2] states:

> Keyboard.h (and Mouse.h) only works on devices that use the ATmega32u4 processor, like the Leonardo or Micro.  See: https://www.arduino.cc/en/Reference/MouseKeyboard

[This solution][3] might help though

> I had the same problem using Flora
>
> This worked for me:
>
> 1. Tools > Boards > Boards Manager
> 2. Install TeeOnArdu (Then select that board from Boards Manager)
> 3. Tools > USB Type > Serial, Keyboard, Mouse < Joypad
> 4. Upload and run code again (might need to restart IDE)

  [1]: https://forum.arduino.cc/index.php?topic=346139.0
  [2]: https://forum.arduino.cc/index.php?topic=346139.msg2386530#msg2386530
  [3]: https://forum.arduino.cc/index.php?topic=346139.msg3671683#msg3671683


message:
How to fix this code so instead of having to hold button to change led, you can press?

const int buttonPin = 1; // the pin number of the pushbutton input pin
    const int ledPins[] = {2, 3, 4, 5, 10, 11, 12, 13};    // variables will change:
    int buttonState = 0; // variable for reading the pushbutton status
    int buttonPressCount = 0;
    int numberOfLED = 8;

    void setup() {    // initialize the LED pin as an output:
      for (int i = 0; i < numberOfLED; i++) {
        pinMode(ledPins[i], OUTPUT);
      }
      pinMode(buttonPin, INPUT);
    }

    void loop() {    // read the state of the pushbutton value:
      buttonState = digitalRead(buttonPin);    // check if the pushbutton is pressed.    // if it is, the buttonState is HIGH:
      if (buttonState  == HIGH) {
        for (int i = 0; i < numberOfLED; i++) {
          if (buttonPressCount % numberOfLED == i)
            digitalWrite(ledPins[i], HIGH);  // turn LED on
          else
            digitalWrite(ledPins[i], LOW);   // turn LED off
        }
      }
      buttonPressCount++;
      delay(300);
    }

body:
instead of changing every time the buttonState == HIGH, change it when the button state was `LOW` the previous time but `HIGH` now:

    buttonState = digitalRead(buttonPin);
    if (oldButtonState != buttonState && buttonState == HIGH) {
        //...
    }
    oldButtonState = buttonState;

However keep in mind contact bounce. Which can result in multiple transitions being detected. Most solutions for that set a minimal delay between handling transitions, dropping all others detected.


message:
Does SoftwareSerial and the servo library produce interrupt conflicts?

I'm planning a project that will involve multiple serial ports and the Arduino servo library. I have heard that this may cause interrupt conflicts. Are there any simple solutions to this

body:
> I have heard that this may cause interrupt conflicts.

Indeed. The Arduino can only run one interrupt routine at a time, and:

* Servos use rapidly firing interrupts
* SoftwareSerial both turns off interrupts while sending (for relatively long periods)
* SoftwareSerial uses an interrupt for receiving that runs for an extended period

So really you can't use both together.

Options?

1. Use hardware PWM to drive the servos (There is a library for this somewhere)
2. Use an external servo PWM driving board (Adafruit do one IIRC)
3. Don't use SoftwareSerial.  IIRC AltSoftSerial is better, though no software serial implementation will ever be particularly good.

The underlying problem is that the low-end Arduinos only have on serial port. If you need to use more than one serial port then you really need to be looking at using a different Arduino - one with multiple serial ports.


message:
Do I need the Ground and 5 V pin connect to Led?

I am building an ambilight. So I bought a 3 pin LED Strip which I power with the USB hub from my TV. Next step is to connect it to the Arduino Nano. Is it OK when I only use the dataport from the Aduino and the power only from the television?

body: Yes, you can take +5v from the TV's USB and supply data from the Arduino, as long as you connect both the TV's USB-Ground and the Arduino-Ground together.


body:
I think it is not a good idea to power the LED strip via USB.

Normally USB delivers a maximum of mA  (see below). Assuming you have 30 LEDs (minimum for a normal LED strip), and each LED gives 40 mA (maximum), this is already more than what most USB ports can deliver. This can ruin your USB port.

For the Arduino Nano you can use the 5 V, and you should connect all GNDs together.

But you will need a decent adapter anyway for the LED strip, so than you can power your Arduino Nano from the adapter you use for the LED strip.

**Update**

According to [Wikipedia USB power][1]

> Low-power devices (such as a typical USB keyboard) may draw at most 1
> unit load (1 unit load is 100 mA for USB devices up to USB 2.0, while
> USB 3.0 defines a unit load as 150 mA), and all devices must act as
> Low-power devices when starting out as unconfigured.
>
> High-power devices (such as a typical 2.5-inch USB Hard Drive) draw at least 1 unit load and at most 5 unit loads (500 mA) for
> devices up to USB 2.0 or 6 unit loads (900 mA) for SuperSpeed devices.

  [1]: https://en.wikipedia.org/wiki/USB#Power


body:
<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/fz4At.png)

<!-- End schematic -->

Can you follow this? Connect all GNDs. TV 5V can power the Arduino, connect to the 5V/VCC pin and not the Vin pin.  5V power supply only powers the LED strip.  No reason it couldn't power the Arduino as well tho, in which case there would be no need to connect to connect anything to the TV.

PC USB ports typically can only supply 500mA, only enough for 8 RGB LEDs at full white. I doubt your TV can do much more.


message:
3V Arduino options

I have an Arduino Mega board to test 3V devices. Which is the simplest way to connect those 3V devices to the Arduino Mega (it works at 5V) without burning them? I saw the Adafruit Trinket works at 3V, could be an option? Since I need many input/outputs (around 50), Arduino Mega is the most suitable in terms of input/outputs pins.

What do you suggest me to do?

body:
There are plenty of non-Arduno boards that both give you more power and 3.3V operation.  Personally I love the chipKIT boards (the Max32 is the chipKIT equivalent to the Mega2560).

If you want to stick with Arduino then consider the Due, which is the same footprint as the Mega2560 but again with more power and 3.3V operation.

For interfacing 3.3V devices to a 5V board, though, that can be done simply with level shifters.  You need to get the right type though:

* Basic GPIO, SPI and UART etc can be done with a simple MOSFET shifter (cheaply available on eBay)
* I2C requires a special I2C level shifter (I use the PCA9306) which maintains the open-drain and bidirectional operation required for I2C


message:
Weird behavior (Couldn't pull the pin LOW)

I was trying to implement my own code to control a stepper motor on arduino uno, however I noticed that the pins were always HIGH despite what was written to them. I started to erase the code to leave only the crucial part to troubleshoot it and was left with the following

    #define IN1  8
    #define IN2  9
    #define IN3  10
    #define IN4  11
    long int *period;

    void setup() {
    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);
    pinMode(IN3, OUTPUT);
    pinMode(IN4, OUTPUT);
    *period=256;
    }

    void loop() {
     digitalWrite(IN1, LOW);
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, HIGH);
    }

The period statements were leftovers from the previous code, and didn't think of them too much but once I deleted them the code started working. More over, the code worked if the period value was below 256. Once it reached 256 the pins weren't pulling low.

The problem is solved now, however I am interested why would a value of a variable cause such a behavior?

body:
You have an uninitialized pointer:

    long int *period;

It will point to zero (or a register map, see comment Edgar Bonnet below), but you write 256 to it.
Since a long pointer points to 4 bytes, if you write values upto 255 only one byte will be filled (and others are 0), when you write a value from 256, another byte will be filled with a non-zero value.

Anyway, uninitialized pointers can result in strange effects, so initialize it like:

    long int period;

    long int* periodPointer = .

And set the content by

    *periodPointer = 256;


body:
You are creating a pointer variable, not a normal variable.

That pointer variable is, until told otherwise, pointing at address 0x00.  It covers 4 bytes.

Addresses 0x00 to 0x1F are the internal CPU registers R0 to R31.  Your pointer variable points to R0 plus three more addresses above it (a long is 4 bytes in total).

So when you write to your pointer you are directly writing to CPU registers R0, R1, R2 and R3.

According to the [AVR-GCC ABI](https://gcc.gnu.org/wiki/avr-gcc):

* R0 is the scratch register
* R1 is the zero register
* R2 & R3 are general purpose (call-saved) registers.

So if you write 255 to your pointer variable you are doing:

    R0 = 255
    R1 = 0
    R2 = 0
    R3 = 0

And that's no big deal: some things may go a little awry, but nothing major.

However, writing 256 results in:

    R0 = 0
    R1 = 1
    R2 = 0
    R3 = 0

The big thing here is that the *zero register* R1 is now 1, not zero.  The ABI states:

> **R1** always contains zero. During an insn the content might be destroyed, e.g. by a MUL instruction that uses R0/R1 as implicit output register. If an insn destroys R1, the insn must restore R1 to zero afterwards. This register must be saved in ISR prologues and must then be set to zero because R1 might contain values other than zero. The ISR epilogue restores the value. In inline assembler you can use `__zero_reg__` for the zero register.

So R1 must be zero except for a brief moment when you use it for something else.  Since you're setting it to 1 and leaving it as one, any other operations that then rely on that register being zero will have a hard time knowing just what they are doing.

Having a "zero" register is a common thing. There are many times (especially in a RISC architecture) when you want the number zero - and having a register that is guaranteed to always be zero saves a lot of time. For instance, in MIPS the register $0 is hard-wired to be zero and can never change.  AVR doesn't have that luxury, but the GCC compiler imposes the rule for R1 which you have to abide by - since there are huge amounts of library code and other auto-generated code that rely on that register being zero.

So when it's set to one, all gloves are off, and no one can ever really know just what is happening - you'd have to disassemble the code (or get an intermediate listing out of the compiler) to see just what is using R1, and work out what the effect of that being 1 instead of 0 would be.

As an example, `digitalWrite` has this:

            if (val == LOW) {
     370:   11 11     cpse r17, r1
     372:   05 c0     rjmp .+10          ; 0x37e <digitalWrite+0x50>

That's "COMPARE SKIP IF EQUAL".  It's looking at the value you pass (`val`) to see if it's equal to zero - by using R1 as the zero value. But if R1 isn't zero then it will never know that what you passed as LOW is LOW - instead it would find HIGH as LOW, since HIGH is 1 and R1 is 1.  So you've basically swapped HIGH and LOW over as far as `digitalWrite` is concerned.

There are also places where the number 255 is wanted.  This is easy to generate with "eor r1,r1" - exclusive-or of the zero register. EOR turns bits off that are on and on that are off - so zero becomes 255. Except if zero is actually 1, you end up with 254 not 255, and more strange things happen.


message:
HC-05/Arduino receiving spam data

I connected everything properly. On the first try I did receive data as  I was supposed to. I then wrote some logic, re-uploaded and started receiving crazy spam.

My serial monitor is getting spammed with:

 - question marks if the variable is `char`, or;
 -  `25252525252` if the variable is `int`, or;
 - `-1` if variable is `String`.

I'm monitoring at 38400 baud which is the same as my `Serial.begin()`.

Any ideas ?

Code:

    #include <Wire.h>
    #include <Adafruit_PWMServoDriver.h>

    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

    #define MIN_PULSE_WIDTH 650
    #define MAX_PULSE_WIDTH 2350
    #define DEFAULT_PULSE_WIDTH 1500
    #define FREQUENCY 50

    char data = 'a';

    void setup()
    {
      analogReference(DEFAULT);

      Serial.begin(38400);

      pwm.begin();
      pwm.setPWMFreq(FREQUENCY);
      Serial.println("hello world");
    }

    void loop()
    {
      data = Serial.read();
      Serial.println(data);
      Serial.flush();
      if (data == 'a'){
        pwm.setPWM(0, 0, pulseWidth(90));
      }
      if (data == 's'){
        pwm.setPWM(0, 0, pulseWidth(30));
      }
      delay(1000);
      //printing time in seconds
    }

    int pulseWidth(int angle)
    {
      int pulse_wide, analog_value;
      pulse_wide = map(angle, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
      analog_value = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);

      return analog_value;
    }

body:
`Serial.read()` returns -1 if no data is available. It doesn't wait for the byte. Test for -1 or use `Serial.available()` as any example does.

Replace `Serial.print(data)` with `Serial.write(data)` to get the data echoed back unchanged.


message:
Arduino Uno with ESP8266-01. Is that any alternative way to connect Arduino Uno to Wifi

I have bought an ESP8266-01 Wifi module last month, and I am trying to connect Arduino Uno to network so that I could connect to the MQTT broker. However, I failed to upload the sketch/communicate with ESP8266 module due to the error:

    espcomm_open failed
    espcomm_upload_mem failed
    espcomm_upload_mem failed

I think the problem is wiring problem or power supply is unstable because the ESP8266 is required 3.3V to communicate. This is how I connect ESP8266 Wifi module to Arduino Uno, and I just simply connect Arduino Uno to USB port on my laptop:

[![Connection][1]][1]

I've been searching solutions on Internet and watching tutorials but ending up with getting the same error. In addition, I am not using any resistor, capacitor when I do the connection between ESP8266 & Arduino Uno.

These are my confusions as below:

 1. What is the best/easiest way to connect Arduino Uno to Wifi?
 2. How can I avoid power supply issues? Maybe a Serial Adapter Wireless development board or module?
 3. What do I need to connect Arduino Uno to Wifi?
 4. Is it possible to connect Arduino Uno to MQTT broker without using network? I found this [Ardulink][2] but I don't know how to deal with it
 5. Can external wifi shield solve my problem instead of using ESP8266-01?

Thank in advance

  [1]: https://i.stack.imgur.com/y0yuE.jpg
  [2]: http://www.ardulink.org/how-ardulink-mqtt-works/

body:
The Arduino board does not have enough current available to power the ESP8266. You should have a 3.3 volt supply that is capable of at least 500mA. The average current consumption is typically 80mA but the peak currents can go to 600mA during a start up calibration.

You also need to use a proper level converter to connect the RX and TX of each board. The ESP8266 is NOT 5 volt tolerant.

The ESP8266 can be programmed under the Arduino framework. This is how most people use it. (rather than using the AT command set the board comes with. This is what I suggest, but is not a requirement. If you do go that way I suggest you get a NodeMCU or a Wemos type board to learn with. Just working with the ESP8266 alone. They are cheap, they have a USB to serial converter, and they have a proper regulator for Vcc.

The ESP modules are not simple to power. You have to use a good regulator and have it electrically close to the board. No 20cm jumper wires.

Continuing on with your electrical connections. Reset is not connected to ground. It should be pulled up to 3.3 volts with a resistor, typically 10K.

And external WiFi shield is a simpler option. I prefer the ESP8266 since it has a fast processor, 80 or 160Mhz. Lots of ram and up to 1MB of program space. It is my go-to board. It is a little light on IO but that is easy to add. It is cheap, and there is a huge user base for it.


message:
Learn Arduino Basics : Temperature sensor with LCD Display and Potentiometer setup

I have temperature sensor, potentiometer and LCD screen attached to mini breadboard and wired to an Arduino. My temp sensor appears to be working fine however sometimes it reads inaccurate numbers which is unusual. It only does this when I have all my components on the same mini breadboard. When I detach then reattach my temperature sensor to a separate breadboard its hasn't been noticeably inaccurate. There is no issue but I was thinking that maybe the temperature sensor is hotter because its closer other to components or maybe because the close electrical wiring range is making it hotter. My solution is putting the temp gauge on another breadboard but I was save space to use one. Any ideas as why my gauge reads random hotter temperatures more often when sharing a board?

body:
It could be measuring the heat of nearby components, or it could be a wiring issue. Breadboards are convenient but it also allows people to use poor wiring practices. Long wires, poor ground return paths, insufficient bypass capacitors.

The first thing to do is to arrange the layout so that there is little chance of the other components heating the sensor. You might also try using a fan to blow on all the components. Make it so that if there is any heat generated it does not accumulate it the parts. If that clears up the problem then look into making a better thermal layout. Maybe with the sensor physically separate from the rest of the circuit.

If the fan makes no difference then you may need to consider the way it has been wired.


message:
Alternative Rx/Tx Pins for Arduino Uno and Pro Mini

Do they have specific pins that is best to be use as Rx/Tx pins (aside from D0 and D1)? If so, what makes them special?

edit: What pin feature i should look out for when choosing the rx/tx pin? Is there any specific pins that will make it a better rx/tx pin?

body:
Pins `D0` and `D1` are used for *hardware serial*, see [`Serial`][1] library reference.

You can use any other pins for virtual Rx/Tx lines employing a *software serial* mode, for example by using the `SoftwareSerial` library, see [Software Serial example][2], or by implementing your own custom code, or custom library.

  [1]: https://www.arduino.cc/reference/en/language/functions/communication/serial/
  [2]: https://www.arduino.cc/en/Tutorial/SoftwareSerialExample


body:
The Arduino SoftwareSerial library can use any pair of pins.

[AltSoftSerial][1] uses special pins. AltSoftSerial uses a 16 bit hardware timer to generate the transmit output and measure the receive input waveforms. The timer works on pins 8 and 9 on Uno and Atmega 328p boards.

  [1]: https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html


message:
Arduino Adafruit playground: Adafruit_CPlay_LIS3DH.cpp:27:35: fatal error: Adafruit_CPlay_LIS3DH.h: No such file or directory

I've tried installing the Arduino Adafruit playground but came across the same error.

    sketch\src\Libraries\Adafruit_Circuit_Playground\utility\Adafruit_CPlay_LIS3DH.cpp:27:35: fatal error: Adafruit_CPlay_LIS3DH.h: No such file or directory

     #include <Adafruit_CPlay_LIS3DH.h>

                                       ^

    compilation terminated.

    exit status 1

I don't really know what else I can try. I've tried reinstalling the library and
different versions of the Arduino IDE but is doesn't seem to work.

IDE version: 1.8.7

Playground version: 1.8.1

body: Sorry completely forgot about this post. Apparently I had a folder in my project with the playground library that wasn't updated. When I removed this folder everything worked fine.


message:
What are the negative PINs for on the IndustrialShield M-Duino 58 Analog

I am working as an internship on an Arduino based PLC. It is the M-Duino 58 Analog from IndustrialShields. I try to figure out how it works; Reverse Engineering. But i dont know why it has negative Digital Inputs like normal Digital Input I1.0 also has a connection -I1.0.
It is probably a simple question but i cant figure it out. Hope you guys can help me.

[![enter image description here][1]][1]

I guess i figured it out. Seems to be the GND connections. Should read the Manual better next time.

[![enter image description here][2]][2]

  [1]: https://i.stack.imgur.com/0NVZ0.jpg
  [2]: https://i.stack.imgur.com/IV5W0.png

body:
It looks like those inputs are opto-isolated. That means that the "input" goes through a resistor and the internal LED of an opto-isolator, which then comes back out of the "-" pin:

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/24D5A.png)

<!-- End schematic -->

So "-" connects to the ground of the remote device, and the "input" connects to the signal.


message:
STM32 and NRF send & receive

This is my send and receive code in STM32 (blue board).
But i can't send and receive data . why?
I did use Enrf24.h .
Enrf24 link: [https://github.com/spirilis/Enrf24][1]
send code is:

    #include <SPI.h>
    #include <Enrf24.h>
    #include <nRF24L01.h>
    #include <string.h>
    #define ce_nrf PB12
    #define csn_nrf PB13
    #define irq_nrf PA0
    Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
    const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
    void setup() {
      Serial.begin(9600);
      SPI.begin();
      SPI.setDataMode(SPI_MODE0);
      SPI.setBitOrder(MSBFIRST);
      radio.begin();  // Defaults 1Mbps, channel 0, max TX power
      radio.setTXaddress((void*)txaddr);
    }

    void loop() {
      Serial.print("Sending packet: ");
      radio.print("OONN");
      radio.flush();  // Force transmit (don't wait for any more data)
      delay(1000);
      Serial.print("Sending packet: ");
      radio.print("OOFF");
      radio.flush();
      delay(1000);
    }

receive code is:

    #include <SPI.h>
    #include <Enrf24.h>
    #include <nRF24L01.h>
    #define ce_nrf PB12
    #define csn_nrf PB13
    #define irq_nrf PA0
    Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
    const uint8_t rxaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
    const char *str_on = "ON";
    const char *str_off = "OFF";
    void dump_radio_status_to_serialport(uint8_t);
    void setup() {
      Serial.begin(9600);
      SPI.begin();
      SPI.setDataMode(SPI_MODE0);
      SPI.setBitOrder(MSBFIRST);
      radio.begin();  // Defaults 1Mbps, channel 0, max TX power
      radio.setRXaddress((void*)rxaddr);
      radio.enableRX();  // Start listening
    }

    void loop() {
      char inbuf[33];
      while (!radio.available(true));
      if (radio.read(inbuf)) {
        Serial.print("Received packet: ");
        Serial.println(inbuf);
      }
    }

this image can help :
[![enter image description here][2]][2]

  [1]: https://github.com/spirilis/Enrf24
  [2]: https://i.stack.imgur.com/Wb1Ki.png

body:
You did not say which library you are using, but based on the `#include`s, I am assuming http://maniacbug.github.io/RF24

This line in your receiver code:

      while (!radio.available(true));

does not make sense. You are passing `true` to the `radio.available()` function, but t[he function does not care about a parameter][1].

You probably mean something like:

    while (!radio.available());

When you pass in a variable, you are calling a variant of the function that expects a pipe number to be given, and `true` is defined as `1`. Your transmitter, however, is not sending on pipe number 1.

  [1]: http://maniacbug.github.io/RF24/classRF24.html#a127105eb7a3b351cfe777c1cec50627a


body:
First of all, remove

    while (!radio.available(true));

after that use

    PA_5 ----> SCK
    PA_6 ----> MISO
    PA_7 ----> MOSI

it will work correctly.


message:
Using c_str() on String for IPAddress with NTPClient provides wrong values

## Libraries

- [NTPClient](https://github.com/arduino-libraries/NTPClient)

## Board

Olimex ESP32-POE board

## Behaviour

I have written a code that connects the board to a local NTP Server (which is an embedded board). I tried assigning the IP Address of the above NTP Server using `IPAddress` and then convert it to `c_str()` to pass into the `NTPClient` constructor as follows:
<!-- language-all: lang-cpp -->

     WiFiUDP ntpUDP; // udp socket object for NTP

     IPAddress NTPServer(192.168.3.11); // Local NTP Server IP Address

     NTPClient timeClient(ntpUDP, NTPServer.toString().c_str(), 0, 60000);

The reason for this is because the `NTPClient` class uses `const char*` for the IP Address of the NTP Server.

The values that are obtained once the code is flashed on the board are wrong because the timestamps are have the year `2106`.

On the contrary, when I use

     NTPClient timeClient(ntpUDP, "192.168.3.11", 0, 60000);

and run the code on the board, this provides me perfect values of UTC time.

Why is there some discrepancy here?

# Code

    #include <Wire.h>
    #include <ETH.h>
    #include <WiFiUdp.h>
    #include <NTPClient.h>
    #include <RTClib.h>

    WiFiUDP ntpUDP;
    /* IP CONF for NODE */
    ///////// >>>> MODIFY Values Here <<<< ////////
    const IPAddress node_static_ip(192, 168, 3, 101);
    const IPAddress default_gateway(192, 168, 3, 250);
    const IPAddress subnet_mask(255, 255, 255, 0);
    const IPAddress dns_add(192, 168, 3, 250);
    const IPAddress NTPServer(192, 168, 3, 11);

    NTPClient timeClient(ntpUDP, "192.168.3.11", 0, 60000); // This works
    NTPClient timeClient(ntpUDP, NTPServer.toString().c_str(), 0, 60000); // This won't (provides timestamps of 2106)

    void setup() {
      // put your setup code here, to run once:
      Wire.begin(I2C_SDA, I2C_SCL);
      Serial.begin(115200);
      ETH.begin();
      ETH.config(node_static_ip, default_gateway, subnet_mask, dns_add);
      delay(1000);
      if (!rtc.begin()) {
        Serial.println("No RTC");
      }
      timeClient.begin();

    }
    void loop() {
      // put your main code here, to run repeatedly:
      timeClient.update();
      Serial.println(timeClient.getEpochTime());
      DateTime now_time(timeClient.getEpochTime());
      Serial.print(now_time.year(), DEC);
        Serial.print('/');
        Serial.print(now_time.month(), DEC);
        Serial.print('/');
        Serial.print(now_time.day(), DEC);
        Serial.print(now_time.hour(), DEC);
        Serial.print(':');
        Serial.print(now_time.minute(), DEC);
        Serial.print(':');
        Serial.print(now_time.second(), DEC);
    Serial.println();

      delay(2000);

    }

body:
The String object created as return from IPAddress.toString() as parameter to constructor of NtpClient is temporary. It contains the char array returned by c_str(). NTPClient doesn't copy the string, only stores a reference to it. And the referenced string (char array) doesn't exist at the time the NTPClient wants to use it.

    class TestClass {
    public:
      TestClass(const char* _ip) : ip(_ip) { }

      void test() {
        Serial.println("--");
        Serial.println(ip);
        Serial.println("--");
      }

    private:
      const char* ip;
    };

    //String s("abc");
    //TestClass Test(s.c_str()); <- this works

    TestClass Test(String("abc").c_str()); // <- this can't work

    void setup() {
      Serial.begin(9600);
      Test.test();
    }


message:
Connecting wires and coding in GPS Module GY-NEO6MV2 with ESP8266-01

[![enter image description here][1]][1][![enter image description here][2]][2][![enter image description here][3]][3]

Here is the link : https://www.circuito.io/app?components=10167,11021,12083,13678,13959,975601

   I'm just a beginner I don't have the idea on how GPS module wires should be connected

    #include "DHT.h"
    #include "NewPing.h"
    #include <SoftwareSerial.h>
    #define DEBUG true
     SoftwareSerial esp8266(11,10);
      //SoftwareSerial gps(8,9);
     #define DHTPIN 2       // DHT-11 Output Pin connection
     #define DHTTYPE DHT11   // DHT Type is DHT 11 (AM2302)
     #define TRIGGER_PIN 4
     #define ECHO_PIN 3
     #define MAX_DISTANCE 400

     NewPing sonar(TRIGGER_PIN,ECHO_PIN,MAX_DISTANCE);

     float hum;
     float temp;

     DHT dht(DHTPIN, DHTTYPE);

     void setup() {
     Serial.begin (9600);
     Serial.println("START");
     esp8266.listen();
     esp8266.begin(9600);
     gps.begin(9600);
     dht.begin();

      pinMode(TRIGGER_PIN, OUTPUT);
      pinMode(ECHO_PIN, INPUT);

      sendData("AT+RST\r\n",2000,DEBUG);            // command to reset the
      module
         sendData("AT+CWMODE=2\r\n",1000,DEBUG);       // This will configure
         the mode
         as access point
       sendData("AT+CIFSR\r\n",1000,DEBUG);          // This command will get
       the ip
       address
      sendData("AT+CIPMUX=1\r\n",1000,DEBUG);       // This will configure the
      esp
    for multiple connections
    sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // This command will turn on
    the
    server on port 80
    }

    void loop()
    {

     delay(2000);  // Delay so DHT-11 sensor can stabalize

     hum = dht.readHumidity();  // Get Humidity value
     temp= dht.readTemperature();  // Get Temperature value

      digitalWrite(TRIGGER_PIN, LOW);
      delayMicroseconds(2);
      digitalWrite(TRIGGER_PIN, HIGH);
      delayMicroseconds(10);
      digitalWrite(TRIGGER_PIN, LOW);

    long duration,distance;
    duration= pulseIn(ECHO_PIN,HIGH);

    distance = duration/58.2;

    Serial.print("Humid: ");
    Serial.print(hum);
    Serial.print(" %, Temp: ");
    Serial.print(temp);
    Serial.print(" C, ");
    Serial.print("Distance: ");
    Serial.print(distance);
    Serial.println(" cm");
    delay(50);

    gps.listen();
    while (gps.available())
    Serial.write(gps.read());

    esp8266.listen();
    if(esp8266.available())         // This command will that check if the esp
        is sending a message
        {
        if(esp8266.find("+IPD,"))
        {
        delay(1000);

        int connectionId = esp8266.read()-48; /* We are subtracting 48 from the
        output because the read() function returns
                                            the ASCII decimal value and the
        first decimal number which is 0 starts at 48*/
         String webpage = "<meta http-equiv=\"refresh\" content=\"5;
         url=192.168.4.1/\">";
         webpage += "
Mabalacat City College Garbage Monitoring System
";
        webpage += "

";
        if (distance<=5)
        {
        webpage+= " Trash can is Red";
        }
        if (distance == 20)
        {
          webpage+= " Trash can is Orange";
          }
          if (distance == 35)
        {
          webpage+= " Trash can is Light Orange";
          }
          if (distance == 50)
        {
          webpage+= " Trash can is Yellow";
          }
          if (distance == 70)
        {
          webpage+= " Trash can is 2st Light Yellow";
          }
          if (distance == 85)
        {
          webpage+= " Trash can is 1st Light Yellow";
          }
          if (distance == 95)
        {
          webpage+= " Trash can is Green";
          }
          if (distance >= 100)
        {
          webpage+= " Trash can is Empty";
          }
          webpage+= "
";
          webpage+="Distance: ";
          webpage+=distance;
          webpage+=" cm";
          webpage+= "
";
          webpage+="Temperature: ";
          webpage+= temp;
          webpage+=" celsius";
          webpage+= "
";
          webpage+= "Humidity: ";
          webpage+= hum;
          webpage+= " %";

     webpage += "

";
     String cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";
     sendData(cipSend,1000,DEBUG);
     sendData(webpage,1000,DEBUG);
     String closeCommand = "AT+CIPCLOSE=";
     closeCommand+=connectionId;
     closeCommand+="\r\n";
     sendData(closeCommand,3000,DEBUG);
    }
       }
      }

      String sendData(String command, const int timeout, boolean debug)
    {
    esp8266.listen();
    String response = "";
    esp8266.print(command);
    long int time = millis();
    while( (time+timeout) > millis())
    {
      while(esp8266.available())
      {
        char c = esp8266.read();
        response+=c;
      }
    }
    if(debug)
    {
      Serial.print(command);
      Serial.print("> ");
      Serial.print(response);
    }
    gps.listen();
    return response;
    }

  [1]: https://i.stack.imgur.com/Sa4CN.png
  [2]: https://i.stack.imgur.com/PF14m.png
  [3]: https://i.stack.imgur.com/WXYGy.png

body:
    GPS - Arduino
    ---------------
    GND -  GND
    TX  -  pin of SoftwareSerial RX
    RX  -  pin of SoftwareSerial TX
    Vcc -  3.3 V

Only one instance of SoftwareSerial can listen. Method listen() determines which one. So you must add `esp8266.listen();` before talking to esp8266 and `gps.listen();` before talking to GPS module.

 - in `setup()` add `esp8266.listen()` before first `sendData` call
 - in `loop()` add gps.listen() before `while (gps.available())`
 - in `loop()` add esp8266.listen() before `if (esp8266.available()) `


message:
Custom Classes - Redefinition of void error

I'm getting a redefinition error from my classes, but can't see what I did wrong.

**Error: Icon.cpp:3:6: error: redefinition of 'void Icon::setIcon(byte (*)[8])'**

Can any help me out on this? Thanks!

**MyFile.ino**

    #include "MyIcon.h"

    MyIcon myIcon;

**MyIcon.h**

    #ifndef MyIcon_h
    #define MyIcon_h

    #include "Arduino.h"
    #include "Icon.h"

    class MyIcon : public Icon {
      public:
        MyIcon();
    };

    #endif

**MyIcon.cpp**

    #include "MyIcon.h"

    MyIcon::MyIcon() {

      byte _icon[8][8] = {
        {1, 1, 1, 1, 1, 1, 1, 1},
        {1, 1, 2, 2, 2, 2, 1, 1},
        {1, 2, 1, 1, 1, 1, 2, 1},
        {2, 1, 2, 2, 2, 2, 1, 2},
        {1, 2, 1, 1, 1, 1, 2, 1},
        {1, 1, 1, 2, 2, 1, 1, 1},
        {1, 1, 2, 1, 1, 2, 1, 1},
        {0, 0, 0, 1, 1, 0, 0, 0},
      };
      MyIcon::setIcon(_icon);

**Icon.h**

    #ifndef Icon_h
    #define Icon_h

    #include "Arduino.h"

    typedef struct{
      byte r;
      byte g;
      byte b;
    } RGB;

    class Icon {
      public:
        Icon();
        inline virtual void setIcon(byte icon[8][8]){};
        inline virtual void setIconColors(RGB colors[3]){};
    };

    #endif

**Icon.cpp**

    #include "Icon.h"

    void Icon::setIcon(byte icon[8][8]) {
      __icon = icon;
    }

    void Icon::setIconColors(RGB colors[3]) {
      __colors = colors;
    }

**Edited on 09/11/18**

I attempted the following changes, before I realised thanks to KIIV, that I couldn't use array like that.

My idea was to be able to getIcon() and get back the byte array, which is later used to light up specific leds on a NeoMatrix panel.

I thought I would be able to build an icon "library" by extending a base class, setting the correct byte array in the class, and using it as needed (MyIcon, MyOtherIcon, etc...)

Have I completely missed the point?

**Icon.h**

    void setIcon(byte icon[8][8]);
    void setIconColors(RGB colors[3]);

**Icon.cpp**

    #include "Icon.h"

    Icon::Icon(){ }

    void Icon::setIcon(byte icon[8][8]){
      memcpy(__icon, icon, sizeof(icon));
    }

    void Icon::setIconColors(RGB colors[3]){
      memcpy(__colors, colors, sizeof(colors));
    }

body:
You have bodies for `setIcon` and `setIconColors` in both the header file and the cpp file.  You can only have them in one or the other - choose.

Also, as an aside, the way that you are assigning icon data will go out of scope before you use it.  You create a local array variable which you then pass a pointer to to your constructor. That pointer is then saved. But then you go out of scope and the pointer is discarded, and the data will be overwritten.


body:
As Majenko writes, you are having two bodies.

The bodies in the header file are empty and probably you do not want this. It is normal to implement the functions in the cpp file (which you do), so in the header file remove the {} in

    inline virtual void setIcon(byte icon[8][8]){};
    inline virtual void setIconColors(RGB colors[3]){};

so it becomes

    inline virtual void setIcon(byte icon[8][8]);
    inline virtual void setIconColors(RGB colors[3]);