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.
Kiss,
No, I don't get upset or angry or in bad moods, in fact every day I wake up & smell fresh air I am grateful to be alive. Three years ago I nearly kicked the bucket & now I have a totally different outlook on life. However I do get very frustrated, confused & very ill on a daily basis due to my condition but that's unavoidable now, that's life though!
I don't know how to give up & will keep going at this until I drop before I give in.

My biggest stumbling block is that I had no education when younger, my education was with Lathe, Mill, Welders, Engines, Dyno's, Airflow Development, Race Cars etc from a very young age.

Hence the cross eyed attitude when I have to learn Binary, Programming etc, I could read a Micrometre, Verniers, Manometers & Tape measures from the age of eight but never learnt how to read & write until about ten years ago.

That aside, today I did learn something that was useful, for some reason I thought that BCD was the same as Binary numbers & I can tell ya it caused me so much confusion I did think I could never work it out. When I started on this I found an on line calculator & punched in the number 8 & in Binary & BCD it was 1000 then I tried 9 & got 1001.
My thoughts were ok they are both the same?

Today I found out differently & can now see what BCD is, bloody hell I wasted some time thinking this is impossible to work out haha!
I only have a couple of brain cells left & this killed a couple more!

Ok, onto the Sketch, I tried the new sketch you posted & still get the same result as the first original sketch, I have attached a serial shot named:
"ULN2003 +5V New Code", test was from 0-9 on the switch. The Output is still inverted.

I tried many other things today with no luck but I don't really know what I am trying to get, I thought 0-9 is what we wanted, isn't this BCD to Decimal & what we need?
So if we have two BCD switches & select say 20 with them the Arduino will see 0010 0000, this is where I am confused now, what are we looking for & why?

Anyway, I tried "+5V to Common" instead of "common to ground" & used 10k resistors to ground without the ULN2003 & have attached a serial shot of this as well named:
"+5V Common Original Sketch", again the test was 0-9 on the switch. The Output is not inverted now, not sure about the switchNo though?

I did try ( ~ ! @ # $ % ^ & * () _ + =><?":;'}[{}]`HYGTFREXRGHHUHYYRXEWT:"UTDJHUIUYK+89879/+-=99867656565643fcfgd4wwjxe32dhgguhggcdajgjhgukruy) today as well as a million more things, the only thing I didn't try was throwing the computer out the window which I think may improve things ha!

Cheers
 

Attachments

  • ULN2003 +5V New Code.PNG
    ULN2003 +5V New Code.PNG
    7.9 KB · Views: 174
  • +5V Common Original Sketch.PNG
    +5V Common Original Sketch.PNG
    8 KB · Views: 190
Congratulations!

The first one is PERFECT! It's EXACTLY what you want!

It can probably be cleaned up (done differently) and shortened, but it's not necessary yet. Eventually you'll want to move it into a function form.

The only way of changing the pattern is add inverters or buy the complement switch. Both are unnecessary. Although, it may be easier hardware wise later if they were inverted.

So, now, you can take switchNo and multiply and or divide and add to get any digit of the setpoint.
e.g. switchNo*10, switchNo, and switchno/10

OK. My migraine was messing me up. The BITWISE AND and OR and NOT operators are not the same as the comparison operators. It's been a while since I programmed in C.

==
ULN2003
I told you from the beginning the ULN2003 is a hard to understand part. I had trouble with it too, some 35 years ago.

In THIS application, it only needs ground, one input and one output connected. Common of that chip gets connected to a POSITIVE voltage when driving relays. The diode coil suppression is in the chip.

==

So, connect ground, pin 8, to the ULN2003 chip.

Connect an output, e.g. pin 10, of the ULN2003 to the Common terminal of the BCD switch that is now connected to ground.

Now with +5 (HIGH) on the corresponding input (i.e. pin 7), you should get the 0-9 output. Unconnected or connected to ground (LOW) you should read 15.

Goal: Prepping for the ability to read multiple switches.

Regards,

KISS

==
Notes:
DS 2560, #219
Pressure sensor datasheet: MPX2010DP
 
Last edited:
I thought 0-9 is what we wanted, isn't this BCD to Decimal & what we need?
So if we have two BCD switches & select say 20 with them the Arduino will see 0010 0000, this is where I am confused now, what are we looking for & why?

Yes, that is the ultimate goal. To get there, we have to be able to read multiple switches. The Arduino already sees 0-9 after some brain cell processing. That is going to be some digit of xx.x. At present, it is the *x.* digit.

So, now, you can take switchNo and multiply and or divide and add to get any digit of the setpoint.
e.g. , switchNo*10, switchNo, and switchno/10

Now, we need the Arduino the be able to select the digit we want to read.
 
I can't foresee any problems with the above exercise, so we'll go on to the next BABY STEP.

Inversion of the Control Signal


We need the control signal inverted. You can do it with a 7400 series chip or you can use another section of the ULN2003 with a 10K pull-up resistor. That means connect the output of another section of the ULN2003 to a 10K resistor to +5. Connect that output to the input of what you created above and use the new input. Remember to connect ground IF you use another ULN2003.

Now with the new input LOW, you will read 0-9 and with it HIGH, 15.

Eventually, you will need a total of 5*2 sections. 5 with resistors. Two ULN2003 chips would be easier to layout than an inverter and a ULN2003. This entire circuit can be replaced with a single HEX open collector or Open Drain Buffer. The logic might be hard to understand, but an invert followed by an open collect invert is an open collector buffer.
 
Last edited:
Another baby step: Convert to function

Convert into function Read_BCD() and return switchNo

Later we may change this function to Read_BCD_digit(wafer)

Aside:
If I were programming, I might want to make this a re-useable function that could be used in any other program I write. In that case, I would consider generic sort of arguments and write the function accordingly. One argument could be INVERT, another DIGITS, and an array of ports and Masks. Who knows if this is beyound Arduino's capability andit may be beyound you. A function called with (2, A[0]=A5, a[1]=B3, INVERT) could be very useful. We are not going to do this.
 
Last edited:
You next step is just as easy

Expand to two BCD switches

You are to duplicate the circuit you just created with the diodes, 2 ULN2003's or whatever, and the pull up. Attach both BCD switches to the same port at the same time. Eventually you will connect all 6 or 7 individual switches to the same port.

You will then have two inputs with a truth table of:
00 - indeterminate (actually the OR of two switches)
01 - The switch with the zero
10 - The switch with the zero
11 - 15

The ULN2003 will have to actually have levels applied. A 74xx series chip, the inputs would float high.

In the final product, this expansion will occur six or 7 times and the truth table will change. Don't do it yet.
 
Last edited:
The next step can be one of two:

1. Make the Auduino read BCD switch 1 or BCD switch 2.
2. Conserve bits (Add 74xx138) chip


Do item #1. Configure three consecutive bits (easier) as an output port and see if the x00, x01, x10 and x11 give expected results. x is a Don't care state. Ignore the MSB of #00 for now. If you can't use 3 consecutive bits, it just makes the code more difficult.

==
Notes:
DS 2560, #219
Pressure sensor datasheet: MPX2010DP
74xx138
 
Last edited:
74xx138 (Anticipate problems using chip because of datasheet)

That part is confusing. I'll sort of stop here. I just changed it to the Motorola Datasheet because it has all of the enables listed. The TI datasheet does not. However, the Motorola datasheet messes with you head in another area. The A2, A1, A0 table should be reversed to A2, A1, A0. So, BE CAREFUL!

This is an ENDIAN issue. It's listed in BIG Endian.

~E1 and ~E2 will be set permanently LOW and E3 will be set permanently HIGH. A3, A1, A0, will connect to the Auduino where A0 is the LSB (Least Significant Bit) and are active high. So, a 000 selects Y0. Y0 is active low.

So, if you connect Y0 to one of the inputs we created and Y1 to the other.

You can now manipulate which switch is read by using A3, A2 and A0. For now, tie A3 permanently low or program it low. 000 will select one wafer and 001 will select the other. When completed 000-111 will select one of 7 switches.

Then I will show you how to turn two switches into the real numbers 0.0 to 9.9 and 00 to 99. From there you can turn three wafers into 00.00 to 99.9.

At this point, you should be ready to build to a max of 7 wafers. If you use the ULN2003 parts, you can do 7 channels with two. If you use Hex parts, then initially your limited to 6 channels. The open drain/open collector buffer would have two IC's for 7 channels. The ULN2003 solution will also have two IC's per 7 channels.

For 6 wafers and the open drain part,only one hex open collector buffer would be required.

One possible parts list is:
7*4 or 28 diodes.
2 ULN2003's
7 10 K resistors.

Your choice on how to connect to the BCD switches. Ribbon cable, connector at one end or both ends.
To reduce cabling, you might be able to create two daughter boards. One for each group of switches, One of the daughter boards would contain the '138. and have a few wires to the other board. e.g. (logic ground, power ground, +5, 2 select lines). It might be possible to mount a connector on the PCB and attach the PCB directly to the BCD switches.

All of that would reduce the number of wires down to 10 from like 30 or one cable per BCD switch.

4 to the BCD port
3 for select
Logic ground

Power ground
+5

==
Notes:
DS 2560, #219
Pressure sensor datasheet: MPX2010DP
74xx138 (Watch)
 
Last edited:
Congratulations! The first one is PERFECT! It's EXACTLY what you want!

If I am not mistaken that is what I had in post #235 with the original sketch?
***********************************************************************

My first impression this morning when I saw all your posts was :arghh:.
All good though, I will read through it all & take one step at a time.

Baby Steps, I like that!

Get back to you soon.

Cheers
 
I think you called it "thumbwheel" rather than "switchNo" and that didn't register that as a computed number. Probably migraine again. The delay should have given it away. It gave you time for you to change the switch. I changed + to a bitwise OR. :arghh:

Hopefully, the instructions will go well.
 
Hi Kiss,

No I had it as "switchNo" it's no problem, I thought I would look into the programming a little further before proceeding with the exercises & the instructions.
I found quite a few things that may help me & I am just spending some time at the moment trying to get a grip on a few things.
All of a sudden the programming is seeming interesting for the first time to me, if I can get it or not is another question though.

Give me a little time as I would like to try some things out before I forget about them, I will then get back onto where we are up to.

I am also attempting to understand the datasheet for the 2560, this has always given me grief but I finally found some things that I am partially understanding.

Sorry for the delay but it's important to me to get a better understanding of things.

Just quickly I have some Hex Invertors if required as well.

Get back to you soon.

Cheers
 
see: https://www.electro-tech-online.com/attachments/bcd-serial-readout-png.88318/ "thumbwheel"

I would advise reading everything through to get an idea where your going. I covered the use of inverters vs the ULN2003's as well and a part that you don't have: An open collector or open drain buffer. I also briefly talked about layout and the idea of building daughter cards", but I don't know what the connections are like on the switches, so I can't comment further.

It sort of boils down to build for 6 or seven switches. I think you need 5. When you think about it, an expansion to 7, would allow you to read 8 more bits without utilizing Arduino ports, assuming your using 5 of the switches. e.g. the SP/MV/dev switch or the Man/Auto switch.

The datasheets for the '138 are very different depending on the manufacturer.

Ask questions.
 
Last edited:
willeng:

I guess in the Arduino world, it looks like you did the right thing: https://www.arduino.cc/en/Reference/PortManipulation

Ports, I guess are "old school". So if you don't need fast transfers or have to set two or more bits at the same time, stay away from manipulating ports. In the old model, ports were just memory locations not special multi-function "pins".

I did change a variable to unsigned, but that, of course, made no difference either.

So, yea, you can assign the binary weights to any pin whatsoever and that appears to be a good thing.

But, I still don't like the interrupt handler. Neither does Matt. derStrom8 here.

KISS

PS: Lathe/Mill etc. I was in a college prep curricuum and I wanted to take metal shop. Tough to do. We had a modular system and on Tuesdays, I had a 45 min class in the morning. That was it. On Thursday, I had 15 minutes for lunch. Shop was basically pick a project and the instructor would teach you the skills necessary to do it,

When I started working in a research lab, we had two machinists which eventually dwindled down to none with a fully functioning shop.
Anyway, I learned from the machinists, but they had to have work supported by contracts to support themselves. Anyway, setups were done by the machinists until I could do them myself. Eventually, I had almost free rein. I never learned welding, but I did silver soldering or brazing and glass blowing. However, I had a stick, tig and Mig torch in my hand at least once and my welds were A+ once I was set-up. And this was like a first time. I'm sure the extensive glass blowing, soldering and brazing had something to do with it.
 
QUOTE="KeepItSimpleStupid, post: 1193866, member: 158325"]I guess in the Arduino world, it looks like you did the right thing: .[/QUOTE]

Not to sure about that being a novice but I'm learning slowly.
But, I still don't like the interrupt handler. Neither does Matt. derStrom8 here..

I find the best thing to do when you don't like something is to find away around things so they do work correctly, maybe it can be done with this?
At the end of the day it's a control program so it should be capable of that surely?
I'm sure with yours & Matts knowledge you can help with this hey!:happy:

I was actually looking at Port Manipulation to see what it was all about.

After your comment that the program could be shorter & more compact as a result I have been trying to do just that & have started doing that first, I thought it was not much good proceeding if I can't do things so I gave it a go.
I still have more work to do but I will post what I have done so far.

Not finished yet but you may be able to advise on the rest & on proceedings so far, it works good.
It doesn't look like much but it has taken some time to try to figure out things when basically I have no idea!
Sketch Below!

EDIT: Showing me how to post the Code is pretty cool, thanks for that.
Forgot to mention that my Interrupt Handler is a FBH.:cool:

Code:
/*Willeng
23/9/2014
Modified Sketch
BCD TEST _ Shorter Version
*/
const byte number[] = {6, 7, 8, 9};
void setup()
{ Serial.begin(9600);
DDRH = 0x00;
PORTH = 0xFF;
}
void loop() {
unsigned int val_1 = digitalRead(6);
unsigned int val_2 = digitalRead(7);
unsigned int val_4 = digitalRead(8);
unsigned int val_8 = digitalRead(9);
int switchNo = 0; //reset

if ( val_1 ==  0)  { switchNo = switchNo + 1; }
if ( val_2 ==  0)  { switchNo = switchNo + 2; }
if ( val_4 ==  0)  { switchNo = switchNo + 4; }
if ( val_8 ==  0)  { switchNo = switchNo + 8; }
{

Serial.print  (val_8);
Serial.print  (val_4);
Serial.print  (val_2);
Serial.print  (val_1);
Serial.print("[switchNo: ");
Serial.print( switchNo );
Serial.println("] ");
}
delay(3000);
}
 
Last edited:
With the Arduino, I think you did better with the first one. The cool part, is you learned something doing it a different way. I was thinking more of removing the intermediate variables.

Code:
// read

int switchNo = 0; //reset

if (digitalRead(BCDpin1) == 0) { switchNo = switchNo | 1; }
if (digitalRead(BCDpin2) == 0) { switchNo = switchNo | 2; }
if (digitalRead(BCDpin4) == 0 { switchNo = switchNo | 4; }
if (digitalRead(BCDpin8) == 0 { switchNo = switchNo | 8; }

And maybe change switchNo to Thumbwheel because it may be a better name and make it a function because later, you;ll have to do something like:

Code:
/Get Setpoint

Select_Thumbwheel(1)
Setpoint = Get_BCD_Digit
Select_Thumbwheel(2)
Setpoint=Setpoint+Get_BCD_Digit/10
Select_Thumbwheel(3)
Setpoint=Setpoint+Get_BCD_Digit*10

and

Code:
/Get function

Select_Thumbwheel(4)
Function = Get_BCD_Digit
 
Last edited:
Hi Kiss,
Yes, I first had it as Thumbwheel as you know & only changed it for testing purposes, I see what your getting at & will try a few things, I have something in mind but not sure if I can get it to work yet.
I have had to go to town today & will be in & out of town for a couple of days which is slowing things down but is unavoidable.

It was good to find different ways of achieving the same result with the sketch. I'll get back onto things as soon as I can.

Cheers
 
Not that it matters, but I was looking around and found an alternate way of doing the switch interfacing. The MAX6118 See: **broken link removed**

The only real advantage would be inherent contact debouncing, which I don;t think will be a problem anyway. You would need one MAX6118 per thumbwheel and it's a surface mount part. No diodes would be required and most of the other parts would go away too.

The other way is a cheaper design since the parts are free.
 
Rotary Encoder

I have this https://www.sparkfun.com/products/10596 encoder, breakout board and clear knob from Sparkfun.

I dunno if I'll get to it, but I might try to make a rotary encoder interface using the LFS7183/7184 **broken link removed**, the MAX6816 **broken link removed** At the very least, 1x, 2x and 4x would be jumper selectable. I ordered some of the USdigital chips in SMT and DIP packages.

I'll probably make both up/dn and clk/dir interfaces available (i.e. Use two chips) Up/Dn is probably easier for the Arduino Due and CLK/DIR easier for uP' s with less interrupts available.

I'll use some yet to be undetermined parts for the high side drivers for the LEDs and level translation.

It looks like they made some changes on how interrupts are handled for the Due, more to my liking and the Due does require level translation.

With that in mind, the design seems simple.
 
Hi Kiss,
Firstly, I would like to apologize for not continuing with this very interesting project & cutting it short, but it has been & was unavoidable. Health Issues!
I have been off my feet for a very long time & only this week finally am I on the mend & out of the damn bed.
Obviously I will have to back track to get up to speed with this again & I would like to finish what was started.
I would very much appreciate your patience & assistance once I get a handle on things again.

I am hoping you have the time to oversee & slap me on the head when I don't understand things once again, if not I fully understand & appreciate your efforts so far anyway.

Cheers
 
Status
Not open for further replies.

Latest threads

Back
Top