Unable to compile the basic PID code

Hello,

I am unable to compile the code of Basic PID and below are the error messages.

Can someone help me please?

=====================================================================
Arduino: 1.8.10 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\aprasad\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10810 -build-path C:\Users\aprasad\AppData\Local\Temp\arduino_build_385467 -warnings=none -build-cache C:\Users\aprasad\AppData\Local\Temp\arduino_cache_104574 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\aprasad\Desktop\Arduino-PID-Library-master\Arduino-PID-Library-master\examples\PID_Basic\PID_Basic.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\aprasad\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10810 -build-path C:\Users\aprasad\AppData\Local\Temp\arduino_build_385467 -warnings=none -build-cache C:\Users\aprasad\AppData\Local\Temp\arduino_cache_104574 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\aprasad\Desktop\Arduino-PID-Library-master\Arduino-PID-Library-master\examples\PID_Basic\PID_Basic.ino
Using board 'uno' from platform in folder: C:\Program
Using core 'arduino' from platform in folder: C:\Program
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\aprasad\AppData\Local\Temp\arduino_build_385467\sketch\PID_Basic.ino.cpp" -o nul
Alternatives for PID_v1.h: [Arduino-PID-Library-master@1.2.1 PID@1.2.0]
ResolveLibrary(PID_v1.h)
-> candidates: [Arduino-PID-Library-master@1.2.1 PID@1.2.0]
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x7855fb]

goroutine 1 [running]:
github.com/arduino/arduino-cli/legacy/builder.ResolveLibrary(0x130de5a0, 0x133e80b3, 0x8, 0x133e80b3)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/resolve_library.go:64 +0x14b
github.com/arduino/arduino-cli/legacy/builder.findIncludesUntilDone(0x130de5a0, 0x1331efa0, 0x88ed00, 0x131aa690, 0x133530f0, 0x133b6000, 0x0)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/container_find_includes.go:358 +0x3b6
github.com/arduino/arduino-cli/legacy/builder.(*ContainerFindIncludes).Run(0xdebc68, 0x130de5a0, 0xdebc68, 0x0)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/container_find_includes.go:152 +0x3e5
github.com/arduino/arduino-cli/legacy/builder.runCommands(0x130de5a0, 0x13075e1c, 0x20, 0x20, 0x1, 0x2bfffff, 0x800)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:210 +0xbd
github.com/arduino/arduino-cli/legacy/builder.(*Builder).Run(0x13075f40, 0x130de5a0, 0xdebbb4, 0x13046c78)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:117 +0xb9c
github.com/arduino/arduino-cli/legacy/builder.RunBuilder(...)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:226
main.main()
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-builder/main.go:398 +0x6d2
C:\Program Files (x86)\Arduino\arduino-builder returned 2
Error compiling for board Arduino/Genuino Uno.

=======================================================================================================================

Sincerely,
Prasad

Can someone help me please?

Not without seeing your code

Please Read this before posting a programming question and follow the instructions for posting code and error messages

#include <PID_v1.h>

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

  • PID Basic Example
  • Reading analog input 0 to control analog PWM output 3
    ********************************************************/

#include <PID_v1.h>

#define PIN_INPUT 0
#define PIN_OUTPUT 3

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
double Kp=2, Ki=5, Kd=1;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

void setup()
{
//initialize the variables we're linked to
Input = analogRead(PIN_INPUT);
Setpoint = 100;

//turn the PID on
myPID.SetMode(AUTOMATIC);
}

void loop()
{
Input = analogRead(PIN_INPUT);
myPID.Compute();
analogWrite(PIN_OUTPUT, Output);
}

Did you Read this before posting a programming question ?

no..I have not gone through.
I am not a programming guy..I am just pursuing my hobby on PID controllers and found this code.

I would be glad, if you can point out quickly of any changes to be made to the code

I would be glad, if you can point out quickly of any changes to be made to the code

I have not even looked at the code, but if you read the advice in the link I gave then you will see that is advises the use of code tags when posting code together with supporting information such as how it was compiled, hardware used and the programming environment

#include <PID_v1.h>

/********************************************************
 * PID Basic Example
 * Reading analog input 0 to control analog PWM output 3
 ********************************************************/

#include <PID_v1.h>

#define PIN_INPUT 0
#define PIN_OUTPUT 3

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
double Kp=2, Ki=5, Kd=1;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

void setup()
{
  //initialize the variables we're linked to
  Input = analogRead(PIN_INPUT);
  Setpoint = 100;

  //turn the PID on
  myPID.SetMode(AUTOMATIC);
}

void loop()
{
  Input = analogRead(PIN_INPUT);
  myPID.Compute();
  analogWrite(PIN_OUTPUT, Output);
}

Looks like something in the compiler crashed. Try updating your installation:

  • Select Tools->Board:->Boards Manager...
  • In "Type:" select "Updatable"
  • Click on the "Update" button of the first item in the list.
  • Repeat from step 2 until the list of updatable boards is empty.

And it couldn't hurt to update your libraries:

  • Select Tools->Manage Libraries...
  • In "Type:" select "Updatable"
  • Click on the "Update" button of each item in the list.

I did the both steps above...and still no luck sir

if I open an inbuilt arduino example, I am able to compile successfully (verify). The problem is with the Basic_PID sketch which is callilng PID_v1.h library.

johnwasser:
Looks like something in the compiler crashed. Try updating your installation:

I have to concur with @johnwasser.

You did not tell us which PID library you are using. I downloaded the first I found on a Google search (Arduino-PID-Library/PID_v1.cpp at master · br3ttb/Arduino-PID ...Arduino-PID-Library/PID_v1.cpp at master · br3ttb/Arduino-PID ...).

Also assume you are using an UNO. I am on Windows 10 and also Arduino IDE Ver 1.8.10.

Selected 328P in Minicore and I compiled your sketch exactly as in post #6. It compiled clean.

Sketch uses 3072 bytes (9%) of program storage space. Maximum is 32768 bytes.
Global variables use 81 bytes (3%) of dynamic memory, leaving 1967 bytes for local variables. Maximum is 2048 bytes.

I do, however, think you may have problems with using pin 0 for analogRead. It is not an ADC input pin.

Willem.

Willem43:
I do, however, think you may have problems with using pin 0 for analogRead. It is not an ADC input pin.

Willem.

Nonsense.
In analogRead, 0 and A0 both refer to the same pin.

TheMemberFormerlyKnownAsAWOL:
Nonsense.
In analogRead, 0 and A0 both refer to the same pin.

Interesting. Looking at my Arduino pinout, Ardiuno pin 0 refers PD0 - RX. Ardiuno A0 refers to PC0. Hence my comment. Must have misunderstood how pins are referenced when using analogRead() - which I do not use too frequently.

Will check that out at some stage. Thanks for pointing it out.

So, that sketch should be fine.

Willem.

[EDIT]: Did a bit of reading, and you are correct. There is, however, quite a bit more to the way analogRead behaves than I initially assumed. I learn something new all the time.

I have installed the library and took sketch from the below location please

All, I have uninstalled and re-installed the Arduino IDE 1.8.10 and re-installed the PID_Basic library from above link.

Now I am able to compile and download in to my UNO.

Thanks for the great support extended by all.