text:
Weird serial behavior on atmega2560
EDIT
This seems to be something to do with the oscillators. Switching to the internal oscillator and writing straight avr-c allows me to run a basic blink program. Writing the same basic blink in arduino and flashing with the IDE (through serial or usbasp) results in a non functional program. I'd like to be able to use the oscillator because it doesn't look like I can get everything done in time at 8MHZ
I have an arduino mega 2560 which a few weeks ago was working fine. Now, I'm trying to output some data from it, and 've broken it down to a very, very basic proof of concept:
void setup() {
// put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
   // put your main code here, to run repeatedly:
   Serial.println("hello");
}

This prints:
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

indefinitely on the screen. If I change the baud to 115200, I get the "hello" and the newline, and slowly start getting garbage afterwards. If I switch to 234500, I get a few prints, and then nothing.
Adding a delay after the print does not change the frequency of the serial prints:
void loop() {
// put your main code here, to run repeatedly:
    Serial.println("hello");
    delay(100000);
}

They still come in immediately.
I have a feeling this has something to do with timing of an interrupt, but I'm not setting anything up. I plan to reflash and fix the fuses, but my usbASP cable is broken right now. Any other input on what might be going on here?
Edit:
This occurs on two different boards. I originally had some i2c devices (mag/gryo/barometer) on board, but those have since been removed. I have tried two different usb cables in two different USB ports. This might be on the host side?
Edit:
Both the TX and Rx lights are solid this whole time. Almost as if there's a loopback. My other laptop won't even boot right now. I'm concerned a surge from a storm last night might have taken out both of these machines
More testing:
Looking at the output on a scope, the board is actually only outputting an "h" character. If I do:
Serial.println('U');
delay(1000);

I get a square wave, so the delay doesn't run at all.
If I do:
Serial.println('U');
Serial.println('U'); //or any other character
delay(1000);
I get a U character over the scope, and then an empty serial frame. The delay still doesn't run, but it looks like the second println is exiting.
Even burning a new bootloader fails on these boards

This does look like some kind of hardware problem. I have seen Uart chips causing strange output and act as if having a loopback, but only on real Uarts, not on USB devices.

Was either of the Atmega boards connected to anything during the surge? Was the host computer plugged in to power? It does sound like the common element is your computer's USB. Can you try using a different physical USB port on the laptop? A different laptop?

I've brushed both boards to eliminate shorts. I'd accept hardware failure but two previously working boards on the same day?

@jrobert boards were not powered, laptop was charging. My other laptop (also charging) will not boot today, which contributes to my suspicion

add Serial.println("world"); delay(5000); to your code

@jstola the issue here is it's never exiting the original serial print. I need to read the Arduino core code (and/or just code this in straight avr-c) to see what error handling is going on and why serial print is never exiting

It would help to print something distinct in setup() to know whether or not the boards are resetting.

Consider doing a loop-back test.  Connect RESET to GND and D0 to D1.    This will hold the ATMega2560 in reset so it doesn't interfere.  IdeallyD0 and D1 would be connected by low value resistor, say 330 ohms to protect against accidentally letting the 2560 out of reset. With D0 and D1 connected, what you send you should receive at any of the standard baud rates.  This will tell you something about whether are before or after the serial transceiver.

Answering my own question - a bit of a walk of shame here.
I had disabled the internal TIMER0_OVF_vect in the arduino core code, so that I could write my own (for another project). I wrapped in in an #if 0 so I could go and bring it back when I needed it.
Today, I learned that the atmega interrupts aren't filled with an IRET by default, but instead hit the reset vector, resetting the board. Anything I compiled on this library would reset whenever TIMER0 overflowed, because my ifdefs didn't cover the TIMSK setting in the arduino core either
The "Serial.println isn't exiting" was actually "the board is resetting before it can complete" and explains why faster bauds could print more data.
Not much smarter than hairless apes, sometimes.


text:
Coding for RTC and stepper motor
How easy is it to create a code using an RTC to rotate the stepper motor one way at a specific time and back the other way at a specific time? and that time being charged different months of the year. how would I go about this?
I want to make an automatic chicken door, to open in the morning and close at night.
Thanks

please do not ask opinion based questions .. those are off topic here ... anyway, what is the point of asking how easy something is? ... how is an answer like somewhat easy even useful?

develop the project in sections .... start with rotating the stepper to desired positions ... next, add code tbat rotates the stepper when a button is pressed ... next, replace button control with time based control

This question is difficult to answer because it depends on your skills. For an absolute beginner it can be complicated, for someone with a little more experience it will be easy.

code is finite, and better yet logical.  should be "easy" compared to the hardware portion where the possibilities are nigh infinite and chaotic.  If hardware is done, tested, and reliable, then just loop over: reading rtc (1), deciding on an action such as deep sleep or running motor to change door (2), and performing the action (3).  Break each step down into simpler actions based on searches, but if you properly tested the hardware already, you should have code to break up and reuse from when you did that.

I am assuming that you want to make a clock. To do that you need to find a gear ratio where 1 revolution of the motor equals 60 seconds, and then make the gear ratios for the minutes and horse from that. Then you can use the RTC to spin the motor by 6 degrees every second. If you are not making a clock, please be more descriptive.

Spend some time searching the web, I have seen several solutions one of them even did a chicken door.

source: Stack Exchange

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

sort: votes


text:
Need help with independent speed control on multiple steppers
I am a NOOB. I admit to a huge lack of understanding of programming. I just need my machine to work.
I cannot wrap my head around getting independent speed control of 2 steppers since it seems that controlling the speed is dependent upon adjusting the length of delay between sending pulses to the motors, however sketches only contain one Loop and any delay in that loop has a global effect.
Here is my code so far
// My sketch to control 1.8 degree stepper motors operating the Gizmoto V3 Braiding Machine
// One 10k Pot speed-controls 2 braiding steppers,
// Second Pot speed-controls 3rd stepper which operates the take-up capstan

// Rev 1.0  March 10 2021

// Defines pins numbers

const int braidStepPin = 3;
const int braidDirPin = 2;

const int capstanStepPin = 5;
const int capstanDirPin = 4;

//Define variables here

int braidDelay; // Controls the speed of the braiding drive according to braidSpeed function
int capstanDelay; // Controls the speed of the capstan drive according to capstanSpeed function

void setup() {
  // Sets the pins as Outputs
  pinMode(braidStepPin,OUTPUT);
  pinMode(braidDirPin,OUTPUT);
  pinMode(capstanStepPin,OUTPUT);
  pinMode(capstanDirPin,OUTPUT);

  digitalWrite(braidDirPin,HIGH); // Sets the braid motors' direction
  digitalWrite(capstanDirPin,HIGH); // Sets the capstan motor's direction
}
void loop() {

  digitalWrite(braidStepPin, HIGH); // Sends the braid motors one pulse
  digitalWrite(braidStepPin, LOW);
  delayMicroseconds(braidSpeed);

  digitalWrite(capstanStepPin, HIGH); //Sends the capstan motor one pulse
  digitalWrite(capstanStepPin, LOW);
  delayMicroseconds(capstanSpeed);
}
// Function for reading the Braiding Potentiometer
int braidSpeed() {
  int braidDelay = analogRead(A0); // Reads the potentiometer
  int newBraidDelay = map(braidDelay, 0, 1020, 200, 700); // Converts the read values of the potentiometer from 0 to 1023 into desired delay values
  return newBraidDelay;
}
// Function for reading the Capstan Potentiometer
int capstanSpeed() {
  int capstanDelay = analogRead(A1); // Reads the potentiometer
  int newCapstanDelay = map(capstanDelay, 0, 1020, 200, 700); // Converts the read values of the potentiometer from 0 to 1023 into desired delay values
  return newCapstanDelay;
}

your code is step braid ... pause ... step capstan ... pause ... do you see a problem with that? .... the code needs to be look at time ... if needed, step braid ... if needed, step capstan .... or this ... decrement braid counter ... if zero, reset braid counter and step braid ... decrement capstan counter ... if zero, reset capstan counter and step capstan

Thank you for taking the time to offer help. As I stated I am very inexperienced at coding. I am aware of the accumulative effects of multiple pauses in the loop.. Do you know of an example of the code which you described: using counters, decrements and resets.. once I see that, maybe I'll be able to work through it. Sorry to be a nuisance.

there is a lot of example code included with the Arduino IDE ... lots more code on the internet ... here is an example of a counter https://mechatrofice.com/arduino/arduino-counter-code-circuit-working .... look at the lines that deal with count_value ... remove all the code that deals with the button ... keep the delay just for testing ... you'll have increment count_value ... print count_value ... delay 100

next, change the increment to decrement ... next, add code that sets value of count_value if count_value == 0 .... it's all baby steps ... expand your code slowly

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


text:
Do these types of wires exist?
I was wondering if the following type of wire adapter existed. Because I have some small JST pins and I need to connect them to some JST XH pins. (Preferably on amazon):

JST to JST XH adapter

JST What to JST XH?

I can do PH to XH custom cables.

@jsotola Looks like it's been spliced from two images.

@Majenko you are right ... i was seeing heatshrink tubing ... my apologies to the OP

@jsotola That's what I thought at first too.

@DigitalRookie4 what's the application? ... what is preventing you from buying the two different connectors with pigtails and splicing the pigtails?

@jsotola I am not an expert on all things to do with "splicing the pigtails". In addition to this, the picture was edited and the reason why the wires were different sizes was just because I was just trying to get the idea of what I was wanting across. What I am asking is that do these types of wires exist.

@Majenko I don't know how to really describe it. A small JST to a large JST?

Every type of JST connector has a code made from a combination of letters. One end of that is XH. The other end is unknown. You need to know what the JST code is for that end. Then you can google for it.

@Majenko I have just had a look and I think the small wire is a ZH JST.

You can buy both XH and ZH cables on eBay. Just get both and connect them together.

@DigitalRookie4 all you need is some heatshrink tubing, a cigarette lighter and diagonal cutters (or strong fingernails) ... wirestrippers would work, but are more specialized ... strip the two wire ends, twist together, slide on heatshrink tubing and shrink using a cigarette lighter ... no soldering required

@jsotola I have a soldering kit somewhere (I think). I have not used it before, how about I use that to solder the 2 wires together?

if you apply solder to the connection, then it becomes brittle and breaks easily, unless the wire does not get moved after installation

https://www.instructables.com/Master-a-perfect-inline-wire-splice-everytime/

@jsotola That's perfect! However one wire is quite small in diameter and one is larger in diameter. Will this still work? I have wiring tape which might work instead of "headshrink tubing". Why would I need some sort of lighter to do it?

Yep sorry, that must have been a typo, you know what I mean. What is the answer to the question above?

@jsotola I have tried it out with a spare wire and it seemed to work very well

heatshrink tubing shrinks about 50% in diameter when heated ... a butane cigarette lighter is the easiest tool to use ... electrical tape tends to become gummy and peels off ... heatshrink tubing grips the wire insulation tightly and becomes a good strain relief for the connectionby keeping it together and maintaining flexibility


text:
18b20 dallastemperature
I can't compare for the condition Error "sensors not int type" translate to int type does not work. Please tell me the solution to this problem
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define ONE_WIRE_BUS 2
#define Rele 5

OneWire oneWire(ONE_WIRE_BUS);
LiquidCrystal_I2C lcd(0x27,16,2);
DallasTemperature sensors(&oneWire);

int tmp;
int PotenciometrPin = A0;
int val;

void setup(void)
{
 pinMode(Rele, OUTPUT);
 digitalWrite(Rele, HIGH);

 lcd.init();
 lcd.backlight();
}

void loop(void)
{
 lcd.setCursor(0, 0);
 sensors.requestTemperatures();
 val = analogRead(PotenciometrPin);
 lcd.print("Ustonovit`: ");
 val = map(val, 0, 1023, 0, 100);
 lcd.print(val);
 int(sensor);
 // if(val = sensors){ <-- THIS PROBLEM
 //digitalWrite(Rele, LOW);
 // }
 lcd.setCursor(0, 1);
 lcd.print("Fakt: ");
 lcd.print(sensors.getTempCByIndex(0));
 delay(1000);
}

What is this supposed to do? sensors is an object, you cannot compare it to a value. What are you trying to compare it to? Besides, it should be ==, not = for a comparison. And the line above the if is also useless.

Just look at the examples provided with that library (and look carefully at both the actual use and the setup parts).


text:
Why is my button not working?
I'm trying to making a traffic light for my school project but my button for the traffic light doesn't work. The traffic lights should light up normally but when the button is pressed all LEDs should go to LOW but that does not happen. Did I connect my buttons incorrectly?
Code:
int Pins[] {2,3,4,5,6};
int red =2;
int yellow=3;
int green = 4;
int GruenF =6;
int RotF=5;

int blaulichtTaster = 12;
int blaulichtTasterStellung = 0;

void setup() {
  for(int i=0;i<9; i++) {
  pinMode(Pins[i], OUTPUT);
}
  pinMode(blaulichtTaster, INPUT);

}
void loop() {

  blaulichtTasterStellung = digitalRead(blaulichtTaster);

  if(blaulichtTasterStellung == 0){
    digitalWrite(red, HIGH);
  delay(3000);
  digitalWrite(GruenF, HIGH);
  digitalWrite(RotF,LOW);
  delay(4000);
  for(int i =0;i<4;i++) {
    digitalWrite(GruenF,LOW);
    delay(500);
    digitalWrite(GruenF,HIGH);
    delay(500);
  }
  digitalWrite(GruenF,LOW);
  digitalWrite(RotF, HIGH);
  delay(3000);
  digitalWrite(yellow,HIGH);
  delay(4000);
  digitalWrite(red,LOW);
  digitalWrite(yellow,LOW);
  digitalWrite(green, HIGH);
  delay(10000);
  digitalWrite(green, LOW);
  delay(500);
  for(int i = 0; i<3; i++) {
    digitalWrite(green, HIGH);
    delay(500);
    digitalWrite(green, LOW);
    delay(500);
  }
  digitalWrite(green, HIGH);
  delay(500);
  digitalWrite(green, LOW);
  digitalWrite(yellow, HIGH);
  delay(4000);
  digitalWrite(yellow, LOW);
  }

  else{
    digitalWrite(red,LOW);
    digitalWrite(yellow,LOW);
    digitalWrite(green,LOW);
    digitalWrite(RotF,LOW);
    digitalWrite(GruenF,LOW);
  }

}

My circuit:

Assuming that the power rails in your breadboard are continuous, and you hold the button long enough for the entire light sequence to execute from start to finish (33 seconds?), then yes it looks like it should work. Are you expecting it to react instantly to you pressing the button or something?

Yes it schould react instantly.

Then you're going to have to re-think your program and get rid of all those delay() functions.

@fatihakan21, can you address the "Assuming that the power rails in your breadboard are continuous" part of Majenko's comment.  Have you in fact confirmed that they are continuous?

write a test sketch that turns on all the LEDs when the button is pressed and turns off the LEDs when the button is released ... after all, the question is about the button, not about the rest of the sketch ... you are assuming that the button is failing, so you need to test your assumption


text:
Trying to interface E18-D80NK sensor but the output is always one - what to do?
I'm trying to use a E18-D80NK but the output is always 1
Referring to the above link. I am facing the same problem. But unfortunately there is no solution in the given link. My code goes as follows:
#define SENSOR 2 // define pint 2 for sensor
void setup() {
  Serial.begin(9600);// setup Serial Monitor to display information
  pinMode(SENSOR, INPUT_PULLUP);// define pin as Input  sensor
}

void loop() {

  int L =digitalRead(SENSOR);// read the sensor

      if(L == 0){
    Serial.println(" Obstacle detected");

     }else{

     Serial.println("  === All clear");

     }
  delay(500);

}

Wiring:
Brown = 5V
Black = INPUT
Blue = Gnd

This is always giving me '=== All clear' as output. Also, would like to mention that, I bought a new sensor recently. Now i doubt is it a defective piece.
Could you please help.

your post needs to be self-contained ... the linked post could get deleted

Try connecting the sensor's power and measure the voltage of the input pin (disconnected from the arduino) with a voltmeter. If that works, then your sensor is good. Try then with the pullup disabled.

the datasheet has the pullup resistor incorrectly connected ... the note next to the wire color chart is correct ... you are using internal pullup, so you do not need an external resistor

please remove the ir tag ... your question is not about IR

Thank you, jsotola for your correction and reply. I tried what you suggested still no results.

Thank you, Mat for you reply. I just want a little clarification. I did not understand, what do you mean by 'sensor's power'? However, I simply tried with pullup disabled, but did not work.


text:
Remove unwanted characters from char type
I'm working on an ESP8266 module that needs to fetch date data from worldtimeapi, everything works fine but the problem is How do I strip of the time field off the datetime JSON response without loop.
Note: Arduino JSON library was used in deserializing the response data and it seems the library only supports char data type.
void loop ()
{
  // Initialize the request object
  HTTPClient request;

// Make a http request
  request.begin(dateTime);
  delay(2000);

  // Check the request status code.
int  responseCode = request.GET(); //Get the api host response code.
  Serial.print("Response code is: ");
  Serial.println(responseCode);
  if (responseCode == 200); // If the server returned OK
  {
      String responseData = request.getString();
      Serial.println("Response from the server is:");
      Serial.println(responseData);
        // Deserialize the JSON response data
       StaticJsonDocument<715> result; // Declare data storage to stack

      //Check for error during data deserialization
      DeserializationError error = deserializeJson(result, responseData);

      if (error)
      {
        Serial.print(F("Response deserialization failed with reason: "));
        Serial.println(error.f_str());
        return;
      }

      else
      {
        char abbreviation = result["abbreviation"];  // Returns the current time zone abbreviation
        char timezone = result["timezone"]; // Returns the current time zone
        char datetime = result["datetime"]; // "2021-03-12T17:04:0
        char date = datetime.remove(9,22); // This line throws error : request for member 'remove' in 'datetime', which is of non-class type 'char'

        Serial.print("Current time is ");
        Serial.print(datetime);
        Serial.print(" ");
        Serial.print(abbreviation);
        Serial.print(" ");
        Serial.println(timezone);
        delay(2000);
      }

  }

}

why without loop?

You can use strtok to split the string on the T character:
char *datepart = strtok(datetime, "T");
char *timepart = strtok(NULL, "T");

Serial.print("The current date is: ");
Serial.println(datepart);
Serial.print("The current time is: ");
Serial.println(timepart);

An alternative is to just find the T and turn it into the NULL terminating character:
char *T = strchr(datetime, 'T');
*T = 0;

If you need to copy the string data into a temporary string first you can do:
char temp[strlen(datetime)+1];
strcpy(temp, datetime);

Then operate on temp instead of datetime.

I need to get rid of T17:04:0.

Then just use datepart.

How do I do that in C++, I think datepart is a SQL syntax.

I have shown you how to do it.

Followed the ALT but seems the the Arduino Json library has some const definition. New error message: path/to/arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantAs.hpp:94:27: error: invalid conversion from 'ArduinoJson6172_91::enable_if<true, const char*>::type {aka const char*}' to 'char*' [-fpermissive]    return variantAs<T>(data);

You may need to copy the string content to a temporary work string first then.

Seems to work but the Arduino Json library won't allow that, I'll use NTP Client lib to get the date data. Thank You Majenko.

What @Majenko suggested works just fine. Define an appropriate sized character array (with an extra for the null terminator) and just strncpy() to it.

@Ruby, esp8266 has built in NTP


text:
using a variable to index an array
I'm using the keypad library to return a number 1-9. (im fairly sure this returns an int)
I have an array (data) showing the state of each button press.
so i would like the number returned by the keypad (key) to be the index number that gets edited from 0 to 1 and from 1 to 0.
    //REMOTE KEYPAD TO CONTROL OUTPUTS OVER SERIAL

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},

};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int iAm = 1;                                    //this is device number 1
float checkSum = 0.00;                          //check sum to send as serial
float voltage = 5.26;                           //system voltage
bool data[8] {0, 0, 0, 0, 0, 0, 0, 0, 0};       //keypad output call

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

void loop() {

  int key = keypad.getKey();

  if (key) {
        data[key] = 1;

    //checkSum = voltage * (iAm + data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7] + data[8] + data[9]);
    //Serial.print(iAm);
    //Serial.print("/");
    Serial.print(data[1]);
    Serial.print("/");
    Serial.print(data[2]);
    Serial.print("/");
    Serial.print(data[3]);
    Serial.print("/");
    Serial.print(data[4]);
    Serial.print("/");
    Serial.print(data[5]);
    Serial.print("/");
    Serial.print(data[6]);
    Serial.print("/");
    Serial.print(data[7]);
    Serial.print("/");
    Serial.print(data[8]);
    Serial.print("/");
    Serial.print(data[9]);
    Serial.print("/");
    Serial.print(voltage);
    Serial.println("/");
    //Serial.println(checkSum);

  }

}

i can edit the index location by typing data[1] = 1 but not as a variable so i suspect an index cant be addressed as int? but i don't know what it should be addressed as or how to change it to that.

im fairly sure this returns an int -- Wrong. It returns a char. You need to then convert that to an integer before you can use it as an array index. Hint: subtract zero.

{'1','2','3'}, {'4','5','6'}, {'7','8','9'} these are ASCII characters ... the array is equal to {49, 50, 51}, {52, 53, 54}, {55, 56, 57} ... take a wild guess what the array should be, if you want values of 1 to 9

not going to pretend i understand why all my keypad numbers are 48 higher than the number printed on the keypad but:
int key2 = key -48;

works

One word to google: "ASCII".


text:
Controlling op amps amplification ratio by arduino
Is there any option how to control amplification ratio of operational amplifier by some logic signal which can be produced by arduino? I am talking about some clasic op amp like lm356 or ui741 in basic inverting or non-inverting circuit (i would like to use non-inverting circuit in my application). I know only about digital potentiometer like solution but i think that it isn't profesional and most eficient solution, so I want to know your opinion. Thanks for reply.

There's nothing wrong with digipots...  I made a whole mixer system using digipots and op-amps once.

not a question about Arduino

Could you provide more details on your requirements? Do you need gain adjustments in fine tuning or just large steps, like the scales of a multimeter? What are the characteristics of your input signal?

The basic principle is easy to implement.  A non-inverting configuration has a resistor Ri from the inverting input to ground, and a feedback resistor Rf from the same input to the output.  The signal is applied to the non-inverting input.  The gain is 1+Rf/Ri.  You can control the gain by changing Ri, which can be done via a CD4016 quad analog switch and 4 resistors.
HOWEVER, the Arduino is a 0-5V device.  The CD4016 can handle 15V, but to switch it the digital input must pass through half the supply.  The op-amps you mention will require bipolar supplies to handle AC signals (which I assume is what you want), so you could run them with +/-7.5V, with the CD4016 powered between them.  Then to get the Arduino 0-5V to toggle the CD4016 you'd need some level-shifting transistors to get it to +/-7.5.  The upshot is that this is surely going to be more trouble than it's worth.
However, if you are willing to drop the ancient op-amps and use a modern single-supply type (MCP6021, LT1013, etc) that runs on 0-5V, you can use input and output capacitors to convert the signal to AC, then just use the CD4016 as-is. Or JFET transistors, or even bipolars to switch the gain resistor under Arduino control if you don't need audiophile quality.


text:
Atmega 328P U crash on 5V/1A
Atmega 328PU crash on 5v/1A. Why? It works on 5V/400ma but when i switch it to 5V/1A power it crash. Any idea or solution for this?

sure, don't use the defective power supply that causes crashes

You're asking why, but you're providing no details to enable us to answer your question. There's no reason a more powerful supply should crash your ATMega328P, so it's probably caused by a faulty supply or some other problem (which we can't help you with because you have not told us anything about your setup).

Thanks guys, yea the power supply was foulty. i get a new one and its working fine. thanks!

Nothing wong, if your power supply is trustworthy enough, then , if u even provide 100000 Amps of current with 5 volt,
your IC won't burn, in your case , it burnt because your power supply seems to be defective, and please check the voltage of the power supply which is supposed to be defective, so it output more than 5 volts burning or crashing your ic...
Note:
I have personally worked with 5 volt 6 amp power supply which is very well precise and my ic is working full fledged without any problems.

yea the adapter was faulty. i get new one (5V/1A) and it's working fine. Thank you @Subha Jeet


text:
Strange behavior from uint32_t, acting like signed int (Nano clone)
I'm having trouble with these variables. As you can see they're uint32_t type, so they should have a maximum value of 4 million or so, but they're rolling over and going negative at 32,767 like a signed int. Here's the relevant code:
byte lPin = 7;
char buff[100];
uint32_t loAvg = 0;
uint32_t hiAvg = 0;

void setup() {
  pinMode(lPin, OUTPUT);
  digitalWrite(lPin, HIGH); // Active LOW, so this is off

  Serial.begin(9600);
  // Generate high/low averages
  for(int i = 0; i < 100; i++) {
    loAvg += analogRead(A0);
  }
  loAvg /= 100;

  digitalWrite(lPin, LOW);
  delay(500);

  for(int i = 0; i < 100; i++) {
    hiAvg += analogRead(A0);
  }
  hiAvg /= 100;

  digitalWrite(lPin, HIGH);
  delay(500);

  sprintf(buff, "loAvg=%d, hiAvg=%d", loAvg, hiAvg);
  Serial.println(buff);

  Serial.println(hiAvg);
  digitalWrite(lPin, LOW);
  hiAvg = 0;
}

void loop() {
  sprintf(buff, "test=%d", hiAvg);
  Serial.println(buff);
  hiAvg+=100;
}

I removed a bunch of stuff from the code to save posting the whole (much longer) thing. If it ends up being relevant I can though, I just think I narrowed the problem down to this. Observing the serial monitor I get this on startup:
loAvg=287, hiAvg=0
933
test=0
test=100
test=200
...

The test=# repeats until 32700, then continues at -32736. I'm confused by the hiAvg=0 followed by the 933, showing that it totally is getting a high average, because that's around what it should be. Even if it's the sprintf() messing with it, in the setup function the value should only be around the 900 range so it wouldn't overflow there. Any ideas anyone?

there are only three lines involved ... my bet is on sprintf() ... specifically the %d ... that formats the data for output

"%" PRIu32  There's almost no reason to use sprintf over snprintf. In this code as written, no reason to use either.

This code above is only the parts that were relevant to the question so I can understand not seeing the point. The sprintf is only used during testing. When DEBUG is defined, the serial prints are between #ifdef / #endif blocks so they're not present during normal operation. I did end up figuring out that I needed %lu. Thank you for the replies and answers.

%d expects a signed int. %u expects an unsigned int. Insert the l modifier to expect a long in each of those cases. So you need a format code of %lu to print a uint32_t.
The following code:
#include <Arduino.h>

void setup()
{
    uint32_t x=110000;
    char buf[50];

   // Open console
   Serial.begin(115200);

    sprintf(buf, "%%d: %d\n", x);       Serial.print(buf);
    sprintf(buf, "%%u: %u\n", x);       Serial.print(buf);
    sprintf(buf, "%%ld: %ld\n", x); Serial.print(buf);
    sprintf(buf, "%%lu: %lu\n", x); Serial.print(buf);
}

void loop() {
   ;
}

prints this:
%d: -21072
%u: 44464
%ld: 110000
%lu: 110000

*printf and bit-width specified types
#include <inttypes.h> or C++'s #include <cinttypes> counterpart (when you have it; not on AVR-based Arduinos) gives access to macros defined for the format specifiers for each of the fixed, fast, and least versions of these types.  All of these macros expand to some string literal or another.
For uint32_t the macro defining to its format specifier is PRIu32.  For an AVR, this is "%lu".  It needn't be "%lu" in  the general case.  uint32_t is one of the types where you can often get away with using "%lu" and have it either work out being exactly correct for the platform or somewhat incorrect but working anyway because it's a platform where unsigned int and unsigned long happen to have the same representation.
In C and C++, and so Arduino, adjacent string literals are concatenated into one logical string in the early phases of compilation that follow the macro preprocessor.  So, the intention is that you choose the correct macro and you put them following something like "%" or "%12" if you wanted a minimum-width of 12.  As in "%" PRIu32 and "%12" PRIu32 respectively.  So, in your case,  having included (directly or indirectly) <stdint.h> for uint32_t and <inttypes.h> for PRIu32 or their C++ counterpart headers, and then your code looks something like:
snprintf(
  buf,
  sizeof buf,
  "loAvg=%" PRIu32 ", hiAvg=%" PRIu32,
  loAvg,
  hiAvg
);

There's little to no reason to not use the snprintf.  The reason why the non-n version exists at all is mostly that snprintf showed up in 1999, instead of circa the mid 1970s.  I'd say it's pretty safe to use snprintf now.  There probably hasn't been an Arduino that doesn't support it.  About the only reason to use sprintf would be if you were calling it with a null pointer for the buffer argument to get it to do a dry run and tell how much memory you need for the result, and you just didn't want to supply a limiting size.
There are PRI... macros for all of the combinations of standard bit width and choice of signed decimal, unsigned decimal, lowercase hex, uppercase hex, etc.  E.g "%" "PRId16" is  for int16_t in decimal, "%" PRIX64 for uint64_t in hexadecimal with uppercase alphabetics.  The are ones for the fast and least bitwidth types, and whole show is repeated with macros starting with SCN for the scanf specifiers, not that you should use the scanf family functions for anything really.
snprintf and sprintf are variadic functions.  After the format specifier there's no type information available to the compiler to know what conversions to apply.  It will convert types smaller than int rank up to int on unsigned int, but that's about it.  E.g. it will not reliably down-convert an unsigned long long into an unsigned int, the way it would if the types were known.  Modern compilers will sometimes warn you if you grossly misapply format specifiers, but they're not required to.  They're not expected to dissect the format string and attempt to recover type information.  So it's up to you to make sure whatever you pass in for arguments matches with the format specifiers.  As you've seen it's confusing if you get it wrong with printf-type functions, but it doesn't cause real problems unless you, you know, don't limit it to stay within the output buffer with the snprintf version.  In the case of passing in an unsigned long long where an unsigned int was expected, in practice, for a little-endian system like AVR, it may appear to do that for one argument.  But then it may fail on the next argument, because the size of the last argument was in correct, it is now reading from the wrong place.
Print/Stream/Serial concatenating and buffering
The way you're using sprintf in your code isn't taking advantage of any of its features that Serial/Print doesn't do.
Serial.print(F("loAvg="));
Serial.print(loAvg);
Serial.print(F(", hiAvg="));
Serial.println(hiAvg);

Despite taking four lines, this is actually smaller, faster, more reliable code than the sprintf one-liner.
Putting the output into a buffer first might make sense if you were going to put it into a packet, like for UDP or nRF24L01.  But, Print/Stream/Serial already concatenates and buffers things for you.

Incidentally, if you're going to use printf functions and you're doing it on an AVR-based Arduino, look at the avr-libc documentation for the _P variants that take their format strings from PROGMEM and the PSTR macro.
It is also possible to complete the implementation of <stdio.h> for stdout and stderr through libc-specific means.  So, if you really want to, you can have the regular printf function pushing data out through Serial (among other things) such that you don't need to buffer repeatedly with sprintf.


text:
ESP8266 wdt reset
I just bought a KS0354 ESp8266 board to make a remote control for my iot project. Not sure why I keep on getting a wdt error. Even before I can complete my entire code I start getting this error. Below is my code:
int PIN_BUTTON_A = 2;
int PIN_BUTTON_B = 3;
int PIN_BUTTON_C = 4;
int PIN_BUTTON_D = 5;
int PIN_BUTTON_E = 6;
int PIN_BUTTON_F = 7;

void setup() {
  Serial.begin(9600);
  pinMode(PIN_BUTTON_B, INPUT);
  pinMode(PIN_BUTTON_E, INPUT);
  pinMode(PIN_BUTTON_C, INPUT);
  pinMode(PIN_BUTTON_D, INPUT);
  pinMode(PIN_BUTTON_A, INPUT);
}

void loop() {
   Serial.print("Buttons A:");
   delay(5000);

}

This seems to be a very simple code. Not sure what is wrong here. Below is the error I am getting @115200 baud rate:
 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld

Does anyone has any idea what could be wrong?
Thanks

has the module a 40 MHz clock? the bootlog at 115200 indicates that. then you must set it in Tools menu. or you did set 40 MHz and it has a 26MHz clock?


text:
Arduino Leonardo doesn't print anything to Serial Monitor with my specific code
I did a project with an Arduino Leonardo and a fingerprint sensor (DY50).
When I uploaded the enroll example from the Adafruit Fingerprint Library and saved my fingerprint, everything worked. But when I upload my code, it doesn't print anything.
My Code
#include <Keyboard.h>
#include <Adafruit_Fingerprint.h>
#define mySerial Serial1

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int fingerprintID = 0;
String inData;
bool isRight;
int pos;

//Number of services to log in
#define servNum 5

//Login URLs for Google, Amazon, Stackoverflow, Arduino and Github
String LogInURL[] = {"https://accounts.google.com/signin", "https://www.amazon.de/ap/signin", "https://stackoverflow.com/users/login", "https://login.arduino.cc/", "https://github.com/login"};
String LogInUser[] = {"user.name@gmail.com", "user.name@example.com", "user.name@example.com", "username", "username"};
String LogInPwd[] = {"password", "password", "password", "password", "password"};

void donothing() {};

void StepsBefore(int serviceNum){
  switch(serviceNum){
    case 0: donothing(); break;
    case 1: donothing(); break;
    case 2: for(int k=0; k<18; k++) Keyboard.press(KEY_TAB); Keyboard.release(KEY_TAB); break;
    case 3: for(int k=0; k<2; k++) Keyboard.press(KEY_TAB); Keyboard.release(KEY_TAB); break;
    case 4: donothing(); break;
    default: Serial.println("Error: Number not recognized."); break;
  }
}

void StepsAfter(int serviceNum){
  switch(serviceNum){
    case 0: Keyboard.println(); break;
    case 1: Keyboard.println(); break;
    case 2: Keyboard.press(KEY_TAB); Keyboard.release(KEY_TAB); break;
    case 3: Keyboard.press(KEY_TAB); Keyboard.release(KEY_TAB); break;
    case 4: for(int k=0; k<2; k++) Keyboard.press(KEY_TAB); Keyboard.release(KEY_TAB); break;
    default: Serial.println("Error: Number not recognized."); break;
  }
}

int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;
  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;
  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;
  Serial.print("Found ID #");
  Serial.print(finger.fingerID);
  Serial.print(" with confidence of ");
  Serial.println(finger.confidence);
  return finger.fingerID;
}

void askForFingerprint() {
  fingerprintID = getFingerprintIDez();
    delay(50);
    if(fingerprintID == 1){
      isRight = true;
    }
}

void delAfterChar(String inString, String fromToKill){
  pos = inString.indexOf(fromToKill);
  inString.remove(pos, 1000);
  inData = inString;
}

void setup() {
    Serial.begin(115200);
    Serial.println("Debug 1");
    Keyboard.begin();
    Serial.println("Debug 2");
    finger.begin(57600);
    Serial.println("Debug 3");
    if(finger.verifyPassword()) {
        Serial.println("Found fingerprint sensor!");
    }
    else {
        Serial.println("Did not find fingerprint sensor :(");
        while (1) { delay(1); }
    }
}
void loop() {
  inData = Serial.read();
  delAfterChar(inData, "?openid"); //Amazon
  delAfterChar(inData, "/v2/"); //Google
  delAfterChar(inData, "?ssrc"); //Stackoverflow
  delAfterChar(inData, "login?state"); //Arduino
    for (int i=0; i<servNum; i++){
     if(inData == LogInURL[i]){
        askForFingerprint();
        if(isRight == true){
           StepsBefore(i);
           Keyboard.print(LogInUser[i]);
           StepsAfter(i);
           Keyboard.println(LogInPwd[i]);
        }
        else Serial.println("Finger not recognized");
     }
    }
}

What I've tried so far

I changed the baud rate from 9600 to 15200, didn't help
Added a few debug points in the setup to check for an error there, nothing changed
Uploaded a simple Hello World via Serial Monitor sketch, worked perfectly

Question
What could be the issue? It compiles with no error message. If you see any coding mistakes, feedback would be great.

EDIT
Using SoftwareSerial instead didn't help either.

@jsotola I did that, as explained in the third point of what I've already tried. Sorry if it's not understandable, I don't speak English natively.

add while (!Serial); after Serial.begin

Thanks, @Juraj, totally forgot about this. But why did printing Hello World work without that?

the Hello World print was in loop? it doesn't take long to connect, but the code runs fast

@Juraj Yes, it was.

As @Juraj pointed out, I just forgot to use while (!Serial) in the setup, probably because I use other boards that don't need this more often.


text:
Arduino Uno with Sensor, Bluetooth Module and tftlcd
In code attached below I am using tftlcd display of 2.4 inch in which i want to show clock as home page, when user click on tftlcd screen then a screen appears which can show three options to user which are about the sensors user want to use. There are three sensors in this code: Pulse oximeter, glucose meter, pedometer. After choosing some option(sensor) the data of sensor will appear on screen.
I have write code for all this procedure which is given below:
//include all libraries
#include <Wire.h>
#include <SPFD5408_Adafruit_GFX.h>
#include <SPFD5408_Adafruit_TFTLCD.h>
#include <SPFD5408_TouchScreen.h>
#include "MAX30105.h"
#include "spo2_algorithm.h"

//Exit buttons
bool backsensed = false;
bool resetsensed = false;

//Include Max30102 lib
MAX30105 particleSensor;

//Define LCD pins
#define YP A1  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 7   // can be a digital pin
#define XP 6   // can be a digital pin

//pedometer
const int xpin = A3;
const int ypin = A4;
const int zpin = A5;
byte p[8] = {0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F
};
float threshold = 100;
float xval[100] = {0};
float yval[100] = {0};
float zval[100] = {0};
float xavg, yavg, zavg;
int steps, flag = 0;
//pulseoxi
#define MAX_BRIGHTNESS 255
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
uint16_t irBuffer[100]; //infrared LED sensor data
uint16_t redBuffer[100];  //red LED sensor data
#else
uint32_t irBuffer[100]; //infrared LED sensor data
uint32_t redBuffer[100];  //red LED sensor data
#endif
int32_t bufferLength; //data length
int32_t spo2; //SPO2 value
int8_t validSPO2; //indicator to show if the SPO2 calculation is valid
int32_t heartRate; //heart rate value
int8_t validHeartRate; //indicator to show if the heart rate calculation is valid
byte pulseLED = 11; //Must be on PWM pin
byte readLED = 13; //Blinks with each data read

// LCD Calibrate values
#define TS_MINX 100
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

// For better pressure precision, we need to know the resistance between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

int BLUE = tft.color565(50, 50, 255);
#define TFT_BLACK   0x0000
#define TFT_DARKBLUE 0x0010
#define VIOLET 0x8888
#define TFT_RED     0xF800
#define TFT_GREEN   0x07E0
#define TFT_CYAN    0x07FF
#define TFT_MAGENTA 0xF81F
#define TFT_YELLOW  0xFFE0
#define TFT_WHITE   0xFFFF
#define TFT_GREY    0x5AEB
#define TFT_BLUE    0x001F
#define GOLD 0xFEA0
#define BROWN 0xA145
#define SILVER 0xC618
#define LIME 0x07E0
#define BLUE  0x001F

//button screen
int currentpcolour;
int currentpage;
bool running;

//Minimum and maximum pressure to sense the touch
#define MINPRESSURE 10
#define MAXPRESSURE 1000

//clock
float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0;
float sdeg = 0, mdeg = 0, hdeg = 0;
uint16_t osx = 120, osy = 120, omx = 120, omy = 120, ohx = 120, ohy = 120;
int16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0, x00 = 0, yy00 = 0;
uint32_t targetTime = 0;
uint16_t xpos;
uint8_t conv2d(const char* p) {
  uint8_t v = 0;
  if ('0' <= *p && *p <= '9')
    v = *p - '0';
  return 10 * v + *++p - '0';
}
uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6);
boolean initial = 1;
char d;

//for buttons
void drawHome()
{
  tft.fillScreen(TFT_BLACK);
  tft.drawRoundRect(0, 0, 319, 240, 8, TFT_YELLOW);     //Page border

  tft.fillRoundRect(60, 180, 200, 40, 8, TFT_DARKBLUE);
  tft.drawRoundRect(60, 180, 200, 40, 8, TFT_YELLOW);  //PEDO

  tft.fillRoundRect(60, 130, 200, 40, 8, TFT_DARKBLUE);   //Glu
  tft.drawRoundRect(60, 130, 200, 40, 8, TFT_YELLOW);

  tft.fillRoundRect(60, 80, 200, 40, 8, TFT_DARKBLUE);
  tft.drawRoundRect(60, 80, 200, 40, 8, TFT_YELLOW); //Pulse oxi and heart rate

  tft.setCursor(25, 20);
  tft.setTextSize(3);
  tft.setTextColor(TFT_WHITE);
  tft.print("Welcome Here..");
  tft.setCursor(25, 50);
  tft.setTextSize(2);
  tft.setTextColor(TFT_YELLOW);
  tft.print("Choose Your Sensor");
  tft.setTextColor(TFT_WHITE);
  tft.setCursor(110, 195);
  tft.print("Pedometer");

  tft.setCursor(80, 145);
  tft.print("Glucose Sensor");

  tft.setCursor(80, 95);
  tft.print("Pulse Oximeter");
  //  delay(500);

  }

  void setup()
{
  tft.reset();
  tft.begin(0x9341);
  tft.setRotation(1);
  currentpage = 0; //clock page
  tft.setTextColor(TFT_WHITE);// text color
  tft.fillScreen(TFT_BLACK);// background color

  xpos = tft.width() / 2;
  tft.drawCircle(xpos, 120, 125, TFT_YELLOW);
  tft.fillCircle(xpos, 120, 118, TFT_BLUE);
  tft.fillCircle(xpos, 120, 110, TFT_BLACK);
  for (int a=95; a<104; a++){
  tft.drawCircle(xpos, 120, a, TFT_WHITE);}

  for (int i = 0; i < 360; i += 30) {
    sx = cos((i - 90) * 0.0174532925);
    sy = sin((i - 90) * 0.0174532925);
    x0 = sx * 114 + xpos;
    yy0 = sy * 114 + 120;
    x1 = sx * 100 + xpos;
    yy1 = sy * 100 + 120;
    tft.drawLine(x0, yy0, x1, yy1, TFT_YELLOW);
  }
  for (int i = 0; i < 360; i += 6) {
    sx = cos((i - 90) * 0.0174532925);
    sy = sin((i - 90) * 0.0174532925);
    x0 = sx * 102 + xpos;
    yy0 = sy * 102 + 120;
    x00 = sx * 92 + xpos;
    yy00 = sy * 92 + 120;
    // Draw minute markers
    tft.drawPixel(x0, yy0, TFT_GREEN);
    tft.drawLine(x0, yy0, x00, yy00, TFT_BLACK);
    tft.drawLine(x0+1, yy0+1, x00+1, yy00+1, TFT_BLACK);
    // Draw main quadrant dots
    if (i == 0 || i == 180) tft.fillCircle(x0, yy0, 2, TFT_WHITE);
    if (i == 90 || i == 270) tft.fillCircle(x0, yy0, 2, TFT_WHITE);
  }
  tft.fillCircle(xpos, 121, 3, TFT_WHITE);
  targetTime = millis() + 1000;
  //touch event
  tft.setCursor (80, 250);
  tft.setTextSize (1);
  tft.setTextColor(TFT_BLACK);
  tft.println("Touch to proceed");
  waitOneTouch(); // Wait touch
  drawHome(); //buttons screeen
}

void loop(){
  if (currentpage == 0){
  if (targetTime < millis()) {             //clock code
    targetTime = millis() + 1000;
    ss++;
    if (ss == 60) {
      ss = 0;
      mm++;
      if (mm > 59) {
        mm = 0;
        hh++;
        if (hh > 23) {
          hh = 0;
        }
      }
    }
    sdeg = ss * 6;                     // 0-59 -> 0-354
    mdeg = mm * 6 + sdeg * 0.01666667; // 0-59 -> 0-360 - includes seconds, but these increments are not used
    hdeg = hh * 30 + mdeg * 0.0833333; // 0-11 -> 0-360 - includes minutes and seconds, but these increments are not used
    hx = cos((hdeg - 90) * 0.0174532925);
    hy = sin((hdeg - 90) * 0.0174532925);
    mx = cos((mdeg - 90) * 0.0174532925);
    my = sin((mdeg - 90) * 0.0174532925);
    sx = cos((sdeg - 90) * 0.0174532925);
    sy = sin((sdeg - 90) * 0.0174532925);
    if (ss == 0 || initial) {
      initial = 0;
      // Erase hour and minute hand positions every minute
      tft.drawLine(ohx, ohy, xpos, 121, TFT_BLACK);
      ohx = hx * 62 + xpos + 1;
      ohy = hy * 62 + 121;
      tft.drawLine(omx, omy, xpos, 121, TFT_BLACK);
      omx = mx * 84 + xpos;
      omy = my * 84 + 121;
    }
    // Redraw new hand positions, hour and minute hands not erased here to avoid flicker
    tft.drawLine(osx, osy, xpos, 121, TFT_BLACK);
    osx = sx * 90 + xpos + 1;
    osy = sy * 90 + 121;
    tft.drawLine(osx, osy, xpos, 121, TFT_RED);
    tft.drawLine(ohx, ohy, xpos, 121, TFT_CYAN);
    tft.drawLine(omx, omy, xpos, 121, TFT_WHITE);
    tft.drawLine(osx, osy, xpos, 121, TFT_RED);
    tft.fillCircle(xpos, 121, 3, TFT_RED);
    tft.setCursor(xpos-30, 50);
    tft.setTextSize(2);
    tft.print("Glucoxy");

  // Draw MINI clock face "SECOND"
  tft.drawCircle(xpos, 155, 20, TFT_YELLOW);
  tft.drawCircle(xpos, 155, 18, TFT_BLUE);
  tft.drawCircle(xpos, 155, 17, TFT_CYAN);
  tft.drawCircle(xpos, 155, 16, TFT_CYAN);
  tft.fillRect(xpos-10, 149,22,15,TFT_BLACK); //erase
  if(ss<10){tft.setCursor(xpos-10, 149); tft.setTextSize(2);
  tft.print('0'); tft.setCursor(xpos+2, 149);}
  else{
  tft.setCursor(xpos-10, 149);}
  tft.setTextSize(2);
  tft.print(ss);
  // Draw MINI clock face "Minutes"
  tft.drawCircle(xpos+35, 117, 20, TFT_YELLOW);
  tft.drawCircle(xpos+35, 117, 18, TFT_BLUE);
  tft.drawCircle(xpos+35, 117, 17, TFT_CYAN);
  tft.drawCircle(xpos+35, 117, 16, TFT_CYAN);
 tft.fillRect(xpos+25, 111,22,15,TFT_BLACK); //erase
  if(mm<10){tft.setCursor(xpos+25, 111); tft.setTextSize(2);
  tft.print('0'); tft.setCursor(xpos+37, 111);}
  else{
  tft.setCursor(xpos+25, 111);}
  tft.println(mm);
  // Draw MINI clock face "Hour"
  tft.drawCircle(xpos-35, 117, 20, TFT_YELLOW);
  tft.drawCircle(xpos-35, 117, 18, TFT_BLUE);
  tft.drawCircle(xpos-35, 117, 17, TFT_CYAN);
  tft.drawCircle(xpos-35, 117, 16, TFT_CYAN);
  tft.fillRect(xpos-45, 111,22,15,TFT_BLACK); //erase
  if(hh<10){tft.setCursor(xpos-45, 111); tft.setTextSize(2);
  tft.print('0'); tft.setCursor(xpos-33, 111);}
  else{
  tft.setCursor(xpos-45, 111);}
  tft.setTextSize(2);
  tft.print(hh);
  //tft.setCursor(xpos-65, 111);
  //tft.println(':');
  if (hh>=0 && hh<12) d='A'; else {d='P';}
  tft.drawRoundRect(xpos-14,72,29,21,5,TFT_CYAN);
  tft.fillRect(xpos-11, 75,23,15,TFT_BLACK); //erase
  tft.setCursor(xpos-11, 75);
  tft.setTextSize(2);
  tft.print(d);
  tft.println('M');
  }
  }
  //home page
  if (currentpage == 1){
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();     // Read touchscreen
  digitalWrite(13, LOW);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  {if (p.z > 10 && p.z < 1000)
    {
      if (p.x > 736 && p.x < 855 && p.y > 255 && p.y < 725  && p.z > MINPRESSURE && p.z < MAXPRESSURE)
      {
        Serial.println("Pedometer");
        tft.fillRoundRect(60, 180, 200, 40, 8, TFT_WHITE);
        delay(70);
        tft.fillRoundRect(60, 180, 200, 40, 8, TFT_WHITE);
        tft.drawRoundRect(60, 180, 200, 40, 8, TFT_YELLOW);
        tft.setCursor(65, 195);
        tft.println("  Pedometer");
        delay(70);
        currentpage = 2;
        startPedo();
      }
      else if (p.x > 563 && p.x < 683 && p.y > 275 && p.y < 750)
      {
        Serial.println("Glucose Sensor");

        tft.fillRoundRect(60, 130, 200, 40, 8, TFT_WHITE);   //rgb led
        delay(70);
        tft.fillRoundRect(60, 130, 200, 40, 8, TFT_WHITE);   //rgb led
        tft.drawRoundRect(60, 130, 200, 40, 8, TFT_YELLOW);   //rgb led
        tft.setCursor(105, 145);
        tft.print("Glucose Sensor");
        delay(70);
        currentpage = 3;
        startGlu();
      }
      if (p.x > 403 && p.x < 525 && p.y > 271 && p.y < 725)
      {
        Serial.println("Pulse Oximeter");
        currentpage = 4;
        tft.fillRoundRect(60, 80, 200, 40, 8, TFT_WHITE);
        delay(70);
        tft.fillRoundRect(60, 80, 200, 40, 8, TFT_WHITE);
        tft.drawRoundRect(60, 80, 200, 40, 8, TFT_YELLOW);
        tft.setCursor(80, 95);
        tft.print("Pulse Oximeter");
        delay(70);
       // startPulse();

      }
    }
  }
  if (currentpage == 2) //pedo
  {
    senseBack();
    if (backsensed)
    {
      currentpage = 1;
      drawHome();
    }
    sensereset();
    calibrate();
  }
  if (currentpage == 3) // glucose
  {
     senseBack();
     if (backsensed)
     {
      currentpage = 0;
      drawHome();
     }
    sensereset();
  }

  if (currentpage == 4)  //pulse oxi
  {
    senseBack();
     if (backsensed)
     {
      currentpage = 1;
      drawHome();
     }
    sensereset();
    pinMode(pulseLED, OUTPUT);
  pinMode(readLED, OUTPUT);
  if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed  // Initialize sensor
  {
    Serial.println(F("MAX30105 was not found. Please check wiring/power."));
    while (1);
  }
  Serial.println(F("Attach sensor to finger with rubber band. Press any key to start conversion"));
  while (Serial.available() == 0) ; //wait until user presses a key
  Serial.read();
  byte ledBrightness = 60; //Options: 0=Off to 255=50mA
  byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
  byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
  byte sampleRate = 100; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
  int pulseWidth = 411; //Options: 69, 118, 215, 411
  int adcRange = 4096; //Options: 2048, 4096, 8192, 16384
  particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
  startPulse();
  }
}

}
// Wait one touch
TSPoint waitOneTouch() {
  TSPoint p;
  do {
    p= ts.getPoint();
    pinMode(XM, OUTPUT); //Pins configures again for TFT control
    pinMode(YP, OUTPUT);
  } while((p.z < MINPRESSURE )|| (p.z > MAXPRESSURE));
  return p;
}
void sensereset()
{
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();     // Read touchscreen
  digitalWrite(13, LOW);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  if (p.x < 199 && p.y < 293 && !running)
    resetsensed = true;
  else
    resetsensed = false;
}
void startPedo()        //-------------------pedometer function--------------------------
{
  int acc = 0;
  float totvect[100] = {0};
  float totave[100] = {0};
  float xaccl[100] = {0};
  float yaccl[100] = {0};
  float zaccl[100] = {0};
  for (int a = 0; a < 100; a++)
  {
    xaccl[a] = float(analogRead(xpin) - 345);
    delay(1);
    yaccl[a] = float(analogRead(ypin) - 346);
    delay(1);
    zaccl[a] = float(analogRead(zpin) - 416);
    delay(1);
    totvect[a] = sqrt(((xaccl[a] - xavg) * (xaccl[a] - xavg)) + ((yaccl[a] - yavg) * (yaccl[a] - yavg)) + ((zval[a] - zavg) * (zval[a] - zavg)));
    totave[a] = (totvect[a] + totvect[a - 1]) / 2 ;
    Serial.println("totave[a]");
    Serial.println(totave[a]);
    delay(100);
    if (totave[a] > threshold && flag == 0)
    {
      steps = steps + 1;
      flag = 1;
    }
    else if (totave[a] > threshold && flag == 1)
    {
      // Don't Count
    }
    if (totave[a] < threshold   && flag == 1)
    {
      flag = 0;
    }
    if (steps < 0) {
      steps = 0;
    }
    Serial.println('\n');
    Serial.print("steps: ");
    Serial.println(steps);
    delay(1000);
  }
  delay(1000);
  //print results on lcd
  tft.setCursor(130, 145);
  tft.setTextSize(3);
  tft.setTextColor(TFT_WHITE);
  tft.print(steps);

  }
void calibrate()            //<----------------------calibrate funtion--------------------->
{
  float sum = 0;
  float sum1 = 0;
  float sum2 = 0;
  for (int i = 0; i < 100; i++) {
    xval[i] = float(analogRead(xpin) - 345);
    sum = xval[i] + sum;
  }
  delay(100);
  xavg = sum / 100.0;
  Serial.println(xavg);
  for (int j = 0; j < 100; j++)
  {
    yval[j] = float(analogRead(ypin) - 346);
    sum1 = yval[j] + sum1;
  }
  yavg = sum1 / 100.0;
  Serial.println(yavg);
  delay(100);
  for (int q = 0; q < 100; q++)
  {
    zval[q] = float(analogRead(zpin) - 416);
    sum2 = zval[q] + sum2;
  }
  zavg = sum2 / 100.0;
  delay(100);
  Serial.println(zavg);
}
void senseBack()
{
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();     // Read touchscreen
  digitalWrite(13, LOW);

  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  if (p.y < 305 && p.x < 285 && p.x > 239 && !running)
  {
    backsensed = true;

  }
  else
    backsensed = false;
}
void startGlu()                 //-------------------------------startGlu-------------------------
{
  }
void startPulse()             //--------------------------------startpulse-----------------------
{
  bufferLength = 100; //buffer length of 100 stores 4 seconds of samples running at 25sps

  //read the first 100 samples, and determine the signal range
  for (byte i = 0 ; i < bufferLength ; i++)
  {
    while (particleSensor.available() == false) //do we have new data?
      particleSensor.check(); //Check the sensor for new data
    redBuffer[i] = particleSensor.getRed();
    irBuffer[i] = particleSensor.getIR();
    particleSensor.nextSample(); //We're finished with this sample so move to next sample
    Serial.print(F("red="));
    Serial.print(redBuffer[i], DEC);
    Serial.print(F(", ir="));
    Serial.println(irBuffer[i], DEC);
  }
  //calculate heart rate and SpO2 after first 100 samples (first 4 seconds of samples)
  maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
  //Continuously taking samples from MAX30102.  Heart rate and SpO2 are calculated every 1 second
  while (1)
  {
    //dumping the first 25 sets of samples in the memory and shift the last 75 sets of samples to the top
    for (byte i = 25; i < 100; i++)
    {
      redBuffer[i - 25] = redBuffer[i];
      irBuffer[i - 25] = irBuffer[i];
    }
    //take 25 sets of samples before calculating the heart rate.
    for (byte i = 75; i < 100; i++)
    {
      while (particleSensor.available() == false) //do we have new data?
        particleSensor.check(); //Check the sensor for new data
      digitalWrite(readLED, !digitalRead(readLED)); //Blink onboard LED with every data read
      redBuffer[i] = particleSensor.getRed();
      irBuffer[i] = particleSensor.getIR();
      particleSensor.nextSample(); //We're finished with this sample so move to next sample
      //send samples and calculation result to terminal program through UART
      Serial.print(F("red="));
      Serial.print(redBuffer[i], DEC);
      Serial.print(F(", ir="));
      Serial.print(irBuffer[i], DEC);
      Serial.print(F(", HR="));
      Serial.print(heartRate, DEC);
      Serial.print(F(", HRvalid="));
      Serial.print(validHeartRate, DEC);
      Serial.print(F(", SPO2="));
      Serial.print(spo2, DEC);
      Serial.print(F(", SPO2Valid="));
      Serial.println(validSPO2, DEC);
    }

    //After gathering 25 new samples recalculate HR and SP02
    maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
    //print results on lcd
    tft.setCursor(130,145);
  tft.setTextSize(3);
  tft.setTextColor(TFT_WHITE);
  tft.print(heartRate);

  }

}

Please see above code whether it works perfect as i want. I am getting error when i try to compile this code which is given below

My questions are:

whether this code is right, if not then point out my mistakes.
Solution of error shown in image.

please, no pictures of text .. not everyone is able to view images ... post the actual text

code is right? ... if it does what you expect, then yes .... otherwise no

The Arduino Uno doesn't have enough SRAM, the current Rev3 has just 2 KB. You can circumvent that by using less variables, use #define xpin instead of const int, etc.
Here is an article about how to reduce memory usage, give it a try.
Another option is to use a different Microcontroller with more SRAM, with at least 3KB like a Arduino Mega, ESP32. But first try to optimize your program, if you don't have another unused board lying around anyway.
EDIT:
You might also take a look at the header files if you can optimize anything there.

Ok i am trying to make this code optimized.

@Nimra I think you have to find the right number of arrays being saved in memory and the right number of them saved in Flash, because you don't have that much space on the Flash left over either.

Arduino Mega has 8192 bytes of SRAM which will solve your problem.
Reduce the RAM usage (ref)

Look at this post, where I have implement the clock using a tft touch-enabled screen, with touch-enabled choice boxes for setting the time.  I used a Teensy 3.2, which handles the memory requirements nicely.  From the compile report
Compiling 'Teensy_LCDClockV4' for 'Teensy 3.2 / 3.1'
Using previously compiled file: C:\Users\Frank\AppData\Local\Temp\VMBuilds\Teensy_LCDClockV4\teensy31\Release\pch\Arduino.h.gch
Program size: 117,320 bytes (used 45% of a 262,144 byte maximum) (4.14 secs)
Minimum Memory Usage: 5936 bytes (9% of a 65536 byte maximum)

So you might have some trouble fitting it into a typical Arduino board


text:
Sharing clock pin on Pro Micro
I am trying to get both a SPI LED matrix display and an NRF24L01 to both work on the same Arduino Pro Micro. I know they both want to use the clock pin but how do I get them to share? Can I use the CS pin to turn off one device while trying to use the other? The display does can be set only when something needs to change so it's not always running.

"isp led matrix" was meant to read "SPI LED matrix" right?

Yes sorry I fixed it

You can indeed use different CS (chip select) lines to address individual SPI devices on a single bus run by an SPI “master”. The MOSI, MISO and SCLK lines can be reused and shared between perpiheral devices, as long as only one device is actively being addressed at any point in time.

It is indeed possible and supported to use different CS (chip select) or SS (“slave select”) lines to address individual SPI devices on a single bus run by an SPI “master”.

Image from Wikipedia
Many SPI TFT Touch displays need this to address the display controller and the touch controller as individual SPI devices and/or an integrated SD Card interface (wich also uses SPI).
The MOSI, MISO and SCLK lines can be reused and shared between perpiheral devices, as long as only one device is actively being addressed at any point in time. I.e. only one SS/CS may be active at any time and the software must support such sharing of SPI resources.

Welcome to 1K =)

@timemage Thanks!


text:
Arduino MPU6050 AD0 Tricks with offset setting gives corrupted data
I am currently experimenting with two MPU6050 which the AD0 is connected via PIN 7 and PIN 8 respectively, and if this is working, I plan to add another 2 more MPU6050 to it.
I am using i2cdevlib's MPU6050 library and what I did in a flow is:

Initialize one MPU6050 object
Set MPU6050 Object as 0x68 (LOW AD0)
Set all to HIGH, but one to LOW (to select the MPU6050)
Calculate offset and calibrate, store everything in array. (offsets and etc)
Repeat steps 3 to 4 unless all are calibrated.
Start to loop between two MPU, setting everything to HIGH and the one to be used as low.
Write the LOW's (current selected) MPU with offset that is stored in array, then getMotion6 (Raw data).
Write selected MPU to high, repeat from step 6 to step 7.

Everything is working, however when I am having a loop to collect data, it gives me corrupted data, the problem I find is in this function
void loop{
    for (int i = 7; i <= 8; i++) {
      pinMode(i, OUTPUT);

      digitalWrite( i, LOW);
      //      Serial.print("\nWriting pin: ");
      //      Serial.print(i);
      //      Serial.println(" to LOW");
      delay(2);
      int index = i - 7;
      Serial.print("Offsets:\t");
      Serial.print(ax_offset[index]);
      Serial.print("\t");
      Serial.print(ay_offset[index]);
      Serial.print("\t");
      Serial.print(az_offset[index]);
      Serial.print("\t");
      Serial.print(gx_offset[index]);
      Serial.print("\t");
      Serial.print(gy_offset[index]);
      Serial.print("\t");
      Serial.println(gz_offset[index]);

      accelgyro.setXAccelOffset(ax_offset[index]);
      accelgyro.setYAccelOffset(ay_offset[index]);
      accelgyro.setZAccelOffset(az_offset[index]);
      accelgyro.setXGyroOffset(gx_offset[index]);
      accelgyro.setYGyroOffset(gy_offset[index]);
      accelgyro.setZGyroOffset(gz_offset[index]);

      Serial.print(accelgyro.getXAccelOffset()); Serial.print("\t");
      Serial.print(accelgyro.getYAccelOffset()); Serial.print("\t");
      Serial.print(accelgyro.getZAccelOffset()); Serial.print("\t");
      Serial.print(accelgyro.getXGyroOffset()); Serial.print("\t");
      Serial.print(accelgyro.getYGyroOffset()); Serial.print("\t");
      Serial.print(accelgyro.getZGyroOffset()); Serial.println("\t");

      //      delay(1000);
      //      accelgyro.getMotion6(&ax[index], &ay[index], &az[index], &gx[index], &gy[index], &gz[index]);
      int ax, ay, az, gx, gy, gz;
      accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

      Serial.print("PIN ");
      Serial.print(i);
      Serial.print("'s data is:");
      Serial.print("aX:" ); Serial.print(ax); Serial.print("\t");
      Serial.print("aY:" ); Serial.print(ay); Serial.print("\t");
      Serial.print("aZ:" ); Serial.print(az); Serial.print("\t");

      Serial.print("gX:" ); Serial.print(gx); Serial.print("\t");
      Serial.print("gY:" ); Serial.print(gy); Serial.print("\t");
      Serial.print("gZ:" ); Serial.println(gz);

      pinMode(i, INPUT_PULLUP);
    }
}

The first few loops will return accurate data (as in, all the sensors are close 0 [no motion])
I am suspecting because there is a huge difference between both sensors and the getMotion6 is comparing with the old sensor, can that be the case?
Attached is the output of my sensors reading, untouched.


text:
Error compiling for board Arduino Uno SIM7000
I'm using  botletics / SIM7000-LTE-Shield with Arduino Uno, I selected all examples but all end up with the same Error
C:\Users\lenovo\Documents\Arduino\libraries\SIM7000\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::postData(const char*, uint16_t, const char*, const char*, const char*)':
C:\Users\lenovo\Documents\Arduino\libraries\SIM7000\Adafruit_FONA.cpp:2045:3: error: expected ';' before 'readline'
readline(10000);
^~~~~~~~
exit status 1
Error compiling for board Arduino Uno.

do you have some old version of the library? there is no postData function  in current Adafruit_FONA.cpp

There's no "postData" (case sensitive) in any of the files of any of the commits in the Adafruit repo for that library.

I cloned botletics comparatively gigantic repo.  They've modified the Adafruit library without changing the name.
The problem appears to be that you are working out of the current master branch.  Switch to the latest tag, 1.1.0, and the SMS_Response example will compile just fine.  I didn't try all of the others.
Direct link to the zip file for the 1.1.0 tag.


text:
HC-05 Module not receiving commands and not pairing
I'm working on a project where I'll need to establish a connection between two HC-05 modules, each connected to an Arduino, but for now I'm just trying to get one to work and connect to my phone, but I'm not sure if I'm doing anything right...
I'm not able to give AT-Commands, and as a result the device is not able to pair with my phone.
My setup looks something like this:

With minor differences being that I'm using an Uno board instead of a Mega, the RX and TX pins are connected to...well, I tried a lot of different pins, from the default RX/TX pins to specifying other pins like the ones in the code, as well as reversing the connections (RX to TX, TX to RX), also this schematic neglected to mention the 'ENABLE' pin, which I connected to my Arduino's 3,3V pin.
I tried a lot of different code samples, the latest one I tried is the following:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(38400);
  Serial.println("Enter AT commands:"); // a prompt in Serial Monitor
  // Deleted while loop, unnecessary

  mySerial.begin(38400);
}

void loop() { // run over and over
  //if (Serial3.available()) { // we don't use Serial3 any more
  if (mySerial.available()) {
    //Serial.write(Serial3.read());
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    //Serial3.write(Serial.read());
    mySerial.write(Serial.read());
  }
}

Which I blatantly ripped-off from this answer, with minor changes.
So, I connect my Arduino to my PC, upload the code, connect my module, set the serial monitor's baud rate to 38400 and...a bunch of gibberish appear on screen, just an alternating sequence of the characters 'x' and '?', to my understanding that's actually the message "Enter AT commands:" written in my code...
Now, with this exact setup, I'm now actually receiving a response to my commands, except the response is also gibberish, this is as far as I've gotten.
EDIT: By following some of the comments and setting the Serial baud rate to 38400, I managed to get other Reponses to my commands, but it's just a new type of gibberish and it's still not actually responding to my commands.
The thing is, all of the tutorials I've seen online are contradicting each other, some connect the RX and TX pins in reverse to the Arduino, some don't, some specify other pins on the board, some don't bother with the ENABLE pin entirely, some don't use a voltage divider, some connect VCC pin to the 3,3V instead of the 5V, some even skip the AT-Command setup entirely!
One last detail I feel like I should mention, there's a red light that blinks on and off every two seconds, I believe that means the module is read to receive commands but I've seen contradicting information about this as well so I'm not sure.
I want to know what I'm doing wrong, and what's the right way to do this?

I spent hours trying to figure this out too. So many pitfalls, RX vs TX, software serial vs pins 1/0, baud rates, NL & CR settings in the serial monitor, having to press the button while powering on the module.

It's been a year since I made this post and I sadly don't remember the setup I did to solve the problem, I think it might have been not using and resistors and just directly connecting the HC module to the Arduino, sorry but I'm not sure.

You have seen contradictory statements, because there are many variables here, that might be different for each of the tutorials.

some connect the RX and TX pins in reverse to the Arduino, some don't, some specify other pins on the board

There are basically 2 ways to communicate between the Serial Monitor and the HC-05:

You can connect the HC-05 directly to the USB Serial chip on the Arduino board, thus you would communicate directly with the HC-05. In that case the TX and RX pins are used, since they are connected to the USB Serial chip. But the labels TX and RX are referring to the Arduinos chip (Atmega328p at the Arduino Uno). Since serial connections need to be connected alternating (RX to TX and TX to RX), the pin labeled TX leads to the RX pin of the USB Serial chip and vice versa.
Thus you would connect TX of HC-05 to the TX pin on the Arduino and RX of HC-05 (through the voltage divider) to the RX pin on the Arduino. Also you should program the Arduino with an empty sketch before doing that, so that the Arduino does not interfere in the Serial communication with its own Serial usage.

Or you can use a SoftwareSerial interface and let the Arduino code translate between the devices. The Arduino received from the PC and sends the data to the HC-05. Also it receives from the HC-05 and sends that data to the PC. This is what you were trying. But you absolutely need to specify a different set of pins for the SoftwareSerial interface, than 0 and 1. These pins are doing the hardware Serial interface, which is connected to the PC. So change these pin numbers (for example to 2 and 3).
In fact: Whenever you see a code for Uno, Nano or Mega using SoftwareSerial on pins 0 and 1, you can be sure, that it is garbage.

I connect my Arduino to my PC, upload the code, connect my module, set the serial monitor's baud rate to 38400 and...a bunch of gibberish appear on screen

Even when you change the pins as described above, your code still uses 9600 baud for the connection to the PC. When you set the Serial Monitor to 38400 while the code uses 9600 baud for that interface, you will get just gibberish. Either change your Serial Monitor to 9600 baud or change your code to Serial.begin(38400). The last option is better, since that makes sure, that you are using the same baudrate for both interfaces.

some don't bother with the ENABLE pin entirely

The ENABLE pin seems to have a pulldown resistor on the HC-05 board, which pulls it to ground, when nothing is connected. Ground means data mode, HIGH command mode. So when they don't connect anything, they want to stay in data mode. Though this also depends on if the specific HC-05 board has a pulldown or pullup resistor there. Pulldown is more likely, but since there is no one single producer of these modules, you cannot be sure. Since you want to get into AT mode, you should use command mode and connect it to 3.3V. For normal operation it would go to ground. Though you can also connect it to a digital output pin of the Arduino and let the code decide in which mode the module should be.

some don't use a voltage divider

The chip on the HC-05 board is a 3.3V device. The actual breakout boards, that can be bought everywhere, mostly only add a voltage regulator from 5V to 3.3V, an LED for status display and break out the necessary pins. The data pins are mostly directly connected to the chip. There are many resources, that claim the HC-05 to be 5V tolerant, but also many that antagonize that. To be sure not to destroy the HC-05, you should also use a voltage divider.

some connect VCC pin to the 3,3V instead of the 5V

This is only done, when the used board does not have a 5V to 3.3V voltage regulator. Depends on the exact board, that you own.

some even skip the AT-Command setup entirely!

When they don't need to configure the HC-05 in a special way, why would they go into command mode. That might be different for you.

Voting yours up.  Seems to say everything mine says and more.  I'm guessing based on the length and detail you started before I did as well.

Ok, I changed the code to Serial.begin(38400), the "Enter AT commands:" message does appear as normal now, and the command responses are...less gibberish now, seem to be a mixture of '?'s and whatever command I typed, but it's definitely still not receiving the commands, I tried changing the device's name and it still appears as "HC-05" (The default name)on my phone, after that I switched the RX and TX pins to  2 and 3 respectively, and now it's not even responding to my commands.

Have you switched the physical connections of the HC-05 to the new pins and also changed the pin numbers in the code? and connected HC-05 TX to the RX of your SoftwareSerial interface?

Btw: Where exactly are you failing to establish the connection? When it appears on your phone, I assume, that the pairing would work. The real connection is then established by a fitting app. The Android bluetooth setting page (where you can pair devices) does not do the real connection.

@chrisl Yes, I have switched the physical pins to the new positions, and tried both combinations (RX to RX & TX to TX, and then RX to TX and TX to RX), still no response, as for how I'm trying to connect, I thought I was supposed to connect through setting page first, that's where I was failing, but I did try using a fitting app I already had installed (Bluetooth Terminal), but no luck, can't connect through that one either.

pins 2 and 3 on Mega don't support pin change interrupt used by SoftwareSerial

@Juraj I'm using an Uno, does that still apply?

@TheRiser You can add the new code version and the new wiring to your question by editing it. Just add it as an update at the end of your question. Then we can look further. Comments are not really made for discussions. Also that way someone else might see the problem, without going through all the comments

Alright, thanks.


text:
nuttx hex too large
I have a teensy 4.1, and I am trying to install NUTTX the Real Time Operating System ( RTOS ). Teensy is a supported platform.
I am trying install nuttx compiled from source, and upload it using the teensy loader program. my current issue is that the hex file is too large. the file size is 229Kb, which shouldn't be an issue where the flash size for a teensy 4.1 is 8MB.
I have been following the steps on these websites:
this one where Nuttx is installed on a teensy 3, and the documentation for nuttx on their website
any tips or recommendations to install nuttx on a teensy 4.1 would be greatly appreciated.

OK, so I pressed the reset button and the teensy loader program reset, and reloaded the hex file. Now it lists as I would expect it to, using 1% of the flash space. and uploads without error.


text:
PWM and Analog Signal Quality
I'm converting a 0-5v PWM signal to an analog signal using an LM358D. I've connected the output to an oscilloscope to look at the signal but I'm not really sure what I'm looking at. The PWM looks ok but I'm unsure of the analog signal.
Here's some images, please let me know what you think.
Both pics are at 50% signal strength. The oscilloscope is set to defaults, simply connected the probe.
Thanks

EDIT:
Here's the schematic for the PWM to analog converter. The cap is a tantalum. The dip switch changes the analog from 5v to 10v, the signal looks the same on both and is correct voltage so seems to be ok?

What are you expecting to see? That looks like a 50% PWM duty cycle so are you expecting 2.5V on the output (as a straight line)?

The voltages check out but I'm not sure of the analog signal. When I see other images the line is smooth curve at top and bottom but I don't know if that's a setting on scope or I have a bad signal? If the triangles look good I'm happy.

You need a resistor and capacitor to smooth the signal. Do you have those? Perhaps edit your post to show your schematic.

What do you mean with "smooth"? the signal has an amplitude of 584mV according to the measurements of your scope. Is that smooth enough? If you want to compare the image of the signal, you need to set the same y-div setting as in the reference image

Something like this should work:

With this code on a Uno:
void setup () { }

void loop () {
  analogWrite (3, analogRead (A0) / 4);
}

For slightly more details see my post about doing that.

Thanks, that's actually the same I'm using and guess what, I got the original from you. ) I knew your name looked familiar. I'm using a tantalum 10uf cap but resistor is only 220 ohm and I have an extra resistors someone said to add, I'll add the schematic.

You have a much lower resistor (220Ω vs 4700Ω) than I did. The higher value resistor will charge the capacitor more slowly, thus smoothing out the signal and effectively giving you an average, which is what I assume you are trying to do.

My op-amp was configured for unity gain, I don't know why you need those extra components.

The PWM looks ok but I'm unsure of the analog signal.

The “analog signal” looks like the PWM smoothed by a first-order
low-pass filter. It still has some oscillations, 584 mV
peak-to-peak. If you can tolerate that, then it's perfectly fine. If
not, then increase the time constant of your filter.
A first-order low-pass filter behaves, in its stop band, like an
integrator. Thus, a square signal is turned into a triangle. You are
seeing exactly the expected behavior.

The oscilloscope is set to defaults

There are no “default” settings in the oscilloscope. You probably used
the “autoset” button instead. This button tries to find some settings
that let you see something on the screen. I mean, some kind of signal,
not just straight line. If the signal is almost flat, the autoset will
increase the gain until you can see it is not flat. In this case, it
increased the gain by a factor 10 (200 mV / division instead of
2 V used previously). It also added a negative offset in order to
avoid the trace going out of the screen. See the small pentagon on the
far left with a “1” inside? On the first picture this tells you where
the zero (the reference potential) is relative to your signal. On the
second picture, the polygon pointing at the bottom of the chart tells
you the zero is off-scale.
If you want to really appreciate the smoothing action of the filter, you
have to look at its input (the PWM signal) and its output (the “analog”
signal) using the exact same settings. Connect the input, hit “autoset”,
and look. Then connect the output, do not change the settings (do not
hit “autoset”) and look at the output.
Better yet: forget the autoset button, adjust the settings manually and
mind their values.
Better yet: as you have a two channel scope, display both signals
simultaneously, using the exact same settings on both channels.

Thank-you for the detailed reply, I appreciate it! I updated the original post with schematic. What's an "acceptable" peak-to-peak? If a resistor or cap would improve that would be good. You can see I have PWM freq at 1000 Khz, is there a "magic" number? I use pca9685. I couldn't see any difference on scope, only PWM. My scope does have a "default" button and "autoset", latter was useless as it zoomed out so I manually set to view, I did use same settings for both signals just had to change voltage scale so I could view better. Thanks!

@tryingHard: 1. It is up to you to decide what you would consider “acceptable”. It's your application! 2. If you want less residual oscillations, increase the value of R78. 3. The PWM frequency is 1 kHz, not 1000 kHz. 4. There is no magic.

Thanks, impossible for me to know what is acceptable when I don't know what the number means, not something you can understand after an hour of reading. Maybe 500mV isn't bad or maybe it's horrible. I will see what happens with R78 and thanks for clarifying frequency.

@tryingHard: Re “acceptable”: it depends on your application, on what you want to do with that signal. “Acceptable” means “acceptable by whoever will be the consumer of the signal”.

I hear you, it's for LED drivers and aquarium power heads.


text:
DC motor with slow speed to actuate mirrors
I am thinking to use Arduino to control a DC motor and apply a small torque to move the mirrors of my interferometer experiment. I have the components from the Arduino Starter Kit K000007, just to understand how it works because I am approaching it just now.
The mirror mount has a knob with a 2mm Hex hole and each revolution corresponds to a displacement of 50 microns: I would need a speed around 1/50 revolution/second, or even less. Is it possible to move the motor that slow?
Moreover, I should use a coupler to interface the motor with the knob, basically some joint to connect the shaft to a 2mm Hex bar or something: could you suggest a way to do so?

DC motors are made for spinning. Trying to spin it in sub full revolution steps is not really possible. But you can use a geared DC motor, where the rotor after the gear is slow enough for your purpose. Also this can give you enough torque for moving the knob (since small DC motors are often rather weak by their own). You can find geared DC motors with many different values (torque, voltage, speed, gear ratio, size...) at the typical online sellers. The small ones are rather cheap, so you might just buy some and test out, whats fitting for you. Otherwise you would need to set exact requirements for torque and speed (and maybe other parameters) and then search for a fitting one.
Also keep in mind, that you need something like a driver circuit for the motor. Since you will want to drive it in both directions, a H-bridge is needed. You can build those yourself with transistors, or buy a small chip, which incorporates the complete H-bridge (make sure to use one with MOSFETs in it, since they are more efficient). Also don't forget the flyback diode to avoid killing the electronics with the induction voltage from the motor.

I should use a coupler to interface the motor with the knob, basically some joint to connect the shaft to a 2mm Hex bar or something: could you suggest a way to do so?

Yes, you need some kind of coupler. But we cannot really suggest something here. It depends totally on your exact setup. This mechanical part will be something, that you have to design. There are different kinds of couplers available online, but I don't know, if they are good for your purpose.
Also maybe you should make sure to make the coupler flexible on the other axes than the rotation axis. That way the motor will not stall when a small disalignment happens, and the vibrations from the motor might not get transmitted to your mirror as much. I know this principle from my 3D printer, which uses a coupler like this one:

Thank you! As I need a ratio of severlal thousands to one, I have to use a gearbox for sure. For the H bridge yes, I saw it in one of the projects contained in the starter kit, thus I should be covered for that.Regarding the coupler, I think that I could ask the university workshop to manufacture one similar to the one you suggested very easily.


text:
Neo 6m outputting something i as a noob can't understand
So i connected my ublox neo 6m gps breakout board GY-GPS6MV2 to the arduino software serial and got this result, i used resistors and only supplied 3.3v to the board, gps encode library couldn't give me anything out of this. if possible please help and if this is the wrong forum please suggest a better one. also the board thinks that the date for some reason is Mar 17 2011 16:18:34*59. which is pretty wierd.

$GPTXT,01,01,02,HW UBX-G60xx 00040007 FFF9FFFFp*5D

$GPTXT,01,01,02,ROM CORE 7.03 (45969) Mar 17 2011 16:18:34*59

$GPTXT,01,01,02,ANTSUPERV=AC SD PDoS SR*20

$GPTXT,01,01,02,ANTSTATUS=DONTKNOW*33

$GPRMC,,V,,,,,,,,,,N*53

$GPVTG,,,,,,,,,N*3⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$GPTXT,01,01,02,HW UBX-G60xx 00040007 FFF9FFFFp*5D

$GPTXT,01,01,02,ROM CORE 7.03 (45969) Mar 17 2011 16:18:34*59

$GPTXT,01,01,02,ANTSUPERV=AC SD PDoS SR*20

$GPTXT,01,01,02,ANTSTATUS=DONTKNOW*33

$GPRMC,,V,,,,,,,,,,N*53

$GPVTG,,,,,,,,,N*3⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$GPTXT,01,01,02,HW UBX-G60xx 00040007 FFF9FFFFp*⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$GPTXT,01,01,02,HW UBX-G60xx 00040007 F⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$GPTXT,01,01,02,HW UBX-G60xx 00040007 FFF9FFFFp*5D

$GPTXT,01,01,02,ROM CORE 7.03 (45969) Mar 17 2011 16:18:34*59

$⸮$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

$GPTXT,01,01,02,HW UBX-G60xx 00040007 FFF9FFFFp*5D

$GPTXT,01,01,02,ROM CORE 7.03 (45969) Mar 17 2011 16:18:34*59

$GPTXT,01,01,02,ANTSUPERV=AC SD PDoS SR*20

$GPTXT,01,01,02,ANTSTATUS=DONTKNOW*33

$GPRMC,,V,,,,,,,,,,N*53

$GPVTG,,,,,,,,,N*30

$GPGGA,,,,,,0,00,99.99,,,,,,*48

$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30

$GPGSV,1,1,00*79

$GPGLL,,,,,,V,N*64

$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50

Here is the full unedited output after 40 mins
https://drive.google.com/file/d/148W_6shE0U2lprimApvtvG1i3Vf2-Izx/view?usp=sharing
edit:- i also connected the tx pin to the rx and vice versa and used a resistor as told by an tutorial on the tx pin from the arduino or the rx pin of the board. it is also sending many gptxt messages which some say on other forums are usally send when some error occurs or the board restarts. idk why it is coming on my board.

does anyone know anything i can do to fix it?

What do you mean by " i used resistors and only supplied 3.3v to the board" ?

@Majenko i followed a tutorial which said me to attach 3.3v to vcc pin and use resistors on the tx pin which sends data from arduino.

Why do you think there's something wrong? What kind of output did you expect? The GPS is outputting NMEA data just like it's supposed to. It's not supposed to be human readable. You mention a date in 2011 but that's looks to be the date the ROM core was compiled, not wat the GPS thinks is the current date. Not weird at all. You need software to interpret the NMEA output, like TinyGPS. Try it.

@StarCat the gps is supposed to atleast give proper nema data and a nema lat long, but if you open the drive doc, the nema is just sending gptxt texts and most of the nema fields are empty. and tinygps just gives 0,0 at lat long and this is after keeping it on for 40 mins

That's because it probably does not have a fix yet. That may take a very long time and your GPS needs to have an unobstructed view of the sky. Many "U-blox" GPS chips are fake and can have all kinds of problems (like taking impossibly long to get a fix).

It looks to me like it's browning out and resetting repeatedly.

@Majenko yeah thats what i thought too. please help if you can

@StarCat the chip is real and i can assure you the chip is real.

@gamer1478 Ok, if you say so. Did you run checks to confirm it and did you buy it from a reputable seller? Do you have a link to where you bought it or do you have any documentation for the module? It looks like the power supply might be an issue. Maybe a photo of your setup might help.

@StarCat Yes. I bought 10 chips from the seller and the seller is reputable from china. I buy from him using alibaba. And all other chips are working and getting gps lock and data using the same circuit and Arduino. Due to the low value of 1 chip replacement is not an option as delivery value from india to china with export taxes is higher than the value of the chip. If possible please tell some way to fix this. My power supply is just normal Arduino Uno 3.3v supply. I can't share a photo due to some privacy concerns.

@StarCat I am very new to gps and gps chips but I am by no means new to coding or  arduino. I meant I am noob in like gps and stuff. I have used the gps chip also in my drone following a tutorial and it works absolutely fine there.

Ok, I understand. I'm asking because I know there are a lot of fakes around (have run into them myself). Is there any way you can check for a stable power supply or a marginal connection? Or do you have a schematic? It's hard to troubleshoot something that I can't see. If you say that all of the other chips you bought are functioning well, I would consider the possibility that this one is faulty. I know some GPS boards are 5V tolerant and have their own 3.3V stabilizer. Maybe yours is too?

@StarCat i have a GY-GPS6MV2 chip. this is the wiring-(https://www.xarg.org/image/GY-GPS6MV2.png) (but instead of vcc to 5v it is connected to  3.3v), many people online say that this breakout board is 5v tolerant and has an onboard regulator, haven't tested that yet but all other chips are working too, so it might be that this one is faulty. but i don't think so as this problem is pretty new to me, it is printing stuff in the console but has no data in it.

@StarCat thanks for help, someone on ublox portal recommended me to connect the boards vcc to 5v's and when i did that, it stopped rebooting, and after 20 mins got a lock, thanks for your help.

someone on ublox portal recommended me to connect the boards vcc to 5v's and when i did that, it stopped rebooting, and after 20 mins got a lock, thanks for your help.
the guy on ublox portal

Post a photo of the board and a link of where you bought it so that we can point out that 5V is needed.
The reboot symptom is usually caused by an inadequate voltage source --- when the 6m starts, current draw is low, when it finishes initial startup, it goes to work looking for sats and current draw jumps up. The higher current draw on a poor power source causes supply voltage to drop too.low which then causes the 6m to reset and restart and will happily repeat the cycle forever.
Use a good DVM or oscilloscope to verify the inadequate voltage source.

after connecting the board to 5v supply the problem seemed to be fixed


text:
Stepper Motors Strange Behaviour
I am working in a project in which I need to control at the same time three NEMA17 stepper motors. In order to do so, I am using three DRV8825 drivers working at 12V connected to an Arduino MEGA.
This Arduino is generating the pulses in velocity ramps so that we have an accelerated movement to reach the goal.
The schematic I am using for connecting the drivers is the one that the manufacturer recommends:

With a digital analyzer, I can see that my velocity ramp is being generated properly:

In this picture below you can see how steps (ST) are generated once the direction (DR) is set for each of the motors. The time waiting after the direction change is bigger than the necessary established by the manufacturer and also does the duration of the step pulses.
Following this, the motors are supposed to make an accelerated movement until reaching a certain position and then, decelerate and stop.
Although, I am facing the problem that, in some cases, one of the motors (not always the same one) makes a few steps in the opposite direction of the movement and, after that, it executes the expected movement. This leads to, even of making the three motors perform the same movement, one of them finishes differently.
I tried to change the drivers but the same happens. Also, as I said before, I have checked that the pulses are correctly generated.
I would like to know if anyone has faced a similar problem or knows any reason that could lead to this strange behavior.
Thanks.

/fault is an active low output

So, apparently the motors I am using have a optimal work range that doesn't start at 0 but 200PPS. Though, even generating properly the velocity ramps, when using a low acceleration, my motors would be running for some steps outside this optimal range, causing strange movements at the beginning of the movement.
In order to solve it, these non-optimal low velocities are avoided while accelerating so that motors enter directly to the optimal work area.


text:
pull-up or pull-down
Do you have to build the circuit on an external board every time you decide there is a need
for a pull-up or pull-down circuit? If not, then what is the alternative and how can you use
it?

This depends on what you are doing.
The IO hardware of the Uno (more specific the Atmega328p, which is the used chip) has internal pullup resistors, that can be used, when the pin is configured as input. This can be done in one line:
pinMode(pin_number, INPUT_PULLUP);

This is true for all AVR based chips.
Other, more complex and capable chips also have an internal pulldown resistor (as I remember this is true for the ESP32 for example). In this case you can do
pinMode(pin_number, INPUT_PULLDOWN);

If you are using special hardware of the Arduino, it depends on the hardware itself, since in most cases the normal IO hardware is internally not connected to the pin, when using this hardware. For example: The internal pullup resistor will not be active, when doing an analog measurement with the ADC (like via analogRead()).