body:
I have made a project using Arduino, 3 LDRs and a L293D motor driver shield. My project was that when I block light from the first LDR, the motor will spin. When I block light from the second LDR, the motor will spin in opposite direction, and when I will block light from the third one, it will stop. The code had no errors and I expected it to work... But no luck. When I blocked light from the first or second LDR, the motor only made a faint "_zing-zing_" type of sound. Why is this happening? Is this a power problem? But I have connected 2 9v batteries to the shield and the Arduino. Please help! Here is the code I used-

    #include (AFMotor.h)

    const int LDR1 = A0;
    const int LDR2 = A1;
    const int LDR3 = A2;
    const int LightIntensity = 150;
    int SensorReading1 = 0;
    int SensorReading2 = 0;
    int SensorReading3 = 0;
    AF_DCMotor motor(1);

    void setup(void)
    {
      pinMode(LDR1, INPUT);
      pinMode(LDR2, INPUT);
      pinMode(LDR3, INPUT);
      motor.setSpeed(255);
    }

    void loop()
    {
      SensorReading1 = analogRead(LDR1);
      SensorReading2 = analogRead(LDR2);
      SensorReading3 = analogRead(LDR3);

      if (SensorReading1 < LightIntensity)
      {
        motor.run(FORWARD);
      }

      if (SensorReading2 < LightIntensity)
      {
        motor.run(BACKWARD);
      }

       if (SensorReading3 < LightIntensity)
      {
        motor.run(RELEASE);
      }
    }

title: Help! My motors are not working!

Answers: 1

body:
You have not said what you motor is and that normally has a big bearing on the answer, but I think your problem is you need more power.

A 9V battery doesn't actually give you much current, you would be better off with a 'wall wart' aka a mobile phone charger.  The higher the amps the better normally, particularly with motors.  Try and find one that can put out 5Volts at 1Amp (assuming you have a 5V motor).

Also make more use of Serial.println() to show you what your program is doing.  If you had debug statements in the LDR if statements then you would know the switches are working.


body:
I use Visual Studio Code to develop for arduino which uses Arduino Studio installed files and needs the installation to work. This works very well.

Annoying is that when verifying a sketch it takes longer than in the Arduino IDE. I suspect the following warning to cause it:

> [Warning] Output path is not specified. Unable to reuse previously
> compiled files. Verify could be slow. See README.

I would like to get rid of the warning and I searched through all README files in the arduino installation folder and I also searched google but haven't found out what its supposed to mean and how to fix it. No readme file mentions that or I overlooked it.

Is there a documentation on how to fix this anywhere?

title: Warning when verifying sketch with VS code

Answers: 2

body:
Thanks to @Majenko I looked some place new:

documented in the arduino plugin of VS Code Arduino Extension there is an option to set an output directory.
Note though that according to this it should not be in the workspace or subfolders.

So in arduino.json settings file add:

    "output": "../ArduinoOutput"

body:
To clarify the answer, for those new in arduino world +StudioCode (source: https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino )

The following settings are as per sketch settings of the Arduino extension. You can find them in .vscode/arduino.json under the workspace.

    {
        "sketch": "example.ino",
        "port": "COM5",
        "board": "adafruit:samd:adafruit_feather_m0",
        "output": "../build",
        "debugger": "jlink",
        "prebuild": "bash prebuild.sh"
    }

**sketch** - The main sketch file name of Arduino.

**port** - Name of the serial port connected to the device. Can be set by the Arduino: Select Serial Port command.

**board** - Currently selected Arduino board alias. Can be set by the Arduino: Change Board Type command. Also, you can find the board list there.

**output** - Arduino build output path. If not set, Arduino will create a new temporary output folder each time, which means it cannot reuse the intermediate result of the previous build leading to long verify/upload time, so it is recommended to set the field. Arduino requires that the output path should not be the workspace itself or in a subfolder of the workspace, otherwise, it may not work correctly. By default, this option is not set.

**debugger** - The short name of the debugger that will be used when the board itself does not have a debugger and there is more than one debugger available. You can find the list of debuggers here. By default, this option is not set.

**prebuild** - External command before building the sketch file. You should only set one prebuild command. command1 && command2 does not work. If you need to run multiple commands before the build, then create a script.

When You add folder with sketch, you are creating "so called" project.
VS code puts there some hidden folders with the project configuration files.
To see them from windows file explorer you may enable show hidden files. than in your project folder You may find .vscode , and there is the arduino.json file.

More simple way is just click on the project navigation bar on the left, and open there the .vscode folder and using vscode as editor just add

"output": "../ArduinoOutput" or "output": "../build" or whatever you want to name that folder.

".." tells that it is one level above the "project folder" so it is "outside" as VScode wants.

And as far as i know this is not global setting, so You need to set it for every project if you want it.

Check the proper formatting in order to save file, use code hints to add options in file.

Hope that this is as clear as possible and help others to find that magic arduino.json file and understand where what and why.

Cheers.
[![vscode arduino.json file location and editing][1]][1]

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


body:
I have a [LoRa Click](https://learn.mikroe.com/lora-rf-click-solution-for-iot-developers/) Module and [Adafruit Ultimate GPS](https://www.adafruit.com/product/746) which both use Serial Communication.

I wish to just check the initial tests with all the components in on the Serial Console. Hence I have declared :

- `SoftwareSerial GPSSerial(10,11);`
- `SoftwareSerial LoRaSerial(5,6);`

Apparently when I declare them and upload the code on the board I do not obtain any information.

### observations
1. However when I comment out the `LoRaSerial` declaration I obtain the GPS coordinates.

2. When I set the `SoftwareSerial LoRaSerial(10,11)` I retrieve the information.

3. I thought `5,6 ` pins won't be the right choice and hence went on the set `SoftwareSerial(8,9)` but I retreive no information.

### inference
Nano cannot take into consideration more than 1 SoftwareSerial Component. However the Official Documentation states that all Digital pins can be used for Software Serial.

Is it too much for a Nano to have overall __3__ Serial ports (including `Serial` itself)?

### sketch

    #include <SoftwareSerial.h>
    #include <TheThingsNetwork.h>

    SoftwareSerial GPSSerial(10, 11); //RX , TX
    SoftwareSerial LoRaSerial(8,9); // RX, TX (tried with 5,6 too)
    #define freqPlan TTN_FP_EU868

     TheThingsNetwork ttn(LoRaSerial, Serial, freqPlan);
    void setup() {
      Serial.begin(115200);
      GPSSerial.begin(9600);
      LoRaSerial.begin(57600);
    }
    void loop() {
      delay(2000);
      while (GPSSerial.available()) {
        char c = GPSSerial.read();
        Serial.write(c);
      }
      delay(2000);
      while (LoRaSerial.available()) {
        ttn.showStatus();
      }
      delay(2000);
    }

title: No Information obtained when using 2 x SoftwareSerial ports on Arduino Nano

Answers: 2

body:
Sometimes, with some devices, SoftwareSerial can struggle at higher baud rates, there are quite a few posts on here about it.  Would it be possible to set the LoRaSerial to 9600 too?

Can you try just the LoRaSerial on its own?

Do you have a second device, could you wire the SoftwareSerials on you Nano to two Software Serial ports on your second device and then squirt anything it receives to the hardware serial port (and then to the console).  Then send some test messages from the Nano and see if the device picks them up?

ESP8266 have 2 and a half serial ports (Serial1 is Tx only), but unless you were going to hook the ESP to the Nano via I2C or use the ESP instead of the Nano, that's probably not going to help you in the case.

body:
You cannot use two SoftwareSerial instances at the same time - or not for receiving anyway.

SoftwareSerial is a "last resort" system - only to be used if there is absolutely no other option. And then you need to be aware of certain information and rules:

* Only one device can *listen* at any time, switchable using the `SoftwareSerial::listen()` method
* When a byte is being received nothing else can happen - it takes over the entire CPU for the duration of reception
* When a byte is being transmitted nothing else can happen - it takes over the entire CPU for the duration of transmission
* There is a minimum required time between successive bytes when receiving that causes problems at higher baud rates

These limitations mean that, when using multiple devices, you have to know before hand which device will be sending you data so you can be ready to receive it. It also means that SoftwareSerial is effectively half duplex - it only really works properly when you are either only receiving, only transmitting, or using a "call-response" scenario like sending "AT" commands and looking for a response afterwards.

So the general recommendation is: use hardware UARTs whenever possible (and if you don't have enough, then consider using a different, more suitable, board with multiple UARTs), and if you *must* use SoftwareSerial then limit yourself to only *one* instance of it.

As a last resort you can always use multiple boards and connect them using a different system, such as I2C.


body:
I am curious if the following scenario is possible.

    EICRB |= (0<<ISC60)|(0<<ISC61);
    EIMSK |= (1<<INT6);

    ISR(INT6_vect) {
      myISR();
    }

    void myISR() {
         digitalWrite(led_off, OFF);
         // Please break my main for loop :)
    }

    void loop()
    {
          for (i=100; i>=0; i--)
                 {

                /* STOP button */
                  if (read_switch() == 1) {
                          break;
                   }
               .. delays and other logic ...
    }

As you see the following code is not complete but quite understandable. I have a heating process done in the main program, each loop temp adjustments, printing, delay etc takes about 2-3 seconds to complete. When somebody pushes a switch read_switch will return 1 and that breaks up this function ending the heating process.
This works just fine except the user have to hold the button for the time it finishes looping and get to this point again.
I have fortunately realized that the switch pin (Arduino promicro pin7) also an interrupt pin so I could do interrupt in real time, as I doing it in other code already.

However what you can do in this ISR routine is limited (eg you cannot print to serial etc). I could setup a global volatile bool variable here of course which would immediately get flipped as the interrupt triggered but it would not solve anything since in the main loop I would have to wait for the next round again.

So is it possible with some hack to tell the ISR to break that for loop (not the whole program with an exit(0)) and continue execution afterwards?

title: Breaking up for loop with ISR

Answers: 3

body:
No, it's not possible, nor desirable. It's complicated and unnecessary.

What you have to do is:

 1. Declare a **volatile** global variable (a switch).
 2. Inside ISR, change that switch to signal that a break is needed.
 3. Inside your loop (for, while, ...) test for that global variable and proceed.

This example print "This is the end" each time a button connected to pin 2 is pressed.

    volatile bool fin = false; // The switch for ISR-loop communication.

    void setup()
    {
     Serial.begin(9600);
     pinMode(2, INPUT);  // Read a button or other signal.
     attachInterrupt(0, buttonISR, RISING);
    }

    void loop()
    {
     if(fin) {
      Serial.println("This is the end");
      fin = false; // Reset the switch.
     }
    }

    void buttonISR()
    {
     fin = true;  // Just raise the signal for the main loop.
    }

This method keeps ISR ultra-short and there is no mixing between ISR's instructions and loop's instructions. All of your logic reside in the main loop.

body:
Turn the loop into a state machine instead.

Wrap the entire loop body in a switch.

Every time you have a `delay(t);` make it a target for a case label and replace it with

    startTimeout = millis();
    currentState = N;
    case N: if(millis() - startTimeout < t) return;

Every `for(init; condition; inc)` loop that has delays inside them can be replaced with

    <init>
    state = N;
    case N: if(!condition) state = N1;
    <body>
    <inc>
    state = N;
    return; //return from loop() and let it restart
    case N1;

Then any delay inside body can be adjusted like above.

Make sure that every state case is unique and make any state that needs to persist across states global.

body:
Fairly easy to do. In your heater code, tests the state of the switch periodically and exits if the right state is detected.

As to how periodically you should test, it will depend on your requirement for response time.


body:
I have multiple ESP8266 units programmed using Arduino SDK and I would like each one of them to adjust the transmission power to lower the power requirements.

Arduino allows setting the TX power of the ESP8266 using the function [WiFi.setOutputPower()][1], however it is not clear to me how to choose that value.

I know that RFM69 using the [LowPower library][2] has automatic gain control using the ACK packet sent by another RFM69 module. However, with ESP8266 there is a standard AP and a similar approach would not be obvious.

How can I perform optimal gain control?

This question is independent from the choice of the WiFi mode b/g/n using WiFi.setPhyMode().

**Edit**

An idea could be to detect AP station signal strength and transmit at a power level offset by a fixed amount, decreasing that delta by one tick at every wake up, until no connection is achievable. At that point the delta should be increased by an amount corresponding to a sort of hysteresis, to jump above the no-connection threshold, and kept.

After a predefined amount of successful wake ups, for example 100, the process of decreasing the calculated delta would be tried again.

For example: AP strength -60 dB, transmission +12 dB: success -> delta 48 dB is good.

Next wake up, delta 48.25 dB: is AP is at -55 dB, transmission would be 55-48.25 dB = 6.75 dB. If success, delta increased to 48.50 dB.

  [1]: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp
  [2]: https://github.com/LowPowerLab/RFM69

title: How to optimise TX power for ESP8266?

Answers: 1

body:
> I would like ... to adjust the transmission power to lower the power requirements.

Is your goal to reduce overall/average power consumption, or peak current draw? If the former, then because of the high-level nature of the wifi API exposed by the ESP system, you may get a greater level of success by optimizing the time you are connected, rather than the power consumption.

That is, make sure WiFi radio is disabled while you are preparing whatever data you may wish to send over WiFi, then turn the radio on, connect+send, go back to sleep.

[This blog post][1] gives experimental details, but the gist is

*In `Setup()`:*

    WiFi.mode( WIFI_OFF );
    WiFi.forceSleepBegin();
    delay( 1 );

*Just before you choose to connect:*

    WiFi.forceSleepWake();
    delay( 1 );

    // Bring up the WiFi connection
    WiFi.mode( WIFI_STA );
    WiFi.begin( WLAN_SSID, WLAN_PASSWD );

*And, when you go to sleep, tell the system to keep the radio off by default:*

    WiFi.disconnect( true );
    delay( 1 );

    // WAKE_RF_DISABLED to keep the WiFi radio disabled when we wake up
    ESP.deepSleep( SLEEPTIME, WAKE_RF_DISABLED );

Part 3 of this blog also notes that if you will continually be connecting to the same WiFi network, you can tell the ESP8266 to not spend the time loading the previous connection's details from flash memory, but requiring you to provide them in the connection call:

    WiFi.forceSleepWake();
    delay( 1 );

    // Disable the WiFi persistence.  The ESP8266 will not load and save WiFi settings in the flash memory.
    WiFi.persistent( false );

    WiFi.mode( WIFI_STA );
    WiFi.begin( WLAN_SSID, WLAN_PASSWD );

  [1]: https://www.bakke.online/index.php/2017/05/21/reducing-wifi-power-consumption-on-esp8266-part-2/


body:
I found this code below for the Arduino platform to obtain current measurements from the SCT013 sensor, and I am wondering how can I define the 'delay' or 'frequency' of my readings? I'd be looking for 200Hz.

Code:

    //
    #include "EmonLib.h"                   // Include Emon Library
    EnergyMonitor emon1;                   // Create an instance

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

      emon1.current(5, 60);             // Current: input pin, calibration.
      //calibration is explained bellow
    }

    void loop()
    {
      double Irms = emon1.calcIrms(1480);  // Calculate Irms only

      Serial.print(Irms*230.0);        // Apparent power
      Serial.print(" ");
      Serial.println(Irms);         // Irms
    }
    //

title: Setting reading frequency SCT013 current sensor code using Arduino Uno

Answers: 2

body:
you skip reading when the last read is less than 1000/200 = 5ms ago.

    unsigned long lastRead;

    void loop()
    {
       unsigned long currentMillis = millis();
       if(currentMillis - lastRead >= 5){

          double Irms = emon1.calcIrms(1480);  // Calculate Irms only

          Serial.print(Irms*230.0);        // Apparent power
          Serial.print(" ");
          Serial.println(Irms);            // Irms
          lastRead = currentMillis;
        }

    }

body:
If you want a 200Hz sample rate this code doesn't work for you.

With this line:
`double Irms = emon1.calcIrms(1480);` you take 1480 samples as fast as Arduino can.

If you want 200Hz sample rate, read analog ping every 5ms using millis() function. And when you have enough samples you can calculate the rms current https://en.wikipedia.org/wiki/Root_mean_square

This is an example code:

    unsigned int sample_time = 0;
    int readings[200];  //num samples 200
    int i = 0;

    setup() {
    }

    loop() {
        if (millis() - sample_time > 5){
            readings[i] = readAnalog(A0);
            i++;
            sample_time = millis();
        }
        if (i > 200)
             Caculate_Irms();
             i = 0;
    }


body:
I'm testing a servo using varspeedservo.h and it rotates to 180 degree on start and then rotates back to programmed position.
Here is the code:

    #include <AFMotor.h>
    #include <VarSpeedServo.h>
    VarSpeedServo myServo;

    void setup()
    {
      myServo.attach(10);
    }
    void loop()
    {
      myServo.slowmove(0, 30);
      delay(5000);
    }

title: On start servos rotates to 180 degree

Answers: 1

body:
You will need to open up the [VarSpeedServo library source code][1] and read through it to understand how the library actually works with your sketch.

Consider that you have not setup an initial position before issuing your first "slow moving" command.  It may be by setting an initial position before assigning a pin to the servo, you may prevent any unexpected movement.

Try something (for your code) like "myServo.wirte(0,0)" where the first argument is the position and second is the speed.

  [1]: https://github.com/netlabtoolkit/VarSpeedServo


body:
I was having some problems on a project, so to test my Arduino, I wrote the following program to check things. When I start the serial monitor, the value of `i` is 1, but after I start sending numbers, they change into ASCII. Why?

<!-- language: lang-cpp -->

    int i = 1;
    void setup(){
      Serial.begin(9600);
    }
    void loop(){
      Serial.println(i);
      if(Serial.available()){
        i = Serial.read();
      }
    }

title: Serial.read(): Value changes to ASCII when I input from Serial Monitor

Answers: 1

body:
When you send the character `1`, `Serial.read()` returns the integer 49.
 `Serial.println(i)` then sends the characters `4`, `9`, carriage return and a newline.

If you want to get back the same characters that you sent, change the type of `i` to `char`.


body:
I got my hands on one of these [ISP programmer for Atmel AVR microcontroller in USB stick design][1]:

[![mySmartUSB light][2]][2]

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}

  [1]: http://shop.myavr.com/index.php?sp=article.sp.php&artID=200006
  [2]: https://i.stack.imgur.com/Wb2ZD.png

title: Burn Bootloader to Chinese Arduino 2560 with AVR ISP programmer

Answers: 2

body: 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.

body: 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.


body: Is it possible to read somehow VGA port of graphics card by Arduino? Even with some minimal 320 x 240 resolution and minimal frame rate per second, to convert pixels into numbers (for example) somehow. Who can show where to dig?

title: Decode VGA port by Arduino

Answers: 2

body:
Calculation:

   320 x 240 resolution (assuming 8 bits for 256 colors) is 76,800 bytes

Assuming a frame rate of 50, that is 50 * 76,800 = 3,840,000 bytes/s

The most Arduino's are 16 MHz so assuming quite some instructions are needed (for converting and doing something) I doubt you will get this frame rate.

Also, you cannot store a complete page, but this may not be necessary.

body:
Your standard VGA (640x480@60Hz) has a 25.175MHz pixel clock. That's far too high for an Arduino to read as an analog signal. It's even to high to read as a digital signal through a comparator (1-bit monochrome). Added to that you have three signals, red, green and blue, you would want to sample the signal at 75.525Msps if done sequentially, or 25.175Msps if done with three ADCs in parallel.

Now the Arduino has no hope of ever doing that. However there are methods that could be useful - methods that allowed a lowly little 8-bit computer, such as the ZX Spectrum, etc, to capture graphics when running at only a couple of MHz (such as the [Videoface](https://en.wikipedia.org/wiki/Videoface)).

One of the most interesting in this scenario is called *progressive scan* (not to be confused with the "progressive scan" used in HD terminology to mean the opposite of interlaced). With this you don't try and capture an entire frame in one go. Instead you capture just a few pixels from each scan line (and even only from a selection of scan lines) from each frame. In subsequent frames you capture a different selection of pixels. Over a number of frames (which can be quite a large number given the amount of data you'd need to capture) you will get the entire image. Of course this is no use if the image is rapidly changing since the image data that you would be reading would change part way through constructing your final image resulting in interesting banding effects.

About half way through [this video](https://youtu.be/99lX3n8Ahak) you can see the scanning in action and how motion causes banding.

So yes, technically it is possible to capture VGA on an Arduino (maybe with the addition of extra external memory) however it is very hard to do it and the results may not be anywhere like what you actually want.


body:
Recently I have been attempting to make my Arduino Uno a PIC16F877A programmer. Looking at the schematic to do this, I see that there is no JP1 pin on the Arduino as specified on the diagram on the top-left.

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

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

As I am new to electrical engineering I may just be simply overlooking it yet this is unlikely because I have been puzzled by this for two days.

title: Where is JP1 on the Arduino Uno?

Answers: 2

body: **None** of this is on the Arduino. You must construct **all** of this yourself.

body: JP1 is not a pin. It is a connector, with, if my eyes still work, 2 pins, which look like 13 volt DC and Ground. Likewise JP2 is not a pin, but a connector, with, hmmm, 6 pins. Three of which go directly to the Arduino, another one to the Arduino via Q1, and a final pin to Ground.


body:
I am new to the community and this is my first question. Hope it turns out to be a nice question :)

Me and my friend are preparing a senior design project on home automation. I have several things in my mind such as controlling drapes, lights, fans with an IOS application.

We started everything from scratch and came up with a great NTC controlled fan and etched it on a PCB as follows

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

However, here's our bottleneck . Although this circuit works perfectly fine and dandy, this is kind of not what we want. We want a user to control the fan, which made us realized this circuit is a total waste because it is independent of the user, turns up the fan when the temperature goes high not when the user wants it to turn up. What we really want to implement is using something that can be controlled with a phone and works as a switch.

How do you think we can do this? We have this in mind :
[![enter image description here][4]][4]

We are writing an IOS app with Xcode and we use ESP8266 Wifi module to bridge our phone to a web server which makes the connection between the phone and system. Do you think we can go from here? If so, what should we do to make this system work ?

  [3]: https://i.stack.imgur.com/jhJoN.jpg
  [4]: https://i.stack.imgur.com/e7Z99.jpg

title: Using Arduino or ESP8266 as a switch to turn on a 12V DC Fan

Answers: 2

body:
Sounds like you want an ESP8266 with an API that controls a GPIO pin state.  Very simple.

Phone App or Web app -> ESP8266 with route for controlling GPIO -> MOSFET

The MOSFET should be suitable for 3.3V logic.  Don't forget the flyback diode on the motor.

Here's some pseudo-ish code:

    espServer->on("/api/fan", HTTP_POST, [&]() {
        int pwmSpeed = server->arg("pwm").toInt()
        switchGpioState(pwmSpeed);
    }
    espServer->on("/get-state", HTTP_GET, [&]() {
        // Send state to browser/app
    }
[![enter image description here][1]][1]

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

body:
Take a look at MQTT. This a lightweight protocol designed for the IoT.

You will need:

 - An MQTT *broker*. This program is the "Post Office" for MQTT messages. Clients publish and subscribe for messages here. It run on a PC.
 - An MQTT *client* library for the NodeMCU or ESP8266.
 - An MQTT *browser* for iPhone (Android, PC, Mac, ...).

I recommend mosquitto as a broker, but you can start working with a public broker in Internet. It is free, multi-platform and can run in any old laptop.

For iPhone/Android, I use MQTT Dash as a browser.

The beauty of this alternativa: you don't have to code an app for your phone. Protocol is trivial. Setup is non-existent. Is data agnostic (you can send/receive anything, any size). It can easily interact with apps in other platforms (like databases).

The best: it works thru Internet without any extra effort.

[![A MQTT application][1]][1]

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


body:
Got this module from Aliexpress
[![enter image description here][1]][1]

W5500 [Ethernet Network Modules For Arduino][2] 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?

  [1]: https://i.stack.imgur.com/Plitu.png
  [2]: https://www.aliexpress.com/item/For-Arduino-W5500-Ethernet-Network-Modules-For-Arduino-TCP-IP-51-STM32-SPI-Interface-3-3V/32673979144.html?spm=2114.search0104.3.9.vIV2jD&ws_ab_test=searchweb0_0,searchweb201602_3_10152_10065_10151_10068_10344_10342_10343_10340_10341_10307_10060_10155_10154_10056_10055_10054_10059_10534_10533_10532_100031_10099_10338_10339_10103_10102_10052_10053_10142_10107_10050_10051_10173_10084_10083_10080_10082_10081_10110_10111_10112_10113_10114_10312_10313_10314_10078_10079_10073,searchweb201603_25,ppcSwitch_7&btsid=cb5c75f4-fcc7-424d-bcfe-3b0a40528c80&algo_expid=27f625ee-2770-4ec2-a367-cd7fcec3e2db-1&algo_pvid=27f625ee-2770-4ec2-a367-cd7fcec3e2db

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?

title: Arduino Micro + W5500 module from AliExpress

Answers: 4

body: 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.

body:
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.

body: 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.

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


body:
Following is the code I found in Arduino example files. It compiled fine on Arduino UNO. But there was an error when I tried to compile it for nodeMCU 1.0(ESP 12E Module).

    #include <TimerOne.h>
    void setup() {
      pinMode(13,OUTPUT);
      Timer1.initialize(5000000);//5 sec
      Timer1.attachInterrupt(timerIsr);
    }
    void loop() {}
    void timerIsr(){
      digitalWrite(13,!digitalRead(13));
    }

Following was the error message. I had this kind of error previously on OneWire.h and I solved it by replacing the OneWire.h library with another OneWire.h library that was made especially for nodeMCU.

Error msg:

    Arduino: 1.8.3 (Windows 8.1), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"

    In file included from D:\iox Prime\TEC project\code\building modules\timerIsrDemo\timerIsrDemo.ino:1:0:

    C:\Program Files (x86)\Arduino\libraries\TimerOne/TimerOne.h:39:20: fatal error: avr/io.h: No such file or directory

     #include <avr/io.h>

                        ^

    compilation terminated.

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

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
I searched the library everywhere in the internet to solve this error but end up with no success. I wish somebody modifies the existing library for me. Thank you for the help.

title: TimerOne.h library for nodeMCU

Answers: 3

body:
The TimerOne library is specifically for Timer 1 on the AVR microcontrollers1. No other microcontroller has the exact same timer structure, so the library cannot be used with them.

You need a library that works with the timers the ESP8266 has, or you need to manually manipulate the timer registers, for which you will need to consult and understand the datasheet.

----
1: It also appears to have #defines in it for ARM (Teensy 3.x) chips.

body:
I have found a solution. There is a library called Ticker.h
I found this on github: https://github.com/esp8266/Arduino/tree/master/libraries/Ticker

Following is my demo code:

    #include <Ticker.h>
    Ticker ticker;
    void setup() {
      pinMode(D7,OUTPUT);
      ticker.attach(1,isrFunc);//tickerObj.attach(timeInSecs,isrFunction)
    }

    void loop() {}
    void isrFunc(){
      digitalWrite(D7,!digitalRead(D7));
    }

For me, this code worked seamlessly on nodeMCU. Thank you.

body:
There is a another Ticker.h for non ESP processors like UNO, see below:

    // Filename: Ticker_Example - Does'nt work on ESP)
    // this is based upon published version V3 of 3/2018
    // refer to : https://github.com/sstaub/Ticker/blob/master/examples/Example.ino
    // Complete example. Here we created five timers, you can run it and test the result
    // in the Serial monitor and the on board LED.
    #include "Ticker.h"

    void printMessage();
    void printCounter();
    void printCountdown();
    void blink();
    void printCountUS();

    bool ledState;
    int counterUS;

    /*
    Creates a Ticker object          Constructors / Destructor
    Ticker(fptr callback, uint32_t interval, uint16_t repeats = 0, resolution_t resolution = MICROS)
        parameter callback for the function name you want to call
        parameter interval sets the interval time in ms or us when using MICROS_MICROS with the resolution parameter
        parameter repeats sets the number of repeats the callback should executed, 0 is endless
        parameter resolution sets the internal resolution of the Ticker, it can MICROS, MICROS_MICROS or MILLIS
    or in Ray's simpler terms...  Ticker (give it a name)(the callback function, interval, number of times, resolution)
    */
    Ticker timer1(printMessage, 0, 1);      // once, immediately
    Ticker timer2(printCounter, 1000, MILLIS);  // internal resolution is milli seconds
    Ticker timer3(printCountdown, 1000, 5);   // countdown 5 times, every second
    Ticker timer4(blink, 500);          // changing led every 500ms
    // Ticker timer5(printCountUS, 100, 0, MICROS_MICROS); // originally used 'MICRO_MICROS' so the the interval time would be 100us
                                                 //with a internal resolution of micro seconds BUT this did not compile
    Ticker timer5(printCountUS, 2000, 0, MICROS);  // now set to 2 seconds

    void setup() {
      pinMode(LED_BUILTIN, OUTPUT);
      Serial.begin(9600);
      delay(2000);
      timer1.start();
      timer2.start();
      timer3.start();
      timer4.start();
      timer5.start();
      }

    void loop() {
      timer1.update();
      timer2.update();
      timer3.update();
      timer4.update();
      timer5.update();
      }

    void printCounter() {
      Serial.print("Counter ");
      Serial.println(timer2.getRepeatsCounter());
    //  Serial.println(timer2.counter()); // this original line did not compile
      }

      void printCountdown() {
        Serial.print("Countdown ");
        Serial.println(timer3.getRepeats() - timer3.getRepeatsCounter());
        // Serial.println(4 - timer3.counter());  // this original line did not compile
        }

    void printMessage() {
      Serial.println("Hello!");
      }

    void blink() {    // blink every 500ms
      digitalWrite(LED_BUILTIN, ledState);
      ledState = !ledState;
      }

    void printCountUS() {
      counterUS++;
     // if (counterUS == 10000) {
     // Serial.println("10000 * 100us");
      if (counterUS == 5) {
        Serial.print("5 * 2000mS when millis = ");
        Serial.println(millis());
        counterUS = 0;
        }
      }

    /*
    Functions called in format 'timer1.start();' for the Ticker previously named timer1

    void start()
    Start the Ticker. Will count the interval from the moment that you start it. If it is paused, it will restart the Ticker.

    void resume()
    Resume the Ticker. If not started, it will start it. If paused, it will resume it. For example, in a Ticker of 5 seconds, if it was paused in 3 seconds, the resume in continue in 3 seconds. Start will set passed time to 0 and restart until get 5 seconds.

    void pause()
    Pause the Ticker, so you can resume it.

    void stop()
    Stop the Ticker.

    void update()
    Must to be called in the loop(), it will check the Ticker, and if necessary, will run the callback

    status_t state()
    Returns the state of the Ticker.

    uint32_t elapsed()
    Returns the time passed since the last tick, ms or us depending from the resolution.

    uint16_t counter()
    Returns the number of executed callbacks.
      */


body:
I have used PIR motion sensor with arduino Uno r3, alongwith one piezo buzzer. and the program is as

     /*
     * PIR sensor tester
     */

    int ledPin = 13;                // choose the pin for the LED
    int inputPin = 2;               // choose the input pin (for PIR sensor)
    int pirState = LOW;             // we start, assuming no motion detected
    int val = 0;
    int piezoPin = 11;
    // variable for reading the pin status

    void setup() {
      pinMode(ledPin, OUTPUT);      // declare LED as output
      pinMode(inputPin, INPUT);
      pinMode(piezoPin, OUTPUT);
      Serial.begin(9600);
      // declare sensor as input

    }

    void loop(){
      val = digitalRead(inputPin);  // read input value
      if (val == HIGH) {            // check if the input is HIGH
        digitalWrite(ledPin, HIGH);
        tone(piezoPin,300,160);
        delay(150);

        // turn LED ON
        if (pirState == LOW) {
          // we have just turned on

          // We only want to print on the output change, not state
          pirState = HIGH;
        }
      } else {
        digitalWrite(ledPin, LOW);
        tone(piezoPin,0,0);
        delay(300);

        // turn LED OFF
        if (pirState == HIGH){
          // we have just turned of

          // We only want to print on the output change, not state
          pirState = LOW;
        }
      }
    }

but it supposed to ring buzzer at the time of pir motion sensor getting signal. But buzzer continuously ringing and at the time of pir sensor getting signal, it just ring louder. What is the problem in program``

title: What's the problem with program , continously beeping buzzer

Answers: 1

body:
**noTone()**

*Description*

Stops the generation of a square wave triggered by `tone()`. Has no effect if no tone is being generated.

NOTE: if you want to play different pitches on multiple pins, you need to call `noTone()` on one pin before calling `tone()` on the next pin.


body:
I have this relay module. I don't understand what is a role of the jumper on it (for now it's shorting the jd-vcc (what??) and vcc pins).

[![Relay][1]][1]

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

title: Description about arduino relay

Answers: 1

body: The jd-vcc pin can be used to power the relay coils using a separate 5V power supply. Why would you want to do that? Each relay coil draws about 73mA @ 5VDC when energized. Theres a circuit schematic on this website: http://howtomechatronics.com/tutorials/arduino/control-high-voltage-devices-arduino-relay-tutorial/


body:
I'm reading two digital inputs and one analog input. For [reasons] I must use `A0` and `A1` as digital ins, and `A2` as an analog in.

I'm uncertain about how the Arduino hardware deals with mixing analog and digital inputs on the same port. For speed, I'm reading like this:

     uint8_t raw = PINC;
     boolean digitalA = (bool)(raw & 1);  // read A0
     boolean digitalB = (bool)(raw & 2);  // read A1
     int analogC = analogRead(A2);

Will the raw reading of the port interfere with the `analogRead` in any way? I did see a caveat about mixing A & D, but it only had to do with noise introduced in the analog ins when doing digital outs. Would reading analog first minimize that?

title: Mixing analog reads with raw port reads

Answers: 2

body:
In general, most embedded processors multiplex external pins into specialized internal circuits.  Circuits which check standard fixed threshold crossings (digital inputs), circuits which check variable threshold crossings (comparators) and circuit which combine comparators with a variable settable reference (analog to digital converter) to name only three.

Usually a pin is multiplexed to a particular internal circuit only once during initialization.  Switching between internal circuits as part of normal operation is tricky and can lead to unexpected results.

Analog reads are often problematic because of noise.  However, it is unlikely that reading the state of a digital input will effect the conversion of the ADC circuit.

It would be far more effective to read the actual processor's application note you are using and understand that processor's ADC issues.  You may be surprised that the number is significant bits (usable bits) are less than the number found in the ADC register.  Or that you can increase the number of significant bits simply by adding averaging to your software.

body:
What you are trying to do is perfectly safe. In fact, you reading `PINC`
will have _no effect whatsoever_ on the input circuitry. You are just
reading an I/O register and, whether you read it or not, this register
is updated on every clock cycle from a set of comparators that monitor
the pin voltages.

Just for completeness, I should mention that it is _possible_ to disable
the comparators that update the register. The Atmel datasheet recommends
to disable them if you want the lowest possible ADC noise. If you follow
that recommendation, then reading `PINC` will just return zero. The
Arduino core library does not disable them: the input comparators are
thus always active, and you can get a meaningful value by reading that
digital input register.

**Edit**: You can _selectivly_ disable the input comparator on the pin
`A2` by issuing `DIDR0 |= _BV(ADC2D);`. But that is only useful if you
really need to maximize the accuracy.


body: I'm almost a beginner to microcontrollers and have done a few simple projects, but this time I have to use an Arduino Uno (powered by a battery) to support an RFID reader (RC522), a Zigbee module and a touch screen altogether. Apparently there are too few pins to support all the modules. What is the easiest way to implement such a system?

title: Can I use an Arduino Uno to support an RFID reader, Zigbee module and a touch screen at the same time?

Answers: 1

body:
Also I don't know what the RFID, zigbee and touch screen uses (generic GPIO pins, I2C, SPI, something else)?

You always can combine multiple inputs/outputs using a multiplexer (i.e. 74HC165, 74HC595), although it will mean extra software and less performance.

About the touch screen, that might be problematic regarding performance and memory usage, since the Uno has only a few KB and even the more expensive Arduino's do not have that much memory you might need.


body:
What I am after is a reliable way of telling whether the GSM900 shield is powered up or not.  "Obviously" the shield power is the constant green light.  But i'm talking about the red light on the other side (next to the flashing green light).

I know i can PowerUp/Down by using the code

    digitalWrite(9, HIGH);
    Serial.println("write 9 high");
    delay(1000);
    digitalWrite(9, LOW);
    Serial.println("write 9 low");
    delay(5000);

And from the AT command manual, I can Power it down by using the command...

    AT+CPOWD=1

So it seems that the only way I can ensure that the board is On, is to power it down and then toggle the power.  Surely there's a better way than that?

Another idea is to issue a simple "AT" command, and if I get back "OK" then its on, and if I dont get anything back (timeout of maybe 2 seconds), then its off - thoughts?

title: How can i tell the power status of a GSM900

Answers: 0


body:
I'm using several ACS712-based 5A current sensors. They're non-polar and so (I gather) the output is biased to Vcc/2 to allow a swing in either direction. The sensor outputs +/- 185mV/A, plus the bias.

The example sketch I've seen does a computation like `amps = ((analogRead(A0) * 5.0) / 1023) - 2.5` (where 2.5v is the bias).

In my case the actual current value and polarity aren't important, just the presence of current. Is there anything untoward about doing this instead?

    boolean isCurrent = (abs(analogRead(A0) - 512) > thresholdValue);

This avoids floating point (unless `abs()` forces it?) and an ADC count of 512 should be equivalent to a bias of Vcc/2. The threshold just cores out some noise / jitter / drift. Seem OK? Can anyone suggest a better approach?

title: Where to remove an ADC bias?

Answers: 1

body: No, there is nothing untoward about that - it is perfectly acceptable and, in fact recommended, since as you note it uses no floating point.


body:
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.

title: Servo motors suddely stopped moving and a clicking sound can be heard

Answers: 0


body:
I am looking to add block detection to my model railroad. I need approx. 40 infrared sensors to power 40 LED's on my control panel. No signals or other logic required *yet*, just the LED indications -LED- on=occupied  off=vacant.
How many Uno boards would I need to do this? I may, in the future, look at integrating several two (or three) aspect signals down the track. I am an absolute novice here, never having used an Arduino, nor done any coding of any sort.

title: How many Infrared sensor modules can be added to a single Arduino (eg;Uno)

Answers: 1

body:
You just want to know how many you can attach to an Arduino board or how many Arduino Uno boards you need, but it does not work like that.

Some sensors with a led require 5mA or 10mA or 20mA. The reflective optical sensors use a IR (InfraRed) led. The Arduino Uno 5V pin can probably not supply enough current for 40 leds. Therefor you might need a seperate power supply.
I think the TCRT5000 is typically set at 10mA.

The Arduino Mega 2560 and the Arduino Due have many pins. But with 40 TCRT5000 sensors, the total current is too close to the limit.

In such situation often extra hardware is added. You can use one Arduino Uno board, with extra hardware for multiple inputs or outputs.

An "**expander**" is a chip or a module that connects to the Arduino with a few wires, but has many input and/or output pins. For example a "expander" with I2C interface to the Arduino Uno as mentioned by @matsk. Although a I2C expander has a slow I2C interface, they are sometimes smart and can tell which pin has changed by reading a single byte.

"**Shift registers**" are chips with for example 8 input pins or 8 output pins. The data of the pins is shifted into the chip with a data and clock signal. There are many examples for that: [ShiftOut with a 74HC595][1].

A analog "**multiplexer**" or "mux" is a chip that can connect one common pin to one of 8 pins. The signal can go both ways. [Nick Gammon about a multiplexer][2].

A "**ADC**" is short for "Analog to Digital Converter". The Arduino Uno has an internal ADC, but also a external ADC can be used. They have often more than one analog input.

"**Polling**" is when an Arduino is reading many inputs continuously one by one. If for example it takes 5ms to read a sensor, then 40 sensors take 200ms. That means that every sensor is read once per 200ms. If a train would pass within that 200ms, then it might be not detected.
The opposite of polling is with interrupts. If an external event happens, it could trigger an interrupt and the Arduino can react right then at that very moment. However, 40 interrupts is not possible.

**Conclusion:**
The best way depends on your hardware and software skills, on the maximum interval that you want to read the sensors, on the sensors themself, and how far apart the sensors are, and if you want 40 wires to a Arduino board.
The best Arduino board also depends on what you want to do with the data and what else the Arduino has to do.
Some sensors have a analog output and some a digital output. It depends on your situation and the way the train is detected.
If possible, then I would choose a solution where all the hardware can be easily be replaced. If the sensor has digital outputs, then I would connect them to a Arduino Mega 2560 or Arduino Due.

  [1]: https://www.arduino.cc/en/Tutorial/ShiftOut
  [2]: https://www.gammon.com.au/forum/?id=11976


body:
I try to make a weather station, but I don't understand why it doesn't work. I had tried to read a lot of the sensors but I doesn't find my errors.

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

  The code:

 #include "DHT.h"
 #include "SFE_BMP180.h"
 #include "Wire.h"
 #include "MQ135.h"
 #include "SPI.h"
 #include "Adafruit_GFX.h"
 #include "Adafruit_ILI9341.h"

 #define DHTPIN 2
 #define DHTTYPE DHT11
 DHT dht(DHTPIN, DHTTYPE);

 SFE_BMP180 bmp180;
 double PresionNivelMar=1013.25;

 int UVOUT = A3;
 int REF_3V3 = A1;

 #define PIN_MQ135 A0
 MQ135 mq135_sensor = MQ135(PIN_MQ135);

 #define TFT_DC 9
 #define TFT_CS 10
 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

void setup() {
  Serial.begin(9600);
  dht.begin();
  if (bmp180.begin())
          Serial.println("BMP180 iniciado correctamenten");
        else {
          Serial.println("Error al iniciar el BMP180");
        }
  pinMode(UVOUT, INPUT);
  pinMode(REF_3V3, INPUT);

  tft.begin();
  tft.setRotation(0);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_DARKGREEN);
  tft.setTextSize(2);
  tft.setCursor(70,20);
  tft.print("S.E.M.S.");
  tft.setTextSize(1);
  tft.setTextColor(ILI9341_WHITE);
  tft.setCursor(20,310);
  tft.print("Colegio Panamericana");
  tft.setTextSize(1.5);
}

void loop() {
  char a;
  double T,P,A;
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float rzero = mq135_sensor.getRZero();
  float correctedRZero = mq135_sensor.getCorrectedRZero(t, h);
  float resistance = mq135_sensor.getResistance();
  float correctedresistence = mq135_sensor.getCorrectedResistance(t, h);
  float ppm = mq135_sensor.getPPM();
  float correctedPPM = mq135_sensor.getCorrectedPPM(t, h);

  Serial.println();
  Serial.print("Temperatura: ");
  Serial.print(t);
  Serial.print(" °C ");
  Serial.println();
  Serial.print("Humedad: ");
  Serial.print(h);
  Serial.print(" %RH");
  Serial.println();

  a = bmp180.startTemperature();
  if (a != 0) {
    delay(a);
    a = bmp180.getTemperature(T);
     if (a != 0) {
         a = bmp180.startPressure(3);
        if (a != 0) {
                  delay(a);
                        a = bmp180.getPressure(P,T);
                 if (a != 0) {
                  A= bmp180.altitude(P,PresionNivelMar);
                 }
              }
           }
       }

  Serial.print("Temperatura: ");
  Serial.print(T);
  Serial.print(" °C , ");
  Serial.println();
  Serial.print("Presion: ");
  Serial.print(P);
  Serial.print(" mb");
  Serial.println();
  Serial.print("Altitud: ");
  Serial.print(A);
  Serial.print(" m s.n.m.");
  Serial.println();

  int uvLevel = averageAnalogRead(UVOUT);
  int refLevel = averageAnalogRead(REF_3V3);
  float outputVoltage = 3.3 / refLevel * uvLevel;
  float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0);

  Serial.print("Output: ");
  Serial.print(refLevel);
  Serial.print(" v");
  Serial.println();
  Serial.print("ML8511 output: ");
  Serial.print(uvLevel);
  Serial.print(" v");
  Serial.println();
  Serial.print("ML8511 voltage: ");
  Serial.print(outputVoltage);
  Serial.print(" v");
  Serial.println();
  Serial.print("UV Intensity (mW/cm^2): ");
  Serial.print(uvIntensity);
  Serial.println();
  Serial.print("MQ135 RZero: ");
  Serial.print(rzero);
  Serial.println();
  Serial.print("Corregido RZero: ");
  Serial.print(correctedRZero);
  Serial.println();
  Serial.print("Resistance: ");
  Serial.print(resistance);
  Serial.println();
  Serial.print("Corregido Resistencia: ");
  Serial.print(correctedresistence);
  Serial.println();
  Serial.print("PPM: ");
  Serial.print(ppm);
  Serial.println();
  Serial.print("Corregido PPM: ");
  Serial.print(correctedPPM);
  Serial.println("ppm");
  Serial.println();

  escribir(14,40,1,"ILI9341_GREEN","Temperatura");
  escribir(14,60,0.6,"ILI9341_RED",String(t));
  escribir(14,60,0.6,"ILI9341_RED","°C");
  escribir(14,80,1,"ILI9341_GREEN","Humedad");
  escribir(14,100,0.6,"ILI9341_BLUE",String(h));
  escribir(14,100,0.6,"ILI9341_BLUE","%RH");
  escribir(14,120,1,"ILI9341_GREEN","Presión");
  escribir(14,140,0.6,"ILI9341_LIGHTGREY",String(P));
  escribir(14,140,0.6,"ILI9341_LIGHTGREY","psi");
  escribir(14,160,1,"ILI9341_GREEN","Calidad del Aire");
  escribir(14,180,0.6,"ILI9341_CYAN",String(correctedPPM));
  escribir(14,180,0.6,"ILI9341_CYAN","ppm");
  escribir(14,200,1,"ILI9341_GREEN","Radiación UV");
  escribir(14,220,0.6,"ILI9341_MAGENTA",String(uvIntensity));
  escribir(14,220,0.6,"ILI9341_MAGENTA","mW/cm^2");
}

int averageAnalogRead(int pinToRead) {
  byte numberOfReadings = 8;
  unsigned int runningValue = 0;
  for(int x = 0 ; x < numberOfReadings ; x++)
          runningValue += analogRead(pinToRead);
          runningValue /= numberOfReadings;
    return(runningValue);
}

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void escribir(int X,int Y, int tam, short color, String mensaje){
  tft.setCursor(X,Y);
  tft.setTextSize(tam);
  tft.setTextColor(color);
  tft.print(mensaje);
}

Also I adds a little screen.

I make this:

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

Sorry for the size, the original image was too heavy to upload, in addition to the disorder.

I bought on: naylampmechatronics.com .
And I used his information.
And I read a bit of adafruit.com

  [1]: https://i.stack.imgur.com/GOeUo.png
  [2]: https://i.stack.imgur.com/GogiK.jpg

title: The sensors don't send correct data

Answers: 1

body:
The method for troubleshooting is:

 1. Disconnect everything.

 2. Add one sensor.

 3. Verify if the sensor works.

 4. If it works repeat step 2 for next sensor.

 5. If it doesn't work, why? is it the connections correct?


body:
I found this great code to pick a random number from a "hat" without repeat:

    /* RandomHat
      Paul Badger 2007 - updated for Teensy compile 2017
      choose one from a hat of n consecutive choices each time through loop
      Choose each number exactly once before reseting and choosing again
    */

    #define randomHatStartNum 0  // starting number in hat
    #define randomHatEndNum 25    // ending number in hat - end has to be larger than start
    #define numberInHat (randomHatEndNum - randomHatStartNum) + 1

    void setup()
    {
      Serial.begin(9600);
      Serial.println("start ");
    }

    void loop()
    { // randomHat test
      for (int i = 1; i <= numberInHat; i++) {
        int x = randomHat();
        Serial.print(x);
        Serial.print(", ");
        delay(50);
      }
      Serial.println(" ");
    }

    int randomHat() {
      int thePick;    //this is the return variable with the random number from the pool
      int theIndex;
      static int currentNumInHat = 0;
      static int randArray[numberInHat];

      if  (currentNumInHat == 0) {                  // hat is emply - all have been choosen - fill up array again
        for (int i = 0 ; i < numberInHat; i++) {    // Put 1 TO numberInHat in array - starting at address 0.
          if (randomHatStartNum < randomHatEndNum) {
            randArray[i] = randomHatStartNum + i;
          }
        }
        currentNumInHat = abs(randomHatEndNum - randomHatStartNum) + 1;   // reset current Number in Hat
        Serial.print(" hat is empty ");
        // if something should happen when the hat is empty do it here
      }

      theIndex = random(currentNumInHat);                  //choose a random index from number in hat
      thePick = randArray[theIndex];
      randArray[theIndex] =  randArray[currentNumInHat - 1]; // copy the last element in the array into the the empty slot
      //                                                     // as the the draw is random this works fine, and is faster
      //                                                     // the previous version. - from a reader suggestion on this page
      currentNumInHat--;    // decrement number in hat
      return thePick;
    }

I would like to use a custom array to choose from like so:

    char *things[]={
    "Thing 1",
    "Thing 2",
    "Thing 3",
    "Thing 4",
    "Thing 5",
    "Thing 6",
    };

Which is quite possible as I use the numbers from to first piece of code to select items from my custom array.

So I have two questions about this:

The first being the code first returns "hat is empty" before the numbers.

    start
      hat is empty 11, 24, 17, .......
      hat is empty 4, 19, 23, .......

 Is there a way to reverse this?

And secondly, I would like define the `randomHatEndNum` automatic by the lenght of my custom array, but I have trouble implementing that code. What is the right way to approach this?

title: Select from Custom Array without Repeat

Answers: 1

body:
> The first being the code first returns "hat is empty" before the
> numbers.

Well, you have to comment out the line

    Serial.print(" hat is empty ");

> I would like define the randomHatEndNum automatic by the lenght of my
> custom array,

To get the size of an array, the standard idiom is

    const int numberInHat = sizeof(things) / sizeof(things[0]);

I rewrote your sketch.

The idea is use randArray to store all the remaining values to return. Then, randomly pick one value (to return) and replace randArray with -1, which signal that the value has been returned, so don't return it again.

The best for functions returning random values is always work in the range 0..n, and adjust that value in the calling code if you need some other range (like 1..n+1). It's simplier and simplify debugging.

    /* RandomHat
      Paul Badger 2007 - updated for Teensy compile 2017
      choose one from a hat of n consecutive choices each time through loop
      Choose each number exactly once before reseting and choosing again
    */

    char *things[]={
    "Thing 0",
    "Thing 1",
    "Thing 2",
    "Thing 3",
    "Thing 4",
    "Thing 5",
    "Thing 6",
    };

    const int numberInHat = sizeof(things) / sizeof(things[0]);

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

    void loop()
    { // randomHat test
      for (int i = 0; i < numberInHat; i++) {
        int x = randomHat();
        Serial.print(x); Serial.print(" ");
        Serial.println(things[x]);
        delay(50);
      }
      Serial.println("----");
    }

    int randomHat() {
      int thePick = -1;    //this is the return variable with the random number from the pool
      int theIndex;
      static int left = 0;
      static int randArray[numberInHat];

      if  (left == 0) {                                // hat is emply - all have been choosen - fill up array again
        for (int i = 0 ; i < numberInHat; i++) {    // Put {0, ..., n} into randArray.
            randArray[i] = i;
          }
        left = numberInHat;
      }

      // bEmpty always false at this point.
      while (thePick == -1) {
        theIndex = random(numberInHat);                  //choose a random index from number in hat
        thePick = randArray[theIndex];
       }

      left--;
      randArray[theIndex] =  -1;        // value theIndex is not longer available.
      return thePick;
    }


body: I need to know when a 3 phase AC submersible pump is turned on, for the sake of logging it to a online database. Thing is, I do not know how tell if it is ON, or OFF. I've given a thought to using a current transformer, specifically the "STC-013-30" one, but it requires to be wrapped around one of the AC wires (live/neutral) but the motor i have has both the wires insulated together forming a single, huge wire. Plus, its 3 phase, and I do now know if the STC can detect 3 phase currents. Can it be done some way? Can I utilise some other tool to tell if the motor is ON?

title: Detect if a 3 phase AC submersible pump is on

Answers: 2

body:
The long and short of it is that you need to measure the current. And there's two basic methods of doing that, and both require access to just one of the wires in the cable.

So you will either have to take a knife to your cable and *carefully* remove a section of the outer insulation to access the wires within it, or create some kind of adaptor cable that the existing cable plugs into (however that is done on your system) to allow access to the individual wires.

Then it's a case of either:

* Use the magnetic field of one wire to monitor the current (current transformer) or
* Introduce a shunt resistance into the current path and measure the voltage drop across it.

The first option is by far the safest.

Alternatively there may well be some form of commercial three-phase power monitor with an output that you can monitor to achieve what you want with less danger of electrocuting yourself and others in the process.

body:
It's likely that the power to the motor is originating at a panel with breakers. You should be able to confirm that only one breaker set is being used to power the pump motor. At that location, all the wires are separated.

If you do not have the necessary skill to identify the correct wires, consider to consult an electrician. It is advisable to remove power to the panel before you begin to insert your fingers to wrap the sensor wire around the correct lead.


body:
I am trying to make my own library and it uses some local variables with the same name as some variables in ino. Compiler complains about it. I stripped it to (nonsence but simple) example

**mylib.h:**

    #ifndef MYLIB_H
    #define MYLIB_H
    int doit();
    #endif

**mylib.cpp:**

    #include "mylib.h"
    int value;
    int doit(){
     return value++;
    }

**example.ino:**

    #include "mylib.h"
    int value;
    void setup(){
     value=3;
     pinMode(13,OUTPUT);

    }
    void loop() {
     digitalWrite(13,(value==doit()) );
    }

**compiling:**

    $ make
    /usr/bin/avr-gcc -Os -Wl,--gc-sections -mmcu=atmega328p example.o mylib.o .lib/arduino.a -lm -o example.elf
    mylib.o:(.bss.value+0x0): multiple definition of `value'
    example.o:(.bss.value+0x0): first defined here
    collect2: error: ld returned 1 exit status
    /home/gilhad/GIT/HW/Arduino/minipro//../Arduino.mk:436: recipe for target 'example.elf' failed
    make: *** [example.elf] Error 1

----------
I am **not** usint the `value` in the `.h` file, so why it collides with similary named variable from another module?

Should not be it private to the module until exposed via `.h` file?

title: multiple definition of local variable in linking

Answers: 2

body:
The common practice is to [write Arduino libraries][1] using C++ classes:

> The core of the header file consists of a line for each function in
> the library, wrapped up in a class along with any variables you need.

    class Morse
    {
      public:
        Morse(int pin);
        void dot();
        void dash();
      private:
        int _pin;
    };

In this way you can specify what is private (variables and methods only seen within the class) and what is public (variables and methods that can be seen outside the class).  In the given example, the variable called "_pin" is private to the class Morse.

In your case, you would want to make a private class variable called "value".  Because it is private, you are free to re-use the name when not inside the class.

  [1]: https://www.arduino.cc/en/Hacking/LibraryTutorial

body:
> I am not usint the value in the .h file, so why it collides with similary named variable from another module?
>
> Should not be it private to the module until exposed via .h file?

The quick answer is that a source code file is not a separate unit. The last step in the build process is to link all the object file and create the executable binary. The linker will need to resolve all the symbols. In this case there are two definitions and the compiler cannot resolve the references. The linker can be told to ignore multiple definitions.

The keyword "static" will make the symbol local to the compiled unit (object file). As the keyword "external" tells the compiler that the definition is in another compiled unit. Header files is just a structuring convention. The language does not actually say anything about this. It is a pre-processor (cpp) in the build process that creates the combined source code for the compiler.

C++ (and OOP) adds a number of ways to control the visibility of symbols (aka [encapsulation][1]). In a class definition the keywords "public", "protected" and "private" may be used. Also the keyword "static" may be used. In this case it means that the symbol is defined globally for the class (class variable) and not per instance (member variable).

The keyword "static" in C/C++ is actually a "recent" development of the languages. In the early versions of C local symbols where prefixed with [underscore][2] "_local". This is still a common practice even though the object files contain much more scope information today.

Cheers!

  [1]: https://en.wikipedia.org/wiki/C++#Encapsulation
  [2]: https://stackoverflow.com/questions/2627511/why-do-c-compilers-prepend-underscores-to-external-names


body:
I use Arduino Leonardo board for virtual keyboard. Everything work fine, but when my local keyboard layout is russian it's not work how I want. This is my code

    Keyboard.print("cmd");
    typeKey(KEY_RETURN);
    delay(2000);
    Keyboard.print("powershell iwr -outf %TEMP%\\index.html http://google.com");
    typeKey(KEY_RETURN);

Otput in English US keyboard layout:

    cmd
    powershell iwr -outf %TEMP%\index.html http://google.com

Output in Russian keyboard layout

    сьв
    зщцукырудд шцк -щгеа %ЕУЬЗ%\штвучюреьд реезЖ..пщщпдуюсщь

Is there a way to make Arduino Leonardo to write every time in English US keyboard layout no matter what keyboard layout uses my computer?

title: Arduino Leonardo keyboard

Answers: 1

body:
The Arduino Leonardo, in the same way as any keyboard, just sends keystroke data. It is down to your computer's operating system to translate those into individual letters and symbols. The Leonardo (and indeed any keyboard) has no say over how the operating system does that translation.

A brief google search (which led back to Stack Exchange) found me [this project](https://www.codeproject.com/Articles/20994/Using-multiple-keyboards-with-different-layouts-on) which may be of some interest. It allows you to automatically change the selected keyboard language depending on which keyboard is being used at any one moment in time.


body:
I'm going to build a **8x8x8 Led RGB Cube**, therefore I will need a **lot of Power** which the **arduino can't handle**, so I'm using a **12V** 20A (I know 20A isn't necessary but I had one laying around).

So the question is, is it possible to power the arduino over the Vin Pin with the 12V and program / communicate over serial connection in the same time? Like a real time programmed RGB LED Cube.

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

<!-- End schematic -->

title: Power Arduino with 12V while using Serial Communication over USB

Answers: 2

body:
I'm now starting to doubt what I though about Arduinos.
If you are using a 12V PSU to power the Arduino, you are only going to get 5V out of the vOut pin.  The 20Amps you are supplying isn't going to come out either, all you'll get is ~300mA from the vOut or ~20mA from the digital pins. This is because of all the regulators.

If you want to get the Arduino to switch LEDs on and off from another source you are going to need **transistors**.  This will let you switch different voltages and higher currents.

body:
**How to power an Arduino**

Arduino can manage multiple power inputs at the same time while fully operational (incluide Serial - USB connection to the PC).

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

**JAPAN JACK socket:** an external source (a power supply, usually) must be connected to this socket, with the positive pole going to the central part of the jack, and the value must be ranging between 6 V and 20 V, even though the range recommended by the manufacturer is 7÷12 V, thus it is not advisable to use voltages that are lower than 7 V or greater than 12 V, if not in the case of a real need; 6 V may not guarantee a proper stabilization on the part of the regulator, it is in fact needed to consider the voltage fall of the protection diode, placed in series at the regulator’s input (whose purpose is to preserve the board from destruction in the case of polarity inversion on the jack); while values above 12 V would create an excessively high drop-out (an electric potential difference between the regulator’s input and output) that would cause a pointless overheating of the regulator, even with low levels of current draw.

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


body:
I burned the bootloader in ATtiny45 with the Arduino tool.

1. I want to know how much memory it has taken.
2. Is this bootloader the same code of a bootloader used in the 328P or other chips?
3. Can I see this code in any way, to know how it works?

title: How do I know the size of the bootloader of ATtiny? Is it the same as ATMega328P?

Answers: 1

body:
> 1) I want to know how much memory it has taken

Look to see how big the bootloader is. If it's a HEX file you will either want to load it into a HEX (Intel HEX, not hexadecimal representation) file editor, or convert it to binary with `avr-objcopy`.

    $ avr-objcopy -I ihex <hex file> -O binary <bin file>

> 2) and if this bootloader is the same code of a bootloader used in the 328P or other chips

No, each chip requires its own special bootloader - simply because all chips are different: that's why they exist.  If they were all the same there would only be one chip.

> 3) Can I see this code in any way, to know how it works ?

If it's open source and you download the bootloader from wherever it's stored (probably Github somewhere), then yes, you can. Of course, that also assumes that you would understand what you are seeing which, judging by this question, is not that likely.