Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Switching Led

Status
Not open for further replies.
Thought I would post the modified sketch I have been playing around with for the BCD switch.
Not sure what to do from here though at this moment?

The output is still inverted!

/*Willeng
20/9/2014
Modified Sketch
BCD TEST?
*/
const byte BCDpin1 = 2;
const byte BCDpin2 = 3;
const byte BCDpin4 = 4;
const byte BCDpin8 = 5;
void setup()
{ Serial.begin(9600);
pinMode(BCDpin1, INPUT_PULLUP);
pinMode(BCDpin2, INPUT_PULLUP);
pinMode(BCDpin4, INPUT_PULLUP);
pinMode(BCDpin8, INPUT_PULLUP);

}
void loop() {
// read
unsigned int val_BCDpin1 = digitalRead(BCDpin1);
unsigned int val_BCDpin2 = digitalRead(BCDpin2);
unsigned int val_BCDpin4 = digitalRead(BCDpin4);
unsigned int val_BCDpin8 = digitalRead(BCDpin8);

int switchNo = 0; //reset

if ( val_BCDpin1 == 0) { switchNo = switchNo + 1; }
if ( val_BCDpin2 == 0) { switchNo = switchNo + 2; }
if ( val_BCDpin4 == 0) { switchNo = switchNo + 4; }
if ( val_BCDpin8 == 0) { switchNo = switchNo + 8; }

{
Serial.print("[BIT8: ");
Serial.print(val_BCDpin8);
Serial.print("] ");
Serial.print("[BIT4: ");
Serial.print(val_BCDpin4);
Serial.print("] ");
Serial.print("[BIT2: ");
Serial.print(val_BCDpin2);
Serial.print("] ");
Serial.print("[BIT1: ");
Serial.print(val_BCDpin1);
Serial.print("] ");
Serial.print("[switchNo: ");
Serial.print(switchNo);
Serial.println("] ");}

delay(3000);
}
 
Willeng:

You should be able to replace all of these switchNo = switchNo + 1 type expressions with corresponding lines similar to: switchNo = switchNo && 1; etc,

After this if ( val_BCDpin8 == 0) { switchNo = switchNo + 8; } line add
switchNo = !switchNo or this line switchNo = !switchNo; wwhatever works. Not sure if the space is required.

ULN2003-pinout.jpg


Take the ULn2003, shown above and connect pin 8 to ground. Leave #9 disconnected.
Take pin 10 and connect it to common of the BCD switch your currently using and remove the ground that's currently connected there.

With pin 7 open, you should read all 1's with your program and 15 with the modified program.
Connect pin #7 to +5 and you should get the same BCD results that you had. 0-9 with the modified code.

With this chip, you can float the inputs with no damage and the floated inputs will be interpreted as a LOGIC 0.

==

The next step is to tie pin 7 to an output port.

==

Then think about if you need to "conserve bits".


==
Notes:
DS 2560, #219
Pressure sensor datasheet: MPX2010DP
 
Last edited:
To save bits, you would have to find a chip like the 74HC251 or similar https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCMQFjAA&url=https://www.onsemi.com/pub/Collateral/MC74HC251A-D.PDF&ei=ZckcVI2wIc-iyASL-YLQAg&usg=AFQjCNEiUyYnIP1CzzoJrTVs18uCGSXjjQ&sig2=BtvoBrAsNz3cma8Kf6dn9A&bvm=bv.75775273,d.aWw&cad=rja

That one has both inverted and non-inverted outputs.

==

If you get past the previous exercise then you should understand what's going on. Conserving bits is a design decision. Then, I think your looking at a minimum of building a 3 digit xx.x for setpoint and a 1 digit BCD switch, each with endcaps. Lots of diodes.

==
Notes:
DS 2560, #219
Pressure sensor datasheet: MPX2010DP
 
Ok, I finished the exercise & the results are as follows:

ULN2003 (Pin 7 Open Original Code) = [Bit8: 1] [Bit4: 1] [Bit2: 1] [Bit1: 1] [switchNo: 0] on
all 0-9 settings on Thumbwweel switch.
-----------------------------------------------------------------------------

ULN2003 (Pin 7 Open Modified Code) = [Bit8: 1] [Bit4: 1] [Bit2: 1] [Bit1: 1] [switchNo: 1] on
all 0-9 settings on Thumbwweel switch.
---------------------------------------------------------------
So they both read 15 in Binary or 1111!

ULN2003 (Pin 7 +5V Original Code) reads the same as the original code I had before 0-9 in
Binary & shows the switchNo like before.
--------------------------------------------------------------------

ULN2003 (Pin 7 +5V Modified Code) reads the same as the original code I had before 0-9 in
Binary except for the actual Thumbwheel switchNo because it now has && in the code & the serial
won't read that.

If you get past the previous exercise then you should understand what's going on.

Could you explain what I should be understanding.

Then, I think your looking at a minimum of building a 3 digit xx.x for setpoint and a 1 digit BCD switch, each with endcaps. Lots of diodes.

How do I go about doing & testing this?

Cheers

==
Notes:
DS 2560, #219
Pressure sensor datasheet: MPX2010DP [/QUOTE]
 
Somehow you got the inputs and outputs mixed up I believe and your also making little sense. Explain:
No because it now has && in the code & the serial

Pin 7 is an input and pin #10 is an output.

You had a ground connected to the common of the BCD switch, right? Remove that ground.

Connect the Common to (pin #10), an output of the ULN2003. Pin #10 is labeled O7 for output #7. Pin #7 is the corresponding INPUT.

Putting a high (+5) on pin #7 will put pin #10 to "ground", thus it's now the same as when the common of the BCD switch was grounded. This will read the BCD value or complement depending on the code.

Putting a LOW (ground or OPEN) just opens the common connection and all bits should be a 1. It should read 15 or 0 depending on the code.

==

==
Notes:
DS 2560, #219
Pressure sensor datasheet: MPX2010DP
 
Last edited:
I picked the wrong part. Back to the drawing board. We need the reverse of that chip. One input is multiplexed to n outputs where n is like 7 or 8 with a 3 bit address.
Sorry.:mad: My head is behaving badly. I'm outside at night with flood light re-enforceing a brand new snow shovel for use in a few months.
 
For the "conserve bits mode" you would need a 74x138 part https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCAQFjAA&url=https://ecee.colorado.edu/~mcclurel/sn74ls138rev5.pdf&ei=y_gcVMfMIvL_sASTm4HADg&usg=AFQjCNHeqCshjQI-em-T1KQjb-m4ZocISA&sig2=sQDr5_yT2PTlVrabJIX_cA&bvm=bv.75775273,d.cWc&cad=rja

It would have a consequence of having to add an inverter for each wafer. There are usually 6 on a chip.

UNLESS you happen to have a 74xx07 buffer with open collector or open drain outputs. That would eliminate the ULN2003 and the inverter.

==
Notes:
DS 2560, #219
Pressure sensor datasheet: MPX2010DP
 
Somehow you got the inputs and outputs mixed up I believe and your also making little sense. Explain:

Pin 7 is an input and pin #10 is an output.

You had a ground connected to the common of the BCD switch, right? Remove that ground.

Connect the Common to (pin #10), an output of the ULN2003. Pin #10 is labeled O7 for output #7. Pin #7 is the corresponding INPUT.

Putting a high (+5) on pin #7 will put pin #10 to "ground", thus it's now the same as when the common of the BCD switch was grounded. This will read the BCD value or complement depending on the code.

Putting a LOW (ground or OPEN) just opens the common connection and all bits should be a 1. It should read 15 or 0 depending on the code.


No, I have it connected exactly as you mentioned previously, not sure why it's not making any sense.
Only pin 8 to ground connection.

Cheers
 
Somehow you got the inputs and outputs mixed up I believe and your also making little sense. Explain:


You should be able to replace all of these switchNo = switchNo + 1 type expressions with corresponding lines similar to: switchNo = switchNo && 1; etc,

After this if ( val_BCDpin8 == 0) { switchNo = switchNo + 8; } line add
switchNo = !switchNo or this line switchNo = !switchNo; wwhatever works. Not sure if the space is required.

You mentioned to change part of the code to switchNo = switchNo && 1; etc, when I do this the Serial will not read the switchNo but the original code will?

Cheers
 
I still have the Diodes connected from the BCD switch to the Arduino Ports as mentioned in post #224, is this an issue now?

Cheers
 
You mentioned to change part of the code to switchNo = switchNo && 1; etc, when I do this the Serial will not read the switchNo but the original code will?

Cheers

What's wrong with me today. https://www.tutorialspoint.com/cprogramming/c_logical_operators.htm

The && is the AND operator. The || is the or operator. You want the OR operator.

The add that you did was perfectly fine. Replaceing with OR should just make it faster.

This switchNo = !switchNo or this line switchNo = !switchNo should just turn 000 to 1111 etc.
 
No problem, I will give it a go & let you know.

I couldn't figure out what the heck was going on with anything & got totally confused.

All Good!

Cheers
 
Just did a test using the Or operator as suggested from 0-9, +5V to Pin 7 ULN2003, see attached:

Cheers
 

Attachments

  • BCD Serial Readout.PNG
    BCD Serial Readout.PNG
    7.4 KB · Views: 179
I have to admit trying to understand this is beyond my capability at this stage.

It may be better if I just return to using voltage references as the set points & see what error exists & then try to compensate for it?

I don't know?

Cheers
 
Post your code again. Thanks. See next post.

It should look like:

if ( val_BCDpin1 == 0) { switchNo = switchNo + 1; }
if ( val_BCDpin2 == 0) { switchNo = switchNo + 2; }
if ( val_BCDpin4 == 0) { switchNo = switchNo + 4; }
if ( val_BCDpin8 == 0) { switchNo = switchNo + 8; }

or

if ( val_BCDpin1 == 0) { switchNo = switchNo | 1; }
if ( val_BCDpin2 == 0) { switchNo = switchNo | 2; }
if ( val_BCDpin4 == 0) { switchNo = switchNo | 4; }
if ( val_BCDpin8 == 0) { switchNo = switchNo | 8; }

They should both give the identical result.

switchNo is an integer - Not good! This means that NOT will give very wierd results. In any event, the bitwise NOT operator is apparently "~" and not the "!" :oops: Logical OR wasn't right either.

It has to be an "unsigned int" for NOT to work correctly.

Don't get too upset yet. Please?
 
Last edited:
Better yet, try this. I put the code within code tags. [code]code goes here[/code]

Code:
/*Willeng
20/9/2014
Modified Sketch
BCD TEST?
*/
const byte BCDpin1 = 2;
const byte BCDpin2 = 3;
const byte BCDpin4 = 4;
const byte BCDpin8 = 5;
void setup()
{ Serial.begin(9600);
pinMode(BCDpin1, INPUT_PULLUP);
pinMode(BCDpin2, INPUT_PULLUP);
pinMode(BCDpin4, INPUT_PULLUP);
pinMode(BCDpin8, INPUT_PULLUP);

}
void loop() {
// read
unsigned int val_BCDpin1 = digitalRead(BCDpin1);
unsigned int val_BCDpin2 = digitalRead(BCDpin2);
unsigned int val_BCDpin4 = digitalRead(BCDpin4);
unsigned int val_BCDpin8 = digitalRead(BCDpin8);

unsigned int switchNo = 0; //reset

if ( val_BCDpin1 == 0) { switchNo = (switchNo |  1); }
if ( val_BCDpin2 == 0) { switchNo =  (switchNo | 2); }
if ( val_BCDpin4 == 0) { switchNo = (switchNo | 4); }
if ( val_BCDpin8 == 0) { switchNo =  (switchNo | 8); }

{
Serial.print("[BIT8: ");
Serial.print(val_BCDpin8);
Serial.print("] ");
Serial.print("[BIT4: ");
Serial.print(val_BCDpin4);
Serial.print("] ");
Serial.print("[BIT2: ");
Serial.print(val_BCDpin2);
Serial.print("] ");
Serial.print("[BIT1: ");
Serial.print(val_BCDpin1);
Serial.print("] ");
Serial.print("[switchNo: ");
Serial.print(switchNo);
Serial.println("] ");}

delay(3000);
}

Yep, lots of problems. My fault. Your almost there. I edited the last two posts.
 
Last edited:
Hi Kiss,
Thought I would leave you alone today & spent some time studying, more on that later.

I"ll have a look at what you have posted then get back to you.

Thanks Again

Cheers
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top