text:
Set SPI Mode on Arduino Uno R4
I am switching a code from Arduino Uno R3 to Arduino Uno R4 Wifi due to the limitation of RAM spaces on R3. I use a thermocouple shield and SD Card read/write shield with the project, which requires me to transfer between mode 3 and mode 0 on R3. However, when I try to do the following code on R4:
SPI.setDataMode(SPI_MODE3);

The IDE told me that SPI does not have a function named setDataMode. I tried to run the program without using setDataMode, but it does not seem work correctly (SD Cards with empty data).
Compilation error: 'class arduino::ArduinoSPI' has no member named 'setDataMode'

Thank you all for helping. the issue is resolve by using SPISettings variable along with SPI.beginTransaction(SPISettings) and SPI.endTransaction(SPISettings)

The text is pretty much what described in the question, it says: Compilation error: 'class arduino::ArduinoSPI' has no member named 'setDataMode', which this is the command to change data mode using Arduino UNO R3

the message text belongs in the question. not in a comment ... added it for you ... you can delete the comment

The first paragraph of the SPI.setDataMode() documentation said "This function should not be used in new projects. Use SPISettings. with SPI.beginTransaction(). to configure SPI parameters". I wish they could be more explicitly saying "This function is deprecated since 2014 and only exist for backward compatibility reason".

See my answer to a similar question for further explanation.

Thank you for the help @hcheung, the issue is resolved with 'SPISettings' and SPI.beginTransaction(SPISettings)

I looked at SPI.h in the R4 core here:
https://github.com/arduino/ArduinoCore-renesas/blob/main/libraries/SPI/SPI.h
It looks like you have to set up a configuration struct and pass to a different function:
arduino::SPISettings const DEFAULT_SPI_SETTINGS = arduino::SPISettings(1000000, MSBFIRST, arduino::SPI_MODE0);
    arduino::SPISettings _settings = arduino::SPISettings(0, MSBFIRST, arduino::SPI_MODE0);

Then in beginTransaction you have the opportunity to pass in those settings:
virtual void beginTransaction(arduino::SPISettings settings);

I'm not 100% sure how that all works, but at least this should get you going in the right direction.

Thanks for the help, you can reply to me either here or on the forum. I will be looking at both sides, and I will post solutions either from forum or from here once we have a solution

It would be better if you had only one post.  It's mostly the same people on both sites.  Your post there is probably better because there are a few of us that have been digging really deep on the R4.

Have you tried this?  Create the settings you need following the model in this answer and then try passing that to beginTransaction


text:
Continuous servo motor won't stop rotating
I want to use Bluetooth to control my continuous servo motor to rotate 360° once, and I used MIT app inventor for the UI to control it.
My continuous servo motor won't stop rotating even though I tried myservo.write(90).
I was wondering if anything is wrong with my hardware, or whether the problem is in my code as I am a beginner at coding and I put different functions together that I found on the internet (I was trying to make the MIT to send letters to the Arduino code where the letter would activate a command to the servo).
Here's my code:
#include <SoftwareSerial.h> // TX RX software library for bluetooth

#include <Servo.h> // servo library
Servo myservo; // servo name

int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup() {
  myservo.attach(9); // attach servo signal wire to pin 9
  // Setup usb serial connection to computer
  Serial.begin(9600);
  myservo.write(90);  // set servo to mid-point

  // Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}

void loop() {
  // Read from bluetooth and write to usb serial
  if (bluetooth.available() > 0 ) { // receive number from bluetooth
    int servopos = bluetooth.read(); // save the received number to servopos
    Serial.println(servopos); // serial print servopos current number received from bluetooth

    char c = Serial.read();
    if (c == 'a') {
      myservo.write(180);
      delay(1000);
      myservo.write(90);
    }
    else if (c == 'b') {
      myservo.write(90);
    }
  }
}

Would be really great if you could help

I'm not familiar with the Servo class, but what is its default state?  What happens if none of your code in loop() is there?  Does the servo still rotate?  Is there a command that you need to send to tell the servo not to rotate?  If there is then should you be sending this command when the bluetooth is not available, or when c is not a or b?  (Hope that makes sense)

do a sweep through all values ... hopefully the servo will stop for some

A "continuous servo" is one in which it stops rotating when the angle is set to 90 degrees, rotates forward when the angle is more than 90 degrees and rotates in reverse when the angle is less than 90 degrees.  The further from the angle of 90 degrees, the faster the continuous servo will rotate.
You can not control the angle of a continuous servo.  There is no feed back to know when it has rotated, say, 360 degrees.
You can only guess at the timing and send a command like "go to angle 100" to start rotating a continuous servo slowly forward then send a command like "go to to angle 90" to stop it after your "guessed at" time of how log it took to travel, say, a quarter the way around has elapsed.
Here is a similar Stack Exchange question where continuous servos are discussed as well.

Doesn't the angle in the Servo library goes from 0 to 180, so that the stopping value for a continuous rotation servo would be 90, just like the OP did? The main problem seems to be that the Servo doesn't stop, even at the start of the program.

The angle sent to a normal servo controls the position.  But the angle set to a CONTINUOUS servo speed and direction.  For example, you would use a normal servo to control the steering of a sumo bot.  And you would use CONTINUOUS servos to propel a sumo bot.

That wasn't my point. The OP wrote that the servo doesn't stop rotating, but with using Servo.write(90) it should, since that is normally the value for a speed of zero for cont. rotation servos. In your answer it sounds as if doing Servo.write(0) will stop the servo.

Ohh, I see what you are saying @chrisl.  From what I remember, writing a 0 stopped my continuous servos.  Maybe I'm not remembering correctly.  If writing 90 stops a continuous servo, then writing, say 45 would make them go backwards and writing, say 135 would make them go forwards.  Let me know if that is correct and I'll change my answer.  Thanks!

Ah!  Found another Stack Exchange question which agrees w/what you said.  I'll change my answer and refer to the other answer as well.

source: Stack Exchange

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

sort: votes


text:
How to limit backlight LED current in 16x2 LCD
I'm getting the error "Current through backlight led is 23.7 kA, while maximum is 20.0 mA". What am I doing wrong?

#include <LiquidCrystal.h>

LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

void setup()
{
  lcd.begin(16,2);
}

void loop()
{
  lcd.print("Arduino");
  delay(3000);
}

The two pins on the LCD which are marked "LED" are directly connected to the backlight LED. If you drive an LED over its forward voltage the current is rising exponential in relation to the voltage. Thus every LED needs a current limiting circuit, like a simple resistor in series. Otherwise the current through the LED will be so high, that it gets fried.
So to solve the problem you should place a resistor in series with the backlight LED (so for example between Vcc and the positive LED pin). The needed resistor value depends on the LED. The error message states 20mA max (just like a digital output pin on an Arduino), thus a value above R = U/I = 5V/20mA = 250 Ohm will be enough to hold the current below the maximum. To have a safety margin I would start with like 300 Ohm (depending on whats available).

Thanks for the help. I tried putting a 300 Ohm resistor on VCC but it didn't work. So I added it on LED Anode. It works perfectly now.

I meant on the connection between Vcc and the LED. But I think you have it now

While of course, this is going to fry the display. But if the current was really 23.7kA, that would be the smallest of the problems...

In ancient Egypt kA has an interesting and almost relevant meaning. Interesting to look up!

You need to limit the current going to the backlight LED by putting a resistor in series with the LED.
Currently you have the LED wired to 5V and Ground with nothing to limit the current. This will result in the LED failing from over-current.
You will want to install a 330 ohm resistor in series with the LED, like illustrated in the image below. (Note the data lines are not shown to make the circuit simpler.)

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


text:
Can I power up an Arduino Uno via the 5 V pin while USB is connected at the same time?
I want to use Grbl to control a diy CNC machine. I need to communicate with the CNC using Grbl and this is done via the PC's USB port.
So the PC's USB port is connected to the Arduino Uno which is connected to the shield and the shield and Arduino are powered from an external 5 V power source.
Can someone advise me if this is a power conflict (all grounds are common)?

Powering from the 5V pin and USB at the same time should be avoided. This is because the circuit that controls the power from the USB is triggered from the VIN / barrel jack and needs to be above about 6.5V to cause the USB power to be isolated.
It won't damage your Arduino, but there is a chance that your computer may be unhappy and shut the USB port down. 5V shouldn't cause any damage though, but it may detect that something isn't quite as it should be and take steps to protect itself.
One possible "fix" is to take any suitable disposable USB cable and strip some of the plastic outer casing from it (a couple of inches should do the job) and spread out the wire and foil shielding (assuming it exists). Locate the red wire and cut it. Join the red wires together again through a diode (ideally Schottky to reduce voltage drop) with the anode towards the computer and the cathode (stripe) towards the Arduino. This will isolate any reverse power while still providing the USB 5V to the USB interface chip's VBUS pin.


text:
ESP web server calling Javascript function
Is there a way to call Javascript functions from an ESP?
I don't want to call AJAX requests every few seconds; I want to update my values only when they change.
Can it by done?

much simpler: you can connect both the browser and the mcu to a real server. the browser connects to it via websocket, and the MCU pushes updates to the server as data becomes available.

Do you want to access the JavaScript from a browser or do you want the esp to call a server which provides JavaScript?

First thank you for the answers. I have the esp as a server and it runs a website that i am using as GUI for my esp program. Now i use XMLHttpRequest so that the browser gets data every 5 seconds and updates values in the gui. And i want to call the update function in the page whenever the values in the esp change. That's posible with the server-push or server send event? I need to google this first. Thanks for now.

@Tomas Did you see my comment on my answer? It might help you understand

Thank you all. Yes i read it and it helped. I understand it now. Sorry that i write you only now but this is my first night shift with no real work, that means that i had time to read all of your sugestions.

If you want server-push, you can use Server Sent Events or a Websocket instead of polling with XMLHttpRequest.
So yes, it can be done, and I have implemented both using a Nano 33 IoT at one end and Javascript in a browser on the other. Some example code is here: https://github.com/ocrdu/arduino-webinterface-sse and here: https://github.com/ocrdu/arduino-webinterface-websocket.
I don't know if there are convenient libraries for the ESPs to do this, though.

I am gonna Google it. Thanks

I assume that you misunderstand how JavaScript works. JS is executed on the client side and therefore the esp can easily serve JS code the same way it would provide any html content. Take a look at the Webserver examples and embed your JavaScript code into the html content that the examples use.
The important thing to note is that the esp does not execute JavaScript, from its perspective the content is just an ordinary string without functionality.
The easiest and fastest way to update values on a web interface is probably using a websocket: the esp is a websocket server (using link2004‘s websocket library) and the JavaScript binds to the esp‘s websocket as a client (this has nothing to do with the esp/arduino/C++, but you’ll find examples out there).

I am a beginner in this stuff. I know or think that my esp is a websocket server. But what that means i have no idea. To build the website gui i learned about spiffs, and little bit of html, css and javascript. It is more complex that i firstly hade in mind when i started this project. I try to learn only what i need directly for my needs. I learn mostly from examples and Google is my best friend but all the examples i found used the XMLHttpRequest. Or maybe i asked Google the wrong questions.

Well, I can‘t make you understand that within a second, but an important hint: you still need the Webserver to provide the client with html/JS code. And beside that you also need the esp to be a websocketserver. Once the websocket client (JavaScript, executed by browser, provided by esp-Webserver) has connected to the websocket server, you have a full-duplex connection in which both devices can send at any time. In the JavaScript you have to parse whatever the server sends and update the relevant values. I’ll add an example for a JS websocket client.

https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications

Here, exampleSocket.onmessage() is where all messages sent by the server arrive

This was a big help. Thanks


text:
DHT22 sensor reading code interprets negative values weirdly
The following code reads the DHT22 temperature and humidity values, assuming the pin value as the sensor's host pin.
When the temperature drops below 0°C, this code returns inadequate values in the range from -3200 to -3300 (most often the values range around -3275). When using a popular Adafruit library, the values are also incorrect. The code was not written by me, it originates from here, but the comments in the source are in Russian.

The problem is quite common, but there was no adequate solution provided in any case. It was mentioned in the Adafruit library issues quite a few times (here, here and here (related)), and on other websites. People even reported this issue on DHT11 and DHT21 sensors.

// "DHTLif.h"

#pragma once
#include <Arduino.h>
#include <Firmata.h>

uint64_t readingTime;

void DHTt(const uint8_t pin) {
  if ((millis() - readingTime) > 2000) {
    unsigned char receivedDHTData[5];
    float temperature, humidity;

    #define DHT_PORT PORTD
    #define DHT_DDR DDRD
    #define DHT_PIN PIND
    #define DHT_BIT pin
    int count = 32;
    unsigned char i, j;

    ReLoad: // Restarting point for error handling
    //=============MCU send START
    DHT_DDR |= (1 << DHT_BIT); // exit
    DHT_PORT &= ~(1 << DHT_BIT); // the pin's level is low, set it to high and wake up the sensor
    delay(18); // 18 ms delay from the docs
    DHT_PORT |= (1 << DHT_BIT); // set the pin's level to low
    DHT_DDR &= ~(1 << DHT_BIT); // the pin as exit

    //=============Initialize DHT
    delayMicroseconds(50); // delay from the docs
    if (DHT_PIN & (1 << DHT_BIT)) { // DHT must return 0
      if (count != 0) {
        goto ReLoad;
        count--;
      } else {
        // send initialization error message
        Firmata.sendString("ERR;DHTt;INIT");
        return;
      }
    }

    delayMicroseconds(80);
    if (!(DHT_PIN & (1 << DHT_BIT))) { // the bus must be set to 0 after 80 ms
      if (count != 0) {
        goto ReLoad;
        count--;
      } else {
        // send weird behaviour error message
        Firmata.sendString("ERR;DHTt;BHVR");
        return;
      }
    }

    //===============Receive 40 bits of data
    while (DHT_PIN & (1 << DHT_BIT)); // wait until the bus is set to 1
    for (j = 0; j < 5; j++) { // loop for 0-4 bytes
      receivedDHTData[j] = 0;
      for (i = 0; i < 8; i++) { // receive bits and pack them into bytes
        while (!(DHT_PIN & (1 << DHT_BIT))); // wait until the bus is set to 0
        delayMicroseconds(30); // 30 ms delay from the docs
        if (DHT_PIN & (1 << DHT_BIT)) // if the pin is 1 after the delay,
          receivedDHTData[j] |= 1 << (7 - i); //set the i'th bit to 1
        while (DHT_PIN & (1 << DHT_BIT)); // wait until the bus is set to 0
      }
    }

    if ((unsigned char)(receivedDHTData[0] + receivedDHTData[1] + receivedDHTData[2] + receivedDHTData[3]) != receivedDHTData[4]) { // checksum
      Firmata.sendString("ERR;DHTt;CHSM");
      return;
    }

    temperature = (receivedDHTData[3] * 0.1) + ((receivedDHTData[2] & 0b01111111) * 25.6); // calculating temperature for DHT22
    if (receivedDHTData[2] & 0b10000000) temperature *= -1; // if the temperature is negative
    humidity = (receivedDHTData[1] * 0.1) + (receivedDHTData[0] * 25.6); //calculating humidity for DHT22

    // form the final message
    char result[32], catres[8];
    readingTime = millis();
    strcpy(result, "OK;DHTt;");

    dtostrf(temperature, 5, 2, catres);
    strcat(result, catres);
    strcat(result, ";");
    dtostrf(humidity, 5, 2, catres);
    strcat(result, catres);
    Firmata.sendString(result);
    return;
  }
}

The only fix I found looks really silly and it does not work, the values don't drop below zero.
// The temperature is a 16 bit signed integer, 10 times the actual value in degrees Celsius
int16_t temperatureTimesTen = (int16_t)((receivedDHTData[2] << 8) | receivedDHTData[3]);
float temperature = (float)(temperatureTimesTen) * 0.1f;

// The maximum possible temperature for an DHT22 is 80 degrees Celsius
if (temperature > 80) temperature = temperature - 3276.7f;

That seems to be a bit of a silly way of combining bytes to form a 16 bit value if you ask me...

I've got the exactly same code in another library. I'll try to put my DHT22 into the freezer tomorrow and see what happens.

@Majenko, at least this thing manages to work while the temperature is positive. I now wait until the temperature outside drops below zero, since my DHT22 is installed outside without a possibility to move it. Maybe, changing temperature *= -1; to temperature *= -1.0f; will help?

That's unlikely to help, because temperature is already a float at that point.

Looking at the data sheet (Page 3), the DHT22 uses, unlike the DHT11 and unlike the implementation in many libraries, a standard Base-2 format for the temperature. So converting the temperature should be as easy as:
// The temperature is a 16 bit signed integer, 10 times the actual value in degrees Celsius
int16_t temperatureTimesTen = (int16_t)((receivedDHTData[2] << 8) | receivedDHTData[3]);
float temperature = (float)(temperatureTimesTen) * 0.1;

I was not able to confirm this yet (couldn't get my sensor cold enough), but your observation that the wrong values report as being in the order of -3300 point to the same conclusion.
EDIT
I need to correct myself. The documentation is misleading, therefore my understanding of it was incorrect. After I finally got the possibility to really test my DHT22 in negative temperatures (it's snowing outside now), I found the correct formula to be:
int temp = ((receivedDHTData[2] & 0x7F) << 8 | receivedDHTData[3]) * 0.1;
// if MSB = 1 we have negative temperature
temp = ((receivedDHTData[2] & 0x80) == 0 ? temp : -temp);

return temp; // in degrees celsius

EDIT 2
For this particular sensor, decoding seems to be as follows. It appears that on negative temperatures, the resolution is only 1 degree, not 0.1 degrees.
float temperature = 0;
int32_t temp = ((receivedDHTData[2]) << 8 | receivedDHTData[3]);
// if MSB = 1 we have negative temperature
if (temp & 0x8000)
{
    temp = temp | 0xFFFF0000; // sign-extend
    temperature = temp; // Convert to negative whole-degrees
}
else
{
    temperature = (float)temp / 10.0f;
}

I will try to implement this solution. I will get back to you shorty after getting any results.

That didn't help, the -3275-like values are still reported.

That is weird. Can you try to print out the values of receivedDHTData[2] and receivedDHTData[3]? The byte value at index 2 should be 255 (0xFF) if my assumption is right.

indeed, it does: https://skr.sh/i/031121/YWJ4uO4E.jpg?download=1&name=Скриншот%2003-11-2021%2016:26:01.jpg

When I feed my code with exactly these values I get the correct result. Maybe this is also a compiler/board issue? I have tested on an AVR board (Arduino Nano)

my board is also an AVR-based Arduino Uno. I am using this simple sketch: https://github.com/StarterCraft/Hyrex_AsQamm/blob/6eb87320997e0b2cf4a714d13f210cb1359f640e/AsQammArduino/DHTTest/DHTTest.ino

and this is a Serial.println-converted version of the code in question: https://github.com/StarterCraft/Hyrex_AsQamm/blob/6eb87320997e0b2cf4a714d13f210cb1359f640e/AsQammArduino/Features/DHTLifo.h

Please use the code I posted above exactly as it is, replacing lines 71 and 72. Do not squeeze it into one line (two casts on the same line may confuse some compilers).

replaced the lines, please check.

nothing has changed after changing this statement to a two lines.

Let us continue this discussion in chat.

I just saw https://stackoverflow.com/questions/69870078/visual-studio-c-has-different-comparison-results-for-uint16-and-uint32?noredirect=1#comment123516299_69870078 Maybe this is related. You should maybe try a manual sign-extend?

Could you confirm your information with freezing the sensor?

No, I didn't have the time to test this again. I seriously wonder why you get different results than I am. I will try again.

@Starter I'm sorry this took so long, but I think the above formula should now do the trick. The data was different than what I expected from the documentation.

https://skr.sh/i/051221/kWFdQYc1.jpg?download=1&name=Скриншот%2005-12-2021%2014:27:41.jpg that didn't help, though :<

@Starter: That looks like what I originally expected that it should be, but my observation showed a different binary pattern for negative temperatures. Are you sure you have a DHT22? These are the sensors with the white enclosure.

Yes, I am totally sure. This is the item card from the Aliexpress seller I've bought the sensor from. I use the DHT22 Module variant. Also, can you please share your binary data? https://github.com/StarterCraft/Hyrex_AsQamm/blob/29eb8f825140b98287feeb3cac1f1e4cc3ada88c/AsQammArduino/Features/DHTLifo.h#L72 is the code producing my output

My data was [2] = 0x80 and [3] = 0x04 for -0.4°C. Yours looks like base-2 encoded. Can you confirm that the correct temperature is -2.5°C?

Right now, according to local weather forecast provider (https://skr.sh/i/061221/qEcPFcRN.jpg), the temperature is around -9 degrees Celsius, and this is the current binary data: https://skr.sh/i/061221/fYC1gHnH.jpg

Also please fix your syntax: there is no var in C++, there is auto

1111 1111 1111 0111 is -9 in standard base-2 encoding. There's no DHT variant I'm aware of that uses this encoding, particularly since all variants provide the temperature in tenths of a degree. Do you have the possibility to get a data set with a positive measurement?

can you offer me a way to decode this correctly?

I am afraid I can't do this, my sensor is installed statically outside

I think the following should do: int32_t temperature = ((receivedDHTData[2] << 8) | receivedDHTData[3]); if (temperature & 0x8000) temperature |= 0xFFFF0000; The result is then in whole degrees.

https://skr.sh/i/071221/bF9R2Yb2.jpg?download=1&name=Скриншот%2007-12-2021%2009:31:24.jpg Positive reading

It gets more confusing each time :-( As you show, this is decoded correctly, and 100101b is 37 decimal, which can (as specified) be correctly divided by 10 to result in 3.7°. (I'm assuming it's not 37° outside) I've more and more got the impression that you've got some chinese clone there that doesn't align with the official specs. I'll add the suggested code for this finding above, but it must remain a guess.

https://skr.sh/i/141221/775SSTjY.jpg?download=1&name=Скриншот%2014-12-2021%2008:36:51.jpg oumph, that's pretty cold. I think I need to multiply it by 0.1

Yea, apparently. Then at least it would be consistent. Still not sure why my first suggestion didn't match then. However, I'm happy that it finally works for you.

I ran into this issue of getting -3200 values. I swapped the sensor with another one from the same vendor (tenstar robot on ali express) and the values for the 2nd sensor were normal. I put a regular thermometer next to the sensor and the reading are within a couple of degree of each other at -15c. I am supplying my sensors with 3.3 volts which in some cases can also cause issues.  Might be worth trying 5 volts to see it that makes any difference.


text:
How to get rid of low quality sound out from DFPlayer plus amplifier?
I use my Seeeduino V4, DFPlayer mini, and this speaker module from AliExpress to create an automatic doorbell.  The problem is that it seems that this speaker module's Yurobot amplifier is not powerful enough to create a noise-free loud sound. Also, the bundled speaker is 0.5 W, 8 Ω.
There is a volume selector on the speaker module. If it is selected to a value a bit higher than 0 then the sound's quality is quite high (click here to listen), but the volume is not enough by far for a doorbell, even though the DFPlayer's programmed volume is set to maximum.
But if I increase the amplifier's volume selector to something near maximum, I start hearing some very scary noises (please click here to listen).
How can I increase the volume without having hard-to-listen-to noises? Maybe I need to buy another, better amplifier?

The DFPlayer already has a 3W amplifier on it you can connect a 3W speaker to. If you connect an extra amplifier to the DPlayer and turn the volume of the DFPlayer up, the second amplifier will probably clip. You could try how the DFPlayer sounds when you connect a speaker directly to it; a 3w speaker would be good for this.

I don't have a 3W speaker currently at my's, so I can't do such a test. Also, my only speaker has a unique connector that is compatible with the speaker module I talked about in the question.

If you want a load sound, you should buy a speaker with the wattage of your amplifier (here the 3W amp of the DF player).

@chrisl, otherwise I'll get rasps and hard-to-listen-to noises?

I think that is because your extra amp module is clipping the sound,  since it reached its maximum amplification. In that case you get distorted sounds (that how the distortion with e-guitars works). But with the 3W speaker you could enable to full potential in the DF player and then see, if that is load enough. On aliexpress there is mostly few to none documentation, so we cannot know, how strong the amp module is. But judging from the speaker, that came with it, I would say, that it is weaker than the DF player.

Somewhat related: https://arduino.stackexchange.com/questions/79260/how-to-use-an-arduino-speaker-module-with-dfplayer-mini/79261#79261

can I use a 50 Ohm speaker? Are there the speaker's ohmnage restrictions?

Also, the datasheet says about a drive speaker **less** than 3W. Does this mean that I can use only 2W speakers maximally?

I would think, the "less than 3W" is just a not ideal phrasing. 2.99W would be less than 3, so like 3W max. I would interpret this as 3W max.

You can use a higher wattage speaker with the same impedance. If you have a 5W instead of a 1W and they are both 8 ohms you should be able use the 5W unit without any problems. I would expect the 50 Ohm to work but the sound level will be low. Wattage is the amount of power it can withstand, not its SPL or efficiency of the speaker. Generally increasing the impedance of the speaker is not a problem however lowering it can be very quickly cause problems.

The DFPlayer already has a 3 W amplifier on it, so you can connect a speaker directly to the DFPlayer. There is no need for an extra amplifier.
If you do connect an extra amplifier to the DPlayer, and turn the volume of the DFPlayer up too far, the input of the second amplifier will clip and it won't sound good.
Also, the output of the DFPlayer is probably from a class-D amplifier designed to be connected directly to a speaker; it won't play nice with other amplifiers.
You should try how the DFPlayer sounds when you connect a speaker directly to it. The 0.5 W speaker you have is not a good fit; it can't handle the power of the DFPlayer's amplifier.
A 3 W (or more), 8 Ω speaker would be good for this if you want to use the maximum power the DFPlayer can deliver. According to most publications on the interwebs a 2 W, 8 Ω speaker will also do, but I would be careful with turning the volume all the way up.
Note that the DFPlayer can pull a fair bit of current (about 25 mA in standby, and in the order of 200 mA when playing) and it needs a power supply that can deliver that.

I'm probably going to be playing with a couple of these soon and this contains some useful information to me.  Welcome to 1K.

@timemage: Thanks! Note that if you only need to play short sound bites for a user interface or something like that, the memory and DAC of anything SAMD21-based will also do.

The problem has been solved by buying a YD103-O4B 8Ohm 4W speaker. Thanks for the help!

Interesting! The wattage rating of the speaker does not affect its loudness, the efficiency does at a given wattage. Wattage is the maximum amount of power you can drive the speaker with, that does not indicate the source can provide more or less. The SPL (SPL stands for sound pressure level and is also commonly referred to as efficiency and sensitivity.  This parameter represents how loud a speaker is.  A higher SPL equates to a louder speaker). To get more volume out of a speaker you have to put more power in. Ohm's Law explained this. The impedance (AC Resistance) of the speaker varies with frequency but typically a nominal number such as 8 ohms is used.  Looking at Ohm's law the only way to get more power is to lower the impedance or increase the voltage with voltage being the most popular as well as the easiest. Putting more power into a speaker then it is rated at will eventually destroy it as well as distort the sound. This may not be noticeable to the human ear at low amounts but it is there.  Also the sound coming out is directly related to the signal going in. Clipping is a common occurrence when the amplifier is being over driven ie. it is asked to put out a higher voltage then it is capable of. There is an old saying garbage in garbage out. That includes the components as well. To solve your problem you probably need an amplifier capable of doing what you want and a speaker that will at a minimum handel the worse case power you will send it.

I am sorry if my questions are stupid, but is it possible to calculate the SPL of a speaker? Actually, this answer is very interesting, but it actually seems like I will need to experiment with multiple speakers... This will take a long, according to AliExpess' shipping durations. I actually hope that a 2W 8Ohm speaker will work correctly without an amplifier, but directly connected to the DFPlayer, as had people suggested some time ago.

It is relative involved with math. The easiest is to use a calculator. A good one is found here: https://myhometheater.homestead.com/splcalculator.html This works quite well. Have fun with it!

i was experiencing the same phenomen in my project , and got to this page in my research . I am using a tda 2003 amplifier and the speaker is a intercom that i modify so changing the speaker is out of question also the amplifier is a good and versatile . The problem is in the gain setting of the amplifier . I was using a 220ohm resistance on the gain setting . going back an forth i was getting better sound with low gains. i hooked up a potetiometer in the place of the resistance to fine tune the gain aand at 8 ohms i get the sound that i want.


text:
Code does not run when Arduino is powered by AC adapter
I'm trying to implement the circuit as shown with an Arduino Nano. The project runs fine when powered via the USB port of the Arduino. However, the code freezes when connected to an AC adapter. When switched back to power supply via USB, the code does not run and resetting the board has no effect. The board starts to work again only when the code is re-uploaded.
Tried the following to troubleshoot the issue with no success:

Changed the power supply
Tried with a blink sketch and an example code of U8glib
Eliminated the MOSFET's Q1 & Q2 to simplify further

The only other component in question seems to be the buck converter connected between the AC adapter and the Nano board, but it is rated for 5 V, 3 A and should not be of concern I believe. I appreciate your inputs.
I uploaded a blink sketch to the Nano. It works OK over the USB power, but it starts resetting randomly when connected to the power supply. I swapped the buck converter with an LDO and it seems to work flawlessly. The output of the buck converter reads about 5.18 V and according to the ATmega328p datasheet, it can accept up to 5.5 V.
Could the problem be associated with the switching frequency of the buck converter (the stated switching frequency is about 500 kHz).
P.S. I'm using the Nano clone. I'm not sure if it adheres to the original parameters as stated in the ATmega datasheet.

what happens if you unplug the nano from the circuit?

Unfortunately, can't uplug the nano as it is soldered onto the PCB.

That the code has to be re-uploaded to get it to work sounds strange. Maybe show your software. Does it have a line like while ( ! Serial ) ;  ?

I'm using the same code as given in the following link.https://github.com/nppc/Heater12VControl/blob/master/Arduino/HeaterControlV2/HeaterControlV2.ino However, the problem persists even with simpler codes as well.

What is the rating of the power supply. What is the power supply and converter voltages when running off power supply?

Power supply is rated 15V, 65W. This voltage is stepped down to 5V using a buck converter(CN3903).

so is the Nano powered over Vin with 12 V or directly over 5 V pin?

The nano is powered over the 5V pin

Uploaded a blink sketch to the nano. Works ok over the USB power. But it starts resetting randomly when connected to the power supply. Swapped the buck converter with an LDO and it seems to work flawlessly. The output of the buck converter reads about 5.18V and according to the Atmega328p datasheet, it can accept upto 5.5V. Could the problem be associated with the switching frequency of the buck?(The stated switching frequency is about 500kHz) P.S- I'm using the nano clone. Not sure if it adheres to the original parameters as stated in the Atmega datasheet.

I assume you have this in your setup:  pinMode (D6, OUTPUT); If not it will remain an input.

Yes, D6 is defined as an output

You should use a decoupling capacitor on the nano board (something as 10uF//100nF). On the OP original picture, eventually, replace D1 or add a serial resistor (100 Ohm or more, see current needed ?)

Is the buck converter properly filtered?
Many ebay/amazon supplies are done too cheaply. While LEDs will run from practicaly anything with at-least some sign of correct specs, combination of back converter trying to keep-up with changing current and compensate to achieve correct voltage, while voltage regulator is adjusting and as such changing the consumption characteristics... dependant on buck converters changes.
MCU requirements for clean supply are lot greater them that of LEDs.
Bunch of suitable capacitors after the buck converter, but before the arduino might do it. Hopefuly somebody better then me in that area might advice you bout capacitor values. mine rough guess would be 100nF of about 20V.

I think the buck converter module has a capacitor at the output. According to the datasheet, it's rated around 20uF-60uF.

try holding ones legs next to the input (its normal for Amazon/ebay sellers to take description from other listing without checking)


text:
Non-blocking sketch
So far, a part of this code works fine, but Relay 1 keeps turning on and off instead of staying off.
My purpose is to turn Relay 7 on, wait 3s, turn Relay 8 on, wait 10s, turn Relay 6 on, wait 10s, turn Relay 7 off, wait 10s, turn Relay 5 on, wait 3s, turn Relay 6 off, wait 10s, turn Relay5 on, wait 3s, turn Relay 6 off, wait 10s, turn Relay4 on, wait 3s, turn Relay 5 off, wait 10s, turn Relay 3 on, wait 3s, turn Relay 4 off, wait 10s, turn Relay 2 on, wait 3s, turn Relay 3 off, wait 10s, turn Relay 1 on, wait 10s, turn Relay 1 off, wait 3s, turn Relay 8 off, without looping, only one sequence.
I need some help.
int RelayPompe = 2;
int RelayVanne7 = 3;
int RelayVanne6 = 4;
int RelayVanne5 = 5;
int RelayVanne4 = 6;
int RelayVanne3 = 7;
int RelayVanne2 = 8;
int RelayVanne1 = 9;

const unsigned long eventInterval1 = 10000;
const unsigned long eventInterval2 = 3000;
const unsigned long eventInterval3 = 15000;
const unsigned long eventInterval4 = 20000;
unsigned long previousTime1 = 0;
unsigned long previousTime2 = 0;
unsigned long previousTime3 = 0;
unsigned long previousTime4 = 0;

void setup() {
  Serial.begin(9600);
  pinMode(RelayPompe, OUTPUT);
  pinMode(RelayVanne1, OUTPUT);
  pinMode(RelayVanne2, OUTPUT);
  pinMode(RelayVanne3, OUTPUT);
  pinMode(RelayVanne4, OUTPUT);
  pinMode(RelayVanne5, OUTPUT);
  pinMode(RelayVanne6, OUTPUT);
  pinMode(RelayVanne7, OUTPUT);
  digitalWrite(RelayPompe, HIGH);
  digitalWrite(RelayVanne1, HIGH);
  digitalWrite(RelayVanne2, HIGH);
  digitalWrite(RelayVanne3, HIGH);
  digitalWrite(RelayVanne4, HIGH);
  digitalWrite(RelayVanne5, HIGH);
  digitalWrite(RelayVanne6, HIGH);
  digitalWrite(RelayVanne7, HIGH);
}

void loop() {
  unsigned long currentTime = millis();
  if (currentTime - previousTime1 >= eventInterval1) {
    digitalWrite(RelayPompe, LOW);
    previousTime1 = currentTime;
  }
  if (currentTime - previousTime2 >= eventInterval2) {
    digitalWrite(RelayVanne1, LOW);
    previousTime2 = currentTime;
  }
  if (currentTime - previousTime3 >= eventInterval3) {
    digitalWrite(RelayVanne2, LOW);
    previousTime3 = currentTime;
  }
  if (currentTime - previousTime4 >= eventInterval4) {
    digitalWrite(RelayVanne1, HIGH);
    previousTime4 = currentTime;
  }
}

which one is relay 1?

please review what you wrote ... there appear to be some mistakes

@jsotola "RelayPompe is number 1 and connected to pin 2 of arduino board"

the code you presented does not continually cycle RelayPompe, unless the arduino repeatedly resets ... add some debugging code to determine what is happening

have you read your description of the desired sequence? ... there appears to be an error that messes up timing

stil cant figure it out.

you said wait 10s turn Relay 5 On, wait 3s turn Relay 6 Off twice in a row

it is a watering system I need to turn on relay 1 first wich connected to Solenoid Valve 1 then turn on relay 8 wich is connected to waterpompe and keep it running the rest of sequence, then turn on relay2 -Solenoid Valve2 after 3s turn off relay1 then after 10s turn on relay3-Solenoid Valve3 then after 3s turn off relay2 ...  until relay8-Solenoid Valve8 , at the end turn off relay 8-waterpompe and finish sequence. by the way  3s and 10 are just for testing later wil modify to longer period

For this kind of thing I'd be inclined to create an array (maybe of structs) describing what you want the relays to do, then write a program that steps through that array executing each "instruction" in sequence. That way it separates out what you want to do from how you want it to be done (if that makes sense).
So you could make a simple struct:
typedef struct {
    uint8_t relays;
    uint32_t postDelay;
} RelayState;

Then you can make an array using that struct to describe your relay states. Using a bitmap for your relays (bit 0 is relay 1, bit 1 is relay 2, etc) means you can pack everything into one integer and describe the relays in binary notation:
RelayState states[] = {
    { 0b01000000,  3000 }, // Relay 7 on, wait 3 seconds
    { 0b11000000, 10000 }, // Relay 8 on, wait 10 seconds
    { 0b11100000, 10000 }, // Relay 6 on, wait 10 seconds
    { 0b10100000, 10000 }, // Relay 7 off, wait 10 seconds
    { 0b10110000,  3000 }, // Relay 5 on, wait 3 seconds
    // ... etc ...
    { 0, 0 } // Marker for the end of the array
};

If ever you want to change the sequence you just change the contents of that array with no need to mess with the rest of your program.
It can also be useful to create an array with your relay pins in it:
const uint8_t relayPins[8] = { 9, 8, 7, 6, 5, 4, 3, 2 };

Now you just need to write a small program that only has to deal with the current entry in the array - set the relays according to the first part then delay according to the second part, and step to the next entry.  Something that could look like:
void setup() {
    // Set the relay pins to outputs
    for (int i = 0; i < 8; i++) {
        pinMode(relayPins[i], OUTPUT);
    }

    // Set the initial state from the first entry in the array
    setRelays(states[0].relays);
}

void loop() {
    static uint32_t ts = millis(); // Storage for the time
    static uint8_t pos = 0;

    if ((millis() - ts) >= states[pos].postDelay) { // Our time is up
        ts = millis(); // Record the time
        pos++; // Move to the next entry
        if ((states[pos].relays == 0) && (states[pos].postDelay == 0)) { // Last entry marker
            pos = 0; // Start from the beginning again
        }
        setRelays(states[pos].relays);
    }
}

// Small helper function to set the relays according to a bitmap
void setRelays(uint8_t bm) {
    for (int i = 0; i < 8; i++) {
        digitalWrite(relayPins[i], bm & (1 << i));
    }
}

Note: this code has not been tested, just written "off the cuff", and may not even compile. But regardless, it should give you a rough idea of the methodology.

The format of the bitmaps is very simple. They're just a binary representation of a number where each bit is one relay. Turn that bit on and the corresponding relay turns on.

Relay 1: 0b00000001
Relay 2: 0b00000010
Relay 3: 0b00000100

etc.  Just set a 1 for a relay to be on and a 0 for a relay to be off at that point in time.
So turn relay 1 on is 0b00000001, then turn on relay 4 at the same time is 0b00001001, and then turn relay 1 off again is 0b00001000 (relay 4 is still on).

I got it I have to write all binary for all pins, I wil give it a try

plz explain to me how to add more entry in array:{ 0b01000000,  3000 }

what is { 0b01000000,  3000 } and how to add all the relays?

0bxxxxxxxx is the state of each of the 8 relays. 3000 is how many ms to delay for.

3000 is the ms delay but 0bxxxxxxxx, how to add all the 8 relays wich rule to create it?

Decide which relays you want on and which you want off - relay 8 is on the left and relay 1 on the right. 1 for on, 0 for off. So turning on relays 1 5 and 7 would be 0b01010001.


text:
I2C requesting more than one byte
I got an Arduino Uno set up as an I2C master to an ATtiny85 slave, using the Wire (Master) and TinyWireS (Slave) libraries.
Communication works well. I have been able to keep the network running correctly for hours. However, I have not been able to let the master request more than a single byte from the slave.
Using the code below the master asks for 4 bytes from the slave, but in my serial console I get only an actual value for the first bytes. The next three bytes read 255.
How can I request multiple bytes from the slave, using the Wire library?

Master (Arduino Uno)
#include <Wire.h>

#define I2C_MASTER_ADDR 0x04
#define I2C_SLAVE_ADDR 0x05

int pollInterval = 700;//Milliseconds
unsigned long lastPoll = 0;

void setup()
{
  Wire.begin(I2C_MASTER_ADDR);  // join i2c bus
  Serial.begin(115200);
  Serial.println("Setup complete");
}

/*
 * The main loop
 */
int i = 0;

void loop()
{

  //Writing to the slave
  if( (millis()-lastPoll) > pollInterval)
  {
    Wire.beginTransmission(I2C_SLAVE_ADDR);
    Wire.write(0x01);//Register to start at
    switch(i)
    {
      case 0:
        Wire.write(255);
        Wire.write(0);
        Wire.write(0);
        i++;
        break;
      case 1:
        Wire.write(0);
        Wire.write(255);
        Wire.write(0);
        i++;
        break;
      case 2:
        Wire.write(0);
        Wire.write(0);
        Wire.write(255);
        i = 0;
        break;
    }
    Wire.endTransmission();

    delay(1);//Dont let the slave panic

    //Set the register pointer back to 0x01, preparing for a read
    Wire.beginTransmission(I2C_SLAVE_ADDR);
    Wire.write(0x00);//Register to start at
    Wire.endTransmission();
    delay(1);//Dont let the slave panic

    //Get values from the three registers up from 0x01
    Wire.requestFrom(I2C_SLAVE_ADDR, 4);//Request N bytes
    while (Wire.available())
    {
      uint8_t next_byte = Wire.read();
      Serial.print(next_byte);Serial.print(" ");
    }
    Serial.println("\n");

    lastPoll = millis();
  }//End if time to poll again

}//End loop

Slave - ATTiny85
#include <EEPROM.h>
#include <TinyWireS.h>
#include <Bounce2.h>
#include <WS2812.h>
#ifdef __AVR__ //Which will be true for ATtiny85
  #include <avr/power.h>
#endif

#define I2C_SLAVE_DEFAULT_ADDR 0x05
#define BUTTON_DEBOUNCE 5//Debounce milliseconds

#define NEOPIXEL_PIN  1
#define BUTTON_PIN    3

#define NUMPIXELS     1

/*
 * I2C Registers
 *
 * Register map:
 * 0x00 - Button state
 * 0x01 - led value red
 * 0x02 - led value green
 * 0x03 - led value blue
 *
 * Total size: 4
 */
const byte reg_size = 4;
volatile uint16_t i2c_regs[reg_size];

/*
 * Internal variables
 */
cRGB value;
volatile boolean led_needs_update = false;
volatile byte reg_position;

/*
 * Initialize instances/classes
 */
Bounce button = Bounce();
WS2812 led(NUMPIXELS);

void setup()
{
  //Start I2C
  //uint8_t _device_addr = EEPROM_DATA::get_device_addr();
  TinyWireS.begin(I2C_SLAVE_DEFAULT_ADDR);
  TinyWireS.onReceive(i2cReceiveEvent);
  TinyWireS.onRequest(i2cRequestEvent);

  //Start Led
  led.setOutput(NEOPIXEL_PIN);
  value.b = 255; value.g = 0; value.r = 0;
  led.set_crgb_at(0, value); //Set value at LED found at index 0
  led.sync(); // Sends the value to the LED

  //Start Button
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  button.attach(BUTTON_PIN);
  button.interval(BUTTON_DEBOUNCE);

}

void loop()
{
  button.update();

  if(led_needs_update)
  {
    led_update();
    led_needs_update = false;
  }

  if(button.fell())
  {
    i2c_regs[0x00] = true;
  }
  if(button.rose())
  {
    i2c_regs[0x00] = false;
  }

  // This needs to be here for the TinyWireS lib
  TinyWireS_stop_check();

}

/*
 * I2C Handelers
 */
void i2cReceiveEvent(uint8_t howMany)
{
    if (howMany < 1)
    {
        return;// Sanity-check
    }

    reg_position = TinyWireS.receive();
    howMany--;
    if (!howMany)
    {
        return;// This write was only to set the buffer for next read
    }

    while(howMany--)
    {
        //Store the recieved data in the currently selected register
        i2c_regs[reg_position] = TinyWireS.receive();

        //Proceed to the next register
        reg_position++;
        if (reg_position >= reg_size)
        {
            reg_position = 0;
        }
    }
    led_needs_update = true;
}//End i2cReceiveEvent()

void i2cRequestEvent()
{
    //Send the value on the current register position
    TinyWireS.send(i2c_regs[reg_position]);

    // Increment the reg position on each read, and loop back to zero
    reg_position++;
    if (reg_position >= reg_size)
    {
        reg_position = 0;
    }
}//End i2cRequestEvent

/*
 * Helper functions
 */
void led_update()
{
  cRGB val;
  val.r = i2c_regs[0x01];
  val.g = i2c_regs[0x02];
  val.b = i2c_regs[0x03];
  led.set_crgb_at(0, val);
  led.sync(); // Sends the value to the LED
}

This is another case where the Arduino documentation is horribly incomplete to the point of being useless, and you must refer to the source code itself.
Presuming your TinyWire library works like the ordinary Arduino Wire, you need to use the two-argument form of the write method:
size_t TwoWire::write(const uint8_t *data, size_t quantity)

So your handler would probably look like this
void i2cRequestEvent()
{
    TinyWireS.write(i2c_regs, sizeof(i2c_regs));
}

However, you're also going to need to change your definition to an 8-bit type, rather than the 16-bit one you surprisingly had
volatile uint8_t i2c_regs[reg_size];

If you really do need to use a 16-bit type, then you'll need to either double the transfer size (since both processors are AVRs you won't hit any byte order issues) or first copy the values that you care about to a byte buffer.

Thanks for your answer. I updated uint16_t to uint8_t, my mistake.
The TinyWireS uses the following write command, accepting only a single argument:
void USI_TWI_S::send(uint8_t data){  // send it back to master
usiTwiTransmitByte(data);
}
But as far as I understand that's actually normal I2C convention: the Wire library should request multiple bytes, one at a time. The slave responds with one byte to each request, jumping to the next register afterwards so the next requested byte comes from the next register.

It may offer a single argument write, but that won't work for you.  Check its source code and see if it also offers a two argument write - the normal Wire library offers both.  If not, you'll probably have to modify the library.  And no, i2c convention is to request multiple bytes at once, which is what you are doing.   However, if you write a starting register in the preceding write, then you could I guess do distinct one-byte requests for each register in turn.

Hi @Chris, thanks again. I could only find a single argument write. In terms of performance, would making multiple one-byte requests slow things down (compared to a wire.request N bytes request)? Just figuring out my options, based on your answer/comment.

Yes, multiple one byte requests would be slower.  Also, it might yield values that aren't consistent with one another but come from different data points.   You should be able to create a multi-byte write by comparing the source of the usual Wire library which has it with yours which apparently does not, and using that to write one - ie, figure out the differences between the two for the single byte case, and then apply those to the multi-byte code.

The master uses the 'normal' Wire library, but the TinyWireS is not normal at all. The master defines how many bytes are read. The slave can send a byte or not. If the slave does nothing, then the data will become 255. Could you try a requestEvent with four calls to TinyWireS.send with fixed numbers. For example TinyWireS.send('A') and 'B', and 'C' and 'D', or with numbers.

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


text:
Keeping Adafruit Feather charged
I'm creating a keyboard for someone using an Adafruit Feather 32u4 Bluetooth LE as the brains. The case I want to put in into would be hard to remove to charge the battery.
Can I use this USB LiIon/LiPoly charger to charge the LiPo battery and keep power to the board? And then unpluging from the USB mini-B would switch over to the battery?

From the very page you linked to:
"... we added a connector for any of our 3.7V Lithium polymer batteries and built in battery charging. You don't need a battery, it will run just fine straight from the micro USB connector. But, if you do have a battery, you can take it on the go, then plug in the USB to recharge. The Feather will automatically switch over to USB power when its available. We also tied the battery thru a divider to an analog pin, so you can measure and monitor the battery voltage to detect when you need a recharge."
So, the board has a charger and battery connector already built in.


text:
How to send HTTP requests to specific port using Ciao?
I currently have a working REST client on my Arduino, but the requests always go to port 80. How do I make it send the request to a specific port?
This is my current code:
/*
File: RestClient.ino
This example makes an HTTP request after 10 seconds and shows the result both in
serial monitor and in the wifi console of the Arduino Uno WiFi.

Note: works only with Arduino Uno WiFi Developer Edition.

http://www.arduino.org/learning/tutorials/boards-tutorials/restserver-and-restclient
*/

#include <Wire.h>
#include <UnoWiFiDevEd.h>

void setup() {
  const char* connector = "rest";
  const char* server = "download.arduino.org";
  const char* method = "GET";
  const char* resource = "/latest.txt";

  Serial.begin(9600);
  Ciao.begin();
  pinMode(2, INPUT);
  delay(10000);
  doRequest(connector, server, resource, method);
}

void loop() {
}

void doRequest(const char* conn, const char* server, const char* command, const char* method) {
  CiaoData data = Ciao.write(conn, server, command, method);
  if (!data.isEmpty()) {
    Ciao.println( "State: " + String (data.get(1)) );
    Ciao.println( "Response: " + String (data.get(2)) );
    Serial.println( "State: " + String (data.get(1)) );
    Serial.println( "Response: " + String (data.get(2)) );
  } else {
    Ciao.println ("Write Error");
    Serial.println ("Write Error");
  }
}

If I add for example :8080 to the end of the server variable, it does not work.
How do I make that request go to a specific port?

Chances are you can't unless 'Ciao' allows you to.  Have a look a PAT, port forwarding or proxy servers.  Depending on you topology one of those may be able to help.

change the firmware to WiFi Link https://github.com/jandrassy/UnoWiFiDevEdSerial1#uno-wifi-with-wifi-link-firmware

update 2022. put AT firmware 1.7.5 into the esp8266 and use my WiFiEspAT library

You can find a port definition for your Arduino in this path:
/usr/lib/python2.7/ciao/connectors/restserver/restserver.json.conf
{
 "name" : "restserver",
 "description" : "REST server connector for the Ciao Core",
 "authors": ["Arduino Team <swdev@arduino.org>;"],
 "repository" : "https://github.com/arduino-org/Ciao",
 "version" : "0.0.2",
 "params" : {
            "port" : 80
             },
 "log" : {
         "level" : "info"
         }
}

The confusing part is that your Arduino has a server-client connection to itself from the CPU/Linino server to the MCU/Arduino client.
https://www.arduino.cc/en/Reference/CiaoRestServer

OP has Uno WiFi, not Yun. The library UnoWiFiDevEd has a ciao-like object but the WiFi is served by esp8266


text:
Arduino analog input to iphone notification
I need some help :)

Is it even doable?
Is there anyone who wants to help me program it?

My wish:
I want to receive a iphone notification when 1 arduino analog input drop from 5 to 0 volt.
Then (later) when the voltage goes back to 5V i want another message.
It needs to be over Wifi (not BT).
Is there anyone that can help me with this?
Thanks in advance

Thanks guys,
I already have the pushsafer app installed, so that comes in quitte handy. You say there is alot to be found for The kind of thing i wanna do.
But what do i search for? And where do i look?
Could you provide me with websites or links?
Or mabye forums where people could help me build the code? Greetings :)

Regarding your "Could you provide ... Or mabye[sic] forums where people could help me build the code?"  There is an official Arduino forum.

It is totally doable, but we cannot give detailed tutorials here, since this is a simple Q&A site. So I will point you to a direction, that can lead you to the solution.
When building IOT devices with Arduino (and thats exactly, what you are doing) there are 2 internet services, that are commonly used for getting information from the device to other devices (like your phone):

Blynk
IFTTT (means If This Then That)

Both have apps and can be used to push notifications, when your IOT device does a webrequest to the service. There are also libraries for Arduino available (at least for Blynk). There are many tutorials out there, so I suggest, that you search for yourself and try some of them.
For the hardware of your IOT device, I would suggest an ESP board, because they already have Wifi build in, for example the ESP32 gives you great IO capabilities.

If you only need to send a push-message, you can also use Prowl, Pushbullet, or Pushsafer.


text:
WifiClientSecure connect returns 0 ( fail ) except for www.google.com which connects
So to wile away the long lockdown and curfew hours I decided to get out a stack of Wemos D1 mini ESP8266 boards and build simple indoor temperature and humidity sensors ( using an SHT30 and feeding the data into Graphite or Influx ). I'm using the WifiClientSecure library but its connect() function returns 0 ( false/fail ) every time I try this except when I connect to www.google.com. I've tried connecting to various other servers, both port 80 and 443 but they all fail. I can connect to all of these server absolutely fine from my network so it's not a firewalling issue. The D1 does get an IP and has DNS ( in fact, in my full sketch I'm using NTP with pool.ntp.org and that works fine ).
I've created a simple test ( https://gist.github.com/mkraats/1d1b11691c179793c799fcbb21e5debe ) with just the connect to WiFi and connect() but I still get the same results.
This code:

    char servername[]="www.google.com";

    int connectval;
    connectval = client.connect(servername, 443 );
    Serial.println("...");
    Serial.println(connectval);
    Serial.println("...");
    delay(12000);

}

Works fine while this:
void loop() {

    char servername[]="graphite-us-central1.grafana.net";

    int connectval;
    connectval = client.connect(servername, 443 );
    Serial.println("...");
    Serial.println(connectval);
    Serial.println("...");
    delay(12000);

}

Does not. What stupid mistake am I making that I am not seeing? :-)

graphite-us-central1.grafana.net does not seem to listen on https port 443

@SimSon I checked on my PC with curl https://graphite-us-central1.grafana.net:443 . That worked. So I guess, it does serve https on port 443

No, https://downforeveryoneorjustme.com/graphite-us-central1.grafana.net works, so it definitely does listen.

do you have All SSL ciphers (most compatible) selected in Tools menu?

Yes, that is selected. It also wouldn't explain why plain old HTTP port 80 doesn't work.

does the site allow unsecure connection?


text:
ESP8366: ets Jan 8 2013,rst cause:4, boot mode:(1,7)
I am trying to control esp8266 esp 01 with Alexa
This is my code:
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"

#define ssid "admin"
#define pass "admin0000"

#define device1 "arduino"

fauxmoESP fauxmo;

void wifi()
{
  WiFi.mode(WIFI_STA);

  WiFi.begin(ssid,pass);
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print("not connected\n");
    delay(100);
  }
    Serial.print("1");

}

void setup()
{
  Serial.begin(115200);
  wifi();
  fauxmo.createServer(true);
  fauxmo.addDevice(device1);
  Serial.print("device added\n");
    fauxmo.setPort(80);
   fauxmo.enable(true);

  fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
  Serial.printf("[MAIN](%s) state: %s\n",device_name, state ? "ON" : "OFF");
    if (strcmp(device_name, device1) == 0)
    {
      if (state)
        Serial.print("3");
      else
        Serial.print("2");
    }

  });
}

void loop()
{
  fauxmo.handle();
}

And I am getting an error after 10 - 20 sec
ets Jan  8 2013,rst cause:4, boot mode:(1,7)

wdt reset

Anyone please help me to solve this issue

Looks like a watchdog timer reset. You could try to "feed" the watchdog by adding a yield(); command inside loop();, for example.

you have io 0 LOW so on watchdog reset the exp8266 goes into flashing mode

@StarCat adding a yield() call to that loop() won't do anything. loop() has an implicit yield() when it returns. Give that there's only one line of code inside loop(), adding a yield() would be pointless.

@romkey correct, but there’s still a watchdog timeout.

@StarCat yes but adding a yield() as you suggested won't fix that in this case - there's already an implicit yield() as soon as loop() returns. It already happens, and doesn't solve the timeout.

@romkey, yes, I already agreed with you.


text:
Arduino Mega not receiving data from Neo-6M
I am using the trying to get data from the Neo-6M GPS module with an Arduino mega, but, the condition 'While (gpsSerial.available() > 0' is being met. I believe this means the no bytes are being transferred from the module to the serial port but I'm not sure why.
The light on the Neo-6M was blinking which means it getting a lock but not giving out the data.
#include <SoftwareSerial.h>

// Choose two Arduino pins to use for software serial
int RXPin = 19;
int TXPin = 18;

//Default baud of NEO-6M is 9600
int GPSBaud = 9600;

// Create a software serial port called "gpsSerial"
SoftwareSerial gpsSerial(RXPin, TXPin);

void setup()
{
  // Start the Arduino hardware serial port at 9600 baud
  Serial.begin(9600);

  // Start the software serial port at the GPS's default baud
  gpsSerial.begin(GPSBaud);
  Serial.write("123");
}

void loop()
{
  // Displays information when new sentence is available.
  while (gpsSerial.available() > 0)
    Serial.write(gpsSerial.read());
}

I had it working on an Uno by connecting to pins 2,3 rather then 18 and 19. I have also tried swapping the 18 and 19 pins over but still noting.
Thanks for the help
EDIT:
I have the RX and TX plugged into the mega at pins 1 and 2, however, it will only print GPS information when the reset button is pressed or held down

Not all pins on the Mega support software serial, have a read below:
https://www.arduino.cc/en/Reference/SoftwareSerial
Pins 18 / 19 are actually hardware serial pins so should not need the use of software serial.
Edit, should have noted to use hardware pins 18 / 19 you would use the constructor Serial1.begin(9600)


text:
NodeMCU ESP32s can't get Vin to work?
Trying to power the board with a 9V battery through VIN. As the documentation says, it can take input voltage of 6-12 Volts, but when I connect the 9V battery, all it does is power the board on and nothing else happens.
Anyone know what I am doing wrong?
EDIT: I am stupid had the ground connected to the wrong pin thanks for the help everyone.

What kind of 9V battery?

Just a regular 9V E-Block Battery.

Yes, but what chemistry?

Assuming you are using a 9V block battery: They don't deliver the current you need for the esp32 to run/create an access point/act as a client. What you can do is connect 6 AA batteries in a row (6*1.5V = 9V) and they will deliver a higher current than the 9V block.


text:
Sporadically corrupted data returned from ESP8266
I have an Arduino Uno connected to an ESp8266 via an ESP-01 adapter.  The Adapter is powered from the Arduino 5v and Gnd pins and the Tx/Rx to the Adapter use Arduino pins 2/3. I have basic code which sets the ESP8266 as an access point and I am able to connect to the AP from my phone, send a message and receive a reply from the ESP8266.  This works fine for 75% of the time.  other times, the message received by ESP8266 ( and printed on the serial monitor for debug ) is truncated, and/or corrupted.
I have tried a different ESp8266 and a different adapter; I don't get corruption errors with other programs run on the Uno; I have dropped the communications speed between the Uno and ESp8266 to 9600 baud.
What could be the cause of the corruption I am seeing in the data ? Thanks
I have updated my app an no longer get corrupted data, but there are characters data missing from the returned data stream.
Here is my sketch :
#include <SoftwareSerial.h>

//
// ESP8266 interface
////////////////////

SoftwareSerial wifiSerial(2, 3);            // RX, TX for ESP8266

#define TICK  100

bool DEBUG = true;
int responseTime = 1000;

#define ESP8266CMD_SET_UART_9600            "AT+UART_CUR=9600,8,1,0,3"
#define ESP8266CMD_SET_UART_38400           "AT+UART_CUR=38400,8,1,0,0"

#define ESP8266CMD_ECHO_OFF                 "ATE0"
#define ESP8266CMD_ECHO_ON                  "ATE1"
#define ESP8266CMD_SET_WIFI_STATION_MODE    "AT+CWMODE=1"
#define ESP8266CMD_SET_WIFI_SOFTAP_MODE     "AT+CWMODE=2"
#define ESP8266CMD_GET_IP_ADDRESS           "AT+CIFSR"
#define ESP8266CMD_CONFIG_AP_LIST_ALL       "AT+CWLAPOPT=1,2047" // Sort and display all netwroks
#define ESP8266CMD_CONFIG_AP_LIST           "AT+CWLAPOPT=1,3"    // Sort and display ECN / ESSID only
#define ESP8266CMD_LIST_AVAILABLE_APS       "AT+CWLAP"

#define ESP8266CMD_SEND_DATA                "AT+CIPSEND=0,"     // required data length to be appended
#define ESP8266CMD_CLOSE_ALL_CONNECTIONS    "AT+CIPCLOSE=5"

//
// LCD interface
////////////////

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR                            0x27
#define BACKLIGHT_PIN                       3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

//
// S E T U P
////////////

void setup()
{
  Serial.begin(115200);
  Serial.println("Initialising...");

  lcd.begin( 16, 2 );                                 //  LCD is 16x2

  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);        // Switch on the backlight
  lcd.setBacklight(HIGH);

  lcd.home();
  lcd.print("Initialising...");

  wifiSerial.begin(9600);

  sendToWifi( ESP8266CMD_ECHO_OFF, responseTime, DEBUG );
  sendToWifi( ESP8266CMD_SET_WIFI_STATION_MODE, responseTime, DEBUG );

  sendToWifi( ESP8266CMD_CONFIG_AP_LIST, responseTime, DEBUG );

  Serial.println("Wifi connection is running!");

  lcd.clear();
  lcd.print("Ready");

  pinMode(13,OUTPUT);  //set build in led as output
}

//
// L O O P
//////////

void loop()
{
String APList = sendToWifi(ESP8266CMD_LIST_AVAILABLE_APS, responseTime, DEBUG);

  Serial.println(APList);

  delay(100 * TICK);
}

/*
* Name:         sendToWifi
* Description:  Send data to ESP8266.
* Params:       command - the data/command to send
*               timeout - the time to wait for a response
*               debug - print to Serial window?(true = yes, false = no)
* Returns:      Response from the esp8266 (if there is a reponse)
*/
String sendToWifi(String command, const int timeout, boolean debug){
 String response = "";

 if(debug)
    Serial.println( "Command[" + command + "]" );

 wifiSerial.println(command);       // send string esp8266

 long int time = millis();
 while( (time+timeout) > millis())
 {
   while(wifiSerial.available())
   {
   char c = wifiSerial.read();      // read resonse

    response += c;
    time = millis();                // data received - reset timeout
   }
 }
 if(debug)
    Serial.println( "Response[" + response + "]" );

 return response;
}

..and here is output debug data from a sample run.
Initialising...
Command[ATE0]
Response[
OK
]
Command[AT+CWMODE=1]
Response[
OK
]
Command[AT+CWLAPOPT=1,3]
Response[
OK
]
Wifi connection is running!
Command[AT+CWLAP]
Response[]

Command[AT+CWLAP]
Response[+CWLAP:(4,"VM2293456_EXT")
+CWLAP:(3,"NVR9ca3a92708f2")
+CWLA]
+CWLAP:(4,"VM2293456_EXT")
+CWLAP:(3,"NVR9ca3a92708f2")
+CWLA
Command[AT+CWLAP]
Response[+CWLAP:(4,"VM2293456_EXT")
+CWLAP:(4,"VM2293456")
+CWLAP:(5,"]
+CWLAP:(4,"VM2293456_EXT")
+CWLAP:(4,"VM2293456")
+CWLAP:(5,"

As well as the two networks VM2293456 and VM2993456_EXT there are a number of other netwroks available, and on some runs I see those networks shown. In any case, there are missing characters from the response text.

you have AT firmware in esp-01? how long is the message and how do you read it? show your sketch.

Thanks for coming back to me.  I do have firmware in the esp and I'm happy to share my sketch, but as a newbie here I can't see how to share the code.

I have added the sketch and sample output data to my question. Thanks

ESP-01 is a 3.3v device.

Thanks Robert. I beleive that the adapter I'm using steps 5v down to 3.3v

AT firmware writes the data to Serial without any control. If the data are not read fast the Serial buffer overflows. If you count the bytes read by your sketch (including 2 not visible line ending characters per line) you count 64 bytes. That is the size of the RX buffer of SoftwareSerial. SoftwareSerial can tell you if the buffer overflowed. Call wifiSerial.overflow().
The CWLAP takes time to execute on esp8266 side and then the AT firmware puts out the complete listing to Serial. Reading it byte by byte and storing millis() in-between is then too slow. You need to read it faster with a buffer.
I use readBytesUntil to read a line into buffer. This function waits for the next byte if there is a gap between bytes and stops reading if terminator is received or it times out. Default timeout is 1000 millis. It can by set with setTimeout(t).
In your sketch you use String. I do not recommend it for a project, but in a test you could use:
result += wifiSerial.readStringUntil('\n');

to read and append a whole line.

Thanks, that makes a lot of sense - I'll modify my code and try again. Cheers

So I have now modified my receive fundtion to this :
{
int l, j = 0;

    do {
      l = wifiSerial.readBytesUntil( '\0', &Buffer[j], BUFFER_LEN );
      j += l;
      Buffer[j] = '\0';
    } while( l > 0 );
}

.. but I am still getting 64 characters of data only.  Note I am using 'SoftwareSerial', and in that case I can't see why the readBytesUntil() function is available to me.  Where am I going wrong ?

AT firmware never sends \0. line ends with \r\n. and to read into buffer readBytesUntil('\n', &Buffer, BUFFER_LEN) https://arduino.stackexchange.com/questions/63106/how-to-compare-a-string/63116#63116

@Juraj: you'll need to append the '\n' manually - result += wifiSerial.readStringUntil('\n') + "\n";

@SBF, we want the data only

Taking the information that people have kindly offered to me, I have re-written my code to use the AltSoftSerial library and I now have my small app working fine.  Thanks.  AltSoftSerial uses pins 8/9 in an interrupt driven manner, leaving the 'standard' pin 1/2 serial comms for a debug channel.  I have it running at 19200 baud.
I have remove String variable from the code and my final improvement will be to use malloc() to allocation data buffer in place of the current statically declared buffer.
The purpose of my test app is to connect to my home wifi network a to print out the IP address allocated.  All output goes to an LCD display, but the serial monitor could be used instead.
Here's my code :
#include <AltSoftSerial.h>
#include "ESP8266_cmd.h"

//
// Connect to home WiFi network using AltSoftSerial via pins 8/9 to ESP8266
///////////////////////////////////////////////////////////////////////////

//
// ESP8266 interface
////////////////////

AltSoftSerial wifiSerial;                   // RX, TX for ESP8266

#define TICK  100

#define DEBUG                               false
#define ResponseTime                        1000

#define NW_CREDENTIALS                      "\"VM2293456\",\"----------\""

//
// LCD defines
//////////////

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR          0x27
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

int n = 1;

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

//
// Buffer for ESP8266 data
//////////////////////////

#define BUFFER_LEN    512
char Buffer[BUFFER_LEN];

//
// State Machine
////////////////

enum {
 STATE_INIT_WIFI = 0,
 STATE_WIFI_CONNECT,
 STATE_WAIT_FOR_CONNECTED,
 STATE_GET_IP_ADDRESS,
 STATE_WAIT,

 STATE_ERROR,
} State;

int MachineState = STATE_ERROR;
int ErrorCode = 0;

void setup()
{
String response;

  Serial.begin(115200);
  Serial.println("Initialising...");

  lcd.begin( 16, 2 );                                 //  LCD is 16x2.  Cmd is Column, Row

  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);        // Switch on the backlight
  lcd.setBacklight(HIGH);

  lcd.clear();
  lcd.home();
  lcd.print( "Network Connect " );

  wifiSerial.begin(19200);

  MachineState = STATE_INIT_WIFI;
}

void loop()
{
String response;
char cmd[64];

  switch( MachineState )
  {
  case STATE_INIT_WIFI:
    lcd.setCursor( 0, 1);
    lcd.print("Initialising    ");

    sendToWifi( ESP8266CMD_ECHO_OFF, ResponseTime, DEBUG );
    if( strcmp( Buffer, "OK" ) != 0 )
    {
      ErrorCode = 1;
      MachineState = STATE_ERROR;
      break;
    }

    sendToWifi( ESP8266CMD_SET_WIFI_STATION_MODE, ResponseTime, DEBUG );
    if( strcmp( Buffer, "OK" ) != 0 )
    {
      ErrorCode = 2;
      MachineState = STATE_ERROR;
      break;
    }
    MachineState = STATE_WIFI_CONNECT;
    break;

  case STATE_WIFI_CONNECT:
    lcd.setCursor( 0, 1);
    lcd.print("Connecting           ");

    strcpy( cmd, ESP8266CMD_CONNECT_TO_AP );
    strcat( cmd, NW_CREDENTIALS );
    sendToWifi( cmd, ResponseTime, DEBUG );
    MachineState = STATE_WAIT_FOR_CONNECTED;
    break;

  case STATE_WAIT_FOR_CONNECTED:
    lcd.setCursor( 0, 1);
    lcd.print("Wait for connect");
    readFromWiFi( ResponseTime );
    if( strstr(Buffer, "WIFI GOT IP") != NULL )
       MachineState = STATE_GET_IP_ADDRESS;
    else
       delay( 1000 );
    break;

  case STATE_GET_IP_ADDRESS:
    lcd.setCursor( 0, 1);
    lcd.print("Getting IP Addr ");

    sendToWifi(ESP8266CMD_GET_IP_ADDRESS,ResponseTime,DEBUG);

    MachineState = STATE_ERROR;   // prime for error case
    ErrorCode = 3;

    if( strstr( Buffer, "OK" ) != NULL )
    {
      if( strncmp( Buffer, "+CIFSR:STAIP", 12 ) == 0 )
      {
        lcd.setCursor( 0, 1 );
        lcd.print( "                " );
        lcd.setCursor( 0, 1 );
        for( int i = 15; i < strlen(Buffer ); i++ )
        {
          if( Buffer[i] == '"' )
            Buffer[i] = '\0';
        }
        lcd.print( &Buffer[14] );   // Display extracted IP address
        MachineState = STATE_WAIT;
      }
    }
    break;

  case STATE_WAIT:
    delay(10000);
    MachineState = STATE_GET_IP_ADDRESS;
    break;

  case STATE_ERROR:
  default:
    lcd.setCursor( 0, 1 );
    lcd.print( "                " );
    lcd.setCursor( 0, 1 );
    strcpy( cmd, "Err " );
    itoa( ErrorCode, &cmd[strlen(cmd)], 10 );
    lcd.print( cmd );
    delay(10000);
    break;
  }
}

/*
* Name:         readFromWiFi
* Description:  Read data from ESP8266.
* Params:       timeout - the time to wait for a response
*               debug - print to Serial window?(true = yes, false = no)
* Returns:      Response from the esp8266 (if there is a reponse) in Global Buffer
*/
void readFromWiFi(int timeout)
{
int l = 0;
long int t = millis();

    while( ( t + timeout ) > millis() ){
      while( wifiSerial.available() > 0 ) {
        Buffer[l++] = wifiSerial.read();
        t = millis();
       }
    }

    Buffer[l] = '\0';

    trimRight( Buffer );
    trimLeft( Buffer );
}

/*
* Name: sendToWifi
* Description: Function used to send data to ESP8266.
* Params: command - the data/command to send; timeout - the time to wait for a response; debug - print to Serial window?(true = yes, false = no)
* Returns: The response from the esp8266 (if there is a reponse)
*/
void sendToWifi( const char *command, const int timeout, boolean debug){

 if(debug)
 {
    Serial.print( "Command[" );
    Serial.print( command );
    Serial.println( "]" );
 }

 wifiSerial.println( command );       // send string esp8266

 readFromWiFi( timeout);

 if(debug)
  {
    Serial.print( "Response[" );
    Serial.print( Buffer );
    Serial.println( "]" );
  }
}

void trimRight( char *src )
{
  int i = strlen(src)-1;

  for( ; i >= 0; i-- )
  {
    if( (src[i] != ' ' ) && ( src[i] != '\t' ) && ( src[i] != '\n' ) )
      break;
  }
  src[i] = '\0';
}

void trimLeft( char *src )
{
  int i, l = strlen(src);

  for( i = 0; i < l; i++ )
  {
    if( (src[i] != ' ' ) && ( src[i] != '\t' ) && ( src[i] != '\n' ) && ( src[i] != '\r' ) )
      break;
  }
  memmove( src, &src[i], l);
}

and here is the ESP822_cmd.h header file that I created :
// ESP82266_cmd.h
//
// #defines for ESP8266 interface
//

#define ESP8266CMD_SET_UART_9600            "AT+UART_DEF=9600,8,1,0,0"
#define ESP8266CMD_SET_UART_19200           "AT+UART_DEF=19200,8,1,0,0"
#define ESP8266CMD_SET_UART_38400           "AT+UART_CUR=38400,8,1,0,0"

#define ESP8266CMD_ECHO_OFF                 "ATE0"
#define ESP8266CMD_ECHO_ON                  "ATE1"
#define ESP8266CMD_SET_WIFI_STATION_MODE    "AT+CWMODE=1"
#define ESP8266CMD_SET_WIFI_SOFTAP_MODE     "AT+CWMODE=2"
#define ESP8266CMD_GET_IP_ADDRESS           "AT+CIFSR"
#define ESP8266CMD_CONFIG_AP_LIST_ALL       "AT+CWLAPOPT=1,2047" // Sort and display all netwroks
#define ESP8266CMD_CONFIG_AP_LIST           "AT+CWLAPOPT=1,3"    // Sort and display ECN / ESSID only
#define ESP8266CMD_LIST_AVAILABLE_APS       "AT+CWLAP"

#define ESP8266CMD_SEND_DATA                "AT+CIPSEND=0,"      // required data length to be appended
#define ESP8266CMD_CLOSE_ALL_CONNECTIONS    "AT+CIPCLOSE=5"

#define ESP8266CMD_CONNECT_TO_AP            "AT+CWJAP_CUR="      // required essid and password to be appended
```


text:
ESP 8266 serial error
I am using an ESP8266 board and I had it plugged in to my computer via usb. I reached accross the board to press the reset button, and it felt like my finger got stung. The best I can figure, I touched the VIN and Gnd pins with my finger, and, I didn't think this at first, the reset pin. Whenever I try to open a serial port all that shows, and at a different baud rate then I specified, is this error message
 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

 load 0x4010f000, len 1384, room 16
 tail 8
 chksum 0x2d
 csum 0x2d
 v951aeffa
 ~ld

Everything I find online says that this means that the reset pin is causing problems. Although this is the first time a 7 showed up, it used to be a 6. Also, the computer doesn't seem to have a problem uploading the sketches, but they don't seem to run.
I have tried re-flashing the firmware, but just now when I was typing this out, I thought to upload Blink, just to say I could, and it worked, but it isn't sending anything to the computer of serial, at all. I own two of these boards, but the problem happened across both making me think that something happened to my computer.
Any help is appreciated.
Edit: I am running Win 10, using Vscode to upload sketches, and arudino IDE v1.8.7 to monitor serial. I have many Serial.print() lines, and Serial.begin(115200)

is this error message that's not an error message, that's the ESP boot message

you would not feel the voltages on the ESP8266 pins ..... you would however feel a static electricity discharge from your finger into the board ..... did you walk across a carpet before you touched the board? ..... if it was a static electricity discharge, then there is a good reason to believe that the board has been destroyed

rst cause:2 means the boot was due to a reset (perfectly OK) and boot mode(3,x) means GPIO15 was LOW, and GPIO0 and GPIO2 were HIGH ... which is what you want when you boot into your sketch ... what's the issue again?

do you have any Serial.print() commands in your sketch? if not, then there wont be any output

Do you set Generic ESP8266 settings? Try to set DIO

@JaromandaX forgetting Serial.begin() is also classic

@JaromandaX Thanks, that makes me feel a lot better, but why would it send this at a different baud rate?

@jsotola I was sitting in my chair for the last thirty mins reading up on MDNS and the such, and, as I said above, the only clue I got was that my finger felt like it was stung

@Juraj I am using the NodeMCU 1.0 (ESP-12E) board setting following the instructions on the amazon page. A DIO? (is that a digital I/O pin?

"Flash mode" in Tools menu. it is not available to set for NodeMcu


text:
l298N PWM motor control with Uno is not functioning correctly
I'm working on a self-balancing robot. The self-balancing is not the issue. The issue is that the motors don't respond as they are supposed to.
I would understand if it were unable to balance, but the motors are not reacting to the tilt at all. The motors aren't responding to the lines of code that are telling them to move, despite being wired correctly.
I turn on the system and it spins one motor and usually in one direction, but at times it will slow down or change direction. This change does not occur consistently which I am sure of. Moving the robot to the exact same rotation and back gives different results each time.
I have checked the voltage with a multimeter, 4.9V at the Arduino 5V pin. I have a 9V battery connected to the barrel jack (Vin) 8.26V in. I know this Arduino and MPU5060 are not broken and are in fact connected correctly because when I run the serial monitor it shows me the tilt in degrees on my laptop.
A list of tests I did and what they showed me:
1: All voltages were what they should be at 5V pin and Vin according to my multimeter. The 5V on the MPU6050 was also the same as the 5V on the Arduino obviously as it's the same node.
2:  I tried a blink sketch to see if the Arduino was working when plugged into the battery (9V) instead of the computer cord. It blinked as it should, showing that indeed it had sufficient power from the battery and was working correctly. I now know the Arduino is working and is not underpowered.
3: I tested if the MPU6050 was functioning on the battery power (powered off Arduino which is powered off the 9V). I made a sketch that turned on the onboard LED if the MPU6050 was past 0 degrees. This test worked consistently When it was tilted between -1 and -90 degrees it turned the LED on. When I positioned it back up to 0 degrees or past 0 it turned the light off. So now I know conclusively that the Arduino and MPU6050 are functioning and not being underpowered.
4: I tested both motors individually disconnected from the l298n, with a 6V 4AA battery pack and both spun like they should.
5: When I disconnect the two PWM pins and put the tiny jumpers on the l298n back in place both wheels turn in the same direction at a consistant speed but do not react to the tilt at all. They continuously move in that direction and nothing stops them from spinning until I unplug it.
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
#include "math.h"

#define leftMotorPWMPin 5
#define leftMotorGoForward 6
#define leftMotorGoBack 7
#define rightMotorGoForward 8
#define rightMotorGoBack 9
#define rightMotorPWMPin 10

int16_t accY, accZ;
float accAngle;

MPU6050 mpu;

void setup() {
  // set the motor control and PWM pins to output mode
  pinMode(leftMotorPWMPin, OUTPUT);
  pinMode(leftMotorGoForward, OUTPUT);
  pinMode(leftMotorGoBack, OUTPUT);

  pinMode(rightMotorGoForward, OUTPUT);
  pinMode(rightMotorGoBack, OUTPUT);
  pinMode(rightMotorPWMPin, OUTPUT);
  // set the status LED to output mode
  mpu.initialize();
  Serial.begin(9600);
}

void loop() {
  //delay(100);
  accZ = mpu.getAccelerationZ();
  accY = mpu.getAccelerationY();
  accAngle = atan2(accY, accZ)*RAD_TO_DEG;

  if (isnan(accAngle));
  else
    Serial.println(accAngle);

  if ((accAngle <= 5) && (accAngle > 0)) {
    analogWrite(leftMotorPWMPin, 42.5);
    digitalWrite(leftMotorGoForward, HIGH);
    digitalWrite(leftMotorGoBack, LOW);

    analogWrite(leftMotorPWMPin, 42.5);
    digitalWrite(rightMotorGoForward, HIGH);
    digitalWrite(rightMotorGoBack, LOW);
  }
  else if (accAngle == 0) {
    analogWrite(leftMotorPWMPin, 0);
    digitalWrite(leftMotorGoForward, LOW);
    digitalWrite(leftMotorGoBack, LOW);

    analogWrite(leftMotorPWMPin, 0);
    digitalWrite(rightMotorGoForward, LOW);
    digitalWrite(rightMotorGoBack, LOW);
  }
  else if ((accAngle <= 15) && (accAngle > 5)) {
    analogWrite(leftMotorPWMPin, 85);
    digitalWrite(leftMotorGoForward, HIGH);
    digitalWrite(leftMotorGoBack, LOW);

    analogWrite(leftMotorPWMPin, 85);
    digitalWrite(rightMotorGoForward, HIGH);
    digitalWrite(rightMotorGoBack, LOW);
  }
  else if ((accAngle <= 30) && (accAngle > 15)) {
    analogWrite(leftMotorPWMPin, 127.5);
    digitalWrite(leftMotorGoForward, HIGH);
    digitalWrite(leftMotorGoBack, LOW);

    analogWrite(leftMotorPWMPin, 127.5);
    digitalWrite(rightMotorGoForward, HIGH);
    digitalWrite(rightMotorGoBack, LOW);
  }
  else if ((accAngle <= 45) && (accAngle > 30)) {
    analogWrite(leftMotorPWMPin, 170);
    digitalWrite(leftMotorGoForward, HIGH);
    digitalWrite(leftMotorGoBack, LOW);

    analogWrite(leftMotorPWMPin, 170);
    digitalWrite(rightMotorGoForward, HIGH);
    digitalWrite(rightMotorGoBack, LOW);
  }
  else if ((accAngle <= 65) && (accAngle > 45)) {
    analogWrite(leftMotorPWMPin, 212.5);
    digitalWrite(leftMotorGoForward, HIGH);
    digitalWrite(leftMotorGoBack, LOW);

    analogWrite(leftMotorPWMPin, 212.5);
    digitalWrite(rightMotorGoForward, HIGH);
    digitalWrite(rightMotorGoBack, LOW);
  }
  else if ((accAngle <= 90) && (accAngle > 65)) {
    analogWrite(leftMotorPWMPin, 255);
    digitalWrite(leftMotorGoForward, HIGH);
    digitalWrite(leftMotorGoBack, LOW);

    analogWrite(leftMotorPWMPin, 255);
    digitalWrite(rightMotorGoForward, HIGH);
    digitalWrite(rightMotorGoBack, LOW);
  }

  //These next bunch are identical but for the negative (if it falls backwards)

  if ((accAngle >= -5) && (accAngle < 0)) {
    analogWrite(leftMotorPWMPin, 42.5);
    digitalWrite(leftMotorGoForward, LOW);
    digitalWrite(leftMotorGoBack, HIGH);

    analogWrite(leftMotorPWMPin, 42.5);
    digitalWrite(rightMotorGoForward, LOW);
    digitalWrite(rightMotorGoBack, HIGH);
  }
  else if ((accAngle >= -15) && (accAngle < -5)) {
    analogWrite(leftMotorPWMPin, 85);
    digitalWrite(leftMotorGoForward, LOW);
    digitalWrite(leftMotorGoBack, HIGH);

    analogWrite(leftMotorPWMPin, 85);
    digitalWrite(rightMotorGoForward, LOW);
    digitalWrite(rightMotorGoBack, HIGH);
  }
  else if ((accAngle >= -30) && (accAngle < -15)) {
    analogWrite(leftMotorPWMPin, 127.5);
    digitalWrite(leftMotorGoForward, LOW);
    digitalWrite(leftMotorGoBack, HIGH);

    analogWrite(leftMotorPWMPin, 127.5);
    digitalWrite(rightMotorGoForward, LOW);
    digitalWrite(rightMotorGoBack, HIGH);
  }
  else if ((accAngle >= -45) && (accAngle < -30)) {
    analogWrite(leftMotorPWMPin, 170);
    digitalWrite(leftMotorGoForward, LOW);
    digitalWrite(leftMotorGoBack, HIGH);

    analogWrite(leftMotorPWMPin, 170);
    digitalWrite(rightMotorGoForward, LOW);
    digitalWrite(rightMotorGoBack, HIGH);
  }
  else if ((accAngle >= -65) && (accAngle < -45)) {
    analogWrite(leftMotorPWMPin, 212.5);
    digitalWrite(leftMotorGoForward, LOW);
    digitalWrite(leftMotorGoBack, HIGH);

    analogWrite(leftMotorPWMPin, 212.5);
    digitalWrite(rightMotorGoForward, LOW);
    digitalWrite(rightMotorGoBack, HIGH);
  }
  else if ((accAngle >= -90) && (accAngle < 65)) {
    analogWrite(leftMotorPWMPin, 255);
    digitalWrite(leftMotorGoForward, LOW);
    digitalWrite(leftMotorGoBack, HIGH);

    analogWrite(leftMotorPWMPin, 255);
    digitalWrite(rightMotorGoForward, LOW);
    digitalWrite(rightMotorGoBack, HIGH);
  }
}

I am aware this is an unconventional way of programming for a self balancing robot, that is not my problem so don't mention it please and thank you!
Anyone have any ideas to what could be the source of the issue? Is it possible one of the libraries is using the PWM pins in the background?
All out of ideas, the motor controller board is practically brand new I highly doubt it's broken.
Schematic:

start by confirming motor operation ... write a simple sketch to run one motor in one direction for 1 second ... pause 1 second ... run reverse for 1 second ... pause 1 second ....... when that works test the next motor

does your l298 module have a 5V regulator onboard and if yes, does it povide 5V on the corresponding pin?

You use leftMotorPWMPin where I would expect to see rightMotorPWMPin, which is  unused beyond being set to output.  That doesn't explain all that you're describing though.

The datasheet states that the minimum supply voltage is Vih+2.5V. You are very close to this limit which may keep yoru high-side MOSFETs in the output bridges from firing reliably.

You're funny: You have a problem; I have an idea of what went wrong and could help, but  you pleased me not to mention it. ;-) Ok, I'm polite. I will not mention it. Of cause, the motors themself could be the problem. But, think of what you measure (accellerations), what type of accelleration can happen for the robot and where you have placed the sensor relative to the roll axes of the robot. And think of the profiles of the wheels and what accelerations they could cause when they are rolling. The sensors are very sensitive. Perhaps (if I'm right) that changes your mind, what your problem is.

Please look at the comment of @timemage wich points you to another problem, you have.

@timemage Thank you that was very foolish I suppose I missed that.

@PeterPaulKiefer Uhuh, I see what you mean, the lateral rotation of it moving forward could alone effect the accAngle. As that is the acceleration of X&Y Multiplied or something of the sort. How can I counteract that so it only changes if it both goes down in X&Y and not just X or Y? Is that where the gyroscope comes in?


text:
How can I prepare for a short circuit between 5V and GND pins?
My Arduino Uno controls a couple of LEDs in a watertight enclosure. I'm running wires from ground, a data pin, and the 5 V pin into the enclosure. The Arduino is powered through the DC jack.
What measures can I take to handle failure of the watertight enclosure, which would short-circuit the wires? Can I protect the Arduino, or at least prevent a fire?

simply put a fuse inline with the power jack, say 1 amp (if the LEDs aren't powerful). Also, water won't cause a dead-short, and with only 5v, you don't really have to worry about a fire, unless you're doing something weird you didn't mention.

Nothing weird! Thank you. Do you mean to put the fuse right after the 5V pin? What would be an appropriate fuse for this?

Se this WONDERFULL vid  (is just 8 mins!!!)

they make pre-assembled DC inline fuses (like these) if you don't want to solder in a fuse holder. The fuse should be sized as 1.5-2X your expected load in amps.

@k.Cyborg Thank you, seems I hade several misconception about water.

@dandavis Thanks a lot! Can I just ask, what is the reason to put the fuse between the power supply and Arduino, as opposed to between the Arduino and the potential short?

well you can do both; i'm evidently not sure of your exact setup, i thought everything was in the enclosure, so putting it up-front made sense in terms of preventing a fire. The MCU should not be in a position to blow out if shorted; GPIOs can be pulled to ground or VCC without issue...

What are you using to supply power to the DC jack? The problem with a fuse could be that the power supply can’t provide enough current to blow the fuse, making it useless.

Shoutout to @k.Cyborg who gave a very nice pointer in the comments to a YouTube video on the effects of water on electronics!
One of the things you can do to handle failure of the watertight enclosure better is to use nail polish clear coat and apply that over your board - it will form a protective layer. I use this technique on protoboards with solder bridges on the bottom - adding a layer of clear coat seals them and prevents any shorts due to placing the bottom of the board on a conductive surface, or from fingers touching and shorting things. This would work with water too, to prevent any electrolytic reaction and corrosion, which the video talks about. The video also briefly shows a nail polish clear coat (but doesn't elaborate and says it's a topic for another video).
Another point to consider when talking about shorts. In my case, I was powering my Arduino Pro Mini through the Vin , connected to a 9v battery. I fried the LDO on it by briefly reversing the polarity by switching the terminals by mistake (nice puff of magic smoke!). I added a reverse polarity protection diode in series with the + to prevent a repeat on my next Pro Mini. Since you are powering your Uno through the DC jack (which has a reverse polarity protection diode), it is not an issue for you, but thought I'd mention it if you plan to move to Vin.


text:
How to program the nodeMCU through OTA using GPRS?
I'm using a NodeMCU in one of my projects. The setup is in a remote location. That place doesn't have WiFi so I'm using GPRS (GSM SIM800V) for sensor data collection to my server. Right now I need to update my new firmware to that NodeMCU.
Is it possible do OTA using GPRS (GSM SIM800V)?

https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html#http-server

Yes, it is possible, but it takes some work on your part.
I recently had to implement OTA updates for the ESP32 over an RS-485 link, and it's actually pretty simple to manage. The hard part (for you) is the communication connection.
Performing an update (assuming the flash is already partitioned and set up right for OTA updates) is a case of "starting" the update, passing the update manager the flash data, then "ending" the update:

Update.begin(size) - This starts the upgrade process. You need to provide the expected size of the flash data at this point.
Update.write(*data, length) - Pass a block of flash data to the updater for writing.  An alternative is to read directly from a Stream class, which will try and read the number of bytes specified in the size parameter to begin.
Update.end() - This will finish it all off and switch the bootloader to load from the new flash. If it worked fine it will return true, otherwise, it will return false.

Assuming the above worked, you can no reset the board with ESP.restart()
For added security you can also pass an MD5 hash of the data to Update.setMD5(md5) and the updater will check that the uploaded data matches that MD5 hash.
Of course, all this needs implementing in your program that is running on the target device before you try and do any OTA updates. And, of course, you need to arrange the actual upgrade channel to get the commands and data through to the target in the first place.
So:

Implement a method of getting the data to the target
Implement the updater code
Go to the device and upgrade the firmware
From that point on you should be able to use OTA updates through your own chosen mechanism.


text:
How can I create an analog signal which is similar to PMT (Photo Multiplier Tube) pulse using analog write?
I have developed a circuit to process the PMT pulse output. For the testing, I need an artificial signal which is similar to the PMT pulse. How can I use AnalogWrite() to create such type of signal?

Do you mean you are looking for a way to generate a pulse as in the picture? The pulse is 40 ns. The Arduino AVR family of boards will have a hard time doing that!

Or do you mean a cascade of pulses with random width, duration and delay? All in the range of micro-seconds.

The PWM frequency of Arduinoboards is normally 490Hz, that means the shortest puls using analogWrite(PIN, 1) would last 8000ns.

You could write 200 NOPs @ 62.5ns each, assuming a 16MHz clock (minus overheads)

Short answer: You can't.
The Arduino can't do analog output at all, much less matching a specific analog waveform of ≈40ns duration.
PWM on the Arduino simulates constant analog voltages using square wave pulses of variable duty cycle. It has no support for creating analog waveforms of any type, much less ones with such a short duration.
EDIT
As mentioned in this thread: Generate a ramp input with an Arduino Uno
You could use a resistor ladder to create a roll-your-own DAC, and then use direct port register manipulation (not digitalWrite) to set the pins controlling your resistor ladder and get a crude approximation of your waveform.
Edit #2
There is no way you'll be able to generate nanosecond scale waveforms with a normal Arduino. It just isn't fast enough.

I doubt very much AVR-based Arduinos could do that.
SAMD21-based Arduinos do have a DAC, but their conversion time is about 2.85 μs. Their timer/counters can be clocked at 96 MHz, so about 10.5 ns/tick, but would yield a square pulse (that may or may not degenerate into what you need 8-).
Overall, I don't think an Arduino is the right tool for the job. Maybe something like the (very fast) Teensy 4.0 could do it, but I don't know much about those.


text:
Sketch halts if button is pressed on boot
I have a KY-040 rotary encoder with a push button wired to an ESP8266. My objective is to be able to detect if the button is pressed or not on boot.
In the below code, if I hold the button down and power on the ESP8266, neither "IT'S STARTED" or "IT'S LOOPING" is printed in the serial monitor, even if I release the button. If I don't press the button, the code works as expected and prints "IT'S STARTED" followed by "IT'S LOOPING". It's as though the code gets stuck/halted if I press the button on boot.
Can someone explain why this is happening?
I would also appreciate suggestions on how I can detect the status (pressed/not pressed) of the button when the ESP8266 is powered up.
Here is my code:
void setup() {
  pinMode(D3, INPUT_PULLUP);
  Serial.begin(115200);
  Serial.println("IT'S STARTED");
}

void loop() {
  Serial.println("IT'S LOOPING");
  delay(1000);
}

D3 is io 0 the boot mode pin. https://arduino.stackexchange.com/questions/75704/what-are-the-best-gpio-pins-to-use-for-my-project/75706#75706

Description of pin D3 from this ESP8266 pinout reference:

connected to FLASH button, boot fails if pulled LOW

So you cannot pull this pin to LOW during boot, as it will keep the ESP in flash mode. You need to use a pin, that doesn't have this limitation, like D1, D2, D5, D6 or D7.

Thanks for the answer @chrisl. Of all the pins I could pick from!


text:
Elechouse Voice Recognition v3 module not responding when I send command using Access port serial tool
I have this challenge of receiving data when I send a command to voice recognition v3 module. The UART connections are okay, but when I send a command I don't receive a response on the terminal.
The prolific USB-TTL with drivers installed blinks when I send a command but still I get no response. Please help with debugging.

Can you be more specific about what you have done.  E.g. show your code, circuit and the "commands" used.

I am using ACCESS PORT in trying to train the module as per the manual commands. But haven't achieved any success. Any suggestions please?

The module can't communicate with Serial Monitor over a USB to TTL Serial adapter. It uses binary communication. Use Arduino, Arduino library and one of the example sketches of the library to communicate with the VR module.
And read the manual.