text:
Powering Arduino from 7805 voltage regulator
I am trying to build an Arduino Uno based robot. My questions are the following:
1) The motor driver also has an on-board 78M05 voltage regulator from ST electronics. I used a 9V battery to power the robot, and the 9V was connected to the input of the voltage regulator, and the +5V output I used to power the Arduino. I did so by connecting the 5V from the regulator to the 5V pin on the Arduino and the GND's together. I read that this is not advised, and solutions ranged from making sure the 5V is regulated, to connecting a diode between +5V and Vin to using one of the ICSP pins and so on. So which is actually a good way to do this?
2) I later realized that the DC motors are rated for max 6V dc, and so switched the 9V battery to 4x AA batteries giving a total voltage of 6V. When I connected this to the regulator, the regulator and the Arduino still turned on, even though the data sheet says the minimum input voltage is 7V. So what is going on here? Can anyone help me understand what is happening?

I read that this is not advised, and solutions ranged from making sure the 5V is regulated, to connecting a diode between +5V and Vin to using one of the ICSP pins and so on. So which is actually a good way to do this?

Nothing wrong with that as long as it is regulated 5V (which yours is). You can use either the 5V pin on the header, or the 5V pin on the ICSP connector. They are both the same.  It is good practice to connect a diode between 5V and VIN to prevent current flowing backwards through the onboard regulator should something connected to VIN want to draw current.

I later realized that the DC motors are rated for max 6V dc, and so switched the 9V battery to 4x AA batteries giving a total voltage of 6V. When I connected this to the regulator, the regulator and the Arduino still turned on, even though the data sheet says the minimum input voltage is 7V. So what is going on here? Can anyone help me understand what is happening?

A regulator has a "drop-out" voltage. That is often in the order of 1.2V for these kind of regulators (it's certainly right for the Arduino's on-board one.
You are providing less than the regulation voltage plus the drop-out voltage, so the output of the regulator will be the input voltage minus the drop-out voltage.
As long as that is above the lowest voltage the Arduino can run from at 16MHz then it will still work fine. You should be fine down to about 4V output from the regulator, and even lower if you're lucky (you may start getting stability problems though since the ATMega328P isn't rated to run at 16MHz at lower voltages).
It also means that the GPIOs on the Arduino will be running at a lower voltage as well.

Which way should the diode between +5V and Vin go? Also, does this mean that when I connect 6V the output is 4.8V and that is what the Arduino is running from?

Anode to +5V, cathode to Vin. Yes.

I actually did a measurement just now with a multimeter, and it confirmed what you said. The unregulated voltage from the AA batteries was 6.4 V and the output voltage was 4.8 V from the 7805. Now I don't know what do: if I go over this I can get 5V on the Arduino but I overpower the motors, if I leave it like this the Arduino will be under-voltage.

4.8V is perfectly fine for the Arduino. Even USB is allowed to be as low as 4.75V...


text:
How can I loop for a set amount of time when a condition is met?
I'm trying to create an Arduino project with a light sensor and a buzzer. The idea is that when the sensor detects that the lights have gone off, the buzzer will sound for 5 seconds. At some point, the lights will come back on, but when they go back off, I need the buzzer to sound again.
At the moment the buzzer does sound the first time the lights are turned off but after the lights have come back on and then off again, it won't sound and I can't figure out why.
int lightSensor = 2;
int buzzer = 3;
long startTime,stopTime;
long myDesiredTime = 5000;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(lightSensor, INPUT);
  pinMode(buzzer, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorState = digitalRead(lightSensor);

  switch(sensorState)
  {
  case 1:
    while (sensorState == 1)
    {
      if(stopTime-startTime<=myDesiredTime && sensorState == 1)
      {
        runBuzzer();
        stopTime=millis();
      }
    }
  }
}

void runBuzzer()
{
  tone(buzzer, 1000); // Send 1KHz sound signal...
  delay(1000);        // ...for 1 sec
  noTone(buzzer);     // Stop sound...
  delay(1000);
}

You have two major issues here:
void loop() {
  // put your main code here, to run repeatedly:
  int sensorState = digitalRead(lightSensor);

  switch(sensorState)
  {
  case 1:
    while (sensorState == 1)
    {
      if(stopTime-startTime<=myDesiredTime && sensorState == 1)
      {
        runBuzzer();
        stopTime=millis();
      }
    }
  }
}

The first is that you never re-read sensorState. The second is that you are comparing stopTime before setting a value to it. Try re-arranging like this:
void loop() {
  // put your main code here, to run repeatedly:
  int sensorState = digitalRead(lightSensor);

  switch(sensorState)
  {
  case 1:
    while (sensorState == 1)
    {
      stopTime=millis();
      if(stopTime - startTime <= myDesiredTime)
      {
        runBuzzer();
      }
    sensorState = digitalRead(lightSensor);  // read sensorState again
    }
  }
}

In your example, the buzzer does not sound when the light has been switch on and then back off again.

Good point. Well, we can simplify somewhat:
void loop() {

  if (digitalRead(lightSensor) == HIGH)
    {
    startTime = millis ();  // remember when we started
    while (digitalRead(lightSensor) == HIGH &&
           millis () - startTime <= myDesiredTime)
      {
      runBuzzer();
      }  // end of while switch still closed and time not up
    while (digitalRead(lightSensor) == HIGH) { } // wait for sensor go to LOW
    delay (200);  // debounce
    }    // end of switch being closed
}      // end of loop

In your example, the buzzer does not sound when the light has been switch on and then back off again.

See amended answer.

Thanks, I've tried it, but now it doesn't stop after 5 seconds and only goes off when the lights come back on. The theory should be like this: Light Detected= No Buzzer, No Light Detected= Buzzer for 5 seconds max then reset. So the next time that light is not detected, it will go off again for 5 seconds.

Hmm. So you want the buzzer to beep for a maximum of 5 minutes? I've added another 2 lines to my last example. Once 5 minutes is up it waits for the sensor to go LOW again.

Understand that your while (sensorState == 1) in your switch() is an infinite loop, with no way out (even if internally it gives the desired 5 seconds of sound).

Think of it like this. Any time you use a while loop your code has the rains until its done its job.
It's important to remember that the loop() function in Arduino should not be blocked. This line:
while (sensorState == 1)
will block forever. The condition is never changed from within the while loop. Theres a simple way you could fix this which would be to set sensorState and update it inside the while loop. But lets not do that. Because thats inefficient and you'll likely run into this problem again in more complex programs and that solution here won't still be a solution.
What you're trying to do is called concurrency. Your program should have obvious units of execution. Your two units are: "run a buzzer for 5 seconds" and "set off an event when a sensor reads true." where the first is depended on the second. So its conditional. That sounds like a job for if
When you code in { and } it is a block. It's not quite a context but is a distinct mode of execution.
So technically this:
void loop() {
    if( ... ) {
      ...
    }
    if ( ... ) {
      ...
    }
}

Is two modes of execution. Since loop() is executed repeatedly. With that in mind when you program you can then use a variable to control the what gets executed as needed. So:
void loop() {
    int sensorState = digitalRead(lightSensor);
    if( sensorState == 1 && buzzer_enabled == 0) { // set off an event when a sensor reads true.
        buzzer_enabled = 1;
        startTime = millis();
    }
    if ( buzzer_enabled == 1 ) { // run a buzzer for 5 seconds
        endTime = millis();
        if(stopTime - startTime <= myDesiredTime) {
            runBuzzer();
        } else {
            buzzer_enabled = 0;
        }
    }
}

We could stop here. But the use of delay is also blocking in the loop function and it is only for perception. So here's the whole thing without delays using a check against the modulus of diffTime.
int lightSensor = 2;
int buzzer = 3;

long startTime,stopTime;
long myDesiredTime = 5000;

bool buzzer_enabled = false;
bool buzzer_active = false;

int sensorState;
int prevSensorState = 0;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(lightSensor, INPUT);
  pinMode(buzzer, OUTPUT);
}

void loop() {
    sensorState = digitalRead(lightSensor);
    if( sensorState == 1 && prevSensorState == 0 ) { // set off an event when a sensor reads true.
        buzzer_enabled = true;
        startTime = millis();
    }
    prevSensorState = sensorState;
    if ( buzzer_enabled == true ) { // run a buzzer for 5 seconds
        stopTime = millis();
        long diffTime = stopTime - startTime;
        if( (diffTime % 2000) < 1000 ) {
            if(buzzer_active == false) {
                buzzer_active = true;
                //tone(buzzer, 1000);
            }
        } else {
            if(buzzer_active == true) {
                buzzer_active = false;
                //noTone(buzzer);
            }
        }
        if(diffTime > myDesiredTime) {
            buzzer_enabled = false;
        }
    }
}

No need for delay >:3 And all for free you got a new feature which is that if you set off the event again (the light goes off) the buzzer is extended another 5 seconds. If you don't want that all you have to do is add && buzzer_enabled == false to the first if.

I'm afraid I tried your example and the buzzer did not run at all.

You need to read the code. I didn't intend for you to just run it as is. I'm not sure what your function tone and noTone actually do so they are left commented where i think they should be.

source: Stack Exchange

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

sort: votes


text:
Interfacing Aduino Nano and RDM8800
I'm attempting to use an Arduino Nano with the RDM8800 to read data from NFC tags. After soldering wires between the Nano and the RDM8800, I attempted to test these devices using code similar to what has been used successfully on other serial devices similar to the RDM8800. Below is the code I used to test.
Wiring:
Nano - RDM8800
--------------
 5V  -  5V
GND  -  GND
 D3  -  TX
 D2  -  RX

Tags Tested:

NTAG 216 (ISO14443A)
MiFare Classic 1k (ISO14443A)

Code:
#include <SoftwareSerial.h>

SoftwareSerial soft(2,3);

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

void loop() {
  if(soft.available() > 0) {
    String serialData = soft.readString();
    Serial.println(serialData);
    writeAck();
  }

}

void writeAck() {
  uint8_t payload[] = "ACK|0|\n";
  soft.write(payload, sizeof(payload));
}

I watched the serial monitor and attempted to scan two different NFC tags that matched the ISO14443A compatibility that should ship with the RDM8800, according to this article. I got no information returned on the serial monitor.
After, assuming the issue is with the firmware, I attempted to upload the firmware to the RDM8800, with no success. I installed the needed board support to the Arduino IDE, as outlined in the intro article. Not having a USB to serial tool, I used another Nano and simply bridged the connection between the GND and RST pins. I was unable to upload the firmware to the RDM8800, getting the error below each time I tried.
Error:
avrdude: stk500_recv(): programmer is not responding

I believe that it's possible that I can't upload the firmware to the RDM8800 because the setup I used with the Nano as the USB to serial tool lacked a reset button. The image in the intro article, says to connect the TX RX GND 5V and RST pins, but the image that it says shows this only shows the TX RX GND and 5V pins connected(See below).
Image:

The information that I've found on the RDM8800 and its use is very limited and so is my knowledge on this topic. I'm unsure how I should proceed right now. I believe that I'm taking the right approach to setup code to scan NFC tags, but I could be wrong there. I'm very unsure on what I'm doing in relation to the potential firmware issue. Overall, I'm simply unsure on how to proceed and I'm looking for more knowledgeable people to give me some advice on how to proceed.
Relevant Resources:
RDM8800 Itead Wiki Page
RDM8800 Data Sheet
RDM8800 Schematic
RDM8800 Introduction Article

your code is set to communicate to pins that are different than your actual connection

SoftwareSerial constructor is rx pin first then tx pin.
You have SoftwareSerial soft(2,3); But you said that
D3 - TX
D2 - RX

Which means soft rx is going to its rx and soft tx is going to its tx. These need to be swapped. Either swap the wires or change it to:
SoftwareSerial soft(3,2);

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


text:
softwareserial between arduino uno and esp8266
I have an Arduino UNO and HUZZAH ESP8266  module.  I need to send data between Arduino UNO and ESP module via Software Serial.  Right now I have the ESP module write data and Arduino UNO display data, but not working. When I run the Arduino UNO  and open its Serial Monitor, nothing is printed using below source code.

ESP8266 RX PIN connected to Arduino UNO PIN 2.
ESP8266 TX PIN connected to Arduino UNO PIN 3.
Using the FTDI cable that came with HUZZAH ESP8266 to power this module.  I just individually connected the RX and TX pins to the ARDUINO PIN 2 and 3 as mentioned above.

Any ideas what why not working? Below is code for both modules. Thanks,
Arduino UNO
#include <SoftwareSerial.h>

SoftwareSerial ESPserial(2, 3); // RX | TX

void setup(void){
  //Start hardware Serial communication
  Serial.begin(115200);

  //Start the software serial for communication with the ESP8266 component
  ESPserial.begin(57600);

}

void loop(void){

if (ESPserial.available()){
  Serial.println("ESP available!!!");
  Serial.println(ESPserial.read());
}

}

HUZZAH ESP8266
#include <ESP8266WiFi.h>

#include <SoftwareSerial.h>

SoftwareSerial ESPserial(2, 3); // RX | TX

void setup(void){
  //Start the software serial for communication with the Arduino UNO component
  ESPserial.begin(57600);

  //TODO: setup Wifi
}

void loop(void){
   ESPserial.write("This message generated by ESP module.");
   delay(500);
}

What is the Arduino Pin 2 ?

RX on the Arduino should be connected to TX on the esp and vice versa, looks like you have RX connected to RX...

The Arduino pin 2 is digital.

@Marquinio yes but is it TX or RX?

Make sure that:

RX pin on the Arduino UNO is connected to the TX pin on the ESP8266.
TX pin on the Arduino UNO is connected to the RX pin on the ESP8266.
Baud rate should be set to the same value from both the Arduino and ESP8266.

I don't know about your arduino but looking at this schematic, your RX and TX should be swapped.

This is a very common mistake which at first may not seem obvious.

Yes this fixed my problem.  The ESP now gets data which seems to be in bytes.  I will try to figure out how to send/read readable strings, but thats another story.  My electronics knowledge is very limited, thanks.

Adding to the above answer. UNO's TX is at 5V , while ESP8266 's RX is at 3.3V, as it is a 3.3V module. So its better to use a resistive divider to bring UNO' TX to 3.3V and then feed to ESP's RX, instead of directly connecting them eachother.

And conversely, the 3.3V TX pin of the ESP8266 is usually enough to drive the Uno's 5V RX pin.

//ESP
#include "SoftwareSerial.h"

SoftwareSerial ArduinoUno(D2,D3); //Rx, Tx

void setup() {

Serial.begin(9600);

ArduinoUno.begin(4800);

pinMode(D2, INPUT);

pinMode(D3, OUTPUT);

}

void loop() {

}

/******************************************************************************/

//UNO
#include "SoftwareSerial.h"

SoftwareSerial ArduinoUno(3,2); //Rx, Tx

void setup() {

Serial.begin(9600);

ArduinoUno.begin(4800);

}

void loop() {

  if(ArduinoUno.available() > 0){

    //float val = ArduinoUno.parseFloat();

    Serial.println(ArduinoUno.read());

  }

  delay(30);

}

format your code properly (CTRL+K)

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


text:
Measure an AA battery?
If I'm going to measure an AA battery (about 1.5 v) with a USB-powered Arduino, I will connect the battery's +ve terminal to the A0 pin. Shall I connect the -ve terminal to the gnd pin too?

Is the AA battery under any kind of load, or just connected directly to the Arduino and nothing else?

Yes you could although this means you're measuring in relation to the Arduino's logic voltage, which is slightly below 5v (due to a diode's voltage drop) or the voltage of vref.

Ok, after connecting arduino reads 234 (1.143 v), and multimeter reads 1.116 v. Is that because of arduino logic? how to fix that?

Try measuring the 5V pin on the Arduino. The USB on a computer is rarely exactly 5V. You might have to do some calibration.

@jdwolf USB-VCC goes through a mosfet (T2 on the schematic), not a diode. Rds(on) is about 70 mOhm, so only a 35mV drop if the board uses the maximum 500mA that USB can supply.

I would use the internal voltage reference of 2.56V, and a protection resistor of about 1k or 4k7 to A0.

@Jot What's the "protection resistor" supposed to be protecting against?

@Majenko, for minimal protecting of the internal clamping diodes. A mistake with a 6, 9 or 12V battery is easily made. Even with a 1.5V battery there could be a problem when the Arduino is turned off and the battery is still connected. Or when the battery is connected in reverse. You know, better be safe than sorry, especially for a beginner.

@Jot That is true, yes.


text:
Arduino ISR timing question
Im trying to understand how the Arduino ISR keeps track of timing between pulses stored in a variable, if that variable is latter used.
Say, for example, you have a magnet mounted on a circular object, that passes a reed switch. Using this to trigger the ISR that calls a function that would have something like counts++ in it, then storing that value in a variable.
If that varible is used latter to turn on a motor, for example, according to the count capture, how does the arduino MCU know the freq or timing to output the count or pulses of the magnet passing the reed switch, at the same frequency that the counts were received? For example, a magnet mounted on a 2 inch dia shaft would turn slower past a reed switch than one mounted on a .5 inch shaft, or one could vary the speed of the magnet past the reed as they wish. So how does counter++ keep track of this freq? is it reading the attachinterupt pin (or is the function that is being called, keeping track) or does the ISR time stamp each pulse it receives and store that interval in the declared variable? so when the variable is used again, it has this interval stored in it?
To be more clear, if it takes one second for the magnet to complete one revolution, how does the MCU know it took one second and store this, along with the counts of the revolutions?
Thanks for any help

It doesn't know that. You'd have to code that yourself. You could indeed have the ISR store the millis() value. Even better would be to have the ISR (locally) store the millis() value of the last time the ISR was called. Then when the ISR is called the next time, it could calculate the time that has passed since the last ISR call. If the motor is running faster, this method can get a bit less accurate. In that case you could have the main loop measure the time it takes for the counter to increase by e.g. 20 (i.e. 20 revolutions). The it can calculate the average RPM.

so when people use for ex. the interupt, to call a function, for ex. void Revolutions(){
rev++;
};  and then have an if statement with varibles like if {
revA = rev;
rev=0; to store revolutions, and use that again in another if statement like if revA>rev, analogWrite(motor) the duration of the value stored in revA is not stored? if not, then what is stored?

@Jim When people just count revolutions like that they introduce the concept of time at a later stage. For instance, they will look at (and reset) that count once a second, giving the number of revolutions in that one second window, and hence the number of revolutions per second.

"they will look at (and reset) that count once a second, giving the number of revolutions in that one second window, and hence the number of revolutions per second"     so your saying the "one second" is an arbutrary value? Im just trying to understand what, for ex. counter++ or rev+1 etc is tied too? the interupt calls the function, then 1,2,3,4.....counts pass, its stored, then output according to what time?

perhaps the key thing Im missing is "reset", the interupt is used, calls its function, then resets so that time frame of all the sets/resets corresponds to the amount of total times it took to capture the time you want to turn on a motor, for ex.   meaning that if it took 1 minute to capture 500 set/resets, then you could approx. capture that in a variable?

The key thing you are missing is that the "time" has absolutely nothing to do with the interrupt. It's elsewhere in the program as is written by the programmer of the sketch. It may be as simple as a delay(1000); in the main loop, or it may be done with millis() in a non-blocking fashion.

yes, Ive seen it done in a sketch, without a delay or millis in the interupt function that is called

All the interrupt does is count. It has no concept of time.  For instance:
volatile uint32_t revolutions = 0;
void count() {
    revolutions++;
}
....
attachInterrupt(0, count, FALLING);

will just count up 1 every time the interrupt triggers.
To be able to convert that count into something meaningful you have to manually introduce the concept of time - that is, the count of "revolutions" (for example) between two points in time.  And it's up to your sketch to implement that.
The simplest way may be:
// For anything more than an 8 bit value on an 8 bit machine
// make a critical section to save and reset the count
cli();
uint32_t savedResolutions = revolutions;
revolutions = 0;
sei();

Serial.print(savedRevolutions);
Serial.println(F(" revolutions per second"));

// Introduce the concept of time - this will
// make it get the count once a second.
delay(1000);

Of course, instead of delay() you can use millis() in much the same way as the BlinkWithoutDelay example in the IDE.
It is possible (as long as you're not counting too fast) to incorporate the time element into the interrupt routine by keeping track of the time in a variable:
volatile uint32_t rps = 0;

void count() {
    static uint32_t revolutions = 0;
    static uint32_t timestamp = millis();

    revolutions++;

    if (millis() - timestamp >= 1000) {
        timestamp = millis();
        rps = revolutions;
        revolutions = 0;
    }
}
....
attachInterrupt(0, count, FALLING);

Then you can just reference the rps variable at any time to get the revolutions per second. Again it should really be queried inside a critical section to prevent the value being changed while you're actively reading it...
cli();
uint32_t myRPS = rps;
sei();

Serial.print(myRPS);
Serial.println(F(" revolutions per second"));

Ive seen people use a variable++ or +1 in a function called by the ISR, without any millis or time reference, then use that variable against another variable to capture a peak value, use that to turn something on for that duration, for example.

Sure, if that's what they are doing requires them to do...

"like that they introduce the concept of time at a later stage"                    could you explain what you mean by this perhaps with an example? I dont quite get it

You mean besides the one I already show in my answer?

yes, it would help

I'm not sure I could add anything by doing something I have already done. I have shown you the most simple and basic example possible. What more do you want?

like if he was to use the interrupt to capture a reed interrupt once per second in a rev++ varible, and use it latter like you suggested

Combine the first code block with the second code block (which you wrap in a setup() and loop() combination with the right pinmodes, serial config, etc) and you have your example.

well that clears things right up dude, thanks. Im imagining those code blocks with everything I should put in them right now. it seems you was suggesting there was a way people were using the count not tied to any milis or delay, so I asked for an example

I know how to use the code blocks and declare initialize in the set up and put the attachinterupt there, outside the loop so it runs independantly of the loop I wanted to know how the counter variable ++ can be mapped or relate to any duration when used with an interupt, but your saying it cant without additional millis internal interupt or delay , but Ive seen it done without all that so I dont get it

If you have seen it done without that then you are looking at something else entirely. You can't get X-per-second without introducing the concept of "seconds". The interrupt has nothing whatsoever to do with that unless you explicitly code it in there like my second example.

so what is a counter like ++ or +1? its just a byte in the regisiters memory?

Either. They both mean the same thing. rev++ means "increment rev", rev = rev + 1 means "add 1 to rev and store it in rev". rev+=1 means "add 1 to rev and store it in rev".

no, Im asking, like if it takes 1 sec for a rev to increment the counter ++ or +1, that one second has no relation to the counter? the value of the increment is just an additional byte into memory?

The value of the increment is just a change of a variable in memory. The number of bytes that takes depends on what the variable is. It's just a variable. There's nothing (apart from the volatile flag) that makes it different from any other variable.

yeah I get that, like a float, int, long, etc, the variable size. Im saying time has no relation, its not stored along with the the increment. like, the magnet passes the reed, 1 count, 1 second, another pass, 2 count 2 sec etc?

Unless you create a variable to store that kind of thing, where would it store it? It only ever does precisely what you tell it. There's never any "magic" in the background storing extra data.

ok cool. I thought maybe the function in the interupt was looking at the interupt pin, and timestamping that, the counts along with the time it took. Actually I see allot of code with just a variable ++ then they store that in a variable, and store the total count in another variable, use that for a duration etc. I didnt see any milis etc like you see in blink delay, none of that so was puzzled how it worked

Ok, I think I see what they were doing. They had rev++ in the interupt function to call, stored that count in a varable, rev, intialized to 0, then used another variable to store the total count into revA. when revA is bigger than rev, do something, else do nothing. still seems like it would be based on the time, but...confusing.

they were comparing 2 variables and saving the larger count, then using that condition to turn on a motor, so it wasnt timed to anything, just when one became larger than the other, save that, and that condition became true, turn on the motor...    As for nested "if" statements, if you have an if then a nested if, that is equilivant to an AND, correct? but an if, then an if else is equilivant to a NOT, correct?


text:
PWM output while using I2C with the ATTiny library
I've noticed that when using the USI interface on the ATTiny to send I2C via the methods from "Wire.h" with the ATTiny Arduino implementation included from the library manager (ATTinyCore), while analogWrite PWM on PB4 (Arduino pin 4, physical pin 3) works OK, it seems attempting to use it on PB1 (Arduino pin 1, physical pin 6) behaves erratically or hangs the processor.
Is this expected behavior, and is there a workaround? With the SDA line on PWM pin 0, physical pin 5 if that's the case it means when using the hardware USI to do I2C communications, I'm down to a single hardware PWM output, which is kind of a bummer.

Just a suggestion (perhaps you have already done this), make sure you are using the most up to date support (software) for this processor.  I had loads of problems with an ARM core Arduino until I updated the supporting software for that processor.

@st2000 The version I have installed via the boards manager is 1.1.4, which is congruent with the latest release on the github page for the project as of August 2017, so likely no joy there. :(

The project also uses millis() which I believe does something with an interrupt on one of the two hardware timers, so I wonder if that might be part of the problem as well, though I was under the impression that firing a timer overflow interrupt wouldn't interfere with the PWM channels. I plan on breaking the situation down into bare-minimum sketches today to try and isolate the problem

This is normal.
Timer0 is used as the clock source for the USI. It's the only internal clock source that can be used. The only other option is to use "software polled" mode where it's up to the sketch (or support library) to manually create the clock signal (less than desirable) by setting a bit in a register at the right time.
So you can only use Timer1 for your own (PWM) purposes while using the USI.

In a situation where two Tiny devices were using i2c to communicate, and at least one of them required more than a single hardware PWM channel, would it be preferable to use software-polling on the slave and the USI on the master, or vice versa?

It only relates to master mode. In slave mode the clock is provided by the master, not Timer0. The slave can have all the PWM running.

Ah, I didn't know if in acting as a slave it also required it for some purpose, that works out fine then.

The only time you need a timer both ends of a connection is for an asynchronous protocol like UART.


text:
Reading and comparing data from Arduino Uno EEPROM
I'm trying to read compare data from EEPROM (Arduino UNO). Reading is working fine but comparing it using the '==' operator is not working as expected.
//string 'True' is already stored in EEPROM

int addr = 0;
char value = EEPROM.read(addr);

Serial.println(value);// this line successfully prints the letter 'T'

// but this function is not working
if (value == "T") {
  Serial.println("foo");
}

this has nothing to do with EEPROM ... this is a question about comparing strings

I have a problem like I that did you finally fix it. I will be glad if it worked.

There is a HUGE difference between "string" and 'c' 'h' 'a' 'r'.
You are comparing address of string "T" with the numerical value of character 'T'.
The expression: if (value == 'T') will be much better.

Thank you for the answer. How can I read and compare the first letter of the string stored at addr = 0; ?

@ShyamMohan  You have to use 'T' instead of "T" to compare value with...


text:
Infinite Loop on Pin Input (Teensy 3.1)?
I have an infinite loop issue that keeps persisting in this code on my Teensy 3.1. This program is intended to take an input on Pin 0 and press the Enter key on the computer it is hooked into.
It is connected to a wire with no current but once a switch is flipped it should send a 5v Digital Signal blip to the Teensy and trigger it to run. It does function but it keeps getting caught in an infinite loop for some reason. Any help would be greatly appreciated!
// Global Variable
int signal_receiving_pin = 0;

void setup() {
  // Outputting for error checking
  Serial.begin(38400);

  // Readying the pin for input
  pinMode(signal_receiving_pin, INPUT);
}

void loop()
{
// If statement to check whether an input has been received
if (digitalRead(signal_receiving_pin) == HIGH)
{
  // If the signal has been detected..
  Serial.println("The signal has been received \n");
  Serial.println("Now sending the ENTER signal \n");

  // .. The ENTER key is sent to the computer
  //Keyboard.press(KEY_ENTER);
  //Keyboard.release(KEY_ENTER);

  // Waiting 1 minute before allowing more input
  //delay(60000); // Pause
}
else
{
  // If the signal is not detected..
  // it will let you know it isn't there
  Serial.println("Input not detected \n");
}
}

Do you have a pulldown resistor?

Try using the internal Pullup/Pulldown resistor to control the input when the pin is not connected to anything.  If you do not have a pullup/pulldown, then the input capacitance on the input pin circuitry can sample and hold the 5V unreliably.
...
void setup() {
  // Outputting for error checking
  Serial.begin(38400);

  // Readying the pin for input
  pinMode(signal_receiving_pin, INPUT_PULLDOWN);
}
...

You may want to uncomment the delay() or add some state logic trigger only one activation per each cycle of signal_receiving_pin

Just changing to INPUT_PULLDOWN solved my problem! Thank you good sir!


text:
NeoPixel library performance: Adafruit vs. FastLED
I'm new to these addressable LED things – I just received a 149-LED WS2812B strip today, and I'm experimenting with various approaches. Adafruit's own tutorial says the FastLED library is faster than their Adafruit_NeoPixel library, so I wanted to test their performance.
I'm running this code on a Nano clone:
// Adafruit
#include <Adafruit_NeoPixel.h>
// FastLED
#include <FastLED.h>
// Common
#define NUM_LEDS 149
#define DATA_PIN 6

// Adafruit initialization
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
const uint32_t adaBlack = strip.Color(0, 0, 0);
const uint32_t adaWhite = strip.Color(255, 255, 255);

// FastLED initialization
CRGB leds[NUM_LEDS];

void setup() {
  // Common
  delay(2000);

  // Adafruit setup
  strip.begin();

  // FastLED setup
  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);

  // Common
  Serial.begin(57600);
}

void loop() {
  unsigned int adafruitMillis = adafruitLoop();
  unsigned int fastLedMillis = fastLedLoop();
  // Yes, this is ugly -- but it works every time
  Serial.print(adafruitMillis);
  Serial.print(",");
  Serial.println(fastLedMillis);
}

unsigned int adafruitLoop()
{
  long unsigned startMillis = millis();
  for (int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed++) {
    strip.setPixelColor(whiteLed, adaWhite);
    strip.show();
    strip.setPixelColor(whiteLed, adaBlack);
  }
  return (unsigned int) millis() - startMillis;
}

unsigned int fastLedLoop()
{
  long unsigned startMillis = millis();
  for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed++) {
    leds[whiteLed] = CRGB::White;
    FastLED.show();
    leds[whiteLed] = CRGB::Black;
  }
  return (unsigned int) millis() - startMillis;
}

The results are totally disastrous for FastLED (shown in red):

Am I doing something wrong, or is FastLED winning on features, rather than on speed?
For the record, I did check whether the performance hit comes from setting the pixel values or from sending the data – FastLED is faster at setting the pixel values than Adafruit's library, but that doesn't matter because setting two pixel values takes 3 ms or less for the entire strip, regardless of the library. Sending the data to the strip takes most of the time, and that's where FastLED lags behind big time (900 ms compared to Adafruit's 200 ms).

Might I suggest a more realistic test-case. Like setting all pixels to white, then call show, then set all pixels black, and call show. Maybe repeat this like 100 times to get a bigger time-diffence value.

You can't rely on the timing reported by millis when comparing FastLED and Adafruit's neopixel library.  Writing out Neopixel data involves disabling interrupts, which is what the clock uses to advance.  FastLED accounts for this and attempts to update the system clock time after writing out led data to account for the amount of time that interrupts were disabled, but the adafruit NeoPixel library doesn't.  You need to use something else to compare timing.
(WS2812 data has a pretty strict data rate - 800khz, or about 30µs per rgb led)
(I should know, I wrote FastLED :)

(Also - when it comes to WS2812 data on AVR, the Fast in FastLED is also for the writing data - the tuned assembly output takes exactly 30µs per pixel (1.25µs per bit, or 20 clock cycles on a 16Mhz avr), and in that 30µs, not only is it writing out data, but it's also doing the scaling/dithering/color correction for the led data to write out)

Also - the rate throttler referred to above is to cap updating WS2812 leds at a rate no higher than 400Hz - WS2812 leds freak out if you update them more than 400 times/second.

Fair enough, that makes sense. I had noticed that in practice the speed difference was barely noticeable – certainly nothing like the 4x difference the millis() data seems to suggest. I was just too lazy to actually rig up a separate clock to measure real user time. Thank you for taking the time to clarify this.
Having said that, I did manage to squeeze a bit more speed out of it by removing the throttler altogether – and the LEDs didn't get borked.

As I understand it, the Fast in FastLED isn't for sending the data, but for manipulating the array/data that holds the colors. The FastLED library contains many functions optimized for dealing with 8-bit unsigned integers for holding color values, including color addition, 8-bit scaling, partially-defined color palettes (for example, you define 8 waypoints in the palette, but can grab a color from the full 8-bit range and it interpolates on the fly using the fast 8-bit math.
Not just math, but also conversion to/from RGB and HSV realms, etc.
It supports pushing multiple strips at the same time (parallel) by writing to the whole PORT instead of just one pin of the 8-pin port, so if you split your strip into multiples, you can really make speed gains in writing to the LEDs.

Fair enough, I had ended up with the same impression – but the difference in performance for this basic test is so large I wanted to make sure I wasn't using it wrong. Thanks for taking the time to whet my appetite, though!

Your evaluation code is fine, but probably doesn't represent a real-world use case. I've commonly seen animation code structured to have a fixed rate for the FastLED.show() command, and you have to complete all your animation steps between each frame update. That is where the fast 8-bit color and math routines are useful.

That's a legitimate observation, but it depends on whether the library is throttling data bursts, or if what we're seeing is plain overhead. If it's throttling data it's all good, because all of my real-world scenario calculations will eat into the time it's currently idling. But if this is overhead then all of this is going to add up to the calculations, resulting in limited performance. I actually did track down a refresh rate throttler in the library, and hope to experiment a bit tonight. In case you're curious: https://github.com/FastLED/FastLED/blob/master/FastLED.cpp#L41


text:
Can't burn bootloader through Arduino Nano clone ISP to atmega328p
I'm trying to use a Nano v3 as ISP to program an atmega328p on a board with ISP headers:
I followed the instructions under
https://www.arduino.cc/en/Tutorial/ArduinoISP which I think have been recently updated. I'm simply connecting ISP headers together except for D10 from programmer to reset on the target AVR.

The ISP sketch seems to be working fine as far as I can see the heartbeat pulsing a led. But when trying to burn bootloader with settings:
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x15
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x15

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x01
avrdude: stk500_initialize(): (a) protocol error, expect=0x14, resp=0x10
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: stk500_disable(): unknown response=0x12
Error while burning bootloader.

I noticed something weird though, the 5V and GND on the ISP header on the programmer nano only has around 0.4V. This even without anything external but the usb connected. Is my nano broken or is the usb connection not able to deliver enough power?

If the vcc from your nano is down to 0.4v then the board you are trying to program is not getting any power and it wont work. You have to make sure that both the nano and the board atmega328 you are trying to program are both supplied with power AND THAT THEY ARE RUNNING OFF OF THE SAME SUPPLY VOLTAGE. Only then is it going to work. The reason you are only measuring 0.4v could be because the target board is drawing too much power.

If it's down to 0.4 V then there might be an almost-short circuit somewhere.

Turns out I was an idiot when I took that picture and did the measurement. I had simply turned the ISP header upside down :(. I'm at 4.7V which should be fine. Still same error though.

Your slave micro isnt resetting when your master wants it to reset.
Ie: master sends a reset signal before initiating further communication, and it seems that your slave not being reset.
So its not responding.
Once cross check your isp signal lines.

Try adding the 10µF capacitor connected to RESET and GND on the board you are using as programmer (in this case, your Nano). This is required according to the Documentation.

The 10µF electrolytic capacitor connected to RESET and GND of the programming board is needed only for the boards that have an interface between the microcontroller and the computer's USB, like Mega, Uno, Mini, Nano.

I just encountered the exact same error output, and the capacitor solved it.


text:
Getting stable measurements with the BNO055 IMU
I bought the BNO055 "smart" IMU from Adafruit, thinking it would be a simple way to get orientation data for a small mobile robot project, but I've found the thing to be very difficult to use and nearly worthless.
It's advertised as being able to auto-calibrate, and although it does attempt to do this, I've found that the calibration doesn't hold. It continuously re-calibrates itself, and either gets stuck in an error state or find a successful calibration...but then loses it after a few seconds.
Is there anything I can do to improve its stability? Does it need to be mounted inside a special grounded housing? Is there a special incantation I should utter before powering it on?
I'm reading it from an Arduino Uno via I2C, and though the wiring and programming is relatively simple, getting it calibrated and staying calibrated I've found to be nearly impossible.
Even after the "system" flag says its fully calibrated, and I have the IMU just sitting on a table, not moving, after a minute, it loses its "system" calibration. The accelerometer, gryoscope, and magnetometer usually remain calibrated, but how can I trust them if the on-board fusion algorithm is reporting it's not ready?
If the BNO055 is a lost cause, is there anything better? I've tried several MPU-**** chips from InvenSense, but they're even worse.

did you follow the calibration procedure?

Try a permanent calibration. From the Adafruit forums:

You'd basically need to read and write data registers 55-6A. In both cases, you have to set the sensor in CONFIG_MODE. There's more information on page 48 of the datasheet.

The magnetometer is influenced by surrounding magnetic sources like motors. You might be able to tell the extent of the effect using the following method:

The System Calibration Status will start out at 0 and will go to 3
  when the sensor is calibrated. For example, the mag calibration status
  will go to 3 if you do some figure 8s. If you put a piece of metal
  near the sensor, the calibration status will drop to 0. But when the
  metal is moved away, it will go back to 3. You may be able to use this
  value as an indicator that calibration is lost. I have found that once
  it's calibrated, it seems to hold calibration well.

For getting solid readings out of the gyroscope, this might be helpful advice:

I don't worry about scaling the gyro output on a per-sample basis. I simply sum the output into a 32 bit (or larger) integer register. I do subtract-out a null value at each sample, which I will talk about later. But essentially, if you sample your gyro at 1kHz, and sum the output into an accumulator, you will see that the value of that accum at any time will be directly proportional the angle of rotation. If your rate is set for 250 deg/sec, then a rotation of 180 deg will result in approximately 23330000 in the accumulator. I call that the GYRO_CAL number. So, at any given time the angle, in degrees, is deg = accum / GYRO_CAL * 180.
Since the gyro output is linear, the accumulator is insensitive to
  whether the rotation is fast or slow (as long as the max deg/sec isn't
  exceeded).
Here is my basic routine for each gyro reading:

void read_FIFO(){
       sample = read_value_from_FIFO();   //read the latest z-axis sample. I use the fifo, but that isn't necessary
       accum += sample - null;           //add the sample to the sum and subtract the null
       if((accum > GYRO_CAL) -= GYRO_CAL*2;  //roll the accumulator at +180 deg.
       if((accum < -GYRO_CAL) += GYRO_CAL*2; // roll the accumulator at -180 deg.
       angle = accum/GYRO_CAL * 180;   // convert to degrees
}

I calculate the null at the beginning of each run. I sum 1000 readings
  and take the average. The gyro has to sit still for 3 or 4 seconds for
  this. The GYRO_CAL value can be calculated by summing the output while
  you rotate the gyro by 180 deg. Or you can sum over many turns, and
  divide by the number of 180 deg turns for a more accurate value.
You could probably use a 64-bit FP for the accumulator, but since
  arduino only supports 32 bit FP, I found it absolutely necessary to
  use a 32 bit integer to avoid roundoff and other errors.
If you follow that general outline, I promise you will get rock solid
  performance out of the gyro. There are a few other small optimizations
  that I make, which I can discuss later.

Unfortunately, there is no such feature as "permanent calibration" with the BNO055. Yes, once I obtain stable calibration parameters, I can save and later reload them. That's what that forum thread describes, and that's what I'm already doing. Unfortunately, the BNO055 continuously updates and re-calibrates itself, eventually losing these "good" values if the magnetometer encounters a little interference.


text:
Writing data to a specific address in EEPROM
I'm trying to write two strings to an Arduino Uno's EEPROM. Here, the first code block works fine: it writes string(True/False) at 'address 0'. But the second block, which writes data at 'address 5', is not working as expected.Reading data at address 5 prints a blank line. What am I missing here? Is this the correct way to write two different strings to EEPROM?
First code block:
int state = LOW;
char first_eeprom_value;
if (state == LOW) {
  state = HIGH;
  char example_string[4] = "True";
  first_eeprom_value = EEPROM.read(0);
  Serial.println(first_eeprom_value);
  for (int i = 0 ; i < 5 ; i++) {
    EEPROM.update(i, example_string[i]);
  }
} else {
  state = LOW;
  char example_string[5] = "False";
  first_eeprom_value = EEPROM.read(0);
  Serial.println(first_eeprom_value);
  for (int i = 0 ; i < 5; i++) {
    EEPROM.update(i, example_string[i]);
  }
}
Time = millis();

Second code block:
char first_eeprom_value1;
if (state1 == LOW) {
  state1 = HIGH;
  char example_string1[4] = "True";
  first_eeprom_value1 = EEPROM.read(5);
  Serial.println(first_eeprom_value1);
  for (int i = 5 ; i < 11 ; i++) {
    EEPROM.update(i, example_string1[i]);
  }
} else {
  state1 = LOW;
  char example_string1[5] = "False";
  first_eeprom_value1 = EEPROM.read(5);
  Serial.println(first_eeprom_value1);
  for (int i = 5 ; i < 11 ; i++) {
    EEPROM.update(i, example_string1[i]);
  }
}

Time = millis();

//reading data at address 5
int addr = 5;
char value = EEPROM.read(addr);
Serial.println(value);// this prints blank line

is not working as expected - what do you expect, and what is actually happening?

Nothing is getting written when using 2nd code block.

How do you know? Can you please amend your question to include the output from the serial prints that you have in your code?

I have edited the question and 2nd code block.

remove the if ... then ... else statements ... minimize the code as much as possible ... do just a write and then a read ... do you still have the same problem?

you do not terminate the strings with 0. for a string with 4 chars allocate an array of 5 chars and write 0 at the end after reading from eeprom.. otherwise the print doesn't know where the string ends

@Juraj Let me try that.

"you do not terminate the strings with 0"- Can u help me with code?

@Juraj he is reading just one char from the eeprom, not a string, so a terminator is not required

@frarugi87, true. the code is so chaotic

You are cycling outside the string, thus creating undefined behavior.
Try replacing the second block with this:
char first_eeprom_value1;
if (state1 == LOW) {
  state1 = HIGH;
  char example_string1[4] = "True";
  first_eeprom_value1 = EEPROM.read(5);
  Serial.println(first_eeprom_value1);
  for (int i = 0; i < sizeof(example_string1); i++) {
    EEPROM.update(i + 5, example_string1[i]);
  }
} else {
  state1 = LOW;
  char example_string1[5] = "False";
  first_eeprom_value1 = EEPROM.read(5);
  Serial.println(first_eeprom_value1);
  for (int i = 0; i < sizeof(example_string1); i++) {
    EEPROM.update(i + 5, example_string1[i]);
  }
}

Please note that this is not optimal; I suggest you to use fixed-length strings, and fill the unused spaces with blanks or 0s, so you can read back all the bytes you wrote in a safe way


text:
How to input text from Serial monitor into a character array?
I'm using a Mega 2560 and Uno and want to input text to the serial monitor which can be stored in character array char in[];
I want array specifically as I'll be breaking each character to trigger different code for making a morse code.
    #include<Arduino.h>
//#include<Softwareserial.h>

int Speaker1 = 4;
int Speaker2 = 6;
int LED = 2;
int Relay = 12;
char n = '0';
char in[];
//int outPins[] = { 2, 4, 6, 8 };

void high() {

  digitalWrite(Speaker1, HIGH);
  tone(Speaker2, 800);
  digitalWrite(LED, HIGH);
  digitalWrite(Relay, HIGH);

}

void low() {

  digitalWrite(Speaker1, LOW);
  tone(Speaker2, 800);
  digitalWrite(LED, LOW);
  digitalWrite(Relay, LOW);

}

void setup() {

  Serial.begin(9600);

  pinMode(Speaker1, OUTPUT);
  pinMode(Speaker2, OUTPUT);
  pinMode(LED, OUTPUT);
  pinMode(Relay, OUTPUT);

  Serial.print("Enter your desired text: ");
  //in = Serial.readString();  /*<-------------HELP NEEDED HERE */

  for (int i = 0; i < strlen(in); i++) {

    n = in[i];

    switch (n) {

      case 'A':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'B':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'C':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'D':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'E':
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'F':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'G':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'H':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'I':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'J':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'K':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'L':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'M':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'N':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'O':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'P':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'Q':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'R':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'S':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case 'T':
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'U':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'V':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'W':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'X':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'Y':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case 'Z':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case ' ':
        delay(700);
        break;
      case '1':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case '2':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case '3':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case '4':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;
      case '5':
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case '6':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case '7':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case '8':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case '9':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(100);
        low();
        delay(300);
        break;
      case '10':
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(100);
        high();
        delay(300);
        low();
        delay(300);
        break;

    }

  }

}

void loop() {

}

Have you googled it? See https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/

Are you going to send each char at once or you will write a sentence and send?

Welcome to Arduino SE. Please realize that this is not a free design house, homework-answering service or an on-line technical encyclopedia, copied out to you on demand. People will help you take the next step if your question shows that you've done as much as you possibly could on your own - which your post doesn't. Please revise your question showing your work and findings so far. Or delete the question if Internet searches give you your answer anyway.

@rvbarreto I will create a sentence and send.

What's your question?

@LookAlterno I did tried googling it, but the thing is I cannot quite find a way to insert text into character array with spaces. (In sentence format).
This isn't a homework, I was trying to build a code to translate input text into Morse pulses. Code is updated in question.

@LookAlterno Tried editing the question, maybe this would be a bit clear.

@EdgarBonet I don't think that link would help me here. Note - I updated with a code for my use case.

You wrote: “I don't think that link would help me”. Of course it won't help if you don't read it! But it does contains the solution to your problem.

@EdgarBonet Believe me I read it, the problem I'm seeing there is that reading needs void loop (), whereas my whole program lies in void setup and has for loop in it.
Next, I need the program to "wait" like it does in a C program if I say put code printf("Enter your text: \n);
scanf("%s", &in);
Here , the program will wait until I insert the string and then execute the rest of the code below because again, if you check above, I need to break the sentence to trigger individual Morse signal assigned. Please point out any miss info by me here, I'm still learning here.

forget the morse code task and try examples with serial input, understated them, modify a little, try if what you changed does what you expected.

Note: case '10' is not going to work, I even am surprised it compiles. You can only put one character within ' and '

@MichelKeijzers Well Damn I'm dumb.

@Juraj On it! Trying the link by Edgar Bonet RN.

Also, not a solution but to make your program (without making it more complicated) a lot easier: move the low(); and delay(300) at the end of each break statement UNDER the switch statement, this saves a lot of lines.

Another one: add the delay of 100 in low and delay of 300 in high. This saves you a lot of lines.

@MichelKeijzers
Oh, btw then I'll have to create two highs for dots and dashes and low for character space, character end, etc. Couldn't think of a efficient way for that.
Also note one of my case is ' ' i.e. space, so if I remove all the break, do I move the case ' ' to last and set the delay 400 which will make it 700 in total ? - The answer is yes, goddamnit I'm dumb

I will make an answer to show an even better way.

I suggested in a comment you read the blog post Reading Serial on the
Arduino. In this post, Majenko shows a readline()
function that does almost exactly what you want. This function is
non-blocking, which, in the embedded world, is most of the time a
mandatory feature. However, in one of your comments you wrote that you
want a blocking function:

I need the program to "wait" like [...] scanf

Degrading a non-blocking function into a blocking one is as easy as
wrapping the non-blocking function in a loop. Here is a code snippet for
reading a CR-terminated string, which is similar to a blocking version
of Majenko's readline():
char buffer[80];
size_t pos = 0;
for (;;) {
    int c = Serial.read();
    if (c == -1) continue;   // no input
    if (c == '\r') {         // end of line
        buffer[pos] = '\0';  // terminate the string
        break;
    }
    if (pos < sizeof buffer - 1) {
        buffer[pos++] = c;
    }
}

That being said, I could not resist the temptation to brutally simplify
your program. The key to the simplification is to consider the Morse
code as a data structure. Then, the code for keying a string is
generic: you look up each character in the code table and key it in
turn. This saves the long switch/case:
struct code_t {
    char c;
    const char *code;
};

static const code_t morse_code[] = {
    {'A', ".-"   }, {'B', "-..." }, {'C', "-.-." }, {'D', "-.."  },
    {'E', "."    }, {'F', "..-." }, {'G', "--."  }, {'H', "...." },
    {'I', ".."   }, {'J', ".---" }, {'K', "-.-"  }, {'L', ".-.." },
    {'M', "--"   }, {'N', "-."   }, {'O', "---"  }, {'P', ".--." },
    {'Q', "--.-" }, {'R', ".-."  }, {'S', "..."  }, {'T', "-"    },
    {'U', "..-"  }, {'V', "...-" }, {'W', ".--"  }, {'X', "-..-" },
    {'Y', "-.--" }, {'Z', "--.." },
    {'1', ".----"}, {'2', "..---"}, {'3', "...--"}, {'4', "....-"},
    {'5', "....."}, {'6', "-...."}, {'7', "--..."}, {'8', "---.."},
    {'9', "----."}, {'0', "-----"},
    {' ', " "    }, {'\0', NULL}  // sentinel
};

static inline void high() { digitalWrite(LED_BUILTIN, HIGH); }
static inline void low()  { digitalWrite(LED_BUILTIN, LOW);  }

// Key a string in Morse.
void key(const char *s)
{
    for (; *s; s++) {  // *s = current letter

        // Find this letter's code.
        const code_t *p;
        for (p = morse_code; p->c; p++) {
            if (p->c == toupper(*s)) break;  // found
        }
        if (!p->c) continue;  // not found -> ignore

        // Send this code's symbols.
        for (const char *code = p->code; *code; code++) {
            if (*code != ' ')
                high();
            switch (*code) {
                case ' ': delay(100); break;
                case '.': delay(100); break;
                case '-': delay(300); break;
            }
            low();
            delay(100);
        }
        delay(200);  // inter-letter spacing = 300 ms
    }
}

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

void loop()
{
    // Read a string.
    char buffer[80];
    size_t pos = 0;
    for (;;) {
        int c = Serial.read();
        if (c == -1) continue;   // no input
        if (c == '\r') {         // end of line
            buffer[pos] = '\0';  // terminate the string
            break;
        }
        if (pos < sizeof buffer - 1) {
            buffer[pos++] = c;
        }
    }

    // Key it in Morse.
    key(buffer);
}

Note that this program reads CR-terminated strings from the Serial port
and keys them on the builtin LED. If you want your program to work on a
single string, you can call exit() at the end of loop() or,
alternatively, merge loop() into setup() and provide an empty
loop().

Brilliant answer.

I don't understand exactly why your signals are much different from 'real' morse code, e.g. A is .-
Instead of calling each high and low separately like the 'a' for example:
  case 'A':
    high();
    delay(100);
    low();
    delay(100);
    high();
    delay(300);
    low();
    delay(300);
    break;

call it like this:
case 'A':
  send2(false, true); /* means .-
  break;

Than create a function send2 which sends a . and a -
Something like:
void send2(bool b1, bool b2)
{
   send(b1);
   send(b2);
   delay(300); /* Extra wait in between characters */
}

For characters needing 1, 3 or 4 characters, you can make send 1, send3 and send4 accordingly.
void send(bool b1)
{
   digitalWrite(Speaker1, b1 ? HIGH : LOW);
   tone(Speaker2, b1 ? 800);
   digitalWrite(LED, HIGH);
   digitalWrite(Relay, HIGH);
   delay(b1 ? 300 : 100); /* Assuming HIGH needs delay of 300 and low of 100 */
}

void low() {

  digitalWrite(Speaker1, LOW);
  tone(Speaker2, 800); /* I would expect two different values for HIGH and LOW */
  digitalWrite(LED  , b1 ? HIGH : LOW);
  digitalWrite(Relay, b1 ? HIGH : LOW);
}


text:
No ttyACM0 nor ttyUSB0
I checked several related posts but couldn't solve my problem.
I have Antergos Linux :
# uname -a
Linux biutitude 4.14.11-1-ARCH #1 SMP PREEMPT Wed Jan 3 07:02:42 UTC 2018 x86_64 GNU/Linux

The board is a Seeeduino Lorawan.
The problem is that the menu to select the port is greyed, and when I check in /dev I don't see any new tty when I plug the card. However the card blinks.
I tried :
- adding myself to lock + tty + uucp (and restarted my session)
- created a dialout group because I didn't have one, added myself to it
- loading cdc_acm module but got the following error :
# modprobe cdc_acm
modprobe: FATAL: Module cdc_acm not found in directory /lib/modules/4.14.11-1-ARCH

Thus I tried :
[root@biutitude biu]# depmod -ae
depmod: WARNING: -e needs -E or -F
depmod: ERROR: could not open directory /lib/modules/4.14.11-1-ARCH: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
[root@biutitude biu]# depmod
depmod: ERROR: could not open directory /lib/modules/4.14.11-1-ARCH: No such file or directory
depmod: FATAL: could not search modules: No such file or directory

I'm clearly out of ideas. The weirdest is that a few months ago, I was able to use a RFduino card without any trouble.

Run watch lsusb, then plug in the board. Does it show a new entry in the list? If so, what does it say?

dmesg -w is your friend. Run that, plug in the board, and look what it tells you.

My solution - install linux-modules-extra kernel module on ubuntu 20.04. Solved my problem which was identical.
Get OS details:
uname -a
Linux seeeduino-node 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Install the sudo apt install linux-modules-extra:
sudo apt install linux-modules-extra-<kernel-version>

Example:
sudo apt install linux-modules-extra-5.4.0-91-generic

You need to reboot the machine afterwards it should work.


text:
How do I control the buttons on an Arduino LCD keypad shield?
I have just bought a 16x2 LCD display with buttons. I can get the display to work and do various basic sketches included in the Arduino IDE. However, I cannot figure out how to control the buttons.
The buttons work using analog pin 0 and from what I was able to understand from what I have read online, it is something to do with the values you receive when the buttons are pressed. I can't seem to find out what values mine gives, I have found a sketch that is supposed to map the buttons, but I cannot get it to work, as I don't really understand what it is doing, I am very new to this.
The code I am using is as follows:
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int lcd_key     = 0;
int adc_key_in  = 0;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

int read_LCD_buttons() {
  adc_key_in = analogRead(0);
  if (adc_key_in > 1000) return btnNONE;
  if (adc_key_in < 50)   return btnRIGHT;
  if (adc_key_in < 250)  return btnUP;
  if (adc_key_in < 450)  return btnDOWN;
  if (adc_key_in < 600)  return btnLEFT;
  if (adc_key_in < 920)  return btnSELECT;
  return btnNONE;
}

void setup() {
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("Push the buttons");
}

void loop() {
  lcd.setCursor(9, 1);
  lcd.print(millis()/1000);
  lcd.setCursor(0, 1);
  lcd_key = read_LCD_buttons();
  switch (lcd_key) {
    case btnRIGHT: {
      lcd.print("RIGHT ");
      break;
    }
    case btnLEFT: {
      lcd.print("LEFT   ");
      break;
    }
    case btnUP: {
      lcd.print("UP    ");
      break;
    }
    case btnDOWN: {
      lcd.print("DOWN  ");
      break;
    }
    case btnSELECT: {
      lcd.print("SELECT");
      break;
    }
    case btnNONE: {
      lcd.print("NONE  ");
      break;
    }
  }
}

If anyone can give me any pointers it would be greatly appreciated.
Liam

Add a Serial.begin(9600) in setup, and a Serial.print(adc_key_in) after you read the key, to see what values you get. If they don't change, it's a hardware problem (faulty element or wrong circuit), otherwise you know what values you get per key.

Thank you for your help, it didn't occur to me to do that at all.

No problem, for Arduino this is the common way to debug (to use the serial port for print statements), for other AVR's debugging can be used.

I have found an easy way to do this, i found a tutorial on instructables that has explained in detail what to do, i then applied this to my LCD keypad shield rather than external buttons on a breadboard.
All you have to do to see what the results are for your particular buttons is to load the sketch below onto your board then open the serial mapper on the arduino ide, simply press the buttons and you should see the results.
 /*
  Debounce

  Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
  press), the output pin is toggled from LOW to HIGH or HIGH to LOW.  There's
  a minimum delay between toggles to debounce the circuit (i.e. to ignore
  noise).

  created 28 October 2009
  by Riaan Cornelius

  */

 // constants won't change. They're used here to
 // set pin numbers:
 const int buttonPin = 0;     // the number of the pushbutton pin
 const int ledPin =  53;      // the number of the LED pin for testing

 const int BUTTON1 = 1;
 const int BUTTON2 = 2;
 const int BUTTON3 = 3;
 const int BUTTON4 = 4;
 const int BUTTON5 = 5;

 const int BUTTON1LOW = 970;
 const int BUTTON1HIGH = 1024;
 const int BUTTON2LOW = 850;
 const int BUTTON2HIGH = 950;
 const int BUTTON3LOW = 700;
 const int BUTTON3HIGH = 800;
 const int BUTTON4LOW = 400;
 const int BUTTON4HIGH = 650;
 const int BUTTON5LOW = 250;
 const int BUTTON5HIGH = 350;

 // Variables will change:
 int ledState = HIGH;         // the current state of the output pin
 int buttonState;             // the current reading from the input pin
 int lastButtonState = LOW;   // the previous reading from the input pin

 // the following variables are long's because the time, measured in miliseconds,
 // will quickly become a bigger number than can be stored in an int.
 long lastDebounceTime = 0;  // the last time the output pin was toggled
 long debounceDelay = 50;    // the debounce time; increase if the output flickers

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

 void loop() {
   // read the state of the switch into a local variable:
   int reading = analogRead(buttonPin);
   Serial.println(reading);

   /*
   Not needed while getting the values.

   int tmpButtonState = LOW;             // the current reading from the input pin

   if(reading>BUTTON5LOW && reading<BUTTON5HIGH){
     //Read switch 5
     tmpButtonState = BUTTON5;
   }else if(reading>BUTTON4LOW && reading<BUTTON4HIGH){
     //Read switch 4
     tmpButtonState = BUTTON4;
   }else if(reading>BUTTON3LOW && reading<BUTTON3HIGH){
     //Read switch 3
     tmpButtonState = BUTTON3;
   }else if(reading>BUTTON2LOW && reading<BUTTON2HIGH){
     //Read switch 2
     tmpButtonState = BUTTON2;
   }else if(reading>BUTTON1LOW && reading<BUTTON1HIGH){
     //Read switch 1
     tmpButtonState = BUTTON1;
   }else{
     //No button is pressed;
     tmpButtonState = LOW;
   }

   // check to see if you just pressed the button
   // (i.e. the input went from LOW to a buttonState),  and you've waited
   // long enough since the last press to ignore any noise:

   // If the switch changed, due to noise or pressing:
   if (tmpButtonState != lastButtonState) {
     // reset the debouncing timer
     lastDebounceTime = millis();
   }

   if ((millis() - lastDebounceTime) > debounceDelay) {
     // whatever the reading is at, it's been there for longer
     // than the debounce delay, so take it as the actual current state:
     buttonState = tmpButtonState;
     Serial.println(buttonState);
   }

   // save the reading.  Next time through the loop,
   // it'll be the lastButtonState:
   lastButtonState = tmpButtonState;

   // set the LED using the state of the button for testing:
   switch(buttonState){
     case BUTTON1:
     digitalWrite(ledPin, buttonState>0);
     break;
     case BUTTON2:
     digitalWrite(ledPin, buttonState>0);
     break;
     case BUTTON3:
     digitalWrite(ledPin, buttonState>0);
     break;
     case BUTTON4:
     digitalWrite(ledPin, buttonState>0);
     break;
     case BUTTON5:
     digitalWrite(ledPin, buttonState>0);
     break;
   }
   */
 }

Liam

Upload this and it will read the resistance of your buttons on the lcd screen
/*  /*
Arduino 2x16 LCD Detect Buttons
resistance
*/

#include <LiquidCrystal.h>

//LCD pin to Arduino
const int pin_RS = 8;
const int pin_EN = 9;
const int pin_d4 = 4;
const int pin_d5 = 5;
const int pin_d6 = 6;
const int pin_d7 = 7;

const int pin_BL = 10;

LiquidCrystal lcd( pin_RS,  pin_EN,  pin_d4,  pin_d5,  pin_d6,  pin_d7);

void setup() {

  lcd.begin(16, 2);

  lcd.setCursor(0,0);

  lcd.print("  Press Any Key ");
  lcd.setCursor(0,1);
  lcd.print("Resistance:");
}

void loop() {
  int x;
  x = analogRead (0);
  lcd.setCursor(12,1);
  lcd.print (analogRead (0));
  lcd.print("                ");
  delay (500);
  }

As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

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


text:
Manually added boards doesn't work in 1.8.5…?
I'm trying to manually add board definitions in a boards.txt file in hardware subfolder of my sketches folder as per instructions here for instance: https://www.arduino.cc/en/Tutorial/ArduinoISP
They however do NOT show up in my board selection.
My sketches location where hardware subfolder should be placed:

Board defs:
~/D/Arduino ❯❯❯ cat ~/Documents/Arduino/hardware/boards.txt
##############################################################

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05

atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard

atmega328bb.bootloader.tool=arduino:avrdude
atmega328bb.upload.tool=arduino:avrdude

BUT nothing show here:

I have restarted Arduino IDE.

Alternatively, and if the board is on internet, could not you added by the preference menu using the key combination " CTRL + , "?

Newer versions of the IDE (after 1.5) have a different folder structure where there is additional subfolders for maintainer and architecture.
<Arduino sketch folder>/hardware/<custom name>/avr/boards.txt

https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification


text:
Can I power ESP8266 with more than 3.5 V?
I am concerned whether I need to use a voltage divider to power my ESP8266 module. My concerns stem from the warnings that I have heard in multiple tutorials. Everyone seems to regard the ESP8266 as being very sensitive to supply voltage.
Has anyone use the ESP8266 with an supply voltage greater than 3.5 V? What were the effects? Is it even necessary to make a voltage divider?
I am asking because my application has limited real estate.

Surely you mean 3.3V :)

Some of the pins on ESPs are protected against excessive voltage, personally I always err on the side of caution and use regulators and level shifters, but with the real estate restrictions I'd suggest you check the manual on what the absolute maximum is that you version of the board can take.

Are you talking about providing power to the ESP, or just an input-pin? For power use a voltage regulator. For inputs you could indeed use a voltage divider.

To be clear I was talking about the power input.

If your voltage source is high enough, spend less than a buck on a regulator like a LD1117-3.3

you cannot power an ESP from a voltage divider because it's current is not steady.

My esp32 chip got fried when I supplied it with 3.5V (using an LM317) directly to the 3.3-pin. So.. very sensitive.

The datasheet usually is definitive on the allowable range of voltages.
Look in Section 5.1: Electrical Characteristics.
Working Voltage Value:

Min: 2.5 V
Typical: 3.3 V
Max: 3.6 V

If you have to feed in signals that could go higher than 3.3 V in normal operation, you need to either clamp it with Zener diodes, or use a voltage divider.
If you are asking about powering the chip with more than 3.3 V, don't. You can get away with a 3.3 V linear regulator and 2 capacitors so that you are powering it with no more than designed supply voltage.

The result to apply more voltage to a circuit is that the components will be burn. The same if you apply for a long time the maximum voltage. So the board works at 3.3v, your source maybe fluct between that but you will burn it if you apply 3.6 or more as a regular voltage.

Usually ESP8266 modules have an onboard voltage regulator, USB connector and a pin labeled 5V. This pin or the USB cable certainly tolerate resp. need a 5V power supply.
The ESP8266 controller itself will not survive 5V, neither at the Vcc nor at the signal pins.
BTW: a voltage divider (two resistors) is ok for signals, but does not help with the power supply.

I have 4 pieces of ESP01-S with DHT11 that connect to the WiFi every 30 minutes and send temperature data and then go into DeepSleep.  In addition, an ESP01-S as a motion detector and one as a push button.  These two usually in DeepSleep.
All are directly connected to a Li-Ion battery as power supply.  This has been running for over a year (except for changing the battery) and so far I haven't had any problems

Welcome to Arduino:SE.  I don't think this actually answers the question.

This is anecdotal information i.e. it might work for you but it (greatly) exceeds the manufacturer's specifications. Connecting directly to a Lithium Ion cell means the ESP8266 is exposed to voltages of over 4 V when the battery is fully charged.


text:
Wemos: 16x2 display doesn't show anything
I connected a 16x2 LCD display to a Arduino Uno. Then I tested a "Hello, Word" code and it works perfect.
Now I want to do the same with a Wemos D1 Mini but it doesn't work.
Here the Wemos is not connected to USB:

This os the "Hello, World" code. I needed to change the name of the pins (maybe this is the problem):
#include <LiquidCrystal.h>

const int rs = 8, en = 7, d4 = D5, d5 = D4, d6 = D3, d7 = D2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  lcd.begin(16, 2);
  lcd.print("hello, world!");
}

void loop() {
  lcd.setCursor(0, 1);
  lcd.print(millis() / 1000);
}

This is the result (potentiometer works perfect):

A first step might be to clear out the code in loop() so that you can narrow down the issue. Just do the items in setup() so they happen only once. After you get text there, you can move on to more complex action. Of note, though, is that Wemos boards are 3.3V and LCDs are typically 5V. It doesn't look like you're level-shifting, though.

You are doing it on wemos d1 mini isnt it ?
Then you dint include its header files,
Did you check the "LiquidCrystal.h" has definitions for wemos pinouts?
Your lcd is fine, n wemos too, its just your configuration is wrong.
Check those and update here.

Although an old question, i just ran into the excat same issue.
The problem is that the pin numeration on the wemos D1 isn't the same as on the arduino.
I've followed the liquid crystal arduino tutorial but changed the numeration of the pins to
const int rs = 12, en = 13, d4 = 14, d5 = 4, d6 = 5, d7 = 16;

Now, at least for me, the display works as it should

thx, or can be defined like: const int rs = D6, en = D7, d4 = D5, d5 = D2, d6 = D1, d7 = D0;

Three possibilities (it's impossible to be more accurate from your description):

The display isn't wired to the pins you specified in your sketch
The display doesn't accept 3.3V signals when run from 5V
The display doesn't function when run from 3.3V

It's certainly not being initialized, which tells me that the instructions for setting it up aren't getting through, or aren't being executed when they do get through.
You can:

Use an oscilloscope or logic analyzer to confirm the right pins are in use,
Try powering the display from 3.3V if it's currently powered by 5V
Try powering the display from 5V if it's currently powered by 3.3V

If it's powered by 5V you may want to consider adding some logic level translation to boost the IO signals from the Wemos to 5V.


text:
Char* and string conversion from an ESP8266 web server
I have the following Arduino code for configuring a wifi connection through a simple webpage:
I declare char* ssid;. Later I read a value from a SPIFFS config file where q_ssid is declared as a string and successfully populated from the file:
strncpy(ssid, q_ssid.c_str(), 10);

In the line above, I am limiting it to exactly 10 as that is the length of my wifi AP name that this connects to. If I change the initial char* to char ssid[10];, all works well, but SSIDs can have varying names, and if I do not use 10 chars, then the trailing spaces prevent connection in the statement WiFi.begin(ssid, password);.
On the web client handler that reads in values from the user, I use this:
String q_ssid = server.arg("ssid");
strncpy(ssid, q_ssid.c_str(), 10 );

How can I dynamically assign the size of char* ssid; so that it can be used with the correct number of characters for the AP name that the user has stored from the webpage?
Any help is greatly appreciated.
Thanks.

What you need to do is creating a fixed string, this can be done in two ways:
static:
char ssid[100];

Where 100 is the maximum length ever possible. Note that this will always use up 100 bytes, even if less are used (e.g. your string length is 5.
dynamic:
char* p_ssid = malloc(100);

This way a pointer is created to a dynamically created string that can hold 100 characters. Disadvantage is that using malloc in a microcontroller can cause empty memory 'holes' when freeing/mallocing a lot.
With either way you can than use a normal strncpy or strcpy (in first case use &ssid to get a pointer to the ssid).
Also don't forget to add 1 to the length because of the trailing \0 to denote the string is ended.
Thus for storing 10 characters, you need an 11 char sized array.

Thank you for your response. I did do this size 10 to prove that this worked but only copied in 10 characters and not n+1. I will up it to 32 which is the size that I am thinking for the maximum. Do I add the terminating null character at the end after copying in the string characters?

if you do a strcpy I think it will automatically copy the \0

With strncpy it depends if it fits (if there are 10 characters to copy in a 10 byte buffer, than the \0 will not fit), so you have to make it one bigger

strncpy() copies up to the maximum specified. If the number of characters, including trailing zero end of string character, is less than or equal to maximum then the end of string character will be copied as well. However if the string being copied is longer than the maximum specified then there will not be a zero character terminator. When sizing the string buffer you must specify the number of characters you want plus one to include the end of string character. char myS[MAX_COUNT + 1]; and then strncpy (myS, aString, MAX_COUNT); followed by myS[MAX_COUNT] = 0; ensures end of string.


text:
Problem in AT+CIPSEND(CTRL-Z) GPRS GMS A6
I am using GPRS GSM A6 with arduino uno to post data to web server. After sending AT commands to module I get OK response after every command,
AT+CIPMUX=0

OK
AT+CGATT=1

OK
AT+CSTT="internet","",""

OK
AT+CIICR

OK
AT+CIFSR

10.65.87.210

OK
AT+CIPSTART="TCP","xxx.xxx.xxx.xxx", 80

CONNECT OK

OK
AT+CIPSEND

> POST http://xxx.xxx.xxx.xxx/Code/ HTTP/1.1
Host: xxx.xxx.xxx.xxx
Content-Type: application/x-www-form-urlencoded
Content-Length: 18

Data=GPS Data Sent
AT+CIPCLOSE

>

To terminate AT+CIPSEND you have to send CTRL-Z. I am sending CTRL-Z using this statement in code,
Serial.write(0x1A)

But the module doesnot respond to this, and treats the next command (AT+CIPCLOSE) as data.
Please Help... Thanks in Advance!!!

Also just so you know x-www-form-urlencoded requires + instead of spaces and any non-alphanumeric characters must be percent encoded https://en.wikipedia.org/wiki/Percent-encoding

RTFM: https://github.com/espressif/esp8266_at/wiki/CIPSEND
You need to close the input steam with "+++" to return to command mode.

To terminate AT + CIPSEND just apply the next command:
Serial.write(26);

or
gsm.write(26);

where gsm is the UART channel of gsm module.

You can use AT+CIPSEND= instead of AT+CIPSEND