text:
Arduino Fails to Read Thermocouple on External Power
I'm having what I believe to be a power issue with an Arduino project. I've tried 3 different power supplies (all separately):

My computer via USB B
A 5V USB "outlet" via USB B
A 5V USB "outlet", through a 5V->9V boost converter, to the arduino's barrel jack

I can run the sketch without an issue when connected to my computer (supply 1), even if the computer is sleeping and the Arduino program is closed. However, when using supply 2 or 3, everything works EXCEPT reading the pilot light thermocouple through the MAX6675 module. It runs without throwing errors, but always reads 32.0 degrees F from the pilot light thermocouple. The other thermocouples run and update as expected.
Details:

Arduino Uno (bought ~November 2016)
Running Arduino 3 for programming (downloaded October 2017)
Code and Wiring Schematic below

Thanks for your help!
EDIT 1
I can run the Arduino with no problems off a small battery bank (like the kind you use to charge a phone with on the go). This isn't a permanent solution because the battery banks will only last 1-2 days powering the arduino. Anyway, I think this indicates that there's something to do with isolation/noise issues from the USB outlet, or something to do with not having a common ground.
Also, to clarify, the 5V USB outlet is powered by a 12V deep cycle battery, hooked up to a solar system with charge controller, other circuits, etc. I don't know if this is relevant, just trying to provide as much information as possible.
//-------------------------------------------------------------------------------------------
//--------------Inputs-----------------------------------------------------------------------

// DS18B20 Thermocouples
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// High temp thermocouple
#include <max6675.h>

// LCD Libraries
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

// Set temperature
int heatSetTemp = 60; // deg F
int bandwidth = 2; // if temp is within "bandwidth" of set point, it's acceptable

float freshWaterTemp; // deg F, current fresh water temp
float insideTemp; // deg F, current indoor temp
float outsideTemp; // deg F, current outside temp
float pilotTemp; // deg F, pilot light temperature

boolean pilotIsOn = false;
char pilotIsOnText = 'n';
boolean gasIsOn = false;
char gasIsOnText = 'n';

// Set up high temp thermocouple
int pilotThermo_sck_pin = 10;
int pilotThermo_cs_pin = 9;
int pilotThermo_so_pin = 8;
MAX6675 pilotThermo(pilotThermo_sck_pin, pilotThermo_cs_pin, pilotThermo_so_pin);

// Set up pilot light solenoid relay
// pin 3 is saved for A/C control - to be implemented
int ac_relay_pin = 3;
int gasSolenoid_pin = 2;

// Pin 4 has a wire jammed in it - not used

// Set up ambient thermocouples
int freshWaterThermo_pin = 5;
int insideThermo_pin = 6;
int outsideThermo_pin = 7;

OneWire freshWaterThermo(freshWaterThermo_pin);
DallasTemperature freshWaterThermoSensor(&freshWaterThermo);
OneWire insideThermo(insideThermo_pin);
DallasTemperature insideThermoSensor(&insideThermo);
OneWire outsideThermo(outsideThermo_pin);
DallasTemperature outsideThermoSensor(&outsideThermo);

// Set up LCD for user interface
int firstLCDLine = 0;
boolean backlightIsOn = true;

//-------------------------------------------------------------------------------------------
//--------------Functions--------------------------------------------------------------------
void turnGasOn() {
  digitalWrite(gasSolenoid_pin, LOW);
  gasIsOn = true;
  gasIsOnText = 'y';
}

void turnGasOff() {
  digitalWrite(gasSolenoid_pin, HIGH);
  gasIsOn = false;
  gasIsOnText = 'n';
}

void blinkLED() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100);
  digitalWrite(LED_BUILTIN, LOW);
  delay(100);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100);
  digitalWrite(LED_BUILTIN, LOW);
}

void writeTempsLine() {
  lcd.print("In:"); lcd.print(insideTemp, 1);
  lcd.print(" Out:"); lcd.print(outsideTemp, 1);
}

void writeSetLine() {
  lcd.print("Set:"); lcd.print(heatSetTemp);
  lcd.print(" Wt:"); lcd.print(freshWaterTemp, 1);
}

void writeGasLine() {
  lcd.print("P:"); lcd.print(pilotTemp, 1);
  lcd.print(" P:"); lcd.print(pilotIsOnText);
  lcd.print(" G:"); lcd.print(gasIsOnText);
}

void toggleBacklight() {
  if (backlightIsOn) {
    lcd.setBacklight(0x0);
    backlightIsOn = false;
  }
  else {
    lcd.setBacklight(0x1);
    backlightIsOn = true;
  }
}

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

  // Set up relay to gas solenoid
  pinMode(gasSolenoid_pin, OUTPUT);
  turnGasOff(); // Set solenoid to closed by default

  // Start DallasTemperature Library
  freshWaterThermoSensor.begin();
  insideThermoSensor.begin();
  outsideThermoSensor.begin();

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  // Indicator LED
  pinMode(LED_BUILTIN, OUTPUT);
}
//-------------------------------------------------------------------------------------------
//--------------Main Program-----------------------------------------------------------------
void loop() {

  // Read Temperatures
  pilotTemp = pilotThermo.readFahrenheit();

  freshWaterThermoSensor.requestTemperatures();
  insideThermoSensor.requestTemperatures();
  outsideThermoSensor.requestTemperatures();
  freshWaterTemp = freshWaterThermoSensor.getTempFByIndex(0);
  insideTemp = insideThermoSensor.getTempFByIndex(0);
  outsideTemp = outsideThermoSensor.getTempFByIndex(0);

  // Check Pilot Light
  pilotIsOn = (pilotTemp > 300); // flame temp goes here in degF
  if (pilotIsOn) { pilotIsOnText = 'y'; }
  else { pilotIsOnText = 'n'; }

  // Actuate Relay
  if (insideTemp < (heatSetTemp - bandwidth)) // Temp too cold, gas not on yet
  {
    if(pilotIsOn) { turnGasOn(); }
    else { turnGasOff(); } // because pilot is off
  }
  else if (gasIsOn && insideTemp < heatSetTemp) // Temp still too cold, but gas already on
  {
    if(pilotIsOn) { //leave gas on
    }
    else { turnGasOff(); } // because pilot is off
  }
  else // Temp is hot enough
  {
    turnGasOff();
  }

  //Check for button presses
  uint8_t buttons = lcd.readButtons();
  if (buttons) {
    if (buttons & BUTTON_UP) {
      Serial.println("button up pressed");
      firstLCDLine++;
    }
    if (buttons & BUTTON_DOWN) {
      Serial.println("button down pressed");
      firstLCDLine--;
    }
    if (buttons & BUTTON_RIGHT) {
      Serial.println("button right pressed");
      heatSetTemp++;
    }
    if (buttons & BUTTON_LEFT) {
      Serial.println("button left pressed");
      heatSetTemp--;
    }
    if (buttons & BUTTON_SELECT) {
       Serial.println("button select pressed!!!");
       toggleBacklight();
    }
  }

  // Output to Serial Monitor
  Serial.println(String("Fresh Water: ") + freshWaterTemp);
  Serial.println(String("Inside: ") + insideTemp);
  Serial.println(String("Outside: ") + outsideTemp);
  Serial.println(String("Pilot: ") + pilotTemp);
  Serial.println(String("Pilot Is On: ") + pilotIsOn);
  Serial.println(String("Gas Is On: ") + gasIsOn);
  Serial.println(String("Heat Set Temp: ") + heatSetTemp);
  Serial.println(String("firstLCDLine: ") + firstLCDLine);
  Serial.println();

  // Output to LCD
  lcd.clear();
  if(firstLCDLine % 3 == 0) {
    lcd.setCursor(0, 0); writeTempsLine();
    lcd.setCursor(0, 1); writeGasLine();
  }
  else if (firstLCDLine % 3 == 1) {
    lcd.setCursor(0, 0); writeGasLine();
    lcd.setCursor(0, 1); writeSetLine();
  }
  else {
    lcd.setCursor(0, 0); writeSetLine();
    lcd.setCursor(0, 1); writeTempsLine();
  }

  // Automatic scrolling
  firstLCDLine++;

  // Indicate "heartbeat" of sketch
  //blinkLED();
}

Try to remove some power consumption, like the relay board.

@MatsK Thanks for the suggestion. I tried disconnecting the relay board, and it still runs exactly the same way. The only other thing I can think of that the LCD (this one from Adafruit) is drawing a lot of power, but it doesn't seem likely.

There is a method to troubleshoot and it's called reduce the circuit to a barebone and then add and see when it fails.


text:
Burn Bootloader to Chinese Arduino 2560 with AVR ISP programmer
I got my hands on one of these ISP programmer for Atmel AVR microcontroller in USB stick design:

Then I selected Progammer > AVR ISP and clicked on Burn Bootloader but it says
stk500_recv(): programmer is not responding.
Has anybody any experience doing this and if so, could they point me in the right direction?
Edit:
I've also added the following to programmers.txt
mySmartUSB.name=mySmartUSB
mySmartUSB.protocol=stk500v2
mySmartUSB.communication=serial
mySmartUSB.program.tool=avrdude
mySmartUSB.program.extra_params=-P{serial.port}

What operating system?

@Majenko windows 8.1 Drivers seem to be fine and this device works with Atmel Studio

Did you select the right com port for the programmer?

@Delta_G sigh, I was had the board port instead of the programmer's port. Can you write it as an answer so I can mark correct and award the bounty

That error is common and usually means you either have the wrong board selected or the wrong port.  Check the tools menu. Be sure you have the port for the programmer and not the port for the board if the board is also connected.

What if you use another Arduino to burn bootloader on your Arduino 2560? Check this(click here) tutorial on my Github page. Maybe this will help.

source: Stack Exchange

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

sort: votes


text:
Arduino Micro + W5500 module from AliExpress
Got this module from Aliexpress

W5500 Ethernet Network Modules For Arduino TCP/IP 51/STM32 SPI Interface 3.3V 5V I/O MCU
... and trying to hook this up to my proto Aduino Micro as thus:
Micro -> W5500 module

5V (J6.6) ->  5V   (I noted that it has a linear regulator to 3V3 on the W5500 board)

IO11 (J5.16) -> RST ... (I connected it to Pin 11 so that I can do a manual reset, to see if it made a difference, it didn't)

IO10 (J5.15-> SCS

SCLK (J6.1) -> SCLK

MISO (J6.2)-> MISO

MOSI (J5.1)-> MOSI

GND (J6.4)-> GND

I then used a modified version of WebServer to test the functioning of the module:
/*
  Web Server

 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 02 Sept 2015
 by Arturo Guadalupi

 */

#include <SPI.h>
#include <Ethernet.h>

int counter = 0;
const int W5500_RESET_PIN = 11;     // the number of the pushbutton pin

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xED, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 2, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Reset the W5500 module
  pinMode(W5500_RESET_PIN, OUTPUT);
  digitalWrite(W5500_RESET_PIN, HIGH);
  digitalWrite(W5500_RESET_PIN, LOW);
  delay(100);
  digitalWrite(W5500_RESET_PIN, HIGH);
  delay(100);

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}

void loop() {

  if (counter > 0) counter--;
  else
  {
    Serial.print("server is at ");
    Serial.println(Ethernet.localIP());
    counter = 10000;
  }

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("
");
          }
          client.println("");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

The code runs ok, and as you can see I'm printing out debug comms and monitoring using TeraTerm on the USB virtual port. However I'm seeing this output:
server is at 222.237.190.239

server is at 222.237.190.239

server is at 222.237.190.239

server is at 222.237.190.239

server is at 222.237.190.239

server is at 222.237.190.239

So ... the IP address didn't take, and needless to say that the webpage didn't show up when I typed in the IP address 192.168.2.177.
I've tried two identical W5500  modules so far and the problem persists for both in a consistent way. I've looked on the scope and I can see the SCLKs shooting across in 4 lots of clock bursts per each SCS low going pulse, with both the MISO and MOSI lines showing what appears to be "data" ... :)
The W5500 module itself has a power LED which is lit, the 5V is correctly regulating down to 3V3 and the 3V3 pin of the W5500 chipset IC appears to be connected. Both the LEDs on the ethernet balun appears to be turned on and blinking some of the times.
So ... erm ... help? ... what am I doing wrong? What else should I check?
2017-10-08 Update:
Tried Ethernet2 library update from github adafruit ethernet2 libary.
But getting compiling errors now:
    Arduino: 1.6.12 (Windows 7), Board: "Arduino/Genuino Micro"
C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Hemon\Documents\Arduino\libraries -fqbn=arduino:avr:micro -vid-pid=0X2341_0X8037 -ide-version=10612 -build-path C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose Z:\Quantum Sensing Limited\Consulting Work\Arduino\WebServer\WebServer.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Hemon\Documents\Arduino\libraries -fqbn=arduino:avr:micro -vid-pid=0X2341_0X8037 -ide-version=10612 -build-path C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose Z:\Quantum Sensing Limited\Consulting Work\Arduino\WebServer\WebServer.ino
Using board 'micro' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
WARNING: Category 'Device' in library ParPrinter is not valid. Setting to 'Uncategorized'
WARNING: Category 'Device' in library Radar is not valid. Setting to 'Uncategorized'
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\sketch\WebServer.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\sketch\WebServer.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\sketch\WebServer.ino.cpp" -o "nul"
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src\SPI.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Dhcp.cpp
Using cached library dependencies for file: C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Dns.cpp
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet2.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\EthernetClient.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\EthernetServer.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\EthernetUdp.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\EthernetUdp2.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Twitter.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\utility\socket.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\utility\w5100.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\utility\w5200.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\utility\w5500.cpp" -o "nul"
Generating function prototypes...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\sketch\WebServer.ino.cpp" -o "C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino10/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\sketch\WebServer.ino.cpp" -o "C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\sketch\WebServer.ino.cpp.o"
Compiling libraries...
Compiling library "SPI"
Using previously compiled file: C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\libraries\SPI\SPI.cpp.o
Compiling library "Ethernet"
Using previously compiled file: C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\libraries\Ethernet\Dhcp.cpp.o
Using previously compiled file: C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\libraries\Ethernet\Dns.cpp.o
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files (x86)\Arduino\libraries\Ethernet\src" "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp" -o "C:\Users\Hemon\AppData\Local\Temp\arduino_build_838983\libraries\Ethernet\Ethernet.cpp.o"
C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp: In member function 'int EthernetClass::begin()':

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp:26:3: error: 'W5500' was not declared in this scope

   W5500.init();

   ^

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp:37:5: error: 'W5100' was not declared in this scope

     W5100.setIPAddress(_dhcp->getLocalIp().raw_address());

     ^

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp: In member function 'void EthernetClass::begin(IPAddress, IPAddress, IPAddress, IPAddress)':

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp:72:3: error: 'W5100' was not declared in this scope

   W5100.init();

   ^

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp: In member function 'int EthernetClass::maintain()':

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp:158:9: error: 'W5100' was not declared in this scope

         W5100.setIPAddress(_dhcp->getLocalIp().raw_address());

         ^

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp: In member function 'IPAddress EthernetClass::localIP()':

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp:174:3: error: 'W5100' was not declared in this scope

   W5100.getIPAddress(ret.raw_address());

   ^

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp: In member function 'IPAddress EthernetClass::subnetMask()':

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp:181:3: error: 'W5100' was not declared in this scope

   W5100.getSubnetMask(ret.raw_address());

   ^

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp: In member function 'IPAddress EthernetClass::gatewayIP()':

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\Ethernet.cpp:188:3: error: 'W5100' was not declared in this scope

   W5100.getGatewayIp(ret.raw_address());

   ^

Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI
Using library Ethernet at version 1.0.4 in folder: C:\Program Files (x86)\Arduino\libraries\Ethernet
exit status 1
Error compiling for board Arduino/Genuino Micro.
Invalid version found: 0.1.03
Invalid version found: 0.1.04
Invalid version found: 0.1.06
Invalid version found: 0.1.04
Invalid version found: 0.1.07
Invalid version found: 0.1.02
Invalid version found: 0.1.09
Invalid version found: 0.1.00
Invalid version found: 0.1.05
Invalid version found: 0.1.01
Invalid version found: 0.1.06
Invalid version found: 0.1.01
Invalid version found: 0.1.04
Invalid version found: 0.1.07
Invalid version found: 0.1.04
Invalid version found: 0.1.03
Invalid version found: 0.1.03
Invalid version found: 1.2.03
Invalid version found: 0.1.03
Invalid version found: 0.1.08
Invalid version found: 0.1.04
Invalid version found: 0.1.05
Invalid version found: 0.1.05
Invalid version found: 0.1.00
Invalid version found: 0.1.00
Invalid version found: 0.1.00
Invalid version found: 0.1.00
Invalid version found: 0.1.00
Invalid version found: 0.1.01
Invalid version found: 0.1.09
Invalid version found: 0.1.03
Invalid version found: 0.1.00
Invalid version found: 0.1.00
Invalid version found: 0.1.06
Invalid version found: 0.1.03
Invalid version found: 0.1.04
Invalid version found: 0.1.06
Invalid version found: 0.1.04
Invalid version found: 0.1.07
Invalid version found: 0.1.02
Invalid version found: 0.1.09
Invalid version found: 0.1.00
Invalid version found: 0.1.05
Invalid version found: 0.1.01
Invalid version found: 0.1.06
Invalid version found: 0.1.01
Invalid version found: 0.1.04
Invalid version found: 0.1.07
Invalid version found: 0.1.04
Invalid version found: 0.1.03
Invalid version found: 0.1.03
Invalid version found: 1.2.03
Invalid version found: 0.1.03
Invalid version found: 0.1.08
Invalid version found: 0.1.04
Invalid version found: 0.1.05
Invalid version found: 0.1.05
Invalid version found: 0.1.00
Invalid version found: 0.1.00
Invalid version found: 0.1.00
Invalid version found: 0.1.00
Invalid version found: 0.1.00
Invalid version found: 0.1.01
Invalid version found: 0.1.09
Invalid version found: 0.1.03
Invalid version found: 0.1.00
Invalid version found: 0.1.00
Invalid version found: 0.1.06

Any ideas?

BTW ... I was following this instructable, http://www.instructables.com/id/Arduino-Nano-with-WIZ550io-Easy-Internet/ ... and I did update the wiznet library as it suggests.

The sharp eyed observers would notice that 222.237.190.239 is 0xDEEDBEEF ... which is part of the Mac. So I'm rather confused here.

original Arduino shield with W5500 needs the Ethernet2 library. try it

Thanks Juraj ... but i'm getting compiling errors now, I've updated the original post above.

Note that even the stock WebServer example in Ethernet2 folder doesn't compile correctly. I've restarted Arduino IDE with no luck.

Solved it ... needed to create a new Ethernet2 folder and copy the Ethernet2 library files into it, and now it works great! The Ethernet2 library is a stand alone and different library to the Ethernet one.

For the W5500 chip use the Ethernet2 library. It can be can be found and installed in Library Manager in Arduino IDE.
UPDATE 2018: The Arduino Ethernet library version 2.00 now supports W5200 and W5500.

Change the MISO & MOSI Signal between Micro & W5500 module, now it works with both Etherenet2 & Ethernet Libs. btw Ethernet2 is better see ram.

2 years ago when the Question was asked Erhernet library didn't support W5500. and why should OP change the MISO & MOSI and how?

beside any other coding and library issues: IP Groups are seperated by DOT not comma! If lucky, the interpreter ist Syntax-tollerant. Your Observation for the IP xx.xx.xx.139 could be the indication of the software trying to solve the issue semi-effectively.

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

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


text:
Servo motors suddely stopped moving and a clicking sound can be heard
I think I might have shorted something by accident. I have just purchased the Elegoo Robot Car Kit v2.0. Putting things together was relatively easy. I also managed to run the first example, which basically turns on and off the servos indefinitely for short periods of time making the small robot drive in one direction forwards, then go backwards, spin a little to pick another direction and repeat.
The second thing I wanted to test was the IR remote control. For some reason the LED that is part of the small board where the IR diode is placed didn't blink at all whenever I was pressing a button on the remote control. The car also didn't move even the slightest.
So it was time to get the multimeter out and test what goes on. The problem is that the thing is very small and I accidentally rubbed one lead into the other while having current flowing. The result - everything shutdown...slowly.
Needless to say I got scared that the board (Elegoo's version of the Arduino UNO R3) died. However it seems that's not the case since upon turning it off (I tried both the USB as well as the batteries as a power source) the ON LED turned on and the other LED that is supposed to be blinking is blinking. The sensor board (it allows connecting IR, Bluetooth, the ultrasonic sensor etc. to the Arduino board) also has it's red LED turned on.
However using the same example program now my robot is not moving at all. Instead I can hear at least from on of the motors a clicking sound and also tiny vibration which (it seems) is caused by the motor where the sound comes from and is the result of it attempting to move the wheel attached to it.
I checked the power connector of the servo control board (an H-bridge for 4 servos - one per wheel; uses the L298N) and when I turn on the batteries I get approx. 8.2V which is what I'm expecting to get (two rechargeable Li-Ion batteries BRC 18650 4200mAh, 3.7V each - why I get the higher reading is beyond me). So it's not that the board doesn't get the power. Something else is causing the issue and because of my lack of knowledge I am stuck wondering what has happened.
PS: The IR tranceiver seems to work or at least the LED attached to it blinks now whenever I press a button on the remote control. XD
EDIT: Small update. Sometimes the servos do work. After the n-th time turning the thing on and off all of a sudden all the wheels started moving. But then they stopped again.

You have added few facts, data, schema and other info so it's hard to guess what you have. So a general answer would be, you have blow'n someting when you shorten it.

It's really difficult to provide those. The kit's documentation is basically pictures and a little bit of text but nothing fancy like data sheets or schema.

Then it's rely hard to assist you.

I've also just experienced the strangest thing - the servos started moving for a short period of time but then stopped again.

That's OK that the kit's documentation is short.  We don't want to see the instructions you followed.  If you had it just like that it would work.  We want to see what you actually have.  Grab a piece of paper and a pen and draw a schematic of how you have it wired.  Include your code int he question.  Can you not imagine how impossible it is to help you when we can't see the project?

Will do my best. Meanwhile I'll try to exclude as many of the pieces involved as possible to narrow down that spot where the problem is.


text:
Wiring when burning the bootloader of esp8266
I want to burn the bootloader of esp8266. Assume I have esp8266 on esp12 in hand and an USB ISP programmer (or any other programmer like USBTinyISP).
I (think I) know how to use the Arduino IDE to burn the bootloader (mainly it's by selecting board and the programmer), but how to wire the esp8266? Precisely I mean, "do I use the pins 12, 13, 14, and 15 as these are for SPI connection"?
Edit: I have seen Arduino microcontroller board of which the bootloader was burned, so I was wondering why not do the same for esp8266.

In your previous question on EESE https://electronics.stackexchange.com/questions/334758/can-we-use-nodemcu-to-program-another-esp8266-wifi-module it was already explained to you that the esp8266 serial bootloader is there from the factory.  There is nothing to burn.  And if you're only going to ignore the responses you get, there is also no reason to continue posting in the SE system.

Why, after it has been explained to you four times by two different people that the idea does not apply do you persist with your edit in continuing to wonder about this?

@ChrisStratton Your response here is more beneficial as the question is more basic. This enriches the database of Stack Exchange. There, the question was more complex.

and it's not wrong to listen to other answers from other people. With all respect.

@LookAlterno providing more info is always welcomed to clarify things.

The ESP8266 already has a bootloader to upload new firmware over UART. You don't need to burn anything, and you don't use SPI to program it.
AVR microcontrollers are programmed (aka flashed, or uploaded) using ISP (in-system programming) over SPI. They don't support programming over UART out of the box. To receive new firmware over the serial port, a bootloader is used. It is a piece of software that receives data from the UART and writes it to flash, overwriting the previous firmware.
Before you can do this, you need to write (aka burn) the bootloader firmware to the microcontroller. This can only be done using ISP, because

if the chip is blank, there is no bootloader to receive the bootloader over UART
if there is a previous bootloader that you want to replace, you can't rely on the bootloader for programming over UART either, because the bootloader would be overwriting itself.

The situation on an ESP8266 is completely different. Whereas on an AVR, ISP is the default method to flash new firmware, on the ESP8266, it is UART flashing.
The ESP8266 already has a system built-in for UART flashing (just like an AVR has a system for ISP flashing), so you don't need to flash a software UART bootloader.
There is no ISP system inside of the ESP8266, so trying to do ISP on the HSPI port won't flash anything.
Read this: A Beginner's Guide to the ESP8266

do you mean that USB ISP and other programmers are of no use to esp8266 as they are for Arduino boards?

@YoussefDir Yes, you need a USB-to-Serial converter, please read the link provided in my answer.


text:
Memory leakage caused by String Concatenation
In this link, section "Memory, memory, memory" it's been told that doing many String concatenations in sequence, e.g.: using operator+() multiple times, will cause memory fragmentation, which may lead to the fact that total heap not being totally used.
An alternative I'm suggesting is using strcat() with char buffers and not using Strings at all, and then convert from resultant char buffer to String if a String is needed at the end?
Would that be an escape from fragmentation of the heap?
Clarification: I will specify the upper bound of the char buffer beforehand, as if I know the maximum needed/to-be-used size.

Useful read: The Evils of Arduino Strings

If you size the buffer to be able to hold your final string, then yes, that method will avoid the fragmentation caused by the String concatenation function.
Note that String holds the string as a C-style char array internally; it is the concatenation procedure which dynamically allocates and deallocates memory, causing the fragmentation.

I wonder, if simply by allocating and deallocating then memory is fragmented, a char buffer then causes fragmentation! (I mean since I will be freeing it) But since the allocated size is fit to requirements then it's still a lot better than String concatenation. Agree?

What the String object does is allocate a new piece of memory large enough to contain the resulting concatenated data, copies both source strings to the new memory, and then deallocates the old memory (of the first String). This means there is a free bit of memory that is now smaller than any subsequent needs for future concatenation of the string in question, so that bit of free memory could be used again by some other function, but it won't be used again by the String being concatenated onto.

I think that the the standard C string manipulators are better for small micros than the String object, though they are more complicated to use. Both methods work in many cases, but you must be aware of how they work so you can understand when debugging problems.

Your method would reduce the fragmentation. But will your application need do this once? A few times? Must it run forever? If your application uses malloc()/free() or new/delete pairs often, it will fragment the heap, causing it to grow, and eventually cause a stack collision. This is not so much about the Arduino being a resource-limited device; it will eventually happen in any continuously running device with a fixed amount of memory.
If you can set an upper bound to the buffer requirements, then pre-allocating a buffer-pool globally, locally as a file-level- or local-static, or on the heap (using malloc() [1]) - an array of "big-enough" buffers and enough of them for your application. Then always allocate/de-allocate one of these and you will avoid fragmentation. Your application (or buffer-handler library) will have to keep track of which buffers are free and which are in use, just as the system allocators do. But in exchange for writing this way, you get to allocate and deallocate memory, forever, fragmentation-free. Every request, and every return is the same size, so any free piece can fill a request with no need to grow the pool.
My personal preference is a static allocation (file-level or globally visible) because 1) it comes from lower memory which has the same effect as allocating it on the heap, and 2) it is declared as an array of arrays so array-indexing syntax works without manually having to write around it as you might if you malloc()ed on big chunk.
Note[1]: Though I have cautioned against using malloc() and free() calls, here and elsewhere on the site, the cause of fragmentation is repeated allocation and de-allocation from/to the heap. In this case, though, I'm suggesting using malloc() to allocate memory which will be kept for the rest of the program run.

When setting an upper-bound e.g. char buff[ 100 ], am I not allocating it on the stack? I want to use the heap instead. Because the stack in esp8266 I'm working on is only 4KB if I'm not mistaken.

I was not clear that the buffer pool needs to be allocated made statically - that is, as a global, a static, or from the heap (with malloc()). I've updated my answer to clarify that.

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


text:
Arduino Uno, ESP8266 HTTP request have no response
Firmware version
AT+GMR

AT version:0.21.0.0
SDK version:0.9.5

OK

Connection
ESP8266(ESP-01) <> Arduino Uno
GND  <> GND
3V3 <> 3.3V
EN(CH_PD) <> 3.3V
TX  <> D2
RX <>  D3

ps) I know I must not connect RX directly to Arduino's D3.
When I level down ESP8266's RX 5V to 3.3V, ESP8266 didn't work.
But when directly, It works well.
I supply power to Arduino Uno and ESP8266 by usb from PC.
Arduino Code
    #include <SoftwareSerial.h>
    #include <ESP8266.h>        //다운 후 libraries폴더에 저장한 라이브러리

    SoftwareSerial esp8266Serial = SoftwareSerial(2, 3);
    ESP8266 wifi = ESP8266(esp8266Serial);

    #define SSID "MYSSID"
    #define PWD "MYPWD"

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

      wifi.begin();
      wifi.setTimeout(1000);

      // test
      Serial.print("test: ");
      Serial.println(getStatus(wifi.test()));

      // restart
      Serial.print("restart: ");
      Serial.println(getStatus(wifi.restart()));
      Serial.print("quitAP: ");
      Serial.println(getStatus(wifi.quitAP()));

      // joinAP
      Serial.print("joinAP: ");
      Serial.println(getStatus(wifi.joinAP(SSID, PWD)));

      // getAP
      Serial.print("getAP: ");
      Serial.println(getStatus(wifi.getAP(SSID)));

      // getIP
      Serial.print("getIP: ");
      IPAddress ip;
      Serial.println(getStatus(wifi.getIP(ESP8266_WIFI_STATION, ip)));
      Serial.print("IP: ");
      Serial.println(ip);

      // connect with webserver

      Serial.print("connect: ");
      Serial.println(getStatus(wifi.connect(ESP8266_PROTOCOL_TCP, IPAddress(192, 168, 0, 52), 3000)));
      getConnectionStatue(wifi);

      // send to webserver
      Serial.print("send: ");

      Serial.println(getStatus(wifi.send("GET /?id=arduino HTTP/1.0\r\nHost: http://192.168.0.52:3000\r\n\r\n")));
    }

    void loop()
    {
      // read data
      unsigned int id;
      int length;
      int totalRead;
      char buffer[11] = {};
      if ((length = wifi.available()) > 0) {
        id = wifi.getId();
        totalRead = wifi.read(buffer, 1000);
        if (length > 0) {
          Serial.println((char*)buffer);
        }
      }
    }

    void getConnectionStatue(ESP8266 wifi) {
      // getConnectionStatus
      ESP8266ConnectionStatus connectionStatus;
      ESP8266Connection connections[5];
      unsigned int connectionCount;
      Serial.print("getConnectionStatus: ");
      Serial.print(getStatus(wifi.getConnectionStatus(connectionStatus,                                         connections, connectionCount)));
      Serial.print(" : ");
      Serial.println(connectionCount);
      for (int i = 0; i < connectionCount; i++) {
        Serial.print(" - Connection: ");
        Serial.print(connections[i].id);
        Serial.print(" - ");
        Serial.print(getProtocol(connections[i].protocol));
        Serial.print(" - ");
        Serial.print(connections[i].ip);
        Serial.print(":");
        Serial.print(connections[i].port);
        Serial.print(" - ");
        Serial.println(getRole(connections[i].role));
      }
    }

    String getStatus(bool status)
    {
      if (status)
        return "OK";

      return "KO";
    }

    String getStatus(ESP8266CommandStatus status)
    {
      switch (status) {
        case ESP8266_COMMAND_INVALID:
          return "INVALID";
          break;

        case ESP8266_COMMAND_TIMEOUT:
          return "TIMEOUT";
          break;

        case ESP8266_COMMAND_OK:
          return "OK";
          break;

        case ESP8266_COMMAND_NO_CHANGE:
          return "NO CHANGE";
          break;

        case ESP8266_COMMAND_ERROR:
          return "ERROR";
          break;

        case ESP8266_COMMAND_NO_LINK:
          return "NO LINK";
          break;

        case ESP8266_COMMAND_TOO_LONG:
          return "TOO LONG";
          break;

        case ESP8266_COMMAND_FAIL:
          return "FAIL";
          break;

        default:
          return "UNKNOWN COMMAND STATUS";
          break;
      }
    }

    String getRole(ESP8266Role role)
    {
      switch (role) {
        case ESP8266_ROLE_CLIENT:
          return "CLIENT";
          break;

        case ESP8266_ROLE_SERVER:
          return "SERVER";
          break;

        default:
          return "UNKNOWN ROLE";
          break;
      }
    }

    String getProtocol(ESP8266Protocol protocol)
    {
      switch (protocol) {
        case ESP8266_PROTOCOL_TCP:
          return "TCP";
          break;

        case ESP8266_PROTOCOL_UDP:
          return "UDP";
          break;

        default:
          return "UNKNOWN PROTOCOL";
          break;
      }
    }

Response
    test: OK
    restart: OK
    quitAP: OK
    joinAP: TIMEOUT
    getAP: OK
    getIP: OK
    IP: 192.168.0.55
    connect: OK
    getConnectionStatus: OK : 1
     - Connection: 0 - TCP - 192.168.0.52:3000 - CLIENT
    send: OK

There is no response
On server, the request ESP8266 sent didn't come.
I have no Idea...........
Addition
I send AT commands directly to ESP8266 by Arduino IDE
connection
ESP8266(ESP-01) <> Arduino Uno
GND  <> GND
3V3 <> 3.3V
EN(CH_PD) <> 3.3V
TX  <> TX
RX <>  TX

response
AT

OK
AT+CIPSTART="TCP","192.168.0.52",3000

CONNECT

OK
AT+CIPSEND=74

OK
> GET /?id=arduino HTTP/1.0\r\nHost:http://192.168.0.52:3000\r\n\r\n

busy s...

SEND OK
CLOSED

AT+CIPSTART="TCP","192.168.0.52",3000

CONNECT

OK
AT+CIPSEND=39

OK
> GET http://192.168.0.52/id?=arduino\r\n\r\nbusy s...

SEND OK
CLOSED

AT+CIPSTART="TCP","192.168.0.52",3000

CONNECT

OK
AT+CIPSEND=39

OK
> GET http://192.168.0.52/id?=arduino\r\n\r\n
busy s...

SEND OK

Sometime connection CLOSED after sending the request, sometime connection alive.

the 3.3 V pin on Arduino can't supply enough power to esp for wifi transmission

@Juraj then How can I supply power to esp? Connecting another 3.3V to ESP8266 will be enough?

sorry I don't know. I bought an esp on a 5 V adapter board with level shifters and the 5 V pin on Uno can supply the required power


text:
Can I control a cellphone's lcd (+touch screen)?
I had an Xperia txt pro just laying around and tried to revive it. I burned it like an idiot using 5v in the battery pins by accident :/
So I decided to read it apart and got to the lcd, can I use my Arduino Mega to control it? Bc I have no idea how to use it.
These are the pins

No. For two reasons:

You will struggle to find the pinout of the TFT (or even identify the model). It will have most likely been custom made for the phone.
The Arduino doesn't have a GPU to drive it. Arduinos need a TFT with built in GPU since they lack the resources to drive one directly.


text:
Pro Micro HID freezes during computer boot or resume from standby
I am using a Pro Micro as a HID touchpad, connected to a laptop running Ubuntu 17.04. Everything works, except that the board freezes or hangs while the computer boots or resumes from standby, requiring me to disconnect and reconnect it every time.
The board is definitely hanging, not resetting; I have programmed the on-board LEDs to flash in sequence during the setup and loop stages and have determined that the board hangs at random points in the program and does not reset. This suggests to me that the problem lies with the computer or the connection rather than the Arduino.
The hangs occur at specific points during the computer's boot sequence. If I boot with the Arduino connected, it will hang very early in the boot while the manufacturer's logo is visible on screen. If I connect the board at GRUB, the board will hang during Ubuntu's boot sequence, somewhere among the commands to initialize hard disk buses. Less predictably, the board will hang about 75% of the time just after logging in or when resuming from standby (just before the login manager appears).
I wonder whether the power supply may be dropping by some amount sufficient to halt execution, but not enough to reset the board, but I don't know if that's a realistic hypothesis. I don't know how to investigate further.
What could be causing this issue? What steps could be taken to determine and solve the problem?
Edit - February 2018
I have updated my operating system to Ubuntu 17.10, which uses GNOME Display Manager for the login prompt instead of LightDM, and the problem no longer occurs when resuming from suspend. So it appears the communication that froze the Arduino was triggered by LightDM, not the BIOS.

Does it always happen at the same time during boot? I.e., is it during the BIOS probing of the USB devices, or during the OS kernel boot sequence, etc?

@Majenko, I've added the information you requested in the 3rd paragraph.

It sounds like it's trying to put the board into boot keyboard mode and failing. There may be a bug in the Arduino USB stack.

OK. Do you know of any way to debug that? Given that the computer is booting and the Arduino ends up hanging, I'm not sure how I could capture the communication packets.

I would resort to using my TotalPhase Beagle 480, but that's out of the question for you. I can try and replicate it some time, but I don't have much time right now.


text:
Arduino Micro vs. Pro Micro
What are the differences between the Arduino Micro and Pro Micro?

Looking at their schematics, the pro micro is a bit smaller (with less available pins) and can come in 5V or 3.3V variants, while the micro is bigger (with some more pins) and only 5V. Apart from this, the micro is the same, and I guess also the bootloader, so from a software point of view they are the same

@LookAlterno The proposed dupe is about Pro Mini and Pro Micro which use a different chip, but this question is about Micro and Pro Micro which use the same chip.

I actually think you are meaning what is the difference between the Arduino Mini and the Arduino Pro Mini, since there is no such board as the Arduino Pro Micro. However there is a board called the Arduino Micro and also the Sparkfun Pro Micro, so this answer will look at all four.
Arduino Mini

Arduino Pro Mini

Arduino Micro

(Sparkfun) Pro Micro

Microcontroller
Arduino Mini: ATmega328
Arduino Pro Mini: ATmega328 (ATmega168 on older boards)
Arduino Micro: ATmega32U4
Pro Micro: ATmega32U4
Memory
All four have 32KB of Flash and 1KB of EEPROM
Both Minis have 2KB of SRAM where as both Micro boards have 2.5KB
Digital I/O
Both Minis have 14 (of which 6 provide PWM output)
The Arduino Micro has 14 also (of which 7 provide PWM output)
Some of the analog pins can also be used as digital I/O
The Pro Micro has 12 (5 PWM pins)
Analog Inputs
Arduino Mini/Pro Mini: 8 (some boards only break out 6 analog inputs)
Arduino Micro: 12 (6 dedicated and 6 from digital I/O pins)
Pro Micro: 9 channels of 10-bit ADC
USB
Arduino Mini/Pro Mini: Requires FTDI cable or Sparkfun breakout board to provide USB power and communication to the board.
Arduino Micro / Pro Micro: Native USB
Clock
All 16 MHz
(Some 3V3 variants run at 8MHz)
Power
Arduino Mini: 7-9 V
Arduino Pro Mini: There are two version of the Pro Mini. One runs at 3.3V and 8 MHz, the other at 5V and 16 MHz. VRAW  can accept voltage up to 12VDC.
Arduino Micro: USB or external supply of 6 to 20 volts (recommended range is 7 to 12 volts)
Pro Micro: can accept voltage up to 12VDC
Interrupts
Arduino Pro Mini: The Atmega328 has 2 hardware interrupts available
Arduino Micro / Pro Micro: The ATMega32u4 has 5 hardware interrupts available
credit: Enric Blanco

You're correct there is no board (legitimately) named "Arduino Pro Micro" but the question was not about "Arduino Pro Micro", it was about "Pro Micro" which certainly does exist and is a very nice board. You can see the original here: https://www.sparkfun.com/products/12640. Also, the clones (with blue solder mask) are available from all the usual places and may be advertised as "Arduino Pro Micro" some places, though they do not have permission from Arduino to use their tradmark.

Most of my answer is still relevant. I will update my answer shortly.

Maybe you could compare Arduino Leonardo too since it uses the same chip that Arduino Micro and Sparkfun's Pro Micro.

sa_leinad gave a detailed answer.
a simplified version would be on the chips used: 328 vs. 32u4.
the 32u4 is a superb chip if you are into mixed signal mcu. the ability to put a programmable gain and differential analog input into the adc module at such a low price point is simply superb.
unfortunately, not many boards route out AIN0/AIN1 pins.


text:
Serial uart communication issues
I know this isnt specific but could you suggest some causes for the following issue:
Mega2560 sends values to Raspi 3 and Raspi 3 receives prints them accordingly (arduino also prints out the values it sends). However, at every occasional instances, garbage data is printed on Raspi terminal while the right data is still printed on the serial monitor for Arduino for a baudrate of 115200 for both.
Any helpful suggestions would be appreciated

Code? Wiring? ... ?

I often have this issue with my data-loggers.  They use Nano or Uno to send readings to the Pi3 Python programs.   My Arduinos send data every 60 seconds.  Then the Pi adds a date and time stamp and appends it to the day's data file
Invariably, in my case, it happens that I might get some garbage as I start the program, and then it runs fine after that.  I solved the garbage part by flushing the input buffer.  Then I also make sure my data is of the expected length, which depends on how many variables it is sending.
Once I applied a little Python Fu the issue has ceased to be a problem.
Here is a generic representation of my solution:
import serial
ser = serial.Serial("/dev/ttyUSB0",9600)
ser.flushinput()
while True :
    linein = ser(readlin)
    if len(linein<10) : continue
    if len(linein>50) : continue
    PROCESS THE INPUT

This answer will also be not so specific, but you can try:

Check all wiring (use a multimeter/analyzer)
Reduce the data rate
Find out if there is a pattern whenever garbage is created (depending on values?)
Check (if possible) for errors (overrun/parity)
Play with the parity setting/stop bits to see if it makes a difference


text:
Arduino IDE not compile .S program to board
After answering my previous question correctly I'm getting all sorts of errors when trying to compile the following program:
I'm completely new to both assembly and the arduino IDE so I apologise in advance for any basic errors.
sketch.ino:
#include "blink.S"
extern void blink();
void setup() {
  // put your setup code here, to run once:
blink();
}

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

}

blink.S file:
#define __SFR_OFFSET 0
#include <avr/io.h>

  .section .text

  ldi r18, 0x20   ; loading 0x20 = 00100000 into register r18
  out DDRB, r18   ; making pin 5 of port B an output

  mov r16, r18    ; copy mask 00100000 also to r16

loop: out PORTB, r16    ; switch on or off the pins of port B
        ; according to bit pattern in r16

  ldi r17, 82   ; 1000ms delay, see below

outer_delay:
  clr r1
middle_delay:
  clr r2
inner_delay:
  dec r2      ; 1 clock tick
  brne inner_delay  ; 2 clock ticks when z!=0, 1 tick when z=0.

  dec r1      ; when this line is reached, about
        ; 256*3 = 768 ticks have been consumed since inner_delay.
  brne middle_delay ;

  dec r17                 ; when this line is reached, about
        ; 256*256*3 = 196608 ticks have been
        ; consumed since middle delay.
  brne outer_delay

  eor r16,r18   ; invert bit 5 in r16 using exclusive or.
  rjmp loop   ; jump back to loop.

Try just removing #include "blink.S".

blink.s is the source of your pain, and removing it will make a big difference, but if you need the assembler then there is normally some sort of keyword to mark the start and end of the assembler and I suspect you .s file might need there IF you need the .s file.  I have no idea of what it is, its a long time since I did ASM and then it was on a PC.

A couple of things you can try.
First, make sure your assembly code makes the blink() function visible
to the linker. blink.S should start like this:
#define __SFR_OFFSET 0
#include <avr/io.h>

.section .text
.global blink
blink:
  ; Your assembly code goes below the above label.

Next, your sketch file should not try to include the assembly source. It
should only reference it as an external symbol. And note that the symbol
should be declared extern "C".
If your program is a mix of assembly and Arduino code, you could start
with this sketch.ino:
extern "C" void blink();

void setup() {
    blink();
}

void loop() {}

If you are not using the Arduino core library, you could instead write:
extern "C" void blink();

int main(void)
{
    blink();
    return 0;
}

And if you don't want to use C++ at all, you could try to use a dummy or
empty sketch.ino, and rename “blink” to “main” in blink.S.

There's four things I can see wrong (one of which is my fault, actually - I should have mentioned it in the previous question - nevermind).
Firstly you cannot include a .S file in a .INO file. A .S file is assembly, a .INO file is C++. You can't mix the two in one file (and including a file does just that - includes the file verbatim at that point). So remove that #include. Otherwise it would be like opening a book written in English only to find the preface is written in Klingon.
Secondly you need to give your function a name. It doesn't have one at the moment. Naming the file is not naming the function.
So you need to provide a label at the entry point:
  .section .text

blink:    ; << This is the name of the function
  ldi r18, 0x20   ; loading 0x20 = 00100000 into register r18
  out DDRB, r18   ; making pin 5 of port B an output

Third you need to export that name as a global symbol:
  .section .text
  .global blink ; << This exports the function name

blink:    ; << This is the name of the function
  ldi r18, 0x20   ; loading 0x20 = 00100000 into register r18
  out DDRB, r18   ; making pin 5 of port B an output

And finally you have the problem of linkage name munging.  You're linking a C++ file with (ostensibly) a C file - and C++ munges names. So you have to tell your C++ file that the function is not a C++ function, but a C function (which is what I should have mentioned previously):
extern "C" void blink(); // << Add the "C" to tell it not to munge the name

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

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


text:
How to flash pre-compiled bin files into NodeMCU using Ardunio IDE
How to flash pre-compiled binary into NodeMCU using Ardunio IDE. Since every time it require to compile and flash it. Is there way to flash binary alone to nodeMCU via Arduino IDE ?
One can export binary file from IDE -> Sketch -> Export Compiled Binary. Binary will be copied into working directory. U can check the path Sketchbook location in File -> Preferences. But how to flash binary alone to nodeMCU.
I have fashed using esptool.py from linux. But is there a way to flash from IDE for handy ?

I'm viewing from my phone right now, so can't really add a decent answer. Take a look at this guide and see if it helps.

You can't flash precompiled binary with Arduino IDE, you have to use esptool.py from the command line.


text:
Non intrusive current sensor with unreliable (strange) readings
I have a project where I will mount 6 non intrusive current sensor model SCT013 (100A/50mA) manufactured by yhdc.com on an Arduino Mega.
Virtual ground and Burden resistors are 1% tolerance.
To start testing I mounted 2 sensors using the principles of connection found at (http://www.homautomation.org/2013/09/17/current-monitoring-with-non-invasive-sensor-and-arduino/). Code below.
#include "EmonLib.h"                   // Include Emon Library
EnergyMonitor emon0;                   // Create an instance
EnergyMonitor emon1;                   // Create an instance

int Calib = 60;

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

  emon0.current(A0, Calib);             // Current: input pin, calibration.
  emon1.current(A1, Calib);             // Current: input pin, calibration.

   }

   void loop(){

double Irms0 = emon0.calcIrms(1480);
double Irms1 = emon1.calcIrms(1480);

Serial.print("Sensor0: ");
Serial.print(Irms0);
Serial.print(" Amps ");

Serial.print("Sensor1: ");
Serial.print(Irms1);
Serial.println(" Amps ");

}
//------------end------------

The code I found is for UNO and a single sensor and I just added a second, it works fine and sensors do independent readings well.
Both sensors are mounted on the same test live wire so I have to get more or less the same readings most of the times and it is precisely the case with readings floating between sensors on the order of 100s of miliamps.
My problems are:

Even with no load I get, on both sensors, a reading that varies from 270 to 320mA
When I connect a hair dryer that consumes in one mode 10A and in
another mode 5A the readings are a lot closer to the expected (I am
also checking with a clamp meter)

The problem seems to be the no load condition and the imprecise readings at low currents.
I could exclude readings under a certain value on my code to solve the no load problem but them I would be ignoring real electrical measurement situations.

Paulo, to avoid confusion please edit the information in your comment into the question body.  Click 'edit' in the "share edit close flag" group and change the question.  Also please note that "a reading that rovers around 30mA" does not make sense in English.  Do you mean that it hovers near 30mA, ie, stays near 30mA?  Or do you mean that it roves, that is, moves at random, near 30mA?  If so, say what the high and low readings are.  Also show your ADC setup() code and the ADC reading code and say if you used shielding or shielded wire, etc

Every time you use a real clamp meter, you should zero it out before measuring.
The hall effect sensors you describe are the same way. There's magnetic pull from the earth and other sources that need to be corrected for. When you draw 5 or 10 amps, that noise is masked out. They are likely still apart roughly the same # of ma as the baseline reading.
Once you subtract the no-load load from each, maybe on startup, you should get a lot better readings in terms of accuracy and precision.

Hi, I would like to understand where this imprecision comes from. Even with the sensor plug disconnected I get these 270 to 320mA readings. And these values are entirely dependent on the value I put on the variable Calib. The problem seems to start at the Arduino A0 pin inwards. What If I use an external AD converter? Thanks

offsets are common and needed. if you're sensor can read 10A, then each ADC level is ~40ma, and ACDs tend to bounce a few levels each each reading, sometimes more, particularly built-in ones. smoothing caps and an external ADC would help precision, but you still need to calibrate for accuracy.


text:
Why SSD1306 OLED display get scrambled text when printing messages from separate tasks in RTOS? (revised)
ESP32 with RTOS, test app with 2 independent tasks. Each prints a message to OLED display.
Why text gets frequently scrambled? Mutex have been used to share display resource.

#define DEBUG_ESP              //comment out to deactivate debug console verbose
#ifdef DEBUG_ESP
  #define pDBGln(x) Serial.println(x)
  #define pDBG(x)   Serial.print(x)
#else
  #define pDBG(...)
  #define pDBGln(...)
#endif

//create handle for the mutex. It will be used to reference mutex
SemaphoreHandle_t  xMutex;

//*********************************SSD1306 OLED Display
#define I2C_SDA              14
#define I2C_SCL              15
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//*****************************************************

void setup() {

  // create mutex and assign it a already create handler
  xMutex = xSemaphoreCreateMutex();

  Wire.begin(I2C_SDA,I2C_SCL);
  Serial.begin(115200);

   // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    pDBGln("SSD1306 allocation failed - Halt");
    for(;;); // Don't proceed, loop forever
  }else{
    // Show initial display buffer contents on the screen --
    // the library initializes this with an Adafruit splash screen.
    display.setTextSize(1);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 0);
    display.clearDisplay();
  }

    xTaskCreatePinnedToCore(
        task01,             /* Function to implement the task */
        "task01",           /* Name of the task */
        10000,              /* Stack size in words */
        NULL,               /* Task input parameter */
        1,                  /* Priority of the task */
        NULL,               /* Task handle. */
        0);                 /* Core where the task should run */

    xTaskCreatePinnedToCore(
        task02,             /* Function to implement the task */
        "task02",           /* Name of the task */
        10000,              /* Stack size in words */
        NULL,               /* Task input parameter */
        1,                  /* Priority of the task */
        NULL,               /* Task handle. */
        1);                 /* Core where the task should run */
}

void loop() {}

void task01( void * parameter ){
  while(1){
    printToDisplay("Task01..............");
    vTaskDelay(1500);
  }
}

void task02( void * parameter ){
  while(1){
    printToDisplay("Task02..............");
    vTaskDelay(2500);
  }
}

void printToDisplay(String text){
  bool myMutex;
  while(1){
    // take mutex
    myMutex = xSemaphoreTake(xMutex, portMAX_DELAY);
    if(myMutex){
      static byte   lineCounter = 0;
      static String displayText[8];
      if(lineCounter>7){
        for(int i=0;i<7;i++){
          displayText[i] = displayText[i+1];
        }
        displayText[7] = text;
        display.clearDisplay();
        display.setCursor(0, 0);
        for(int i=0;i<8;i++){
          display.println(displayText[i]);
        }
      }else{
        displayText[lineCounter] = text;
        display.println(displayText[lineCounter]);
        if(lineCounter<8){lineCounter++;}
      }
      display.display();

      // release mutex
      xSemaphoreGive(xMutex);
      break;
    }
  }
}

The code below uses no RTOS and works perfectly: (my project requires RTOS)
#define DEBUG_ESP              //comment out to deactivate debug console verbose
#ifdef DEBUG_ESP
  #define pDBGln(x) Serial.println(x)
  #define pDBG(x)   Serial.print(x)
#else
  #define pDBG(...)
  #define pDBGln(...)
#endif

byte lineCounter = 0;

//*********************************SSD1306 OLED Display
#define I2C_SDA              14
#define I2C_SCL              15
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//*****************************************************

void setup() {

  Wire.begin(I2C_SDA,I2C_SCL);
  Serial.begin(115200);

   // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    pDBGln("SSD1306 allocation failed - Halt");
    for(;;); // Don't proceed, loop forever
  }else{
    // Show initial display buffer contents on the screen --
    // the library initializes this with an Adafruit splash screen.
    display.setTextSize(1);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 0);
    display.clearDisplay();
  }
}

void loop() {
  pDBGln("Start Display Test...");
  task01();
  task02();
}

void task01(){
  printToDisplay("Task01..............");
  delay(500);
}

void task02(){
  printToDisplay("Task02..............");
  delay(500);
}

void printToDisplay(String text){
  static byte   lineCounter = 0;
  static String displayText[8];
  if(lineCounter>7){
    for(int i=0;i<7;i++){
      displayText[i] = displayText[i+1];
    }
    displayText[7] = text;
    display.clearDisplay();
    display.setCursor(0, 0);
    for(int i=0;i<8;i++){
      display.println(displayText[i]);
    }
  }else{
    displayText[lineCounter] = text;
    display.println(displayText[lineCounter]);
    if(lineCounter<8){lineCounter++;}
  }
  display.display();
}

At first glance that all looks fine. Maybe there's something behind the scenes that's messing it up. Maybe you should have all the display code in one dedicated thread and pass data to that thread from the others.

You mean create a third task printToDisplay(String text)?

A third task that takes instruction through some other route (maybe a pipe or something similar) from the other tasks and displays the information.

Just found that if I put Task01 to run on the same core as Task02 (core 1) it works perfectly. And if I put both to run on core 0 the mess becomes a lot worse. The problem has clearly something to do when the task running on core 0 tries to write to the display even protected by Mutex.

Core 0 is used for the Wifi and IP stack. There's probably some timing issue then.

Yes, possibly. Still trying to find a way around it or will have to live with it...

Can you show us a picture of the display corruption? We may be able to see a pattern that would explain it.

Please check pictures I added at the top.Yes, there is a pattern that repeats but I believe it to be a result of the timing between task execution.

Ok, so there is one of two things happening here, and it's impossible at the moment to know which. The way the library works is it has an internal framebuffer which is what you modify with the drawing/printing functions. That framebuffer is then output in its entirety to the display in one go with .display(). Either that internal framebuffer is being corrupted while drawing, or the communication with the display is being broken when sending. I suggest having the .display() only ever happen in a thread on core 1. The rest can be wherever.

This is a formal answer to the question based on the comments between Paulo Borges and Majenko.

The ESP32 is dual core, meaning that it comes with 2 Xtensa LX6 32-bit microprocessors: core 0 and core 1.
The issue is not a bug in your code but rather that you are running your threads on Core 0 instead of Core 1.
In the ESP, the Core 0 is used for the RF communications. Even with the mutex protection, it is highly likely that your tasks are having timing issues.
Move Task01 and Task02 into Core 1 and your program will run without any display issues.


text:
How to recover an I2C bus when SDA is stuck low? Edit: SDA line stuck high
See edit at the end of the message.
I have an Arduino in master mode connected via I2c to a slave, with 2k pull-up resistors on SDA and SCL. Sometimes the SDA line is stuck low, which causes my program to hang indefinitely.
How to recover from such a scenario?
Edit1: Since the SDA line is tied low the problem probably comes from the master. My guess is that the slave waits for the rest of the clock pulses that never come.
I'm not using the Wire library. I wrote my own implementation based on the AMmega328P datasheet.
void TWIInit() {
  TWSR = 0x00;
  TWBR = 0x48; // SCL = 100khz
  TWCR = (1 << TWEN);
}

void TWIStart() {
  TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);
  while ((TWCR & (1 << TWINT)) == 0);
}

void TWIStop() {
  TWCR = (1 << TWINT) | (1 << TWSTO) | (1 << TWEN);
  while (TWCR & (1 << TWSTO));
}

void TWIWrite(uint8_t data) {
  TWDR = uint8_data;
  TWCR = (1 << TWINT) | (1 << TWEN);
  while ((TWCR & (1 << TWINT)) == 0);
}
unsigned int TWIReadACK() {
  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);
  while ((TWCR & (1 << TWINT)) == 0);
  return TWDR;
}

unsigned int TWIReadNACK() {
  TWCR = (1 << TWINT) | (1 << TWEN);
  while ((TWCR & (1 << TWINT)) == 0);
  return TWDR;
}

unsigned int TWIGetStatus() {
  unsigned int statusOfRegister;
  statusOfRegister = TWSR & 0xF8;
  return statusOfRegister;
}

int TWISendBytes(uint8_t slaveAddr, uint8_t regAddr, uint8_t buf[], int numbBytes) {
  TWIStart();
  if (TWIGetStatus() != 0x08) {
    TWIStop();
    return 1;
  }
  // send address and Write bit
  TWIWrite(slaveAddr & 0xFE);
  if (TWIGetStatus() != 0x18) {
    TWIStop();
    return 1;
  }
  // send the register address
  TWIWrite(regAddr);
  if (TWIGetStatus() != 0x28) {
    TWIStop();
    return 1;
  }
  // send bytes
  for (int i = 0; i < numbBytes; i++) {
    TWIWrite(buf[i]);
    if (TWIGetStatus() != 0x28) {
      TWIStop();
      return 1;
    }
  }
  TWIStop();
  return 0;
}

int TWIGetBytes(uint8_t slaveAddr, uint8_t regAddr, uint8_t buf[], int numbBytes) {
  TWIStart();
  if (TWIGetStatus() != 0x08) {
    TWIStop();
    return 1;
  }
  // send address and Write bit
  TWIWrite(slaveAddr & 0xFE);
  if (TWIGetStatus() != 0x18) {
    TWIStop();
    return 1;
  }
  // send the register address
  TWIWrite(regAddr);
  if (TWIGetStatus() != 0x28) {
    TWIStop();
    return 1;
  }
  // repeated start
  TWIStart();
  if (TWIGetStatus() != 0x10) {
    TWIStop();
    return 1;
  }
  // send address and Read bit
  TWIWrite(slaveAddr | 0x01);
  if (TWIGetStatus() != 0x40) {
    TWIStop();
    return 1;
  }
  // get bytes
  for (int i = 0; i < numbBytes; i++) {
    if (i == (numbBytes - 1)) {
      buf[i] = TWIReadNACK();
      if (TWIGetStatus() != 0x58) {
        TWIStop();
        return 1;
      }
    } else {
      buf[i] = TWIReadACK();
      if (TWIGetStatus() != 0x50) {
        TWIStop();
        return 1;
      }
    }
  }
  TWIStop();
  return 0;
}

Edit2: The SDA line, and SCL, is held high not low as I first incorrectly assumed (I probably did something wrong when I measured it and thought it was low but anyway.) The problem was that the resistors I was using as pull-up resistors were in fact 1k not 2k. I changed them for 2k resistors and the problem disappeared.

First you'd have to figure out how it is happening.  If resetting the ATmega CPU doesn't clear it, it's probably not the Arduino's fault, and hence off-topic here.  Identification of the chip and traces captured with a cheap logic analyzer would be a help.  I recall a temperature/humidity chip that would jam the bus so badly if read in a certain mode that even removing power wouldn't clear it, you had to literally short the supply rail to ground.

write non blocking code

@ChrisStratton Resetting the Arduino clears it. And I realized that if the SDA line is low it is because the slave is waiting a clock from the master. So the problem must comes from my code. Also I'm not using the Wire library but instead wrote my own functions to handle the I2C communications. So it is likely there's a problem in the way I implemented it.

Is the problem gone when you do use the Arduino Wire library?

Ok so I found the issue. First the SDA line wasn't low but high. Second, I was using 1k pull-up resistors. So the actually issue was that the resistors prevented the slave or master to drive the line low. I changed them for 2k resistors and it stopped hanging. As an additional safety I added a watchdog to reset the Arduino if the program is hanging. @Jot The problem was the same with the Wire library.

I solved the problem by replacing the pull-up resistors with 2k Ohm resistors. I thought I connected 2k Ohm resistors when in fact their value was 1k. So sometimes the SDA line couldn't be driven low due to the too strong pull-up resistors and that caused the hanging.

4.7k is the more generally accepted value for the pull-ups. I have some screenshots here of the effect of different values for the resistors.


text:
Sending mouseX and mouseY from Processing to Arduino
I'm new to serial communication and trying to send mouseX and mouseY from Processing to Arduino. Serial monitor doesn't show anything.
Processing code:
import processing.serial.*;
Serial port;
void setup() {
  size(500,300);
  port = new Serial(this , Serial.list()[0], 9600);
}

void draw() {
   text("X Y mouse",250,50);
   if (port.available() > 0) {
    port.write(str(mouseX)+' '+str(mouseY));
   }
}

Arduino code:
int x = 0;
void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
    x = Serial.read();
    Serial.print("I received: ");
    Serial.println(x);
  }
}

when I close Processing window and enter "ok" in Arduino serial monitor I see:

please add the snapshot of serial monitor with the data you are sending.

https://majenko.co.uk/blog/reading-serial-arduino

Only one program on your pc can communicate over the serial port at once. When processing is connected to it, the Serial Monitor is not ans vice versa

@Vaibhav There's nothing to show...unfortunately.

@chrisl if that means I can't use serial monitor, Can I use mouseX and mouseY data in my arduino program?

Sure can you use the mouse position on the Arduino. You rust have to send them to it via Serial and the Arduino code has to decode it correctly. Currently you are sending an ASCII string but decoding it as byte data. Finish your data, that you send with \n (newline). On the Arduino read the entire message  until you receive \n and put all received bytes into a string (or better a char array). Then you can use functions to convert the string to integers

Since you can't use the serial monitor to "see" the incoming data from Processing, here are 2 test sketches that may help you determine if data is received on the Arduino.
Upload the Arduino sketch first. Leave the serial monitor closed. Now run the Processing sketch.
I'm using frameRate(1) in the Processing sketch to send the data once per second, so the mouse X/Y values in the Processing window will be slow to update.
You should see the LED on the Arduino flash on then off quickly as the data is received. If you have a I2C LCD available, you could connect it to the Arduino and print out the incoming data.
As chrisl mentions in the comments, there is still much work to be done to get the raw data in the format you require.
Arduino
int x = 0;
const byte ledPin = 2;

void setup(){
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop(){
  if(Serial.available() > 0){
    x = Serial.read();
    digitalWrite(ledPin, HIGH);
  }
  else{
    digitalWrite(ledPin, LOW);
  }
}

Processing
import processing.serial.*;
Serial port;
void setup() {
  size(500,300);
  background(148);
  try{
    port = new Serial(this , Serial.list()[0], 9600);
  }
  catch(Exception e){
    System.err.println(e);
    e.printStackTrace();
  }
  frameRate(1);
}

void draw() {
  background(148);
  //@chrisl comment: Finish your data, that you send with \n (newline).
  port.write(str(mouseX)+' '+str(mouseY) + "\n");
  text(mouseX,250,50);
  text(mouseY,250,70);
}

EDIT
Here is a second Arduino sketch that will display the mouse X/Y values sent from Processing on a LCD. You could change the Processing sketch's frameRate() value to 10.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

char inputBuffer[32 + 1];

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup(){
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
}

void loop(){
  if(Serial.available() > 0){
    lcd.print("                ");
    Serial.readBytesUntil('\n', inputBuffer, 32);
    lcd.setCursor(0, 0);
    lcd.print(inputBuffer);
    memset(inputBuffer, 0, sizeof(inputBuffer));
  }
}

fantastic! I'm going to learn more about LCDs. I used an lcd once with parallel wiring... it was exhausting.

If you solder a Serial Interface Board or I2C LCD "backpack" to the LCD, then there are only 4 wires to connect :) https://www.aliexpress.com/item/IIC-I2C-TWI-SPI-Serial-Interface-Board-Port-For-Arduino-1602-2004-LCD-LCD1602-Adapter-Plate/32895120140.html


text:
How to write a function to return matrix?
I need a function to return a 2x2 rotation matrix, something like:
float matrix(float phi){
  float R[2][2] = { {cos(phi), -sin(phi)},
                    {sin(phi),  cos(phi)} };
return R;
}

But it doesn't work obviously. What is the best way to write this function?

One way would be to make the function return a pointer to float ie create a new array and return it
float** matrix(float phi){
   float** R= (float **)malloc(2 * 2 * sizeof(float));
   R[0][0]= cos(phi);
   R[0][1]= -sin(phi);
   R[1][0]= sin(phi);
   R[1][1]= cos(phi);
   return R;
}

Do not forget to free the memory once you do not need it any more!
However, I would advise you not to do it but rather pass the array to the function. See How can I declare an array of variable size (Globally) and Is using malloc() and free() a really bad idea on Arduino? for an explanation why it might not be a good idea to allocate the memory in the function (in an embedded aka Arduino environment)

This is not how you create a 2D array. Here, R[0] and R[1] are uninitialized float * pointers, and R[0][0] is dereferencing one such pointer. This is undefined behavior likely to crash the program.

Wow...  C++ is too hard to program.

@ Edgar Bonet,  so how can I write this function?

You cannot return an array from a function. There are several
alternatives, though. One of them is to allocate the memory for the
array within the function, as suggested by user2912328's answer. I would
not recommend this approach though, for the reasons already stated in
that answer.
For an overview of the other possible options, see this response to the
question “Returning an int array from a function”.
Now, your problem is slightly different, as you have a 2D array.
The C/C++ syntax for dealing with those is tricky, but here we go.
If you opt for the “static array” solution (make sure you understand the
implications), you could write:
float (*matrix(float phi))[2]
{
    static float R[2][2];
    R[0][0] = cos(phi);
    R[0][1] = -sin(phi);
    R[1][0] = sin(phi);
    R[1][1] = cos(phi);
    return R;
}

and you would use it like this:
float (*M)[2] = matrix(angle);

If you instead let the caller manage the allocation, then
float (*matrix(float phi, float (*R)[2]))[2]
{
    R[0][0] = cos(phi);
    R[0][1] = -sin(phi);
    R[1][0] = sin(phi);
    R[1][1] = cos(phi);
    return R;
}

Or maybe forgo the return value to make the syntax simpler:
void matrix(float phi, float (*R)[2])
{
    R[0][0] = cos(phi);
    R[0][1] = -sin(phi);
    R[1][0] = sin(phi);
    R[1][1] = cos(phi);
}

and you could use it like:
float M[2][2];
matrix(angle, M);

The “array in a struct” solution is more straightforward.
If the syntax for dealing with 2D arrays bothers you (which would be
understandable), you can instead use arrays of pointers to 1D arrays.
This are easier to deal with but trickier to allocate. That approach
could warrant another answer...

Edit: One common way to simplify a convoluted array syntax is to use
typedefs. As an identifier for a 2x2 array decays to a pointer to an
array of 2 floats, you can name that type:
typedef float (*pmatrix)[2];  // pointer to an array of 2 floats

Then, instead of
float (*matrix(float phi))[2] { ... }
...
float (*M)[2] = matrix(angle);

you would write
pmatrix matrix(float phi) { ... }
...
pmatrix M = matrix(angle);