Positive is not declared in this scope

NOOB questions.

I'm a total beginner, so please be gentle. I'm trying to upload some code for a resistivity meter, which was written around 2018. When I try to compile it I get an error, which says Positive is not declared in this scope and it highlights this line from the code.

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

I've read various things saying I need rewrite the software, but I haven't a clue where to start.

Below is a copy of the error message.

In file included from /Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/Sd2Card.h:26:0,
                 from /Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFat.h:29,
                 from /Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/SD.h:20,
                 from /private/var/folders/9h/3h27c0ps13zf730rk40f2rrm0000gn/T/.arduinoIDE-unsaved2024021-3187-1ht81mf.p3fo/sketch_jan21a/sketch_jan21a.ino:7:
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/Sd2PinMap.h: In function 'void setup()':
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/Sd2PinMap.h:467:33: error: a function-definition is not allowed here before '{' token
 uint8_t getPinMode(uint8_t pin) {
                                 ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/Sd2PinMap.h:475:44: error: a function-definition is not allowed here before '{' token
 void setPinMode(uint8_t pin, uint8_t mode) {
                                            ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/Sd2PinMap.h:487:38: error: a function-definition is not allowed here before '{' token
 uint8_t fastDigitalRead(uint8_t pin) {
                                      ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/Sd2PinMap.h:495:51: error: a function-definition is not allowed here before '{' token
 void fastDigitalWrite(uint8_t pin, uint8_t value) {
                                                   ^
In file included from /Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFat.h:30:0,
                 from /Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/SD.h:20,
                 from /private/var/folders/9h/3h27c0ps13zf730rk40f2rrm0000gn/T/.arduinoIDE-unsaved2024021-3187-1ht81mf.p3fo/sketch_jan21a/sketch_jan21a.ino:7:
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/FatStructs.h:401:58: error: a function-definition is not allowed here before '{' token
 static inline uint8_t DIR_IS_LONG_NAME(const dir_t* dir) {
                                                          ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/FatStructs.h:407:53: error: a function-definition is not allowed here before '{' token
 static inline uint8_t DIR_IS_FILE(const dir_t* dir) {
                                                     ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/FatStructs.h:411:55: error: a function-definition is not allowed here before '{' token
 static inline uint8_t DIR_IS_SUBDIR(const dir_t* dir) {
                                                       ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/FatStructs.h:415:63: error: a function-definition is not allowed here before '{' token
 static inline uint8_t DIR_IS_FILE_OR_SUBDIR(const dir_t* dir) {
                                                               ^
In file included from /Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/SD.h:20:0,
                 from /private/var/folders/9h/3h27c0ps13zf730rk40f2rrm0000gn/T/.arduinoIDE-unsaved2024021-3187-1ht81mf.p3fo/sketch_jan21a/sketch_jan21a.ino:7:
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFat.h:111:76: error: a function-definition is not allowed here before '{' token
 static inline uint16_t FAT_DATE(uint16_t year, uint8_t month, uint8_t day) {
                                                                            ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFat.h:115:51: error: a function-definition is not allowed here before '{' token
 static inline uint16_t FAT_YEAR(uint16_t fatDate) {
                                                   ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFat.h:119:51: error: a function-definition is not allowed here before '{' token
 static inline uint8_t FAT_MONTH(uint16_t fatDate) {
                                                   ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFat.h:123:49: error: a function-definition is not allowed here before '{' token
 static inline uint8_t FAT_DAY(uint16_t fatDate) {
                                                 ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFat.h:127:79: error: a function-definition is not allowed here before '{' token
 static inline uint16_t FAT_TIME(uint8_t hour, uint8_t minute, uint8_t second) {
                                                                               ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFat.h:131:50: error: a function-definition is not allowed here before '{' token
 static inline uint8_t FAT_HOUR(uint16_t fatTime) {
                                                  ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFat.h:135:52: error: a function-definition is not allowed here before '{' token
 static inline uint8_t FAT_MINUTE(uint16_t fatTime) {
                                                    ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFat.h:139:52: error: a function-definition is not allowed here before '{' token
 static inline uint8_t FAT_SECOND(uint16_t fatTime) {
                                                    ^
In file included from /Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/SD.h:21:0,
                 from /private/var/folders/9h/3h27c0ps13zf730rk40f2rrm0000gn/T/.arduinoIDE-unsaved2024021-3187-1ht81mf.p3fo/sketch_jan21a/sketch_jan21a.ino:7:
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFatUtil.h:39:35: error: a function-definition is not allowed here before '{' token
 static UNUSEDOK int FreeRam(void) {
                                   ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFatUtil.h:61:47: error: a function-definition is not allowed here before '{' token
 static NOINLINE void SerialPrint_P(PGM_P str) {
                                               ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/utility/SdFatUtil.h:72:49: error: a function-definition is not allowed here before '{' token
 static NOINLINE void SerialPrintln_P(PGM_P str) {
                                                 ^
In file included from /private/var/folders/9h/3h27c0ps13zf730rk40f2rrm0000gn/T/.arduinoIDE-unsaved2024021-3187-1ht81mf.p3fo/sketch_jan21a/sketch_jan21a.ino:7:0:
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/SD.h:26:1: error: 'namespace' definition is not allowed here
 namespace SDLib {
 ^~~~~~~~~
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/SD.h:130:17: error: 'SDLib' is not a namespace-name
 using namespace SDLib;
                 ^~~~~
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/SD.h:130:22: error: expected namespace-name before ';' token
 using namespace SDLib;
                      ^
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/SD.h:134:9: error: 'SDLib' does not name a type
 typedef SDLib::File    SDFile;
         ^~~~~
/Users/mrklmacdonald/Library/Arduino15/libraries/SD/src/SD.h:135:9: error: 'SDLib' does not name a type
 typedef SDLib::SDClass SDFileSystemClass;
         ^~~~~
/private/var/folders/9h/3h27c0ps13zf730rk40f2rrm0000gn/T/.arduinoIDE-unsaved2024021-3187-1ht81mf.p3fo/sketch_jan21a/sketch_jan21a.ino:13:53: error: 'POSITIVE' was not declared in this scope
 LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
                                                     ^~~~~~~~
/private/var/folders/9h/3h27c0ps13zf730rk40f2rrm0000gn/T/.arduinoIDE-unsaved2024021-3187-1ht81mf.p3fo/sketch_jan21a/sketch_jan21a.ino:28:14: error: a function-definition is not allowed here before '{' token
 void setup() {
              ^
/private/var/folders/9h/3h27c0ps13zf730rk40f2rrm0000gn/T/.arduinoIDE-unsaved2024021-3187-1ht81mf.p3fo/sketch_jan21a/sketch_jan21a.ino:74:13: error: a function-definition is not allowed here before '{' token
 void loop() {
             ^

exit status 1

Compilation error: 'POSITIVE' was not declared in this scope

Please post your sketch, using code tags when you do

At a guess, at least some of the errors, but not all, are caused by trying to compile code for an LCD library with the same name but different functions

Have you looked at the examples with the LCD library that you have ?

post code, in tags please.

//Include libraries
#include <Wire.h>
#include <Adafruit_INA219.h>
#include <LiquidCrystal_I2C.h>
#include <SD.h>
// INA219 Sensor and LCD screen attached to I2C (Inter-Integrated Circuit) bus as follows:
// SDA (Serial Data Line) - pin A4 (pink)
// SCL (Serial Clock Line) - pin A5 (white)
// Set the I2C address for each device
Adafruit_INA219 ina219;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// SD card attached to SPI (Serial Peripheral Interface) bus as follows:
// MOSI (Master Out Slave In) - pin 11 (yellow)
// MISO (Master In Slave Out) - pin 12 (green)
// SLK (Serial Clock) - pin 13 (orange)
// CS (Chip Select) - pin 10 (blue)
const int DefaultCS = 10; // Default output
// Set adequate length for string transfer to SD card
char buffer [10];
// Initialize reading sequence
int id = 1;
//-----------------------------------------------------------
// SETUP SETUP SETUP SETUP SETUP
//-----------------------------------------------------------
// void setup, to run once:
void setup() {
// Initialize communication with INA219 sensor
ina219.begin();
// Sensor defaults calibration in 32V, 2A range
// Set a lower 16V, 400mA calibration range to improve precision
ina219.setCalibration_16V_400mA();
// Initialize communication with lcd screen
lcd.begin(20, 4);
// Print title
lcd.setCursor(0, 0);
lcd.print("Resistivity Test");
// Print author
lcd.setCursor(0, 1);
lcd.print(" xxxxxx);
// Wait
delay(500);
// Print Status 1
lcd.setCursor(0, 2);
lcd.print("Booting...");
lcd.setCursor(0, 3);
// Wait
delay(500);
40
// Set default CS pin as output
pinMode(DefaultCS, OUTPUT);
// See if SD card is present and can be initialized
if (!SD.begin(DefaultCS)) {
lcd.print("Card failed"); // Print Error 1
return; // Exit void setup
}
// See if file can be written/opened
File logFile = SD.open("LOG.csv", FILE_WRITE);
if (logFile) {
logFile.println(", ,"); // Write a leading blank line
String header = "I, V, R";
logFile.println(header); // Write header
logFile.close(); // and close file
lcd.print("File initialized..."); // Print Status 2
}
else {
lcd.print("File failed"); // Else, print Error 2
}
delay(1000);
}
//--------------------------------------------------------
// LOOP LOOP LOOP LOOP LOOP
//--------------------------------------------------------
// void loop, to run repeatedly:
void loop() {
// Clear screen
lcd.clear();
// Get current in mA from INA219 sensor
float current_mA = ina219.getCurrent_mA();
// Convert to SI unit
float current = (current_mA / 1000);
// Print current
lcd.setCursor(1, 0);
lcd.print("I= ");
lcd.print(current_mA,3);
lcd.print(" mAmps");
// Arduino senses voltage in 0-5V range
// A voltage divider creates an ouput voltage that is a fraction of the input
float Ra = 1000000; // input resistor value of voltage divider
float Rb = 100000; // output resistor value of voltage divider
float RR = (Rb/(Ra+Rb)); // voltage divider ratio
// Read analog value from sensor A0
int value0 = analogRead(A0);
// Calculate voltage sensed at output of voltage divider
float vraw = (value0*5.0/1024);
// Adjust voltage at input of voltage divider
float voltage = (vraw / RR);
// Print voltage
lcd.setCursor(1, 1);
lcd.print("V= ");
lcd.print(voltage,3);
lcd.print(" Volts");
below:
//Include libraries
#include <Wire.h>
#include <Adafruit_INA219.h>
#include <LiquidCrystal_I2C.h>
#include <SD.h>
// INA219 Sensor and LCD screen attached to I2C (Inter-Integrated Circuit) bus as follows:
// SDA (Serial Data Line) - pin A4 (pink)
// SCL (Serial Clock Line) - pin A5 (white)
// Set the I2C address for each device
Adafruit_INA219 ina219;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// SD card attached to SPI (Serial Peripheral Interface) bus as follows:
// MOSI (Master Out Slave In) - pin 11 (yellow)
// MISO (Master In Slave Out) - pin 12 (green)
// SLK (Serial Clock) - pin 13 (orange)
// CS (Chip Select) - pin 10 (blue)
const int DefaultCS = 10; // Default output
// Set adequate length for string transfer to SD card
char buffer [10];
// Initialize reading sequence
int id = 1;
//-----------------------------------------------------------
// SETUP SETUP SETUP SETUP SETUP
//-----------------------------------------------------------
// void setup, to run once:
void setup() {
// Initialize communication with INA219 sensor
ina219.begin();
// Sensor defaults calibration in 32V, 2A range
// Set a lower 16V, 400mA calibration range to improve precision
ina219.setCalibration_16V_400mA();
// Initialize communication with lcd screen
lcd.begin(20, 4);
// Print title
lcd.setCursor(0, 0);
lcd.print("Resistivity Test");
// Print author
lcd.setCursor(0, 1);
lcd.print(" xxxx");
// Wait
delay(500);
// Print Status 1
lcd.setCursor(0, 2);
lcd.print("Booting...");
lcd.setCursor(0, 3);
// Wait
delay(500);
40
// Set default CS pin as output
pinMode(DefaultCS, OUTPUT);
// See if SD card is present and can be initialized
if (!SD.begin(DefaultCS)) {
lcd.print("Card failed"); // Print Error 1
return; // Exit void setup
}
// See if file can be written/opened
File logFile = SD.open("LOG.csv", FILE_WRITE);
if (logFile) {
logFile.println(", ,"); // Write a leading blank line
String header = "I, V, R";
logFile.println(header); // Write header
logFile.close(); // and close file
lcd.print("File initialized..."); // Print Status 2
}
else {
lcd.print("File failed"); // Else, print Error 2
}
delay(1000);
}
//--------------------------------------------------------
// LOOP LOOP LOOP LOOP LOOP
//--------------------------------------------------------
// void loop, to run repeatedly:
void loop() {
// Clear screen
lcd.clear();
// Get current in mA from INA219 sensor
float current_mA = ina219.getCurrent_mA();
// Convert to SI unit
float current = (current_mA / 1000);
// Print current
lcd.setCursor(1, 0);
lcd.print("I= ");
lcd.print(current_mA,3);
lcd.print(" mAmps");
// Arduino senses voltage in 0-5V range
// A voltage divider creates an ouput voltage that is a fraction of the input
float Ra = 1000000; // input resistor value of voltage divider
float Rb = 100000; // output resistor value of voltage divider
float RR = (Rb/(Ra+Rb)); // voltage divider ratio
// Read analog value from sensor A0
int value0 = analogRead(A0);
// Calculate voltage sensed at output of voltage divider
float vraw = (value0*5.0/1024);
// Adjust voltage at input of voltage divider
float voltage = (vraw / RR);
// Print voltage
lcd.setCursor(1, 1);
lcd.print("V= ");
lcd.print(voltage,3);
lcd.print(" Volts");

I'm led to believe that I may have the wrong LCD Library or that the software needs to be rewritten , but I'm not sure what to do.

Where did you get the code from ?

It was from this article

KARST DETECTION USING LOW-COST

ELECTRICAL RESISTIVITY METER

by

Benjamin D. Goffin

Was there any indication of which LCD library was used ?

It listed this the following items

Elegoo Uno R3 board
LCD 4x20 + I2C module
SD card module
INA219 current sensor

No mention of the library in that list

Look at the LCD examples for the library that you have installed and compare them with the code that you have. You will need to make changes in the declaration of the LCD object but the functions that control printing to the LCD will be the same

OK I'll take a look at them. Thank you

There is NO way ANY I2C LCD library constructor needs so many arguments...

As I've said I'm a complete NOOB. I have spent the last 3 hours trying every LCD interface, but to no avail.
Giving up now

It's up to you, but we'll stick with it if you will. Next step has to be you providing a clear photo of your setup, though, because we'll glean a lot of info from that.

I'm hoping the batteries in that drawing are only representative, but we can talk about that later if they are, as long as they're fresh. The one powering the Arduino could well be dead by now.

Start with just the LCD connected - disconnect the SDA and SCL lines from the other device.
In the IDE, open File|Examples|Wire|i2c_scanner.
Power your circuit, open Serial Monitor, and compile and run this sketch. What does it say, when complete? If it found the LCD, it should tell you what address it is at.

Hi I've finally got it working. I downloaded a library called NewLiquidCrystal_lib.zip. In it are various .h files. I selected LiquidCrystal_I2C and it worked.

I will try as you suggested to find the address and report back tomorrow. By the way the batteries are fresh. I'm aware they won't last long.

Thank you

1 Like

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