text:
how to convert the following code into one using direct port manipulation
Following is the program for scanning a keyboard for MIDI transfer.
At present the code works fine, but it could be faster.
I need to know how to use direct port manipulation inside the for loop.
boolean keypressed[6][6]; //for storing key states
int midinote[6][6] ={ 60 ,61 ,62 ,63 ,64 ,65
                 ,66 ,67 ,68 ,69 ,70 ,71
                 ,72 ,73 ,74 ,75 ,76 ,77
                 ,78 ,79 ,80 ,81 ,82 ,83
                 ,84 ,85 ,86 ,87 ,88 ,89
                 ,90 ,91 ,92 ,93 ,94 ,95  }; //code for various midi notes C3 to C6

void setup() {

   Serial.begin(38400);
   for(int i=0; i<6; i++){
      pinMode(i+2,OUTPUT);
      digitalWrite(i+8,HIGH);
   }
   for(int i=0; i<6; i++){
      pinMode(i+8,INPUT);
      digitalWrite(i+8,HIGH);
   }
   for(int i=0; i<6; i++){
      for(int j=0; j<6; j++){
          keypressed[i][j] = false;
          }
      }
   }
void loop() {

   for(int i=0; i<6; i++){
      digitalWrite(i+2, LOW);
      for(int j =0; j<6; j++){
         if ((digitalRead(j+8) == LOW) && !keypressed[i][j]){
            Serial.write(0x91);
            Serial.write(midinote[i][j]);
            Serial.write(127);
            keypressed[i][j] = true;
           }
         if ((digitalRead(j+8) == HIGH) && keypressed[i][j]){
            Serial.write(0x91);
            Serial.write(midinote[i][j]);
            Serial.write(0);
            keypressed[i][j] =false;
         }
      }
digitalWrite(i+2, HIGH);
   }

 }

You need to download the data sheet of the AVR and look up the port registers. Then you can access (read or write) all bits of a port with a single instruction. You will need to change your keyboard scanning algorithm accordingly. -- Having said this, I'm not sure that the Arduino libraries don't have methods to do this already.

I do not think that direct port access increases the speed of your program remarkably. If you natively read a PORT you have to store the value in a CPU register and then check its bits in the loop. There is a difference in reading a IO register compared to an internal CPU register, but its not that much compared to the time you need to send the midi note. And that's limited to the midi speed. (Wich is 31250 bps, as far as i know - not 38400 as I saw in your code). But if the receiver understands, it's OK ;-). So, I would say the midi speed is he bottleneck not the keyboard scanner algorithm.

Ah, if you don't need any wise ( dumb ;-) ) talk. Here is a link that answers yout question. So you can decide whether it is worth it, to change your program.  https://www.arduino.cc/en/Reference/PortManipulation

I doubt if you gain anything with it, as Serial will be the bottleneck. But if you must, I'd suggest something like the digitalWriteFast library.

It is better to use interrupts instead of pooling pins.
but this is related to your arduino controller.
what is you arduino core controller?
if you can select I prefer "Nano 33 IoT " which has 9 pins (2, 3, 9, 10, 11, 13, 15, A5, A7) available for interrupt.
this page may be usable:
https://playground.arduino.cc/Main/PinChangeInterrupt/

I'm not sure how useful interrupts are on a button matrix.

polling force cpu to check i/o ports in loop that cause waste cpu time and code is a cascaded for loop.
where using interrupts lets cpu doing its normal code and interrupt with its input Vector make every thing ready for you, by some bit-wise operations you can find changed port and send correct output.

That’s a very common newbie trap.  But go ahead.


text:
How can measure the 3-axis accelerations?
i'm a student who is studying the Arduino.
I want to measure acceleration using arduino and any sensor. i looked at some acceleration sensors (ex, MPU6050, AXDL335), but they were just measuring gravity, not axial acceleration.
Could you tell me any sensor that can measure the axis-acceleration available with Arduino?

They are measuring any acceleration. Gravity just causes an acceleration in one direction. If you accelerate these sensors into a different direction, the resulting acceleration vector will be a combination of gravity and your acceleration. So these sensors are already capable of what you want to do. Or do you mean rotational acceleration? If yes, then you need a gyroscope (which is also a part of the MPU6050 I think)

But those were not able to measure in the following cases; if the sensor is leveled and accelerated x or y-dir, the directional acc of that axis is zero, and the z-dir is 1g

No, it isn't. The MPU6050 (I know this chip a little) has 3 accelerometers for each axis. When you accelerate in x, the corresponding acceleration value rises. Have you already tried something and failed with it? Then you can edit your question to include this information. Maybe you did something wrong and we might be able to help you

There is no difference between gravity and other kinds acceleration. Gravity is the constant downward acceleration of ≈9.81 m/s². You cannot feel any difference between the force of gravity and the force you would experience on a surface without gravity that's accelerating upwards at 9.81 m/s².
You can use the gyroscope to keep track of the orientation of the sensor, so you know the downward direction of gravity, and can correct your accelerometer measurements for it.
The problem is that gyroscope orientation measurements are subject to drift. To correct the orientation for drift, the accelerometer is used (because it can measure the direction of gravity, so you know what the downward direction is). The accelerometer only measures the exact acceleration due to gravity if the sensor is not accelerating, of course, but that's most likely not the setup you're going to use an accelerometer in.
As you can see, this is kind of a chicken and egg problem.
Luckily, there are advanced sensor fusion algorithms and complementary filters available that combine the accelerometer and gyroscope measurements, and give you a pretty good approximation for both.
I've successfully used Madgwick's algorithm for a quadcopter.
Depending on your use case, you'll have to tweak some coefficients to indicate if you rely mostly on the gyro or the accelerometer data. The MPU6050 has a DMP that can run sensor fusion algorithms on the chip itself, so the Arduino doesn't have to deal with that.

Correction to your your 2nd sentence - gravity appears like an upward (not downward) acceleration.

source: Stack Exchange

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

sort: votes


text:
What sensors can measure 3-axis acceleration?
I'm currently measuring vibration, temp and noise using an Arduino and various inexpensive sensors. The acceleration sensor i found was sensors that measured the gravity on 3-axis of the sensor. But i'd like to measure acc, not gravity, as it moves in the direction of the sensor. For example, if an object is moving front-dir in a horizontal location, the x-directional acc is measured.
Could you tell me if you know the acc soensor i want.

3-axis accelerometer. And yes, they measure gravity. After all, gravity is just acceleration downwards (9.8m/s²)...

The acceleration sensor i found was sensors that measured the gravity on 3-axis of the sensor

Gravity is acceleration.
An accelerometer measures acceleration - or more accurately, it senses the resistance to acceleration (inertia) and equates that to acceleration.
By holding an accelerometer still you are causing it to resist the pull of gravity, and it's that "resistance" that it measures - a constant 9.8m/s²
If you let the accelerometer freefall it won't be resisting gravity any more, and will measure 0 for the Z axis.
So you simply have to "ignore" gravity, by removing that constant 9.8m/s² ("1g") of acceleration from the Z axis.  And you do that by simply subtracting it.
It is normal to calibrate an accelerometer by keeping it at rest and reading the "idle" values. Those values are then subtracted from the readings to give you the actual value.

But, I want to check x and y-dir accs, not gravity. (front(x-dir) acc, on planar)

Yes? And? that's what the other two axes are for. X (forwards/backwards), Y (sideways) and Z (up/down+gravity).

Does this mean that these acceleration measurements are also possible?; https://stackoverflow.com/questions/38962719/how-to-get-acceleration-and-deceleration-like-a-car-in-android   I didn't get the desired value when I moved the acceleration sensor in plane. I used the MPU6050.

Then either you are doing something wrong in your code, or you fundamentally misunderstand the basic nature of the universe.

https://physics.info/kinematics-calculus/

How to remove gravity from axis-acceleration? I'd searched this but i was able to find that i want. Could you tell me the code I want ?

z = z - 9.8; -- assuming Z is vertical acceleration in g.

yes. i have already done. but if the x-axis is oriented upwards, 9.8 is detected.

Then what you want to do is convert the three individual axes into a 3D vector, then subtract the 3D vector of the sensor when stationary.

Oh, the way you're talking about it, first get the roll, pitch, and yaw using the gyro, and then use it to make a three-dimensional transformation. Is it right that i understand?

There is a library, IIRC, that takes all 6 values and does some fancy maths with them to give you useful values. I have never used it and don't know what it's called, but maybe Google could find it for you. It sounds like that is what you need.

acceleration is not gravity. something sitting on the table, z axis of the sensor upward, should have 0 accel, not 9.81 m/s/s. In freefall it is accelerating at g, not 0. It is easy enough to subtract out 9.81 from that reading but that does not work when the orientation of the sensor will vary in use (and integrating orientation over time does not provide the accuracy needed). what I really want is a sensor that actually reads acceleration!!

@JonathanWeaver https://en.wikipedia.org/wiki/Equivalence_principle

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


text:
How do I read from a correct data address of LIDAR using Arduino in I2C?
I need to read the distance data from a lidar in I2C using an Arduino Nano. Currently, this is the code I've written.
unsigned int readDistance()
{
  unsigned int dist = 0 ; // LiDAR actually measured distance value. static so we can return previous dist

  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(0x10) ; // transmit to device 0x10
  Wire.write(2) ; // sets distance data address (addr)
  Wire.write(3) ; // sets distance data address (addr)
  Wire.endTransmission() ; // stop transmitting

  // step 2: wait for readings to happen
  delay(100) ; // datasheet suggests at least 100ms

  // step 3: request reading from sensor
  Wire.requestFrom(0x10, 2) ; // request 2 bytes (DIST_L, DIST_H) from slave device #0x10
  dist = Wire.read() ; dist += Wire.read() << 8; // calculate distance value, bit shift high distance
  return dist ; // return updated dist
}

But I have a feeling I'm requesting from the wrong data address', since I'm not getting the results I expect (ie. varying distance data). Furthermore, I used an I2C scanner which 100% confirms the lidar is on the (default address) of 0x10.
Datasheet of (TF02 Pro): https://www.unmannedtechshop.co.uk/wp-content/uploads/2020/01/TF02-Pro-Product-Manual-Alpha.pdf
Question: am i reading from the right data address
Any help would be appreciated.

which information on which page are you following?

i'm quite new to arduino so please bear with me. are you talking about the datasheet for the lidar which I'm getting the address' from? that's @ https://www.unmannedtechshop.co.uk/wp-content/uploads/2020/01/TF02-Pro-Product-Manual-Alpha.pdf

It looks to me like you have to send the same things through i2c as you would through UART. It's not your typical i2c device.

What results are you getting exactly? If your code is not stalling or failing then I doubt it’s an address issue.
Do you maybe have access to an oscilloscope or I2C test device  to see what’s happening on the I2C bus?

Long story short, some i2c devices are configured such that data is only present in said registers after continually issuing 'read commands'.
In this case, the read command was: 5A 05 00 01 60
Amended code:
unsigned int readDistance()
{
  unsigned int dist = 0 ; // LiDAR actually measured distance value

  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(0x10) ; // transmit to device 0x10
  Wire.write(0x5A) ; // some read command.
  Wire.write(0x05) ;
  Wire.write(0x00) ;
  Wire.write(0x01) ;
  Wire.write(0x60) ;
  Wire.endTransmission() ; // stop transmitting

  // step 2: wait for readings to happen
  delay(100) ; // datasheet suggests at least 100ms

  // step 3: request reading from sensor
  Wire.requestFrom(0x10, 4) ; // request first 4 bytes from slave device #0x10
  Wire.read() ; Wire.read() ; //ignore header bytes
  // remaining two bytes for distance (DIST_L, DIST_H)
  dist = Wire.read() ; dist += Wire.read() << 8 ; // calculate distance value, bit shift high distance
  return dist ; // return updated dist
}


text:
My Arduino UNO works, but 2 smd overheats. Why?
I can use my Arduino with the usb plug, but 2 smd overheating when I plug into the computer, But when I use the DC plug, the leds on the Arduino barely visible (for example the "ON" led), so the arduino is only works with the USB plug.

These look like C2 and C3 in the Arduino UNO R3 schematic. It sounds like both are internally shorted.
Assuming that's true, why it would work (partially anyway) on USB but not external power would depend in part on what external voltage had been applied.  The voltage seen on the board, and therefore the brightness of your LEDs, depends on the voltage being dropped above their source.  That is, it depends on what's happening to the PTC fuse and in the USB host port and cable etc for USB.  And in the linear regulator and similar current limiting in series with it.  Probably the thermal overload protection in your regulator is shutting it down so hard that the LEDs don't even light.  Or whatever event cause this problem happened while you were externally powering it and there's now an open somewhere on the side external powering.
For now it's probably better if you're not continuing to plug it into a PC.  If you're going to do that, it's probably better that you have a powered hub that you don't care about in between.
This seems to be the 3.3V regulator.  If you're not using 3.3V, you may be able to get a soldering iron and through-heat the capacitors and scrape them off the board and see whether or not the rest of the board, the 5V section, works fine.  Before you do that you may want to measure the 5V and 3.3V lines and write down what you get.  One or both are probably low.  Take note of the USB source you're using.  Try taking off the capacitor off the output side of the regulator first, see how things go.  Then go for the input side one.  From the sounds of it both are bad though.  But it can't hurt to go methodically.

I checked the 3.3V and the 5v line too. There's a short circuit between the 3.3V and the ground line, but there is no such problem at 5 volts

3V3 is used also as a reference voltage for disconnecting Vusb when you connect something over 6.6V to barrel jack so it's not back powering anything (if you shut down the connected computer, it could be an issue, same as short on 3V3 and it can't detect anything properly)

Yeah, if it removing the caps makes the regulator unstable enough, it could be a problem.  I'm gathering from the description that the regulator is not shorted; I've yet to see one do that so well (so bad?) that it didn't make itself apparent in heat.  I'd try removing the 3.3v output-side cap first and see how thing change.

With respect to the 5V line not being shorted, well, it is possible for things to be shorted well enough for small components to get very hot but not enough to bog down the 5V/USB voltage.  I had a Leonardo where I'd managed to get about 30VDC onto one of its GPIO pins.  There after it "worked" but ran so hot you could fry an egg on the 32u4 and VUSB was able to keep up just fine.  I've since replaced the IC.  When you clear the fault you may not see any increase in voltage, but I suspect you'd see it change by at least a few mV.


text:
My bluetooth module keeps sending out constant exports
So I have a bluetooth module hooked up to my arduino to control an LED light, something simple to turn on and off. But the app im using constantly is either sending something or receiving. This causes the circuit to not work at all and I cannot figure out what is going on.
void setup() {
   Serial.begin(9600);
   pinMode(8, OUTPUT);
}

void loop() {
   if(Serial.available()>0)
      {
         char data= Serial.read();
         switch(data)
            {
               case 'a': digitalWrite(8, HIGH);break;
               case 'd': digitalWrite(8, LOW);break;
               default : break;
            }
         Serial.println(data);
      }
      delay(50);
}

Your Arduino code is only sending, if it received some data. We don't know your app, so it might be constantly sending data. You could test that by connecting TX of the bluetooth module to TX on the Arduino, holding it in reset and then look at the Serial monitor, what was received there. (or you can use a sketch with a SoftwareSerial interface)

If you send a char from your app, you will send such char plus '\n' or '\r\ or both. For each char your sketch will print a (blank) line.

enable hex rx in your app ... i think that it will allow you to see non-printing characters


text:
Combined code and nothing works. Head scratcher for sure
I have spent a little over 2 hours trying to debug this code. All I did was combine a section of code to write to the SD card. Both of the codes work fine on their own. I can't figure this one out. I am hoping fresh eyes can spot the error. I am using a Arduino Nano with a Robot-Deek data logger board. Pin 10 is used for the data logger. I was using a DTH11 but switched to a LM35, both codes worked with LM35.
#include "RTClib.h"
#include <SD.h>
#include <SPI.h>
#define sample 500
#define current_ms millis()
RTC_DS1307 rtc;
File myFile;
int inPin = 0;   //analog in
float val;       //where to store info from inPin reading
int pinRed = A3;  //output of red led
float tempin = A5;  //input of temp sensor
float tempf;     // variable to hold temp in Fahrenheit
float vout;      // variable to hold voltage from sensor
int array1[sample];  //creates an array with number of elements equal to "sample"
unsigned long averaging;  //the program uses this variable to store the sum of each array it makes
int pinCS = 10;   // write to SD card
float last_dht11_reading_ms = 1;
DateTime now = rtc.now();
#define DHT11_SAMPLE_DELAY 500

void setup() {

  Serial.begin(9600);
  delay(500);//Delay to let system boot
  SD.begin();
  pinMode(pinCS, OUTPUT);
  pinMode(tempin, INPUT);
  Serial.println("Volt and Temperature\n\n");
Serial.println("middle the setup loop");
 // SD Card Initialization
  if (SD.begin())
  {
    Serial.println("SD card is ready to use.");
    File myFile = SD.open("Datalog.csv",FILE_WRITE);
    if (myFile) {
      myFile.println("Time, Temp, Volt");
      myFile.close();
    }
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
  rtc.begin();
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}//end "setup()"

void loop() {

  for (int i = 0; i < sample; i++) {         //this code tells the program to fill each element in the array we made with
    array1[i] = analogRead(inPin);           //information from the antenna wire coming out of the Arduino
    averaging += array1[i];                  //more information about for loops http://arduino.cc/en/Reference/For
  }                                          //the averaging line is simply saying: add averaging to whatever is in array position i
                                             //averaging += array[i] is the same as averaging = averaging + array[i]

  val = averaging / sample;                  //here the program takes the sum of all numbers in array1, and divides by the number of elements "sample"
  val = constrain(val, 0, 100);              //this constrains the variable value to between two numbers 0 and 100
  val = map(val, 0, 100, 0, 255);           //for more information about constrain http://arduino.cc/en/Reference/Constrain
  analogWrite(pinRed, val*20);                  //the map statement tells the program to map out 0-100 to 0-255
  averaging = 0;                                 //this line of code sets averaging back to zero so it can be used again
Serial.println("past the emf loop");

  if ( (current_ms - last_dht11_reading_ms) > DHT11_SAMPLE_DELAY ) {
    vout = analogRead(tempin);                //read LM35 output
    float mv = (vout/1024)*5000;              // conversion to mV
    float celc = mv/10;                       // convert to C
    float tempf = ((celc*9)/5 + 32)/10;       // convert to F
    myFile = SD.open("Datalog.csv", FILE_WRITE);      //open datalog file on SD card

  if (myFile) {                              //write to the SD card time, tempf and val
    myFile.print(now.hour());
    myFile.print(":");
    myFile.print(now.minute());
    myFile.print(":");
    myFile.print(now.second());
    myFile.print(",");
    myFile.print(tempf);
    myFile.print(",");
    myFile.println(val);
    myFile.close(); // close the file;    // close the file
    last_dht11_reading_ms = current_ms;
  }
Serial.println("past the logger loop");
  //delay(1000);//Wait 1 seconds before accessing sensor again.

}
}
// end loop()

What exactly is not working how? Please explain, what you expected and what behavior you actually see

I expect it to write to the SD card and write to the serial monitor. However it is not. I even put in some "markers" to print out to the serial monitor letting me know what part of the code fired off, but they don't print either. The LED does not work. It is like the code is not running.

remove the first SD.begin() and the pinMode for pinCS. add pinCS as parameter of the second SD.begin(). if (SD.begin(pinCS))

Thank you. I made the changes you suggested and still nothing. I run code A, no problem. I run code B, no problem. Run this code, a  combination of the two and I get nothing. No outputs.

DateTime now = rtc.now();
Does not belong above void setup()
4hours to troubleshoot this little mistake.


text:
Motors would make the car go extreme left instead of forward (Self Driving car)
This is my very first day in the community, please bear me until I make myself comfortable here.
Coming to my question,
I'm making a self Driving car.
My car instead of moving forward it moves on the left rigorously which makes the car go round and round.
Along with my arduino, I'm using the L298 bridge to control my motors.
The motors seem to work fine until put on the ground.
Can you guys help me with what could be the possible solution to this and make my car go forward.
Here's my code :

    const int EnableL= 5;
const int HighL = 6;  //Left side motors
const int LowL = 7;

const int EnableR= 10;
const int HighR = 8;  //Right side motors
const int LowR = 9;

void setup() {
 pinMode(EnableL, OUTPUT);
 pinMode(HighL, OUTPUT);
 pinMode(LowL, OUTPUT);

 pinMode(EnableR,OUTPUT);
 pinMode(HighR, OUTPUT);
 pinMode(LowR, OUTPUT);

}

void Forward()
{
  digitalWrite(HighL,HIGH);
  digitalWrite(LowL,LOW);
  analogWrite(EnableL, 255);

  digitalWrite(HighR,LOW);
  digitalWrite(LowR,HIGH);
  analogWrite(EnableR, 255);
}

void Backward()
{
  digitalWrite(HighL,LOW);
  digitalWrite(LowL,HIGH);
  analogWrite(EnableL, 255);

  digitalWrite(HighR,HIGH);
  digitalWrite(LowR,LOW);
  analogWrite(EnableR, 255);
}

void loop() {
  Forward();

}

Components used :
3 pack lithium ion cells at 12V to power L298 bridge
A 9v cell to power Arduino Uno

what does this mean? ... put on the ground ...  placed on ground ...or ground wire connected

https://arduino.stackexchange.com/questions/62889/l298n-motordriver


text:
How is this code working?? val3 is defined as constant
const int val3 = 7;
void setup(){
  Serial.begin(9600);
  int val3 = 8;
  int val4 = 4;
  Serial.print(calc(val3,val4));
}

void loop()
{}

int calc(int val1, int val2)
{
  return val1 + val2;
}

this code gives output as 12.

print val3 in loop()

I did not get you, can you explain again.

you use the second int val3 defined in setup(). it shadows the global val3

@Akash, add a Serial.print() statement into the loop() block ... print out the value of val3 ... what prints in the serial monitor?

In your code, the const int val3 = 7; definition, is outside of any functions so it defines a global constant/variable (available in every part of your code).
The int val3 = 8; definition is inside your setup () function, so it acts as a local variable only within that function. This overrides the val3 constant defined outside of the setup () function. I.e. the global val3 constant and the local val3 variable inside of setup () are not the same variable, which will inevitably lead to confusion (as in your case).
It’s valid syntax but I don’t consider it good coding practice. It’s good to know why it works that way though.

Thanx, i got it.

You have declared val3 two times: One time as constant int and another time as int (in setup loop). Replace the statement int val3=8 by val3 = 8. You will know the difference.
The first declaration is of no use in this case. As a try, you may first declare val3 as int and in the second declaration you may declare val3 as const int.
Just try and note the difference. Happy coding!

Thanx, i got it.


text:
Programming Servo How To Get -90 Degrees
as the question title states, how will I go about turning the servo opposite of 90 degrees?
I have written my code as such;
  // Turn servo to the right
  if(x > 520 && y < 510 && y > 490){
  servo.write(0);
  delay(50);

  //Turn left
  }else if(x < 490 && y < 510 && y > 490){
    servo.write(180);
    delay(50);

 //Turn backwards
} else if(y < 490 && x < 520 && x > 490){
  servo.write(-90);
  delay(50);

Obviously -90 isn't an actual degree on the servo, and it will only turn between 0 and 180. I was therefore wondering if there was any other way to code it?
The servo is connected to a joystick, and the plan is to built a 360 degrees vertical and 180 degrees horizontal turret of sorts. Every other command works, and when I replace -90 with 90 degrees, it works as well. So it is wired correctly.
Of course I would have to add another joystick and another servo later on, but at this stage I am simply testing my own coding skills.

There is no such thing as -90°. Just change your concept of what is "straight ahead"...

It is unclear, how the joystick is connected to the servo and which movements you exactly need on the joystick.

@chrisl In reality I wish for the servo to mimic the joystick.
But since this is first time I am programming with servos and a joystick, I simply wish for a simple up, down, left, right, upper- left and right corner and then lower- right and left corner.
I am basing this on a system, where the directions depending on whether or not x and/or y are above or below the middle value of 510-ish. As you move the joystick from vertical left to right it will increase from 0 to 1320, and the same for horizontal down to up. The x and y variables in my program are based on those values.

See my edited answer. You need two servos to control a 2 axis joystick.

You say "The servo is connected to a joystick, and the plan is to built a 360 degrees vertical and 180 degrees horizontal turret of sorts. "
That doesn't make sense. How could a joystick rotate 360° in one dimension and 180° in the other dimension?
A joystick does not need an angle greater than 180°. It's mounted to a flat surface, and can only move 180° in two different dimensions, X and Y. (And actually probably more like 120° in each dimension.)
Use two 180 degree servos, one for the X axis and one for the Y axis.
Set the "neutral" position to 0
You can map the range 0 - 1320  to -90 to 90 using a map statement. (or adjust as needed since the range of motion of the joystick is probably less than 180 degrees - more like 120°, like  chrisl said in their comment.)
See this article for info on how a 2-axis joystick works. Specifically look at the section titled "Gimbal Mechanism" a little ways down in the article.

I am not sure that I understand?
The joystick itself already moves 360 degrees? What I need to move 360 is the platform for the turret.
Of course, I could always move it counter to what it should be pointing at, and then move the tilting backwards (i.e 180 degrees ) but that seems awkward to me personally.
But mapping it -90 to 90, will still only result in 180 degrees. This means the target can simply just move behind the turret.

What type of joystick do you have? A normal joystick (like on the controllers of game consoles) rotate maybe 120 degrees on the x and the y axis. The axes are independent. So you would need 2 servos, each moving 120 degrees. Where is your joystick moving 360 degrees?

You don't want one 360° rotation. You want to tilt it on separate X and Y axes by ±90° each (actually probably more like ±60 degrees, as chrisl said in their comment.)

Oh, but I would have 2 joysticks.
One normal joystick with a normal code, that will output the normal range of 0-180 degrees on the tilt.
Meanwhile, the other joystick will have a seperate "x" and "y" axis. Of course, I could just use the y axis for all backwards facing degrees by "y = y-output + 180". So that if y = 1, it will be 181, and therefore backwards. And for the forward facing degrees (i.e 0-180) I can simply output the x-value.

Now that is my train of thought, does this change your suggestion? As I understand it, you believe that I am limited to a total range of 180 degrees (in actuality 120 degrees), is that why you suggest using only 180 degrees of motion? Or am I mistaken?

Why are there now 2 joysticks? It is totally, what exactly you are trying to do. Maybe you should draw schematic pictures, how everything is connected and where your 360 and 180 degrees are

If I understand correctly, you only need to move your servo through 180 degrees total, from one limit to the other, but you want -90 to represent one of the limits and +90 to represent the opposite limit? If so, just add 90 to the servo angle before you send it:
servo.write(angle+90);

This turns -90 into 0, 0 into 90, and 90 into 180. You get to use the coordinates that you like (-90 - +90) and the servo sees the coordinates it needs (0 - 180).
This is a simple case of mapping; there is a map() function that can do this for you for all mapping all kinds of ranges, one into another. Mapping (-90 - 90) into (0 - 180) is so straightforward that the map function really doesn't add anything, but in other cases it's handy to know about.

Normal servos only have a range of 180°. You can give yourself an "offset", so you have -90° to 90°, but you only ever get 180° range. You can't go -90° to 180°.
Using mechanics (outside the scope of this site) you can multiply your movement (think gears) so that your range is bigger.

This seems too advanced for me in terms of the mechanical aspect.
Would it possible to use a DC motor for the base and a function, that replicates the movement of the joystick? Or do you see any immediate problems with that?

You can get special servos with wider ranges, and you can get "continuous rotation" servos that go round and round, but you don't specify an angle with those, but a speed. If you want to use anything other than a "normal" servo you will need some form of feedback to know what angle you're facing.

Thank you, are these "wide range" servos called anything special? When I google "360 degree servo" I simply get ads for regular servos.

@GeorgeWTrump, I'd recommend a stepper motor. Also look into motors with quadrature encoders and index pulses. They can be used to set position. Any of the above can rotate continuously in either direction while still knowing it's angle from 0 to 360 deg or -180 to +180 or however you want to think about it. With the proper control algorithm and PID loop, you can also command exact position. This is more advanced, however.


text:
ESP8266 EEPROM Reading extra character
I am very very new to ESP Programming.
I am trying to store Strings into EEPROM of ESP8266.
I am storing the string into eeprom successfully but while reading it from EEPROM extra character 'd' is coming into the picture. I assumed it is a character to end the string but it does being used into the String url and the further code of connecting to server is throwing error due to wrong URL.
My question is how to resolve this issue.
void writeString(int addr, String data)
{

   uint8_t size = data.length();
   for (uint8_t i = 0; i < size; i++) {
      EEPROM.write(addr + i, data.charAt(i));
   }
   EEPROM.write(addr + size, '\0');
   EEPROM.commit();

}

String read_String(int addr)
{

  String result = "";
  uint8_t count = 0;
  while (true) {
     char byte = EEPROM.read(addr + count);
     if (byte == '\0') {
       break;
     }
     else {
       result.concat(byte);
     }
  count++;
  }

 result = result.substring(0, (result.length()));
 return result;

}

Function Calling Snippet:
//Writting to EEPROM
String inputMessage1 = "myurl.co.in";
writeString(10, inputMessage1);

//READING from EEPROM
String hostStr = read_String(10);
Serial.print( "Connecting to Server... "+hostStr);

OUTPUT
Connecting to Server... myurl.co.ind

Include serial print into your routines and do a step by step debug on the serial monitor Its like finding Waldo.


text:
esp8266 OTA issue
I have uploaded the BasicOTA sketch in Esp8266-12e.
I am written one program, when i try to upload it first time in Esp using the OTA port it gets uploaded successfully, but when i try to upload any sketch after that it does not work.
The console responds with No Answer.
After searching on internet many people have asked to check the sketch size. To check if size matters or not i tried with blinking sketch, and same issue happens there too.
The sketch only gets uploaded in first time.
Can anyone guide me resolving this issue.

the uploaded sketch must use the ArduinoOTA library to handle the next upload

Things to check:

Partition arrangement selected. You have to make sure to keep the same partition arrangement between uploads.
Partition arrangement selected. You have to make sure that the partition arrangement you have chose supports OTA uploads.
You have to reset the ESP8266 manually after your USB upload. You can only do an OTA update to a sketch that has booted in "run" mode, not "boot" mode.
You have the right IP address / hostname selected? (I don't know how that is handled in the Arduino IDE...)
You must upload an OTA-enabled sketch for OTA to continue working.

I honestly believe that this issue is related to the fact that the sketch uploaded through OTA doesn't itself include the OTA code to allow for further OTA upload. For example, the Blink sketch would fail to allow OTA comms as soon as it was loaded. Might want to add another point to your list. I'd post myself, but you've already started a decent troubleshooting list here.

Partition Arrangement Selected-> Do u mean to say flash size ?? its 4MB FS:NONE , OTA:1019kb. 2. How to ensure that. 3. Yes i do reset it manually after uploads. 4. Ip address is confirmed to be correct. i print it on display.

@stevieb Does that mean, i have to include the OTA code in every sketch i want to upload to esp.

@stevieb Good point. Added as point 5.

@javabee Yes, if you don't have OTA code in your sketch then OTA can never work. It's the sketch that provides OTA, not some magic pixie dust.

I think the 5th point has answered my question.


text:
RFID scanner- HZ 1050 Module
I just bought a rfid scanner hz 1050 module at $5 to add to my project,in the module I see a lot of pins to male my connections.
Am getting stuck on the ones to use for arduino.
I will be glad to anyone who helps me out.Thank you.

Link: Quick web-search gave a link to Nick Gammon's excellent blog. Start here: http://forum.arduino.cc/index.php?topic=316450.0

You haven't even told us what the pins are or what connection type the scanner is ... serial? I2C? SPI? something else?

The pins are the 5V GND,D1,DO,TXD..Am getting troubled in the  the last three pins. The module is to be connected to arduino and LCD 12c..


text:
Can Serial be safely used in an SPI interrupt routine
I have anecdotal experience that using Serial.print inside a slave's SPI interrupt routine (ISR) causes issues with transmission. It also seems that interrupts may be called more than once before the main loop can react, so it is difficult to print info from all interrupts. Is this because Serial is inherently unsafe, or too slow? Can Serial be used safely inside the ISR routine?

it is not a surprise that the answer with most votes follows the dogma. but no, Serial print or write doesn't hang in interrupt.  It was fixed in 2013. https://github.com/arduino/ArduinoCore-avr/commit/dbe23685c27cb1467dc84140e4899a0bf8e23248

Serial should be avoided in ISRs because interrupts are disabled inside ISRs, and Serial transmission uses interrupts to operate. Better to have the ISR set a flag that is read in the next iteration of loop() to print the desired info.

Hardware Serial write(byte) function in Arduino AVR core will work in interrupt. It checks if interrupts are disabled and if yes and the buffer is full, it executes directly the interrupt function, which pushes bytes from buffer to output.

@Juraj is write or print re-entrant?

it doesn't need to be re-entrant

@Juraj That is interesting to know. I was unaware of that behavior

@josecanuc, it contradicts you answer, but the question is about SPI slave where it can mess with timing or I don't know what else

Feel free to vote my answer accordingly. I did write it as it applies more generically and does not address the specific issue of slave SPI ISR. Better answers are encouraged and should be voted up!

The biggest problem I had was when the tx-buffer was full and I did an Serial.print inside an ISR. Using the highest baudrate fixed the issues I had. But I only used it for debugging, and won't really trust it for production code.

@Gerben, it was before this? https://github.com/arduino/ArduinoCore-avr/commit/dbe23685c27cb1467dc84140e4899a0bf8e23248

Hardware Serial write(byte) function in Arduino AVR core will work in interrupt. It checks if interrupts are disabled and if yes and the buffer is full, it executes directly the interrupt function, which pushes bytes from buffer to output.
(All write and print functions of hardware Serial use the write(byte) function to send data.)
It depends on other factors if a long time spent in interrupt handler will disturb things.

In general, interrupts should run as fast as possible. This is especially true when using SPI, since in the slave's ISR, the slave needs to put a byte in the SPI Data Register (SPDR) before the next transfer occurs. Thus it is good practice to avoid Serial transmission entirely in an interrupt, since in simple interrupts it can be by far the slowest portion of the interrupt.


text:
ESP8266 + HC-05 on same arduino
I'm absolutely new to arduino, so please excuse me if this is a noob question.
I want to use a ESP8266 esp-03 Wifi module with a HC-05 bluetooth module together with my arduino uno.
Unfortunately both use the TX and RX pins on the board.
Is there a way to use both, the wifi and the bluetooth modules?
Or do I have to purchase a wifi board?

You can (just about) use any combination of two of:

Serial to PC,
HC-05
ESP-03

You have, basically, a hardware UART (pins 0/1), and a software UART (any pins of your choice).
Only the hardware UART can be used for communication with the PC, and you can only reliably use one instance of SoftwareSerial.
So, you could:

Use Serial to the PC (0/1) and HC-05 (SoftwareSerial, your choice of pins), or
Use Serial to the PC (0/1) and ESP-03 (SoftwareSerial, your choice of pins), or
Hardware Serial for ESP-03 (0/1) and SoftwareSerial for HC-05 (your choice of pins), or
Hardware Serial for HC-05 (0/1) and SoftwareSerial for ESP-03 (your choice of pins)

If you want anything more complex than that then you need to use a board with more than one hardware Serial port (such as a Mega2560).

Thank you for your reply! So do I understand correctly, that when I use the serial port (e.g. to program the arduino) I cannot use the hardware UART pins at all? I also bought the Mega2560, are the 14TX3, 15RX3, 16TX2, 17RX2, ... pins the hardware serial ports you are talking about?

You can't have anything connected to the UART pins when actually doing the programming. Once programmed you can't use the UART pins and communicate with the PC. I.e., if you want to use the UART pins for a peripheral you will (most likely) have to disconnect it to get the programming to work, and you won't be able to debug your program through serial.  And yes, those are Serial2 and Serial3 etc that you point to there.


text:
Arduino UNO socket
As I learnt so far is that Arduino UNO board has a socket for power input. The available power input range is between 7V - 20V, but the optimal usage range is 7V-12V.
Here I am wondering:
  ---> if there is a USB port for power supply, why do we need a power input socket?
  ---> Or there is a battery on-board to charge?

With a 5v power supply or power bank, the usb connector can be used. The dc barrel jack is for a power supply or battery pack of 7v to 12v, I prefer 7.5v to 9v.

The Arduino Uno has no on-board battery. The dc barrel jack is provided to give you more options to power the Uno, which is handy for stand-alone applications (without USB-connection to a computer) and/or battery powered applications. It can also supply more current than the USB-connection, which can be necessary when using shields.
The current taken from the usb port is limited to 500 mA by by an auto resettable fuse on the Uno (the voltage is not regulated by the Uno). This is the same amount of current as the USB 2.0 standard specifies that a standard down stream port (computer USB port) should be capable to deliver (for USB 3.0 this is 900 mA).
The power taken from the barrel jack is regulated to 5 V by a voltage regulator, the NCP1117ST50T3G. To work properly, this regulator needs a voltage difference (dV) between input and output of 1.2 V (depending on output current and ambient temperature). This means that the minimum voltage on the barrel jack is 6.2 V.
The regulator has an internal thermal limiting circuit that limits the junction temperature to ca. 175°C. This determines the maximum power dissipation (= output current times dV) the regulator can handle at a given ambient temperature. The maximum allowable power dissipation also depends on the size of the copper pad under the cooling tab of the regulator. As I don't know this size it is difficult to calculate de maximum power dissipation precisely, but my guess is that at 25°C and 6.2 V a power dissipation of 1 Watt should be possible. This gives a maximum output current of 1/(6.2-5.0)=0.833A=833 mA. Of course, at higher input voltages the maximum output current is lower. For example at 12 V: 1/(12.0-5.0)=0.143A=143mA.

Many projects (robots, drones, 3D printers, light control, art) made with Arduino have actuators (relays, motors), lights and displays which require a 9 or 12 V power supply. To use this power supply for the Arduino too, you need a voltage regulator which converts the voltage level and filters the noise and fluctuations created for example by that actuators.

Also keep in mind the reverse polarity protection diode that follows the barrel jack after which current goes into the 5V regulator. The diode is only rated for 1A, if one is connecting to Vin as a source for 9V or 12V for other parts of a project.


text:
2 Fingerprint scanner using 1 arduino
I have problem in using 2 fingerprint scanner in arduino mega, every time I need to register I need to go and register my fingerprint on each fingerprint module,

what i am planning to do is when I registered on 1 fingerprint scanner
  then the other fingerprint module automatically registered the
  fingerprint and vise versa.

Can anyone help me with my project thanks. btw my project was already working but I have problems in registration of bio-metrics.
here is my code in verifying the registered fingerprint
#include <Adafruit_Fingerprint.h>
int door1 = 8;
int door2 = 11;
Adafruit_Fingerprint finger1 = Adafruit_Fingerprint(&Serial2);
//fplabas
Adafruit_Fingerprint finger2 = Adafruit_Fingerprint(&Serial3);
void setup() {
Serial.begin(9600);

pinMode(door2, OUTPUT);
  pinMode(door1, OUTPUT);
//  pinMode(Buzzer, OUTPUT);
//
  digitalWrite(door2, HIGH);
  digitalWrite(door1, HIGH);

 finger1.begin(57600);
  finger2.begin(57600);
    if (finger1.verifyPassword() || finger2.verifyPassword()) {
    Serial.println("Found fingerprint sensors!");
  } else {
    Serial.println("Did not find any fingerprint sensors :(");
    while (1) { delay(1); }
  }

  finger1.getTemplateCount();
  finger2.getTemplateCount();

  Serial.print("Fingerprint Sensor1 contains "); Serial.print(finger1.templateCount); Serial.println(" templates");
  Serial.print("Fingerprint Sensor2 contains "); Serial.print(finger2.templateCount); Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
}

void loop () {
  getFingerprintdoor2();
  delay(50);
  //Fingerprint Sensor Labas
  getFingerprintdoor1();
  delay(50);
}

uint8_t getFingerprintdoor2() {
  uint8_t p = finger1.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      //Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
     // Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
    //  Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      //Serial.println("Imaging error");
      return p;
    default:
      //Serial.println("Unknown error");
      return p;
  }
  // OK success!

  p = finger1.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      //Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      //Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
     // Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
     // Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
     // Serial.println("Could not find fingerprint features");
      return p;
    default:
      //Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  p = finger1.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
    digitalWrite(door2, LOW);
//    sendsms(textForSMS + " Noah", f1001);
//    Serial.println(textForSMS);
//    Serial.println("message sent.");
    delay(3000);
    digitalWrite(door2, HIGH);
    delay(1000);
   // Serial.print(finger1.fingerID);
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    //Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
//    Serial.println("Did not find a match");
//    digitalWrite(Buzzer,LOW);
//    delay(1000);
//    digitalWrite(Buzzer,HIGH);
    return p;
  } else {
    //Serial.println("Unknown error");
    return p;
  }

  return finger1.fingerID;
}

uint8_t getFingerprintdoor1() {
  uint8_t p = finger2.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      //Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
     // Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
    //  Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      //Serial.println("Imaging error");
      return p;
    default:
      //Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger2.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      //Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      //Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
     // Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
     // Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
     // Serial.println("Could not find fingerprint features");
      return p;
    default:
      //Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  p = finger2.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");

    digitalWrite(door1, LOW);

   delay(5000);
    digitalWrite(door1, HIGH);

  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    //Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {

    return p;
  } else {
    //Serial.println("Unknown error");
    return p;
  }

  // found a match!
  return finger2.fingerID;
}

And here is the problem code where I need to register on both Fingerprint scanner:
#include <Adafruit_Fingerprint.h>
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2);

Adafruit_Fingerprint finger2 = Adafruit_Fingerprint(&Serial3);

uint8_t id;

void setup()
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit Fingerprint sensor enrollment");

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }
}

uint8_t readnumber(void) {
  uint8_t num = 0;

  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

void loop()
{
  Serial.println("Ready to enroll a fingerprint!");
  Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");

 if (Serial.available()>0)
   switch(Serial.read())
  {
    case 'A':

        id = readnumber();
        if (id == 0) {
           return;
        }
        Serial.print("Enrolling ID #");
        Serial.println(id);

        while (!  getFingerprintEnroll1() );

      break;

       case 'B':

        id = readnumber();
        if (id == 0) {
           return;
        }
        Serial.print("Enrolling ID #");
        Serial.println(id);

        while (!  getFingerprintEnroll2() );

      break;

}

}

uint8_t getFingerprintEnroll1() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  Serial.print("Creating model for #");  Serial.println(id);

  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }
}

uint8_t getFingerprintEnroll2() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger2.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger2.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger2.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger2.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger2.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  Serial.print("Creating model for #");  Serial.println(id);

  p = finger2.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  Serial.print("ID "); Serial.println(id);
  p = finger2.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }
}

Please help I am stuck in this situation..

did you do that and works properly?

The library, that you are using, doesn't seem to support exporting or importing fingerprints. Though if you look into the user manual of the fingerprint sensor at the Adafruit site, there are two commands mentioned, that seem to do what you need:

6.2.2 Upload image:  UpImage
Description: to  upload  the  image  in Img_Buffer  to  upper  computer.  Refer  to  1.1.1  for  more  about image buffer.
6.2.3 Download the image: DownImage
Description: to download image from upper computer to Img_Buffer. Refer to 1.1.1 for more about the image buffer.

These commands can be used to read or write the image buffer, where an image is stored, when it was taken by the sensor (this is only about the image data, not about the recognition or enrolling; that has to be done after loading the image to the buffer). I could not find corresponding functions in the library, so I guess it doesn't support this. So, to get what you need, you need to stop using the library and handle the things yourself (or - maybe better - extend the library to incorporate that feature).
The manual has no good documentation about these functions and the datasheet, that Adafruit has, is in Chinese, so I couldn't read it. You will need to try it out and see, what you get, when issuing the mentioned commands (unless you can read Chinese and there is more useful information in that datasheet).
I guess after requesting the upload of the current image, the module will send data packets in the configured package size, until it has transferred the whole image (Note, that it will only send 4 bits for every pixel over UART, meaning 16-greyscale image). After than you could request the download on the other module. After the acknowledgement packet, I guess you need to send the image data in the same format, as you received it from the first module, in packets with the configured packet size.
When configured to the same packet size, you could request upload and download at the same time for each module and simply let the packets pass through. After transferring the image, you can start the recognition on both modules.

thank you I will look for it ... but can I use that in arduino?

Yes you can. These are just commands issued over UART. You might only get into problems, if you try to buffer the full image in the Arduino. But as I wrote, you can pass the packages through, directly to the other module, so that you only have about 2 packets at the same time in the Arduino

thankyou!!! can you send me a link or guide on where should I start working plss

Start with the library from Adafruit, that you are already using. Try to understand, what the code does. Then you can use the manual, that I linked, and try to trigger the download/upload commands. If that works, you can extent the library for your use. There is no tutorial for doing that, so you need to dig into that topic yourself.


text:
Internet switching
is it possible to switch internet connection from esp8266 wifi module to gsm sim 900A internet if the arduino detects that the esp have no internet connection and vise versa? Thanks

yes, it is possible.

Thank you!, can you guide me how to do it? I'm stuck in this situation, please

What did you try and what happened? Show your code please!

https://arduino.stackexchange.com/tour

@TimeGold, your question asks a simple yes/no confirmation ... if you actually need help with your code, then you need to rewrite your question


text:
Read from Blynk terminal number to arduino
I have a problem in sending numbers from blynk terminal to arduino serial monitor. When I send any number from blynk terminal the arduino always getting 1. How can I get any number please help me. Thank you.
Here's my code
BLYNK_WRITE(V0){
  int pinValue = param.asInt(); // Int Value
  String i = param.asStr(); //String Value
  Serial.println(pinValue);

 if(i == "A"){
      Serial.println("Ready to enroll a fingerprint!");
      Serial.println("Please type in the ID # (from 1 to 127) you want to delete...");

      Blynk.virtualWrite(V0, "Ready to enroll a fingerprint!");
      Blynk.virtualWrite(V0, "Please type in the ID # (from 1 to 127) you want to save this finger
      as...");

      uint8_t num = 0;

        while (num == 0) {
          while (! Serial.available());
          num = Serial.parseInt();
        }
      Serial.print("Enrolling ID #");
      Serial.print(num);
 }
}

The value output of num is always 1 even I sent a different number.

the number is sent as string. so use param.asStr(), then convert it to number

I already know that, but the actual problem was any value that was sent to arduino serial monitor becomes 1

how do you know?. you don't print it. you print the int value

I tried it earlier, the value always get 1. please help


text:
Arduino wait for incomming data from blynk terminal
I need to add wait command in code where it waits the next input value from blynk terminal to arduino? How can I do that? please help, I will appreciate your help, Thank you.
Here is my code
BLYNK_WRITE(V0)
{

     String i = param.asStr(); //String Value from blynk

      if(i == "A"){
          Serial.println("Ready to enroll a fingerprint!");
          Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");

          Blynk.virtualWrite(V0, "Ready to enroll a fingerprint!");
          Blynk.virtualWrite(V0, "Please type in the ID # (from 1 to 127) you want to save this finger");

int numb = i.parseInt; //I need to add a command here to wait for the next blynk terminal value

  Serial.print("Enrolling ID #");
  Serial.print(numb);
}}

Possible duplicate of Read from Blynk terminal number to arduino

No, It was a different problem

you can't wait in blynk handler function. let it end. it will be called with the next input. use some variable to remember in which step of user input the code is


text:
avrdude: stk500_recv(): programmer is not responding, arduino pro
I'm trying to upload a sketch to upload the blink sketch to an arduino pro using a SparkFun Serial Basic Breakout (on Ubuntu 18.04).
setup
Within the arduino IDE I have the following set-up:

Tools -> Board: Arduino Pro or Pro mini
Tools -> Port: /dev/ttyUSB0
Tools -> Programmer: USBasp

I have connected:

DTR sparkfun to DTR on arduino
RX1 sparkfun to RX1 on arduino
TX0 sparkfun to TX0 on arduino
VCC sparkfun to VCC on arduino
GND sparkfun to GND on arduino

the error
The error that I get is as follows
Arduino: 1.8.13 (Linux), Board: "Arduino Pro or Pro Mini, ATmega328P (5V, 16 MHz)"

Sketch uses 924 bytes (3%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
/home/cmhughes/Desktop/arduino-1.8.13/hardware/tools/avr/bin/avrdude -C/home/cmhughes/Desktop/arduino-1.8.13/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:/tmp/arduino_build_457079/cmh-Blink.ino.hex:i

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/cmhughes/Desktop/arduino-1.8.13/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/home/cmhughes/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
...

The error message continues, and tries 10 attempts.
the question
I've tried many different things, including: changing the RX1 to TX0 connections, using a different FTDI serial adapter, trying a different USB cable, trying on Windows operating system.
What else can I try to see if I can progress this?
arduino pro

SparkFun Serial Basic Breakout - CH340C and USB-C

wire RX to TX. transmit to receive

@juraj many thanks; if I've understood you, then that's on the list of things that I've tried ....

it is not a troubleshooting suggestion. it is how it must be

reset the Arduino while avrdude attempts the upload

@Juraj many thanks, that was very helpful. Using both of the things that you detailed, I have now been able to upload onto my arduino pro. If you'd like to post an answer, I'll gladly accept it. Thanks again.

Hello friend ! How Arduino detect you switched to programming mode ? Need an Reset signal before upload sketch(Another important things: All reset signal got timeout conditions). So use push button before upload !

Many thanks, @dsgdfg, that's very helpful :)

the DTR connection should make the reset, but it looks like it doesn't work here

DTR isn't compatible both boot or program things ! DTR will be reset device on standart communication(so every time need disable DTR for talking with Arduino)

@dsgdf The original design for the Arduino Pro Mini  includes a capacitor between the board's "DTR" header position and the ATmega328;s RESET pin - this is intended to facilitate programming through an "FTDI Friend" or similar USB-serial adapter which then uses the DTR line to reset the ATmega328 and cause it to run the bootloader that waits for serial program upload or which times out and runs the previously uploaded "sketch". See https://store.arduino.cc/arduino-pro-mini. So you don't normally have to disable or re-enable DTR anywhere.

@RedGrittyBrick That might be true. However, capacitors used for delay in circuits without guarantee of feeding voltage do not work healthy! (see : SYNC error). Another point Not all communication converters contain DTR!

The upload procedure needs to reset the ATmega328 by use of DTR. This invokes the bootloader code in the ATmega328. If there is a problem with your DTR connection, you have to instead manually press the RESET button at the appropriate time.
So probably your connection to DTR was faulty or. less likely, there could be a fault in the onboard capacitor between the Pro-Mini's "DTR" header and the ATmega328 RESET pin
https://store.arduino.cc/arduino-pro-mini -> Documentation

Automatic (Software) Reset
Rather then requiring a physical press of the reset button before an upload, the Arduino Pro Mini is designed in a way that allows it to be reset by software running on a connected computer. One of the pins on the six-pin header is connected to the reset line of the ATmega328P via a 100 nF capacitor. This pin connects to one of the hardware flow control lines of the USB-to-serial convertor connected to the header: RTS when using an FTDI cable, DTR when using the Sparkfun breakout board. When this line is asserted (taken low), the reset line drops long enough to reset the chip. The Arduino software uses this capability to allow you to upload code by simply pressing the upload button in the Arduino environment. This means that the bootloader can have a shorter timeout, as the lowering of the reset line can be well-coordinated with the start of the upload.

Might have to do with the usb chip on that being not as widely supported as the official chip Arduinos use on their Uno’s, Mega’s, etc. the ch340C one sometimes needs drivers so look online for those drivers and download them.


text:
ESP32 Pins won't fit in solderless breadboard
I bought an Adafrut Huzzah32 ESP32 for an IoT project. When the ESP32 arrived, I attempted to fit it into my existing breadboard, but I immediately noticed that no matter how hard I pushed, the pins wouldn't fit into the solderless breadboard.
I tried to find others with the same problem with no luck, so I went on amazon and purchased another breadboard (an Elegoo 830 tie-points Breadboard). It arrived today and I'm having the exact same problem. I don't want to use a soderable breadboard at this stage of the project as I'm just starting, but I don't know what else to do at this point.
I've Googled images of other peoples' setups and there pins are snug down in the board. What am I doing wrong? I've included photos below:

As you can see, the power module on the end fits fine but the ESP32 won't go down into the board. At this point, I've tried two different boards (one of those small Arduino ones and this one) with no luck.
Any suggestions?
You can see that the pins aren't even close to being down in the board.

It requires quit a bit of force to push them into the breadboard. Imaging the force of just a single pin, and then multiplying that force by 24. Another solution is to try and see if you can push them in some female headers. And then push those female headers in the breadboard.

@Gerben given that the pins on the MCU point down, can you elaborate on how this would work? The benefit of the breadboard is that it sits in a semi sturdy manner while what I’m picturing you describing would have wires coming out the bottom of the MCU, which would be sitting on top of the the wires on my desk. A photo of what you mean would help heaps, thanks!

Are the pins properly aligned above corresponding holes?

I mean these https://www.adafruit.com/product/2830 . Put the huzzaa in the female end, and put the male end in the breadboards. The legs on these headers are a lot thinner than the pins on the Huzzaa.

@Gerben, thanks. That makes sense. I will give this a try later today.

I ended up taking Gerben's suggestion from the comments and ordering the stacking headers (adafruit.com/product/2830) and plugging the ESP32 into that. The reason it works is because the stacking headers (as Gerben mentioned) are thinner and fit down into the breadboard while the female ports on top are big enough for the male pins coming out of the ESP32.
Thanks everyone!

I understand. These breadboards are pretty difficult to work with. Not only fitting an ESP-32 or similar board is difficult, these breadboards are not broad enough to expose all the GPIOs on both the sides.
I had solved this problem in this video. Do have a look. It might be helpful
https://youtu.be/CQlbE1x2i2g

I think the problem they're having really is just the pain of physically inserting the module into the board.  I'm not sure this addresses that, not directly anyway.  That said, it is nice what you're doing there.  When it comes to an answer that's basically a video link, it would help to have something more in the answer, e.g. a still from the video showing the arrangement you've built, so the answer is not entirely dependent on the link.

or you can simply fit two bread boards together and mount the esp on them

(i had to twist the pins a little bit )

Sharing between breadboards halves the force required to push the device into a single breadboard, and also exposes more tie-points per device pin.  Good idea.


text:
How to build a robot that can stop at a certain point using an altimeter
I am thinking about creating a robot that climbs vertically and stops at a certain point. I thought about using an altimiter in order to measure the distance, however, I dont know how to create a code for it. Where would you start with it, can it be done with MATLAB?
Thanks for everything :)

You can use an barometer/air pressure sensor for height, or an acceleromater for relative (height) changes. I don't see where MATLAB comes in.

you are asking the wrong question .... your question should be how do i measure altitude?

Before you consider code, you'll need a way to measure altitude changes. Barometric altimetry (air-pressure based) is probably too crude for the scale of robot you're likely interested in. The change in atmospheric pressure with altitude is (very) appx 1 in-hg/1000ft near sea-level or ~1/2 psi/1000ft. If you want 1 foot altitude precision, you'd need .5/1000 or a pressure measurement good to within 0.0005 psi. A sneeze in the same room could crash your robot! :) ...

... Other means of measurement are likely to be more successful with existing and affordable technologies. If you can work with elevation instead of altitude (height above a surface, like a floor), radar, sonar, or even a sounding line (a fishing line with a weight you drop to the floor and measure how much line you let out) are going to be much easier. You'll need to make these kinds of design decisions before you'll be ready to write code.

have fun playing with the Arduino and some sensors! It is a great platform to learn. For your task, look into the Bosch sensor modules BME280 (pressure with temperature and humidity) or BMP280 (just pressure). You can expect maybe +-1 meter of accuracy. Or check the precision version BME388 that could give you +-50cm. Go to the adafruit shop and try a few of the breakout boards. They provide great library and documentation support.
In order to get absolute altitudes, you need to factor in ambient air pressure. A good source for that are METAR reports issued for aircraft. There are many online sources where you can get the so called altimeter setting for an airport close to you. Airplane altimeters actually just show the altitude above a standard pressure plane, so you need to compensate for whatever pressure the current weather gives you.
For higher precision, you pretty soon have to integrate barometric pressure, GPS altitude, and maybe other sensors, with some serious math. This is where MATLAB fits in.


text:
8266 analogRead(A0) always 1024
dear member.
I have 4 ESP-12 averything OK but one chip behave weird.
always return 1024 on analogRead(A0);
once use ADC_MODE(ADC_VCC) and reflash using ADC_MODE(ADC_TOUT); and never back to normal, is my Chip Error..?
FM 4MB
ArduinoIDE 1.8.13
BR 115200
PS 80MHz
int iVal = 0;
void setup() {
  Serial.begin(115200);
  delay(999);
  pinMode(A0,INPUT) ;
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  iVal=analogRead(A0);
  Serial.println(iVal);

  if (iVal > 900) digitalWrite(LED_BUILTIN,HIGH);
  else   digitalWrite(LED_BUILTIN,LOW);
  delay(720);
}

ADC_MODE(ADC_TOUT); still return 1024 on analogRead(A0); while other 3 Chip just fine

If 4 devices are working correctly, but 1 device not, with the very same program, there seems to be a hardware difference. Check for short circuits, open wires, bad soldering, and so on. You might even have a defective device.

Sounds to me like the ADC has been overpowered and the ESD protection diode has failed short.

@Majenko so, should i let it go? you are right. once, i was powering switch accident between vcc and ground about 2 minute. is it problem?
and how to accept your comment as solved?

First be sure your voltage on the analog input is less then 1V and greater then zero, that is the range for the input. If nothing connected no guarantee what you will get. Just guessing, no circuit or definition.

I have voltage devider, also multimeter test trying to measure 0,6 volt still return 1024. also 0,8 Volt input and measuring after Voltage devider get 0,2Volt still return 1024.

I assume you are saying you get 0.6V reading on the pin with a multimeter, if so consider the unit toast. Probably good for digital usage but for A/D you need another board.  The only real test is to try another board or add an external A/D.

agree with you @Gil, i was order ather board, let this one go, or use without ADC. seem my board ADC has been overpowered.. because weird on testing: ADC pin floating(no conection) measure with voltmeter always 2,8Volt

Actually you did a good job and most of the work.  These things are very hard to diagnose unless it is on the lab bench in front of you.


text:
Weird RTC DS3231 Output only when saving the dates to variables
I am sorry to ask this question as I think it has more to do with my mediocre C++ programming skill than with the arduino.
I do have a project where I want to use an RTC DS2131. I started out by using all the separate examples of the modules I need and put them together. But the RTC give me a headache :-(
The example ran fine where it just output the date to the serial port. Somthing along this:
Serial.print(RTC.getDay());
Serial.print("-");
Serial.print(RTC.getMonth());

Now I want these values in different variables because I want to save them on an SD card as well.
Thus I came up with this simple test program:
#include <Wire.h>
#include <RTC.h>

static DS3231 RTC;

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

void loop()
{
int yearNow;
int monthNow, dateNow, hourNow, minuteNow, secondNow, weekNow;

if (RTC.isRunning())
  {
    yearNow=RTC.getYear();
    monthNow =RTC.getMonth();
    dateNow=RTC.getDay();
    weekNow=RTC.getWeek();
    hourNow=RTC.getHours();
    minuteNow=RTC.getMinutes();
    secondNow=RTC.getSeconds();

    Serial.print("Weekday: ");
    Serial.print(weekNow);
    Serial.print('  Time:');
    // Finally the hour, minute, and second
    Serial.print(hourNow);
    Serial.print('-');
    Serial.print(minuteNow);
    Serial.print('-');
    Serial.print(secondNow);
    Serial.print(" ##  ");
    Serial.print("Date: ");
    Serial.print(yearNow);
    Serial.print('/');
    Serial.print(monthNow);
    Serial.print('/');
    Serial.println(dateNow);

  }
}

Now I would expect this output:
Weekday: 4  Time:16-10-36 ##  Date: 2020/7/28
But this is what I get:
Weekday: 42591416-10-36 ##  Date: 2020/7/28
As a sidenote the variables in this sketch are declared as "int". After having looked into the header files of the library I tried uint8_t resp. uint16_t for the year.
But nothing changed.
I am sorry but I have no clue as what beginner mistake I am achieving this time?? :-(
Thanks for your help.

You used single quotes instead of double quotes. Single quotes are for single characters. Double quotes are for strings (or character arrays).
Serial.print('  Time:');

should be
Serial.print("  Time:");

Thanks. I thought " and ' are interchangable.

They are in javascript or PHP, not in C/C++.


text:
Baud rate of Arduinos bootloader
I am learning UART  and the problem that i have is understanding what happens when i send serial data to my PC via USB which is built in to the Arduino uno board.
For incoming serial data i am using Terminal v1.9b and it basically lets me to set some parameters and listen to incoming data on Software serial port and or write to it.
The process:

Atmega328p's Baud rate is set to 9600
Terminal connects to it (it performs a reset) and i get my data in.

Very simple, it all works and i don't have a problem with it. What my question is: I assume that my PC doesn't talk to atmega328p directly since it has no USB interface. it talks to a bootloader chip which converts the USB to UART and then i receive that message on my atmega328p. How does that chip know which baud rate we agreed to. OR "Terminal" sends the baud rate to that bootloading chip via usb protocol and it sets its UART settings ?

https://cdn.sparkfun.com/datasheets/Dev/Arduino/Other/CH340DS1.PDF

The bootloader runs in the 328, and just as your application programs do, it sets a UART baud-rate for uploading programs to the Uno.
Current bootloaders use 115200 baud for upload; the most recent previous ones used 57600 baud. Setting that is part of the bootloader code. Whatever your application program last set for a baud-rate doesn't matter; if you reset the Uno, the bootloader sets the UART to the known upload baud-rate, and waits briefly for the PC to begin an upload, and jumps to the currently loaded application program if no upload is begun.
Your PC's Arduino IDE configuration is written to use the known bootloader baudrate (you can see that in the avrdude command). In fact, since I have some boards with soldered-in chips with the older, 57600 baud bootloader burned in them, I have two Uno-board configurations in my IDE; one for those older chips, and one for the current ones.

Thanks for the answer, yeah i figured what bootloader is, and my question was not asked correctly. Since i have another USB to serial converter it shows up as a COM device on my computer. What would it take to actually make this device appear as USB storage for example. would i need to write the driver for it ? and how would i apply the driver to the chip if i have no way of changing it's PID.

This is really a new question, but the short answer is, you'd have to reprogram the Uno's USB processor (Atmega 8U2) to act like whatever other kind of USB device.


text:
How to Protect GPIO when using long wires?
I want to connect a normal toggle switch with one of the gpios pins of a tasmotized esp01 with a wire about 20 feet in length. When I tried this before, I lost the GPIO pin mostly due to the high current drawn from GPIO because of the long wire. How can I limit current and protect the gpio and esp completely?

There are reasons why technology such as rS232, RS485 or 4-20 mA DC loop exist, not just for providing isolation, but for ability to send data over twist pair for distance, with noise immunity and without signal degradation.

Thanks for the tips. I have seen one more solution to protect GPIO pins which was never mentioned here. This uses optocouplers. The anode or the cathode of the optocoupler can be connected through a switch to vcc or ground respectively. With respect to the optocoupler a series resistance will also needed to be used. The GPio and ground are connected to the 3 and 4 pins. when the switch is engaged, the 3 and 4 pins are connected.
The limitation is that not all GPIO can be used as some needs physically pulled to ground like Rx pin of esp8266.

You don't say how your switch is connected.
The standard way to protect a GPIO pin is with a series resistor and ideally a couple of Schottky diodes to clamp it to the supply rails.
Unless you're expecting particularly high voltages or require high speed data then around 100 ohms in series is reasonable.
The diodes go from the input pin to the processors power and ground pins. They are connected so that if the input is between 0 and 3.3 V they are reverse biased and have no effect. But if the input goes above VCC or below GND then the appropriate diode turns on and clamps the voltage. The series resistor limits the current that can flow in this situation and so prevents the diode from getting overloaded. In the image below this means pin 1 of the BAT54-S (the lower right one) goes to GND, pin 2 to 3V3 and pin 3 to your signal. Watch out, different manufacturers sometimes number the pins in different orders.
In theory the diode isn't needed. The chip will include the equivalent diodes internally. However they aren't particularly good ones and will be more susceptible to failure, counting on them is never a good plan. The external ones will clamp sooner and harder and are easier to replace if something does fry.
Just for clarity the resistor is on the outside of the diode. The signal path is: Outside world - resistor - clamping diode - ESP32 pin.

You can use a resistor with a transistor in order to control something that requires more power.  This will protect your io pin. Values depend on what you are specifically connecting to the io pin.

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


text:
ESP32-Cam No Response and Unable to Program - Timed out waiting for packet header
I recently purchased an ESP32-CAM but have had no luck in programming the board or getting any response whatsoever. I first tried to program it using the an FTDI programmer and the Arduino IDE (following the steps from this tutorial: https://randomnerdtutorials.com/esp32-cam-video-streaming-face-recognition-arduino-ide/).
I used this exact wiring diagram:  but got the Timed out waiting for packet header error message. This was with the jumper on the FTDI on the 3.3V section.
Other things I've tried:
-Moving jumper to 5V, powering ESP from 5V pin
-Powering ESP from external 5V source (Arduino pin)
-Powering ESP from external 3.3V source
-Switching computers (Linux and Windows)
-Programming board directly from Arduino (bypassing FTDI)
-Various combinations of pressing/holding reset button during flash process
The other thing is that there is no LEDs that turn on when the board is powered. I couldn't find a concrete reference online that said an LED turns on when the device is on, but I assume the one LED would at least flash or something. Also monitoring the serial output with putty during boot did not yield any output. I'm all out of ideas and I am just starting to suspect that the board is completely dead. Any ideas would be appreciated, thank you.

the FTDI can't supply enough current for the ESP32 from the 3.3 V pin

@Juraj was right, connecting 5V to VCC worked! Seems like the diagram above is wrong then because the pin labelled 3.3V on the ESPCAM32 is just an output pin. The only issue I have having now is that my board is extremely hot when doing it this way, too hot to touch in most parts. Is this due to this connection or a different issue

so I was not right. in the schematic Vcc pin is connected to both 5 V and 3.3 V. is there some jumper next to the Vcc pin, which I can't see on photos? use 5 V pin to power the board over voltage regulator. schematics from Adriano's link https://github.com/SeeedDocument/forum_doc/blob/master/reg/ESP32_CAM_V1.6.pdf

there are solder bridges labeled 3.3 V and 5 V next to Vcc pin

Yes I was going to say VCC has a bridge to 3.3V and 5V so it is likely an additional output based on the input power. I am still having issues with this chip, I was able to upload the one time by connecting 5V from FTDI to VCC on ESP. Now that is no longer working and it seems like the device is trying to boot but failing (I can see jumbled up output on a serial output when it tries to boot).

I'm not sure if maybe it is not getting enough power, I think I'll try powering it with a lipo to give it more current, and maybe slightly above 5V, like 5.3 or so since there is a regulator. The yellow square with the +/- is also lighting up, when powering now, not sure if this means low voltage or something. Couldn't find any documentation on that.

to run the sketch remove jumper from io 0. by yellow light you mean the camera's flash light? on USB it should not have problem with current draw, but the manual recommends capacitors on 5 V Vcc to cover current draw spikes by WiFi

Yes I have removed the jumper from io 0. Yes it is quite bright so it is probably the camera's flash light. Weird that it worked to upload once then with the same setup it hasn't worked since then.

to upload wire io 0 to ground again

Yes I have been toggling to io wire appropriately. I think the board is just bricked I ordered another one and I'll see if it works. If there are any other suggestions I'm all ears

esp32 can't be bricked. the bootloader is in ROM.

You're right. There is no LED when you power up your ESP32 cam. So this is normal.
Try to power it with the 5V, so you can power it from your USB instead of the 3.3V regulator of your FTDI. The ESP just need 50mA when in programming mode, so it should not be a problem for your FTDI.
Do you see anything on your serial output? Once you connect it in this way, you should set the baudrate to 115200 on your serial terminal and see some characters.
Then, try to program it.
Once you see the output "...___...", press the reset button! Since you are just connecting RDX and TDX, you have to manually press "RESET" on your ESP32 module.
At this point the ESP will reset and enter in the programming mode.

io 0 is wired to ground on the picture, so any reset or power-up will put the esp32 in flashing mode forever. no need to wait for ...___...

@Juraj: if he get the "Timed out waiting for packet header error message", the ESP is not in flashing mode or the RX/TX are inverted. If he get some characters on the FTDI, then the RX/TX are connected in the right way and the ESP is not in flashing mode. I can't see any other reason why it should not be able to connect.


text:
L298N Dual Motor Controller Enable Pin has power but motors not working
I am trying to get the L298N to work with a simple DC motor.
For now, I have simplified the setup and the code to the basics to try to get it to work. I am using the following wiring setup with no button or pot:
Only 1 motor, I am using a 2S lipo which I measured the voltage to be 7.8V which should be enough. The DC motor works when directly powered from the battery and when power with ~5V from an Arduino so I know it is not the issue.
My code, simplified from this tutorial: https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/
#define enA 9
#define in1 6
#define in2 7

void setup() {
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  // Set initial rotation direction
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
}
void loop() {
  analogWrite(enA, 255); // Send PWM signal to L298N Enable pin
}

I can measure the voltage at the input, it is good 7.8V. No voltage on motor output pins. In1 has voltage of 3.0V and In2 has 0V which corresponds to the code. However, Enable1 has 0V which doesn't make sense. So I attached the jumper for Enable 1 to give it the 5V, measured to confirm and still the motor is not working. I also tried a 2nd L298N with the exact same setup it and does not work. So I suspect it is something in my code or setup.
I feel like I am doing something stupid but I do not know what else to check. I checked continuity on the back of the board and it seems okay.

hint: you are mising a wire between the arduino and the L298N module

Give have to apply 5V to the 5V pin. The L298N's needs power supply for its logic circuitry, so you have:
  - voltage for the motor
  - voltage for the L298N
  - signal lines

Ah yes, this fixed the problem. Maybe I interpreted the tutorial wrong but it implied that for supplying a voltage greater than 7V the onboard regulator would supply the 5V for the logic circuity. Thanks!

I though a regulator converts 12V into 5V and supply for logic, isn't it true? I confirmed 5V with a digital multi meter.

@Watanabe.N L298N is only the H-bridge IC and it does not have a voltage regulator included, so you need to provide 5V yourself. Though, there are many different L298N modules and it's possible that some of those include a voltage regulator onboard

I found this thread for a similar problem,
I realized that my scratch (taken from here) wasn't able to works..
After many and many tries, I found that:
the scratch works only using Serial Plotter, and not using Serial monitor.
In my case it was not necessary to connect 5vout of L298N with arduino,
(clearly you need to connect ground to battery supply and to arduino ground too).
I don't know why the scratch works properly (make motors turn) only by Serial Plotter and it doesn't work by Serial monitor.
I really would like to understand it!! (if someone could explain this oddity I would be very grateful).
Hope this could help.
UPDATE:
I found why it doesn't work on Serial monitor..
In the serial monitor, by using:
int inByte = Serial.read();

you must select "no line ending".
:)
it's always human error!
NOTE:
the 5V pin let to power Raspberry and this is it use.
I don't know if that solution should be risky..
In the Datasheet it's said:

A non-inductive 100nF capacitor must be connected between this pin and ground

I searched about this solution on Raspberry but, after many readings, I just don't know if this could be a safe solution to power it.
I can't suggest it as a secure way.