Error: 'digitalWrite' was not declared in this scope digitalWrite(_CS, LOW);

Hi, I am trying to write code for fireBeetle esp32 on arduino ide. There is a problem that I cannot solve even though I have installed the necessary library for ADS1256. I am sharing the part of the code I am trying to write about ADS. Can you say something about the codes below and the reason for the kata code?

#include <Wire.h>
#include <SPI.h>
#include <ads12xx.h>
#include <LiquidCrystal_I2C.h>

const int  START = 18;  //start pin
const int  CS = 22; //clock pin
const int  DRDY = 26; //data ready pin
float samplingfreq;  //

ads12xx ADS;  //initialize ADS as object of the ads12xx class
#define true 1
#define false 0
 
LiquidCrystal_I2C lcd(0x38,20,4);
  
void setup()
{

  //set up high baud rate for high data rates
  Serial.begin(115200);
    
const byte CS_pin = 22;  //goes to CS on ADS1256
const byte DRDY_pin = 26;  //goes to DRDY on ADS1256
}
 
void loop() {
 
  ADS.begin(CS, START, DRDY);  //initialize ADS as object of the ads12xx class
 
  ADS.Reset(); //Reset the AD chip. Every time you see the message on the Serial Terminal, everything is set to default!
  
    delay(10); //wait a moment
 
    //preconfig
     ADS.SetRegisterValue(STATUS, B00110100);  //Autocal is ON
     ADS.SetRegisterValue(MUX, B00001000); //
     ADS.SetRegisterValue(ADCON, B00000000); //
     ADS.SetRegisterValue(DRATE, B11010000); //7500 SPS     
     ADS.SetRegisterValue(IO, B11101111); //
     ADS.SendCMD(SELFCAL); //run self calibration    
    
  double startTime = millis(); 
    if (Serial.available()) {       
                ADS.SendCMD(SELFCAL); //Self calibration
                delay(200); //wait a little             
                ADS.SetRegisterValue(MUX, B00000001);//AIN0+AIN1 -- CH0
                        
        //printing the result
        Serial.println(ADS.GetConversion());
        //----------------DIFFERENTIAL CHANNEL ------------------------------------------------------------
        
          samplingfreq = Serial.parseFloat();
      
        //ADS.SetRegisterValue(DRATE, B11010000);  //7500 SPS// for 1 sample / second on the PC
   
       ADS.SetRegisterValue(DRATE, B01100011);
        ADS.SendCMD(SELFCAL); //Self calibration
        delay(200); //wait a little
        
        int o=0;    
       //calibration!
       while ( o = 3 ) { //while we don't stop manially by sending N through the terminal....
        //Elapsed time since the sw is started
        double elapsedTime = millis() - startTime;              
        //prints time since program started
        Serial.print(elapsedTime);
        Serial.print("\t");
        //Switch on the first channel
        ADS.SetRegisterValue(MUX, B00000001);//AIN0+AIN1 -- CH0
        Serial.print(ADS.GetConversion());
        pop[o]=ADS.GetConversion(); // saving signal value to a variable array
        Serial.print("\t");
        delay(samplingfreq);
        }  o++;} 
        }

error codes:


C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:3:27: error: 'HIGH' was not declared in this scope
 volatile int DRDY_state = HIGH;
                           ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp: In function 'void waitforDRDY()':
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:11:16: error: 'noInterrupts' was not declared in this scope
   noInterrupts();
                ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:12:16: error: 'HIGH' was not declared in this scope
   DRDY_state = HIGH;
                ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:13:14: error: 'interrupts' was not declared in this scope
   interrupts();
              ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp: In function 'void DRDY_Interuppt()':
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:17:38: error: 'LOW' was not declared in this scope
 void DRDY_Interuppt() { DRDY_state = LOW; }
                                      ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp: In member function 'void ads12xx::begin(int, int, int)':
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:23:15: error: 'OUTPUT' was not declared in this scope
   pinMode(CS, OUTPUT);    // set the slaveSelectPin as an output:
               ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:23:21: error: 'pinMode' was not declared in this scope
   pinMode(CS, OUTPUT);    // set the slaveSelectPin as an output:
                     ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:24:20: error: 'HIGH' was not declared in this scope
   digitalWrite(CS, HIGH); // CS HIGH = nothing selected
                    ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:24:24: error: 'digitalWrite' was not declared in this scope
   digitalWrite(CS, HIGH); // CS HIGH = nothing selected
                        ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:27:17: error: 'INPUT' was not declared in this scope
   pinMode(DRDY, INPUT); // DRDY read
                 ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:32:12: error: 'delay' was not declared in this scope
   delay(500);
            ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:36:65: error: 'FALLING' was not declared in this scope
   attachInterrupt(digitalPinToInterrupt(_DRDY), DRDY_Interuppt, FALLING);
                                                                 ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:36:72: error: 'attachInterrupt' was not declared in this scope
   attachInterrupt(digitalPinToInterrupt(_DRDY), DRDY_Interuppt, FALLING);
                                                                        ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp: In member function 'long int ads12xx::GetContConversion(int32_t*, uint16_t)':
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:44:47: error: 'MSBFIRST' was not declared in this scope
   SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1));
                                               ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:46:21: error: 'LOW' was not declared in this scope
   digitalWrite(_CS, LOW); // Pull SS Low to Enable Communications with
                     ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:46:24: error: 'digitalWrite' was not declared in this scope
   digitalWrite(_CS, LOW); // Pull SS Low to Enable Communications with
                        ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:49:23: error: 'delayMicroseconds' was not declared in this scope
   delayMicroseconds(10); // RD: Wait 25ns for ADC12xx to get ready
                       ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:63:21: error: 'HIGH' was not declared in this scope
   digitalWrite(_CS, HIGH);
                     ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp: In member function 'long int ads12xx::GetConversion()':
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:71:47: error: 'MSBFIRST' was not declared in this scope
   SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1));
                                               ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:72:21: error: 'LOW' was not declared in this scope
   digitalWrite(_CS, LOW); // Pull SS Low to Enable Communications with
                     ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:72:24: error: 'digitalWrite' was not declared in this scope
   digitalWrite(_CS, LOW); // Pull SS Low to Enable Communications with
                        ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:74:23: error: 'delayMicroseconds' was not declared in this scope
   delayMicroseconds(10); // RD: Wait 25ns for ADC12xx to get ready
                       ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:86:21: error: 'HIGH' was not declared in this scope
   digitalWrite(_CS, HIGH);
                     ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp: In member function 'void ads12xx::SetRegisterValue(uint8_t, uint8_t)':
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:102:3: error: 'Serial' was not declared in this scope
   Serial.print("Previous val ");
   ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:103:31: error: 'HEX' was not declared in this scope
   Serial.println(regValuePre, HEX);
                               ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:106:25: error: 'delayMicroseconds' was not declared in this scope
     delayMicroseconds(10);
                         ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:109:20: error: 'MSBFIRST' was not declared in this scope
         SPI_SPEED, MSBFIRST,
                    ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:111:23: error: 'LOW' was not declared in this scope
     digitalWrite(_CS, LOW);
                       ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:111:26: error: 'digitalWrite' was not declared in this scope
     digitalWrite(_CS, LOW);
                          ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:118:23: error: 'HIGH' was not declared in this scope
     digitalWrite(_CS, HIGH);
                       ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp: In member function 'long unsigned int ads12xx::GetRegisterValue(uint8_t)':
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:136:18: error: 'MSBFIRST' was not declared in this scope
       SPI_SPEED, MSBFIRST,
                  ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:139:21: error: 'LOW' was not declared in this scope
   digitalWrite(_CS, LOW);
                     ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:139:24: error: 'digitalWrite' was not declared in this scope
   digitalWrite(_CS, LOW);
                        ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:140:23: error: 'delayMicroseconds' was not declared in this scope
   delayMicroseconds(10);
                       ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:147:21: error: 'HIGH' was not declared in this scope
   digitalWrite(_CS, HIGH);
                     ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp: In member function 'void ads12xx::SendCMD(uint8_t)':
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:160:18: error: 'MSBFIRST' was not declared in this scope
       SPI_SPEED, MSBFIRST,
                  ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:162:21: error: 'LOW' was not declared in this scope
   digitalWrite(_CS, LOW);
                     ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:162:24: error: 'digitalWrite' was not declared in this scope
   digitalWrite(_CS, LOW);
                        ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:163:23: error: 'delayMicroseconds' was not declared in this scope
   delayMicroseconds(10);
                       ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:166:21: error: 'HIGH' was not declared in this scope
   digitalWrite(_CS, HIGH);
                     ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp: In member function 'void ads12xx::Reset()':
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:173:18: error: 'MSBFIRST' was not declared in this scope
       SPI_SPEED, MSBFIRST,
                  ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:175:21: error: 'LOW' was not declared in this scope
   digitalWrite(_CS, LOW);
                     ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:175:24: error: 'digitalWrite' was not declared in this scope
   digitalWrite(_CS, LOW);
                        ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:176:23: error: 'delayMicroseconds' was not declared in this scope
   delayMicroseconds(10);
                       ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:178:10: error: 'delay' was not declared in this scope
   delay(2);             // Minimum 0.6ms required for Reset to finish.
          ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master\ads12xx.cpp:181:21: error: 'HIGH' was not declared in this scope
   digitalWrite(_CS, HIGH);
                     ^
Multiple libraries were found for "Wire.h"
 Used: C:\Users\Hp\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\Wire
 Not used: C:\Users\Hp\Desktop\arduino-1.8.19\libraries\Wire
Multiple libraries were found for "SPI.h"
 Used: C:\Users\Hp\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SPI
 Not used: C:\Users\Hp\Desktop\arduino-1.8.19\libraries\SPI
exit status 1
Error compiling for board FireBeetle-ESP32.

#include <Arduino.h> is something to try.

Why do

?

Maybe: HIGH, LOW, true and false ar values for bool... (not int)

Yep,

The library is not so well written. Adding #include <Arduino.h> as the first line of the .ino should address the issue

They do so in the example

I'm sorry for the late reply. I tried to add the arduino.h library by typing in the ide interface.

#include <Arduino.h>

But I see it is in passive (black) color. Isn't this library installed by default, with ide? When I wanted to load the Arduino.h library externally, I couldn't find it on the internet.

With an ESP32 Arduino.h is not necessarily loaded.

I use

#include "sdkconfig.h"
#include "esp_system.h"

instead of Arduino.h.

When you tried Arduino.h did the code work?

#include <sdkconfig.h>
#include <esp_system.h>

When I type these two library names into ide, it seems to be passive.

Did Arduino.h work?

I'd not get to hooked up on colors and highlighting of text in the IDE.

After loading the ArduinoCore-avr-master library into the ide

#include <Arduino.h>
#include <sdkconfig.h>
#include <esp_system.h>

When I type, all three libraries seem to be inactive. and I keep getting the same errors.

Can you compile the example I linked to in post 4?

Except for this part. I don't understand the arrangement here?

  • START: set HIGH
  • RESET: set HIGH
  • CLOK: set LOW

Don't be concerned with the color. There is no guaranteed coloration of this sort of thing in Arduino IDE 1.x based on the code itself.

The colors mostly come from arbitrary lists of keywords defined by the authors of whichever libraries you happen to have installed (regardless of whether they are used by your sketch).

The library authors can define arbitrary keywords which will be colored. Some of them do, some of them do it inconsistently, some of them do it incorrectly, some of them don't bother to do it at all.

When it comes to the header file names of libraries, it is not really clear whether it is even appropriate to define them as keywords. Most of the time they end up as keywords simply because the header file name happens to be the same as an object from the code itself.

So the only reason why the "Arduino" in Arduino.h is black is because Arduino did not define "Arduino" as a keyword. It does not have any other significance.

Yes. It is actually installed as part of the core library of the boards platforms, but one of those is bundled with the Arduino IDE, so your statement is still accurate.

There are many different versions of the file. You can find them on the Internet, but it would never make sense to install it by itself, so don't bother to look unless you are simply curious.

The reason is the same as I explained for Arduino.h. This is normal and expected and does not indicate any problem at all. The only thing that matters is what the compiler thinks of your code, and the compiler is not the source of those pretty colors.

Thank you for the explanations. I understand that. I continue to get errors even though I have followed all described. Can you help with the solution?

In this case, the installed libraries, the line of code and the first error I get is:

#include <Arduino.h>
#include <ads1248.h>
#include <ads1256.h>
#include <ads12xx.h>
#include <sdkconfig.h>
#include <esp_system.h>
#include <SPI.h>
#include <LIS3MDL.h>
#include <Streaming.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

while (!Serial) {}
 
  ADS.begin(CS, START, DRDY);  //initialize ADS as object of the ads12xx class
 
  ADS.Reset(); //Reset the AD chip. Every time you see the message on the Serial Terminal, everything is set to default!
  
    delay(10); //wait a moment

error codes:

C:\Users\Hp\Documents\Arduino\LF-Antenna1\LF-Antenna1.ino: In function 'void loop()':
LF-Antenna1:104:28: error: no matching function for call to 'ads12xx::begin(const int&, const int&, const int&)'
   ADS.begin(CS, START, DRDY);  //initialize ADS as object of the ads12xx class
                            ^
In file included from C:\Users\Hp\Documents\Arduino\LF-Antenna1\LF-Antenna1.ino:5:0:
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master/ads12xx.h:21:7: note: candidate: void ads12xx::begin(int, int, int, int)
  void begin(
       ^
C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master/ads12xx.h:21:7: note:   candidate expects 4 arguments, 3 provided
Multiple libraries were found for "SPI.h"
 Used: C:\Users\Hp\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SPI
 Not used: C:\Users\Hp\Desktop\arduino-1.8.19\libraries\SPI
Multiple libraries were found for "Wire.h"
 Used: C:\Users\Hp\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\Wire
 Not used: C:\Users\Hp\Desktop\arduino-1.8.19\libraries\Wire
exit status 1
no matching function for call to 'ads12xx::begin(const int&, const int&, const int&)'

I have already exceeded the time I set for my project. I don't know if I can overcome the problems I'm experiencing if I use another card with similar features instead of the freebeetle ESP32. If this is possible, can you suggest another card? Arduino is my choice.

The _RESET parameter was added to the function more recently:

You can study the example sketch included with the library to learn how to use it:

After I wrote this code you suggested in the void setup section, I got the following errors.

Arduino: 1.8.19 (Windows 10), Board: "FireBeetle-ESP32, 80MHz, 115200"


C:\Users\Hp\Documents\Arduino\LF-Antenna1\LF-Antenna1.ino: In function 'void setup()':

LF-Antenna1:50:29: error: '_RESET' was not declared in this scope

   ADS.begin(CS, START, DRDY,_RESET);  //initialize ADS as object of the ads12xx class

                             ^

C:\Users\Hp\Documents\Arduino\LF-Antenna1\LF-Antenna1.ino: In function 'void loop()':

LF-Antenna1:124:28: error: no matching function for call to 'ads12xx::begin(const int&, const int&, const int&)'

   ADS.begin(CS, START, DRDY);  //initialize ADS as object of the ads12xx class

                            ^

In file included from C:\Users\Hp\Documents\Arduino\LF-Antenna1\LF-Antenna1.ino:5:0:

C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master/ads12xx.h:21:7: note: candidate: void ads12xx::begin(int, int, int, int)

  void begin(

       ^

C:\Users\Hp\Desktop\arduino-1.8.19\libraries\ADS12xx-Library-master/ads12xx.h:21:7: note:   candidate expects 4 arguments, 3 provided

Multiple libraries were found for "SPI.h"

 Used: C:\Users\Hp\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SPI

 Not used: C:\Users\Hp\Desktop\arduino-1.8.19\libraries\SPI

Multiple libraries were found for "Wire.h"

 Used: C:\Users\Hp\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\Wire

 Not used: C:\Users\Hp\Desktop\arduino-1.8.19\libraries\Wire

exit status 1

'_RESET' was not declared in this scope

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

That is why you must study the example:

Thank you for your helping efforts.
I meant this; I tested the example in the link completely on the ide side. I've shared the errors I got after making up for some parenthesis and semicolon omissions.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.