Pages: 1 [2] 3   Go Down
Author Topic: SOLVED: Getting Error:- 'INPUT_PULLUP' was not declared in this scope  (Read 4322 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Somewhere outside of those snippets, out must be declared. The changes in those snippets look a lot more useful than redefining INPUT_PULLUP to be equivalent to INPUT.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
TBH, do I need to do anything unless I actually add code, or use libraries that make use of the INPUT_PULLUP option.
No, you don't. I thought you were doing this because you did need INPUT_PULLUP supported.
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I solved the problem when I upgraded to arduino IDE 1.0.3 by just copying the two files Arduino.h and wiring_digital.c from the 1.0.3 core folder to replace the ones in my custom hardware core folder in my 644P add-on user hardware folder. Seems to work fine. By the way the IDE 1.0 had not yet added the INPUT_PULLUP option.

Lefty

Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your fix will work.

Code:
       if (mode == INPUT) {
uint8_t oldSREG = SREG;
                cli();
*reg &= ~bit;
*out &= ~bit;

I would comment out the last line. pinMode() should really be operating on just the DDRx.
Logged

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
TBH, do I need to do anything unless I actually add code, or use libraries that make use of the INPUT_PULLUP option.
No, you don't. I thought you were doing this because you did need INPUT_PULLUP supported.

No, it was because the sketch that used keypad.h wouldn't compile when I changed my board from Uno to 1284P.

The library itself was looking at Arduino version and expecting define of INPUT_PULLUP for IDE versions over 1.0.

I'm not using INPUT_PULLUP myself at all.

lefty, I might just try what you did and copy the cores across for my 1284P and 644P entries. I'll back up what I have first.
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6106
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"The only difference" is the line that turns on the internal pull-up.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm not using INPUT_PULLUP myself at all.

In that case, define it as "INPUT".
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
TBH, do I need to do anything unless I actually add code, or use libraries that make use of the INPUT_PULLUP option.
No, you don't. I thought you were doing this because you did need INPUT_PULLUP supported.

No, it was because the sketch that used keypad.h wouldn't compile when I changed my board from Uno to 1284P.

The library itself was looking at Arduino version and expecting define of INPUT_PULLUP for IDE versions over 1.0.

I'm not using INPUT_PULLUP myself at all.

lefty, I might just try what you did and copy the cores across for my 1284P and 644P entries. I'll back up what I have first.


I wasn't brave enough to copy the complete core files, just the two I mentioned as I think that is the only two files that are involved with the INPUT_PULLUP addition.

LEfty
Logged

Worst state in America
Offline Offline
God Member
*****
Karma: 32
Posts: 792
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


No, it was because the sketch that used keypad.h wouldn't compile when I changed my board from Uno to 1284P.

The library itself was looking at Arduino version and expecting define of INPUT_PULLUP for IDE versions over 1.0.

I'm not using INPUT_PULLUP myself at all.

lefty, I might just try what you did and copy the cores across for my 1284P and 644P entries. I'll back up what I have first.

I thought INPUT_PULLUP == 0x02, not 0x20????
Logged

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Phillipsburg, NJ
Offline Offline
Full Member
***
Karma: 6
Posts: 184
Author: Matrix Keypad Library
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It masks the problem, not solving the problem.
Actually, it should be a resonable fix in the case of the keypad library.  The offending lines in Keypad.cpp are:
Code:
// When sharing row pins with other hardware they may need to be re-intialized.
for (byte r=0; r<sizeKpd.rows; r++) {
pin_mode(rowPins[r],INPUT_PULLUP);
pin_write(rowPins[r],HIGH); // Enable internal pullup resistors for Arduino<101
}
I did this to maintain some sort of backwards compatibility but my error was in deciding to test for Arduino versions instead of the existence of INPUT_PULLUP.
Code:
// See http://code.google.com/p/arduino/issues/detail?id=246
#if defined(ARDUINO) && ARDUINO < 101
#define INPUT_PULLUP INPUT
#endif
Becomes...
Code:
// See http://code.google.com/p/arduino/issues/detail?id=246
#if !defined INPUT_PULLUP
#define INPUT_PULLUP INPUT
#endif
Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 63
Posts: 2639
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My suggestion would be to not depend on it and fix the code not to depend on using INPUT_PULLUP
or even use it all since it is only available on such a recent Arduino release and then only if
the core supports it.
There are many other cores, libraries, and IDEs for other processors (maple, chipkit) that
may not have this recent addition.
Also many linux environments, Debian Squeeze, Ubuntu 12.04, Linux Mint 13/14 all have
Arduino 1.0 in their repositories, so they will not have this support if using the Arduino IDE
in the repository.

Assuming you are using this code: http://arduino.cc/playground/uploads/Code/keypad.zip
It looks like it already checks for the arduino revision and maps INPUT_PULLUP to INPUT
on older arduino versions. However, the problem with that is that while the Arduino IDE version may be 103
not all the cores being used have all the support in 103.
This is a great example of one of the many flaws in the Arduino build methodology.
The Arduino version reflects the version of the IDE and not really the version of the underlying core
being used.
Libraries often need to know more than just the IDE revision.
This problem is only going to get worse as other processor are introduced and the cores
start to differ in revision and functionality.

What is odd is that keypad code is already is setting the pullups by writing to the port after setting the port to input mode.
It seems crazy to be using the INPUT_PULLUP mode at all since it just adding to the confusion and is not needed.

I'd go in and rip out the all the INPUT_PULLUP stuff since it simply is not needed.



The saddest part of all this was that many people including the Arduino team fought adding this mode in literally for years.
(Teensy had it but it was rejected for main line arduino)

And while the Arduino team added stuff that literally broke 100% of all the existing libraries when going
from the beta release candidate to the 1.0 release, this useful simple addition still wasn't accepted and didn't make
it in to 1.0

The crazy part now is that because this is such a new feature that wasn't in 1.0,
library writers really can't depend on it being there and the other non AVR parts now have to have special code to emulate
the AVR way of turning on pullups by looking for writes to a port that is input mode to support all the existing
code that turns on pullups without using INPUT_PULLUP.
This slows things down for the non AVR processors.

--- bill
Logged

Phillipsburg, NJ
Offline Offline
Full Member
***
Karma: 6
Posts: 184
Author: Matrix Keypad Library
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It seems crazy to be using the INPUT_PULLUP mode at all since it just adding to the confusion and is not needed.
This is a very compelling argument. It seems that I was trying to fix a problem that didn't exist.

Quote
I'd go in and rip out the all the INPUT_PULLUP stuff since it simply is not needed.
I'm going to do this. I'm debugging a problem with the library right now and when I am finished I will also update the library with the INPUT_PULLUP stuff removed.

Thanks bperrybap
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This is a very compelling argument. It seems that I was trying to fix a problem that didn't exist.

I think the often used expression is "a solution looking for a problem" applies. Not unlike the new Serial.flush command that is so popular with beginner programmers.  smiley-wink

Lefty
Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 63
Posts: 2639
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This is a very compelling argument. It seems that I was trying to fix a problem that didn't exist.

I think the often used expression is "a solution looking for a problem" applies. Not unlike the new Serial.flush command that is so popular with beginner programmers.  smiley-wink

Lefty
Actually I think the INPUT_PULLUP is a very good thing and it does solve real-world problems.
In fact, I wish it had been accepted by the Arduino team sooner.
Without it, code that needs pullups enabled, is having to step outside Arduino and do AVR register specific operations
which makes the code non portable to other processors.
It always struck me as odd that the point of Arduino was to try to abstract the hardware away from the sketch
and yet turning on the pullup without something like INPUT_PULLUP is not supported by Arduino
and therefore becomes a processor specific non portable operation that is outside the
scope of Arduino.
Not sure why the Arduino team never saw it that way.

The real problem is it wasn't accepted as a solution to a real problem and implemented soon
enough in the mainline arduino core code so it didn't make it into the flagship 1.0 release
(It was added in 1.0.1 )

It has now now created a difficult backward compatibility issue
for porting existing arduino code that runs on AVR to non AVR like ARM and PIC.
The non AVR processor core code writers have two choices.
- Emulate the AVR pullup enable capability in s/w as well as support INPUT_PULLUP
- Only support the new INPUT_PULLUP and break any code using the AVR specific
pullup enable method which is what all AVR Arduino code did prior to INPUT_PULLUP

The issue with emulating the AVR pullup enables in s/w is that it slows down the digital write code
by having to look to see if it is a write to an input pin vs just being able to write directly to the hardware.
It is really sad because other processor like the ARM and PIC have better i/o capabilities than
the AVR yet they can't be fully utilized when s/w has to do this AVR emulation.

From a library portability standpoint, the ideal solution would be to use ifdefs so
the code would use INPUT_PULLUP if it exists and not do the extra write to the input pin.
If it doesn't exist, assume AVR or AVR emulation is
available and drop back to INPUT and do the AVR specific method of writing to the input pin
to turn on the pullup.
It's a bit ugly but it would then be fully compatible with pretty much anything out there.

As and alternative,
you could actually hide it pretty well by playing a few games with macros.
i.e

Code:
#ifndef INPUT_PULLUP
#warning "Using  pinMode() INPUT_PULLUP AVR emulation"
#define INPUT_PULLUP 0x2
#define pinMode(_pin, _mode) _mypinMode(_pin, _mode)
#define _mypinMode(_pin, _mode) \
do                             \
{                              \
 pinMode(_pin, INPUT);         \
 if(_mode == INPUT_PULLUP)     \
   digitalWrite(_pin, 1);       \
}while(0)
#endif

This allows code to always pinMode() with INPUT_PULLUP regardless of whether the
core code supports it.

The tricky part with the keypad library is that the pin mode is done through a virtual function which
can be remapped.
If the virtual function may need to know if the pin is INPUT or INPUT_PULLUP.
Using the above macros may be a better solution than simply eliminating the INPUT_PULLUP
because the virtual function can now receive a 2 (INPUT_PULLUP) rather than a INPUT which
is currently defined as 0
Just keep in mind that to do this, the code implementing the virtual function would also need
to have something like the above macros to ensure the INPUT_PULLUP is defined to the same value in
pre 1.0.1 environments.



--- bill
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It always struck me as odd that the point of Arduino was to try to abstract the hardware away from the sketch
and yet turning on the pullup without something like INPUT_PULLUP is not supported by Arduino
and therefore becomes a processor specific non portable operation that is outside the
scope of Arduino.
Not sure why the Arduino team never saw it that way.

Prior to the INPUT_PULLUP change the method shown for arduino users to enable the internal pull-up resistor on a pin was with a two command sequence:

pinMode(pin#,INPUT);
digitalWrite(pin#,HIGH);

How was that "not supported by Arduino and therefore becomes a processor specific non portable operation that is outside the scope of Arduino." ?

Lefty
Logged

Pages: 1 [2] 3   Go Up
Jump to: