i have 2 mega 2560's and i cannot get the pullups to work
ive tried making them inputs or not declaring that because they default to inputs
im using arduino 1.0 and havent updated it but pullups work on my unos and custom 328 boards
something like this
pinMode(30, INPUT);
digitalWrite(30, HIGH);
and just
digitalWrite(30, HIGH);
both of these methods work on an uno??
check arduino website and it says the 2560 has pullups
ive used both methods of setting the pullups with the same result
and i have pushbuttons connected to digital pins and then to ground
the program reads the push when the line is low
they go whack without external pullups. on my unos it works just fine everytime.
i tried this on 3 different megas
i am upping this because i have the exact same problem.
for some reason, i need to write a polling driver for a keyboard. It is a 4x4 kb, i have x1.. x4 connected to pins 32, 34,36,38; and y1..y4 connected to pins 40,42,44,46.
pins are configured with Ys as output, Xs as input with pullups.
Algorithm is pretty simple, basically when i set a Y pin to LOW, if any touch is pressed, an X pin will be set to LOW state; otherwise it will read HIGH.
Problem: it reads garbage whenever i touch the pins with my finger, or when i just move the keyboard, meaning the pullups are not activated.
I am using arduino 1.5.4, if that matters. If anyone has an idea, i am listening.
I tried to narrow it down in a separate file,so i am only using 1 output line instead of 4.
Keyboard is using a 1x8 header, connected on pins 32/34/36/38/40/42/44/46. the first 4 are the output of the KB (ie the inputs of the arduino), the next 4 are the input of the KB (ie the outputs of the arduino).
The board has an ethernet shield, not used in this example.
//this definition is for a 1x8 header
int kbLigne[4] = {32, 34, 36, 38};
int kbColonne[4] = {40, 42, 44, 46};
int previousKbState[4];
int currentKbState[4];
void initKb(void)
{
int j= 0;
for (j= 0; j< 4; j++)
{
previousKbState[j]= HIGH;
currentKbState[j] = HIGH;
}
}
void setup() {
// put your setup code here, to run once:
//keyboard
int i= 0;
for (i=0; i< 4; i++);
{
pinMode(kbLigne[i], INPUT_PULLUP); // first method, doest not work
// pinMode(kbLigne[i], INPUT); // second method to set pullups
// digitalWrite(kbLigne[i],HIGH); // does not work either
pinMode(kbColonne[i], OUTPUT);
}
initKb();
Serial.begin(19200);
}
void loop() {
// put your main code here, to run repeatedly:
int i = 0;
int j = 0;
boolean changed = false;
uint8_t temp;
digitalWrite(kbColonne[0],LOW); // in that state, any kbLigne should be at HIGH with the pullups, and at LOW when a touch is pressed
delay(2); // time seen with the scope to get a clean change
for (j=0; j <4; j++)
{
temp =digitalRead(kbLigne[j]); //read each ligne
currentKbState[j] = temp; // store it
if (currentKbState[j] != previousKbState[j] ) // compare with previous state. If changed, write it on serial.
{
Serial.print("Changed at line ");
Serial.print(j);
Serial.print(" new value is: ");
Serial.println(currentKbState[j]);
}
previousKbState[j] = currentKbState[j]; // set the state for the next cycle
}
}
If i just approach my hand near the keyboard, the whole thing goes berserk, which usually means pullups arent working.
I am more and more thinking the problem comes from the keyboard ... i tried removing it. Now i need to touch the arduino input pins with my finger to make it go awol (it shows changes all the time on the only pin i touch though, which is already better)
But wouldnt that mean the pullups are not working either ?
edit: same thing happens with the ethernet shield removed.
edit2: ok found it. Actually someone else just stared at my code and said "you have a ';' after your for in the setup()" .
int i= 0;
for (i=0; i< 4; i++);
{
pinMode(kbLigne[i], INPUT_PULLUP);// this is wrong, but will compile
}
After you've given yourself a slap, please get in the habit of declaring loop variables inside the loop. This makes it harder to misuse them outside the loop:
for (int i=0; i< 4; i++);
{
pinMode(kbLigne[i], INPUT_PULLUP);// this is wrong, and does not compile
}