text:
Different functions using 2 buttons
I'm currently learning Arduino. So right now I'm trying to create an Arduino app that will use buttons, LEDs and RGB.
So I have 2 buttons, 8 LEDs and an RGB. The first button is the function switcher: when you press it the LED will light according to their function. The second button is the function activator so right now here's I want to do:

Function 1: Turn on/off RED light
Function 2: Increase RED light brightness by 5; if already at 255, reset at 0
Function 3: Turn on/off GREEN light
Function 4: Increase GREEN light brightness by 5; if already at 255, reset at 0
Function 5: Turn on/off BLUE light
Function 6: Increase BLUE light brightness by 5; if already at 255, reset at 0
Function 7: Turn on ALL lights, all brightness to 255
Function 8: Turn off ALL lights, all brightness to 0

I already started coding and I'm stuck at turning on and off the red light. Here's my code:
const int red = 5;

int b1, b2; //Buttons
int dir = 0;
int light = 11;
int func = 0;
boolean buttonValue = true;
boolean buttonState = true;

void setup() {
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(red, OUTPUT);
  for (int i = 11; i <= 18; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  b1 = digitalRead(2);
  if (b1 == HIGH) {
    dir = 2;
    func++;
    if (func >= 8)
      func = 0;
    } else {
      dir = 0;
    }
    digitalWrite(light, LOW);
    if (dir == 2 && light < 18) {
      light++;
    }
    digitalWrite(light, HIGH);
    delay(200);
  }

void function(int pin) {
  b2 = digitalRead(3);
  switch (func) {
    case 1:
      if (b2 = true) {
        digitalWrite(5, HIGH);
      } else {
        digitalWrite(5, LOW);
      }
  }
}

ArduinoMenu library can do that, using a code driven menu (driven by the 2 buttons) and an headless menu (no output devices). Menu event handlers can then control the led, I've done this for an RGB led with only 2 buttons. https://github.com/neu-rah/ArduinoMenu

I have to be honest after reading you description and looking at you code I have no idea how you arrived at the code you have arrived at.
For now lets try a much simpler bit of code, once that is working you can build on it.
#define PIN_BUTTON_1    2
#define PIN_LED_RED     5

void setup() {
    pinMode(PIN_BUTTON_1, INPUT);
    pinMode(PIN_LED_RED, OUTPUT);
}

void loop() {
    const int buttonState1 = digitalRead(PIN_BUTTON_1);
    digitalWrite(PIN_LED_RED, buttonState1);
    delay(200);
}

If that code doesn't work then there is something wrong electrically.
I think is the next step you were trying for:
#define PIN_BUTTON_1    2
#define PIN_LED_RED     5

int lastButtonState1 = LOW;
int functionNumber = 0;
int currentLedValue = 0;

void setup() {
    pinMode(PIN_BUTTON_1, INPUT);
    pinMode(PIN_LED_RED, OUTPUT);

}

void loop() {
    const int currentButtonState1 = digitalRead(PIN_BUTTON_1);
    if (lastButtonState1 != currentButtonState1)
    {   // If the button's state has changed
        if (currentButtonState1 == HIGH)
        {
            ++functionNumber;
        }
        lastButtonState1 = currentButtonState1;
    }
    DoFunction(functionNumber);
    delay(200);
}

void DoFunction(const int& function)
{
    switch (function)
    {
    case 1:
        if (currentLedValue > 0)
        {
            currentLedValue = LOW;
        }
        else
        {
            currentLedValue = HIGH;
        }
        digitalWrite(PIN_LED_RED, currentLedValue);
        break;
    case 2:
        currentLedValue = 128;
        analogWrite(PIN_LED_RED, currentLedValue)
        break;
    default:
    }
}

If you would like to call the function you defined at the end of your code you need to give it a name function name()....
In your code you used if (b2 = true). That will not work as expected, since it sets the b2 variable to true. Note the if expressions use == to compare values, see the Arduino Reference. Further you should use the HIGH and LOW Pin level constants for comparing pin states as described here.
So your code will look like

    if (b2 == HIGH) {
        digitalWrite(5, HIGH);
    } else {
        digitalWrite(5, LOW);
    }

or shorter just:
digitalWrite(5, b2); without the if/else expressions.

Hi! I already figured it out but I was wondering why the RGB doesn't turn on.


text:
Optimizing ext. SPI ADC for speed and verify the speed
So I have a project where I will be using an Arduino Leonardo and an external ADC (AD7980) to run a 16-bit (18bit) conversion and transmit it to the Arduino and then out on USB as fast as possible.
The AD7980 can run up to 1 MSPS, and I know I cannot reach that with the ATmega32U4 - but I want to know how to optimize my code for running it as fast as possible and how to measure it.
Right now my code is:
#include <SPI.h>

int CNV= 11; //Convert on pin 11
int Slaveselect=8;
int adcValue;
byte highByte;
byte lowByte;

void setup() {
  Serial.begin(115200);
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV2 ); // 8 MHz rate
  SPI.setBitOrder(MSBFIRST);
  pinMode(Slaveselect, OUTPUT);
  pinMode(CNV, OUTPUT);
}

void loop() {
  digitalWrite(Slaveselect,HIGH);
  // SS always high to use 3 Wire mode without busy indicator
  digitalWrite(CNV,LOW);
  digitalWrite(13,LOW);
  digitalWrite(CNV,HIGH);//starts conversion
  digitalWrite(13, HIGH);
  digitalWrite(CNV,LOW); //starts to transmit MSB on data line
  digitalWrite(13,LOW);
  highByte = SPI.transfer(0x00);
  lowByte = SPI.transfer(0x00);
  adcValue = highByte << 8;
  adcValue = adcValue | lowByte;
  Serial.print("analog value =");
  Serial.println(adcValue);
  Serial.print('\n');
}

The datasheet for the ADC can be found here: Datasheet

Don't use digitalWrite().
Don't use delay().
Don't flood your Serial connection with useless junk ("analog value =")

You may also consider using lower level SPI operations instead of the SPI library, which is completely blocking and slows you down. At least consider the use of SPI.transfer16(...) which is more efficient than two SPI.transfer(...) calls.

"1. Don't use digitalWrite()" What should i use then?

@Martin.E Direct port manipulation. https://www.arduino.cc/en/Reference/PortManipulation

Either write on GPIO registers directly (https://www.arduino.cc/en/Reference/PortManipulation, http://stackabuse.com/speeding-up-arduino/) or use at least https://github.com/NicksonYap/digitalWriteFast .

Also - changed my code to not use delay() and changed to SPI.transfer16 - now I have a sample periode of 44 micros - #Edit - With digital write fast, i am now down to 8 Micros

But by useing this, It looks like i lost some precision - Before this change, my max ADC value was 32000 - now its around 19000, and my minimum was 0 now it is 10000

You are probably violating some of the timing specifications (p.7f of the PDF). Conversion time is at least 500ns to at max 710ns, and the SPI.transfer might kick in before that. Time between conversions is at least 1000ns, acquisition time 290ns. FastDigitialWrite needs ~125ns on a 16MHz Uno. You should probably get an oscilloscope / logic analyzer to debug this thing now on these speeds. "Waiting" can also be done by burning cycles using the "NOP" instruction (https://forum.arduino.cc/index.php?topic=433372.0)

For fast possible speed, use spi transmission buffer and spi interrupt. The concept is that once there is at least free space in the buffer, it interrupts and you load the next byte into the buffer.
That's assuming that dma isn't available.
Short of that, don't use arduino GPIO functions - they are like 100x slower than that's possible. And use a usartt isr to  manage transmission.

source: Stack Exchange

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

sort: votes


text:
How to control RC power switch with Arduino-/Adafruit-Board?
I want to control (switch on/off) a solenoid valve via an RC power switch and an Adafruit M0 Feather Bluefruit LE. The RC power switch is this one, and this is the Adafruit Board Pinout.
My assumption was that I have to wire up the servo wire connector of the power switch with the Adafruit board like I would do with an ESC and control it via PWM (my guide tells me that possible pulse widths are between 870 and 2,220 µs). I am connecting the white cable (I assume it's the impulse wire) of the power-switches' servo-connector with a PWM-capable GPIO pin and the black cable (I assume it's the minus wire) with the GND pin of the Adafruit Board, like I did with an ESC, which is working fine with the servo library of Arduino.
My problem is that the solenoid valve is showing no reaction. Am I thinking the right way or am I completely wrong?
Thank you and many thanks.

The Code for successfully controlling the escs is like: gist.github.com/vitorleal/9083802

I'm voting to close this question as off-topic because it is about RC gear not about Arduino.

I fixed the problem by myself. If you want to arm an RC power switch, do it like arming an ESC with your sketch. The servo connector wires have to be connected as follows:

(white) PWM-capable GPIO
(red) positive wire of your battery
(black) negative wire of your battery

The simple solution was that the power switches got less/no power.

"arming" as required by a typical ESC typically means running the throttle PWM up and back down to demonstrate that there's a prepared driver/pilot at the controls.  What you are describing sounds more as if you are simply providing power to a switch designed to be powered by the RC receiver rather than to power itself (and potentially also the receiver) from the motor battery.

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


text:
If and while statements not working
The second and third while and if are not working but the first while and if do work. Am I doing something wrong?
#include <DFMiniMp3.h>

int sw1 = 3;
int sw2 = 4;
int sw3 = 5;

class Mp3Notify
{
  public:
    static void OnError(uint16_t errorCode)
    {
      // see DfMp3_Error for code meaning
      Serial.println();
      Serial.print("Com Error ");
      Serial.println(errorCode);
    }

    static void OnPlayFinished(uint16_t globalTrack)
    {
      Serial.println();
      Serial.print("Play finished for #");
      Serial.println(globalTrack);
    }

    static void OnCardOnline(uint16_t code)
    {
      Serial.println();
      Serial.print("Card online ");
      Serial.println(code);
    }

    static void OnCardInserted(uint16_t code)
    {
      Serial.println();
      Serial.print("Card inserted ");
      Serial.println(code);
    }

    static void OnCardRemoved(uint16_t code)
    {
      Serial.println();
      Serial.print("Card removed ");
      Serial.println(code);
    }
};
DFMiniMp3<HardwareSerial, Mp3Notify> mp3(Serial); //Create the UART connection to the module

void setup()
{

  //3 push buttons with pullups
  pinMode(sw1, INPUT); //Define each button as input with pullup
  pinMode(sw2, INPUT);
  pinMode(sw3, INPUT);

  digitalWrite (sw1, HIGH); //12 Votls supply set to off state
  digitalWrite (sw2, HIGH); //5 Votls supply set to off state
  digitalWrite (sw3, HIGH); //3 Votls supply set to off state

  Serial.begin(9600);
  mp3.begin(); //Start communication with the DFplayer module
  uint16_t volume = mp3.getVolume(); //Get actual volume
  mp3.setVolume(30); //Set new volum (max is 30)
  uint16_t count = mp3.getTotalTrackCount(); //Get the total tracks on the SD card in case we want to sue this later...
}

//just a fucntion that we use to create delays in "ms"
//without using the delay() function
void waitMilliseconds(uint16_t msWait)
{
  uint32_t start = millis();

  while ((millis() - start) < msWait)
  {
    // calling mp3.loop() periodically allows for notifications
    // to be handled without interrupts
    mp3.loop();
    delay(1);
  }
}

void loop()
{

  if (digitalRead(sw1) == LOW)
  {
    mp3.playMp3FolderTrack(1); // Play audio track 0001
    waitMilliseconds(5000); // 1s of delay
    while (digitalRead(sw1) == HIGH); // do nothing until state changes

  }

  if (digitalRead(sw2) == LOW)
  {
    mp3.playMp3FolderTrack(2); // Play audio track 0002
    waitMilliseconds(5000); // 1s of delay

    while (digitalRead(sw2) == HIGH); // do nothing until state changes

  }

  if (digitalRead(sw3) == LOW)
  {
    mp3.playMp3FolderTrack(3); // Play audio track 0002
    waitMilliseconds(5000); // 1s of delay

    while (digitalRead(sw3) == HIGH); // do nothing until state changes
  }
}

Am I doing something wrong? - if the alternative is that while/if statements do not work, then sure, you're doing something wrong. Please format your code properly and someone will help you find the mistake.

@SimSon, from the basic concept it looks fine. I need someone to help me with this.

Thanks for formating the code. The code just behaves differently than you expect, but those statements definitely work. What makes you believe they don't? Please add your observations and expectations into the question.

@SimSon, After "void loop" I have 3 "if" statements. The first one works, but not the second and not the third. If I changed the order of "if" statements then just the first work works. it doesn't matter which one of "if" statements are placed after first "if" statement but the after the first statement others doesn't work.

After pressing sw1, the while (digitalRead(sw1) == HIGH); line just makes it sits there without continuing with the rest of the code until you press sw1 again.

You should substitute the mp3 stuff with serial prints in each if clause and while loop to debug this.

@ocrdu, yes that is fine. but the second "if" statement doesn't function.

@ocrdu actually no. After execution enters any of the if statements, the while loop is meaningless if the button state hasn't changed

@Sim-Son They are push buttons that change state on release, and there's a delay that gives plenty of time for that release.

Does sw2 work if you haven't pushed sw1 at all since the last reset?

Maybe you better have a look how to read a button properly. The loop is executed so fast that reading a button like that won't give any good results anyway. You want to detect when the button changes its state, not if it is in a certain state. You're also better off using non-blocking code and avoiding delays like in the BlinkWithoutDelay example. If you keep several buttons pressed and release them randomly, you'll see that the 2. and 3. ifs are executes as well.

@ocrdu, no. Sw2 and sw3 don't work. If I change the order to sw2, sw3, sw3. Now the sw2 works. If I change the order to sw3, sw2, sw1 then sw3 works. I keep pressing all the buttons, but only the first "if" statement works and not others.

@ocrdu yes, you're right. Actually, after the while loop 1 has finished, the corresponding if statement is re-entered immediately on the next loop iteration unless button 2 or 3 is pressed.

Don't keep pressing all the buttons, reset the Arduino and only press sw2. Does sw2 work then?

@ocrdu, no, not working. Just the first if statement works.

How do you know if you only pressed sw2 after reset? Comment out the delays and the while loops. Do all buttons work then?

@ocrdu, 1- Power supply is off. 2- now power supply turned on. 3- non of switches connected. 3- switch number one held down. 4- MP3 played. 5- sw1 released. 6- sw2 pressed. 6- nothing happens.
7- sw1 pressed and released to see if it needs reset.
8- sw2 pressed, released, held down > nothing happens.
10- if the the sw2 code moved above sw1 "if" statement then sw2 works.

After pressing sw1, the first if works. After releasing sw1 (it's a push button), the line while (digitalRead(sw1) == HIGH); will make the code just sit there forever without continuing with the rest of the code until you press sw1 again, which will be caught by the first if unless you release 'sw1' inhumanly fast.
So, once you have pressed and released sw1, the rest of the code with the next two ifs will never run.

your last statement looks right, but somehow it can't figure out the problem.
If I held the sw1 down and press the sw2 then sw2 start working. Now only sw2 functions sw1 not working. The switching locks to sw2. but when I reset everything it goes back to sw1.

The while loops block the execution. Maybe it will work as you intended if you remove them and make the delays a bit shorter.

I use a DFmini player. It works well if the button is press and release. But in my case, the button will need to be held down. the problem with holding the button down is that the MP3 get played over and over. I want it to play only for once if the pin is high and or button is held down for a long time. If i remove the "while" then it will play over and over again. does not stop.

If you use a blocking delay, no button will respond during the delay time, and only repeat after the delay time. Or, debounce the buttons (you can look that up) and use a long debounce time, basically debouncing the push button and the human too.

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


text:
How to test continuity on signal wire?
I’m reassembling an LED strip, SK6812, that I had cut into smaller lengths. I don’t have a lot of faith in the connectors I’m using or my ability to solder, so I’d like to test it before I put power to it. A simple continuity test is easy for the power “wires” but how do I test the signal “wire”?

The easiest way to test that is to use it, first checking that data doesn't have continuity with gnd or v+ (although that shouldn't really hurt anything anyway).

If you have a multimeter, that has a continuity or resistance measurement mode, you can use this. And when you suspect the connectors being bad, you could just measure the continuity on the wires at both sides of the connector. That is the same for power and data lines

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


text:
How to run a sketch for a period (e.g. 1min) and then attiny85 goes to sleepmode automaticaly?
Another beginner to arduino device.
My knowledge for programming is so weak.
As i mention to the title i would like your help.
I just want to run this simple sketch into attiny85 for lets say 1 min and then chip goes to sleepmode by its own.
My code is below but i cannot manage to achive what i want.
Any help?
Many thanks.
void setup() {

  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);

}

void loop() {

                              // put your main code here, to run repeatedly:
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);

  digitalWrite(0, HIGH);
  digitalWrite(1, LOW);  // 1
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  delay(180);
  digitalWrite(0, LOW);
  digitalWrite(1, HIGH);   // 2
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  delay(180);
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);      //3
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  delay(180);
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);   //4
  digitalWrite(2, INPUT);
  digitalWrite(3, HIGH);
  digitalWrite(4, LOW);
  delay(180);
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);   //5
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, HIGH);
  delay(180);
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);   //4
  digitalWrite(2, INPUT);
  digitalWrite(3, HIGH);
  digitalWrite(4, LOW);
  delay(180);
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);     //3
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  delay(180);
  digitalWrite(0, LOW);
  digitalWrite(1, HIGH);   // 2
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  delay(180);
  digitalWrite(0, HIGH);
  digitalWrite(1, LOW);  // 1
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);

}

I'd start by turning your sets of five digitalWrite into a call to single function that takes the number given in the comment.

where is your attempt to put the device to sleep? ... you presented only unrelated code ... please present minimal code that demonstrates the problem ... that means, have code for only one LED

Hello,thanks both for your replies. This is my main sketch code. No attempt to put chip in sleepmode yet. Then its better to read more about commands, try to put attiny to sleepmode and revert. Maybe its to early for questions. thnx guys.

@GEORGEBOULIS I think that I have seen several tutorials about ATTiny85 sleep modes ... perhaps that can be your start

Thanks once again.

You can write, at the end of loop(), “if one minute has elapsed, then
go to sleep”. In C++, that would be:
if (millis() >= 60000)  // 60 seconds elapsed
    sleep_mode();

You will need to include <avr/sleep.h> in order to have access to the
sleep_mode() function. The sleep is likely to be very short though,
probably less than a millisecond, as the ATtiny will be waken up by the
next timer interrupt.
If you want a deeper, longer sleep, you could choose a different sleep
mode in setup():
set_sleep_mode(SLEEP_MODE_PWR_DOWN);

Read the datasheet if you want to know what wakeup sources are available
in each sleep mode.
Alternatively, if you want to make the ATtiny sleep forever (until the
next power cycle), call cli() in order to disable the interrupts,
right before calling sleep_mode().

Dear Edgar , i am trying to do whats u r saying and i have a good result. Sketch is running for a period set into millis() and then stops. The problem is that led in pinmode 0 remains high for ever. Now i am trying to figure out what i am doing wrong. Normally i desire all pinmodes to be low once sleepmode is activated. i will revert. Thanks again.

hELLO, i think i solved it. It was easier than i thought. After millis command I set all pinmodes to low digitalWrite(0, HIGH);
digitalWrite(0, LOW);
digitalWrite(1, LOW);  // 1
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);   after that statement i proceed with sleepmode commands and here we go. All leds stop flashing and no current runs from battery. This is a small victory for me. Thank you so much all.


text:
Windows Driver for Arduino error code 22
I'm trying to use avrdude to load an Arduino program with the console, but I have a Windows 7 x86 Professional with Service Pack 1 (old PC).  When I install the Arduino driver that comes with the IDE manually, with pnputil.exe, in the Windows 7 on PCs that have these processors:

Intel(R) Pentium(R) 4 CPU 2.80GHz
Intel(R) Core(TM)2 Duo CPU E6400 @ 2.13GHz
Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz

I see that the drivers don't work properly.  I get error code 22 in some cases.  And in other cases, the Windows system disables the Arduino in the Windows devices and prevents enabling the COM device.
But, if I install the Arduino IDE or manually install the Windows driver on Core i3, Core i5 and i7 in Windows 7, 8 , 10, the response is perfect.  But, in the others I get error code -22 or Windows doesn't allow to enabling the device.
Has anyone had the same problem and how did you solve it?
Thanks.

Did you install the drivers as administrator? Does the user with that you installed them have full admin privileges?

Yes i install the driver as administrator


text:
How to install CH340G in iOS
I have bought a new Arduino UNO and it works on CH340G. I want to code it using iOS phone, don't have a PC is there any way to install CH340G driver for iOS.

your question is about the IOS, not about the arduino ... do a search for IOS ch430g driver ... if you find it, install it, otherwise you are out of luck .... do you even have a USB port on your phone?

You may have better luck searching for "CH340G" rather than "CH430G" as you'd had it in your original revision.  I wouldn't expect much though.


text:
HobbyTronics UNO PRO Board Definition does not work in newer IDE versions
I have a HobbyTronics UNO PRO that replaces the UNO's 328P in DIP with an ATMega1284 on an adapter board:

I cannot link to the original page since it does not exist anymore.  But, it is available through archive.org.
The original board definition, supplied by the distributor, stopped working after 1.8.10 and throws errors in 1.9.
The particular error when trying to compile:
recipe.preproc.macros pattern is missing

It is not about a particular library or similar; I cannot compile at all (even an empty sketch).
How can I migrate this board? I'd really like to use a current version of the compiler & IDE.

Can you link to this "replacement chip" that you have?  Because, as is, that doesn't completely make sense to me, unless you're using a term in an unusual way.  A Link to "the original board" may also be helpful.

so the mysterious board definition, needs a fix

what happens if you add the missing entry?

please post a link to the library

@timemage The Board is not a default "uno", since its cpu was swapped to an 1284 (which has way more ram etc.) How it should be used with the IDE is on the product page which i added to the question

The link to the archive.org was helpful.  That it was swapped from a 328p to a PCB that adapts 1284 to a 328p pinout was the critical part not conveyed by "replacement chip" or "swapped" chips etc.

Making your board definition work
What I did was slightly different from their directions, but:
Close any instances of the IDE you have running.
Create the directories along this path:
<sketchbook>/hardware/uno_pro/avr/variants/uno_pro

Where <sketchbook> refers to to where your IDE is saving sketches by default.
Place the following slightly modified boards.txt at <sketchbook>/hardware/uno_pro/avr/boards.txt:
uno_pro.name=Arduino Uno*Pro

uno_pro.upload.tool=avrdude
uno_pro.upload.protocol=arduino
uno_pro.upload.maximum_size=130048
uno_pro.upload.maximum_data_size=16384
uno_pro.upload.speed=115200

uno_pro.bootloader.tool=avrdude
uno_pro.bootloader.low_fuses=0xFF
uno_pro.bootloader.high_fuses=0xDE
uno_pro.bootloader.extended_fuses=0xFD
uno_pro.bootloader.unlock_bits=0x3F
uno_pro.bootloader.lock_bits=0x0F
uno_pro.bootloader.file=optiboot/optiboot_atmega1284p.hex

uno_pro.build.mcu=atmega1284p
uno_pro.build.f_cpu=16000000L
uno_pro.build.board=AVR_UNO_PRO
uno_pro.build.core=arduino:arduino
uno_pro.build.variant=uno_pro

This is the original file with one important modification, and that's the addition of arduino: in the second to last line reading uno_pro.build.core=arduino:arduino
Place the following (unmodified from original) pins_arduino.h at <sketchbook>/hardware/uno_pro/avr/variants/uno_pro/pins_arduino.h:
#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <avr/pgmspace.h>

// ATMEL ATMEGA1284 on Hobbytronics UNO*Pro
//
//
// 2014-01-24 - Modified for Software Serial Library to work
//
//   ATMEGA1284 Pin     Arduino Mapping    Features
//     PA0                   D21  A7
//    PA1                   D20  A6
//     PA2                   D19  A5
//    PA3                   D18  A4
//     PA4                   D17  A3
//    PA5                   D16  A2
//     PA6                   D15  A1
//    PA7                   D14  A0
//
//     PB0                   D4
//    PB1                   D5
//     PB2                   D2
//    PB3                   D3               PWM
//     PB4                   D10                    PWM  SS
//    PB5                   D11                   MOSI
//     PB6                   D12              PWM  MISO
//    PB7                   D13              PWM  SCK
//
//     PC0                   D22                   SCL
//    PC1                   D23                   SDA
//     PC2                   D24
//    PC3                   D25
//     PC4                   D26
//    PC5                   D27
//     PC6                   D28
//    PC7                   D29
//
//     PD0                   D0                    RX
//    PD1                   D1                    TX
//     PD2                   D6                    RX1
//    PD3                   D7                    TX1
//     PD4                   D30              PWM
//    PD5                   D8               PWM
//     PD6                   D9               PWM
//    PD7                   D31              PWM
//

static const uint8_t SS   = 10;
static const uint8_t MOSI = 11;
static const uint8_t MISO = 12;
static const uint8_t SCK  = 13;

static const uint8_t SDA = 23;
static const uint8_t SCL = 22;
static const uint8_t LED = 13;

static const uint8_t A0 = 0;
static const uint8_t A1 = 1;
static const uint8_t A2 = 2;
static const uint8_t A3 = 3;
static const uint8_t A4 = 4;
static const uint8_t A5 = 5;
static const uint8_t A6 = 6;
static const uint8_t A7 = 7;

#define NUM_DIGITAL_PINS            32
#define NUM_ANALOG_INPUTS           8

// Macros
#define analogInputToDigitalPin(p)  ((p < NUM_ANALOG_INPUTS) ? (p) + 14 : -1)
#define digitalPinToAnalogPin(p)    ((p) >= 14 && (p) <= 21 ? (p) - 14 : -1 )
#define analogPinToChannel(p)         ((p) < NUM_ANALOG_INPUTS ? NUM_ANALOG_INPUTS - (p) - 1: -1 )
#define digitalPinHasPWM(p)         ((p) == 3 || (p) == 8 || (p) == 9 || (p) == 10 || (p) == 12 || (p) == 13 || (p) == 30 || (p) == 31 )

#define ifpin(p,what,ifnot)     (((p) >= 0 && (p) < NUM_DIGITAL_PINS) ? (what) : (ifnot))

extern const uint8_t digital_pin_to_pcint[NUM_DIGITAL_PINS];

#define digitalPinToPCICR(p)    ifpin(p,(&PCICR),(uint8_t *)0)
#define digitalPinToPCICRbit(p) ifpin(p,(digital_pin_to_pcint[p] >> 3),0)
#define digitalPinToPCMSK(p)    (((p) <= 1) ? (&PCMSK3) : (((p) <= 5) ? (&PCMSK1) : (((p) <= 9) ? (&PCMSK3) : (((p) <= 13) ? (&PCMSK1) : (((p) <= 21) ? (&PCMSK0) : (((p) <= 29) ? (&PCMSK2) : (((p) <= 31) ? (&PCMSK3) : ((uint8_t *)0))))))))
#define digitalPinToPCMSKbit(p) ifpin(p,digital_pin_to_pcint[p] & 0x7,0)

#define digitalPinToInterrupt(p)  ((p) == 6 ? 0 : ((p) == 7 ? 1 : ((p) == 2 ? 2 : NOT_AN_INTERRUPT)))

#ifdef ARDUINO_MAIN

#define PA 1
#define PB 2
#define PC 3
#define PD 4

const uint8_t digital_pin_to_pcint[NUM_DIGITAL_PINS] =
{
  24, // D0  PD0
  25, // D1  PD1 1
  10, // D2  PB2
  11, // D3  PB3
  8,  // D4  PB0
  9,  // D5  PB1 5
  26, // D6  PD2
  27, // D7  PD3
  29, // D8  PD5
  30, // D9  PD6 9
  12, // D10 PB4
  13, // D11 PB5
  14, // D12 PB6
  15, // D13 PB7 13
  7,  // D14 PA7
  6,  // D15 PA6
  5,  // D16 PA5
  4,  // D17 PA4
  3,  // D18 PA3
  2,  // D19 PA2
  1,  // D20 PA1
  0,  // D21 PA0 21
  16, // D22 PC0
  17, // D23 PC1
  18, // D24 PC2
  19, // D25 PC3
  20, // D26 PC4
  21, // D27 PC5
  22, // D28 PC6
  23, // D29 PC7 29
  28, // D30 PD4
  31  // D31 PD7 31
};

// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] =
{
    NOT_A_PORT,
    (uint16_t) &DDRA,
    (uint16_t) &DDRB,
    (uint16_t) &DDRC,
    (uint16_t) &DDRD,
};

const uint16_t PROGMEM port_to_output_PGM[] =
{
    NOT_A_PORT,
    (uint16_t) &PORTA,
    (uint16_t) &PORTB,
    (uint16_t) &PORTC,
    (uint16_t) &PORTD,
};

const uint16_t PROGMEM port_to_input_PGM[] =
{
    NOT_A_PORT,
    (uint16_t) &PINA,
    (uint16_t) &PINB,
    (uint16_t) &PINC,
    (uint16_t) &PIND,
};

const uint8_t PROGMEM digital_pin_to_port_PGM[] =
{
  PD, // D0
  PD, // D1
  PB, // D2
  PB, // D3
  PB, // D4
  PB, // D5
  PD, // D6
  PD, // D7
  PD, // D8
  PD, // D9
  PB, // D10
  PB, // D11
  PB, // D12
  PB, // D13
  PA, // D14
  PA, // D15
  PA, // D16
  PA, // D17
  PA, // D18
  PA, // D19
  PA, // D20
  PA, // D21
  PC, // D22
  PC, // D23
  PC, // D24
  PC, // D25
  PC, // D26
  PC, // D27
  PC, // D28
  PC, // D29
  PD, // D30
  PD, // D31
};

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
{
  _BV(0), // D0  PD0
  _BV(1), // D1  PD1
  _BV(2), // D2  PB2
  _BV(3), // D3  PB3
  _BV(0), // D4  PB0
  _BV(1), // D5  PB1
  _BV(2), // D6  PD2
  _BV(3), // D7  PD3
  _BV(5), // D8  PD5
  _BV(6), // D9  PD6
  _BV(4), // D10 PB4
  _BV(5), // D11 PB5
  _BV(6), // D12 PB6
  _BV(7), // D13 PB7
  _BV(7), // D14 PA7 (A0)
  _BV(6), // D15 PA6 (A1)
  _BV(5), // D16 PA5 (A2)
  _BV(4), // D17 PA4 (A3)
  _BV(3), // D18 PA3 (A4)
  _BV(2), // D19 PA2 (A5)
  _BV(1), // D20 PA1 (A6)
  _BV(0), // D21 PA0 (A7)
  _BV(0), // D22 PC0
  _BV(1), // D23 PC1
  _BV(2), // D24 PC2
  _BV(3), // D25 PC3
  _BV(4), // D26 PC4
  _BV(5), // D27 PC5
  _BV(6), // D28 PC6
  _BV(7), // D29 PC7
  _BV(4), // D30 PD4
  _BV(7), // D31 PD7
};

const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
{
  NOT_ON_TIMER, // D0  PD0
  NOT_ON_TIMER, // D1  PD1
  NOT_ON_TIMER, // D3  PB2
  TIMER0A,      // D3  PB3
  NOT_ON_TIMER, // D4  PB0
  NOT_ON_TIMER, // D5  PB1
  NOT_ON_TIMER, // D6  PD2
  NOT_ON_TIMER, // D7  PD3
  TIMER1A,      // D8  PD5
  TIMER2B,      // D9  PD6
  TIMER0B,      // D10 PB4
  NOT_ON_TIMER, // D11 PB5
  TIMER3A,      // D12 PB6
  TIMER3B,      // D13 PB7
  NOT_ON_TIMER, // D14 PA0
  NOT_ON_TIMER, // D15 PA1
  NOT_ON_TIMER, // D16 PA2
  NOT_ON_TIMER, // D17 PA3
  NOT_ON_TIMER, // D18 PA4
  NOT_ON_TIMER, // D19 PA5
  NOT_ON_TIMER, // D20 PA6
  NOT_ON_TIMER, // D21 PA7
  NOT_ON_TIMER, // D22 PC0
  NOT_ON_TIMER, // D23 PC1
  NOT_ON_TIMER, // D24 PC2
  NOT_ON_TIMER, // D25 PC3
  NOT_ON_TIMER, // D26 PC4
  NOT_ON_TIMER, // D27 PC5
  NOT_ON_TIMER, // D28 PC6
  NOT_ON_TIMER, // D29 PC7
  TIMER1B,      // D30 PD4
  TIMER2A,      // D31 PD7
};

#endif // ARDUINO_MAIN

#endif // Pins_Arduino_h
// vim:ai:cin:sts=2 sw=2 ft=cpp

Open the IDE and your board should be listed.  It should compile with a blank sketch.  I did not test further than that.
MCUDude MightyCore
Your board could also likely be made to work with MCUdude MightyCore.  However, MightyCore will not have your pin mapping.  So, although you could use it, you would need to ignore the normal UNO pin labeling and instead of work out which pin number used by the chosen MightyCore variant routes to which pin on the UNO headers.  It would be annoying to do, but you could do that by comparing entries in your adapter's pins_arduino.h file with the entries in the chosen variant from the MightCore package.  But, the modifications above seem to work fine.  So, I don't necessarily suggest that route; I'm just saying it could be used that way also.
MightyCore could also be modified, but that works out to the same or more work than just using your board definition, I think.


text:
Powering a system using batteries
I made an arduino nano IR sensor based auto liquid dispenser. Currently it is being powered by a 12V 2 amps adapter. The 12v adapter is connected to a LM2596 DC to DC buck converter which converts the 12V to 5V and powers the arduino, IR sensor and a regular green LED. Also I am using a RO valve solenoid (rated upto 24V DC) which is being powered by the 12V adapter. So whenever the IR sensor is triggered, the DC motor (5V 200mA) and solenoid (12V 300-500mA) are turned on for 3 seconds.
Now, I intend to power this system via batteries. I am considering the following 3 options.
a.) Lithium batteries in series (4 of 3.7V batteries). But again here I believe things would be complex as I have to make a BMS and charger for this. Is anything available off the shelf so that I can directly integrate the battery and charger with my existing system ?
b.) Connect 8 AAA batteries in series to get 12V. But how long would these batteries last for my application ?
c.) Connect 2 9V batteries in series. Again, can you guys please tell me how long these may last in the system.
Arduino nano I believe consumes 20mA and the IR sensor probably around another 10- 20mA.
If it wasnt for the solenoid, I was considering connecting a mobile power bank to power the system.

You should check out radio controlled model suppliers. They have the best offerings for batteries and chargers.

The 9V block batteries are out here. They cannot provide enough current to power the solenoid

Using AA would give you about 5 days of runtime, assuming it's activated once an hour (24 times a day) and the LM2596 running at 80% efficiency. With AAA you'd only get 2.5 days. Most of the power is used by the Arduino + IR sensor. So putting the Arduino in sleep mode most of the time, would give you a lot longer runtime.

Consider using a 12V sealed cell lead-acid battery. Those are fairly cheap and easy to find in a wide variety of capacities, and chargers are also simple and easy to find.
A car battery would power your system approximately forever, since they have such huge capacity.
Figuring out how long a given type of battery will last is a simple question of math. Figure out the average current draw of your entire project, in milliamps. (You need to include the power consumed by your voltage regulator. The linear regulators built into Arduinos are quite inefficient, and work by dissipating excess voltage as heat.)
The total power of a battery is expressed in milliamp/hours. (where 1 milliamp/hour is a milliamp of power drawn for a full hour.) If you your system draws 2 amps, or 2000 milliamps average current, and your battery is rated for 2000 mAh, or 2 amp/hours, the battery will last 1 hour.
For battery-powered systems you should think about skipping the built-in linear regulator in your Arduino and instead using a switching regulator and providing regulated 5V directly to the board. Switching regulators can run at 90%+ efficiency, compared to something like 40% - 50% efficiency for linear regulators (I don't have a specific efficiency figure for linear regulators on hand, and it depends on input voltage compared to output voltage. The 40% - 50% number is an educated guess.)

I think you should go with 3 lithium batteries in series and for proper balance charging of batteries, you can use an off the shell 3s lithium charging circuit like this here.So you will get 4.2*3 = 12.6V on full charge and on full discharge you will get 3.7*3=11.1v out of the battery.
So still I think your pump motor would work on 11v and ther are chances that your solanoid also work on 11v it will just draw more current then usual.

Thank you. As per datasheet (https://aws.robu.in/wp-content/uploads/2017/09/DATASHEET_ROBU.IN_.pdf), I believe I need to connect 3S1P to get 12.6V. Also, can I charge the batteries simultaneously with a 12V 2A adapter while powering the load ? Also, how do I know when I should connect the charger? How long would my system last with 3s1p combination of 3 18650 batteries.

You should not run a device from batteries whilst at the same time charging the batteries. The charger will have a hard job knowing when the batteries are charged (dv/dt won't work right) and you risk overcharging.  For 3S batteries you need a balancing charger otherwise you can end up with a reverse charged cell as the cells discharge unevenly. That will kill your battery. You need an intelligent "In-place" charger that disconnects the battery while it's being charged and powers the device directly from the incoming power.

@Majenko As per the datasheet page 3 (https://aws.robu.in/wp-content/uploads/2017/09/DATASHEET_ROBU.IN_.pdf), I believe this has the power multiplexing mechanism in place as they have connected charger supply and load together.

Looks good to me, though that's not a charger, just protection. It should protect the batteries from over/under charge with a dumb charger, which is good.

@Majenko thank you. But still this doesnt have the auto disconnect from the battery and power the load directly when the dumb adapter is connected , right ? So simultaneously connecting adapter to power the load and charge batteries would not be possible.

The protection circuit will disconnect the battery when it's charged.

@user3796354  It will not make any issue if you charge under load condition because your load will get its power from the battery as well as the adapter so no worry.
but for charging voltage it will not charge fully if you give 12v it will make battery voltage level to 12v but not more than that so you need to provide more than 12.6v to 13v as per the datasheet.
And for time calculation that how long your battery last you can use online converters like this

@dharmik Thanks. Instead I can also use a battery pack like this one (https://robokits.co.in/batteries-chargers/skycell-li-ion-battery/11.1v-skycell-li-ion-batteries/li-ion-11.1v-2200mah-2c-with-inbuilt-charger-protection), right ? It has built in BMS and can be charged from a 12V 1A adapter.

@user3796354 yes you can because this battery pack has the same circuit inside.

Dharmik, Do you think the battery in the link above can be charged with a regular charger ? Because I was researching about charging lithium batteries and I believe the charger should be able to maintain absolute max @4.2v per cell which regular chargers wont be able to do.

@user3796354 It will charge your battery pack with 12v regular but not full charge because the voltage has a property of flowing from high potential to low potential voltage so it will do charge to the max voltage of 12v not more than that until you give more voltage to it. So you can do one thing if you want full charge battery and regular adapter you can add an 2amp DC-DC bust converter in betwen for changing 12v to around 12.6 to 13v.

@dharmik ok. thanks

That is not a charger; it is a protection circuit aka BMS. Try getting a 3S balancing BMS for building your battery pack and use a proper charger to charge the pack.


text:
Is it possible to use Pi's output signal as Arduino's input signal?
I have a relay attached to an Arduino Uno which I want to control using my raspberry pi 3b. And yes I know it can be done by attaching the relay directly to Pi but I cannot do so. Don't ask me why. That is why I want to know whether it is possible to use Pi's output signal as input for the Arduino or not. I do not have spare parts so I don't want to experiment. If anyone knows about this, please tell me.

What type of "signal" do you want? A simple pin, that can be set high or low from the Pi? Or a real data connection like Serial (UART)?

This way is fine: the Pi is a 3.3V based board, so connecting one of the GPIO pin from the pi to an Arduino will not damage it. Furthermore, the 3.3V are sufficient to be considered as HIGH even on a 5v Arduino like the UNO.
The other way around: connecting the output of a 5V Arduino to the input of a pi, will very likely damage the raspberry Pi!
So beware of your Pinmode before doing such a connection!


text:
AMIS30543 | DataSheet Understanding CIRCULAR TRANSLATOR TABLE
I was reading the data sheet of AMIS-30543 stepper motor and I didn't understand fully what does this Circular Translator Table means, I have a couple of doubts

What does Circular Translator table Stands for.? How to read it .? pg:13
What does the current pairs can be projected approximately on a circle in Ix, Iy plane means.? pg:25

In the data Sheet it is given that Changes on the NXT input will move the motor current one step up/down in the translator table (even when the motor is disabled:  = 0). So the changes happened in the table while the motor was disabled will reflect as soon as the motor become active.? Like if I give say 5 step input while the motor was disabled and when I make the motor enable , will the motor will move by itself to reach that position in the translator table.? pg:25

Link to datasheet

It describes the current going through the two coils of the stepper motor at each step.

I'm not quite sure, as I would think the last two diagrams should actually be squares. But for example, in the first image, you can see that the current in the X coil will steadily increase, while the current in the Y coil will steadily decrease. This will make the stepper rotate more slowly.
In the second image, you can see that only the Y coil driver is at 100% in step 0. In step 1 both coils are at 100%. In step 2 coil Y is turned off. I think this is profile produces more torque, but is less smooth.

No. I you are, for example using full step mode, and the motor is in step 0. If you give it 3 steps forward  (while the motor is disabled) it would drive the coils (once you re-enable to motors) as described in the lookup table for step 3. Which in practice would mean the motor would rotate backward one step (instead of 3 steps forward).

In other cases, it could result in undefined behavior. Going from step 0 to step 2 could mean it would rotate clockwise, anticlockwise, or even not rotate at all.
Though in practice I don't think this would even be an issue, and disabling the motor, but still sending it step pulses is kind of silly.


text:
Controlling dynamixel servo from Arduino-Mega
I was trying to control a dynamixel servo from Arduino Mega. The protocol for the communication is half duplex, and I successfully sent data to the servo motor and got it actuated/turned the LED on and off. However, unfortunately, the status packet coming back from the servo is somehow corrupted. I am only getting everything 0xFF.
The code used is
#include <Arduino.h>

#define Direction_PIN PG5

#define TX_DIRECTION (PORTG |= 1<< Direction_PIN)
#define RX_DIRECTION (PORTG &= ~(1<<Direction_PIN))

#define FOSC 16000000
#define BAUD 57600
#define BAUD_UBRR (FOSC / 16/ BAUD - 1)

void USART_initialization();

void USART_Transmit(unsigned char data);

unsigned short update_crc(unsigned short crc_accum, unsigned char *data_blk_ptr, unsigned short data_blk_size);

void sendData_to_Dxl(unsigned char *packet, uint8_t n);

void USART_initialization() {
    /* Set baud rate */
    UBRR2H = (unsigned char) (BAUD_UBRR >> 8);
    UBRR2L = (unsigned char) BAUD_UBRR;
    /* Enable receiver and transmitter */
    UCSR2B = (1 << RXEN2) | (1 << TXEN2) | (1 << RXCIE2) | (1 << TXCIE2);
    /* Set frame format : 8data, 1stop bit; no parity */
    UCSR2C = (3 << UCSZ20);
}

/*
 * DXL Specific Codes
 */
unsigned short update_crc(unsigned short crc_accum,
                          unsigned char *data_blk_ptr,
                          unsigned short data_blk_size) {
    unsigned short i, j;
    unsigned short crc_table[256] = {
            0x0000, 0x8005, 0x800F, 0x000A, 0x801B, 0x001E, 0x0014, 0x8011,
            0x8033, 0x0036, 0x003C, 0x8039, 0x0028, 0x802D, 0x8027, 0x0022,
            0x8063, 0x0066, 0x006C, 0x8069, 0x0078, 0x807D, 0x8077, 0x0072,
            0x0050, 0x8055, 0x805F, 0x005A, 0x804B, 0x004E, 0x0044, 0x8041,
            0x80C3, 0x00C6, 0x00CC, 0x80C9, 0x00D8, 0x80DD, 0x80D7, 0x00D2,
            0x00F0, 0x80F5, 0x80FF, 0x00FA, 0x80EB, 0x00EE, 0x00E4, 0x80E1,
            0x00A0, 0x80A5, 0x80AF, 0x00AA, 0x80BB, 0x00BE, 0x00B4, 0x80B1,
            0x8093, 0x0096, 0x009C, 0x8099, 0x0088, 0x808D, 0x8087, 0x0082,
            0x8183, 0x0186, 0x018C, 0x8189, 0x0198, 0x819D, 0x8197, 0x0192,
            0x01B0, 0x81B5, 0x81BF, 0x01BA, 0x81AB, 0x01AE, 0x01A4, 0x81A1,
            0x01E0, 0x81E5, 0x81EF, 0x01EA, 0x81FB, 0x01FE, 0x01F4, 0x81F1,
            0x81D3, 0x01D6, 0x01DC, 0x81D9, 0x01C8, 0x81CD, 0x81C7, 0x01C2,
            0x0140, 0x8145, 0x814F, 0x014A, 0x815B, 0x015E, 0x0154, 0x8151,
            0x8173, 0x0176, 0x017C, 0x8179, 0x0168, 0x816D, 0x8167, 0x0162,
            0x8123, 0x0126, 0x012C, 0x8129, 0x0138, 0x813D, 0x8137, 0x0132,
            0x0110, 0x8115, 0x811F, 0x011A, 0x810B, 0x010E, 0x0104, 0x8101,
            0x8303, 0x0306, 0x030C, 0x8309, 0x0318, 0x831D, 0x8317, 0x0312,
            0x0330, 0x8335, 0x833F, 0x033A, 0x832B, 0x032E, 0x0324, 0x8321,
            0x0360, 0x8365, 0x836F, 0x036A, 0x837B, 0x037E, 0x0374, 0x8371,
            0x8353, 0x0356, 0x035C, 0x8359, 0x0348, 0x834D, 0x8347, 0x0342,
            0x03C0, 0x83C5, 0x83CF, 0x03CA, 0x83DB, 0x03DE, 0x03D4, 0x83D1,
            0x83F3, 0x03F6, 0x03FC, 0x83F9, 0x03E8, 0x83ED, 0x83E7, 0x03E2,
            0x83A3, 0x03A6, 0x03AC, 0x83A9, 0x03B8, 0x83BD, 0x83B7, 0x03B2,
            0x0390, 0x8395, 0x839F, 0x039A, 0x838B, 0x038E, 0x0384, 0x8381,
            0x0280, 0x8285, 0x828F, 0x028A, 0x829B, 0x029E, 0x0294, 0x8291,
            0x82B3, 0x02B6, 0x02BC, 0x82B9, 0x02A8, 0x82AD, 0x82A7, 0x02A2,
            0x82E3, 0x02E6, 0x02EC, 0x82E9, 0x02F8, 0x82FD, 0x82F7, 0x02F2,
            0x02D0, 0x82D5, 0x82DF, 0x02DA, 0x82CB, 0x02CE, 0x02C4, 0x82C1,
            0x8243, 0x0246, 0x024C, 0x8249, 0x0258, 0x825D, 0x8257, 0x0252,
            0x0270, 0x8275, 0x827F, 0x027A, 0x826B, 0x026E, 0x0264, 0x8261,
            0x0220, 0x8225, 0x822F, 0x022A, 0x823B, 0x023E, 0x0234, 0x8231,
            0x8213, 0x0216, 0x021C, 0x8219, 0x0208, 0x820D, 0x8207, 0x0202
    };

    for (j = 0; j < data_blk_size; j++) {
        i = ((unsigned short) (crc_accum >> 8) ^ data_blk_ptr[j]) & 0xFF;
        crc_accum = (crc_accum << 8) ^ crc_table[i];
    }
    return crc_accum;
}

void setup() {

    DDRG = (1 << Direction_PIN); // setting the pin4:PG5 as output for controlling the direction
    RX_DIRECTION;

    USART_initialization();

    uint8_t CRC_L = 0x00;
    uint8_t CRC_H = 0x00;

    /* LED ON */
    unsigned char TxPacketLed_ON[] = {
            0xFF, 0xFF, 0xFD, 0x00,
            0x01,
            0x06, 0x00,
            0x03,
            0x41, 0x00,
            0x01,
            CRC_L, CRC_H
    };
    /* LED OFF */
    unsigned char TxPacketLed_OFF[] = {
            0xFF, 0xFF, 0xFD, 0x00,
            0x01,
            0x06, 0x00,
            0x03,
            0x41, 0x00,
            0x00,
            CRC_L, CRC_H
    };

    uint8_t n;

    while (true) {

        n = sizeof(TxPacketLed_ON);
        sendData_to_Dxl(TxPacketLed_ON, n);

        delay(1000);
        n = sizeof(TxPacketLed_OFF);
        sendData_to_Dxl(TxPacketLed_OFF, n);

        delay(1000);
    }
}

void sendData_to_Dxl(unsigned char *packet, uint8_t n) {
    uint8_t CRC_L, CRC_H;
    unsigned short CRC;
    CRC = update_crc(0, packet, n - 2);   // 12 = 5 + Packet Length(7)

    CRC_L = (CRC & 0x00FF);               //Little-endian
    CRC_H = (CRC >> 8) & 0x00FF;

    packet[n - 2] = CRC_L;
    packet[n - 1] = CRC_H;

    TX_DIRECTION;
    for (uint8_t i = 0; i < n; i++) {
        USART_Transmit(packet[i]);
    }
}

void loop() {

}

void USART_Transmit(uint8_t data) {
    /*Wait for empty transmit buffer*/
    while (!(UCSR2A & (1 << UDRE2)));
    /*Transfer the data*/
    UDR2 = data;
}

ISR(USART2_TX_vect) {
    RX_DIRECTION;
}

The schematic of the circuit made to drive the servo is shown below. Where PIN4 is the direction pin and TX and RX are the UART transmit and Receive corresponding to the Serial 2

There is no part in the code for receiving the status data from the servo motor after the instruction set is sent. A logic analyzer was used, and the instruction data is shown as send, but the status data is all 0xff.
what is the mistake I am doing here.?
The various link I have used
MOTOR USED
dynamixel protocol 2.0
74LS126 datasheet
74HC06 datasheet
I have tried the library from this answer here, but the status was faulty.


text:
MPU6050 Arduino Jeff Rowberg library interrupt Issue
I was trying to get the data from MPU6050 using the Arduino library mentioned here.
The following code is an edited version of the sample code given in the library folder which seems to be working fine.
#define printfloatx(Name,Variable,Spaces,Precision,EndTxt) { Serial.print(F(Name)); {char S[(Spaces + Precision + 3)];Serial.print(F(" ")); Serial.print(dtostrf((float)Variable,Spaces,Precision ,S));}Serial.print(F(EndTxt)); }//Name,Variable,Spaces,Precision,EndTxt

#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps_V6_12.h"

#include "Wire.h"

MPU6050 accelgyro;
MPU6050 mpu;

I2Cdev a;

/*
    IMU Zero variables
*/

int16_t data_acc[3];
int16_t data_Gyro[3];

/*
   IMU initialization variables
*/
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
bool dmpReady = false;  // set true if DMP init was successful
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)

/*
   IMU angle finding variables
*/
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer

Quaternion q;           // [w, x, y, z]         quaternion container
VectorFloat gravity;    // [x, y, z]            gravity vector
float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector

void Initialize()
{
  // initialize device
  Serial.println("Initializing I2C devices...");
  accelgyro.initialize();

  // verify connection
  Serial.println("Testing device connections...");
  Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
  Serial.println("tuning Each Dot = 100 readings");
  accelgyro.CalibrateAccel(10);
  accelgyro.CalibrateGyro(10);

  a.readWords(0x68, 0x06, 3, (uint16_t *)data_acc);
  a.readWords(0x68, 0x13, 3, (uint16_t *)data_Gyro);
} // Initialize

void setup() {
  Wire.begin();
  Serial.begin(115200);
  Initialize();
  Wire.setClock(400000);
  while (!Serial);
  Serial.println(F("Initializing I2C devices..."));
  mpu.initialize();
  Serial.println(F("Testing device connections..."));
  Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

  Serial.println(F("\nSend any character to begin DMP programming and demo: "));
  while (Serial.available() && Serial.read()); // empty buffer
  while (!Serial.available());                 // wait for data
  while (Serial.available() && Serial.read()); // empty buffer again

  // load and configure the DMP
  Serial.println(F("Initializing DMP..."));
  devStatus = mpu.dmpInitialize();

  // supply your own gyro offsets here, scaled for min sensitivity
  mpu.setXGyroOffset(data_Gyro[0]);
  mpu.setYGyroOffset(data_Gyro[1]);
  mpu.setZGyroOffset(data_Gyro[2]);
  mpu.setXAccelOffset(data_acc[0]);
  mpu.setYAccelOffset(data_acc[1]);
  mpu.setZAccelOffset(data_acc[2]);

  if (devStatus == 0) {
    // Calibration Time: generate offsets and calibrate our MPU6050
    mpu.CalibrateAccel(6);
    mpu.CalibrateGyro(6);
    Serial.println();
    mpu.PrintActiveOffsets();
    // turn on the DMP, now that it's ready
    Serial.println(F("Enabling DMP..."));
    mpu.setDMPEnabled(true);

    // enable Arduino interrupt detection
    Serial.print(F("Enabling interrupt detection (Arduino external interrupt "));
    mpuIntStatus = mpu.getIntStatus();
    Serial.println(F("DMP ready! Waiting for first interrupt..."));
    dmpReady = true;
    packetSize = mpu.dmpGetFIFOPacketSize();
  } else {
    Serial.print(F("DMP Initialization failed (code "));
    Serial.print(devStatus);
    Serial.println(F(")"));
  }

  Serial.println("-------------- done --------------");
} // setup

void loop()
{
  if (!dmpReady) return;
  if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer)) {
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
    Serial.print("ypr\t");
    Serial.print(ypr[0] * 180 / M_PI);
    Serial.print("\t");
    Serial.print(ypr[1] * 180 / M_PI);
    Serial.print("\t");
    Serial.print(ypr[2] * 180 / M_PI);
    Serial.println();
  }

}

Then I have activated the input capture pin to use with the interrupt and the code is as follows
#define printfloatx(Name,Variable,Spaces,Precision,EndTxt) { Serial.print(F(Name)); {char S[(Spaces + Precision + 3)];Serial.print(F(" ")); Serial.print(dtostrf((float)Variable,Spaces,Precision ,S));}Serial.print(F(EndTxt)); }//Name,Variable,Spaces,Precision,EndTxt

#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps_V6_12.h"

#include "Wire.h"

MPU6050 accelgyro;
volatile MPU6050 mpu;

I2Cdev a;

/*
    IMU Zero variables
*/

int16_t data_acc[3];
int16_t data_Gyro[3];

/*
   IMU initialization variables
*/
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
bool dmpReady = false;  // set true if DMP init was successful
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)

/*
   IMU angle finding variables
*/
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer

Quaternion q;           // [w, x, y, z]         quaternion container
VectorFloat gravity;    // [x, y, z]            gravity vector
volatile float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector

void Initialize()
{
  // initialize device
  Serial.println("Initializing I2C devices...");
  accelgyro.initialize();

  // verify connection
  Serial.println("Testing device connections...");
  Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
  Serial.println("tuning Each Dot = 100 readings");
  accelgyro.CalibrateAccel(10);
  accelgyro.CalibrateGyro(10);

  a.readWords(0x68, 0x06, 3, (uint16_t *)data_acc);
  a.readWords(0x68, 0x13, 3, (uint16_t *)data_Gyro);
} // Initialize

void timer4_initialization() {
  pinMode(49, INPUT);
  TCCR4A = 0; TCCR4B = 0; TCCR4C = 0;
  TCCR4B = B11000000;
  TIFR4 = _BV(ICF4);
  TIMSK4 = B00100000;
}

ISR(TIMER4_CAPT_vect) {
  if (!dmpReady) return;
  if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer)) {
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
  }
}

void setup() {
  Wire.begin();
  Serial.begin(115200);
  Initialize();
  Wire.setClock(400000);
  while (!Serial);
  Serial.println(F("Initializing I2C devices..."));
  mpu.initialize();
  Serial.println(F("Testing device connections..."));
  Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

  Serial.println(F("\nSend any character to begin DMP programming and demo: "));
  while (Serial.available() && Serial.read()); // empty buffer
  while (!Serial.available());                 // wait for data
  while (Serial.available() && Serial.read()); // empty buffer again

  // load and configure the DMP
  Serial.println(F("Initializing DMP..."));
  devStatus = mpu.dmpInitialize();

  // supply your own gyro offsets here, scaled for min sensitivity
  mpu.setXGyroOffset(data_Gyro[0]);
  mpu.setYGyroOffset(data_Gyro[1]);
  mpu.setZGyroOffset(data_Gyro[2]);
  mpu.setXAccelOffset(data_acc[0]);
  mpu.setYAccelOffset(data_acc[1]);
  mpu.setZAccelOffset(data_acc[2]);

  if (devStatus == 0) {
    // Calibration Time: generate offsets and calibrate our MPU6050
    mpu.CalibrateAccel(6);
    mpu.CalibrateGyro(6);
    Serial.println();
    mpu.PrintActiveOffsets();
    // turn on the DMP, now that it's ready
    Serial.println(F("Enabling DMP..."));
    mpu.setDMPEnabled(true);

    // enable Arduino interrupt detection
    Serial.print(F("Enabling interrupt detection (Arduino external interrupt "));
    mpuIntStatus = mpu.getIntStatus();
    Serial.println(F("DMP ready! Waiting for first interrupt..."));
    dmpReady = true;
    packetSize = mpu.dmpGetFIFOPacketSize();
  } else {
    Serial.print(F("DMP Initialization failed (code "));
    Serial.print(devStatus);
    Serial.println(F(")"));
  }

  Serial.println("-------------- done --------------");

  delay(2000);

  timer4_initialization();

} // setup

void loop()
{
  Serial.print("ypr\t");
  Serial.print(ypr[0] * 180 / M_PI);
  Serial.print("\t");
  Serial.print(ypr[1] * 180 / M_PI);
  Serial.print("\t");
  Serial.print(ypr[2] * 180 / M_PI);
  Serial.println();
}

Here when I am using with the interrupt I am not getting anything printed, seems like the program is frozen somewhere in the interrupt -> function call.
What is the mistake I am making here.
How to take the measurement from MPU6050 using ISR routines.

are you saying that it does not even print Initializing I2C devices...?

The functions mpu.dmpGetCurrentFIFOPacket(fifoBuffer), etc, are using I2C for getting the data. The I2C interface on the Uno and Mega (which you tagged your question with) is implemented in hardware and needs interrupts for handling the data bytes (taking the received byte out of the register or writing data to the register for sending).
By default interrupts are disabled inside of an ISR. Thus the mentioned functions cannot execute correctly. They are waiting for an interrupt, which is never going to happen, since the functions are executed while interrupts are disabled.
It is possible to reactivate interrupts in an ISR, but that is something, that you should only do in a few situations and only, when you know exactly, what you are doing.
Instead you should just set a volatile flag variable inside the ISR. In the main code (in loop()) you can then check for that flag, execute the I2C code when it is set and reset the flag afterwards. And you can then also just print, when there is new data instead of every loop iteration. So somewhat like this:
volatile byte timer_flag = 0;

ISR(TIMER4_CAPT_vect) {
  timer_flag = 1;
}

void loop(){
    if(timer_flag){
        if (!dmpReady) return;
        if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer)) {
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetGravity(&gravity, &q);
            mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
            // then print the values here, since we got new data from the MPU
        }
        timer_flag = 0; // Resetting the flag for the next timer interrupt
    }
}

I've tweaked chrisl's answer to show how to copy the ISR data and reset the ISR flag  in an atomic manner.
volatile bool isr_timer_flag = false;
volatile uint32_t isr_counter = 0;  // Added to demonstrate how to copy a multibyte data type atomically.

ISR(TIMER4_CAPT_vect)
{
    isr_timer_flag = true;
    isr_counter++;
}

void loop()
{
    //
    // Get a copy of the data and reset the flag atomically by temporarily disabling interrupts.
    //

    // Disable interrupts by clearing the global interrupt flag.
    cli();

    // Copy the data.
    bool timer_flag = isr_timer_flag;
    uint32_t counter = isr_counter;

    // Reset the ISR flag for the next timer interrupt.
    // Resetting it here avoids clearing any re-flag during the following if statements.
    isr_timer_flag = false;

    // Enable interrupts by setting the global interrupt flag.
    sei();

    // Now use the local copy of the ISR flag.
    // The ISR flag could be re-flagged at any time during the remainder of the loop,
    // but a fresh copy will be obtained on the next iteration of the loop.

    if (timer_flag)
    {
        if (!dmpReady) return;
        if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer))
        {
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetGravity(&gravity, &q);
            mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
            // then print the values here, since we got new data from the MPU
        }
    }
}


text:
AMIS30543 | Data-Sheet understanding Status register
I was reading the data Sheet of AMIS-30543 stepper motor driver and I was not able to understand how to combine the result of the Micro step position status register MSP[8:0]. I know that its a 9 bit value . Help me understand how to get the value.
In the data sheet it is given like

in SR3 -> MSP[8:2], and in SR4 -> MSP[6:0]. How I am I suppose to get the 9 bit out of these.

In the library I have seen that , (sr3<<2) | (sr4 & 3)  . I don't understand why they are doing and & here.
Please explain . also If there was no library how am I suppose to know how to combine these registers from the dataSheet .
Link to DataSheet

Most of the data is duplicated between the registers. Both registers contain MSP[6:2].
If MSP contains 111001001 the registers (ignoring the MSB "PAR" bit) would look like:
SR3: 1110010
SR4: 1001001

If we line those up it's then like:
SR3: 1110010
SR4    1001001

You can now see the overlap.
So taking SR3 and shifting it left two places (sr3 << 2) gives you:
SR3:   1110010
<<2: 111001000

Taking the lowest two bits of SR4 with & 3 gives you:
SR4:   1001001
& 3:   0000001

Then ORing the two results together:
SR3<<2: 111001000
SR4 &3: 000000001
-----------------
MSP   : 111001001

How can I understand this from data sheet like from sr3 and sr4

The 8:2 and 6:0 refer to the range of bits stored in that register. It's a little unusual to have overlap like that.

So is it okay to do like :: ‘(sr3 << 2 | sr4)’

No, because of the PAR bit that's in the MSB that will corrupt SR3.

Ohh ok. I understand now .

Again one more doubt this overlapping of bits you came to know by practice and experience or you read some where ?

Practice and experience. It's the first time I have seen overlapping bits like that, but the code snippet you showed and the 8:2 and 6:0 in the datasheet allowed me to infer it. It's really not clear at all in the datasheet, so it's not surprising you were struggling with it.


text:
digitalRead() function of Arduino doesn't read Input value sent by sensor after detecting the object
I'm trying to turn ON the LED(inbuilt/PIN13) when photoelectric proximity sensor(12v) senses any object. Sensor is connected on pin 2. Assigned pin 2 as INPUT, I've got a 12v spdt relay for switching. 12v output from sensor is fed to coil, on the other end 5v supplied to COM pin and "Normally Open"(NO) pin to Arduino (with pull-down resistor). When 'NO' connected to loose LED it works properly (shows 5V on voltmeter when object is detected). But when connected to Arduino digitalRead(), it always returns LOW/0.
//code
int a=0;
void setup() {
  pinMode(2,INPUT);
  pinMode(13,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  a ==  digitalRead(2);
  Serial.println(a);
  if(a==HIGH){
    Serial.println("Object Detected");
    digitalWrite(13,HIGH);
  }else{
    Serial.println("There's no object");
    digitalWrite(13,LOW);
  }
  delay(1000);
}

it is difficult to visualize what you are describing ... please draw a schematic diagram or a wiring diagram ... also include the code that you are using

To read that detector: get rid of the relay and replace it with an ordinary voltage divider.

I tried using 7805 to get 5v output. It did not work, @SimSon

@jsotola yes. sure. I'm uploading a schematic and code.

use 1kOhm resistor for pulldown

@Juraj I used 1K resistor for pulldown, it did not work.

I'm not talking about a voltage regulator, but a simple voltage divider consisting of two resistors. The sensor is probably (do you have a datasheet?) not able to provide sufficient current to activate the relay without harm. Just don't use the relay, it's a poor design this way.

And are you sure the relay pinout is correct? Relays usually have primary contacts on one side and secondary on the other side.

@SimSon Right now I don't have appropriate value resistors to make voltage divider. It's just a relay not a relay module hence the relay pinout is correct. The sensor must be providing sufficient current(I have no datasheet) because relay switches when object is detected also on the other side of relay gets 4.96 volts (measured by multi-meter) when object is detected. But Arduino pin does not recognize change in voltage (i.e.0 to 4.96). All other stuff works absolutely fine but digitalRead() function associated with Arduino input pin returns LOW even after detecting 4.96 V.

Thank you all for replying. The problem is solved it was silly mistake.

a == digitalRead(2) must be a = digitalRead(2). You also better change the if clause to if(a) to avoid true/HIGH/1 confusions.
If you had formatted the code properly, you'd have safed some time (you just need to select the code and press the {} button).
You also better replace the relay with a voltage divider (as I mentioned in my comment), because as long as you don't have a datasheet for the sensor you can't be sure that the sensor is designed to source that much current. If the sensor is supposed to drive a TTL logic, it will eventually fail, just like you don't drive relays with GPIOs directly. And beside that you need a freewheeling diode across the relay coil to deal with back EMF which will also harm the sensor.

I can't forgive myself for this. I have wasted like 3 days on this stupidest syntax typo. Thank you for drawing my attention to it. Thank you for suggestions.

oh! I'll give it a try. The freewheeling diode stuff is really helpful for me. thanks.


text:
WDT ISR not called when SPI ST7789 module initiated
Using the .init function for the ST7789 TFT screen prevents my WDT ISR from firing. What explains this behaviour, and is there something I can do? Any other timer ISR I could use instead?
#include <Adafruit_ST7789.h>    // Includes Adafruit_GFX.h

#define TFT_CS 10 // define chip select pin
#define TFT_DC 9  // define data/command pin
#define TFT_RST 8 // define reset pin, or set to -1 and connect to Arduino RESET pin

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

void setup()
{
    //Serial.begin(9600);
    pinMode(13, OUTPUT);

    WDTCSR = (24); // Change enable and WDE - also resets
    //prescalers only - get rid of the WDE and WDCE bit.
    WDTCSR = (6); // 1 sec
    WDTCSR |= (1 << 6); //enable interrupt mode - WDT as an interrupt is useful to wake up from sleep
    sei();

    tft.init(240, 240, SPI_MODE2); // comment this out and WDT works fine
    tft.setRotation(0);
    tft.setTextWrap(true);
}

void loop()
{

}

ISR(WDT_vect)
{
  digitalWrite(13, (digitalRead(13) ^ 1));   // toggle LED pin
}

Thanks!

To be clear, you're saying pin 13 blinks if and only if the call to tft.init is commented out?

@timemage yes, exactly

You can't use the LED on pin 13 on Uno, Nano or Nano Every, if you use SPI . It is the clock pin of the SPI.
The init function of the display initializes SPI which dedicates the pin to SPI peripheral and disconnects it from pin IO peripheral.

Good point. Maybe I'd notice that if he mentioned about used pins like "using freaking 8 - RST; 9 - DC; 10 - CS; 11 - MOSI; 12 - MISO; 13 - SCLK; 13 - LED_BUILTIN"


text:
Need help - skipping over some serial.print statements
I have a project I'm working on for a chicken coop.  I want to control the door with timing of the sunrise and sunset.  Also looking to a few other things but somewhere along the way, I must have screwed up the placement of setup(), loop() and other void statements.  I'm not longer getting Serial.print statements to print.  I've done quite a bit of borrowing from other codes (which might be apparent to those that are much better at this than me).  For some of those borrowed codes, I'm getting serial prints.  I'm using this as my debug, so I can verify the values that I'm passing and to determine if they are what I'm expecting, specifically for the times of sunrise and sunset, to control my door actuator.
Any ideas why these various serial.print lines are not printing?
I've indicated some of the serial.print lines with <------------------------.
/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  WARNING!
    It's very tricky to get it working. Please read this article:
    http://help.blynk.cc/hardware-and-libraries/arduino/esp8266-with-at-firmware

  This example shows how value can be pushed from Arduino to
  the Blynk App.

  NOTE:
  BlynkTimer provides SimpleTimer functionality:
    http://playground.arduino.cc/Code/SimpleTimer

  App project setup:
    Value Display widget attached to Virtual Pin V5
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include "DHT.h"
#include <Wire.h>
#include <time.h>
#include <TimeLib.h>
#include <Dusk2Dawn.h>
#include <DS1307RTC.h>

#define TIMEZONE    -6
#define LATITUDE    38.3970
#define LONGITUDE   -90.6412

//The type of DHT that is being used
#define DHTTYPE DHT11   // DHT 11
//Which pin the DHT output is connected to the Arduino
#define DHTPIN 5
DHT dht(DHTPIN, DHTTYPE);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "d*********************************0";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "P**********k";
char pass[] = "m*****************a";

int DisconnectCount = 0;
int ReCnctFlag;
int ReCnctCount = 0;

  Dusk2Dawn HouseSprings(LATITUDE,LONGITUDE, TIMEZONE);
  tmElements_t tm;
  //Changes Mins to the same format as Sunrise/Sunset (minutes after midnight)
  int Mins = tm.Hour * 60 + tm.Minute;
  int Sunrise = HouseSprings.sunrise(tm.Year, tm.Month, tm.Day, true);
  int Sunset = HouseSprings.sunset(tm.Year, tm.Month, tm.Day, true);

//char Str_door_status[] = "";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate: adjust per project
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

BlynkTimer timer;

//Section of code that will handle getting the humidity/temp data and where to send it
void send_sensor()
{
  //Set the variable h to the value for humidity
  float h = dht.readHumidity();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  //Set the variable f to the value for temp
  float f = dht.readTemperature(true);
  //delay(1000);
  //Perform a check if either h or f has no value
  if (isnan(h) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  //These would be used to send data to the serial window
  Serial.println(h); // <------------------------
  Serial.println(f); // <------------------------
  //Set the virtual pin 3 of the blynk to the temperature value
  Blynk.virtualWrite(V3, f);
  //Set the virtual pin 4 of the blynk to the humidity value
  Blynk.virtualWrite(V4, h);
}

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.

}

int in1 = 11;
int in2 = 12;

void motor_stop()
{
  digitalWrite(in1,LOW);
  digitalWrite(in2,LOW);
  Blynk.virtualWrite(V6,0);
  Blynk.virtualWrite(V7,0);
}

BLYNK_WRITE(V6)
{
  int pinValue = param.asInt();
  pinMode(in1,OUTPUT);
  pinMode(in2,OUTPUT);
  if (pinValue = 1);
  {
    digitalWrite(in1,HIGH);
    digitalWrite(in2,LOW);
    Blynk.virtualWrite(V0,1);
    //delay(35000);
    //digitalWrite(in1,LOW);
    //Blynk.virtualWrite(V6,0);
    timer.setTimeout(35000L, motor_stop);
    Blynk.virtualWrite(V0,2);
  }
}

BLYNK_WRITE(V7)
{
  int pinValue = param.asInt();
  pinMode(in1,OUTPUT);
  pinMode(in2,OUTPUT);
  if (pinValue = 1);
  {
    digitalWrite(in1,LOW);
    digitalWrite(in2,HIGH);
    Blynk.virtualWrite(V0,1);
    //removed this delay function as Blynk doesn't like it
    //delay(35000);
    //digitalWrite(in1,LOW);
    //Blynk.virtualWrite(V6,0);
    //Secondary method of delay that Blynk appears to prefer
    timer.setTimeout(35000L, motor_stop);
    Blynk.virtualWrite(V0,0);
  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);

  dht.begin();

  timer.setInterval(1000L, send_sensor);

  //RTC.read(tm);

}

BLYNK_CONNECTED() {
  Serial.println("Connected");
  ReCnctCount = 0;

}

  //Serial.println(Sunrise);  // 418
  //Serial.println(Sunset);   // 1004

void open_door()
{

}

void close_door()
{
  Serial.println("info"); // <------------------------
  Serial.println(Mins); // <------------------------
  Serial.println(Sunrise); // <------------------------
  Serial.println(Sunset); // <------------------------
  char time2[] = "00:00";
  Dusk2Dawn::min2str(time2, Sunrise);
  Serial.print("Sunrise: ");     // <------------------------
  Serial.println(time2); // 16:53  // <------------------------
  char time3[] = "00:00";
  Dusk2Dawn::min2str(time3, Sunset);
  Serial.print("Sunset: ");  // <------------------------
  Serial.println(time3); // 16:53 // <------------------------
}

void loop()
{
  Serial.println(Mins); // <------------------------
  Serial.println(Sunrise); // <------------------------
  Serial.println(Sunset); // <------------------------

  if (Blynk.connected())
  {
    Blynk.run();                                    // Starts Blynk connection
  }
  else if (ReCnctFlag == 0)
  {
    ReCnctFlag = 1;                                 // Set reconnection Flag
    Serial.println("Starting reconnection timer in 3 seconds...");
    timer.setTimeout(3000L, []() {                 // Lambda Reconnection Timer Function
      ReCnctFlag = 0;                             // Reset reconnection Flag
      ReCnctCount++;                              // Increment reconnection Counter
      Serial.print("Attempting reconnection #");
      Serial.println(ReCnctCount);
      Blynk.connect();                            // Try to reconnect to the server
    });
  }
  timer.run(); // Initiates BlynkTimer

  //if (Mins > Sunrise) {
    //Serial.println("Door is open");
  //}
  //if (Mins > Sunset) {
  //  Serial.println("Door is closed");
  //}

}

This is what I'm getting in the serial window:
[45108333] Ready (ping: 53ms).
Connected

Not sure why the code posted weird, sorry for the mess.  Everything ran together from separate lines.

You can see what I did in the edit history.  In short, backticks rather than single-quote characters.  I've changed your attempt at bolding the print statements to indicating them with an arrow in a comment because formatting doesn't place nice with code listings.

I notice in the code is the use of 3 in SoftwareSerial EspSerial(2, 3); which seems to be Serial's RX pin.  But a severely cut down version of your code doing nothing but this didn't seem cause the problem.  My only suggestion is that you start removing code from your question, starting with things that people who might try to help you are not going to want to deal with.  Blynk, the DHT sensor, whatever you can remove while still demonstrating the problem.

put in lots of serial.print statements to determine where the program hangs

you can call Serial.begin() again to "fix" it and see if something else breaks. I'm guessing something is trying to digitalWrite to the serial pin.

@timemage, this is a sketch for Uno

try #define BLYNK_NO_BUILTIN before #include <BlynkSimpleShieldEsp8266.h>

@Juraj, yeah, that does make more sense.  Without a pile of stuff removed, I'm not going to get much use out of that information though.


text:
DS3231 Clock project shows right date but wrong day
Heeya Guys!
Today I created a project with the help of instructables site. I followed the on screen steps and everything. Uploaded the sketch and it works like a charm, but there's one problem.
Everything works correctly but not the "Day", i.e as of today its Friday, 9 April 2021, the clock shows the correct time and date but it tells that today is "Tuesday" in place of Friday. I don't know why this is happening.
Any help would be appreciated :)
Here's the code that I'm using:
/*Arduino Clock by AnthoTRONICS
* Last edit: March 22,2019
*/
// Libraries you'll need (Same as the ones in the guide:
// TAKE NOTE OF THE VERSIONS!!!

// MD Parola 3.0.1: https://github.com/MajicDesigns/MD_Parola // click the link to download the library
// MD_MAX72XX 3.0.2: https://github.com/MajicDesigns/MD_MAX72XX //click the link to download the library
// DS3231 1.0.2: https://github.com/NorthernWidget/DS3231 // click the link to download

/*CODE:*/
// Header file includes
// These are for the matrix
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include "Font_Data.h"

//These are for the clock
#include <DS3231.h>
#include <Wire.h>
DS3231 Clock;

bool Century=false;
bool h12;
bool PM;
byte  dd,mm,yyy;
uint16_t  h, m, s;

#define MAX_DEVICES 4 // Set the number of devices
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE,CS_PIN, MAX_DEVICES);

#define SPEED_TIME 75 // speed of the transition
#define PAUSE_TIME  0

#define MAX_MESG  20

// Global variables
char szTime[9];    // mm:ss\0
char szMesg[MAX_MESG+1] = "";

uint8_t degC[] = { 6, 3, 3, 56, 68, 68, 68 }; // Deg C
uint8_t degF[] = { 6, 3, 3, 124, 20, 20, 4 }; // Deg F

char *mon2str(uint8_t mon, char *psz, uint8_t len)

// Get a label from PROGMEM into a char array
{
  static const __FlashStringHelper* str[] =
  {
    F("Jan"), F("Feb"), F("Mar"), F("Apr"),
    F("May"), F("Jun"), F("Jul"), F("Aug"),
    F("Sep"), F("Oct"), F("Nov"), F("Dec")
  };

  strncpy_P(psz, (const char PROGMEM *)str[mon-1], len);
  psz[len] = '\0';

  return(psz);
}

char *dow2str(uint8_t code, char *psz, uint8_t len)
{
  static const __FlashStringHelper*  str[] =
  {
  F("Sunday"), F("Monday"), F("Tuesday"),
  F("Wednesday"), F("Thursday"), F("Friday"),
  F("Saturday"), F("Sunday")
  };

  strncpy_P(psz, (const char PROGMEM *)str[code-1], len);
  psz[len] = '\0';

  return(psz);
}
// Time Setup: Code for reading clock time
void getTime(char *psz, bool f = true)
{
  s = Clock.getSecond();
  m = Clock.getMinute();
  h =Clock.getHour(h12,PM); //24hr Format
  sprintf(psz, "%02d%c%02d", h, (f ? ':' : ' '), m);
  //12hr Format
  //uncomment if you want the clock to be in 12hr Format
  /*if (Clock.getHour(h12,PM)>=13 || Clock.getHour(h12,PM)==0)
  {
    h = Clock.getHour(h12,PM) - 12;
  }
  else
  {
    h = Clock.getHour(h12,PM);
  }*/

}

void getDate(char *psz)
// Date Setup: Code for reading clock date
{
   char  szBuf[10];

   dd=Clock.getDate();
   mm=Clock.getMonth(Century); //12
   yyy=Clock.getYear();
   sprintf(psz, "%d %s %04d",dd , mon2str(mm, szBuf, sizeof(szBuf)-1),(yyy + 2000));
 //strcpy(szMesg, "29 Feb 2016");
}

void setup(void)
{
  P.begin(2);
  P.setInvert(false); //we don't want to invert anything so it is set to false
  Wire.begin();

  P.setZone(0,  MAX_DEVICES-4, MAX_DEVICES-1);

  P.setZone(1, MAX_DEVICES-4, MAX_DEVICES-1);
  P.displayZoneText(1, szTime, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);

  P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, 0,PA_PRINT , PA_NO_EFFECT);

  P.addChar('$', degC);
  P.addChar('&', degF);

}

void loop(void)
{
  static uint32_t lastTime = 0; // millis() memory
  static uint8_t  display = 0;  // current display mode
  static bool flasher = false;  // seconds passing flasher

  P.displayAnimate();

   if (P.getZoneStatus(0))
  {
    switch (display)
    {
      case 0:    // Temperature deg C
      P.setPause(0,1000);
      //P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_UP);
      P.setTextEffect(0, PA_MESH, PA_BLINDS);
      display++;
      dtostrf(Clock.getTemperature(), 3, 1, szMesg);
      strcat(szMesg, "$");
      //strcat(szMesg, "26.5$");

        break;

      case 1: // Temperature deg F
        //P.setTextEffect(0, PA_SCROLL_UP, PA_SCROLL_LEFT);
        P.setTextEffect(0, PA_OPENING, PA_GROW_DOWN);
        display++;
        dtostrf((1.8 *Clock.getTemperature() )+32, 3, 1, szMesg);
        strcat(szMesg, "&");

   // strcpy(szMesg, "71.6&");

        break;

      case 2: // Clock

     P.setFont(0, numeric7Seg);
     P.setTextEffect(0, PA_PRINT, PA_NO_EFFECT);
     //Sleep Mode
     //Uncomment to enable Sleep Mode and adjust the hours to your needs
     /*if (h==12 || h<8)//Time intervals (in this case, from 12AM to 8AM)
     {
      P.setIntensity(0); //Set display brightness to lowest setting
     }
     else
     {
      P.setIntensity(6); //Set display brightness to 6 (15 is the brighest)
     }*/
     P.setPause(0,0);

     if (millis() - lastTime >= 1000)
    {
    lastTime = millis();
    getTime(szMesg, flasher);
    flasher = !flasher;
    }
    if(s==00&& s<=30){
    display++;
    P.setTextEffect(0, PA_PRINT, PA_SCROLL_UP);
    }

    //  strcpy(szMesg, "36 % RH");

        break;

      case 3: // day of week

        P.setFont(0,nullptr);
        P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
        display++;
        dow2str(Clock.getDoW()+1, szMesg, MAX_MESG); // Added +1 to get correct DoW

       //dow2str(5, szMesg, MAX_MESG);
        break;
      default:  // Calendar

        P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
        display = 0;
        getDate(szMesg);
        break;
    }

    P.displayReset(0);
  }

}

If your problem isn't dependent on it, remove your display code and more people will be able to compile your example.

Did you set the correct day of the week? The clock can't work it out from the date, it needs to be told it.

Note that, unlike the DS3231 library, RTClib computes the day of the week from the other date fields.

put in a bunch of serial.print commands to determine what are the variable values at different points in the program flow

Re-read @Majenko's comment-- You need to set the correct DOW in the DS3231 when you set its time. The DS3231 does not reset the rolling DOW register when you reset the other registers.  If it is uninitialized, the results are indeterminate.  https://github.com/NorthernWidget/DS3231/blob/master/DS3231.cpp#L274

The library seems to be addressing device register 3.
According to the DS3231 datasheet this register has valid values 1-7, with 1 being Sunday.
You have:
dow2str(Clock.getDoW()+1, szMesg, MAX_MESG);

1-7 becomes 2-8.  And then, how dow2str:
strncpy_P(psz, (const char PROGMEM *)str[code-1], len);

2-8, become array indices 1-7.
Your array is:
  static const __FlashStringHelper*  str[] =
  {
  F("Sunday"), F("Monday"), F("Tuesday"),
  F("Wednesday"), F("Thursday"), F("Friday"),
  F("Saturday"), F("Sunday")
  };

The indices here start at 0, so everything is off-by-one.  But, I don't know how you get Tuesday out of Friday.  If you cut your code down to something smaller that is testable without the display code, just using Serial, you'll probably get better answers.

It is probably an initialization problem.  The DS3231 doesn't recompute the DOW when the other registers are set, so if the other registers are properly set but the register 3 DOW is wrong, it likely wasn't properly initialized with the rest.


text:
Problem while uploading sketch
Hello I just tried to upload a simple sketch to my arduino Uno and the sketch is uploading forever and when I try to change the USB port where my arduino is connected no matter the port I putt the arduino in the IDE always says it is COM3.
Here is the error code I get while uploading:
avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Users\PC\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.0.1-arduino5/etc/avrdude.conf"

         Using Port                    : COM3
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x74
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x74
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x74
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x74
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x74
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x74
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x74
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x74
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x74
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x74

avrdude done.  Thank you.

Failed uploading: uploading error: exit status 1

Could you help me out to be able to upload my code to my arduino

what com port name does the windows device manager report?

What's the model of the USB-to-Serial chip on your Arduino board? If it's something like CH340G, you need to install additional driver before uploading your sketches.

Good day!
The error you are getting is a very generic one. It simply says that the Arduino IDE can't establish a connection with your Board.
There are many reasons such as:
-Bad USB cable
-Wrong board setting in the IDE
-Missing Bootloader
-Bricked Arduino
-Loose USB port
etc.
But from what I read here, it's most likely that COM3 is not really your Arduino but some other Serial port on the Computer. (Certain internal devices use these)
To check if that is the case, try disconnecting your Arduino and checking wether it still offers COM3 as a port.
If the port is gone it's either:
-Wrong board setting (Tools > Board)
-Broken board or cable
If the port is still available after you've removed your Arduino it means that said port is something else.
In that case my main suspect would be a missing CH340 driver. Try installing that, rebooting your computer and see if there is another COM port available.
The last suspect would be a Power-only USB cable. While these tend to be rare, I've come across them before. Try switching the cable for a different one.
If all that doesn't help, your Arduino might be broken.


text:
How to show repeated result on LCD while button is pressing
my results are here.
0 press--"a"
1st press--"b"
2nd press--"c"
3rd press-- still showing "c"
When button pressed 3rd time, It must be repeated to show "a" again. How can I repeat above 3 results to LCD?
#include <LiquidCrystal.h>
#include <ezButton.h>
ezButton button(7);
int count;
int count1;
const float rs = 1, en = 2, d4 = 3, d5 = 4, d6 = 5, d7 = 6;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
  button.setDebounceTime(50); // set debounce time to 50 milliseconds
  button.setCountMode(COUNT_FALLING);
  lcd.begin(16, 1);
}
void loop() {
  int count = button.getCount();
  button.loop();
  count1 = constrain(count, 0, 2);
  if(count1 == 0){
  lcd.print("a");
  }
  if(count1 == 1){
  lcd.print("b");
  }
  if(count1 == 2){
  lcd.print("c");
  }
  delay(500);
  lcd.clear();
}

investigate the remainder operator %

use button.resetCount();

The ezButton counter will keep counting up every time you release the button. count will be 3, then 4, 5, etc. But constrain will keep count1 stuck at 2. You could use button.resetCount(); when you print c to start over. Or use count1 = count % 3 like jsotola suggested.


text:
Error coming from specified code
Error
Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"

AnalogInOutSerial:8:56: error: no matching function for call to 'PID::PID(int*, int*, double*, double&, double&, double&, int)'
 PID pid(&Rawval, &Rawval, &setpoint, kp, ki, kd, DIRECT);
                                                        ^
In file included from C:\Users\USER\AppData\Local\Temp\arduino_modified_sketch_407168\AnalogInOutSerial.ino:1:0:
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:24:5: note: candidate: PID::PID(double*, double*, double*, double, double, double, int)
     PID(double*, double*, double*,        // * constructor.  links the PID to the Input, Output, and
     ^~~
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:24:5: note:   no known conversion for argument 1 from 'int*' to 'double*'
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:20:5: note: candidate: PID::PID(double*, double*, double*, double, double, double, int, int)
     PID(double*, double*, double*,        // * constructor.  links the PID to the Input, Output, and
     ^~~
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:20:5: note:   candidate expects 8 arguments, 7 provided
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:5:7: note: candidate: constexpr PID::PID(const PID&)
 class PID
       ^~~
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:5:7: note:   candidate expects 1 argument, 7 provided
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:5:7: note: candidate: constexpr PID::PID(PID&&)
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:5:7: note:   candidate expects 1 argument, 7 provided
exit status 1
no matching function for call to 'PID::PID(int*, int*, double*, double&, double&, double&, int)'

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

Actual Code
#include <PID_v1.h>

int analogPin = A3;
int Rawval ;  // variable to store the value read
double setpoint = 169; // target value for the system is set to 169
double kp = 1, ki = 0.1, kd = 0.01; // PID constants
int RELAY_pin = 10;    // Relay is connected to pin D10
PID pid(&Rawval, &Rawval, &setpoint, kp, ki, kd, DIRECT);

void setup()
{
  Serial.begin(9600);           //  setup serial
  pinMode(RELAY_pin, OUTPUT);
  pid.SetMode(AUTOMATIC);
}

void loop()
{
  Rawval = analogRead(analogPin);
  Serial.print("Rawvalue from Analog input  =");
  Serial.println(Rawval);
  pid.Compute();
  digitalWrite(RELAY_pin, Rawval < setpoint ? HIGH : LOW);
}

The error message is quite clear about the problem (extracted and formatted for clarity):

no matching function for call to
PID::PID(int*, int*, double*, double&, double&, double&, int)
[...]
candidate:
PID::PID(double*, double*, double*, double, double, double, int)
[...]
no known conversion for argument 1 from 'int*' to 'double*'
[other candidates left out due to non-matching number of arguments]

You need to provide pointers to double as the first two arguments, and the candidate will match.

EDIT:
I hesitated a while to provide your this, because you learn much better by doing it yourself. Anyway, here it is.
Your original variable declaration is:
int Rawval ;  // variable to store the value read

Replace the data type int by double, as the called constructor expects:
double Rawval ;  // variable to store the value read

Now there is this line, assigning an int to a double:
Rawval = analogRead(analogPin);

And you might ask yourself, is this OK? Well, try it. You will find that the compiler implicitly converts the value. If you want to make it explicitly, change the line to:
Rawval = static_cast<double>(analogRead(analogPin));

A final point, as datenheim states: Read and learn about the PID. It is for sure an error to use the same variable for input and output.

Can you kindly modify the portion & provide it here accordingly so that I can execute without any further error.Thanks in advance

My code is fine?? I will integrate yours as per modification..Till it will give error?
The code is to integrate PID in to arduino to an analogous sensor based on threshold value like 169 for raw value. If the value is less than the relay will be operational.
Target rawvalue =169
Target scaleval =5
Setpoint also
What would be the ka, kp, ki value for fully functional as described. Please guide. Thanks!

@Rocky, That is not how this site works. Your code is yours. You have been given enough information to fix the error in your code and now it's up to you to integrate the solution and fix your code so it does what you want.

I do understand the importance of. Highly obliged but it would be great for me if you kindly guide what would be the values for kp,ka,ki

@Rocky I have no idea. This is a completely different question, and certainly not one about programming. Since your course seems to involve control engineering, you should repeat the material you have.

Set value or target value is 169 as raw & 5% as scaled value. Current value -4&8 .So accordingly..Kp,ka, ki?

@Rocky, that makes no sense and this site is not a free homework service.

The first two parameters need to be of type double.
PID pid(&Rawval, &Rawval, &setpoint, kp, ki, kd, DIRECT);
        ^^^^^^^  ^^^^^^^

It also makes probably no sense to have input and output both wired to &Rawval.
Take a look on this example.

Can you kindly modify the portion & provide it here accordingly so that I can execute without any further error.Thanks in advance

No, sorry, learning is by doing. Try it, you will see :-)


text:
can we use Lm317 1.25 ref for ext. reference of arduino
I m trying to give ext ref. To Arduino using lm317 1.25 ref.
I  tried to do it. Iswt this voltage in programme too
But when I run it it was just displaying 1.25
And der was no variation as I varie the resistance of potentiometer which is connected to A0
So plz help me.....
My Arduino chip is Atmega 8A

Please post your code, and also your schematic. As it is your question doesn't make a lot of sense. See how to ask a good question.

yes but you have to use the analogReference(EXTERNAL); command otherwise it will short the default VCCref volatage with the external (i assume this will cause damage.. dunno never done that. yet...)
also if you use a 1.25v reference just remember that that will be the maximum voltage you can measure up to.
theres a couple of things you can do
1 use a voltage devider circuit to drop the max voltage out of your sensor(potentiometer) down to about 1.25v
2 put a series resistor betweent vcc and the positive terminal of your potentiometer (creating a voltage devider between the resistor and the full resistance of the potentiometer)
3 and probably the easiest connect the positive of the potentiometer to the lm317 /reference pin so that its output will be between Aref and GND this is the best option as it will be the most stable as its output will be in propotion to any fluctuation of the lm317
as in 3. the same can be done if using the internal Vref conect the pot to Aref (but remember that it has a limited current output so be carefull not to draw too much by using low resistance pots or many in parallel)

Kk i tried it. But the thing is I came to know my adc is not working means all the 6 pins.

The are always giving 1023 for any value . I tried also a basic programme of potentiometer but the thing is even there it was giving maximum value.....plz is there a solution for this. I also saw dat d aref pin is not shorted anywhere.

please post the relevant portion/s of your code for pot reading and void setup and variables. enough to compile please cheers