text:
How can I set up outputs without using digitalWrite?
Consider the following:
#define IN1 9
#define IN2 10

pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);

void LeftMotor(Direction direction) {
  digitalWrite(IN1, direction == Forward ? LOW : HIGH);
  digitalWrite(IN2, direction == Forward ? HIGH : LOW);
}

How can I modify the LeftMotor method to achieve the same result without using digitalWrite?

Nope! I want it to react faster.

https://www.arduino.cc/en/Reference/PortManipulation

This will not make it react faster. Add more of your sketch if you want help with that. Cheers!

@MikaelPatel: according to the link i posted above, it will be faster, because it's "able to turn pins on and off very quickly, meaning within fractions of a microsecond ... . Direct port access can do the same job in a lot fewer clock cycles." (than digitalWrite). Now for an hbridge, it's not going to make a hill of beans diff, but the OP's question is legit.

Why do you think that digitalWrite isn't fast enough for your application? Direct port manipulation will be significantly faster than using digitalWrite, but for most things (like controlling a motor) digitalWrite is plenty fast enough. Port manipulation is harder to set up, harder to understand, and is not portable across devices (the port assignments are different for different Arduino models.)

@DuncanC digitalWrite is slow. Teach the kid how to set the ports directly. Your advice is horrible. Setting the registers isn’t hard.

@PhillyNJ, if the use case demands fast code, sure. If not, I'd say stick with digitalWrite(). Premature optimization is the root of all evil, after all.

I've written commercial software in assembler, back when that's what you had to do to get reasonable performance. I wouldn't recommend it today, however, for the same reason I wouldn't recommend direct port manipulation unless you really need that level of performance. I wrote an Arduino app for high speed photography of shooting things with air rifles, and for that I used direct port manipulation.

what is unclear in the arduino tutorial about direct port manipulation?

@DuncanC - The OP wasnt asking when he/she should use digitalWrite vs setting the registers directly, they were asking how to set the ports directly. A perfectly valid question.

@PhillyNJ: I think I see Duncan C's point. If the OP finds his program is not fast enough, it is most likely not because of digitalWrite(). Especially if a motor is involved, which is thousands of times slower than digitalWrite(). We can then either directly answer the OP's question (which you did) or try to help him understand his actual problem (which Duncan tries to do).

@EdgarBonet - Thanks for your point of view. I fear that these types of comments hurt the community. In this case, we aren't total sure of what the limitations of the motor is. The bottle neck could be the motor or his/her code. The OP will find out soon enough if they try both ways. Its a good learning moment. I find digitalWrite to be very slow, exceptionally when writing to something like a TFT that expects lots of data. Teaching this OP whats under the hood of the Arduino Library is always good. Lets not discourage it.

I moved to this community after checking answers on the arduino forum. I suppose you have been there also in the past. Actually the project involved is about decoding RF signals from a receiver (6 shannels, each 1 to 2 ms input) plus 4 pwm's for output, which is time critical. I am sorry that the method name is missleading, but i just tried to keep my question as simple as i could.

For motors, especially starting/stopping/inverting direction, as the rest of the code and comments suggest, digitalWrite is definitely fast enough.

Setting ports directly is a great way to learn AVR programming. I might recommend this book Make: Avr Programming.
First you need to set the direction of the port in the Data Direction Register as either input or output. If Input, check its state and handle it. Here is a small example.
#define HIGH 1
#define LOW 0

#define  SWI_PIN PORTB0
#define  BUTTON PORTB4

int main (void)
{
    // set the pin directions
    DDRB |=  (1 << SWI_PIN); // output
    DDRB &= ~(1<<PORTB4); //input
    while(true){

      if ((PINB & (1<<BUTTON)) == 0){ // pin is high! Rising edge
          PORTB &= ~(1<<SWI_PIN); // LOW turn off swi_pin
      }else {
          PORTB |= (1<<SWI_PIN); // HIGH  turn on swi_pin
      }

}

Not all Arduino pins are on port B. There are macros to make your solution a bit more universal and as fast as yours.

@DataFiddler no of course not. This is an example not a full lesson on setting ports.

digitalWrite() is just a convenience function to hide away complexity from the user, so that she/he can just use a pin number and a value. This complexity takes some time to execute. If this is too slow for you, you need to go a bit deeper into the rabbit hole and use direct port manipulation:
Inside the microcontroller on the Arduino all the special functions for peripherals and such (digital IO, ADC, Serial(UART), SPI, Timer, ...) are configured via Special Function Registers (SFR). These are specific memory places, that are directly connected to the peripherals. You can configure the whole microcontroller by setting these registers to specific values.
For digital IO you first need to know, that the microcontrollers pins are ordered into groups of max 8 pins. These groups are called Ports. Each available port of the microcontroller gets a character, like PORTB. On the Arduino Nano for example PORTD includes the pins 0 to 7.
For each port we have 3 different SFRs (with the x being the character for the corresponding port), where each bit inside the registers corresponds to one pin:

DDRx controls the direction of the pins. If you set a bit to 1 in there, the corresponding pin is set as output. If you set it to zero, the pin will be an input (which is also called High-Z for high impedance, because a digital input pin has a very high resistance).
PORTx controls the output hardware of the digital pins. If you have set a pin as output (as described above) you can use the corresponding bit in the PORTx register to set it's state. If you write a 1 to the bit, the pin will become HIGH (means, the voltage on the pin will go to the same level as Vcc, the supply voltage of the micrcontroller). If you write a zero, the pin will go to LOW (meaning the same level as ground). The PORTx register has a different function, when you configured a pin as input. In this case, a 1 will turn on the interal pullup resistor of the pin, which pulls the level of the pin to HIGH, when nothing is pulling it down to ground (like a switch for example). A zero disables the pullup.
PINx reflects the current state of the pins. If you configured the pins as input, this is the voltage level, that currently lies at the corresponding pin (about the actual voltage levels, see below). A 1 at a bit means, that the corresponding pin is HIGH, else it is LOW.

You can read all of this in the datasheet of the used microcontroller. The datasheet is a must read (at least the relevant chapters), if you want to control the microcontroller via its registers. In most microcontrollers these registers are named as above. But some microcontrollers might define other names. The corresponding datasheet will list all the registers with rather detailed descriptions.
Now let's take that knowledge into actual code. Here I assume an Arduino Nano, though you can exchange that for most other microcontrollers.
// Configure pin D3 as output
DDRD |= (1 << PD3);
// Configure pin D2 as input
DDRD &= ~(1 << PD2);
// Check, if pin D2 is HIGH
if(PIND & (1 << PD2)){
    // Set pin D3 to HIGH
    PORTD |= (1 << PD3);
} else {
    // Set pin D3 to LOW
    PORTD &= ~(1 << PD3);
}

Excourse on bitwise operators: The code above can only be understood by knowing bitwise operators, which are very important for direct port manipulations. I will break down the operations, that are done there:

First we have PD2 and PD3. These are defines from the Arduino core. They are set to the index of the bit, that corresponds to the named pin. So PD2 is defined as 2, PD3 is defined as 3, PD0 as 0.
1 << PD3: The << operator does a bitwise left shift, which means all bits of the value on the left are shifted to the left by the amount standing on the right of the operator. We shift the value 1 three digits to the left here. In binary that looks like this:
0b00000001 << 3 = 0b00001000

That set bit in the result is exactly at the place, where the bits for pin PD3 will be in the Special Function Registers.
DDRD |= (1 << PD3):  This is the same as doing DDRD = DDRD | (1 << PD3), so the |= operator is just an abbreviation for it. The bitwise OR operator | will unite the bits from both sides. If a bit is set to 1 at either side, the result will also have set this bit to 1. This means, that we can set a bit to 1 with this.
~(1 << PD2): The tilde ~ takes the inversion of the data. Alike above, the value inside the paranthesis can be written as binary value 0b00000100. The inversion will flip all bits to the other value: 0b11111011
DDRD &= ~(1 << PD2): The abbreviation is similar to the above. The bitwise AND operator & will also unite the bits of the values around it, but it will only set the resulting bits to 1, if both of the corresponding bits of the values are also set. Here this results in the third bit (the one for D2) being cleared to zero. All other bits (where you can see a 1 at the right value) are left untouched.
PIND & (1 << PD2): This is similar to the above, but now we don't have an inversion. We are doing PIND & 0b00000100 here. All bits of the result will be set to zero, except for the bit for D2. It will only be zero, if the corresponding bit was zero in PIND. Thus we have isolated the needed bit by this way.

You can also combine the same operations on a single register. Let's say we want to set both D2 and D3 as output. Then we can either write this as two seperate statements
DDRD |= (1 << PD2);
DDRD |= (1 << PD3);

or we can combine them into one statement by connecting them with the bitwise OR
DDRD |= (1 << PD2) | (1 << PD3);

The Arduino documentation also provides a site to explain direct port manipulation. Also again you should take the time to look into the datasheet of your used microcontroller. At first it will seems very difficult, but doing these direct port manipulations is a great way of learning how to use the SFRs, and then you can do all sorts of cool stuff with your microcontroller. So it really is worth it. You don't need to read or understand the whole datasheet at once.

How can I modify the LeftMotor method to achieve the same result without using digitalWrite?

After all this text now to the specific question. On the Nano pin 9 and 10 are PB1 and PB2. You used a conditional inside your digitalWrite() statement, which I will replace by a complete if statement here. So you can use
if(direction == Forward){
    PORTB &= ~(1 << PB1);
    PORTB |= (1 << PB2);
} else {
    PORTB |= (1 << PB1);
    PORTB &= ~(1 << PB2);
}

instead of your two digitalWrite() statements.

I don't know why this question is downvoted. As for 'canonical' answer it is better than the other.Maybe someone has a problem with reading...

chrisl provided a very good reference answer. Here I am just adding a
few bits of information about the pin mapping and the pin electrical
states.
Pin mapping
One of the firs things you need when dealing with direct port access is
the mapping between the Arduino pin names and the names of the
microcontroller (MCU) pins as given by the manufacturer. For the Arduino
Nano the mapping is the following:
 Arduino │ MCU
─────────┼─────
   RX0   │ PD0
   TX1   │ PD1
   D2    │ PD2
        ...
   D7    │ PD7
   D8    │ PB0
        ...
   D13   │ PB5
   A0    │ PC0
        ...
   A5    │ PC5

where “PD0” means “pin number 0 of port D” and so on. Notice that pins
A6 and A7 are not listed here, as they are analog only, with no digital
I/O capability.
The information above can be found on the product page of the board,
under the “Documentation” tab. Alternatively, an image search for
“Arduino <board name> pinout” will find some nice schematics like
the one below:

Pin states
This has already been covered by chrisl's answer in the description of
the DDRx and PORTx registers. Below is a summary table showing the
four available electrical states of the pins, and how they are selected
with the DDR and PORT bits:
 DDR │ PORT │ electrical state │ equation
─────┼──────┼──────────────────┼─────────────────
  0  │   0  │  INPUT (high-Z)  │ I = 0
  0  │   1  │  INPUT_PULLUP    │ V = Vcc − Rpu I
  1  │   0  │  OUTPUT LOW      │ V = 0
  1  │   1  │  OUTPUT HIGH     │ V = Vcc

The provided equations relate the output voltage (V) and the output
current (I) of the pin. Beware that these are just rough approximations,
as:

they neglect the output resistance, which is of the order of
25 Ω
an input pin can have some (sub-µA) leakage current
the pullup resistor is not completely linear
the datasheet only provides weak guaranties, such as a range for the
output voltage, conditioned on the output current being low enough.

How can I set up outputs without using digitalWrite?

So this question is actually about the fastest possible implementation of digitalWrite.
As described in other answers this can be achieved by using direct port manipulation. But there are actually libraries (for instance, https://github.com/mikaelpatel/Arduino-GPIO) that does this in a portable way and avoids some of the errors that can occur. The library is 10-100X faster than the Arduino core digital pin functions.
Pins in a MCU are organized in ports. On the AVR there are a set of 8-bit port registers that hold the current pin setting. To change the value of a pin the CPU has to read the register and change the corresponding bit associated with the pin. This has to be done as an atomic operation, i.e. an interrupt may not occur during the update of the port register.
To allow a very fast update, i.e. one instruction/1-2 clock cycle, the CPU has a set of special instructions. For the AVR there are bit set and clear instructions for the 32 first special registers. On the Arduino Mega some of the pins/ports have higher address special registers and cannot use the special instructions. To make the pin operation atomic explicit interrupt handling must be added.
Other issues with direct port manipulation is portability. Code written using the AVR io handling cannot be used on SAM (e.g. Arduino Due). There is actually even issues when changing between AVR MCUs.
In short, a portable faster implementation of digital pin functions is recommended.
Below is the code written with the GPIO. It is portable and as fast as direct port manipulation.
#include "GPIO.h"

GPIO<BOARD::D9> IN1;
GPIO<BOARD::D10> IN2;

IN1.output();
IN2.output();

void LeftMotor(Direction direction) {
  IN1 = (direction == Forward ? LOW : HIGH);
  IN2 = (direction == Forward ? HIGH : LOW);
}

or
void LeftMotor(Direction direction) {
  IN1 = direction != Forward;
  IN2 = direction == Forward;
}

or
void LeftMotor(Direction direction) {
  if (direction == Forward) {
    IN1.low();
    IN2.high();
  }
  else {
    IN1.high();
    IN2.low();
  }
}


text:
Why ESP8266 slower than Arduino nano?
I'm using the same script(and standard wire and serial library only) one uploaded to Arduino nano one uploaded to ESP8266. However, despite ESP8266 running at 160MHz, 10 times faster than nano, it's taking 3.5 ms to complete the loop, compare to 2.5 ms than that of nano.
How could that be?  why ESP8266 was slower?

It depends on what the script is doing. In practice the ESP8266 will almost always be faster. An exception might be I2C (the Wire library, like in your test). The Arduino Nano AVR processor has hardware support for I2C; the ESP8266 must use the much slower “bit banging” method.

@StarCat will the same thing (wire) happen to esp32?

It depends. Please show us the code.

@ShoutOutAndCalculate, The ESP32 has hardware support for I2C so should be able to run faster.

@StarCat Thanks! So I won't need to do the pull up resistor on ESP 32 like that of ESP 8266 right?

You can use internal pull ups, but the consensus seems to be that they are too weak for fast I2C operation and that external pullups are better (around 4.7K Ohm).

However, despite ESP8266 running at 160MHz, 10 times faster than nano, it's taking 3.5 ms to complete the loop, compare to 2.5 ms than that of nano.

There's a number of reasons for that. Chiefly:

The ESP8266 has no I2C hardware, so has to use software "bit-banging" to emulate I2C. That is slower to execute.
The ESP8266 also has to manage the WiFi hardware which takes a portion of the processing power away from the user

The result is slower execution for I2C operations and "jitter" added to timings of loops and such.

will the same thing (wire) happen to esp32?

No (or not as much). The ESP32 has hardware I2C so it doesn't need to use bit-banging to emulate it, so it will be faster. Also it is dual core and one core is used for "system management" including managing the WiFi and Bluetooth, while the second core is used to execute your sketch, so there is no (or little1) interruption by the WiFi slowing down your sketch.

1: Two cores accessing the same area of RAM causes some contention as only one core can access the same block of RAM at a time, so it's not perfect. You may still get slight delays, but they will be minuscule compared to the processing needed for the ESP8266's WiFi code.

source: Stack Exchange

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

sort: votes


text:
Connecting Arduino Uno to Arduino Leonardo
I have an RFID shield connected to my Arduino Uno, but I want it to be able to send keystrokes to the computer when I scan the correct card. I have the Uno set up correctly so that when the card is scanned and verified it would send a 1 to the Leonardo. But when I have tried to receive the data using I2C, Leonardo doesn't get it. What could I try next?
This is the master code or the code that is sending the information. (On the Arduino Uno)
// Include the required Wire library for I2C
#include
int x = 0;
void setup() {
  // Start the I2C Bus as Master
  Wire.begin();
}
void loop() {
  Wire.beginTransmission(9); // transmit to device #9
  Wire.write(x);              // sends x
  Wire.endTransmission();    // stop transmitting
  x++; // Increment x
  if (x > 5) x = 0; // `reset x once it gets 6
  delay(500);
}

and this is the slave code (on the Leonardo)
// Include the required Wire library for I2C
#include <Wire.h>
int LED = 13;
int x = 0;
void setup() {
  // Define the LED pin as Output
  pinMode (LED, OUTPUT);
  // Start the I2C Bus as Slave on address 9
  Wire.begin(9);
  // Attach a function to trigger when something is received.
  Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
  x = Wire.read();    // read one character from the I2C
}
void loop() {
  //If value received is 0 blink LED for 200 ms
  if (x == '0') {
    digitalWrite(LED, HIGH);
    delay(200);
    digitalWrite(LED, LOW);
    delay(200);
  }
  //If value received is 3 blink LED for 400 ms
  if (x == '3') {
    digitalWrite(LED, HIGH);
    delay(400);
    digitalWrite(LED, LOW);
    delay(400);
  }
}

x in slave code needs to be defined volatile, since the callback gets called from an ISR. Have you tried with the I2C scan example, if the Uno actually finds the Leonardo? Also you could print the return value of Wire.endTransmission(). A successfull transmission is marked by a return value of zero. If not successfull, the return value is an error code. Please check the error code, it might show the problem. Have you pullup resistors on both I2C lines?

@chrisl I will try the Wire.endTransmisson(). But how do I define x as volatile?

With the keyword volatile. You can google how to use it. When you can confirm, that it solved your problem, I will write an answer, explaining that.

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


text:
How to calculate the RZERO value in MQ135 sensor, I have already burned it for 24 hours?

I've already burned it for 24 hours and it is now giving the constant value of 932.36,pls tell me how to calculate the RZERO value.

your question is not about the Arduino ... it is about calibrating a sensor ... try to find a website that deals with chemistry

From the datasheet here --->MQ135 datasheet, It is the value of Sensing resistor at 100 PPM of Ammonia(NH3) or from the graph in Fig. 3, you can use gases that has y intercept as 1 and appropriate concentration, i.e you need atleast some known parameter to get it. The legend in the graph is also not clear (as far as getting the values from the Log - Log graph, there are tutorials in youtube).
I'm also in need of solution to this, so far this is what I read on the internet... You need a chemistry lab to do it !!!


text:
loop() either stops working, or lcd stops working | buttons don't work
I'm using a Let's Start Coding Ultimate Kit 1 (it was a christmas present, don't ask) and I'm trying to use this as a typing sort of thing. I haven't implemented the actual letters though.
#include <MakerScreenXVI.h>;

MakerScreenXVI lcd;

int currentNumber = 1;
int ms = 0;
int totalMS = 0;
bool first = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(A0, INPUT);
  pinMode(A3, INPUT);

  lcd.begin();
  lcd.print("Success");
  lcd.setCursor(0,1);
  lcd.print(currentNumber);

}

void loop() {
  delay(200);
  changeNumber();
  delay(200);
}

void clearLCDLine(int line) {
        lcd.setCursor(0,line);
        for(int n = 0; n < 16; n++) // 20 indicates symbols in line. For 2x16 LCD write - 16
        {
                lcd.print(" ");
        }
}

void changeNumber() {
  if (digitalRead(A0) == LOW) {
    if (first == false) {
      clearLCDLine(1);
      first = true;
    } else {
      first = false;
    }
    currentNumber++;
    if (currentNumber == 27) {currentNumber = 1;}

    lcd.print(currentNumber);
  } else if (digitalRead(A3) == LOW) {
    currentNumber = currentNumber - 1;
    if (currentNumber == 0) {currentNumber = 26;}
    //clearLCDLine(1);
    lcd.print(currentNumber);
  }
}

For some reason, after it deletes the 1, it stops. Nothing is printed onto the screen, and nothing is cleared from it. How can I fix this?
Also, the buttons always return the LOW value. How can I fix this?

I don't know the LSCU-Kit, but are there any pull-up resistors at the inputs? If not, can you set the pins with internal pull-ups and try that?

The buttons will send a LOW signal when pressed if they are set with pinMode INPUT_PULLUP.
The issue with currentNumber not displaying is that after you clear the screen with the 'for' loop, you need to reset the cursor to position 0,1 with lcd.setCursor(0,1); . Otherwise, the numbers are printing out of view.
If I add lcd.setCursor(0,1); just above each line with lcd.print(currentNumber); , I think the code has the behavior you're looking for.
Edit from the person who asked the question:
 You also have to add a delay of around 150-200, or else one push will count as many.

For some reason, I did something (I think with the button and the sockets on the board) and both buttons go down into negatives. I followed your instructions. Before that, you would have to press the down button first (A3) for the other button to work, and then it would show the single digit numbers and a zero. How can I fix this?

If I understand correctly, you've made some changes to the code, so it's hard to provide direct advice without seeing it. The code you posted above provides "bounds" for the currentNumber variable with the "if" statements. I recommend sending us an email at info@letsstartcoding.com with the code and we may be able to help.


text:
How to find the peak value of analog signal?
I have a question .. Please help me I don't know how Arduino can read the peak value of the sensor signal. The value I want is in the ADC value .. What I want is ... for 5 seconds there will be 1 average value from the highest peak value of the sensor, and the ADC value. I will use pin A0, but I don't know how to code the program that I want. Please help me What is the code?

See if I understand this correctly: For a given time period you want to find the peak.
void setup()
{
  unsigned long int cur_time = 0 ;
  unsigned long int time_elapsed = 0;
  int peaks[20]; // say you want to find 20 peaks , 1 peak for data arriving between 5 secs
  int time_period = 5000;
  int data = 0;
  int mx=0;
}

void loop()
{
   for(int i = 0 ; i<20;i++)
   {
      cur_time = millis();
      while(cur_time - time_elapsed <=time_period)
      {
             if(mx==0)
              { mx = analogRead(A0); }
              else:
               {  data = analogread(A0);
                  mx = max(data , mx);
               }
              cur_time = millis();
        }
         time_elapsed = cur_time;
         peaks[i] = mx;
         mx = 0;
        }
  }

Hope this helps!!


text:
Why doesn't pin 19 work when powering the EzSBC Esp32 board from batteries?
I recently got an ESP32-01 Breakout and Development Board from EzSBC.com.  It is advertised as a board specifically designed for use with batteries because of it's low current draw when in sleep.
As a test I loaded the basic Arduino blink sketch onto the board using pin 19 as the built in test LED.  When I power the board from the computer through the USB connection the LED blinks as expected, but when I connect a battery accross VIN -> GND nothing happens.
What am I doing wrong?

There is a subtle design choice in this board that took be hours to figure out.
According the connection schematic the blue leg of the LS3528RGB LED is connected to IO19 through a 1k resister (R2-1).  However the power leg is connected to Vusb not 3.3V like the other RGB LED.  This means that the LED connected to IO19 is only usable when the board is connected through the micro-USB port and not when connected directly to battery.
This can be useful for programmatically reading whether the board is running on battery or USB.

so the pin works? only the on-board LED is not powered?

This can be useful for programmatically reading whether the board is running on battery or USB. -- also good for saving power when on batteries.

Juraj, that is correct.  When the USB is plugged in the pin will be pulled high by a 1k resister.  When on battery, it will be an open circuit.


text:
Compile error with Arduino tensorflow lite library
I was reading the article about tensorflow lite on SAMD51 here and tried it and failed to compile.
It was the example from the arduino tensorflow lite lirabry and doesnt seem to compile.
Selected Adafruit M4 boards and failed to compile, but can compile with ArduinoMKRZERO(SAMD21).
Here follows the error message:
Arduino: 1.8.12 (Mac OS X), Board: "Adafruit Grand Central M4 (SAMD51), Enabled, 120 MHz (standard), Small (-Os) (standard), 50 MHz (standard), Arduino, Off"

    In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                     from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:58:5: error: unknown type name 'int16_t'
         kiss_fft_scalar r;
         ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:59:5: error: unknown type name 'int16_t'
         kiss_fft_scalar i;
         ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c: In function 'kf_bfly2':
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: error: 'int16_t' undeclared (first use in this function)
     #  define kiss_fft_scalar int16_t
                               ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
     #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
      (x) = sround( smul(  x, SAMP_MAX/k ) )
            ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
      do {    DIVSCALAR( (c).r , div);  \
              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:33:9: note: in expansion of macro 'C_FIXDIV'
             C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2);
             ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: note: each undeclared identifier is reported only once for each function it appears in
     #  define kiss_fft_scalar int16_t
                               ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
     #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
      (x) = sround( smul(  x, SAMP_MAX/k ) )
            ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
      do {    DIVSCALAR( (c).r , div);  \
              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:33:9: note: in expansion of macro 'C_FIXDIV'
             C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2);
             ^
    In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:0:
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:51:19: error: 'int32_t' undeclared (first use in this function)
     # define SAMPPROD int32_t
                       ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:47: note: in definition of macro 'sround'
     #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                                   ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:64:25: note: in expansion of macro 'SAMPPROD'
     #   define smul(a,b) ( (SAMPPROD)(a)*(b) )
                             ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:16: note: in expansion of macro 'smul'
      (x) = sround( smul(  x, SAMP_MAX/k ) )
                    ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
      do {    DIVSCALAR( (c).r , div);  \
              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:33:9: note: in expansion of macro 'C_FIXDIV'
             C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2);
             ^
    In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                     from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c: In function 'kf_bfly4':
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: error: 'int16_t' undeclared (first use in this function)
     #  define kiss_fft_scalar int16_t
                               ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
     #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
      (x) = sround( smul(  x, SAMP_MAX/k ) )
            ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
      do {    DIVSCALAR( (c).r , div);  \
              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:61:9: note: in expansion of macro 'C_FIXDIV'
             C_FIXDIV(*Fout,4); C_FIXDIV(Fout[m],4); C_FIXDIV(Fout[m2],4); C_FIXDIV(Fout[m3],4);
             ^
    In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:0:
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:51:19: error: 'int32_t' undeclared (first use in this function)
     # define SAMPPROD int32_t
                       ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:47: note: in definition of macro 'sround'
     #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                                   ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:64:25: note: in expansion of macro 'SAMPPROD'
     #   define smul(a,b) ( (SAMPPROD)(a)*(b) )
                             ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:16: note: in expansion of macro 'smul'
      (x) = sround( smul(  x, SAMP_MAX/k ) )
                    ^
    Multiple libraries were found for "Adafruit_ZeroDMA.h"
     Used: /Users/ansonhe/Library/Arduino15/packages/adafruit/hardware/samd/1.5.4/libraries/Adafruit_ZeroDMA
     Not used: /Users/ansonhe/Documents/Arduino/libraries/Adafruit_Zero_DMA_Library
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
      do {    DIVSCALAR( (c).r , div);  \
              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:61:9: note: in expansion of macro 'C_FIXDIV'
             C_FIXDIV(*Fout,4); C_FIXDIV(Fout[m],4); C_FIXDIV(Fout[m2],4); C_FIXDIV(Fout[m3],4);
             ^
    In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                     from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c: In function 'kf_bfly3':
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: error: 'int16_t' undeclared (first use in this function)
     #  define kiss_fft_scalar int16_t
                               ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
     #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
      (x) = sround( smul(  x, SAMP_MAX/k ) )
            ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
      do {    DIVSCALAR( (c).r , div);  \
              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:109:10: note: in expansion of macro 'C_FIXDIV'
              C_FIXDIV(*Fout,3); C_FIXDIV(Fout[m],3); C_FIXDIV(Fout[m2],3);
              ^
    In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:0:
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:51:19: error: 'int32_t' undeclared (first use in this function)
     # define SAMPPROD int32_t
                       ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:47: note: in definition of macro 'sround'
     #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                                   ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:64:25: note: in expansion of macro 'SAMPPROD'
     #   define smul(a,b) ( (SAMPPROD)(a)*(b) )
                             ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:16: note: in expansion of macro 'smul'
      (x) = sround( smul(  x, SAMP_MAX/k ) )
                    ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
      do {    DIVSCALAR( (c).r , div);  \
              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:109:10: note: in expansion of macro 'C_FIXDIV'
              C_FIXDIV(*Fout,3); C_FIXDIV(Fout[m],3); C_FIXDIV(Fout[m2],3);
              ^
    In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                     from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c: In function 'kf_bfly5':
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: error: 'int16_t' undeclared (first use in this function)
     #  define kiss_fft_scalar int16_t
                               ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
     #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
      (x) = sround( smul(  x, SAMP_MAX/k ) )
            ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
      do {    DIVSCALAR( (c).r , div);  \
              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:160:9: note: in expansion of macro 'C_FIXDIV'
             C_FIXDIV( *Fout0,5); C_FIXDIV( *Fout1,5); C_FIXDIV( *Fout2,5); C_FIXDIV( *Fout3,5); C_FIXDIV( *Fout4,5);
             ^
    In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:0:
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:51:19: error: 'int32_t' undeclared (first use in this function)
     # define SAMPPROD int32_t
                       ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:47: note: in definition of macro 'sround'
     #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                                   ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:64:25: note: in expansion of macro 'SAMPPROD'
     #   define smul(a,b) ( (SAMPPROD)(a)*(b) )
                             ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:16: note: in expansion of macro 'smul'
      (x) = sround( smul(  x, SAMP_MAX/k ) )
                    ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
      do {    DIVSCALAR( (c).r , div);  \
              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:160:9: note: in expansion of macro 'C_FIXDIV'
             C_FIXDIV( *Fout0,5); C_FIXDIV( *Fout1,5); C_FIXDIV( *Fout2,5); C_FIXDIV( *Fout3,5); C_FIXDIV( *Fout4,5);
             ^
    In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                     from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c: In function 'kf_bfly_generic':
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: error: 'int16_t' undeclared (first use in this function)
     #  define kiss_fft_scalar int16_t
                               ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
     #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
      (x) = sround( smul(  x, SAMP_MAX/k ) )
            ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
      do {    DIVSCALAR( (c).r , div);  \
              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:217:13: note: in expansion of macro 'C_FIXDIV'
                 C_FIXDIV(scratch[q1],p);
                 ^
    In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:0:
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:51:19: error: 'int32_t' undeclared (first use in this function)
     # define SAMPPROD int32_t
                       ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:47: note: in definition of macro 'sround'
     #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                                   ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:64:25: note: in expansion of macro 'SAMPPROD'
     #   define smul(a,b) ( (SAMPPROD)(a)*(b) )
                             ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:16: note: in expansion of macro 'smul'
      (x) = sround( smul(  x, SAMP_MAX/k ) )
                    ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
      do {    DIVSCALAR( (c).r , div);  \
              ^
    /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:217:13: note: in expansion of macro 'C_FIXDIV'
                 C_FIXDIV(scratch[q1],p);
                 ^
    exit status 1
    Error compiling for board Adafruit Grand Central M4 (SAMD51).

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

Please let me know if anyone has any ideas, much appreciated.


text:
How to send sms message on specific area using Longitude and Latitude
Good day everyone! what code should i used for sending sms message depends on the area. the things that i used in my protoype i have MPU6050 accelometer, SIM800C GSM MODULE, NEO6MV2 GPS MODULE. So the flow is if the Accelometer triggred the GSM module will get the GPS location only if the area is on the target location 1 so it will only send to the recepient 1. But if its triggred in another location, Targetlocation2 it will only send on receipient 2.
My question is how to used the longitude and latitude data to get the exact data of what my gps module gets? so that i can use that data to send sms message on specific place or area thank a lot
also i used TINYGPS.H LIBRARY thank you!

You get location information from GPS, and you have some target locations stored. You check, which of the targets is closest and send an SMS to the corresponding phone. And what exactly is your problem in detail?  If you ask "How to do it?" rather show what you tried and why you are not satisfied with the result. And split the task into a couple of smaller ones :)

why are you asking again? ... https://arduino.stackexchange.com/questions/72626/how-to-send-sms-message-depends-on-the-gps-locatiom

Thank you DataFiddler i'm just asking for a format code use to set longitude and latitude, Is it float distance_between (float Lat1, float Lon1, float Lat2, float Lon2)? and how to set this for if statement? to send the sms if my location area is on the target Lat1 Lon1 thank you

sorry jsotola im just despirate sorry for my bad  english


text:
Reading 4-20ma signal on arduino
I want to read a 4-20 mA analog signal from a 24V flowmeter. I've read the simplest way is to convert it into 1-5V signal using a 250 ohm resistor. The thing is I want my reading to be precise so my question is; is there any resolution loss when converting it to 1-5V?
I've also looked up on current to voltage converting boards similar to this one: https://www.sparkfun.com/products/14544
but I don't think they can detect 4mA signal.
I am a beginner in this so need some guidance here.

"resolution loss" compared to what?

compared to current. basically if it has enough sensitivity (to differentiate between 5mV and 15mV). 1023 (10 bit) divisions are spaced out in 4-20mA as compared to 1-5V.

10-bit divisions are only spaced between 4 and 20mA if you can somehow subtract 4mA from everything and then arrange it to work from 0-16mA. Subtracting current is hard.

Using a resistor is the "Normal" way, yes. 250Ω will give you 1-5V, yes, which means that you get 4/5 of the actual resolution of the ADC at your disposal.
That means instead of 0-1023 you're actually reading 204-1023, or 819 possible values. Spread over 16ma (or 4V, which are the same thing) that gives you about 20µA resolution.
If you really really care about that extra 1/5 of the resolution you can instead use a 300Ω resistor to give you 1.2 to 6V, then pass that through a subtracting amplifier (see this post) and subtract 1.1V from it (you need to create that 1.1V, of course).  That will give you 0.1 to 4.9V, which then covers more of the ADC's available range (20-1002, or about 16µA resolution).
Is it worth it? Probably not. Any increase in resolution will likely be swamped by the inaccuracy of the resistor and potential drift though self heating.

self-heating and resistor in-accuracy will also prevail with a 250 ohm resistor. how is that different?

@SumitMann it's not. My point is that you will be getting a tiny bit more accuracy or of a system that is inherently inaccurate.

if this is an inaccurate way, can you suggest me another way to read that analog sensor? Thanks.

https://www.maximintegrated.com/en/design/technical-documents/app-notes/8/823.html

How accurate is the flow meter?  No matter how precise or accurate you make the current to voltage conversion, or how well you utilize the Arduino native A/D resolution, you can't do any better than the flow meter's accuracy/precision?  If the flow meter is only providing +/- 10%, then I wouldn't worry too much about errors introduced by using a +/- 5% 250-ohm resistor.


text:
Does Keyboard.begin() and Keyboard.end() make my code slower?
I'm making an IR Macro keyboard, and about 10% of the code is dedicated to the Keyboard commands, would having Keyboard.begin() and Keyboard.end() in the method responsible for typing make any difference to the speed or size?
My code:
void decodeCode(){ // send the macros.
  int pos = 0;
  for(int i = 0; i<output.length(); i++){
    if(output.charAt(i) == '$' && i!=output.length()-1){ //the $ is a symbol for "$pecial" characters
      i++;
      specialDecodeChar(output.charAt(i));
    }
    else if(output.charAt(i) == '%'){
      Keyboard.releaseAll();
    }
    else{
      Keyboard.press(output.charAt(i));
    }
  }
  Keyboard.releaseAll();
}

I currently have Keyboard.begin() in setup().

All code makes a difference to speed and size. Nothing is free.

keyboard.begin() is probably a constructor and .end is likely the destuctor.  We don't know for sure because not all your code is here.  Usually a constructor is run once during the life of a program. And, well, for an embedded program, the destuctor is sometimes just overlooked.  So, the question to be answered: Why would you need to make calls to these functions over and over?

@st2000 Keyboard.begin() and keyboard.end() are not constructors or destructors. They are normal functions typically called from setup, or wherever else you want to start or stop keyboard functionality. However they happen to be empty functions.

Thanks for clearing that up @Majenko.

The Keyboard::begin() and Keyboard::end() functions,  if you actually look at the code are empty functions. They do nothing.
In theory the compiler should just optimise them out.


text:
How to use tinygps.h library to measure distance? using NEO6mv2
any reference site for the format code for tinygps.h to measure distance?
or any codes for tinygps.h for measuring distance i'm just a beginner in learning arduino thank you

Do you know Pythagoras's theorem?

You don't use the tinygps.h library to measure distance. You use the tinygps.h library to get coordinates. Over short distances those coordinates (longitude and latitude) can be equated to x,y coordinates on a plane (over greater distance - hundreds or thousands of miles - it gets a whole lot more complex).
Two sets of x,y coordinates form a line. A line is one side of a right-angled triangle (the hypotenuse).
Pythagoras (remember him from math class? That rubbish you thought you'd never need? Well, now you do...) says that the square of the hypotenuse is equal to the sum of the squares of the other two sides.
You know the other two sides - they're just the difference between the two x coordinates and the two y coordinates.
We're not going to write the code for you, and Google is probably better at finding websites with example code on than we are.

thanks man appreciate it :D
by the way can i use this format code?
float X = ((long2 - long1) * 24901 * cos(lat1)) / 360.0
float Y = ((lat2 - lat1) * 24860) / 360.0
float X2 = X * X;
float Y2 = Y * Y;
float Distance = sqrt(X2 + Y2);
also how to define to my arduino that i set Lon1 Lat1 is equal to my desired gps coordinates should i used long or const or float sorry for many question


text:
Wire multiple SW-420 Vibration sensors to a single pin
I am working on installing an alarm system using Konnected IO on a NodeMCU esp8266. I have multiple bay widows which will use 4 SW-420 vibration sensors. I would like to wire all 4 of the SW-420 vibration sensors to a single pin. When any of the 4 sensors detect vibration the pin will go to high. I attempted to simply wire the d-outs from all four together and all four sensors stoped working. I'm out of ideas on how to do this any help would be greatly appreciated. I believe sensors send out a low signal when no vibration is detected and high signal when vibration is detected. Link to sensors: https://www.amazon.com/XLX-Vibration-Normally-Sensitive-High-Efficient/dp/B07V8FJRN1/

Two ideas came to my mind, first is to connect each output to four digital pins and then do something like this:
if(digitalRead(pinOne) == HIGH || digitalRead(pinTwo) == HIGH || ...){
do something
}

Or you can use an opamp or comparator for that purpose:

simulate this circuit – Schematic created using CircuitLab
In above configuration if any of the sensors output is HIGH, op amp will drag it's output to the positive rail (~5V). otherwise output is LOW (~0 V).


text:
Does flashing ESP8266/ESP-01 firmware mean uploading a new 'sketch' and why different firmware?
Hi I am new to IOT and I am now in love with this. However I'm a little confused right now with the jargon. My question is similar to this. But I do have some extra questions though.

When using ESP as standalone microcontroller, and if I uploaded a sketch written on the Arduino IDE, does that count as 'Arduino firmware' other people are referring to?
On the Arduino IDE, uploading sketches onto the ESP8266 seems easy by just installing extra libraries from Board Manager and selecting the right board. Is this step equivalent of doing this but for different firmwares such as AT, NodeMCU and Micropython?
For the NodeMCU dev boards, is the default firmware on the module NodeMCU firmware? If I were to use the Arduino IDE to upload a sketch, does that mean I have overwritten the NodeMCU firmware with my custom 'Arduino firmware' sketch?
To the extent of my knowledge, when using NodeMCU firmware, I would need to code in LUA language using some sort of LUA IDE and if I flashed/uploaded micropython I would need to code in micropython using exclusively the Thonny IDE. And there is no way to code in micropy or LUA from the Arduino IDE.
Is the reason for using other firmware is because of how the code is compiled and the language used?

If someone could clear things up for me I would greatly appreciate it. Thanks!

the right term is "application". firmware is application. sketch is application. the rest of the question is off-topic

firmware can mean both host environments that run higher-level code like LUA, tasmota, and AT, or it can mean something custom like ardunio, sdk, etc.

When using ESP as standalone microcontroller, and if I uploaded a sketch written on the Arduino IDE, does that count as 'Arduino firmware' other people are referring to?

Yes. "Firmware" is application code running on the microcontroller.

On the Arduino IDE, uploading sketches onto the ESP8266 seems easy by just installing extra libraries from Board Manager and selecting the right board. Is this step equivalent of doing this but for different firmwares such as AT, NodeMCU and Micropython?

Yes. "Firmware" is application code running on the microcontroller.

For the NodeMCU dev boards, is the default firmware on the module NodeMCU firmware? If I were to use the Arduino IDE to upload a sketch, does that mean I have overwritten the NodeMCU firmware with my custom 'Arduino firmware' sketch?

Yes. "Firmware" is application code running on the microcontroller.

To the extent of my knowledge, when using NodeMCU firmware, I would need to code in LUA language using some sort of LUA IDE and if I flashed/uploaded micropython I would need to code in micropython using exclusively the Thonny IDE. And there is no way to code in micropy or LUA from the Arduino IDE.

No. The Arduino IDE is for coding in C++ with the Arduino API extensions.

Is the reason for using other firmware is because of how the code is compiled and the language used?

The firmware is just what runs on the chip. If that firmware provides its own programming language then you can use that to execute that programming language.
If you write your own firmware in the Arduino IDE then the chip runs that firmware. If you upload the AT firmware then the chip runs the AT firmware and you can control it with AT commands. If you upload the NodeMCU Lua firmware then the chip runs the NodeMCU Lua firmware and you control it using Lua commands and scripts.

my opinion about the term 'firmware' https://stackoverflow.com/questions/57333773/is-programming-arduino-means-adding-firmware/57455539#57455539

@Juraj Your opinion is wrong. Firmware is machine code that runs directly on the hardware and has no other requirements. Software is code (compiled or otherwise) which requires other code to already exist to function. Anything "bare metal programmed" is firmware. On a PC the OS is software, but the BIOS or EFI are firmware. Sketches are therefore firmware.


text:
Will a pull up resistor help the UART transmission accuracy on Arduino nano?
On A post from Arduino forum , someone mentioned that a pull up resistor over RX/TX pin could help the reliably of UART communication.
Is that really the case for nano and uno board?

Nope. Did you read the question and the answer on that post? This question was about connecting multiple TX to one RX with the UART (something that it was not designed to do). The UART actively drives the RX and TX pins both low and high and does not normally need pull ups (or pull downs for that matter). If you're planning to cross larger distances, you should look at RS232, RS422 or 485.

@StarCat But they said" Master will probably need 2.2K to 4.7K pullup resistor to bring the line high reliably/quickly."

Please read the question and the answer for that post. This was not about a simple TX->RX connection but a connection of multiple TX to one RX via a diode on every TX and a pull up on the RX. This is not the way that the UART is usually used and requires bus arbitration between multiple devices.

In my experience the BIGGEST gain in reliability came from using the hardware port instead of SoftwareSerial. MASSIVE gain...

@Wendall I'm having defects in hardware port, that's why I'm looking for better ways, I've already implemented twisted wire, and capacitors, so I'm wondering if pull up resistor will help for the fast response.

What type of defect? Fried at some time or not working the way you wish? Is it distance related? Baud rate? or ???

Is the interface RS232, 485, or ? You are not getting the data you expect. What is the layout of what you are doing?

Depending on the interface, capacitors will likely do bad things.

@Wendall Capacitors stabilize the power supply.

On power yes, but on comm lines is a bad thing... they will destroy frequency response.

Please show your circuit and elaborate on your problem.

No. That is not the case. Adding a pullup resistor on a normal UART will do nothing except maybe reduce your reliability.
You only want pullup resistors on something which is "open drain" (AKA "open collector") which has no way of raising the voltage of a signal line, only lowering it - such as I2C signals, or a shared open-drain, interrupt signal.


text:
Is it permissible to connect 3.3V powered devices to the 5V I2C bus?
I have several devices on the I2C bus:

RTC DS3231SN
TMP100 temperature sensor
EEPROM 24LC256

All devices are powered by 3.3V. The voltage on the I2C bus is 5V.
Question:
Is the voltage difference on the bus and device power normal?

It's better to use level translator. Or you can try to power pull-ups from 3.3V, it usually works, but 3.3V CMOS output interfacing 5V CMOS logic input isn't 100% compatible as some devices might need almost 3.5V to detect high level.

KIIV, Thank you for the help!

Are you using the bare chips, or do you have breakout board. If the latter, the problem might be with Arduino enabling the internal pull-up resistors inside the MCU. The breakouts already have pull-up resistors on them, so the Arduino board shouldn't do that (but does). Usually it doesn't matter, and help with people using bare chips, and forgetting to add pull-up resistors on the I2C lines. To disable them; see https://arduino.stackexchange.com/questions/13448/disabling-i2c-internal-pull-up-resistors . After that the I2C lines should read 3.3V instead of 5V.

There are 3.3V devices that have 5V-tolerant inputs; that may be the case for your devices, but I would not risk it. Use a level converter designed for I2C, such as https://www.adafruit.com/product/757. Or you can make your own; https://cdn-shop.adafruit.com/datasheets/an97055.pdf explains how such a level converter works. Use a BSS138 if you are comfortable with soldering SMT components; otherwise use a 2N7000.

JayEye,
Thanks for the answer!

For the DS3231 the maximum voltage if Vcc+0.3V. The TMP100 seems to allow up to 6V regardless of Vcc. The 24L256's maximum is Vcc+1.0V


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

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

Some more images to show how I mounted it:

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

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

Any other suggestion?

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

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

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

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

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

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

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

I have tried and it worked !!


text:
How to connect to MQTT broker with TLS?
I have ESP8266 which is connecting to MQTT broker and it is working ok using user+pass with following code:
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const char* ssid = "WIFINAME";
const char* password = "WIFI_PASS";

const char* mqtt_server = "SERVER_IP";
const char* mqttUser = "user";
const char* mqttPassword = "pass";

WiFiClient espClient;
PubSubClient client(espClient);
unsigned long lastMsg = 0;
#define MSG_BUFFER_SIZE (50)
char msg[MSG_BUFFER_SIZE];
int value = 0;

void setup_wifi() {

  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  randomSeed(micros());

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();

  // Switch on the LED if an 1 was received as first character
  if ((char)payload[0] == '1') {
    digitalWrite(BUILTIN_LED, LOW);   // Turn the LED on (Note that LOW is the voltage level
    // but actually the LED is on; this is because
    // it is active low on the ESP-01)
  } else {
    digitalWrite(BUILTIN_LED, HIGH);  // Turn the LED off by making the voltage HIGH
  }
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Create a random client ID
    String clientId = "ESP8266Client-";
    clientId += String(random(0xffff), HEX);
    if (client.connect(clientId.c_str(), mqttUser, mqttPassword)) {
      Serial.println("connected");
      client.subscribe("CoreElectronics/test");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

void setup() {
  pinMode(BUILTIN_LED, OUTPUT);
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}

void loop() {

  if (!client.connected()) {
    reconnect();
  }
  client.loop();
}

As this is insecure usage I have setup TLS on MQTT broker and I can connect over command line:
mosquitto_sub --cafile ca.crt -h server_ip  -t "#" -p 8883 -d --cert client.crt --key client.key

Problem is that I cannot find any working (for me) sample with using TLS connection on ESP8266 client.
I have tried generating self-signed certs by manually script and over LetsEncrypt.
Thank you

If PSK is acceptable, there are probably some tutorials over at adafruit.com or discussions in their forum.

You could make the following changes to your code by making use of WifiClientSecure (which is already part of the ESP8266 Wifi library).
The tricky part is finding out the SHA1 fingerprint for your own MQTT server and hard coding it into the *fingerprint PROGMEM = "..."  part (for example by examining the certificate via a PC browser and copying the SHA1 fingerprint).
Alternatively, you could set the connection to setInsecure. This means that the connection will be encrypted but it will accept any server certificate without checking.
...
const char* mqttPassword = "pass";

WiFiClientSecure espClient;     // <-- Change #1: Secure connection to MQTT Server
PubSubClient client(espClient);

// Change #2: Set the SHA1 fingerprint for the connection -->
static const char *fingerprint PROGMEM = "44 14 9A 3F C3 E9 F1 F3 84 1A B4 9F B6 4D 19 8A B2 92 31 D6";
...
...
void setup() {
    ...
    setup_wifi();

    espClient.setFingerprint(fingerprint);   // <-- Change #3: Set the SHA1 fingerprint
    // Alternative: espClient.setInsecure;

    client.setServer(mqtt_server, 8883);  // <-- Change #4: Set the port number to 8883
    client.setCallback(callback);
 ...

Good luck!

where I need to put ca.crt, client.crt and client.key?

You won't need them if you use the setFingerprint method. You only need the fingerprint.

I get error 'class PubSubClient' has no member named 'setFingerprint' and also for setInsecure. Which PubSubClient is latest and best for use?

solved. changed client.setFingerprint(fingerprint); -> espClient.setFingerprint(fingerprint);

My bad, I will fix it in the answer.

@StarCat Wouldn't this allow anyone who knows the (accessible) fingerprint to pretend to be the server?

Not really.The fingerprint is a cryptographic hash of the server’s public key. It’s computationally extremely hard to reconstruct a public key from the fingerprint (or a different public key that produces the same fingerprint, called a “collision”).

There is an example of client certificates here.
https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino
I believe the answer by @StarCat should be expanded to use the ca cert and client certs.  With MQTT, we don't want clients being faked either.


text:
Why does per-led current consumption diminishes when more leds are on?
I'm rather new to Arduino. I've been performing some current consumption measurements lately, with a INA219 current sensor, on the blue LEDs from a starter kit.
I plugged three LEDs, on pins 2, 3, and 4 of my Arduino UNO, and wrote a simple script:
digitalWrite(led1, 1);
delay(2000);
digitalWrite(led2, 1);
delay(2000);
digitalWrite(led3, 1);
delay(2000);
digitalWrite(led1, 0);
digitalWrite(led2, 0);
digitalWrite(led3, 0);

Which turns on the leds one by one, and finally turn them off at once.
I measured the current consumption of the first LED, and measured that:

When it's the only one on, LED 1 consumes ~23.5 mA
When the second one is on, LED 1 consumes ~21.7 mA
When the third one is on, LED 1 consumes ~20.2 mA

Could you please tell me why it behaves that way ? Is there any source I should read that would formalize that ?
Thank you

First of all, it's better to not exceed 20 mA per LED, so increase your resistor values.
Second, although 40 mA is the maximum rating for GPIOs, 20 mA is advised.
Note, there is also a maximum per port (in case you want to add more LEDs).
This both doesn't explain your problem though.

Ok, I will add some resistors in the future, I don't want to break anything. Thanks

You mean you don't use resistors now?   Please do immediately before you break your gpios and or leds

Oops. So now I did add some 220ohms resistors on each leds, and performed some new measurements on my LED1.
The difference of current consumed by my LED1 when more LEDs are on is way smaller now: 4.4mA alone, 4.3mA when LED2 is also on, and 4.2ma when LED3 is on. There's still a difference though

I see the problem already has been answered. If you do not use a resistor, the maximum current will flow through the leds. It seems you have a non ideal power source, if it would be (giving much high current), probably you would have broken some components. But with the formula of st2000 you can now calculate your resistor in such a way not to exceed 20 mA.

it's from resistances.  could be on the trace of your MCU or the socket, etc. these lower the voltage diff between gnd and HI, either by raising gnd or dropping vcc. perfectly normal. that's why do don't drive stuff directly from the MCU.

If using a constant voltage source it is advisable to use current limiting resistors in series with LEDs.
If these LEDs are different colors that may explain the different current readings.
Or, if all LEDs are of the same color and you are powering the project from a source with internal resistance (a battery), the more current you draw the lower the supply voltage.  This may show up as a reduced incremental current increase.
Or, if using a poor power source or operating at the current capacity of the power supply - again - this may show up as a reduced incremental current increase.
Note that different generations of LEDs operate at slightly different voltages.  But, in general, RED, GREEN & BLUE LEDs of the same generation operate at slightly increasing voltages respectively.  Details can be found here in this wikipedia.com page:

Typically, the forward voltage of an LED is between 1.8 and 3.3 volts.
  It varies by the color of the LED. A red LED typically drops 1.8
  volts, but since both voltage drop and light frequency increase with
  band gap, a blue LED may drop from 3 to 3.3 volts.

Use the LED current (Iled) and voltage (Vled) specifications to determine the proper resistor value for a given supply voltage (Vbatt).
The following equation from this article should prove useful for this calculation:

Hi, thanks a lot for your answer. I will thoroughly read those references.
My three blue LEDs are exactly the same, this is the corresponding tech spec:
https://www.arduino.cc/documents/datasheets/LED(blue).pdf
I tried with a different power supply (USB this time) and find similar current drop when more leds are turned on.

With out current limiting resistors you are operating outside of specifications.  This may include the processor operating outside of specifications.  This may also include any on board regulator operating outside of specifications.  So it becomes difficult to specify an exact cause for your observations.  Also note, a moderately stressed LED will likely only permanently dim.  So it may be difficult to tell if an LED has been operated outside of specifications.  It looks like these LEDs need a current limiting resistor of (5 - 3.2) / 0.02 ohms when driven by an 5 volt Arduino board.


text:
DS18B20 temperature sensor not working
I am new to arduino.I try to read temperature using DS18B20 temperature sensor.I connected the pins as bellow.But,When I connected 1-pin to ground and 3-pin to +5V the sensor heated and all the little lights on the UNO board turned off and it stopped working.

When I connected 3-pin to ground and 1-pin to +5V the board worked normally.But,I gives -127 as the temperature when I uploaded the bellow code.
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is connected to the Arduino digital pin 2
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);

void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();
}
void loop(void){
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(sensors.getTempCByIndex(0));
Serial.print(" - Fahrenheit temperature: ");
Serial.println(sensors.getTempFByIndex(0));
delay(1000);
}

I connected with both Normal mode and Parasite mode.But, same results..
I use this:

Help me to solve the problem.
Thank you!

you have to connect the middle pin also

The topmost image shows the correct connection (with the flat side of the package facing you). It should not have heated up so I suspect you made an error. Pin 2 (the data pin) should have a pull up of about 4.7k-10k Ohm to VDD. The -127*C value just indicates that the device is not responding or functioning or you might have destroyed it during your first trial. You can use the "Tester" example that comes with the DallasTemperature library to see if the device is recognized and to print out its unique address.

Thank you for the comments...
Yes,I pulled up of 7.4k Ohm to VDD.

Your setup (as you described it) seams OK. I can not find any errors in your program. I fear the device is broken, or you bought a fake 18B20. Can you trust your seller? The device should not heat up at all, even if you reverse connect the power pins. The -127 is plausible because the device was powered with the wrong polarity and does not operate. If you power it correctly it heats up and draws much more current than it should (<4mA). That's a bad sign. Have you a spare part? Then you can try this. But if you bought fake devices, I fear that one will not work too.

I bought this from a trusted shop in the country.
I tried but I could'nt find the error.


text:
Voltage at AREF pin
I find difficulties to measure correctly the voltage at the AREF pin.
I would measure voltages with a resolution not exceeding 1 mV . nda voltage divider
In one of my trials, I was using a  9V battery and a voltage divider made with a 1k resistor and a 2k one.

The battery voltage was about 8890 mV and the reference voltage was about 2960 mV (confirmed by a multimeter).
I  connected the output of the divider to the AREF pin of an Arduino Uno board. The output voltage value dropped to about 1800 mV. Reading the voltage value at AREF pin with a simple sketch:.

the serial monitor printed:

as if the voltage dividere did not exist.
What am I doing wrong? or what I don’t understand?
Thank you for your attention.

analogRead(EXTERNAL)? EXTERNAL s 0. you read A0

On the AREF pin you provide a reference voltage that is compared with the voltage you will measure on the Ax pins. AREF is not a Ax pin. You can not measure it directly with analogRead(EXTERNAL)  but you can connect AREF to e.g A0. But as VREF is the reference you compare A0 with the result would always be 1023. The Voltage you measured on the VREF pin is lower than  you measured on the unconnected voltage divider because VREF has a low impedance and changes the  voltage divider.

One solution to stabilize the voltage divider is to use a Zener diode with a reverse breakdown voltage of 3V (or what ever you need for AREF) instead of the R2 resistor. The arrow/triangle of the Z-Diode  must face towards the R1. You can not measure the AREF with the same Arduino because AREF is the reference of the measurement, its result would always be 1023, if you measure the reference itselfe .

You could also build a stabilized voltage source with a LM317. And you should consider using the 5V of the Arduino to create the reference voltage from. (As long as you need about 3V that's no problem). Then you get rid of the 9v batterie.

Very clear and detailed. Thanks.Paolo

I was using a 9V battery and a voltage divider made with a 1k resistor and a 2k one.

Using a battery is not a good way of getting a stable voltage. A battery's voltage will change over time.
Using a voltage divider is not a good way of generating a reliable stable voltage. The output impedance is very high and will be affected by any loading you apply to it causing it to droop.
If you want 1mV per LSB then you need a 1024mV voltage reference (since there are 10 bits of resolution, or 1024 possible divisions, in the ADC). For that you want a 1024mV voltage reference, which is a standard value for precision voltage reference chips such as the LM4140CCM-1.0/NOPB from Texas Instruments. Personally I like to use a precision DAC like the MCP4821 to provide a settable analog reference voltage.

Reading the voltage value at AREF pin with a simple sketch the serial monitor printed 8890 as if the voltage dividere did not exist. What am I doing wrong?

You cannot read anything from the AREF pin. It is merely a voltage reference, not an active pin you can read. When you use analogRead(EXTERNAL) you are actually doing analogRead(0) since EXTERNAL is a macro that expands to 0. That means you are really reading from pin A0 not the AREF pin.  And then you just map that to 8890 when it's at maximum anyway. Since A0 is (probably, since you don't show anything else in your circuit) floating it will most likely be above the voltage you are feeding in to AREF and will return 1023 all the time anyway.


text:
Arduino IDE on eOS? Java?
Tried to install Arduino IDE on Juno, install script gave warnings about icons not being installed on desktop (which is fine since no desktop folder for eOS) but then when try to launch the IDE icon from Applications it doesn't go. I'm guessing it's a java app? I don't want to run java on eOS unless it's already there. Any insight to running this IDE on Juno would be welcome.

Yes, the Arduino IDE is java, so you need java to run it. You could try to use arduino-cli (commandline tool to compile and upload code to Arduinos). It seems to be written in go

"it doesn't go" is not a good problem description. Have you tried running the Arduino IDE from a terminal and watch, if errors are displayed there? If yes, these errors belong into the question.

I'd be fine w just coding and compiling. Am obv new so didn't know IDE had a cli (sounds counterintuitive). Doesn't go means I click the icon and app doesn't launch. Am setting this all up for the first time so be kind. For now am able to download hex files to the hardware, so am going to backstep and try hand compiling some code via gcc. Not a fan of java so prob isn't on my system by default. No other IDE option?

The CLI is not part of the IDE. It's an extra program. For the case, that you want to stay in the Arduino Framework without much configuration. You can use any C++ IDE to write the sketches as ino files. Then you can execute the compilation and uploading over the CLI. Another option would be Atmel Studio, though I think you need to configure it to use the Arduino framework (google might help you there. Haven't done that myself).

version for what platform did you download? Linux 64-bit?  To what folder did you unpack the installation? The IDE has Java bundled. The install.sh only creates a desktop icon, nothing else.

@Navin eOS is "Elementary OS" - a premium version of Linux.  "Juno" is a release name for the current version. There's no network switch involved. I think you may be getting muddled up with Juniper.

@Majenko thank you, I did get it muddled up with Juniper Junos


text:
How to access native USB port of Arduino Due on Synology NAS?
I would like to flash my Arduino Due from my Synology DS218+ NAS which runs on an Intel 64bit Linux-derivate platform. Previously, I was able to flash a Mega 2560 from this NAS via avrdude and currently, I am able to flash an Arduino Due via bossac through the Due's programming port. The port is registered as /dev/ttyACM0 (as was the Mega 2560) after I installed the necessary usbserial kernel module.
However, the native port is not detected likewise, or rather it is deregistered immediately:
[8336388.471865] usb 1-2: new high-speed USB device number 27 using xhci_hcd
[8336388.613119] Got empty serial number. Generate serial number from product.
[8336388.685041] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
[8336389.331596] usbcore: deregistering interface driver cdc_acm

The programming port shows up like this:
[8338189.956730] usb 1-2: new full-speed USB device number 29 using xhci_hcd
[8338190.100022] usb 1-2: ep 0x82 - rounding interval to 1024 microframes, ep desc says 2040 microframes
[8338190.615513] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
[8338190.621705] usbcore: registered new interface driver cdc_acm
[8338190.628534] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters

Is there anything I need to install in addition to the usbserial kernel modules to get the native port working?
P.S.: I know that the programming port is more stable, but it is also rather slow with its 115200 bps. Uploading a sketch that just takes up 50% of the Due's flash memory takes almost a minute, and if you want to see the effects of code changes, this is quite time consuming.

how is this an Arduino related question?

@jsotola: I think part of the question is whether the Due needs two different drivers for the programming and native port respectively or whether the Due needs some kind of configuration on the native port to be detected properly. Furthermore, when I posted the same question on stackoverflow as I thought it is (also) a operating system question, it was downvoted to -2 within a few hours because it was seen as an Arduino related question.


text:
ESP8266 NodeMCU CP2102 ESP-12E I2C with MPU 6050 Error
So the previous two questions could be found here:
ESP8266 computtion error and ESP8266 not working with MPU 6050 over wire library and I2C
However, it was not resolved, and with updates and debugs, I'm going to delete them later and summarize in this single post.
Issue:
An ESP8266  CP2102 ESP-12E was trying to access MPU 6050. However, it's not working.
Attempts:

You can see the diagram picture. I tried pairs of pull up resistor from 0 to 100 k(the one used in the picture was standard 4.7 k).
Many MPU 6050s have been attempted and tested. They were working, and you can see in the picture, the green light lighted up.
Different ESP 8266 -12E from two different brands have been attempted, both have the same issue.
Various of version of board manager has also been attempted.
Different wires have been attempted. The I2C bus in the graph are twisted wires.
The adjustment of the program has also been attempted. Eventually, an online version of code  was attempted, and not working.
The power supply was ruled out through the usage of power board, capacitors, and external power sources. The issue persisted.
Wire library pins, frequencies, have been checked as correct. As well as constant restart of IDE and hardware.
Different bread boards and have also been attempted, the issue persisted.

The above attempts all resulted failure. Could you help me to figure out why ESP 8266 does not work with MPU 6050 over I2C?

Comments are not for extended discussion; this conversation has been moved to chat.

This is not the answer to your question, but I don't know where you get the idea of using a 100k pull up resistor for I2C communication. The value of pull-up resistor depends on the speed of I2C communication, 4.7k will probably enable the I2C to communicate at fast mode, but 100k will sure too high even for 9600bps, you should read this application node for better understanding of pull up resistor requirements.

@hcheung please read, resistor from 0 to 100k has been attempted and the one in the graph was 4.7k

Well, sorry to be blunt, you are all over the places and don't know what you are doing. It is fine if you don't appreciate the sharing. ESP8266 works for MPU6050, it works for me, works for other people as some pointed out. Good luck...


text:
SIM800L - AT Commands not doing anything on Arduino Serial Monitor
I am trying to send AT commands to SIM800L through Arduino's Serial Monitor. However when I type any command in the serial monitor nothing happens. I'm using an Arduino MEGA 2560 and the TX/RX of the SIM800L is connected to 9 and 10 respectively. Here is the code:
#include <SoftwareSerial.h>

SoftwareSerial GPRS(9, 10);
boolean state, lastState;

void setup()
{
  pinMode(2, INPUT_PULLUP);
  state = digitalRead(2);
  lastState = state;

  GPRS.begin(9600);
  Serial.begin(9600);

  GPRS.println("AT+CMGF=1");

  delay(1000);
}

void loop()
{
  while(GPRS.available()) {
    Serial.write(GPRS.read());
  }

  lastState = state;
  state = digitalRead(2);

  if ( state != lastState ) {
    sendSMS();
  }

  delay(500);
}

void sendSMS() {
  Serial.print("Switch was turned ");
  Serial.println(state ? "on" : "off");

  GPRS.println("AT+CMGS=\"+64XXXXXXXXX\"");

  delay(500);

  GPRS.print("Switch was turned ");
  GPRS.println(state ? "on" : "off");
  GPRS.write( 0x1a ); // ctrl+Z character

  delay(500);
}

Any help would be much appreciated!
EDIT2: I forgot to mention but I am able to send, receive, and call from the GSM Module (with a different code). However I am not able to read the the received messages, since I only get a +CMT "SM",  message and I can't exactly use AT+CMGR or CMGL commands because the serial monitor does nothing with them. here's the code for that:
#include <SoftwareSerial.h>
SoftwareSerial sim(9,10);
int _timeout;
String _buffer;
String number = "+639XXXXXXXXX"; //-> change with your number
void setup() {
  delay(1000); //delay for 7 seconds to make sure the modules get the signal
  Serial.begin(9600);
  _buffer.reserve(50);
  Serial.println("Lets go!");
  sim.begin(9600);
  delay(1000);
  Serial.println("Type s to send an SMS, r to receive an SMS, and c to make a call");
}
void loop() {
  if (Serial.available() > 0)
    switch (Serial.read())
    {
      case 's':
        SendMessage();
        break;
      case 'r':
        RecieveMessage();
        break;
      case 'c':
        callNumber();
        break;
    }
  if (sim.available() > 0)
    Serial.write(sim.read());
}
void SendMessage()
{
  Serial.println ("Sending Message");
  sim.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);
  Serial.println ("Set SMS Number");
  sim.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message
  delay(1000);
  String SMS = "Wala kang jowa!";
  sim.println(SMS);
  delay(100);
  sim.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  _buffer = _readSerial();
}
void RecieveMessage()
{
  Serial.println ("SIM800L Read an SMS");
  delay (1000);
  sim.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
  Serial.write ("Unread Message done");
}
String _readSerial() {
  _timeout = 0;
  while  (!sim.available() && _timeout < 12000  )
  {
    delay(13);
    _timeout++;
  }
  if (sim.available()) {
    return sim.readString();
  }
}
void callNumber() {
  sim.print (F("ATD"));
  sim.print (number);
  sim.print (F(";\r\n"));
  _buffer = _readSerial();
  Serial.println(_buffer);
}

when I type any command in the serial monitor nothing happens ... you don't have any code for that

@jsotola i thought it would take any AT commands automatically in the serial monitor? anyway i'll add my code that i used where i could send/receive/call the phone but not read any messages i receive

the arduino will not do something on its own ... try this code ... https://www.arduino.cc/en/Tutorial/SoftwareSerialExample

Why are you using SoftwareSerial on a Mega?!?!

Do not use SoftwareSerial on a Mega2560 unless you absolutely know what you are doing.
SoftwareSerial does not work on many of the pins of the Mega2560, and since there are other hardware serial ports available there is seldom any reason to resort to using SoftwareSerial anyway.
Connect your SIM800L to the TX1/RX1 pins of the Mega2560 then communicate using the pre-defined Serial1 object.

I see. I looked up some stuff regarding my question on other posts and almost everyone says to not use SoftwareSerial with Mega2560. Althought tbh I still don't completely understand what to do. Do I simply remove everything related to SoftwareSerial? How do I use the hardware serial ports; do I still need to code them in like in software serial or can i just connect the SIM800L to the TX1/RX1 without worrying about anything else? Dumb questions I know, but I've been out of touch with Arduino for over a year no so please bear with me...

Of course you have to code them in. You read with Serial1.read() and write with Serial1.print(...) in the exact same way as any other form of serial communication. You can't just plug random things in and expect the Arduino to magically know what they are and how to work with them.

i guess what i really wanted to ask there was whether i needed to include another library like software serial. so basically i dont have to use any libraries now, right? What I still don't understand is that everyone seems to be using SoftwareSerial <GSM name>(<TX>,<RX>) to connect their GSM modules to their Arduino, regardless of whether it's an UNO or a Mega. If I'm not supposed to use SoftwareSerial, what should I be replacing that with? Or am I missing something completely here?

No libraries needed. Nothing to define. Serial1 is already defined for you. Just use Serial1.print() and Serial1.read() where you use sim.print() and sim.read() and so forth.

oh so i can just do something like sim(<TX>,<RX>) without anything before it and then it's already defined as Serial1?

No. You don't define anything. You just use Serial1.

oh, that's what i was confused about! thanks!

Make sure the RX of your arduino board is connected to TX of GSM and the TX should be connected in RX of GSM module.
Next try to do this

   GPRS.begin(9600);
   Serial.begin(115200);

Also double check your wirings, if you have a tester you might wanna check if both end are connected with each other. And in the loop try to print this Serial.println(GPRS.available()) if it is not greater than 0 then you have a problem with your connection.

    #include <SoftwareSerial.h>
    SoftwareSerial sim(2,3);

    void setup() {
      // put your setup code here, to run once:
      Serial.begin(115200);
      sim.begin(9600);
    }

    void loop() {
      // put your main code here, to run repeatedly:
      while(Serial.available() > 0){
        sim.write(Serial.read());
      }

      while(sim.available() > 0){
        Serial.write(sim.read());
      }
    }

diagram reference.

Hope this help.

why would you wire it to RX/TX of the Mega and what is the GPRS object in your answer?

Where did I get the GPRS? from his code.
well actually just follow my supper simple diagram from the link bellow for you to understand
https://imageup.me/images/a49982fe-c592-44d7-b696-ed80e725fec5.png
and follow my supper simple code for you again to understand. :-)
#include <SoftwareSerial.h>
SoftwareSerial sim(2,3);
void setup() {
Serial.begin(115200);
sim.begin(9600);
}
void loop() {
while(Serial.available() > 0){
sim.write(Serial.read());
}
while(sim.available() > 0){
Serial.write(sim.read());
}
}

@homerio  Your link gives "Oops! An unhandled exception occurred while processing the request.".

@homerio Comments are not for posting images and code. Please amend your answer to make it clearer.

Follow this link also for the diagram reference - you can embed images into answers. That is better because external links can become link-dead.

That's strange? I don't know how to embed in comment @Nick :D, but thanks man :-)

You posted an answer. You can edit it. When you do so there is an icon for embedding images.

Saw it. thanks man.