Pages: [1]   Go Down
Author Topic: What did I do wrong?  (Read 527 times)
0 Members and 1 Guest are viewing this topic.
Ft. Worth, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 591
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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, smiley-cool 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.magnethead494.com/upload/dial_board.pde (my forum upload folder is full apparently)

« Last Edit: January 05, 2012, 05:46:58 am by magnethead794 » Logged

KF5RVR

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26514
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is the smallest sketch that exhibits this problem?
Logged

"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.

Ft. Worth, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 591
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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....
« Last Edit: January 05, 2012, 05:50:27 am by magnethead794 » Logged

KF5RVR

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 637
Posts: 34579
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Ft. Worth, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 591
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..
« Last Edit: January 05, 2012, 06:11:09 am by magnethead794 » Logged

KF5RVR

Ft. Worth, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 591
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
« Last Edit: January 05, 2012, 06:51:06 am by magnethead794 » Logged

KF5RVR

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 637
Posts: 34579
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
Logged

Ft. Worth, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 591
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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 smiley-cool
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....
« Last Edit: January 05, 2012, 07:13:13 am by magnethead794 » Logged

KF5RVR

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 637
Posts: 34579
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Ft. Worth, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 591
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)) ...
« Last Edit: January 05, 2012, 07:34:23 am by magnethead794 » Logged

KF5RVR

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 637
Posts: 34579
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26514
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
        char theDisplay = digit1+digit2+digit3+digit4; //Concatenate into a 4 byte code
Maybe spend longer debugging the debug code.
« Last Edit: January 05, 2012, 09:22:58 am by AWOL » Logged

"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.

Ft. Worth, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 591
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

KF5RVR

Pages: [1]   Go Up
Jump to: