Go Down

Topic: What did I do wrong? (Read 574 times) previous topic - next topic

magnethead794

Jan 05, 2012, 11:30 am Last Edit: Jan 05, 2012, 11:46 am by magnethead794 Reason: 1
It gets through the setup fine, but thinks all inputs are low, resulting in 0000 on serial display and x000 on main display.

Switches are binary coded decimal. IE 10 position, with binary (1, 2, 4, 8) output. Mega pins are written high and connected to binary pins, switch commons are all grounded. Selected binaries should be grounded, unselected should be high.

When I unplug the switches, no change, even with pins left open-ended (and thus high).

Changing state of 'text' pin doesn't affect anything either. If it thought all inputs are low, it should blank the display...and I confirmed it pulled down to zero volts via multimeter.

http://www.youtube.com/watch?v=eKohYv7wGHo

http://www.magnethead494.com/upload/dial_board.pde (my forum upload folder is full apparently)

KF5RVR

AWOL

What is the smallest sketch that exhibits this problem?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

magnethead794

#2
Jan 05, 2012, 11:47 am Last Edit: Jan 05, 2012, 11:50 am by magnethead794 Reason: 1
I've not tried a smaller sketch yet.

digit1 common has 30 millivolts
digit2 common has 4.995 volts
digit3 common has 4.996 volts
digit4 common has 4.995 volts

digit 1_1, 1_2, 1_4, is low (30mV) (10, 11, 12)
digit 1_8 is high (4.996 volts)

digit1 is a 7

all 4 positions of digit2 are high
all 4 positions of digit3 are high
all 4 positions of digit 4 are high

It mystifies me that digit1 common is low, yet others are high...they are all jumpered off eachother and off of the GND pole of the serial display. But I'm seeing 30mV at the ground connection for the controller and at the ground pole of the serial display....
KF5RVR

Grumpy_Mike

Quote
digit1 common is low, yet others are high...they are all jumpered off eachother

So you mean you connect all the lines together and only one is low and the others are high.

If so then you haven't connected all the lines together.

Quote
I'm seeing 30mV at the ground connection

This is common for an output to be not quite zero.

You need to learn how to write code using loops. What you have posted is what I call write only code. (That is it is almost impossible to read) Comments in code are good as well.

magnethead794

#4
Jan 05, 2012, 12:06 pm Last Edit: Jan 05, 2012, 12:11 pm by magnethead794 Reason: 1
Linear code is easier for me to read and write quickly

They are all connected together I promise you...each one has 2 pins, one from prior and 1 to the next one. zero resistance.

digit1 common in is from mega ground, common out is to...okay AWOL, you got me. I missed a connection. Still doesn't explain why CPU thought the inputs were low..
KF5RVR

magnethead794

#5
Jan 05, 2012, 12:36 pm Last Edit: Jan 05, 2012, 12:51 pm by magnethead794 Reason: 1
alright, fixed connections, now I'm getting something...kinda.

in text mode, I'm getting "nt", "fast" (but it keeps bouncing to Ftnt by wiggling the switch), fast solid (even with wiggling), "cya", "bye", and back to nt.

in numbers mode, I'm getting
digit1: 4 (changed to 6 on wiggle), 7, 8, 9, and back to 7.
digit2: 6, 7, 8, 9
digit3: 4, 7, 8, 9
digit4: 6, 7, 8, 9

fast: position 4 (4)
ftnt: position 6 (2, 4) (wiggle means 2 is loose?)
nt: position 7 (1, 2, 4)
bye: position 8 (8)
cya: position 9 (1,8)

4: (4)
6: (2,4) (wiggle means 2 is loose?)
7: (1,2,4)
8: (8)
9: (1,8)

if 1, 2, and 4 work to make 7, why am I not getting 0-3 and 5?

Checking each digit (0 is known up)

digit1: I'm getting 7 in place of 5, 4 and 6 are switching...I'm thinking 2 is shorting to 4. Any non-working digit (0-3, 5) it displays last working number in one direction. In opposite direction shows an 8

digit2: same as digit1

digit3: getting 8 and 9 mixed, 4 in place of 6

digit4: 7 in place of 5, ect...
KF5RVR

Grumpy_Mike

Quote
Linear code is easier for me to read and write quickly

Yes you write it quickly and you don't think about what you are writing and you can't read what you have written and so you have problems. You post the code and people take one look at it and give up thinking this guy will never learn anything.
Just as an exercise I wrote your setup code a lot shorter, it is here:-

Code: [Select]
int segmenta[] = {52,  36, 35, 51};
int segmentb[] = {50, 34, 33, 49};
int segmentc[] = {48, 32, 31, 47};
int segmentd[] = {46, 30, 29, 45};
int segmente[] = {44, 28, 27, 43};
int segmentf[] = {42, 26, 25, 41};
int segmentg[] = {40, 24, 23, 39};
int segment[7][4] = {52,  36, 35, 51, 
                     50, 34, 33, 49, 
                     48, 32, 31, 47,
                     46, 30, 29, 45,
                     44, 28, 27, 43,
                     42, 26, 25, 41,
                     40, 24, 23, 39 };
                 

char digit1, digit2, digit3, digit4;

void setup(){
 
  Serial3.begin(9600);
  Serial3.print('v');
 
for(int i = 5; i<13; i++){ 
    pinMode(i, INPUT);
    digitalWrite(i, HIGH);
}
for(int i = 22; i<54; i++){
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
}

for(int i = A0; i<=A9; i++){
   pinMode(i, INPUT);
   digitalWrite(i, HIGH);
}   
   
   
    for (int j=0;j<4;j++){
     for(int i=0; i<7; i++){
        digitalWrite(segment[i][j],HIGH);
        delay(50);
        digitalWrite(segment[i][j], LOW);
        }
     }
}

Not tested because I haven't got your hardware but it compiles.

Quote
They are all connected together I promise you

Quote
alright, fixed connections

So what was wrong and why did you not see it the first time. This will be really good information to have to add to the bank of things to tell people to try.

Dose wiggle mean you have to wiggle the wires?

magnethead794

#7
Jan 05, 2012, 01:07 pm Last Edit: Jan 05, 2012, 01:13 pm by magnethead794 Reason: 1

Quote
Linear code is easier for me to read and write quickly

Yes you write it quickly and you don't think about what you are writing and you can't read what you have written and so you have problems. You post the code and people take one look at it and give up thinking this guy will never learn anything.
Just as an exercise I wrote your setup code a lot shorter, it is here:-

Code: [Select]
int segmenta[] = {52,  36, 35, 51};
int segmentb[] = {50, 34, 33, 49};
int segmentc[] = {48, 32, 31, 47};
int segmentd[] = {46, 30, 29, 45};
int segmente[] = {44, 28, 27, 43};
int segmentf[] = {42, 26, 25, 41};
int segmentg[] = {40, 24, 23, 39};
int segment[7][4] = {52,  36, 35, 51,  
                    50, 34, 33, 49,  
                    48, 32, 31, 47,
                    46, 30, 29, 45,
                    44, 28, 27, 43,
                    42, 26, 25, 41,
                    40, 24, 23, 39 };
                 

char digit1, digit2, digit3, digit4;

void setup(){
 
 Serial3.begin(9600);
 Serial3.print('v');
 
for(int i = 5; i<13; i++){  
   pinMode(i, INPUT);
   digitalWrite(i, HIGH);
}
for(int i = 22; i<54; i++){
   pinMode(i, OUTPUT);
   digitalWrite(i, LOW);
}

for(int i = A0; i<=A9; i++){
  pinMode(i, INPUT);
  digitalWrite(i, HIGH);
}  
   
   
   for (int j=0;j<4;j++){
    for(int i=0; i<7; i++){
       digitalWrite(segment[i][j],HIGH);
       delay(50);
       digitalWrite(segment[i][j], LOW);
       }
    }
}

Not tested because I haven't got your hardware but it compiles.

Quote
They are all connected together I promise you

Quote
alright, fixed connections

So what was wrong and why did you not see it the first time. This will be really good information to have to add to the bank of things to tell people to try.

Dose wiggle mean you have to wiggle the wires?


I had missed a jumper from switch 1 to switch 2. simple mistake. wiggle = wiggle switch

I'm checking with multimeter right now. I'm using flat facing up as a reference and turning clockwise (CCW as i see it, since I have it upside down). I'm measuring right at the breadboard the switches are on.
patterns should be 8421

digit4:
up: HLHL (should be 5)
pos1: HLLH displays 9 (should be 6)
pos2: HLLL displays 8 (should be 7)
pos3: LHHH displays 7 (should be 8)
pos4: LHHL displays 6 (should be 9)
pos5: HHHH displays 7 (should be zero)
pos6: HHHL displays 7 (should be 1)
pos7: HHLH displays 7 (should be 2)
pos8: HHLL displays 7 (should be 3)
pos9: HLHH displays 8 (should be 4)

based on that one digit alone, I need to re-check my algorithm methinks..

Also, that setup reduction is why you're the professor & I'm the pupil....
KF5RVR

Grumpy_Mike

Have you noticed:-
Quote
pos1: HLLH displays 9 (should be 6)

9 in binary is 1001
6 in binary is 0110
And so on for the other numbers, you have the input sense the wrong way round.

magnethead794

#9
Jan 05, 2012, 01:15 pm Last Edit: Jan 05, 2012, 01:34 pm by magnethead794 Reason: 1
I was right about to say. I inverted my binaries!

Is there a way to simply the compound if statements using arrays? Not that it mattered for fixing this, find/replace does wonders...(which tells me I see a loop getting thrown at me soon)

Now everything works except ones, numerically.

But one works for text. Wierd.

nevermind. doesn't do much to do a digitalRead(digitalRead(digx_1)) ...
KF5RVR

Grumpy_Mike

Quote
Is there a way to simply the compound if statements

Yes.
As a first step get all the HIGHs / LOWs from each of the inputs and put them in a different bit of a single byte.
Then you simply use a comparison in the if statement to a number.
Code: [Select]
myVal = digitalRead(dig1_1)) | (digitalRead(dig1_2)<<1) | (digitalRead(dig1_4)<<2) | (digitalRead(dig1_8)<<3);
if(myVal == 1) { // do what you want for one


It will simplify even further by making the dig1_1 value into an array and reading all the switches in a simple loop.

AWOL

#11
Jan 05, 2012, 02:50 pm Last Edit: Jan 05, 2012, 03:22 pm by AWOL Reason: 1
Quote
Linear code is easier for me to read and write quickly

It is also a greater disincentive for others to help out - ever heard the figure of speech "finding a needle in a haystack"?

Have you noticed how getDig1, getDig2, getDig3 and getDig4 are spookily similar?
Your sketch is over 1000 lines long, but I'd be surprised if it needed to be one fifth that long.

Code: [Select]
        char theDisplay = digit1+digit2+digit3+digit4; //Concatenate into a 4 byte code
Maybe spend longer debugging the debug code.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

magnethead794

I got it all working. Just installed in the car (it's for our racecar).

By posting on facebook, 2 people have asked me to built them units.

What I'll be doing on revision2, is putting a Mini in the controller box, and running serial to the mega. But that's a topic reserved for the programming sector.
KF5RVR

Go Up