eror when adding expression_parser library

Hi everyone.
I downloaded a expression-parser library from the listed site :

After that, I open Arduino, click Stretch ---> Include Library ---> Add ZIP Library..
And this is the eror :
Specified folder/zip file does not contain a valid library.
Please help me.
Can anyone show me the right expression-parser library.
Thank you.

Is it an Arduino library containing at least .h and .cpp files of the same name ?

Sketch > Include Library > Add ZIP Library… requires that the library be located in the root of the repository. But in this case it’s in the code subfolder of the repository so you can’t install directly from the .zip file.

In addition, the example.c and example.cpp source files that are in that folder will cause major problems.

Here’s how to install it:

  • Download the repository: https://github.com/jamesgregson/expression_parser/archive/master.zip
  • Unzip the downloaded file.
  • Delete expression_parser-master/code/example.c, expression_parser-master/code/example.cpp, and expression_parser-master/code/test.c
  • (In the Arduino IDE) Sketch > Include Library > Add ZIP Library… > Select expression_parser-master/code > Open.

It’s not obvious from the menu name, but Add ZIP Library can be used to install libraries from folders in addition to .zip files.

This code does not appear to have been written with Arduino in mind so I don’t know whether it will work for you, but certainly worth a try.

UKHeliBob:
Is it an Arduino library containing at least .h and .cpp files of the same name ?

oh.
there are example.cpp and expression_parser.c
so i have to rename them.

FriendlY:
there are example.cpp and expression_parser.c
so i have to rename them.

No. You have to delete example.cpp. That is a complete program which defines a main() function. The main() in that file will override the main() function in the Arduino core library which calls the setup() and loop() functions in your sketch. So if you leave example.cpp in the library it will cause your sketch code to not run.

You don't need to rename expression_parser.c. However, you should be aware that Arduino sketches are C++ and the .c extension on that file will cause it to be compiled as C code.

I also just noticed the test.c file. You need to delete that file before you install the library for the same reason that you need to delete the example.cpp file.

pert:
Sketch > Include Library > Add ZIP Library.. requires that the library be located in the root of the repository. But in this case it's in the code subfolder of the repository so you can't install directly from the .zip file.

In addition, the example.c and example.cpp source files that are in that folder will cause major problems.

Here's how to install it:

It's not obvious from the menu name, but Add ZIP Library can be used to install libraries from folders in addition to .zip files.

This code does not appear to have been written with Arduino in mind so I don't know whether it will work for you, but certainly worth a try.

thanks a lot.
it works but error again.
ERROR : Not enough memory.
I am Newbie.
So hard.

pert:
No. You have to delete example.cpp. That is a complete program which defines a main() function. The main() in that file will override the main() function in the Arduino core library which calls the setup() and loop() functions in your sketch. So if you leave example.cpp in the library it will cause your sketch code to not run.

You don't need to rename expression_parser.c. However, you should be aware that Arduino sketches are C++ and the .c extension on that file will cause it to be compiled as C code.

I also just noticed the test.c file. You need to delete that file before you install the library for the same reason that you need to delete the example.cpp file.

thank you for helping.
I am just a newbie.
I cant understand that.
But thank you very much.

Maybe you should start by telling us what you're trying to accomplish.

Hi eveyone.
I copy code form the internet.
I run it and there is an error: Not enough memory.
So how can I reduce the size of my sketch?
P.s:
I use Board Arduino Uno R3.
The code i copy use for another board
but i see 2 board use the same microcontroller: ATmega328P.
Please help me.
I search everything in the internet but can find the solution.

sketch_oct09a.ino (2.11 KB)

Post your code using Code Tags as described here: Read this before posting a programming question
Pay particular attention to Item #6.

FriendlY's previous thread on this topic:

Post a link to where you got the Keypad and LiquidCrystal_I2C libraries from. Please use the chain links icon on the toolbar to make it clickable. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

Hi,
What Arduino board was it originally written for?

Tom.. :slight_smile:

Hi everyone.
I am making a simple calculator. It only has +, -, x and /.
I use board Arduino Uno, LCD with I2C module, and keypad 4x4.
I use 3 libraries that download from the internet:

  1. This is for LCD with I2C module:
    https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
  2. This is for keypad 4x4:
    https://github.com/Chris--A/Keypad
  3. https://github.com/jamesgregson/expression_parser
    My code:
#include "expression_parser.h"
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x3F, 16, 2);
// Khai báo ma trận bàn phím
const byte ROWS = 4; //4 dòng
const byte COLS = 4; //4 cột

char keys[ROWS][COLS] = {
  {'1', '2', '3', '+'},
  {'4', '5', '6', '-'},
  {'7', '8', '9', '*'},
  {'.', '0', '=', '/'}
};

 
byte rowPins[ROWS] = {10, 9, 8, 7}; 
byte colPins[COLS] = {6, 5, 4, 3}; 


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

String s = "";  
char ex[16];

void setup() 
{
  Serial.begin(9600);
  lcd.init();          
  lcd.backlight();      
  lcd.setCursor(0, 0);  
}

int cur = 0;
bool enter = false;

void loop() {
  char key = keypad.getKey();   
  // Kiểm tra nêu phím đã được nhấn.
  if ((key != '=') && (key != NO_KEY) ) {
    if (!enter) {               
      Serial.println(key);
      if(key=='/')
        lcd.print(':');
      else 
      if (key=='*')
        lcd.print('x');
      else
        lcd.print(key);
      s = s + key;             
      cur++;                    
      lcd.setCursor(cur, 0);    
    } else {                    
      
      lcd.setCursor(0, 0);      
      lcd.print("");
      enter = false;
      lcd.setCursor(0, 0);
      cur = 0;
      lcd.print(key);
      s = "";
      s = s + key;
      cur++;
      lcd.setCursor(cur, 0);
    }
  } else if (key == '=') {    
    enter = true;
    // Kiểm tra nhập sai
    if ((s[0] == '=') || (s[0] == '/') || (s[0] == '*') || (s[0] == '.')) {
      lcd.setCursor(0, 1);
      lcd.print("Error");
    } else {
      lcd.setCursor(0, 1);
      lcd.print("");
      s.toCharArray(ex, 16);
      Serial.println(s);
      double re = parse_expression(ex); 
      String check = String(re);
      if (check.length() > 15) {
        lcd.setCursor(0, 1);
        lcd.print("Overflow");
      } else {
        Serial.println(re);
        lcd.setCursor(0, 1);
        lcd.print("=");
        lcd.print(re);                
      }
    }
  }
}

I run it and got error:

Sketch uses 27124 bytes (84%) of program storage space. Maximum is 32256 bytes.
Global variables use 3302 bytes (161%) of dynamic memory, leaving -1254 bytes for local variables. Maximum is 2048 bytes.
Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint.

Please help me.
Thank you so much.

I just copied and pasted your code. No changes except: commenting out expression_parser.h as I don’t have that library, and the line in loop() that uses it, replacing it with an arbitrary number.

//#include "expression_parser.h"
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x3F, 16, 2);
// Khai báo ma trận bàn phím
const byte ROWS = 4; //4 dòng
const byte COLS = 4; //4 cột

char keys[ROWS][COLS] =
{
    {'1', '2', '3', '+'},
    {'4', '5', '6', '-'},
    {'7', '8', '9', '*'},
    {'.', '0', '=', '/'}
};


byte rowPins[ROWS] = {10, 9, 8, 7};
byte colPins[COLS] = {6, 5, 4, 3};


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

String s = "";
char ex[16];

void setup()
{
    Serial.begin(9600);
    lcd.init();
    lcd.backlight();
    lcd.setCursor(0, 0);
}

int cur = 0;
bool enter = false;

void loop() {
    char key = keypad.getKey();
    // Kiểm tra nêu phím đã được nhấn.
    if ((key != '=') && (key != NO_KEY) )
    {
        if (!enter)
        {
            Serial.println(key);
            if (key == '/')
                lcd.print(':');
            else if (key == '*')
                lcd.print('x');
            else
                lcd.print(key);
            s = s + key;
            cur++;
            lcd.setCursor(cur, 0);
        }
        else
        {

            lcd.setCursor(0, 0);
            lcd.print("");
            enter = false;
            lcd.setCursor(0, 0);
            cur = 0;
            lcd.print(key);
            s = "";
            s = s + key;
            cur++;
            lcd.setCursor(cur, 0);
        }
    }
    else if (key == '=')
    {
        enter = true;
        // Kiểm tra nhập sai
        if ((s[0] == '=') || (s[0] == '/') || (s[0] == '*') || (s[0] == '.'))
        {
            lcd.setCursor(0, 1);
            lcd.print("Error");
        }
        else
        {
            lcd.setCursor(0, 1);
            lcd.print("");
            s.toCharArray(ex, 16);
            Serial.println(s);
            
            //double re = parse_expression(ex);
            double re = 12234;
            String check = String(re);
            if (check.length() > 15)
            {
                lcd.setCursor(0, 1);
                lcd.print("Overflow");
            }
            else
            {
                Serial.println(re);
                lcd.setCursor(0, 1);
                lcd.print("=");
                lcd.print(re);
            }
            
        }
    }
}

Sketch uses 10398 bytes (32%) of program storage space. Maximum is 32256 bytes.
Global variables use 595 bytes (29%) of dynamic memory, leaving 1453 bytes for local variables. Maximum is 2048 bytes.

At a guess it is the expression parser library that is causing the problem. Was it actually intended for use with an Arduino I wonder ?

What can you do about it ?
Use an Arduino such as a Mega that has more memory would be one thing.

The expression parser is not designed to be used on an Arduino. It includes many constant strings without using the F() macro to move them to the flash memory. That's one problem, the other is the use of the String class, try to eliminate it as it wastes memory.

pylon:
The expression parser is not designed to be used on an Arduino. It includes many constant strings without using the F() macro to move them to the flash memory. That's one problem, the other is the use of the String class, try to eliminate it as it wastes memory.

I'll say. Just added the library and got over a zillion errors. Find another way to do that. You only use it once to perform the same function essentially as atoi().

DON'T CROSS POST!!!!!!!!!!!!!!!!!!!!

I HAVE REPORTED THIS THREAD TO THE MODERATORS

Duplicate posts waste the time of the people helping you. I might spend 15 minutes writing a detailed answer on this thread, without knowing that someone already did the same in the other thread. This behavior is very disrespectful to the people you're asking for assistance. Just because we give our time freely doesn't mean it has no value.

In the future, take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, which you would already know if you had bothered reading the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

Threads merged.