text:
ESP8266-01 Wifi module + Wifi shield not present + ESP8266-01 libraries not working?
I have Arduino IDE v. 1.8.13.
I bought an ESP8266-01 module which I want to use in my Arduino-UNO board to send fingerprint registration confirmation (ID) via HttpClient to a xampp server since I dont want to store the fingerprint image in the database.
My ESP connection is as below:

In the serial monitor, my AT commands work well when I connect the module to my wifi using AT+CWJAP="ssid","password".
When I upload my code, which is supposed to connect to wifi, it says WiFi shield not present.
Im new to this, is there anything I am missing?
Thanks in advance.
Here is my code:
#include <ArduinoHttpClient.h>
#include <WiFi101.h>
#include "arduino_secrets.h"
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;

char serverAddress[] = "localhost/bel/arduino/scannerstatus/php";  // server address
int port = 80;

WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;

void setup() {
  Serial.begin(9600);
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   // print the network name (SSID);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);
  }

Basically, my uploaded code does not go past the wifi connection stage. Even though the AT commands individually can connect to wifi.
I have tried different ESP8266 libraries and HttpClient libraries but they all seem to not connect to wifi.
Is there any other way to call a php script from arduino without using wifi?

Why are you using wifi101???

WiFi101 library is for Arduino WiFi101 shield. with esp8266 you can use some of the libraries which use a firmware in esp8266

I have tried WiFi.h, WiFi101 (which seems to have come with my arduino). They all dont work. @majenko

Those are for specific hardware. You need to match your library to your device. Or in your case just send serial commands.

I also used 3.3 volts not 5 V

My Arduino library manager search has no result for esp8266-01. Unless the installation process is different. Kindly bear with me I am fairly new to this. I appreciate.

try the WiFiEsp library. but before using it, change the AT+UART speed to 9600

Can you please include some explanation of how the Arduino Uno and ESP8266-01 are connected. You will need to program for the ESP8266 ESP-01 module like shown below,

You will need to write code for the ESP module to connect to the WIFI and listen to its Serial Com Port. The ESP will need to handle the message interpretation & WIFI updating.
The Arduino Uni will not be capable of directly using the ESP-01 module as a WIFI shield. It will need to communicate with the ESP via a serial coms link, you will need to send commands that include instructions & a Message to the ESP from the Arduino.

https://create.arduino.cc/projecthub/jeffpar0721/add-wifi-to-arduino-uno-663b9e - Link to the above image document, this should help explain my concept in more detail
I apologies if my comments above miss the point but with the amount of information provided I don't think I can help further.

Thanks Jack for the quick informative reply. Let me edit the info

dd you here about AT firmware or WiFiLink firmware?


text:
esp2866 powered externally not working
I got a beginner level problem.
I got two esp2866 nodeMCU, they both work with the usb cable and I can get the blink program to run though it.
Running them with external power doesn't seem to work though. I expect the blink program to run when I plug them in but I get no led light signal at all. My power source looks identical to this. I got jumpers set on 5V. I don't have a voltage meter but I've tested against my Arduino Uno and it runs as expected when connected to the same wires.

Shouldn't I get the blink signal or any other led signal if the nodeMCU got power?
Any clue to how I could fail to provide power?

thank you!
edit: picture and jack barrel power input: 5V 3A

Consider editing your question to include decent images of your wiring.

If you're using the barrel jack into that regulator board, the voltage being provided to the barrel jack may also be important to know.

@timemage- done

It seems like the specification of the NodeMCU VIN as working with 5V is very misleading. I have a board that has the same issue as you, and my 5V supply does turn the NodeMCU on, but I can't get the WiFi to broadcast!

Read the answer by @timemage. The voltage going into the board is not 5V but some lower voltage, caused by the voltage drop in the breadboard power supply. Add to that the fact that all NodeMCU's are not created equal, especially when connecting things to their power bus.

Linear Regulator Dropouts
The linear voltage regulators found on that board are going to expect more than 5V at the barrel jack, because they require a minimum "drop out" voltage.  The AMS1117 that is on that board, so far as I can tell, has a drop out voltage up to 1.3V.  So you would want at least 6.3V (perhaps better 7V) at the barrel jack in order to get 5V out of it.
So the NodeMCU board may be seeing 5 - 1.3 or 3.7V at the input to its 3.3V regulator, which also requires its own drop out.  The output of that 3.3V regulator may then be significantly below what the esp8266 specified operating voltage range.
UPDATE
So I did the tests mentioned in the comments, just to illustrate the problem.  And the results are about as expected.
I altered the stock blink sketch that comes with IDE version 1.8.13 to use LED_BUILTIN (as opposed to 9) in the pinMode and digitalWrite calls.
I changed the LOW period, which is LED ON for my board, to 10000ms so that my voltmeter would have time to settle on a voltage test across the LED.
And I uploaded to the board, a NodeMCU 1.0 clone by Hitletgo.
When powered on its USB micro b jack, 3.3V labeled pin of the broad measuring 3.30 V.  The LED color is blue, it is bright and it is dropping 2.66V.
Then I switched to powering the NodeMCU board by via of VIN pins from the YwRobot regulator board.  I provided 5.05V to the barrel jack.  To not great surprise, it does not blink.
The voltage out of regulator board was 3.26V.  To be clear, I have this jumper for 5V.  As a sanity check, I jumpered it for 3.3V and got about 2.5V out of it.  Again, this is unsurprising because it also needs a dropout voltage.
I then measured the "3.3V" header line on the NodeMCU itself to be 2.14 V.  Without sufficient voltage into the 3.3V regulator, it is not providing 3.3V out.  And what it is producing is below that LED forward voltage when lit.  So it is not surprising that it is not lit.
The ESP8266 technical specifications suggest that it can run down to 1.8V.  So just for the hell of it I connected the board back to USB and updated the blink sketch to "blink" D8 (or GPIO15) 4 seconds on, 4 seconds off.  I did not attach anything to this pin except the voltmeter.
I then reconnected the board to the test rig and found with a meter that it is "blinking" D8 just fine with a logic level consistent with the voltage the ESP8266 is actually receiving.
So in summary, the arrangement here is running the ESP8266 but there is not enough available voltage for it to light the LED.  And it is very likely the exact same thing is happening for you.

Thank you, that sounds reasonable. I assume then my Arduino Uno was just flexible enough so it could run on 3.7V.

@bhenriksson, Possibly.  The ESP8266 module may also go lower than the NodeMCU board as whole can.  To take a simple example, if your LED is blue, it's possible your esp8266 is still functioning but unable to get enough forward voltage to turn on the LED.  You're going to want a meter sooner or later.  Sooner probably is best.

@bhenriksson, tell you what: I will try to locate my NodeMCU clone here and the regulator board that I have of that design.  If I'm able to do that, I may update the question with my measurements, as an example. Though it's difficult to say for certain how well this will translate to your exact conditions.  In the meantime maybe try to locate a 7V to 9V adapter and try that.

@bhenriksson, I probably should have mentioned that there's a diode on the on the breadboard voltage regulator board between the barrel jack and the 5V regular that drops additional voltage, very roughly half a volt, which probably explains why the 5V line is lower than the expected minimum of 3.7V.  I did not measure it, though.  I may update it to include that later.

Think of Vin like a car, not enough gas and you will not get there. Over fill it and you could burn it up.

I can confirm the 'burn up' theory.

source: Stack Exchange

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

sort: votes


text:
NodeMCU ESP8266 Ver 0.1 not powering on with VIN
I'm trying to power on my NodeMCU ESP8266 Ver 0.1 (thats what is written in board), via VIN and Ground with my phone charger.
I'm 100% sure that the USB charger is working, providing 5V, and that the ground and VIN are connected to the right positions.
If I use the same phone charger via the NodeMCU USB, the program blinks the builtin led alright.
If I power via VIN, it flashes when I connect the charger to DC, but the program does not work.
It seems as the NodeMCU is not powering on complety.
Bizarrely, if I short 3V and G pins, the board starts working normally as powered directly via USB port.
This is the code
/*
 ESP8266 Blink by Simon Peter
 Blink the blue LED on the ESP-01 module
 This example code is in the public domain

 The blue LED on the ESP-01 module is connected to GPIO1
 (which is also the TXD pin; so we cannot use Serial.print() at the same time)

 Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
                                    // but actually the LED is on; this is because
                                    // it is acive low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}

Just as a follow up:
I've never solved the problem in this specific board, so I ended up buying a newer one which works fine.

what is the expected voltage range ar Vin?

As I know, 5 to 12 V

Can you check the voltage across AMS 1117 when you connect supply voltage to the esp-01 board

Input vs Ground is 3.4-3.6V when connected via VIN. Output vs Ground is 2.5-2.8V when connected via VIN. Input vs Ground is ~4.7V when connected via USB port;  Output vs Ground is ~3.3V when connected via USB port. Using the exactly same brick to test both

I faced the same issue. My problem was on this version of board both ground (G) pins on the side of Vin pin (I say left side of the board when usb is towards bottom direction) do not have connection with the ground of the 3.3v regulator or to the Gnd pin on right side of the board !! No continuity from ground pin to regulator is the problem I understood. The moment I connected 5v between Vin and Right side 'G' pin it started working. Check and try if not resolved yet.

I can confirm the Cherry's experience. The G pins on the left side are not connected with the regulator.

i found one easy solution for this problem after a few days looking for it.
First of all after a few observations on the ESP8266 Nodemcu runing with my usb cable and powered on the Vin pin and after a few measurements on the the power source i found no problem on the system in general but i was able to find one specific details that calles my attention to it.
When i turned on and off my power source fast on the switch button the ESP started properly but when i left off for some time and triggered it just once the Esp gets frozen, and than same test and and bum it's working.
What i figured out after a few researches is the USB have a diferente way to power up the ESP than the Vin, the Vin came with a more directly power source directly to the ESP.
I created a small control circuit with a NPN Transistor PN2222 addin the following configuration:
+5V (from power source) to Collector Pin of the PN2222
+5V to a 330R (resistor) to the Base Pin of the PN2222
Emiter (PN2222) to Vin Pin
This solved my problem.

Interesting problem. The input range for Vin is 5.5 to 10 volts. This link will give you more information: https://www.make-it.ca/nodemcu-arduino/nodemcu-details-specifications/
I would not venture to guess that your board is OK, since you short pins all kinds of nasties can happen. Also you do not state your reference point for your voltage measurements so I assume it is ground but the readings do not appear correct. How are you 100% sure that the USB charger is working, providing 5V, and that the ground and VIN are connected to the right positions. Did you measure it with the load connected? Can the charger output the voltage at the current you require?

I can measure the breadboard powerrails, and they show 5V. I have two boards of the same vendor, both present the same problem (one I haven't shorted at all). I'm 100% sure because I tested load (via SK6812 leds and I can power an arduino too). This charger can output 5, 9 or 12V. 5V is max 3A, I can power a little more than 1 meter of RGBW led strips. This specific board is requiring 5V from the charger. Also, from the link you showed me, the voltage is 4.5V to 10V

Check the ground pin on the ESP and see if it is less then 0,02, if not you have an open or not connected ground connection.

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


text:
Arduino zero programming port recognized as EDBG USB port
I am using Arduino Zero with Windows 10. I tried following the procedure listed in Getting started with Arduino to set up my Arduino/environment, however, when I connect the Zero's Programming Port to my laptop's USB 3.0 port, it detects it as "Atmel Corp. EDBG USB Port" instead of "Arduino Zero Prog. Port" (or something similar) as described under the section "Installing Drivers for the Zero" in the above link. Since it is recognized as an EDBG USB Port, I am unable to burn bootloader or upload sketches using the Programming port as it cannot detect CMSIS-DAP.
when I try to upload a sketch I get the following error:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Zero (Programming Port)"
Sketch uses 23496 bytes (8%) of program storage space. Maximum is 262144 bytes.
Global variables use 3536 bytes (10%) of dynamic memory, leaving 29232 bytes for local variables. Maximum is 32768 bytes.
Open On-Chip Debugger 0.10.0+dev-gf0767a31 (2018-06-11-13:36)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
debug_level: 0
none separate
adapter speed: 400 kHz
cortex_m reset_config sysresetreq
Error: unable to open CMSIS-DAP device 0x3eb:0x2111
Error: No Valid JTAG Interface Configured.
Error: No Valid JTAG Interface Configured.

When I try to burn bootloader I get the following error:
Open On-Chip Debugger 0.10.0+dev-gf0767a31 (2018-06-11-13:36)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
debug_level: 0
none separate
adapter speed: 400 kHz
cortex_m reset_config sysresetreq
Error: unable to open CMSIS-DAP device 0x3eb:0x2111

Error while burning bootloader.

How can I fix this?
So far, I tried

re-installing the IDE several times, and also tried uninstalling the device- but it auto installs the driver when I connect again.
Starting IDE as an admin did not help, although I think the issue is the EDBG CMSIS-DAP is not installed, and instead, the EDBG USB driver is installed

what I would try:  select EDBG programmer in Tools menu and Burn bootloader or Upload with programmerr

@Juraj, I did select EDBG programmer, chose the right board, and port when I got the error messages.

is it a genuine Arduino Zero? please add a link to a page where you bought it

I bought it a while ago and based on the confirmation email, I bought it from Arduino LLC and the email was from  "Arduino Store USA store-usa@arduino.cc"

ok. are you sure the USB cable good?

Yes, I tried several of them.

I don't have one of these to test with, but in looking at the driver installation instructions, I would expect it to say "EDBG Virtual COM Port" before a driver is installed and "Atmel Corp. EDBG CMSIS-DAP" after the driver is installed.
The "Arduino Zero Programming Port" is something I expect only appears in the Tools/Port menu in the IDE, despite what it says in the article.  You can see this name given in the boards.txt file.  And this makes sense to me, given that the EDBG firmware is Atmel's not Arduino's and there appears to be no indication in the driver directory, the content of the INF files, to suggest that they they're providing their own customized driver for the programming port.  So I would trust what you see in the images, suggesting it should say CMSIS-DAP without mention of "Arduino Zero" at all.  So far as I can tell, you're not doing anything incorrect driver-wise, but I'm also not seeing everything.
In any case, it appears you should have the VID (03eb) and PID (2157) in the device properties that boards.txt instructs the IDE to look for:
arduino_zero_edbg.name=Arduino/Genuino Zero (Programming Port)
  1 arduino_zero_edbg.vid.0=0x03eb
  2 arduino_zero_edbg.pid.0=0x2157

However, your error mentions PID=2111.  I looked this up in a USB VID/PID database, and it mentions the an ATMEL Xplained board, which is not a completely unrelated thing, but this VID:PID are not mentioned in the driver information or boards.txt for the Arduino Zero.
I did find this one mention that the Xplained USB PID was used on the M0 Pro which is a different beast from the Zero.
In any case, I would not worry about not seeing something like "Arduino Zero Prog. Port" in device manager itself for the programming port.
Make sure you are using Zero and not M0 Pro.  If you have the M0 pro, in which case properties in Device Manager may show PID as *2111, I'm not sure what to suggest except that maybe you should install Microchip Studio since this seems to be the only way I can find to get the Xplained EDBG drivers.  Some work may still be required after that to get it to work in the IDE.
If you have a Zero and not M0 Pro installing Microchip Studio may also install the EDBG driver for it as well, although this really shouldn't be necessary.

Thanks! that makes sense. Although I have retrieved the "board info" multiple times in the past, I just now noticed that it says
BN: Arduino M0 Pro (Programming Port)
VID: 03eb
PID: 2111
SN: FFFFFFFFFFFFFFFFFFFF

@jiggling_electrons, interesting serial number (I assume that's what SN is).  I don't know what to make of that, but yeah, it sounds like you need to use the Xplained Pro driver and who knows what from there.  It may be possible for you to alter the PID values the driver .INF and boards.txt file in order to get the IDE to work with it.

@jiggling_electrons,  Or perhaps better, don't mess with the PID in the INF file.  Instead, get the Xplained driver by installing Microchip Studio (I think),  and then modify boards.txt in order to get the IDE to recognize the board, if necessary, after that.

@jiggling_electrons, so is it a M0 Pro or a Zero? can you upload over bootloader when you select M0? what was on the invoice? the boards are very similar at first look.

@Juraj, based on the link pointed by timemage, the board is Zero Pro :(, its programming port says M0 Pro but Native USB is Zero. I am not able to upload even if I select the M0 Pro as the board. I also downloaded the Atmel Studio but I am trying to figure how to upload without an ICE or select the EDBUG. My invoice says Zero.

@jiggling_electrons, without going into detail I have found a few other things and have other questions.  But it's going to be a back and forth.  If you find me on freenode I'll try to help.  Whatever relevant and useful parts can be written up here, but I suspect there will be a bunch of rabbit holes that would otherwise make a mess of the question and answer.

post on forum https://forum.arduino.cc/index.php?topic=715160.msg4804484#msg4804484

@timemage, did you get my pings on freenode? we can also discuss instead on discord jiggling_electrons#1370 or in the arduino forum forum.arduino.cc/index.php?topic=715160.msg4804484#msg4804484, pointed as well by Juraj above.

I did.  That is where to find me, I just wasn't around at the time.


text:
Why does a pull down resistor configuration not destroy the pin it's connected to?
I don't understand why a pull-down resistor connected to ground would prevent a pin connected to 5V through a button would not destroy the pin as the current does not need to go through the resistor to get to the pin. I've tried looking online but the question was never asked and I couldn't find any information that explained how it works.
I'm asking this in the context of something without internal resistors so it would have no protection against a short circuit/being connected straight to a source.

When you have a pin in INPUT mode it is high impedance. That means that to all intents and purposes, to the outside world, the pin is not connected to anything internally.
In reality it is, but that internal connection is of such a high impedance (i.e., resistance) that it is almost equivalent to an open circuit.
It's simplest to think of an input pin as a voltmeter.  A pulldown resistor and button would look like this:

simulate this circuit – Schematic created using CircuitLab
When the button is opened the voltmeter reads zero, because one end is connected to ground, and the other end is connected to ground through the resistor.
However when you press the button the voltmeter reads the voltage across the resistor - that is, 5V - because one end is connected to ground and the other to 5V, with a resistor across it.
If you don't have the resistor then the voltmeter can't measure anything when the button isn't pressed - it's just waving around in the air without a clue what it's doing - and a wire waving around in the air is called an antenna...
The Arduino is that voltmeter. All it does is detect the voltage at the pin, it doesn't conduct any (or only a very very tiny amount of leakage) current through the pin.
Now the possibility of a short circuit comes when you set the pin to OUTPUT. If you drive the pin LOW then the pin is essentially connected to GND, and pressing the button will connect the 5V straight to GND through the LOW-driven IO pin.

good analogy...

A pullup or pulldown wire would destroy the pin because it would source or sink enough current to burn out the pin driver.  But a pullup or pulldown resistor limits the current to a very small value (I = E/R = 5v/10000Ohm = .0005A or .5 ma, well within the pin driver's 20 ma limit.


text:
Digital Comparator with ATTiny85 doesn't behave as expected
Here is my schematic:

I've removed the resistors from the LEDs to make it smaller.
The 1 and 2 on the left are outputs from the arduino (which supplies the VCC and ground).
These 1 and 2 are HIGH or LOW and I want the leds to turn on according to this table:
┌───────┬────────────────────┐
│ INPUT │ OUTPUT             │
├───┬───┼──────┬──────┬──────┤
│ A │ B │ Led1 │ Led2 │ Led3 │
├───┼───┼──────┼──────┼──────┤
│ 0 │ 0 │ 1    │ 0    │ 0    │
│ 1 │ 0 │ 0    │ 1    │ 0    │
│ 0 │ 1 │ 0    │ 0    │ 1    │
│ 1 │ 1 │ 1    │ 0    │ 0    │
└───┴───┴──────┴──────┴──────┘

And this is the code I am using with the ATTiny85
const int pinA = PB3;
const int pinB = PB4;
const int pinOut1 = PB2;
const int pinOut2 = PB1;
const int pinOut3 = PB0;

void setup() {
    pinMode(pinA, INPUT);
    pinMode(pinB, INPUT);
    pinMode(pinOut1, OUTPUT);
    pinMode(pinOut2, OUTPUT);
    pinMode(pinOut3, OUTPUT);

    int a = digitalRead(pinA);
    int b = digitalRead(pinB);

    if (a == b) {
        digitalWrite(pinOut3, HIGH);
    }
    else if (a == HIGH) {
        digitalWrite(pinOut1, HIGH);
    }
    else {
        digitalWrite(pinOut2, HIGH);
    }
}

With this set up, I get this output:
┌───────┬────────────────────┐
│ INPUT │ OUTPUT             │
├───┬───┼──────┬──────┬──────┤
│ A │ B │ Led1 │ Led2 │ Led3 │
├───┼───┼──────┼──────┼──────┤
│ 0 │ 0 │ 1    │ 0    │ 0    │
│ 1 │ 0 │ 0    │ 1    │ 0    │
│ 0 │ 1 │ 1    │ 0    │ 0    │ <- See the difference
│ 1 │ 1 │ 1    │ 0    │ 0    │
└───┴───┴──────┴──────┴──────┘

I think it has something to do with the fact that the ATTiny gets powered on if you supply 5v to one of the input pins too and not to VCC.
And yes, I keep restarting the board (by pulling out the VCC pin and seeing the led turn off).
I've also tried connecting A and B to VCC and ground both in all possible positions. Here I noticed that connecting A (or B) to 5v (of the arduino) while VCC is not connected, the board will turn on.
I hope this is enough info.

The outputs are simple logic with 10k series in R’s to avoid latchup.  L1=XNor<A,B, L2=A&!B , L3 =!A&B

"I've removed the resistors from the LEDs to make it smaller." - Your comment refers to the schematic, not to the circuit as built, is that right?

Yes, just the schematic, I noticed the bad phrasing but didn't bother to edit it.

I see nothing wrong in your code, except a terrible design decision that
forces you to reset the ATtiny every time you want to change its inputs.
I guess, then, that the problem is in the way you use it. For example,
let's say you are testing the lines of the table one by one. Once you
are done with the second line and decide to move to the third, let's say
that you:

power-cycle the ATtiny
set its A input to LOW
set its B input to HIGH.

The ATtiny could very well be reading its inputs right between the steps
2 and 3 above. It would then see both inputs LOW and do what it is
supposed to do in that case. This is called a race condition, and
usually leads to bugs that are very hard to find.
The right way to use this particular program is to never remove the
power and:

set the new inputs
pulse the RESET pin of the ATtiny LOW for a few microseconds.

Of course, it would be way better to have a sensible design that doesn't
force you to reset. C.f. Ahmed M.Zahran's answer. For this kind of
trivial problem (just a truth table implementation) I prefer to
implement the solution in plain C:
#include <avr/io.h>

static const uint8_t truth_table[] = {1, 2, 4, 1};

int main(void)
{
    DDRB = 0x7;  // PB0..PB2 as outputs
    for (;;) {
        uint8_t input = (PINB >> 3) & 0x3;  // the 2 input bits
        PORTB = truth_table[input];  // send output to the LEDs
    }
}

If you are worried about power, put the ATtiny to sleep and wake it up
on a pin change interrupt. But be sure to have the simple version
working first, before you worry about power saving and sleep modes.

I think it has something to do with the fact that the ATTiny gets powered on if you supply 5v to one of the input pins too and not to VCC.
And yes, I keep restarting the board (by pulling out the VCC pin and seeing the led turn off).
Here I noticed that connecting A (or B) to 5v (of the arduino) while VCC is not connected, the board will turn on.

All of the above is roughly translated into "I am frying my chip and don't know why it does not work".
Look at "absolute maximum ratings" in datasheet:
"Voltage on any Pin except RESET with respect to Ground -0.5V to VCC+0.5V"
In short, you need to power MCU up before applying voltage to input pins. That is why it is so surprising that you do not have a loop in your main().

Hm thank you, I'll improve it with a loop or by using interrupts on changed voltages.

do not start thinking about interrupts until you can write basic code

While not entirely false, this does not address the glaring issue of the code, but only the tangential failure to achieve a clean power on reset when inputs are powering the chip.  If the code were correct, this theoretical issue would not be seen in practice.

Why is the code not correct? I don't see a problem with it.

Yes but I was going for low power usage, because I wouldn't need it to run often, I figured I moght as well only turn it on when I need it to output.


text:
Is this a good way of making a low power attiny? Unpower instead of sleeping
I am making a low power rf remote that just has 3 buttons and sends rf signals accordingly.
I've been trying to make pin interrupts work when it's in deep sleep but it's a huge hassle. And then I thought of this:

Is it a bad idea to do this?
I could imagine if you were too fast, you would shut the RF transmitter off while it's sending something, but that shouldn't be an issue because the user would notice nothing changed and will learn to press the button longer.
But the transmitter might also transmit too fast for a user to interrupt it.
And I don't know if debouncing is an issue here. I could just put a capacitor after the buttons.
Of course the code would be something like analogRead which button is pressed and then emit rf signals.
So my question is, is this bad practice and will this kill my battery/attiny/rf emitter?

I haven't notice any hassle with deep sleep mode and pin change interrupts. It's even working when the datasheet states it won't work with IO clock stopped.

Will that use less power than this setup?

If you don't have to wake up periodically, and with disabling power to the RF module (how, it depends on required current), it might take less current than battery's self discharge.

That could work. Add a capacitor between Vcc and Gnd to stabilize the power during bounce. You might have to change the fuses to lower the startuptime (which is 64ms by default I think). To prevent double sending, add a large delay after the sending code. That way the code is only sent once.

I don't have any experience with capacitors, any tips? Do I just go for a big one?


text:
Connect a TM1627 to ESP32
I want to control a 7 segment display that has a TM1637 integrated with an ESP32.
Some time ago I created a layout that used an ESP12e but I need more GPIO pins so I'm switching over to an ESP32.
This was how I had it hooked up:
CLK -> GPOI14
DIO -> GPIO12

I think I did it this way because I had to use the special CLK pin tou can see in this pinout.
Only I don't know if I need to hook them up with special pins on the ESP32. I can't find a good tutorial and I don't have the parts yet to test with.
Do you guys know which pin(s) are suitable for the TM1637?

any. https://playground.arduino.cc/Main/TM1637. io 14 on esp8266 can be SPI CLK,  for your connection it was gpio

It says I can connect it to any gpio, do I understand that correctly?

The label CLK on esp8266 is in a context of SPI pins CLK, MISO, MOSI, SS. You had no reason to connect TM1637 CLK to this pin, since with TM1637 you can use any GPIO pins of the MCU for CLK and DIO.

Shouldn't TM1637 can use any GPIO pins for CLK and DIO be ESP32 can use any GPIO pins for CLK and DIO?

I edited the answer

IMO still a bit misleading, in my understanding the ESP32 is the active component controlling the TM1637 using any of it's pins to do that.

the protocol is determined by the sensor. it it would be SPI you could use only spi pins of the mcu for that sensor. I answer in a context of the question, adding more refinements doesn't help readability.


text:
Why can't I upload a sketch by connecting directly to the serial pins?
I have an handful of fake arduino nanos.  The work fine, but as an experiment, I tried to program them with a usb serial adapter (a real FTDI one).  It doesn't work, but also, strangely, it seems to stop the bootloader from working properly too, or just puts the arduino in a mode where the /dev/ttyUSB* device doesn't appear, and only reappears when I burn the bootloader again
When I try to upload the sketch using the usb serial adapter, I get this:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Failed uploading: uploading error: exit status 1

Then, when I try to upload a sketch over usb again, /dev/ttyUSB* no longer appears when I plug in the usb cable to the normal usb jack.
However, when I can still put the sketch on using an in-circuit-programmer, and when I use the in-circuit-programmer to burn the bootloader again, /dev/ttyUSB* appears again, and I can upload sketches over usb again.
Is that possible?  What could I be doing wrong
Here is how I connected the usb to serial adapter to the fake arduino:

(checkout https://i.sstatic.net/nh3d6.jpg for a bigger picture)
So basically I have connected between the arduino (left column) and the usb to serial adapter right column:
TX - RX
RX - TX
VIN - VCC
GND - GND
RST - 0.1uF capacitor - DTR

I have tried it with and without the reset pin.
The usb to serial adapter is set to 5V.

another clue:
If I leave the adapter and arduino connected as in the picture, but plug the usb cable into the arduino instead of the adapter, so the adapter is powered by the arduino - it still gets the error that I have shown, and stops working completely until I reburn the bootloader.

Does anybody have any idea why this could be happening?

UPDATE:
After it was pointed out, I started using the 5v pin instead of the VCC pin on the fake arduino, but the same thing keeps happening:

burn the boot loader
normal usb upload works
try to upload with the serial adapter
doesn't work
normal usb upload no longer works until I burn the bootloader again

thanks.  I connected two adapters together to make sure they both worked, and sent messages both ways.  I should have mentioned at

Vin is for 7 to 12 V input. feed 5 V over the 5 V pin. the DTR may not work so try a manual reset while avrdude attempts to upload

You appear to have connected the 5v output of the FTDI adapter to the Vin pin of the Nano. You should instead use the 5v pin of the Nano to avoid the path through the internal voltage regulator. You are also aware that if you use the ICSP pins to download a sketch to the Nano, that overwrites the boot loader ?

Yes I have changed power to the 5v pin since @Juraj pointed it out, and gotten the same result.  Yeah, I burned the bootloader using the ICSP pins each time.  That's the only way I could fix normal upload.  Once I fix the bootloader, I can upload sketches until I try to upload with the serial adapter, and then the bootloader seems to stop working.

I have ordered a real arduino nano, so I'll try with that as soon as it gets here - to try to zero in on the issue

It turns out I had this problem https://askubuntu.com/questions/1403705/dev-ttyusb0-not-present-in-ubuntu-22-04. if anybody has a similar problem (a fake arduino that keeps disappearing) try sudo apt-get remove brltty before anything else. I'm not sure if that was the main problem, or just made it hard to figure out the main problem.

OK this was a combination of at least two things:

Main problem:
connecting the fake arduino's RST pin to the FTDI's DTR pin via a 0.1uF capacitor seems to stop it from uploading, when when you manually reset.  Also when I remove it it doesn't seem to fix itself right away if you can believe it.

Red Herring
This was not the direct cause of this issue, but is probably a big problem for a lot of other fake arduinos out there:
When I went back to the built-in USB, brltty's udev rules were claiming the CH341 as described here https://askubuntu.com/questions/1403705/dev-ttyusb0-not-present-in-ubuntu-22-04
So if you just have the simpler problem of a fake arduino not appearing, this might solve the problem for you:
sudo apt-get remove brltty

or if you need brltty you can just go into the udev rules that come with it and comment out this one:
# Device: 1A86:7523
# Baum [NLS eReader Zoomax (20 cells)]
ENV{PRODUCT}=="1a86/7523/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

(as long as that isn't the screen reader you use - then you might just have to buy a real arduino, or make some better udev rules that recognise your screenreader from the port it's plugged into)
The reason this confused me is that when I tried to plug in to the standard usb port after failing to use the programmer, the above udev rules kicked me out.  But then I think when I burned a new bootloader, because you still have to power the board from usb while the pololu is connected, I managed to have it connected without the above udev rule kicking it - and then when I tried the external FTDI again, and then plugged back in the internal CH341, the brltty udev rule claimed it, and it seemed like trying to upload over FTDI is what broke it.

wouldn't you have the same problem uploading with the on-board FTDI? how is this related to the use of external FTDI on RX.TX pin?

yeah - that's a good point.  I haven't quite figured it out.  I think either this was the only problem, and I totally misinterpreted it - or there was another problem, but having this problem at the same time made it really hard to figure out.

I have updated the answer @Juraj.  The direct cause was trying to automatically reset - which you also suggested I stop, and the CH431 udev issue just distracted me from getting to the bottom of that, since I couldn't verify that the arduino was working at all.

It appears the boot loader does not support serial programming. You would need to change that first. Is the baud rate the same?

it works over USB and the USB chip connects to the same RX/TX as the header pins RX/TX


text:
Generate & Display QR using Nodemcu on TFT Display ST7789 240*240
I have NodeMCU & ST7789 TFT display. I want to generate QR Code of any dynamic input and display it on my TFT display. Not able to find any suitable reference. All Standard QR code libraries only work for Arduino & not for NodeMcu, board not supported for them. Can someone please help ?
Libraries Tried :
https://github.com/yoprogramo/ESP_QRcode
https://github.com/anunpanya/ESP8266_QRcode
https://github.com/ricmoo/qrcode
https://github.com/onelife/rtt-qrcode

I suspect the real question is why does the Arduino QR library not work for the Nodemcu?  Also, post a link to the QR library you are intending to use just to make things clear.  Lastly, to make the project easier - you may want to constrain the code to a fixed length or at least limit it.  I have see QR codes on the sides of trucks so complex they look like sand grains.

Thanks for helping, I tried all existing libraries : https://github.com/yoprogramo/ESP_QRcode , https://github.com/anunpanya/ESP8266_QRcode, https://github.com/ricmoo/qrcode/, https://github.com/onelife/rtt-qrcode, But they all seems to dont seem to work with NodeMCU. Can you correct me if I am wrong, or if you have a work around. I dont require very complex QR Code (Grainy), simple usual ones, that we we see around.


text:
How can I make a Parallax Servomotor move a water tap correctly and prevent from vibrations?
I am using Arduino Mega 2560
I have built an structure with plastic 3D pieces to move this water tap.:

I am using the "Servomotor Parallax Inc 140 mA, 4 6 V" to rotate the tap:

Some more images to show how I mounted it:

Video 1. I tried to use the power of the arduino directly (5V). But the motor is not steady in all the positions I set, in some positions the noise you hear in the video do not stop, and my impression is that the motor will burn soon because it keeps pusshing all the time.
Video 2. Without almost any load, the motor is also making a small sound. I don't know if you can appreciate it in the video. They are like cracks or clicks
Possible solutions:

Is there a way to cut the power supply when the motor already moved the tap? Or just to stop the motor to keep pushing?
Using a external power should solve the problem? I found this tutorial where they use that system. Which will be the benefits of that? It will fix the problem?
Using another stronger servomotor?
A stepper motor?
Is my servomotor faulty?
Would I need some controller?

Any other suggestion?

You must have exceptional hearing. I can't hear any noise...

@Majenko Don't you hear it? Here, almost at the end of the video, the sound is clear, just turn up the volume of your speakers. I could have edited the sound of the video to make it more clear. The sound is a humming quite like this other one

When you set a servo motor to be in a specific position it is constantly and actively striving to keep in that position. The feedback from the internal potentiometer is constantly being processed and the motor adjusted to ensure that it remains at the right position.  Potentiometers, of course, aren't 100% perfect, and there will always be a certain amount of "noise" in the signal that means the motor will always be making really tiny adjustments.
That's perfectly normal.
The simple way to stop it trying to keep precisely to one position is to stop telling it to be in that position.

.attach() the motor
Move it to the desired position
Wait long enough for the motor to get to that position
.detach() the motor

When you call servo.detach() the PWM signal is terminated and the motor no longer has a position to keep to - so it just stops doing anything and goes to sleep.
The down-side of this is that if you have a load under tension (for example if you are lifting a weight with the servo) the tension is then free to move the motor.

Thanks for your interest !! I like your idea, I will try it when I buy another servo because I have burnt out the one in the pictures haha. I put the terminal poles of my external power supply in the wrong position for some seconds

ElectronSurf suggests in his answer that I cannot plug the servomotor directly to the Arduino. I believe I can connect up to 40mA to each pin, but I have a capacitor of 100μF 25V to make it work. Do you think I would need to use an external supply to make it work better (or to prevent from burning the Arduino board), or the result would be the same?

I have tried and it worked !!


text:
Can I cut the pin holes off of my Arduino board?
I'm making a project, but my arduino pro micro is just slightly too big to fit in it's case.
What would happen if I cut off the pin holes that I don't need? Would it still work? Or would it be ruined?

Hello and welcome! Do you mean cutting the pins (as suggested in the questions) or cutting the printed circuit board itself (as hinted in the title)?

Cutting the printed circuit board itself

If you don't accidentally cut any other traces you'll be fine. I think most board don't snake any traces around the pins, but you'd have to check yourself, or post a detailed picture. Where did you buy your pro micro, as there are a few variations of the same board?

I bought a fake Chinese one from eBay

I guess that one could cut (or hone down) parts of the PCB. Obviosly this process devoids the warranty and there is the risk of damaging either the board or some components on it (i.e. by holding or clamping it during the process).
I would not expect any other wiring besides those connecting the pins to run in this part of the PCB. The reference layout (see board layout and using Eagle (free version)) - if the clones follow that layout - confirms that there are no other traces there. So it is mostly important to not cut any other traces and remove any chippings after the cutting to avoid short circuits.
If in doubt buy two or three boards ;) to try and repeat the process.

Rather than trying to modify the board (which I think is a bad idea) why not use a Pro Mini.
These are smaller (and cheaper), and almost identical in function, apart from the USB interface. You do need a serial interface (or ICSP) to program.

This is a bad ideas:

the PCB is made of fiber glass which, when broken, cut or filed, produces a very fine powder; any powder you might breath in during the process wil stay in lungs for a very long time, in the order of decades
the risk of cracking traces running close to the are of cut, even if they are not directly being cut, is pretty high; the copper traces rely on the fiberglass rigidity, but a crack in the fiberglass propagating under the traces is welcoming a broken trace

Go for a different case, if that's not a viable option go for a barebone arduino. If that is also a non viable option consider the idea of producing a few custom PCBs: they are not that expensive!

You could use a Pro Mini as Milliways suggested, but you don't necessarily need a USB interface to programme it.  You can use your Arduino UNO to directly programme the Arduino Pro Mini.

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


text:
Should I use motor driver or Motor driver shield?
I want to run 4 microgear motor for an RC car with Arduino. Should I use L293d motor driver/L298n motor driver/L293d motor driver shield?? I am using N20 microgear motor with following rating: 6 V, 200 RPM and 120 mA with no load, 40 oz-in (2.9 kg-cm) and 1.6 A at stall.

I don't think you should be using L293 based drivers for new projects. You should be using TB6612FNG drivers instead. They're much more efficient.

The right driver module or shield depends on the motor. Do you know the voltage and the stall current of the motors ?
The L293D uses bipolar transistors for the output stage inside the chip and can only drive 600mA. It has a large voltage drop: the motor gets less voltage than the power voltage applied to the driver. Therefor it can be used with small 12V motors, but it does not work very well with 6V.
The L298N also uses bipolar transistors and also has a large voltage drop.
A mosfet driver like the DRV8833 works better with 6V, because it has a low voltage drop.
In small RC toys with four AA batteries, sometimes a H-bridge is made is transistors instead of using a special driver chip.
The very cheap motor shield with two L293D chips (originally designed by Adafruit) can drive four motors, but it uses many pins.
Bottom line: Everything depends on your motors. I suggest to use a mosfet driver.

The T in MOSFET stands for transistor.  It is misleading to say the  L293D and L298N use transistors as if MOSFET drivers don't.  So, instead say  “L293D uses Darlington bipolar transistors” etc

@JamesWaldby-jwpat7, thank you, I have corrected it. Mum, if the motors require that 1.6A and the batteries can supply it, then you need a motor driver that is capable to drive 1.6A, for example the DRV8838, MC33926 or MAX14870. I found those drivers at Pololu: https://www.pololu.com/category/11/brushed-dc-motor-drivers

@Jot Will motor driver shield help?

@Mum, the motor shield with two L293D ? No, it won't work very well with 6V. Look at the bottom of this page what Pololu suggests for the N20 motor: https://www.pololu.com/product/997

@Jot Is there any chance using L293d is harming the motor driver and arduino?Because my arduino seemed to have frozen,

@Mum, when it is connected properly, then the Arduino should still be okay. Disconnect everything from the Arduino board and try to upload the Blink sketch to blink the led at pin 13.

@Jot I  tried but error is showing failed to upload.. and  the receiver led is not blinking while uploading.

@Mum, that's not good. It might be broken. You need another Arduino board.

@Jot cant I somehow revive it?

@Jot and can you tell me why this happened?so that it wont happen again..

@Mum, I'm sorry, I don't know what happened. I don't know how it all is connected. The Arduino gets easily broken with a loose wire with 12V accidently touching the Arduino board. With the motor shield, the Arduino should be okay. Perhaps the L293D got very hot and broke and because of that, a voltage spike from the motor reached the Arduino board. That is just a wild guess, I don't know.

The key differences between the L293D and the L298 are these:

the L298 supports higher currents (up to 4 A with proper heat sink), the L293D is limited to 600 mA
the L298 has a higher operating voltage (up to 46 V), the L293D is limited to 36 V
the L298 is a dual full bridge driver whereas the L293D is a quadruple half bridge driver

Ok, what's the difference of two full bridges vs. four half bridges - it somehow sounds to be equal? In fact, when driving a DC motor that requires to reverse the polarity to reverse rotation a full bridge is required. This full bridge could now be provided by either of the L293D (two half bridges) or the L298 (one full bridge). If you on the other hand want to drive a four winding stepper motor (two phase bipolar) the L293D would be more helpful as it could drive two such steppers (using two separate half bridges) whereas the L298 would need to use both its full bridges and could therefore only operate one such stepper.
But since steppers are not part of this question this difference does not really matter and you could pick either chip with respect to the required current rating. A stall current of 1.6 A would be a serious problem for the L293D:

Peak output current, I_O (nonrepetitive, t ≤ 100 μs): 1.2 A

Whether to use the chip or a driver board or a shield, to be honest, is mainly personal preference. Shields and driver boards come ready-to-use on a pretty printed circuit board which is probably their main benefit.

There are differences, yes, but what they have in common is that both are long obsolete, lossy bipolar devices that should not be chosen today.

Fair enough, @ChrisStratton, but that is not what was asked by the OP ;)

@ChrisStratton If you mention some alternatives, it will be very valuble

authors: Индер колледж

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


text:
Can not initialize ESP module in Arduino SoftwareSerial
Can not initialize ESP module in Arduino SoftwareSerial's example sketch in configuring WiFi module.
In the sketch it tells:
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(11,12); // RX, TX
#endif

I plugged jumper wires in from esp8266 RX to Digital 11 of mega which is RX and TX of esp8266 to Digital 12 of mega, and I compile the code and looked at the Serial Monitor, but it says:
[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module

Advise is greatly appreciated.

it is not SoftwareSerial on Mega. Mega has Serial1. did you connect ground? connect Rx to TX and TX to RX. use pins of hardware  Serial1 of Mega

Yes i connect the ground, my esp01 responds if the connection is RX of esp01 to TX of mega and TX of esp01 to RX of mega.

#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(11,12); // RX, TX
#endif

Because your Mega has a Hardware Serial1 port, HAVE_HWSERIAL1 is defined. Thus the lines inside that preprocessor conditional will not be compiled. This means you should connect the ESP8266 to the Serial1 lines on your Mega:
Mega | ESP8266
--------------
19   | TX
18   | RX

I try to plug it in mega's 18 with esp01's TX and 19 with esp01's RX  and reverse but still gives me time out :( i don't know what to do now.

And also it gives me :error compiling for board arduino /genuino mega or mega2560. please sir help.

first of all the sketch with WiFiEsp library must compile. what are the error details?

I download the library in this link:https://github.com/bportaluri/WiFiEsp and tried the ConnectWPA example.

Then i connect the RX of esp01 to TX 19 of mega and TX of esp01 to RX of mega but still no success.

and the compile error? changing connections is for nothing if the code doesn't compile and upload


text:
3.3V Conversion
I'm writing a SPI Master module for my FPGA and I would like test it with my Arduino Uno.
What's the problem? My FPGA has 3.3V logic and Arduino has 5V TTL logic.
So, what's the simplest solution to convert 5V TTL logic into 3.3V logic?
I know this topic has been already discussed in many sites but I can't find an unified answer.
Thanks in advance!

Logic level Converter boards

Just about any 5V powered IC will take 0-3.3V and output 0-5V.
Like this one for example

If you don't need the 16 MHz clock speed, running your Arduino at 8 MHz/3.3v is an option.  Or there are chips that run far faster at that voltage.  Or you can use level conversion, either fully push/pull or low side with pullup - it's not really possible to pick the best solution without considering context that is missing from your question.

You will get better answers (and maybe stop people arguing with each other) if you mention what FPGA you have in mind, and maybe a link to its datasheet, so we can see what its requirements are. Please read How do I ask a good question?.

But just any 3.3V device won't take 5V.

You can get 5, 4 channel bi-directional logic level converters for less than $1 USD Logic Level Module
Not only will they "translate" 3.3V to 5V and 5V to 3.3V, but they also work with higher voltages as well. For example, a vehicle with a 12V electrical system to 5V and vice versa works too.

While this clever circuit will work for some purposes, one should beware that such devices only actively drive low.  The high side output is provided by a pull-up resistor only, typically 10K (though could be smaller).  As a result, it is limited to moderately low speeds and short wire runs in quiet environments.

The OP asked for the "the simplest solution". My answer is simple and very inexpensive. If you have a simpler method, please share it with us.

Your answer is indeed simple, but it is not always suitable.  The point of my comment was to point out the limitation so that an informed decision can be made.  Engineering almost always comes down to such a trade off between needs and costs, so the key to success is knowledge rather than blind assumption.  I've used circuits such as you suggest in projects, but I've also had needs which they cannot meet.

Just like I thought, you don't have a simpler way to level translate.

If you prefer to shop US instead of ordering from China, both Sparkfun & Adafruit manufacture similar modules.

-1 If you are going to absolutely beg for a downvote by positioning your suggestion as a contest entry rather than a technical solution limited to some circumstances, you are welcome to one.  As for a "simpler" way, there are circumstances where just a series resistor is enough (one of which is in a Xilinx FPGA app note, no less!).  And there are circumstances where you do not need anything at all.  But as always, what is suitable depends on the unstated details of the need.

@Chris Stratton - If you don't like my answer and have a better one, why won't you answer the question? Comments are for clarifying the question, not answering it.


text:
Sensor Robot Car Arduino Cannot Detect Every Inch
I'm very new about this thing. I have made an arduino robot car for my assignment. There is a maze that I have to complete it. I'm using L298N Dual H-Bridge Motor Driver, Servo Motor, HC-SR04 Ultrasonic Sensor, DC Motor, Arduino Sensor Shield.
The problem when in the maze is, the sensor will check if there is wall front of the car. Then it will scan from left, then right. BUT, the maze was straight line and at the middle, has one way out.
I have a problem on how to make the sensor detect the 180 degree of wall every second. What I mean is, when the car move ahead inch, the sensor will scan left, front, right. Then, if there is a wall at left, the car move ahead inch, then scan again. I really need help for this assignment.

Here is my code:
#include <Servo.h>
// Pins for the Echo Sensor
#define TRIG_PIN A0
#define ECHO_PIN A1
//Define all the connections maps to the L298N
#define enA 13
#define in1 12
#define in2 11
#define in3 7
#define in4 6
#define enB 5
#define servoPin 2

class Motor{

int enablePin;
int directionPin1;
int directionPin2;

public:

//Methods to define motor pins
Motor(int ENPin,int dPin1,int dPin2){
enablePin = ENPin;
directionPin1 = dPin1;
directionPin2 = dPin2;
};

//Method to allow robot to turn and move forward and backwards
void Drive(int speed){
if(speed>=0){
digitalWrite(directionPin1, LOW);
digitalWrite(directionPin2, HIGH);
}
else{
digitalWrite(directionPin1, HIGH);
digitalWrite(directionPin2, LOW);
speed = - speed;
}
analogWrite(enablePin, speed);
}
};

Motor leftMotor = Motor(enA, in1, in2);
Motor rightMotor = Motor(enB, in3, in4);
Servo myservo; // create servo object to control a servo

void motorInitiation(){
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
// Set initial direction and speed
digitalWrite(enA, LOW);
digitalWrite(enB, LOW);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}

//Variables--------------------------------------------------------------------------
// Anything over 400 cm (23200 us pulse) is "out of range"
const unsigned int MAX_DIST = 23200;
bool ObsticalAhead = false;
int servoPos = 90;

enum Directions { Forward, TurnLeft, TurnRight, TurnAround,Brake};

Directions nextStep = Forward;

unsigned long t1;
unsigned long t2;
unsigned long pulse_width;
float cm;
float inches;

//SETUP--------------------------------------------------------------------------
void setup() {

// The Trigger pin will tell the sensor to range find
pinMode(TRIG_PIN, OUTPUT);
digitalWrite(TRIG_PIN, LOW);

// Serial monitor to view the sensor output
Serial.begin(9600);
myservo.attach(servoPin);
motorInitiation();
Directions nextStep = Forward;
}

void loop() {

checkDistance();
checkDirection();
drive();
}

void checkDistance(){

// Hold the trigger pin high for at least 10 us
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);

// Wait for pulse on echo pin
while ( digitalRead(ECHO_PIN) == 0 );

// Measures how long the echo pin was held high (pulse width)
t1 = micros();
while ( digitalRead(ECHO_PIN) == 1);
t2 = micros();
pulse_width = t2 - t1;

// Calculate distance in centimeters and inches from sound to bounce back
cm = pulse_width / 58.0;
inches = pulse_width / 148.0;

// Print out results
if ( pulse_width > MAX_DIST ) {
//Serial.println("Out of range");
} else {
//Serial.print(cm);
//Serial.print(" cm \t");
//Serial.print(inches);
//Serial.println(" in");
}

// Wait at least 60ms before next measurement
delay(60);

if(cm<= 20){
ObsticalAhead = true;
Serial.println("Problem Ahead");

}
else{ ObsticalAhead = false;}

}
void checkDirection(){
Serial.println("checking direction");
if(ObsticalAhead ==true){
nextStep = Brake;
drive();
myservo.write(180); // tell servo to go to position in variable 'pos'
delay(400); // waits 15ms for the servo to reach the position
checkDistance();
if(ObsticalAhead ==false){//if left side is open
nextStep = TurnLeft;
Serial.println("Next step is TurnLeft");
myservo.write(90);//reset servo position
delay(400);
}
else{// left is blocked, now need to look at right
myservo.write(0); // tell servo to go to position in variable 'pos'
delay(800); // waits 15ms for the servo to reach the position
checkDistance();
if(ObsticalAhead ==false){//if right side is open
nextStep = TurnRight;
Serial.println("Next step is TurnRight");
myservo.write(90);//reset servo position
delay(400);
}
else{//right is blocked as well, need to turn around
nextStep = TurnAround;
myservo.write(90);//reset servo position
delay(300);
Serial.println("Next step is TurnAround");
}
}

}
else{nextStep = Forward;}//No obstical ahead
}

void drive(){
switch (nextStep){
case Forward:
leftMotor.Drive(255);
rightMotor.Drive(255);
Serial.println("Forward");

break;
case TurnLeft:
leftMotor.Drive(-255);
rightMotor.Drive(255);
Serial.println(" TurnLeft");
delay(400);

break;
case TurnRight:
leftMotor.Drive(255);
rightMotor.Drive(-255);
Serial.println(" TurnRight");
delay(400);
break;
case TurnAround:
leftMotor.Drive(255);
rightMotor.Drive(-255);
Serial.println(" TurnAround");
delay(600);
break;

case Brake:
leftMotor.Drive(0);
rightMotor.Drive(0);
Serial.println(" stopped");
}
}

Tip: break your program down into smaller functions and "unit test" them. Make sure that each component of your program does what you expect it to, then make them all work together.

I am not sure from your description what the problem is. What is it not doing that it should, or doing that it shouldnt?


text:
Problem with html code in ESP8266 WebServer
Here I have a small problem:
I have an ESP8266, to which I have connected a matrix of LEDs to move text (the array of LEDs is made with the tape of LEDs addressable ws2812); when you turn on the computer you create an access point with a Captive Portal, which takes you to a small (though still ugly) web interface, where I can manage both the text I show and the speed, intensity and colors of it. All right, everything works ... I know I still have to change several things in the "code" html to work properly, but I hate CSS and right now it is functional.

The problem is the following:
I have several html forms that collect the values of the variables mentioned above (text to be displayed, color, brightness and speed with which the text is displayed), but every time I hit the "Send" button the browser (I have only tried the browser that comes with my phone (a Xiaomi Redmi Note 4, the application is called Browser itself) and the Google browser, on the same phone) takes me to a screen (I leave screenshot) where it shows me the html code of the page that resides within the esp8266 . And what bothers me is why !? Why does this happen!? (I leave a copy of the code too at the end!)

The only thing that occurs to me is that I am saving the page in a variable type String (String object, not an array of characters) ... will anyone know what is due?
Copy of the code:
//++++++++++++++++++++++++++++++++++++++++++++++//
//                LIBRERIAS                     //
//++++++++++++++++++++++++++++++++++++++++++++++//
        /*WiFi*/
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

        /*SSID and Password of your WiFi router*/
const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);
DNSServer dnsServer;
ESP8266WebServer server(80);
const char* ssid = "asd";
const char* password = "123456789";

String responseHTML = ""
  "<!DOCTYPE html><title>CaptivePortal</title>"
  "
Hello World!

This is a captive portal example. All requests will "
  "be redirected here.
";

//++++++++++++++++++++++++++++++++++++++++++++++//
//                  MATRIZ                      //
//++++++++++++++++++++++++++++++++++++++++++++++//
        /*LedStrip*/
#include <FastLED.h>
#include <LEDMatrix.h>
#include <LEDText.h>
#include <FontMatrise.h>

#define LED_PIN        2
#define COLOR_ORDER    GRB
#define CHIPSET        WS2812B
#define MATRIX_WIDTH   -8
#define MATRIX_HEIGHT  7
#define MATRIX_TYPE    HORIZONTAL_ZIGZAG_MATRIX

  /*Creando instancias de la matriz y el objeto*/
cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;
cLEDText ScrollingMsg;

    /*Texto a mostrar y colores*/
char buf[200] = "HOME";
byte red = 255;
byte green = 255;
byte blue = 0;
byte intensity = 25;
byte intensity_old = 25;
int fastness = 300;

//++++++++++++++++++++++++++++++++++++++++++//
//                 Index                    //
//++++++++++++++++++++++++++++++++++++++++++//
String getPage(){
  String page = "<!DOCTYPE HTML>";
  page += "";
  page += "";
  page += "<meta name = \"viewport\" content = \"width = device-width, initial-scale = 1.0 maximum-scale = 1.0, user-scalable=0\">";
  page += "<title>Cartel Led</title>";
  page += "";
  page += "";
  page += "";
  page += "
Página de configuración del Cartel Led
";

  //Formulario para cartel
  page += "<FORM action=\"/\" method=\"post\">";
  page += "Introduzca texto a mostrar:
";
  page += "<input type=\"text\" name=\"texto\" id=\"texto\" value=\"Mickey\">";
  page += "
";
  page += "<input type=\"submit\" value=\"Enviar\">";
  page += "</form>";
  page += "
";
  page += "
";
  page += "
";

  page += "<FORM action=\"/\" method=\"post\">";
  page += "Elija el color:
";
  page += "<input type=\"range\" min=\"0\" max=\"255\" id=\"red\" name=\"red\" value=\"";
  page += red;
  page +="\" class=\"slider\">
";
  page += "<input type=\"range\" min=\"0\" max=\"255\" id=\"green\" name=\"green\" value=\"";
  page += green;
  page +="\" class=\"slider\">
";
  page += "<input type=\"range\" min=\"0\" max=\"255\" id=\"blue\" name=\"blue\" value=\"";
  page += blue;
  page +="\" class=\"slider\">
";
  page += "<input type=\"submit\" value=\"Enviar\">";
  page += "</form>";
  page += "
";
  page += "
";
  page += "
";

  page += "<FORM action=\"/\" method=\"post\">";
  page += "Elija la intensidad :
";
  page += "<input type=\"range\" min=\"10\" max=\"255\" id=\"intensity\" name=\"intensity\" value=\"";
  page += intensity;
  page +="\" class=\"slider\">
";
  page += "<input type=\"submit\" value=\"Enviar\">";
  page += "
";
  page += "
";
  page += "
";

  page += "<FORM action=\"/\" method=\"post\">";
  page += "Elija la rapidez:
";
  page += "<input type=\"range\" min=\"50\" max=\"1000\" id=\"fastness\" name=\"fastness\" value=\"";
  page += fastness;
  page +="\" class=\"slider\">
";
  page += "<input type=\"submit\" value=\"Enviar\">";
  page += "
";
  page += "
";
  page += "
";

  page += "";
  page += "";
  return page;
  }

//++++++++++++++++++++++++++++++++++++++++++//
//          REDIRECCIONAMIENTO             //
//++++++++++++++++++++++++++++++++++++++++++//
void handleNotFound(){
  server.send(200, "text/html", getPage());
}

//++++++++++++++++++++++++++++++++++++++++++//
//      handleSubmit                        //
//++++++++++++++++++++++++++++++++++++++++++//
void handleSubmit(){
  //Text to show
  if (server.hasArg("texto")){
      String texto_string = server.arg("texto");
      int texto_string_size = (texto_string.length()+1);
      texto_string.toCharArray(buf, texto_string_size);
      Serial.print("El texto a mostrar sera:");
      Serial.println(buf);
      }
  //Colors
  if (server.hasArg("red")){
      String red_h = server.arg("red");
      red = red_h.toInt();
      Serial.print("El color rojo cambio a:");
      Serial.println(red);
      }
   if (server.hasArg("green")){
      String green_h = server.arg("green");
      green = green_h.toInt();
      Serial.print("El color verde cambio a:");
      Serial.println(green);
      }
   if (server.hasArg("blue")){
      String blue_h = server.arg("blue");
      blue = blue_h.toInt();
      Serial.print("El color azul cambio a:");
      Serial.println(blue);
      }

  //Intensity
  if (server.hasArg("intensity")){
      String intensity_h = server.arg("intensity");
      intensity = intensity_h.toInt();
      Serial.print("La intensidad cambio a:");
      Serial.println(intensity);
      }

  //Fastness
  if (server.hasArg("fastness")){
      String fastness_h = server.arg("fastness");
      fastness = fastness_h.toInt();
      Serial.print("La intensidad cambio a:");
      Serial.println(fastness);
      }

  server.send(200, "text/plain", getPage());       //Response to the HTTP request
}

//++++++++++++++++++++++++++++++++++++++++++//
//            handleRoot                    //
//++++++++++++++++++++++++++++++++++++++++++//
void handleRoot() {
  if (server.args() ) {
    handleSubmit();
    } else {
      server.send(200, "text/html", getPage());
      }
}

//++++++++++++++++++++++++++++++++++++++++++++++//
//        Recoger del puerto serial             //
//++++++++++++++++++++++++++++++++++++++++++++++//
//int readline(int readch, char *buffer, int len) {
//    static int pos = 0;
//    int rpos;
//
//    if (readch > 0) {
//        switch (readch) {
//            case '\r': // Ignore CR
//                break;
//            case '\n': // Return on new-line
//                rpos = pos;
//                pos = 0;  // Reset position index ready for next time
//                return rpos;
//            default:
//                if (pos < len-2) {
//                    buffer[pos++] = readch;
//                    buffer[pos] = 0;
//                }
//        }
//    }
//    return 0;
//}

//++++++++++++++++++++++++++++++++++++++++++++++//
//            SETUP()                           //
//++++++++++++++++++++++++++++++++++++++++++++++//
void setup(){
  delay(1000);
  Serial.begin(115200);

  //WiFi initilization part
  Serial.print("Creating AP...");
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
  WiFi.softAP("DNSServer CaptivePortal example");

  // if DNSServer is started with "*" for domain name, it will reply with
  // provided IP to all DNS request
  dnsServer.start(DNS_PORT, "*", apIP);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.onNotFound(handleNotFound);

  // if DNSServer is started with "*" for domain name, it will reply with
  // provided IP to all DNS request
  dnsServer.start(DNS_PORT, "*", apIP);

  server.begin();

  //LedStrip initialization part
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.Size());
  FastLED.setBrightness(intensity_old);
  FastLED.clear(true);
  delay(500);

  FastLED.showColor(CRGB::White);
  delay(500);
  FastLED.show();

  //Se declara la fuente que se utiliza
  ScrollingMsg.SetFont(MatriseFontData);
  //Se inicializa la matriz
  ScrollingMsg.Init(&leds, leds.Width(), ScrollingMsg.FontHeight() + 1, 0, 0);
//  ScrollingMsg.SetBackgroundMode(BACKGND_DIMMING, 50);
  //Se introduce el textoque se va a mostrar y su tamanho
//  ScrollingMsg.SetText((unsigned char *)TxtDemo, sizeof(TxtDemo) - 1);
  //Se declara los colores/efectos con los que se van a mostrar los mensajes
  ScrollingMsg.SetTextColrOptions(COLR_RGB | COLR_SINGLE, red, green, blue);

  //Para organizar el sentido del mensaje como mas convenga
  //Setear la direccion del mensaje
//  ScrollingMsg.SetScrollDirection(SCROLL_UP);
  //Setear la direccion de las letas
//  ScrollingMsg.SetTextDirection(CHAR_DOWN);

}

//++++++++++++++++++++++++++++++++++++++++++++++//
//              LOOP                            //
//++++++++++++++++++++++++++++++++++++++++++++++//
void loop(){
  dnsServer.processNextRequest();
  server.handleClient();         //Handling of incoming requests

  ScrollingMsg.SetTextColrOptions(COLR_RGB | COLR_SINGLE, red, green, blue);
  FastLED.setBrightness(intensity);

  if (ScrollingMsg.UpdateText() == -1) {
    ScrollingMsg.SetText((unsigned char *)buf, strlen(buf));}
  else {
    FastLED.show();
  delay(fastness);
        }

//  if (readline(Serial.read(), buf, 200) > 0) {
//        Serial.print("You entered: >");
//        Serial.print(buf);
//        Serial.println("<");
//    }

  delay(50);
}

You have content type "text/plain" in handleSubmit(). Use "text/html".

Hi! Thanks!!! I review this so many times!!! Thanks!!! Feel free to use this (punny) code if you want :D


text:
What value of resistance to put between the output of a 74hc595 and the LEDs?
I'm going to start a project to make an array of LEDs using the shift registers 74HC595, I've seen many tutorials and it's not really difficult using the Arduino plataform.
The situation is as follows: in the tutorials they put a resistance between the outputs of the 74HC595 (Qx) and the LEDs , but in each tutorial the resistance varies (between 200 and 575 Ohms).
Then the question would be: if feed with 5V to 74HC595 (the same power as the Arduino) and the resistance that I put between its outputs (Qx) and the LEDs is lower (let's say 200 Ohms), the LEDs will light brighter than if I do it with resistors with higher values (let's say 500 Ohms)?

What does the 74HC595 datasheet say about maximum current per output and maximum current for the entire IC? The Texas Instruments datasheet uses 560 ohms per LED on the Typical Application page.

@VE7JRO, the OP is asking, using a lot of words, if a 200 ohm series resistor will produce brighter LED output when compared to a 500 ohm series resistor.

I know the Ohm´s law, I just asking for experience, I Live in Cuba and is very dificult to me order pieces (when I buy them I have to wait almost 4 month to get them); so, when I order I try to order "things" that I would know that will work, I ask for this reason. Sorry

They say 25mA per output.

no need to apologize .... then you should be asking about what @VE7JRO mentioned in the above comment .... can the 74HC595 handle the load when all the LEDs are on?

You are correct that a lower resistance would offer higher brightness. The more current through the LED, the brighter it will be. The current is calculated by dividing the voltage across the resistor by resistance value. The voltage across the resistor would be your 5V - the voltage drop across the LED. this often varies by color. A RED LED might have a 1.2V drop, and GREEN or BLUE would be higher. So to get the same relative brightness in different color LEDS, you will often see a lower resistance used, to get the same current.
Lets say you have a 20mA Red LED, with a 1.2V drop. So (5 - 1.2)/.020 = 190 ohms. If the LED required 10mA, that would be 380 ohms.
Now you DO need to look at the data sheet for the chip driving the LED, and make sure it is up to the task. Can a pin source or sink 10mA? 20mA?


text:
digital input pins on arduino nano with standard firmata and pyfirmata are always 'None'

I have connected pin D2 on my arduino nano to high, and tried it out with an arduino c program and it works.  However, when I load standard firmata onto the the controller from the arduino IDE and try the following python program:
import pyfirmata

board = pyfirmata.Arduino('/dev/ttyUSB0')

for x in range(2,14):
    print("%s %s" % (x, board.get_pin("d:%s:i" % x).read()))

I get this:
$ venv/bin/python test.py
2 None
3 None
4 None
5 None
6 None
7 None
8 None
9 None
10 None
11 None
12 None
13 None

I can write digital pins with fermata and pyfirmata, but I can't read.
I have also tried this:
import pyfirmata

board.digital[2].mode = pyfirmata.INPUT
board.digital[3].mode = pyfirmata.INPUT

for x in range(2,14):
    print("%s %s" % (x, board.digital[x].read()))

and other combinations, and always get None
(disconnecting the wire in the picture doesn't change anything either)

I have also just repeated the experiment with an arduino uno and get the same result

so I guess my questions are:

Can anybody spot anything obvious that I am doing wrong?
Can anybody confirm that pyfirmata input ever works?
What did you do that I am not doing?

what should the resistor do?

Unless I have done something totally wrong, it is a pull down resistor in case I want to disconnect the yellow wire to see a low signal on D2.  It was necessary when I tested the set-up with arduino-c.

"None" indicates that there is no data to be found by read() because the incoming serial stream has never been serviced.  Launch an Iterator to start a new Python thread that services the serial port in the background.
it = pyfirmata.util.Iterator(board)
it.start()


text:
Reading from 2 serial ports
I have 2 Arduino Nano, they are connected via ports 2 and A2
While I use only one port to receive, it works properly. But if I activate the second port, system crash (and even first port don't work properly)
Code of first Arduino:
#include <SoftwareSerial.h>
SoftwareSerial SerialPort2(2,A2);
SoftwareSerial SerialPort3(3,A3);

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

void loop() {
  delay(500);
  SerialPort2.listen();
  if(SerialPort2.available()){
    char value = SerialPort2.read();
    Serial.print(value);
    Serial.print(" First port\n");
  }
  // IF YOU REMOVE PART BELLOW, THE 'SerialPort2' WILL WORK PROPERLY
  SerialPort3.listen();
  if(SerialPort3.available()){
    char value = SerialPort3.read();
    Serial.print(value);
    Serial.print(" Second port\n");
  }
  // END OF THIS PART
}

Code of second Arduino:
#include <SoftwareSerial.h>
SoftwareSerial SerialPort2(2,A2);

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

void loop() {
  SerialPort2.write('a');
  delay(1000);
}

PS in real system I need to listen 6 ports

you think the other side will wait until you listen? you switch listen() so fast so no port will listen

@Juraj yes of course

so no it will not wait. it has no clue to know if the port listens

switching listen() clears the receive buffer. after listen() wait for data

@Jurai each serial has own buffer

no. buffer is static

@Juraj,thnks much for your answer ,  but if I wait after listen(), I can loose data from another serial. Is any way to receive data from 2+ ports simultaneously?

@Juraj to be correct, I don't know the port from what I receive the data. I don't receive data from 2 ports simultaneously, only from one, but it may be any port

can you use RS485?

@Juraj no way, it is too big

@Jurai only ard to ard without any accessories

SoftwareSerial is only a "good" choice (for certain values of "good") if you only use one instance, and that is the only serial port in the system.
Using SoftwareSerial to read from 2 ports simultaneously is not possible.  Using SoftwareSerial to read data in tandem with any other hardware serial ports will result it data loss.
SoftwareSerial is only any real use when you are using it to request data from another device and times when you command it to happen.
To receive data in an "unsolicited" fashion SoftwareSerial is not good.
Instead you need a hardware serial port for each incoming signal. And obviously you can't do that with a small board like a nano.  So you need to think more creatively.
If you have one real serial port you can talk to one device. But there are other communication channels at your disposal. So you take one board and have that communicate to one of your serial devices. Then you take the data read and convert it into another communication protocol that is capable of sharing time with other boards. Then that, and 5 other boards, all send their data (or get data from) one central "master" board.  In effect you have 6 "UART to Protocol X" converter boards, and one "Protocol X" master board.
Alternatively choose a board that has 6 UARTs. There are many higher-end chips like some ATSAMD, SAMX, and PIC32 chips, that have 6 UARTs available to you.

SoftwareSerial can only listen to one port at a time. You cannot listen to both, no way. To really listen to both, you need an Arduino with more hardware Serial ports, where most of the protocol is done in hardware, thus can receive without CPU intervention. The Arduino Mega has 4 hardware Serial ports.
Or you could impose a protocol on the Serial stream to make the listening Arduino the master. You would listen to the first serial interface, send a start byte over this interface, that tells the slave Arduino to start sending. It sends and the listening interface receives (The transmission has to be delimited by either a time limit, e.g. listen for a specific time, or by a stop byte). Then you listen to the next interface, send again the start byte and receive. And so on.
With such a protocol, you could even use a single serial interface. The protocol makes sure, that only one slave is transmitting at a time. Though you should add resistors to every slave to protect their TX pins.

in real system I need to listen 6 ports

Serial (UART) is really not the best interface type for such topology. You should consider using interfaces like SPI. It doesn't need additional electronics and is better fit for multiple slaves.

In my system I have 6 masters and 1 slave. What interface do you recommend to use?

I have written about using 1 master, because I suggested to overthink your topology. Multi master is difficult with every interface, that you have on the Nano. You should think about, if you really need multi master functionality. You didn't describe your application, so I cannot know about that. Or, if you need it, then you may have to extend to a more complex interface, that is not supported by the Nano itself.


text:
Button debounce using millis() in this example
I have been trying to find a way to use millis() instead of delay(), in order to press 2 buttons to turn on and off a blue led.
EDITED:
const int right_button = 8, left_button = 9, yellow_led = 7, blue_led = 6, green_led = 5, red_led = 4;
int previous_left_button_status = LOW, previous_right_button_status = LOW, blue_status = LOW, green_status = LOW;
unsigned long time_setup = millis();
const int delay_task = 250;

void setup()
{
  pinMode(right_button, INPUT_PULLUP);
  pinMode(left_button, INPUT_PULLUP);
  pinMode(blue_led, OUTPUT);
  pinMode(green_led, OUTPUT);
  pinMode(red_led, OUTPUT);
  pinMode(yellow_led, OUTPUT);
  Display.clear();
}

void loop()
{
  int right_button_status = digitalRead(right_button);
  int left_button_status = digitalRead(left_button);
  unsigned long time_passes = millis();
  if (time_passes - time_setup >= delay_task)
  {
    time_setup = time_passes;
    if (right_button_status == previous_right_button_status)
    {
      green_status = !green_status;
      digitalWrite(green_led, green_status);
    }
  }
}

start with the arduino debounce example sketch ..https://www.arduino.cc/en/Tutorial/Debounce

this code does not work is a very poor description of the program behavior ... what actually happens when you run the sketch?

@jstola, my bad for not being specific ;/ my problem here is with both buttons, right/left_button_press are not working as I want them to turn on and off a LED using only delay

you have logic errors in your code .. . using the else keyword creates code that excludes one of the buttons if the other button is pressed ... each button should have a separate if statement

@jstola, so "else if" here means exactly the same as "else",  if a condition is met then do this, and if not(else) do the other one but do not execute the first condition, correct?

@jstola, why is it considered to be a logical error? what if the scenario that I want excludes one condition and activate the other? or do you mean by error, is that if I press right button to turn on a LED, i cannot turn that LED forever because of else if ?

a logic error is something like adding two numbers, when you meant to multiply ... you are monitoring two button presses, but you are excluding a button press under certain conditons because you think that the button press detection is somehow related to the lighting of an LED .... but, the LED lighting and the button press detection are really completely separate functions ... a button press should set a value of a variable, nothing more .... the resulting value can be used to determine if an LED should be lit

Let us continue this discussion in chat.

You've declared the variable for the millis function inside your loop correct and you've declared the delay duration you want to use. Two things you've missed are you've declared 2 variables with the millis function and to use it to control the program flow based on some condition to execute some code, in your case, to press 2 buttons to turn on and off an LED.
The way to to this is to use an if-else statement inside the loop function with one variable declared with the millis function, delay_duration as your reference, and 1 variable declared with a zero value.
unsigned long storeMillis = 0;
const int delay_duration = 500;

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

void loop() {
unsigned long currentMillis = millis();
if (currentMillis - storeMillis > 500) {
storeMillis = currentMillis; //update and store the value of storeMillis for the next iteration
//code you want to do
}

Thank you for your answer, I did somewhat understand your millis(). First, you have an unsigned long which has not been used, you used firstMillis, I think you meant storeMillis in that if condition, correct? Second, how do I use that in a button debounce, I still do not understand the button debounce part using millis()

I suggest that you first change the variables that you used in storing the states of the buttons from true/false to high/low. You've set your variable "left_state" as a boolean wherein you gave it a pin level of "LOW" which is a big no no. Remember that boolean is used in defining logical levels to represent a truth or not while HIGH/LOW is used to represent pin levels in Arduino.

thanks for your explanation, do you mind taking a look at my edited code? millis() is not working in my EDITED part, I still do not know why my right button is not debouncing (going with the flow, everytime I press it) it misses, waits or not turn a led ON

Great, now you need to carefully check if you're comparing the right variables in your condition. Remember that the millis() function starts keeping track of time where you declared it in your code. The variable "time_setup"' is the one that will start counting, say 0 to 5000ms, until the loop function starts. Then that will be the time your variable "time_passes" will start counting, therefore the time value of it must be lesser than the time value of "time_setup".

I suggest that you print these values in the serial monitor for you to know what's actually going on and how it's storing the time in milliseconds.

i really am confused, first you have a variable called secondMillis which was never declared anywhere, and then you did storeMillis = millis(); why didn't you store storeMillis to currentMillis ? ;/

My bad, I edited it already. I was pertaining to the second variable that I declared when I was writing this (which is currentMillis)


text:
Summarizing a repetitive code in a void loop function
How can I summarize dozens of code lines for blinking a red LED in Arduino Rich Shield? Is there a way or method to eliminate at least half of the code for repetitive scenarios?
const int redPin = 4;

void setup()
{
 pinMode(redPin, OUTPUT);
}

void loop()
{
  digitalWrite(redPin, HIGH);
  delay(250);
  digitalWrite(redPin, LOW);
  delay(250);
  digitalWrite(redPin, HIGH);
  delay(250);
  digitalWrite(redPin, LOW);
  delay(250);
  digitalWrite(redPin, HIGH);
  delay(250);
  digitalWrite(redPin, LOW);
}

void loop()
{
  digitalWrite(redPin, HIGH);
  delay(250);
  digitalWrite(redPin, LOW);
  delay(250);
}

I'm not quite sure what you're after but this is shorter and would get you equivalent results.  Since loop is going to repeat anyway, there's no need to repeat yourself inside loop.
Per the comments, not that this is particularly useful...
const int redPin = 4;

int counter = 0;

void setup()
{
 pinMode(redPin, OUTPUT);
}

void loop()
{
  if(counter < 4) {
     digitalWrite(redPin, HIGH);
     delay(250);
     digitalWrite(redPin, LOW);
     delay(250);
     counter++;
  }
}

ok I didn't know that, but what if I wanted 3 to 5 blinks and then stop red LED? would that result change in code?

If you want to stop it (and don't do anything else), move the code to setup which is only executed once.

thank you for your reply, but I want it in a loop function, to stop it from blinking after 3 to 5 blinks for instance

The point of loop is that it keeps repeating.  If you want it to stop after so many blinks then you need to have a variable that starts out at zero and adds one every time the loop runs.  Put the part that blinks the light inside an if statement that checks to see if that number is below whatever limit.

Aha now I understand the logic behind stopping a certain loop, thank you so much Delta, that was of a great help from you!


text:
Error compiling for board Arduino Nano
I have multiple Arduino Nano boards.
I am able to compile or upload code only once. If I try to compile/upload again I get an error: "Error compiling for board Arduino Nano". However there is a workaround: to be able to upload again I change something in tools menu for example board or processor.
I tried all of the nanos and all of the ports.
The error message is below (verbose is enabled).
The problem appeared from nowhere.
Thank you in advance!
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\Nauris\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328old -vid-pid=1A86_7523 -ide-version=10812 -build-path C:\Users\Nauris\AppData\Local\Temp\arduino_build_956544 -warnings=none -build-cache C:\Users\Nauris\AppData\Local\Temp\arduino_cache_309115 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Nauris\Documents\Arduino\RC\wifi_arduino\wifi_arduino.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\Nauris\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328old -vid-pid=1A86_7523 -ide-version=10812 -build-path C:\Users\Nauris\AppData\Local\Temp\arduino_build_956544 -warnings=none -build-cache C:\Users\Nauris\AppData\Local\Temp\arduino_cache_309115 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Nauris\Documents\Arduino\RC\wifi_arduino\wifi_arduino.ino
Using board 'nano' 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
Detecting libraries used...
Error compiling for board Arduino Nano.

Please enable verbose output for compilation and upload in the preferences. There might be a better error description about the problem in the verbose output

If that is really the verbose output, there is something wrong with the IDE. Have you tried reinstalling it (with the latest version)? As you are on Windows, don't install the Arduino IDE from the Windows app store, since that version is buggy as hell. Use the latest version from the official website

Sorry, didn't mention that I tried to reinstall the ide. Deleted "Arduino15" folder, deleted "libraries" folder and uninstalled arduino ide.

I resolved this issue by installing older arduino ide version.

ive been having this same issue for the last 9 or so month it is driving me insane i have uninstalled and reinstalled arduino in every way i possibly can... using revouninstaller and cccleaner and even tried starting a new user account on my computer and installing it and i still have this issue.. i can only click verify or upload one time and the very next time as soon as i click it i get the exact same error message.. and not just for the nano for every board i have on the list,, it is so irritating!!!! the only work around i have found. well the simplest is to change back and forth from nano old bootloader to atmega328.. or switch back and forth from nano and uno in the boards menu..
so when im trying to put multiple codes together and get it to compile every time i click verify i have to change the board info.. or it instantly says
Using core 'arduino' from platform in folder: C:\Program Files\Arduino\hardware\arduino\avr
Detecting libraries used...
Error compiling for board Arduino Nano.
about to just throw it all in the trash


text:
Teensy 4.1 Ethernet Throughput
Using a socket server on a Teensy 4.1, I am sending and receiving data in a loop from a Windows socket client (WinForms C#.NET).
I am sending or receiving 530 bytes of data. In each direction, it takes approximately 1.6 seconds to read or write and I think I've narrowed this delay down to the Teensy end when either client.read() or client.write(buffer, 530) are called by using Wireshark and a stopwatch in my C#.NET code on the Windows side.
The read code on the Teensy looks like this:
byte buffer[530];
int idx = 0;

while (client.available() > 0)
{
   buffer[idx] = client.read();
   idx++;
}

The write code is simply a byte array of 530 elements written like so: client.write(buffer, 530);
Is this typical? If not, is there some way to reduce this bottleneck?
Update
I found the issue - it was to do with some scanning function on the I2C bus taking up processing time. Isolating the socket server code allows it to execute very fast.

1.6 seconds sounds about 1.59999 seconds too long.

Are you opening the socket fresh each time you want to send? Is there a slow DNS lookup involved with that socket opening? Do you have other things in your code that will slow down the operation?

The socket connection is opened once and left open while the read/write loop is running. I'm using a static IP address to connect to the Teensy server so there's no DNS lookup involved.

I’m voting to close this question because the problem was elsewhere.