message:
PROGMEM for IR command storage

I'm working on a code that is able to send raw data as IR signal to IR transmitter,
the memory of arduino Nano is not enough to store the array in SRAM storage,so i'm about to use PROGMEM to store arrays in flash memory.

these are arrays for IR signal raw command:

    unsigned int irSignaloff[]={6060, 7420, 532, 1652, 544, 1668, 508, 1688, 508, 1688, 508, 1692, 532, 1664, 532, 1664, 532, 1664, 536, 604, 528, 588, 548, 580, 552, 580, 528, 636, 500, 600, 532, 588, 548, 580, 552, 1644, 552, 1644, 528, 1664, 532, 1668, 532, 1664, 532, 1668, 528, 1668, 528, 1668, 508, 624, 536, 600, 532, 600, 536, 576, 528, 600, 532, 604, 532, 604, 532, 580, 552, 1648, 548, 1648, 552, 1644, 552, 1648, 552, 1644, 552, 1640, 556, 1644, 528, 1668, 528, 600, 508, 624, 512, 620, 536, 600, 536, 604, 528, 576, 508, 624, 532, 604, 532, 1660, 536, 1660, 540, 596, 536, 1644, 552, 1648, 552, 1644, 552, 580, 524, 1672, 524, 604, 508, 624, 536, 1660, 536, 632, 504, 580, 552, 608, 500, 1668, 528, 600, 508, 1688, 512, 1684, 560, 1668, 504, 660, 500, 1660, 536, 604, 532, 1656, 540, 1660, 540, 584, 548, 580, 528, 596, 512, 1688, 508, 660, 500, 1660, 536, 596, 540, 584, 548, 604, 500, 1672, 528, 600, 512, 1684, 512, 620, 540, 1656, 540, 600, 536, 580, 552, 1644, 552, 576, 528, 1668, 532, 600, 508, 1688, 536, 596, 536, 1660, 540, 1660, 536, 7420, 536};

    unsigned int irSignalon[]={6156, 7336, 592, 1588, 612, 1584, 612, 1588, 608, 1588, 608, 1588, 604, 1592, 604, 1592, 604, 1592, 604, 528, 504, 628, 588, 548, 588, 552, 580, 524, 608, 524, 572, 560, 592, 540, 588, 1608, 592, 1604, 592, 1604, 592, 1608, 592, 1604, 592, 1604, 592, 1604, 596, 1600, 596, 524, 608, 520, 584, 544, 596, 540, 596, 536, 596, 524, 608, 520, 604, 524, 588, 1608, 588, 1608, 588, 1608, 588, 1608, 588, 1612, 536, 1660, 572, 1624, 572, 1628, 564, 600, 504, 628, 504, 580, 528, 600, 636, 528, 540, 564, 532, 588, 548, 604, 504, 1664, 532, 604, 504, 624, 536, 1660, 532, 1664, 532, 1664, 532, 604, 532, 1660, 536, 584, 548, 1652, 548, 1644, 552, 580, 556, 572, 532, 604, 532, 1664, 532, 600, 532, 1668, 532, 1660, 536, 1688, 532, 600, 536, 1664, 532, 584, 620, 1576, 552, 1644, 552, 576, 532, 604, 608, 524, 532, 1664, 608, 512, 620, 1576, 548, 580, 556, 572, 600, 536, 604, 1588, 608, 528, 536, 1660, 536, 584, 620, 1580, 620, 508, 596, 532, 508, 1688, 512, 620, 536, 1660, 604, 532, 608, 1588, 604, 516, 620, 1576, 620, 1576, 624, 7308, 552};

and this is sending command uses IRemote.h library:

     irSend.sendRaw(irSignalon, sizeon, FREQ_KHZ, false);

 so how can i use PROGMEM to store and read this int array in order to send them?
thanks

body:
If your IR library does not support sending signals stored in PROGMEM,
then you will have to provide the data in RAM. However, you do not have
to keep _both_ signals in RAM permanently: only the one you are about to
send needs to be there.

I suggest you keep all the IR signal data in PROGMEM while not sending
them. Whenever you want to send a signal, you copy it to a RAM-based
buffer and give the address of that buffer to the library. The same
buffer will be reused for any signal you are sending. This will cost
you some CPU time for the copy, and save 394 bytes of RAM. The savings
will scale up if you add more signals to your sketch.

```c++
const size_t signal_size = 197;

static PROGMEM const uint16_t irSignaloff[signal_size] = { ... };

static PROGMEM const uint16_t irSignalon[signal_size] = { ... };

/* Send an IR signal from PROGMEM. */
void send_signal(const uint16_t *signal) {
    static uint16_t signal_buffer[signal_size];
    memcpy_P(signal_buffer, signal, signal_size * sizeof *signal);
    irSend.sendRaw(signal_buffer, signal_size, FREQ_KHZ, false);
}

//...
send_signal(irSignalon);
send_signal(irSignaloff);
```

Here I am assuming that all your signals have the same length, which is
true for the example you show, but may be false if you add more signals
later. You may then need to size the buffer as the longest of all your
signals, and provide the signal length as an extra parameter to
`send_signal()`.

Note that the RAM buffer does not need to be static. I chose to make it
static here only in order for avr-size to give you a good estimate of
the memory requirement of the program.


sender: user

message:
ESP32 using PubSub, creating an error when implemted inside a library

I wish to combine into a single library Wifi + MQTT, for a multi devices project.

right after boot, getting Wifi - I get an error the moment MQTT server is trying to connect:
`mqttClient.connect(DEVICE_TOPIC, MQTT_USER, MQTT_PASS, MQTTavltopic, 0, true, "offline");`

yields :

    WiFi connected
    IP address: 192.168.3.186
    Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
    Core 1 register dump:
    PC      : 0x400d26bd  PS      : 0x00060630  A0      : 0x800d28e8  A1      : 0x3ffb1eb0
    A2      : 0x3ffc116c  A3      : 0x3f4010ef  A4      : 0x3f40108c  A5      : 0x3f4010b7
    A6      : 0x3ffc106c  A7      : 0x00000000  A8      : 0x800d26b6  A9      : 0x3ffb1e90
    A10     : 0x00000000  A11     : 0x3ffc116c  A12     : 0x0000000e  A13     : 0x00000010
    A14     : 0x0000000e  A15     : 0x3ffb1d94  SAR     : 0x0000000c  EXCCAUSE: 0x0000001c
    EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffc

    Backtrace: 0x400d26bd:0x3ffb1eb0 0x400d28e5:0x3ffb1ef0 0x400d0fa6:0x3ffb1f20 0x400d103b:0x3ffb1f50 0x400d0e59:0x3ffb1f90 0x400d3651:0x3ffb1fb0 0x40088b7d:0x3ffb1fd0

    Rebooting...

I'm sharing both `.h` and `.cpp` files.  Library is at its begining - so don't pay attention for irrelevant/ immature parts.

TNX

this is `.h` file:

    #ifndef myIOT32_h
    #define myIOT32_h
    #include "Arduino.h"

    // #include <ESPmDNS.h>
    // #include <WiFiUdp.h>
    // #include <ArduinoOTA.h>
    #include "time.h"
    #include "WiFi.h"
    #include "secrets.h"
    #include <PubSubClient.h>

    class myIOT32
    {

    #define DEVICE_TOPIC "ESP32_SLEEP"
    #define MQTT_PREFIX "myHome"
    #define MQTT_GROUP ""
    private:
        char MQTTmsgtopic[50];
        char MQTTlogtopic[50];
        char MQTTavltopic[50];
        char MQTTdevtopic[50];
        char MQTTlastctopic[50];
        struct tm _timeinfo;
        time_t _epoch_time;
        bool _wifi_status = false;
        char *wifi_ssid; // = "WIFI_NETWORK_BY_USER";
        char *wifi_pass; // = "WIFI_PASSWORD_BY_USER";
        char *mqtt_server;
        char *user = "";
        char *passw = "";

        WiFiClient espClient;
        PubSubClient mqttClient;

    public:
        myIOT32(char *devTopic = "no-name", char *ssid = SSID_ID, char *wifi_p = PASS_WIFI, char *mqtt_broker = MQTT_SERVER1, char *mqttU = MQTT_USER, char *mqttP = MQTT_PASS, int port = 1883);
        void looper();
        void start();
        void mqtt_pubmsg(char *msg);
         bool use_wifi = true;
         void startMQTT();

    private:

        void MQTTloop();
        void startNTP(const int gmtOffset_sec, const int daylightOffset_sec, const char *ntpServer);
        bool startWifi();
        void getTime();
        void MQTTcallback(char *topic, byte *payload, unsigned int length);
        void createTopics();
        void connectMQTT();
        void subscribeMQTT();
    };

#endif

and my `.cpp` file

    #include "myIOTesp32.h"

    myIOT32::myIOT32(char *devTopic, char *ssid, char *wifi_p, char *mqtt_broker, char *mqttU, char *mqttP, int port)
    {
      mqtt_server = mqtt_broker;
      user = mqttU;
      passw = mqttP;
      wifi_ssid = ssid;
      wifi_pass = wifi_p;
    }
    void myIOT32::start()
    {
      if(startWifi()){
          getTime();
          startMQTT();
      }
    }
    void myIOT32::looper()
    {
      MQTTloop();
    }

    void myIOT32::MQTTcallback(char *topic, byte *payload, unsigned int length)
    {
      char incoming_msg[150];
      char msg[100];

      Serial.print("Message arrived [");
      Serial.print(topic);
      Serial.print("] ");

      for (int i = 0; i < length; i++)
      {
        Serial.print((char)payload[i]);
        incoming_msg[i] = (char)payload[i];
      }
      incoming_msg[length] = 0;
      Serial.println();
    }
    void myIOT32::createTopics()
    {
      sprintf(MQTTmsgtopic, "%s/%s", MQTT_PREFIX, "Messages");
      sprintf(MQTTlogtopic, "%s/%s", MQTT_PREFIX, "log");
      sprintf(MQTTdevtopic, "%s/%s", MQTT_PREFIX, DEVICE_TOPIC);
      sprintf(MQTTavltopic, "%s/%s", MQTTdevtopic, "Avail");
      sprintf(MQTTlastctopic, "%s/%s", MQTTdevtopic, "nexton_command");
    }
    void myIOT32::connectMQTT()
    {
      if (!mqttClient.connected())
      {
        mqttClient.connect(DEVICE_TOPIC, MQTT_USER, MQTT_PASS, MQTTavltopic, 0, true, "offline");
      }
    }
    void myIOT32::subscribeMQTT()
    {
      mqttClient.subscribe(MQTTdevtopic);
      mqttClient.subscribe(MQTTlastctopic);
    }
    void myIOT32::mqtt_pubmsg(char *msg)
    {
      mqttClient.publish(MQTTmsgtopic, msg);
      Serial.print(MQTTmsgtopic);
      Serial.print("/");
      Serial.println(msg);
    }
    void myIOT32::startMQTT()
    {
      mqttClient.setServer(mqtt_server, 1883);
      mqttClient.setCallback(std::bind(&myIOT32::MQTTcallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
      createTopics();
      connectMQTT();
      subscribeMQTT();
    }
    void myIOT32::MQTTloop()
    {
      static long lastReconnectAttempt = 0;

      if (mqttClient.connected())
      {
        mqttClient.loop();
      }
      else
      {
        long now = millis();
        Serial.println("MQTT Server- NOT connected");
        if (now - lastReconnectAttempt > 5000)
        {
          lastReconnectAttempt = now;
          connectMQTT();
          subscribeMQTT();
        }
      }
    }

    void myIOT32::startNTP(const int gmtOffset_sec = 2 * 3600, const int daylightOffset_sec = 0, const char *ntpServer = "pool.ntp.org")
    {
      configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
    }
    bool myIOT32::startWifi()
    {
      long beginwifi = millis();
      WiFi.begin(wifi_ssid, wifi_pass);

      while (WiFi.status() != WL_CONNECTED && millis() - beginwifi < 30000)
      {
        delay(200);
        Serial.print(".");
      }

      if (WiFi.status() == WL_CONNECTED)
      {
        Serial.println("");
        Serial.println("WiFi connected");
        Serial.print("IP address: ");
        Serial.println(WiFi.localIP());
        startNTP();
        return 1;
      }
      else
      {
        Serial.println("NO-WiFi");
        return 0;
      }
    }
    void myIOT32::getTime()
    {
      int a = 0;
      while (a < 3)
      {
        if (getLocalTime(&_timeinfo))
        {
          delay(100);
          time(&_epoch_time);
        }
        a++;
      }
    }

sender: assistant

body:
    myIOT32::myIOT32(char *devTopic, char *ssid, char *wifi_p, char *mqtt_broker, char *mqttU, char *mqttP, int port)
        : mqttClient(espClient)  // <--- this part was missing *****
    {


message:
Stopping the program after 1 second

I am a Beginner in Arduino Programming.
I am working on a project where I control A DC motor with IR sensor and arduino.

Until here it is fine. But I want the Motor to stop after one second even though the IR sensor detects the Obstacle

Here's My Program

Pin 2- IR Sensor
Pin 4,5,6- Motor

    enter code here
    //Included Libraries
    #include <motor.h>

    //MACROS are defined here
    Motor Motor1(4, 5, 6);

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

     pinMode(2, INPUT);

    }

    void loop() {
     //put your main code here, to run repeatedly:

     if(digitalRead(2)) {
      Motor1.moveMotor(2.55*0);
     }
     else {
      Motor1.moveMotor(2.55*100);
     }
    }

Can anyone help out in this Program. I Just want the Motor to stop after one second.
Thank you in advance!

body:
You need to use read the time (`millis()`) when you start the motor and read it frequently while the motor is running to know when to stop it. You also need to keep track of the sensor, and don't start the motor again until after you've seen the sensor turn off (detect no obstacle). Here is an outline of the logic in psuedo-code; turn this into a detailed `loop()` function in C++:

    if the motor is ON {
      if (millis() - motorStartMillis) > 1000 {
      stop the motor;
    }
    else if sensor is ON {
      if the sensor was OFF {
        start the motor;
        motorStartMillis = millis();
        sensorWasOn = true;
      }
    }
    else {      // sensor must be off
      sensorWasOn = false;
    }


message:
NodeMCU Power supply

I got a question about externally powering my NodeMCU V3. It has an onboard voltage regulator (3v3) which breaks out to 3 header pins. Now I want to power 3v3 from an external board. Can I supply 3v3 to all of those pins at the same time? (Basically connected in parallel).
Anyone has done this before or has this experience with NodeMCU V3?

I have supplied a link below:
https://www.theengineeringprojects.com/2018/10/introduction-to-nodemcu-v3.html

Thanks a lot!

body:
Yes, you may connect all `3V` pins together (red) and all `GND` pins together (black), like so:

[![3V pins connected together][1]][1]

In some cases, more wires will improve the circuit. E.g. when you build the [Ben Eater 8-Bit CPU](https://eater.net/8bit/), you'll find that connecting power in a ring instead of a line will reduce voltage drop by about 50%.

---
When first reading your question, I got the impression that you wanted to solder the 3.3 V wires directly to the voltage regulator. Here's my original answer for that:

That's not a good idea: if you connect the same wire to all pins, your're creating a short, typically causing a malfunction if not worse. You may destroy your equipment (external board as well as the NodeMCU v3). Do NOT connect 3.3V to all pins of the voltage regulator.

A voltage regulator has 3 pins:

* voltage in (for an unregulated voltage you can't exactly control; typically higher than the output voltage)
* voltage out (for the stabilized resulting voltage you want to have)
* ground

The only pin to connect the voltage to is the "voltage in" pin (VIN). And typically, a development board has a pin for that:

[![VIN pin on a 8266 development board][2]][2]

However, you'll find that the [input voltage must be between 4.75V and 10V](https://github.com/nodemcu/nodemcu-devkit-v1.0/issues/15), so supplying 3.3V from an external board is not sufficient.

If you have regulated (stable) 3.3V already, you can connect that to a pin labelled 3V:

[![3V pin on a 8266 development board][3]][3]

Also, you need to connect the grounds (GND) of both circuits together (GND of external board to GND of NodeMCU), otherwise the current will not find its way back.

  [1]: https://i.stack.imgur.com/h6wzo.png
  [2]: https://i.stack.imgur.com/AW6ER.png
  [3]: https://i.stack.imgur.com/7IVNl.png


message:
ESP32 proper DS18B20 wiring

I want to connect a DS18B20 to my newly bought Heltec ESP32 LoRa (V2). For initial testing I have used some standard code:

    #include "heltec.h"
    #include <OneWire.h>
    #include <DallasTemperature.h>

    OneWire ds(14);
    DallasTemperature sensors(&ds);

    void getDS18B20values()
    {
      Serial.print(" Requesting therms...");
      sensors.requestTemperatures();
      Serial.println("DONE");

      uint8_t count = sensors.getDeviceCount();
      for (int i = 0; i < count; i++)
      {
        Serial.print("Temperature " + String(i) + "is: " + String(sensors.getTempCByIndex(i)));
      }

      delay(1000);
    }

    void setup()
    {

      //WIFI Kit series V1 not support Vext control
      Heltec.begin(
          true /*DisplayEnable Enable*/,
          true /*Heltec.LoRa Disable*/,
          true /*Serial Enable*/,
          true /*PABOOST Enable*/,
          868E6/*long BAND*/);

      sensors.begin(); // initialize therm-sensors
    }

    void loop()
    {
      getDS18B20values();

      delay(1500);
    }

Here's a quick schematic I designed with the designer provided by stackexchange. Not all parts were available so I had to improvise a litte. I hope it is accurate enough.
<!-- 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/IYVuw.png)

<!-- End schematic -->

Another weird thing is that if I wire it all up I can start the ESP but I can't flash any new software to it because it doesn't react. So I assume it's a wiring issue the code should be fine but I posted it anyway. I had tested it with multiple DS18B20 sensors. A while ago on an Arduino they were all still working. I am more experienced with Arduinos than with ESPs. Are there any differences in regard to the wiring I have to be careful of?

Edit: I already have some sensored wired to the ESP, a BH1750, DHT11, an analog soil moisture sensor and an analog light dependent resistor.

body:
I have not checked your code, but you certainly have a wiring issue.

There are two main problems.

1. Your Vcc is connected to the data output of the DS18B20. This means you will never read anything except logic "high" from the data output.
2. The 4k7 resistor should not be connected this way. See the schematic below on how it should be connected. You could also set up a data pin with an internal pullup so you don't need an external pullup.

This is roughly how it should look.

<!-- 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/ndRqL.png)

<!-- End schematic -->


message:
HC-05 Stuck in slave loop mode (loopback)

got my HC-05 today and accidently set the AT+ROLE=2(slave loop) and now I can't get out of it! Anything I send it just resends it back to me, even commands like AT+RESET and AT+ORGL, they just get returned. I can't figure out how to put the device back in slave mode, your help would be highly appreciated!

body:
H., you have to connect the module in the natural configuration mode to receive AT commands by default, which it is at 38400 Baud. Try sending AT with the arduino console (with carreturn and new line control). If this works then send AT+MODE=0.
Also, from here, you can send AT+ORGL to set original from factory. I usually use a CP2102 usb-serial interface with the hc-05 module, and the YAT serial terminal program from windows, because it is comfortable for me. Greetings. jvarl.


message:
what command should i use to read and write through spi.tranfer command

#include<spi.h>
    byte val;     // variabe for storing temp data
    #define PIN_SPI_SS    (9)
    #define PIN_SPI_MOSI  (10)
    #define PIN_SPI_MISO  (11)
    #define PIN_SPI_SCK   (12)

    void setup();
    pinMode(SS,output);
    pinMode(SCLK,output);
    pinMode(MOSI,output);
    spi.setBitorder(MSBFIRST);
    SPI.setDataMode(SPI_MODE3);
    serial.begin(9600);
    spi.begin();

    void loop();
      digitalWrite(SS,LOW);
      uint8_t b1 = SPI.transfer(0x00);
      uint8_t b2 = SPI.transfer(0x00);
      uint8_t b3 = SPI.transfer(0xFF);
      digitalWrite(SS,HIGH);
      int16_t val = b1 | b2 ;
      serial.print("val=");
      serial.println(val,DEC);

refer for DATA SHEET//<https://www.ti.com/lit/ds/symlink/lm74.pdf?ts=1591436049550&ref_url=https://www.ti.com/product/LM74>
my problem is i am not able to know what command should i use in SPI.transfer function for writing & reading  temperature data here i use 0x00 for reading 16 bit data of temperture register,but what about writing in configuration register  ,LM74 use 0xFF command for shutdown mode,but  how we came to know that 0xFF refer only to configuration register.

body:
In the LM74 the third byte you send (or more specifically the last 8 bits of *up to* 32 bits past the 16th bit that you send) is read and used as the configuration register setting.

Since the configuration register only has two states `0xFF` is go to sleep sleep and `0x00` is do conversions (as shown in table 1 of the datasheet).

So:

    0x00 0x00 0xFF

means get one result then go to sleep.

    0x00 0x00 0x00

means get one result and stay awake.

If the LM74 is currently asleep from an `0x00 0x00 0xFF` sequence the result you get returned is not a temperature but the chip's manufacturer ID.

It's not an obvious method of controlling a chip, and it's actually pretty poorly written in that datasheet, so don't feel bad about not understanding it, it took me a few moments to understand it.


message:
Arduino Trinket and CCS811 sensor

I have connected trinket and CCS811
I am trying to build and upload sketch to the module:

      /******************************************************************************
      Read basic CO2 and TVOCs

      Marshall Taylor @ SparkFun Electronics
      Nathan Seidle @ SparkFun Electronics

      April 4, 2017

      https://github.com/sparkfun/CCS811_Air_Quality_Breakout
      https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library

      Read the TVOC and CO2 values from the SparkFun CSS811 breakout board

      A new sensor requires at 48-burn in. Once burned in a sensor requires
      20 minutes of run in before readings are considered good.

      Hardware Connections (Breakoutboard to Arduino):
      3.3V to 3.3V pin
      GND to GND pin
      SDA to A4
      SCL to A5

    ******************************************************************************/
    #include <Wire.h>

    #include "SparkFunCCS811.h" //Click here to get the library: http://librarymanager/All#SparkFun_CCS811

    #define CCS811_ADDR 0x5B //Default I2C Address
    //#define CCS811_ADDR 0x5A //Alternate I2C Address

    CCS811 mySensor(CCS811_ADDR);

    #include <SoftwareSerial.h>
    const int rx = 0; //3
    const int tx = 2; //4
    const int alarmPin = 4;
    SoftwareSerial mySerial(rx, tx);

    void setup()
    {
      mySerial.begin(9600);
      mySerial.println("CCS811 Basic Example");

      Wire.begin(); //Inialize I2C Hardware

      pinMode(alarmPin, OUTPUT);
    }

    void loop()
    {
      //Check to see if data is ready with .dataAvailable()
      if (mySensor.dataAvailable())
      {
        //If so, have the sensor read and calculate the results.
        //Get them later
        mySensor.readAlgorithmResults();

        mySerial.print("CO2[");
        //Returns calculated CO2 reading
        double val = mySensor.getCO2();
        mySerial.print(val);
        if(val>=2000){
          digitalWrite(alarmPin, HIGH);
        }
        //Serial.print("] tVOC[");
        //Returns calculated TVOC reading
        //Serial.print(mySensor.getTVOC());
        //Serial.print("] millis[");
        //Display the time since program start
        //Serial.print(millis());
        //Serial.print("]");
        //Serial.println();
      }

      delay(10); //Don't spam the I2C bus
    }

However when I verify the sketch I get following errors:

```
In file included from C:\Users\Nitin\Desktop\co2\co2.ino:26:0:

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:77:28: error: 'TwoWire' has not been declared

  CCS811_Status_e beginCore(TwoWire &wirePort);

                            ^~~~~~~

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:97:2: error: 'TwoWire' does not name a type; did you mean 'Wire'?

  TwoWire *_i2cPort; //The generic connection to user's chosen I2C hardware

  ^~~~~~~

  Wire

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:112:13: error: 'TwoWire' has not been declared

  bool begin(TwoWire &wirePort = Wire);         //Use the Wire hardware by default

             ^~~~~~~

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:113:34: error: 'TwoWire' has not been declared

  CCS811_Status_e beginWithStatus(TwoWire &wirePort = Wire);    //Use the Wire hardware by default

                                  ^~~~~~~

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:112:33: error: could not convert 'Wire' from 'TinyM_USI_TWI' to 'int&'

  bool begin(TwoWire &wirePort = Wire);         //Use the Wire hardware by default

                                 ^~~~

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:113:54: error: could not convert 'Wire' from 'TinyM_USI_TWI' to 'int&'

  CCS811_Status_e beginWithStatus(TwoWire &wirePort = Wire);    //Use the Wire hardware by default

                                                      ^~~~

Multiple libraries were found for "Wire.h"
 Used: C:\Users\Nitin\AppData\Local\Arduino15\packages\adafruit\hardware\avr\1.4.13\libraries\Wire
 Not used: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
Multiple libraries were found for "SparkFunCCS811.h"
 Used: C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library
 Not used: C:\Users\Nitin\Documents\Arduino\libraries\arduino_613982
Using library Wire at version 1.0 in folder: C:\Users\Nitin\AppData\Local\Arduino15\packages\adafruit\hardware\avr\1.4.13\libraries\Wire
Using library SparkFun_CCS811_Arduino_Library at version 2.0.1 in folder: C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library
Using library SoftwareSerial at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial
exit status 1
Error compiling for board Adafruit Gemma (ATtiny85 @ 8MHz).
```

I see that this library - SparkFun_CCS811_Arduino_Library is not compatible with trinket
https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library/issues/19

can anyone give me pointer to write sketch for trinket connected to CCS811 sensor?

body:
Looks like you have two choices

 - Use a different controller that is compatible with the normal Arduino Wire library - maybe something like the Nano?
 - Modify SparkFunCCS811.h to #include TinyWireM.h instead of Wire.h. This is actually not hard at all - just takes a bit of patience and the knowledge that "there is no magic".

Frank


message:
How do I know if I need to use a resistor in a circuit?

I have been trying to find answers on Google to this question but cannot seem to find any answers that actually pertain to what I am wanting to know.  I would consider myself a beginner in the area of electronics having some experience but not understanding how everything comes together outside of the some of the basics.  What I am wondering is this; How can I tell if I need to use a resistor in a circuit?  More specifically, When I am hooking sensors up to an Arduino, how can I determine if I need resistors in the circuit?  Anywhere I look I typically see the default LED/Resistor example but that is not helpful.  It doesn't explain how Arduino/Raspberry PI modules and sensors fit into the equation.  I know the data sheets for the various modules/sensors explain how much current is needed/used by the device but how do I take that and apply it to an Arduino circuit?  Thanks in advance.

body:
> How can I tell if I need to use a resistor in a circuit?

You can tell because the circuit includes a resistor.

If a circuit needs a resistor the circuit diagram will include a resistor. If it doesn't, then it won't.

The circuit for connecting an LED to an Arduino consists of an Arduino, an LED and a resistor.  Because of that you know it needs a resistor. Because it says it needs a resistor.

A resistor drops a certain voltage across it when a specific current flows through it (Read up on Ohm's Law...). If you need to drop a specific voltage with a specific known current, or if you need to cause a specific current to flow with a fixed voltage, then you use a resistor for that job.

You don't just throw resistors willy-nilly into every circuit you make simply because you see one being used with an LED.

If a device says it runs off 5V and uses 300mA current then you know that you need to hook it up to a power source that is 5V. You also know that the module will use up to 300mA of current from that source, so your source has to be capable of providing at least that much current.


body:
From the specifications of the sensor, you know the maximum current the sensor should be allowed to draw. Suppose you need to put 5v across the sensor.

Then write down Ohm's law: E = IR (the voltage across a component is given by the product of its resistance and the current through it. You need to know the value of a resistor to put in series with the sensor to limit the current to that maximum value or less. So solve Ohms law for resistance (R) of voltage (E):

R = E/I or 5v / maximum current.

That gives you the values of a series resistor to limit the current to the maximum, assuming the sensor has no (or very little) internal resistance of its own.

Or let's look at an LED, where the spec sheet gives you both the maximum current and the internal voltage drop (called "forward voltage"). If you don't need the LED to run at full power (and you probably don't), it will last longer if you limit it to less than that, so let's take 75% as a working figure and calculate the serial resistor to give 75% of maximum current. Red LEDs typically have 2v forward voltage and 15 milliamps max current (but don't build for "typical" parts - build for the part you have). We'll assume a 5v power supply:

R = E/I = (5v - 2v) / (.015 X 0.75)  = 3 / .01125 = 266 Ohms.
So we'd pick an available resistor value close to 266 Ohms (no need to be exact here - we've already left a safety factor by reducing the current 25%).

If you calculate the voltage (again, using Ohm's law) across the 266 (or whatever you used) Ohm resistor, you'll find a voltage drop of about 3v, and adding the LED's forward voltage of 2V, you'll get the power-supply voltage of 5v.

<!-- 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/2ceQf.png)

<!-- End schematic -->

Update:

> Why do we need a resistor on an LED which draws 15mA of current which
> the Arduino can supply nicely, but we don't on a sensor like the
> HC-SR04 which draws 15mA of current?

It's about the behavior of the component or module itself, and that needs a datasheet for the component and spec-sheet for the module. An LED has a forward voltage drop but otherwise looks like a nearly short circuit, so it requires a resistor to protect it from over-current. A module often provides some circuitry around the component to help the user integrate into their project. Of course, how much help it provide is up to the designer. One module may offer nothing more then breadboard-compatible pins where another one - for the same device - may have power-conditioning or power supply components, 3.3v <-> 5v logic-level shifters, and protective circuitry to help protect an expensive component from misuse.

Why does this component need a resistor and another one doesn't? It's up to the electrical behavior of those components. Here's a trivial, but I hope illustrative example:

[![An LED "module" and a plain LED][1]][1]

The device on the left might be considered an LED module, compared to the one on the right which is just an LED. Obviously, all I've done is to solder the current limiting resistor on place one leg to make a ready-to-go breadboard LED. It is designed for 5v circuits; putting it in a 12v circuit would fry the LED. Here is where I (as the "module designer") used the LED's datasheet to know what circuitry it needed to protect it, and as the "consumer", would need to consult the spec sheet for the module to know how to apply it. If I were selling these things, they'd come with a Spec Sheet: "Only use this LED module in 5v or less applications."]  Hmph - pretty trivial example, but you get the idea.

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


message:
When does the ADC start reading again in interupt mode?

Simple question, I have set my ADC to read in "continuous"/interrupt mode and I take the reading the following way:

    ISR(ADC_vect) {
       int val = ADCL;
       val += ADCH << 8;
       ... //Code to do stuff with reading here.
       }

My question is does the ADC start the new reading as soon as I have read the ADCH register or does it wait for the code inside the interrupt to finish? Basically I need to know if having more instructions in the interrupt will slow down my reading rate.

I don't have an oscilloscope or any good way to measure my reading rate accurately enough to know if a few extra lines of codes is affecting the rate or not.

body:
Ok, I'm pretty sure I know the answer to this one now after some more testing. I played around with the number of instructions performed inside the ADC interrupt call and simply timed it using micros(). Though it did not give me super precise accuracy there was a clear and quick drop in read frequency when the number of CPU cycles needed inside the interrupt call exceeded the number of CPU cycles needed by the ADC while the frequency was hardly affected when the CPU cycles needed for the instructions were less than the cycles needed for the ADC. The only way I can make sense of this is if the ADC keeps going independently of the code that's inside the interrupt.

If someone wants to correct me/add some details here I would be very happy. But for my purposes this answer is enough :)


body:
Your answer is correct. The ADC does indeed keep going independently of
what the ISR does. There is, however, a point I would like to make
clearer. You asked:

> My question is does the ADC start the new reading as soon as I have
> read the ADCH register or does it wait for the code inside the
> interrupt to finish?

The ADC starts a new reading as soon as it is done taking the previous
one, _irrespective of_ whether you read ADCH or not. When your ISR
starts, the ADC is already busy making the following conversion. This
guarantees a steady conversion rate, at one A/D conversion every
13 ADC clock cycles exactly.

As a side note, you can read the result with

```c++
int val = ADC;
```

No need to read the bytes separately unless you are using a very ancient
version of gcc that does not know how to read a 16-bit register.


message:
Error in defining Ticker in ESP32 library

I'm using the exact piece of code in my ESP8266 library (which works OK ), but when used in a ESP32 library- I got an error:

This is the relevant code snip:

    void myIOT32::_feedTheDog()
    {
      _wdtResetCounter++;
      if (_wdtResetCounter >= _wdtMaxRetries)
      {
        sendReset("Dog goes woof");
      }
    }
    void myIOT32::_startWDT()
    {
      wdt.attach(1, std::bind(&myIOT32::_feedTheDog, this)); // Start WatchDog
    }

    void myIOT32::sendReset(char *header)
    {
      char temp[150];

      sprintf(temp, "[%s] - Reset sent", header);

      if (useSerial)
      {
        Serial.println(temp);
      }
      if (strcmp(header, "null") != 0)
      {
        pub_msg(temp);
      }
      delay(1000);
      ESP.restart();
    }

and this is the error:

    /home/guy/Documents/git/Arduino/libraries/myIOTesp32/myIOTesp32.cpp: In member function 'void myIOT32::_startWDT()':
    /home/guy/Documents/git/Arduino/libraries/myIOTesp32/myIOTesp32.cpp:333:55: error: no matching function for call to 'Ticker::attach(int, std::_Bind_helper<false, void (myIOT32::*)(), myIOT32*>::type)'
       wdt.attach(1, std::bind(&myIOT32::_feedTheDog, this)); // Start WatchDog
                                                           ^

body:
ESP32 ticker attach functions take pure function pointers with at max one argument type -- not a `std::function`/ `std::_Bind_helper` that `std::bind` produces.

See code and types at https://github.com/espressif/arduino-esp32/blob/master/libraries/Ticker/src/Ticker.h#L38.

For the ESP8266 however, they do use a `std::function`:

https://github.com/esp8266/Arduino/blob/master/libraries/Ticker/src/Ticker.h#L36

And that's why it works on ESP8266 and not on ESP32 -- either adapt the `Ticker` library or rework your own code to not use member functions of classes.

Edit: You can easily rewrite your code to use a static helper function with one argument (the watchdog object itself) which then just calls the member function of that object. For this to work, the **called function must be public**. So a rewrite like

```cpp
static void watchdog_timer_triggered_helper(myIOT32* watchdog) {
   //needs to be public!
   watchdog->_feedTheDog();
}

void myIOT32::_feedTheDog()
{
  _wdtResetCounter++;
  if (_wdtResetCounter >= _wdtMaxRetries)
  {
    sendReset("Dog goes woof");
  }
}
void myIOT32::_startWDT()
{
  wdt.attach(1, &watchdog_timer_triggered_helper, this); // Start WatchDog
}

void myIOT32::sendReset(char *header)
{
  char temp[150];

  sprintf(temp, "[%s] - Reset sent", header);

  if (useSerial)
  {
    Serial.println(temp);
  }
  if (strcmp(header, "null") != 0)
  {
    pub_msg(temp);
  }
  delay(1000);
  ESP.restart();
}
```

Since both the ESP32 and ESP8266 versions implement the

```cpp
    template<typename TArg>
    void attach(float seconds, void (*callback)(TArg), TArg arg)
```

templated function this should work on both platforms now.


message:
How do i fix the "A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header"

I have an AI Thinker ESP32-CAM and I've had issues uploading the CameraWebServer sketch, every time I hit upload it says "A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header" and I've tried everything that I can think of, I disconnected and reconnected all the connections on my FTDI board and I've done all sorts of button presses during the connection, I've switched the voltage and I've bought a whole new board and I don't know what the issue is or how to fix it.

body:
**ESP32 only works with 3.3 V serial do not switch the FTDI voltage to 5 V**

**Watch out for the serial connections too**

U0R-->TX

U0T-->RX

**If you mixed it up it won't work!**

First of all you need to connect two pins only when uploading
It is all ready fixed for you need to press the rest button when uploading
and seeing these dots as below image.

 - ESP32-CAM on-board RST button **Press and hold until you see uploading**

[![Uploading image view][1]][1]

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

After a few seconds, the code should be successfully uploaded to your board.

I hope this helped for you!

You can reffer to this link for more info

https://randomnerdtutorials.com/esp32-cam-take-photo-display-web-server/


body:
I have had the same problem / error message with a different board. I did not realise that during upload you **must** make sure that any GPIO pins that the board uses to talk to the flash chip **are NOT connected to other devices**. The upload process should be:

1. Disconnect any GPIO pin connectors.
1. Upload your code.
1. Reconnect any GPIO pin connectors.

(In your question, you say "I disconnected and reconnected all the connections" but **you do not say** whether all your connections were disconnected while you were trying to upload your code.)

I found this information [here](https://github.com/espressif/esptool/issues/394#issuecomment-453613886) (the text in that post says "This message normally means that the ESP32 can't talk to its attached flash chip (the flash chip may be in the module). Check the GPIO pins 6,7,8,9,10 & 11 (which are shared with the flash chip) are not connected to anything external or shorted together, etc.")

HTH.


message:
Compile-time 'Undefined reference' error for functions defined in a .cpp source file that are called in my main project file

I'm currently working with the NodeMCU ESP12E and MPU6050 IMU using the Arduino IDE and wanted to create a project that has a .h file that declares the variables and functions. In the .cpp file, I have various function definitions. The main.ino file just calls some of these functions. Please find some excerpts of code from each file and the errors I encountered. The errors say the three functions called in the .ino file are undefined even though they are defined in the .cpp file

Algo.h file:

```
extern int activity_state; // activity_state=1 for RUN and activity_state=0 for WALK
extern float * speedarray; // Dynamic array for storing speed
extern int speedindex;
extern float * timearray; // Dynamic array for storing time
extern int timeindex;

extern unsigned int localPort;
```
Algo.cpp:

```

static void pedometerInit() // Initialising all pedometer algorithm variables
{
      int i = 0;
  //pedometerAlgo varibles
  pedi_window_high = 2000;
  pedi_window_low = 200;

  pedi_sampling_counter = 0;
  pedi_refresh_frequency = 50;
  validZone = 1;
  jatin_index_1 = 0;
  jatin_mag = 0;
  pedi_max = 0;
.
.
```
All the functions work on the variables declared in the header file.

Ped_algo.ino:

```
void setup() {

  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(STASSID, STAPSK); // Setting up WiFi station
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(500);
  }

  Udp.begin(localPort); // Setting up UDP connection

  MPU6050_Init(); // Initial configuration of the MPU6050
  pedometerInit();
}

void loop() {

  pedometerAlgo();
}
```
Error messages:

Ped_Algo.ino.cpp.o:(.text.loop+0x0): undefined reference to `pedometerAlgo()'
in function `loop':
 undefined reference to `pedometerInit()'
 undefined reference to `MPU6050_Init()'
 undefined reference to `pedometerInit()'

Error compiling for board NodeMCU 1.0 (ESP-12E Module).

body:
Firstly, `static` keeps a function from ever being exported globally:

```
static void pedometerInit() // Initialising all pedometer algorithm variables
```

should not be `static`.

Secondly, `extern` does not define a variable, it merely tells the compiler that "this variable exists somewhere. Find it at link time." - however you're not actually defining those variables anywhere.  In addition to the `extern` hints in the `.h` file you need to have the variables in the `.cpp` file for the compiler to be able to find them.

```
int activity_state; // activity_state=1 for RUN and activity_state=0 for WALK
float * speedarray; // Dynamic array for storing speed
int speedindex;
float * timearray; // Dynamic array for storing time
int timeindex;

unsigned int localPort;

void pedometerInit() // Initialising all pedometer algorithm variables
{
 ... your code ...
}
```


message:
240*320 transparent OLED display with Arduino

A long time ago I ordered this transparent OLED display (from a chinese supplier on alibaba) planning on interfacing it with an Arduino but didn't really have the skills to get the project going.

I have the datasheet (linked below) for the driver and it seems to come with a schematic on it which takes the output from the OLED and gives me 8-bit wiring. My plan is to use the adafruit GFX library with it and probably steal the code from [this adafruit TFT.][1]

Please, someone tell me if this has no hope of working but my plan as it stands is:

1) draw up the datasheets schematic into Kicad, and get it printed onto a PCB (I am worried that if I breadboard/protoboard it, ill have all kinds of issues coming from my poor perfboarding skills and I want to be able to narrow down my problems. I know it's bad practise to print a PCB before doing any breadboarding but I don't think ill successfully manage it)

2) wire up the output pins from the new PCB in the same way that the adafruit board and try and use the same code.

3) Here are where the problems come I think as I am proficient at simple code (I'm probably being ignorant to the fact that 'simple' code is still way above my level) e.g functions/loops etc... but writing code like adafruits example for displays is way above my level. I hope that I can just edit some of Adafruits existing example code and it will just work.

A few years ago I asked a similar question on the Arduino forum but then I was much worse at programming and had less of an idea where to start.

If any of you can provide insight into if this will work or any better ideas then I am all ears.

Thanks

Documents containing datasheets and example code - https://drive.google.com/drive/folders/1ZTmipJKRKWNMudYVQ5ATxixbQtKD4hQm?usp=sharing

[![Schematic Provided][2]][2]

------------------------------------------------------------------

edit:
there is also a file called example_code.txt which contains a lot of (I dont know what I'm talking about really) hex commands.

edit 2: - ILI9341 Mock Example

    /***************************************************
      This is our GFX example for the Adafruit ILI9341 Breakout and Shield
      ----> http://www.adafruit.com/products/1651

      Check out the links above for our tutorials and wiring diagrams
      These displays use SPI to communicate, 4 or 5 pins are required to
      interface (RST is optional)
      Adafruit invests time and resources providing this open source code,
      please support Adafruit and open-source hardware by purchasing
      products from Adafruit!

      Written by Limor Fried/Ladyada for Adafruit Industries.
      MIT license, all text above must be included in any redistribution
     ****************************************************/

    #include "SPI.h"
    #include "Adafruit_GFX.h"
    #include "Adafruit_ILI9341.h"

    // For the Adafruit shield, these are the default.
    #define TFT_DC 9
    #define TFT_CS 10

    // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
    Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
    // If using the breakout, change pins as desired
    //Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

    void setup() {
      Serial.begin(9600);
      Serial.println("ILI9341 Test!");

      tft.begin();

      // read diagnostics (optional but can help debug problems)
      uint8_t x = tft.readcommand8(ILI9341_RDMODE);
      Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
      x = tft.readcommand8(ILI9341_RDMADCTL);
      Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
      x = tft.readcommand8(ILI9341_RDPIXFMT);
      Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
      x = tft.readcommand8(ILI9341_RDIMGFMT);
      Serial.print("Image Format: 0x"); Serial.println(x, HEX);
      x = tft.readcommand8(ILI9341_RDSELFDIAG);
      Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);

      Serial.println(F("Benchmark                Time (microseconds)"));
      delay(10);
      Serial.print(F("Screen fill              "));
      Serial.println(testFillScreen());
      delay(500);

      Serial.print(F("Text                     "));
      Serial.println(testText());
      delay(3000);

      Serial.print(F("Lines                    "));
      Serial.println(testLines(ILI9341_CYAN));
      delay(500);

      Serial.print(F("Horiz/Vert Lines         "));
      Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
      delay(500);

      Serial.print(F("Rectangles (outline)     "));
      Serial.println(testRects(ILI9341_GREEN));
      delay(500);

      Serial.print(F("Rectangles (filled)      "));
      Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
      delay(500);

      Serial.print(F("Circles (filled)         "));
      Serial.println(testFilledCircles(10, ILI9341_MAGENTA));

      Serial.print(F("Circles (outline)        "));
      Serial.println(testCircles(10, ILI9341_WHITE));
      delay(500);

      Serial.print(F("Triangles (outline)      "));
      Serial.println(testTriangles());
      delay(500);

      Serial.print(F("Triangles (filled)       "));
      Serial.println(testFilledTriangles());
      delay(500);

      Serial.print(F("Rounded rects (outline)  "));
      Serial.println(testRoundRects());
      delay(500);

      Serial.print(F("Rounded rects (filled)   "));
      Serial.println(testFilledRoundRects());
      delay(500);

      Serial.println(F("Done!"));

    }

    void loop(void) {
      for(uint8_t rotation=0; rotation<4; rotation++) {
        tft.setRotation(rotation);
        testText();
        delay(1000);
      }
    }

    unsigned long testFillScreen() {
      unsigned long start = micros();
      tft.fillScreen(ILI9341_BLACK);
      yield();
      tft.fillScreen(ILI9341_RED);
      yield();
      tft.fillScreen(ILI9341_GREEN);
      yield();
      tft.fillScreen(ILI9341_BLUE);
      yield();
      tft.fillScreen(ILI9341_BLACK);
      yield();
      return micros() - start;
    }

    unsigned long testText() {
      tft.fillScreen(ILI9341_BLACK);
      unsigned long start = micros();
      tft.setCursor(0, 0);
      tft.setTextColor(ILI9341_WHITE);  tft.setTextSize(1);
      tft.println("Hello World!");
      tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
      tft.println(1234.56);
      tft.setTextColor(ILI9341_RED);    tft.setTextSize(3);
      tft.println(0xDEADBEEF, HEX);
      tft.println();
      tft.setTextColor(ILI9341_GREEN);
      tft.setTextSize(5);
      tft.println("Groop");
      tft.setTextSize(2);
      tft.println("I implore thee,");
      tft.setTextSize(1);
      tft.println("my foonting turlingdromes.");
      tft.println("And hooptiously drangle me");
      tft.println("with crinkly bindlewurdles,");
      tft.println("Or I will rend thee");
      tft.println("in the gobberwarts");
      tft.println("with my blurglecruncheon,");
      tft.println("see if I don't!");
      return micros() - start;
    }

    unsigned long testLines(uint16_t color) {
      unsigned long start, t;
      int           x1, y1, x2, y2,
                    w = tft.width(),
                    h = tft.height();

      tft.fillScreen(ILI9341_BLACK);
      yield();

      x1 = y1 = 0;
      y2    = h - 1;
      start = micros();
      for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
      x2    = w - 1;
      for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
      t     = micros() - start; // fillScreen doesn't count against timing

      yield();
      tft.fillScreen(ILI9341_BLACK);
      yield();

      x1    = w - 1;
      y1    = 0;
      y2    = h - 1;
      start = micros();
      for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
      x2    = 0;
      for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
      t    += micros() - start;

      yield();
      tft.fillScreen(ILI9341_BLACK);
      yield();

      x1    = 0;
      y1    = h - 1;
      y2    = 0;
      start = micros();
      for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
      x2    = w - 1;
      for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
      t    += micros() - start;

      yield();
      tft.fillScreen(ILI9341_BLACK);
      yield();

      x1    = w - 1;
      y1    = h - 1;
      y2    = 0;
      start = micros();
      for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
      x2    = 0;
      for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);

      yield();
      return micros() - start;
    }

    unsigned long testFastLines(uint16_t color1, uint16_t color2) {
      unsigned long start;
      int           x, y, w = tft.width(), h = tft.height();

      tft.fillScreen(ILI9341_BLACK);
      start = micros();
      for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
      for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);

      return micros() - start;
    }

    unsigned long testRects(uint16_t color) {
      unsigned long start;
      int           n, i, i2,
                    cx = tft.width()  / 2,
                    cy = tft.height() / 2;

      tft.fillScreen(ILI9341_BLACK);
      n     = min(tft.width(), tft.height());
      start = micros();
      for(i=2; i<n; i+=6) {
        i2 = i / 2;
        tft.drawRect(cx-i2, cy-i2, i, i, color);
      }

      return micros() - start;
    }

    unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
      unsigned long start, t = 0;
      int           n, i, i2,
                    cx = tft.width()  / 2 - 1,
                    cy = tft.height() / 2 - 1;

      tft.fillScreen(ILI9341_BLACK);
      n = min(tft.width(), tft.height());
      for(i=n; i>0; i-=6) {
        i2    = i / 2;
        start = micros();
        tft.fillRect(cx-i2, cy-i2, i, i, color1);
        t    += micros() - start;
        // Outlines are not included in timing results
        tft.drawRect(cx-i2, cy-i2, i, i, color2);
        yield();
      }

      return t;
    }

    unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
      unsigned long start;
      int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;

      tft.fillScreen(ILI9341_BLACK);
      start = micros();
      for(x=radius; x<w; x+=r2) {
        for(y=radius; y<h; y+=r2) {
          tft.fillCircle(x, y, radius, color);
        }
      }

      return micros() - start;
    }

    unsigned long testCircles(uint8_t radius, uint16_t color) {
      unsigned long start;
      int           x, y, r2 = radius * 2,
                    w = tft.width()  + radius,
                    h = tft.height() + radius;

      // Screen is not cleared for this one -- this is
      // intentional and does not affect the reported time.
      start = micros();
      for(x=0; x<w; x+=r2) {
        for(y=0; y<h; y+=r2) {
          tft.drawCircle(x, y, radius, color);
        }
      }

      return micros() - start;
    }

    unsigned long testTriangles() {
      unsigned long start;
      int           n, i, cx = tft.width()  / 2 - 1,
                          cy = tft.height() / 2 - 1;

      tft.fillScreen(ILI9341_BLACK);
      n     = min(cx, cy);
      start = micros();
      for(i=0; i<n; i+=5) {
        tft.drawTriangle(
          cx    , cy - i, // peak
          cx - i, cy + i, // bottom left
          cx + i, cy + i, // bottom right
          tft.color565(i, i, i));
      }

      return micros() - start;
    }

    unsigned long testFilledTriangles() {
      unsigned long start, t = 0;
      int           i, cx = tft.width()  / 2 - 1,
                       cy = tft.height() / 2 - 1;

      tft.fillScreen(ILI9341_BLACK);
      start = micros();
      for(i=min(cx,cy); i>10; i-=5) {
        start = micros();
        tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
          tft.color565(0, i*10, i*10));
        t += micros() - start;
        tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
          tft.color565(i*10, i*10, 0));
        yield();
      }

      return t;
    }

    unsigned long testRoundRects() {
      unsigned long start;
      int           w, i, i2,
                    cx = tft.width()  / 2 - 1,
                    cy = tft.height() / 2 - 1;

      tft.fillScreen(ILI9341_BLACK);
      w     = min(tft.width(), tft.height());
      start = micros();
      for(i=0; i<w; i+=6) {
        i2 = i / 2;
        tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
      }

      return micros() - start;
    }

    unsigned long testFilledRoundRects() {
      unsigned long start;
      int           i, i2,
                    cx = tft.width()  / 2 - 1,
                    cy = tft.height() / 2 - 1;

      tft.fillScreen(ILI9341_BLACK);
      start = micros();
      for(i=min(tft.width(), tft.height()); i>20; i-=6) {
        i2 = i / 2;
        tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
        yield();
      }

      return micros() - start;
    }

edit 3: - ili9341 header file

    /*!
     * @file Adafruit_ILI9341.h
     *
     * This is the documentation for Adafruit's ILI9341 driver for the
     * Arduino platform.
     *
     * This library works with the Adafruit 2.8" Touch Shield V2 (SPI)
     *    http://www.adafruit.com/products/1651
     * Adafruit 2.4" TFT LCD with Touchscreen Breakout w/MicroSD Socket - ILI9341
     *    https://www.adafruit.com/product/2478
     * 2.8" TFT LCD with Touchscreen Breakout Board w/MicroSD Socket - ILI9341
     *    https://www.adafruit.com/product/1770
     * 2.2" 18-bit color TFT LCD display with microSD card breakout - ILI9340
     *    https://www.adafruit.com/product/1770
     * TFT FeatherWing - 2.4" 320x240 Touchscreen For All Feathers
     *    https://www.adafruit.com/product/3315
     *
     * These displays use SPI to communicate, 4 or 5 pins are required
     * to interface (RST is optional).
     *
     * Adafruit invests time and resources providing this open source code,
     * please support Adafruit and open-source hardware by purchasing
     * products from Adafruit!
     *
     *
     * This library depends on
     * Adafruit_GFX being present on your system. Please make sure you have
     * installed the latest version before using this library.
     *
     * Written by Limor "ladyada" Fried for Adafruit Industries.
     *
     * BSD license, all text here must be included in any redistribution.
     *
     */

    #ifndef _ADAFRUIT_ILI9341H_
    #define _ADAFRUIT_ILI9341H_

    #include "Adafruit_GFX.h"
    #include "Arduino.h"
    #include "Print.h"
    #include <Adafruit_SPITFT.h>
    #include <Adafruit_SPITFT_Macros.h>
    #include <SPI.h>

    #define ILI9341_TFTWIDTH 240  ///< ILI9341 max TFT width
    #define ILI9341_TFTHEIGHT 320 ///< ILI9341 max TFT height

    #define ILI9341_NOP 0x00     ///< No-op register
    #define ILI9341_SWRESET 0x01 ///< Software reset register
    #define ILI9341_RDDID 0x04   ///< Read display identification information
    #define ILI9341_RDDST 0x09   ///< Read Display Status

    #define ILI9341_SLPIN 0x10  ///< Enter Sleep Mode
    #define ILI9341_SLPOUT 0x11 ///< Sleep Out
    #define ILI9341_PTLON 0x12  ///< Partial Mode ON
    #define ILI9341_NORON 0x13  ///< Normal Display Mode ON

    #define ILI9341_RDMODE 0x0A     ///< Read Display Power Mode
    #define ILI9341_RDMADCTL 0x0B   ///< Read Display MADCTL
    #define ILI9341_RDPIXFMT 0x0C   ///< Read Display Pixel Format
    #define ILI9341_RDIMGFMT 0x0D   ///< Read Display Image Format
    #define ILI9341_RDSELFDIAG 0x0F ///< Read Display Self-Diagnostic Result

    #define ILI9341_INVOFF 0x20   ///< Display Inversion OFF
    #define ILI9341_INVON 0x21    ///< Display Inversion ON
    #define ILI9341_GAMMASET 0x26 ///< Gamma Set
    #define ILI9341_DISPOFF 0x28  ///< Display OFF
    #define ILI9341_DISPON 0x29   ///< Display ON

    #define ILI9341_CASET 0x2A ///< Column Address Set
    #define ILI9341_PASET 0x2B ///< Page Address Set
    #define ILI9341_RAMWR 0x2C ///< Memory Write
    #define ILI9341_RAMRD 0x2E ///< Memory Read

    #define ILI9341_PTLAR 0x30    ///< Partial Area
    #define ILI9341_VSCRDEF 0x33  ///< Vertical Scrolling Definition
    #define ILI9341_MADCTL 0x36   ///< Memory Access Control
    #define ILI9341_VSCRSADD 0x37 ///< Vertical Scrolling Start Address
    #define ILI9341_PIXFMT 0x3A   ///< COLMOD: Pixel Format Set

    #define ILI9341_FRMCTR1                                                        \
      0xB1 ///< Frame Rate Control (In Normal Mode/Full Colors)
    #define ILI9341_FRMCTR2 0xB2 ///< Frame Rate Control (In Idle Mode/8 colors)
    #define ILI9341_FRMCTR3                                                        \
      0xB3 ///< Frame Rate control (In Partial Mode/Full Colors)
    #define ILI9341_INVCTR 0xB4  ///< Display Inversion Control
    #define ILI9341_DFUNCTR 0xB6 ///< Display Function Control

    #define ILI9341_PWCTR1 0xC0 ///< Power Control 1
    #define ILI9341_PWCTR2 0xC1 ///< Power Control 2
    #define ILI9341_PWCTR3 0xC2 ///< Power Control 3
    #define ILI9341_PWCTR4 0xC3 ///< Power Control 4
    #define ILI9341_PWCTR5 0xC4 ///< Power Control 5
    #define ILI9341_VMCTR1 0xC5 ///< VCOM Control 1
    #define ILI9341_VMCTR2 0xC7 ///< VCOM Control 2

    #define ILI9341_RDID1 0xDA ///< Read ID 1
    #define ILI9341_RDID2 0xDB ///< Read ID 2
    #define ILI9341_RDID3 0xDC ///< Read ID 3
    #define ILI9341_RDID4 0xDD ///< Read ID 4

    #define ILI9341_GMCTRP1 0xE0 ///< Positive Gamma Correction
    #define ILI9341_GMCTRN1 0xE1 ///< Negative Gamma Correction
    //#define ILI9341_PWCTR6     0xFC

    // Color definitions
    #define ILI9341_BLACK 0x0000       ///<   0,   0,   0
    #define ILI9341_NAVY 0x000F        ///<   0,   0, 123
    #define ILI9341_DARKGREEN 0x03E0   ///<   0, 125,   0
    #define ILI9341_DARKCYAN 0x03EF    ///<   0, 125, 123
    #define ILI9341_MAROON 0x7800      ///< 123,   0,   0
    #define ILI9341_PURPLE 0x780F      ///< 123,   0, 123
    #define ILI9341_OLIVE 0x7BE0       ///< 123, 125,   0
    #define ILI9341_LIGHTGREY 0xC618   ///< 198, 195, 198
    #define ILI9341_DARKGREY 0x7BEF    ///< 123, 125, 123
    #define ILI9341_BLUE 0x001F        ///<   0,   0, 255
    #define ILI9341_GREEN 0x07E0       ///<   0, 255,   0
    #define ILI9341_CYAN 0x07FF        ///<   0, 255, 255
    #define ILI9341_RED 0xF800         ///< 255,   0,   0
    #define ILI9341_MAGENTA 0xF81F     ///< 255,   0, 255
    #define ILI9341_YELLOW 0xFFE0      ///< 255, 255,   0
    #define ILI9341_WHITE 0xFFFF       ///< 255, 255, 255
    #define ILI9341_ORANGE 0xFD20      ///< 255, 165,   0
    #define ILI9341_GREENYELLOW 0xAFE5 ///< 173, 255,  41
    #define ILI9341_PINK 0xFC18        ///< 255, 130, 198

    /**************************************************************************/
    /*!
    @brief Class to manage hardware interface with ILI9341 chipset (also seems to
    work with ILI9340)
    */
    /**************************************************************************/

    class Adafruit_ILI9341 : public Adafruit_SPITFT {
    public:
      Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK,
                       int8_t _RST = -1, int8_t _MISO = -1);
      Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1);
    #if !defined(ESP8266)
      Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs = -1,
                       int8_t rst = -1);
    #endif // end !ESP8266
      Adafruit_ILI9341(tftBusWidth busWidth, int8_t d0, int8_t wr, int8_t dc,
                       int8_t cs = -1, int8_t rst = -1, int8_t rd = -1);

      void begin(uint32_t freq = 0);
      void setRotation(uint8_t r);
      void invertDisplay(bool i);
      void scrollTo(uint16_t y);
      void setScrollMargins(uint16_t top, uint16_t bottom);

      // Transaction API not used by GFX
      void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h);

      uint8_t readcommand8(uint8_t reg, uint8_t index = 0);
    };

    #endif // _ADAFRUIT_ILI9341H_

  [1]: https://learn.adafruit.com/adafruit-2-4-color-tft-touchscreen-breakout/wiring-and-test
  [2]: https://i.stack.imgur.com/qnXIr.jpg

body:
The critical part, assuming your hardware works, is getting the software going. Not all OLEDs are the same, and different ones need different commands to get them working.

You can't just take a random OLED and use a random library - it needs a driver to make it work.

In this case it's the DA8620 that is the main chip that you want to worry about, and your chosen library has to implement the commands and methodologies for that specific chip.

Now, you have a file that contains those commands (all the "hex commands"), and if you can't find an existing library to work with the DA8620 then you will have to write or adapt one while referring to those commands.  You can find out more about what the commands all mean by referencing the datasheet, which lists all the commands and their parameters (from page 78 onwards), so you should be able to relate those to what an existing library needs and map things accordingly while keeping the right power-up sequences.


body:
Your `initial code.txt` file is flawed.

The pdf file has the code in multiple columns on each page, and not all the columns are filled.

This is the code (i think it is correct)

18. Example of Initial Code
```
Command(0x11);
Data(0x00);

Delay_ms(255);   // Delay 255ms or more

Command(0xC5);
Data(0x01);

Command(0xC4);
Data(0x2F);

Command(0xC0);
Data(0x10);
Data(0x00);

Command(0x26);
Data(0x00);

Command(0x2A);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0xEF);

Command(0x2B);
Data(0x00);
Data(0x00);
Data(0x01);
Data(0x3F);

Command(0x36);
Data(0x08);

Command(0xC0);
Data(0x50);
Data(0x00);

Command(0x3A);
Data(0x65);    //Pixel Format 16bit data
//Data(0x67);  //Pixel Format 24bit data

Command(0xBB);
Data(0x4D);
Data(0x97);
Data(0x1C);

Command(0xC1);
Data(0x01);

Command(0xC6);
Data(0x6B);
Data(0x02);
Data(0x00);
Data(0x06);
Data(0x06);
Data(0x06);

Command(0xC9);
Data(0xF0);

Command(0xE0);
Data(0xC0);
Data(0x00);

Command(0xE2);
Data(0x00);

Command(0xE8);
Data(0x23);
Data(0x00);
Data(0x00);

Command(0xEB);
Data(0xC0);

Command(0xD9);
Data(0x40);
Data(0x00);

Command(0xD1);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);

Command(0xDF);
Data(0x35);
Data(0xAD);
Data(0x1C);
Data(0xE7);
Data(0x18);
Data(0xC6);
Data(0x14);
Data(0xA5);
Data(0x18);
Data(0xC6);
Data(0x14);
Data(0xA5);
Data(0x18);
Data(0xC6);
Data(0x14);
Data(0xA5);
Data(0x18);
Data(0xC6);
Data(0x14);
Data(0xA5);
Data(0x18);
Data(0xC6);
Data(0x14);
Data(0xA5);
Data(0x14);
Data(0xA5);
Data(0x18);
Data(0xC6);
Data(0x14);
Data(0xA5);
Data(0x18);
Data(0xC6);
Data(0x14);
Data(0xA5);
Data(0x18);
Data(0xC6);
Data(0x10);
Data(0x84);
Data(0x1C);
Data(0xE7);
Data(0x14);
Data(0xA5);
Data(0x10);
Data(0x84);
Data(0x1C);
Data(0xE7);
Data(0x08);
Data(0x42);
Data(0x0C);
Data(0x63);
Data(0x08);
Data(0x42);
Data(0x0C);
Data(0x63);
Data(0x10);
Data(0x84);
Data(0x08);
Data(0x42);
Data(0x0C);
Data(0x63);
Data(0x08);
Data(0x42);
Data(0x0C);
Data(0x63);
Data(0x10);
Data(0x84);
Data(0x14);
Data(0xA5);
Data(0x08);
Data(0x42);
Data(0x08);
Data(0x42);
Data(0x14);
Data(0xA5);
Data(0x0C);
Data(0x63);
Data(0x08);
Data(0x42);
Data(0x14);
Data(0xA5);
Data(0x08);
Data(0x42);
Data(0x08);
Data(0x42);
Data(0x0C);
Data(0x63);
Data(0x08);
Data(0x42);
Data(0x14);
Data(0xA5);
Data(0x14);
Data(0xA5);
Data(0x08);
Data(0x42);
Data(0x0C);
Data(0x63);

Command(0xD0);
Data(0x9F);
Data(0x19);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0x9F);
Data(0x19);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0x9F);
Data(0x19);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0x9F);
Data(0x19);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x0D);
Data(0x94);
Data(0x28);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x04);
Data(0x16);
Data(0xFF);
Data(0x00);
Data(0x04);
Data(0x16);
Data(0xFF);
Data(0x00);
Data(0x04);
Data(0x16);
Data(0x8F);
Data(0x35);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x04);
Data(0x20);
Data(0xFF);
Data(0x00);
Data(0x04);
Data(0x20);
Data(0xFF);
Data(0x00);
Data(0x04);
Data(0x20);
Data(0x8C);
Data(0x42);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x04);
Data(0x2A);
Data(0xFF);
Data(0x00);
Data(0x04);
Data(0x2A);
Data(0xFF);
Data(0x00);
Data(0x04);
Data(0x2A);
Data(0x8A);
Data(0x50);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x08);
Data(0x33);
Data(0x88);
Data(0x64);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x08);
Data(0x46);
Data(0xFF);
Data(0x00);
Data(0x08);
Data(0x46);
Data(0xFF);
Data(0x00);
Data(0x08);
Data(0x46);
Data(0x7C);
Data(0x67);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x44);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x44);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x44);
Data(0x6E);
Data(0x74);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x54);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x54);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x54);
Data(0x64);
Data(0x90);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x5E);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x5E);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x5E);
Data(0x5A);
Data(0x92);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x5F);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x5F);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x5F);
Data(0x52);
Data(0x94);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x61);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x61);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x61);
Data(0x4C);
Data(0x95);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x65);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x65);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x65);
Data(0x47);
Data(0x97);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x62);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x62);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x62);
Data(0x42);
Data(0x99);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x64);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x64);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x64);
Data(0x3E);
Data(0x9A);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x66);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x66);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x66);
Data(0x3A);
Data(0x9C);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x65);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x65);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x65);
Data(0x37);
Data(0x9D);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x68);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x68);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x68);
Data(0x34);
Data(0x9F);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x6A);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x6A);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x6A);
Data(0x32);
Data(0xA0);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x6B);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x6B);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x6B);
Data(0x2F);
Data(0xA2);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x70);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x70);
Data(0xFF);
Data(0x00);
Data(0x10);
Data(0x70);
Data(0x2D);
Data(0xA4);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x72);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x72);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x72);
Data(0x2B);
Data(0xA6);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x75);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x75);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x75);
Data(0x29);
Data(0xA7);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x76);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x76);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x76);
Data(0x28);
Data(0xA8);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x79);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x79);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x79);
Data(0x26);
Data(0xAA);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x81);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x81);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x81);
Data(0x25);
Data(0xAC);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x81);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x81);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x81);
Data(0x23);
Data(0xAE);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x87);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x87);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x87);
Data(0x22);
Data(0xAF);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x89);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x89);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x89);
Data(0x21);
Data(0xB1);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x8D);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x8D);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x8D);
Data(0x20);
Data(0xB2);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x89);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x89);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x89);
Data(0x1F);
Data(0xB4);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x8E);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x8E);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x8E);
Data(0x1E);
Data(0xB6);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x93);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x93);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x93);
Data(0x1D);
Data(0xB8);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x98);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x98);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x98);
Data(0x1C);
Data(0xBA);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x95);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x95);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x95);
Data(0x1B);
Data(0xBC);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x95);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x95);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x95);
Data(0x1B);
Data(0xBC);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x91);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x91);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x91);
Data(0x1A);
Data(0xBE);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x9A);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x9A);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0x9A);
Data(0x19);
Data(0xC0);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0xA8);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0xA8);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0xA8);
Data(0x19);
Data(0xC0);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0xA0);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0xA0);
Data(0xFF);
Data(0x00);
Data(0x0C);
Data(0xA0);
Data(0x17);
Data(0xC6);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0x2C);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0x2C);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0x2C);
Data(0x16);
Data(0xC9);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0x45);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0x45);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0x45);
Data(0x14);
Data(0xD0);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0x7F);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0x7F);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0x7F);
Data(0x11);
Data(0xDE);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0xF0);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0xF0);
Data(0xFF);
Data(0x00);
Data(0x02);
Data(0xF0);
Data(0x0F);
Data(0xEB);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0x00);
Data(0x03);
Data(0x54);
Data(0xFF);
Data(0x00);
Data(0x03);
Data(0x54);
Data(0xFF);
Data(0x00);
Data(0x03);
Data(0x54);

Command(0xDD);
Data(0x0B);
Data(0x0B);
Data(0x0B);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);

Command(0xDE);
Data(0x1C);

Command(0xE4);
Data(0x7F);
Data(0x7F);
Data(0x7F);
Data(0xEF);
Data(0xEF);
Data(0xEF);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0xFF);
Data(0xFF);
Data(0xFF);
Data(0x00);
Data(0x00);
Data(0x00);

Command(0xED);
Data(0x0F);

Command(0xC7);
Data(0x00);

Command(0xC8);
Data(0xA4);

Command(0xD2);
Data(0xA7);

Command(0xE2);
Data(0x09);

Delay_ms(255);
Delay_ms(255);
Delay_ms(255);

Command(0xF0);
Data(0x7E);
Data(0x54);
Data(0x45);
Data(0x53);
Data(0x54);
Data(0x21);

Command(0x51);
Data(0x16);

Command(0x50);
Data(0x00);

Command(0xCE);
Data(0x80);
Data(0x00);
Data(0xE0);
Data(0x00);
Data(0x00);
Data(0x00);

Command(0xCD);
Data(0x06);
Data(0xC7);

Delay_ms(16);   //Delay 16ms or more

Command(0xCE);
Data(0x80);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);
Data(0x00);

Command(0xCD);
Data(0x06);
Data(0xC7);

Command(0xCD);
Data(0x00);
Data(0x00);

Command(0x35);
Data(0x00);

Command(0xE0);
Data(0xD0);
Data(0x00);

Command(0x29);
Data(0x00);
```


body:
Is the SPI communication method feasible? I have found a chip at present, and it seems that the driver can be transplanted directly. You can look at this chip.
https://nl.mouser.com/ProductDetail/Newhaven-Display/NHD-169-BREAKOUT?qs=wnTfsH77Xs6v7mYjAGElxw==


message:
Understanding the variation of Arduino's current consumption with respect to the voltage supply

Even though this is already a well-debated topic, I couldn't find an extensive discussion about what really is drawing so much power in Arduino's board.

Here is the preamble: I have an Arduino Mega 2560, I measured its power consumption in a steady state with just a red LED turned on with a 560Ohm series resistor.
The power supply (Vcc) was given to Arduino from the Vin pin and the measurement were as follows (below the schematic set-up):

- 30mA @Vcc = 5.2V;
- 65mA @Vcc = 8.3V.

[![Test condition][1]][1]

What I would like to understand is:

1. From a hardware perspective, I don't see **what** is drawing all of this current in Arduino's board;
2. Why the current drawn from the power supply **changes so much** with the power supply's value (i.e. what part of the board changes its consumption with the power supply value);
3. It also seems that turning on an LED through a digital output of Arduino draws a higher current with a higher power supply (Vcc). Why is that?

Note that, by looking at the datasheet of the ATmega2560, the uC mounted on my Arduino, I saw that the current Icc drawn from the power supply is max 14mA (I suppose when no output is sourcing current, I couldn't find the test conditions, unfortunately). I thought the microcontroller was the major cause of power consumption, but it doesn't seem to be so!

Another thing I considered is the onboard LDO, but the input voltage should change the power dissipated by the LDO, not the current drawn from its output.

It's even more strange if you think that regardless of the Vin, all the electronics after the LDO is working at the same voltage.

**EDIT1**

After Majenko pointed out a big flaw in my set-up with his answer, I re-measured with Vcc = 12.1V and I measured approximately the same Icc observed at Vcc = 8.1V.
I completely agree with Majenko's answer and I would just like to go a bit more in details about what happens while the board is working under voltage.

**Here is my analysis:**

The minimum operating condition when supplied from Vin is 7V, and that's the "knee" point in Majenko's answer.

However, the maximum quiescent current of the LDO is 10mA, and the Icc of the ATmega2560 is 15mA, so even if we suppose they don't draw any current at Vcc=5.2V, and then draw 25mA together at the minimum operating voltage at 7V, this doesn't add up to the actual increase of 40 or 50 mA that Majenko calculated I observed from 5.2 to 8.3 (which should be the same as from 5.2 to 7V).

And we're not even taking into account that at 5.2V the micro is perfectly able to turn on and keep on the LED, so it's somewhat working and already drawing some current.

Other things that we can take into account, but don't change the facts, are:

- a second LDO (LP2985) to generate the 3V3, whose quiescent current should be around 100uA since the circuit is not drawing any current from the 3V3.
- <s>a second microcontroller related to the USB programming, whose Icc may be up to 20mA but this one is OFF when supplying from Vin. </s> -->  Edgar Bonet correctly pointed out that this is not true!
- Some voltage dividers and comparators.

**So what is the cause of this increase in current consumption from 5 to 7V?**

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

body:
There is a basic error in your methodology which leads to incorrect conclusions.

You cannot determine what is going on from just two data points. Instead you need far more.

Here is a voltage sweep from 5V to 12V with a 0.05V resolution (overkill, but the default setting for the script I use) connected to a Mega:

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

As you can see the current steadily climes in a pretty linear fashion up to a certain point, then it flattens out.

Everything up to the point where it flattens is below the minimum input voltage for the board. During this time the voltage regulator isn't getting enough voltage, so can't regulate its output voltage to 5V. So the board is running under voltage at this point.  Once it reaches that "knee" point the voltage regulator can regulate the voltage properly - so most of the components on the board start seeing a steady 5V and their current consumption flattens out.

There are a handful of components on the high-voltage side of the regulator - most notably the voltage divider for detecting the input voltage and feeding it to the comparator that drives the P-channel FET to turn the USB power on and off - which will consume slightly more current when the voltage increases, but that is only very small amounts.

So, in short, by comparing a voltage that is below the minimum input voltage for the board with one that is above the minimum input voltage, you are comparing an invalid result with a valid result and inferring that everything in between is valid.

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


message:
Multiple Buttons to control the same led for different on off times

I am just learning the Arduino, it is a learning curve that's for sure.

Using the onboard Led I want to use two buttons to make the Led blink for different times.

I am not sure what is missing from the code, as pressing BUTTON2 gives the same time as BUTTON.

Any help would be greatly appreciated.

     const byte BUTTON = 2;
    const byte BUTTON2 = 3;
    const byte LED = 13;

    unsigned long buttonPushedMillis;
    unsigned long ledTurnedOnAt;
    unsigned long turnOnDelay = 500;
    unsigned long turnOffDelay = 500;
    unsigned long turnOnDelay2 = 1000;
    unsigned long turnOffDelay2 = 1000;
    bool ledReady = false;
    bool ledState = false;

    void setup() {
      pinMode(BUTTON, INPUT_PULLUP);
      pinMode(BUTTON2, INPUT_PULLUP);
      pinMode(LED, OUTPUT);
      digitalWrite(LED, LOW);
    }

    void loop() {
      unsigned long currentMillis = millis();
      if (digitalRead(BUTTON) == LOW) {
        delay(50);
        buttonPushedMillis = currentMillis;
        ledReady = true;
      }
      if (ledReady) {
        if ((unsigned long)(currentMillis - buttonPushedMillis) >= turnOnDelay) {
          digitalWrite(LED, HIGH);
          ledState = true;
          ledTurnedOnAt = currentMillis;
          ledReady = false;
        }
      }
      if (ledState) {
        if ((unsigned long)(currentMillis - ledTurnedOnAt) >= turnOffDelay) {
          ledState = false;
          digitalWrite(LED, LOW);
        }
      }
      {
        unsigned long currentMillis = millis();
        if (digitalRead(BUTTON2) == LOW) {
          delay(50);
          buttonPushedMillis = currentMillis;
          ledReady = true;
        }
        if (ledReady) {
          if ((unsigned long)(currentMillis - buttonPushedMillis) >= turnOnDelay2) {
            digitalWrite(LED, HIGH);
            ledState = true;
            ledTurnedOnAt = currentMillis;
            ledReady = false;
          }
        }
        if (ledState) {
          if ((unsigned long)(currentMillis - ledTurnedOnAt) >= turnOffDelay2) {
            ledState = false;
            digitalWrite(LED, LOW);
          }
        }
      }
    }
\\\

body:
You're making your program too complex for its own good.

Instead of changing your blink code depending on which button is pressed, just make the button change the blink code's parameters, and stick to just one blink code.

That means having just one set of blink variables which your blink code uses, and your button code then just changes what values those variables contain.


message:
Can you activate the whole pixel on LCD?

I'm working on a project where I'm trying to display the level of a filled tank through ultrasonic, then displaying it on a 16x2 LCD. I'm trying to do it through the whole LCD Pixels, such that when the tank level is full, the first 5 pixels are activated (as what happens when you connect the LCD initially without having any code for it, the whole pixels are turned on, giving 16x2 white rectangles, as shown in the picture below). Is there a way to activate an entire pixel on the LCD?

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

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

body:
The LCD is made up from 32 characters each is 5x7 pixels in size, with a 1 pixel gap between each character.

You can never put anything in the gap between the characters, as there is just nothing there.

But what you can do is define your own characters to fit within the 5x7 pixel rectangles.

Some variants of the HD44780 have character 255 as a solid block, but not all (it depends on what language the ROM is).  If you have one that has that character you can just print it with `lcd.print("\xff")` or `lcd.write(255)`.  If it doesn't it will print `ÿ` instead. In that case you will have to define your own character.

One benefit of defining your own characters is that you could then do partial blocks to give you a higher resolution.  Here's an example:

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

You can find that example and the code that goes with it [here](https://www.electronicsblog.net/arduino-lcd-horizontal-progress-bar-using-custom-characters/).

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


body:
The LCDs like the one you picture display **characters**. That is all they do. You can't address the pixels in the display.

And as a point of clarification, you are talking about the 5 pixel by 7 pixel character blocks on the display as if a character is a pixel. It's not. A character block consists of 5 x 7 pixels.

Some versions may have a pre-defined solid block character, as Majenko said in their answer. You could print as many of those solid blocks as you want.

You could also define a single custom character that displays a solid block and print as many of those as you want.

As a third option (again from Majenko's excellent answer) you could define 5 different custom characters, each with a different number of columns of pixels filled in. You could then write code that displayed solid blocks for all but the last character, and then one of the 5 partly filled custom characters, and get a finer resolution of simulated bar graph.

All that said, remember, the LCD display can only display 5x7 blocks with blank space between. The LCD is built without any pixels between the characters, so there will always be blank spaces.

There are other pixel displays you could use. (I've seen OLED displays where you can control every character individually.)


message:
trying to switch input on my speakers via infrared using web browser but i have issue getting it working

ived tested the IR code with
https://github.com/wemos/D1_mini_Examples/blob/master/examples/04.Shields/IR_Controller_Shield/IRsend/IRsend.ino

and it works that way, but when i try to code it together with the web server, i get nothing, can someone explain to me what's wrong in my code? the webserver works fine, its the IR part i dont fully understand why its not working

```
#include <i18n.h>
#include "ESP8266WiFi.h"
#include "ESP8266WebServer.h"
#include <IRremoteESP8266.h>
#include <IRsend.h>
ESP8266WebServer server(80);

void setup() {
  Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
  WiFi.begin("net", "pass");  //Connect to the WiFi network

  while (WiFi.status() != WL_CONNECTED) {  //Wait for connection

    delay(500);
    Serial.println("Waiting to connect…");

  }

  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  //Print the local IP

  server.on("/on", []() {   //Define the handling function for the path

    server.send(200, "text / plain", "Switching to USB input");
    #define IR_LED D3
    IRsend irsend(IR_LED);  // Set the GPIO to be used to sending the message.
    uint16_t rawData[71] = {8992, 4494,  574, 558,  572, 558,  574, 558,  574, 558,  574, 558,  572, 558,  572, 556,  572, 1660,  572, 1658,  574, 1658,  574, 1658,  574, 1660,  574, 1660,  574, 1660,  574, 1658,  602, 528,  574, 558,  574, 1658,  576, 556,  574, 556,  574, 1660,  574, 556,  574, 554,  574, 554,  574, 1658,  574, 556,  574, 1656,  576, 1658,  576, 556,  574, 1658,  576, 1656,  576, 1658,  576, 39978,  8994, 2256,  578};
    irsend.begin();

  });

  server.on("/", handleRootPath);    //Associate the handler function to the path
  server.begin();                    //Start the server
  Serial.println("Server listening");

}

void loop() {

  server.handleClient();         //Handling of incoming requests

}

void handleRootPath() {            //Handler for the rooth path

  server.send(200, "text/plain", "NinjaLights");

}
```

body:
Look at your code. You set up the sender, define the data and then never use it:

    server.on("/on", []() {   //Define the handling function for the path
        server.send(200, "text / plain", "Switching to USB input");
        #define IR_LED D3
        IRsend irsend(IR_LED);  // Set the GPIO to be used to sending the message.
        uint16_t rawData[71] = {8992, 4494,  574, 558,  572, 558,  574, 558,  574, 558,  574, 558,  572, 558,  572, 556,  572, 1660,  572, 1658,  574, 1658,  574, 1658,  574, 1660,  574, 1660,  574, 1660,  574, 1658,  602, 528,  574, 558,  574, 1658,  576, 556,  574, 556,  574, 1660,  574, 556,  574, 554,  574, 554,  574, 1658,  574, 556,  574, 1656,  576, 1658,  576, 556,  574, 1658,  576, 1656,  576, 1658,  576, 39978,  8994, 2256,  578};
        irsend.begin();

      });

You need to add a call to `irsend.SendRaw()` to actually send the data - otherwise you didn't actually do anything.

So your code would look like:

    server.on("/on", []() {   //Define the handling function for the path
        server.send(200, "text / plain", "Switching to USB input");
        #define IR_LED D3
        IRsend irsend(IR_LED);  // Set the GPIO to be used to sending the message.
        uint16_t rawData[71] = {8992, 4494,  574, 558,  572, 558,  574, 558,  574, 558,  574, 558,  572, 558,  572, 556,  572, 1660,  572, 1658,  574, 1658,  574, 1658,  574, 1660,  574, 1660,  574, 1660,  574, 1658,  602, 528,  574, 558,  574, 1658,  576, 556,  574, 556,  574, 1660,  574, 556,  574, 554,  574, 554,  574, 1658,  574, 556,  574, 1656,  576, 1658,  576, 556,  574, 1658,  576, 1656,  576, 1658,  576, 39978,  8994, 2256,  578};
        irsend.begin();

        irsend.sendRaw(rawData, 71, KHZ);
      });

You'll need to replace `KHZ` with the frequency the remote you're trying to replicate uses, otherwise it still won't work.


message:
Motor cutting out when using HC-05 Bluetooth module

I'm using an L293D motor driver chip along with an HC-05 Bluetooth module. The two work as expected separately - I can send a string via a Bluetooth terminal app on my phone to the HC-05 and I see it in the serial monitor just fine, and I can use the serial monitor to change the speed/direction of the DC motor without an issue. However, if I try to use the Bluetooth console on my phone to change the speed, the motor only spins for about a second before I lose connection with the HC-05 and it stops.

I think this is happening because the Arduino is tripping some breaker by drawing too much current to power both the HC-05 chip and the DC motor. Is this the case? Should I use an external battery pack to power the DC motor and L293D chip, and then keep the HC-05 connected to the 5V out line on the Arduino?

Thanks.

body:
>  Previously I was powering everything off of the 5V line on the Arduino, but I just switched to using an external battery pack of 4 AAs and that seems to work fine.

That suggests, that your power source was not strong enough. You didn't say, how you are powering the Arduino, but I guess you are doing so via USB. The USB port of a PC can only give you 500mA of current (at least without any extra configuration to get more). Also the parts on the Arduino (for example the diode between USB power and the 5V pin) can only give you a limited amount of current. Especially when the motor is starting, the needed current is rather big. That might have caused a short voltage dip, deep enough to irritate the HC-05 module.

Using an extra battery as power source for the motor eliminates that problem. Though I think you should be able to connect all parts to the same power source, as long as it is powerfull enough to power all parts (plus some overhead). In that case be sure to connect the power for the L293D and Arduino in parallel, so that the motor current does not have to flow through the Arduino (which could kill the voltage regulator or the diode).

Depending on your motor, it also might generate a huge amount of EMI (Electromagnetic Interference) either though air transmission or through the power lines, which might irritate the HC-05 enough. In that case the easiest option would be to add a second power source. Though I think the problem is with the power source as described above.


message:
Error taking address of temporary array when passing compound literal array

I have an Arduino sketch that passes an array into a method as a compound literal, but for some reason I keep getting the following error:
<!-- language-all: lang-cpp -->

    void setup() { }
    void printConcatLine(char chunks[][20]) { }

    void loop() {
      printConcatLine((char[][20]){ "{", "255", "}" });
    }

I've also tried passing the number of the pointers/length of the array, and explicitly terminating it:

    void setup() { }
    void printConcatLine(char *chunks[]) { }

    void loop() {
      printConcatLine((char*[]){ "{", "255", "}", NULL });
    }

...and

    void setup() { }
    void printConcatLine(char chunks[][20]) { }

    void loop() {
      printConcatLine((char[][20]){ "{", "255", "}", "" });
    }

But they both produce the same error.

What is the correct method of passing the compound literal array as a method parameter?

body:
You can't with the Arduino. I am not quite sure why, but I think it may be because it's a Modified Harvard architecture machine.

You can better achieve what you want with *[variadic](https://www.gnu.org/software/libc/manual/html_node/Variadic-Functions.html) arguments*, however:

```
void printConcatLine(int num, ...) {
    va_list ap;
    const char *s;

    va_start(ap, num);
    for (int i = 0; i < num; i++) {
        s = va_arg(ap, const char *);
        Serial.print(s);
    }
    va_end(ap);
    Serial.println();
}

void setup() {
    Serial.begin(115200);
    printConcatLine(3, "{", "255", "}");
}

void loop() {

}
```

The first argument is the number of arguments that follow, and all the rest are string constants.


message:
Stopping a motor after a given time period

I have a code to turn on a LED when IR Proximity sensor having a object less than 6cm in front of it,
and the LED goes down after it is removed.

Now, I want the LED to run for 3 seconds only, even if the object is not removed, how should I modify my code?
Many thanks in advance!

    int LED = 13; // pin for the LED
    int Sensor = 2;// pin for the IR Sensor

    void setup(){

      pinMode (LED, OUTPUT);
      pinMode (Sensor, INPUT);
    }

    void loop(){

      if (digitalRead(2)){

          digitalWrite(LED , LOW);
      }

      else{

        digitalWrite ( LED, HIGH);
        // if the IR sensor detects an object, the LED turns on or else it should not turn on
    }

body:
    int LED = 13;
    int Sensor = 2;

    void setup(){

      pinMode (LED, OUTPUT);
      pinMode (Sensor, INPUT);
    }

    void loop(){

     if (digitalRead(2)){

            digitalWrite(LED , LOW);
            delay(3);
      }

     else{

        digitalWrite ( LED, HIGH);``
     }