Pages: 1 2 [3] 4   Go Down
Author Topic: BI-DIRECTIONAL PEOPLE SENSOR AND COUNTER USING ARDUINO BOARD  (Read 5655 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mike,

Sorry the ISR stuff wasn't mean't for you.
My counter code is abit verbose coz am a newbie!! I will still modify it as you said.
Still hitting hard rocks on how to call the counting code for my display.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8452
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK here's a program that (I think) will display a counter on your display

Code:
#define NDIGITS 3
 
byte digitPins[] = {37, 38, 39};
byte segmentPins[] = {30, 31, 32, 33, 34, 35, 36};
 
byte display_digits[NDIGITS];
 
byte current_digit = 0;
 
byte digitPatterns [] = {

// gfedcba // note the pin assignment are "backwards", makes it harder
B01111110, // 0
B00000110, // 1
B10110110, // 2
B10011110, // 3
B11001100, // 4
B11011010, // 5
B11111010, // 6
B01100010, // 7
B11111110, // 8
B11111010 // 9
};
 
void convert_to_digits (byte number) {

for (int i = NDIGITS-1; i > -1; i--) {
display_digits[i] = number % 10;
number /= 10;
}

}
 
void show_next_digit () {

digitalWrite (current_digit, LOW);

PORTC &= B00000001;
PORTC |= digitPatterns[display_digits[current_digit]];

current_digit++;
if (current_digit >= NDIGITS) current_digit = 0;

digitalWrite (current_digit, HIGH);

}
 
void setup() {

for (int i = 0; i < 7; i++)
pinMode(digitPins[i], OUTPUT);

for (int i = 0; i < 3; i++) {
digitalWrite (i, LOW);
pinMode(segmentPins[i], OUTPUT);
}

}
 
void loop () {
static int  x;

// update number every 1s
if (millis() % 1000 == 0) convert_to_digits (x++);

// update display every 10mS
if (millis() % 10 == 0) show_next_digit();

}
 

Note that I got rid of all the digitalWrites() as they are a very inefficient way to do this when you have control over the pin assignment which I gather you do. Often on Arduinos you don't have much choice of pins but in this case you do so you can easily write directly to the port as I've done.

Note also that while the pin assignment seemed good when using Arduino logical IO pin numbers it's not great for direct port IO, as it is the 7 segments are on the upper 7 bits of PORTC and one of the cathode selects is on the bottom bit of PORTC. As with most things Arduino this is not well documented (if at all) but if you have a look at the Mega schematics you can see this. Also the pin-to-segment mapping is "back to front" (seg A on bit 7, seg G on bit 1), the computer doesn't care but it's harder for a human to get his head around it.

Anyway you essentially have two programs to write, the counting and the displaying. Try this to see if it works for the displaying.

______
Rob
« Last Edit: December 04, 2012, 11:46:27 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Graynomad,

I do appreciate your help and I will work on the display code.
My main problem is to call the counting code after the interrupts have happened
to update the display. Does the counting code go into the main loop just before the interrupts?
Anyone willing to help please?

Thanks.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8452
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does the counting code go into the main loop just before the interrupts?
The "counting code" IS the interrupt(s).

Your main problem is to get the two halves of the code working I think.

When you have a working counter and a working display it will be easy to merge the two. But trying to get everything working at once just makes life harder.

So you say my interrupt code doesn't work, it wouldn't be the first time smiley, can you post what you are using?

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

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

Quote
Your counting code does not display anything at the moment so I have to work on it.
So you are a bit premature in asking for it to be merged.

Nevertheless I have done it for you in the hope that you can read it and try and learn something.

* merged.ino (2.17 KB - downloaded 9 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mike,

hahahaha Got you! Thanks alot It still needs abit of tweaking here and there.I think it's the ports now.
Am checking the arduino mega 2560 schematics to see the port of my pins.
Sorry for being a newbie!!

Thank you very much.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mike,

I have rearranged the byte digitpatterns and atleast something is coming up on my display,though can't recognise what digits they are apart from digit 1, however, This is not exactly what I want but I will keep working till I achieve this.

This time round I will be mature to ask for any more help as these ideas are great and very helpful.

Much thanks

Steffano.
Logged

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

The trick is to find out the relationship between a bit in your data with the corresponding segment position.
It sounds like there is a miss match between what you have wired up and what the code thinks the wiring is.
So just have a digit with one segment on and see where it shows up. Repeat for all seven segments, then you can write the bit patterns in your code to match the physical layout you have.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mike,

I will do that and let you know.

Thanks.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mike,

I am still struggling with the display code to be honest. it lights my first digit wired to pin 37 and the digit is not clear enough can only see number 1.
my seven segments (a to f) are wired to pins 30 to 36) and my digit enable pins are 37, 38,39 and up to now I can't figure it out.

Thanks.
Logged

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

Quote
it lights my first digit wired to pin 37 and the digit is not clear enough can only see number 1.
Not sure I understand this?

Quote
and up to now I can't figure it out.
Figure what out.

You know the drill, post your code because it has changed since the last time.

However first try and fix it yourself. Just write a sketch showing one digit and advance the count on a push button at the same time print out the number you are displaying. See how the display differs from the number it is showing. Use that to correct the pattern look up table.
Logged

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

Quote
Below is my modified code;
The code needs to sit between the code tags.

Change the pattern defination to this
Code:
byte digitPatterns [] = {
//ABCDEFG   
B0000000, // 0
B1000000, // 1
B0100000, // 2
B0010000, // 3
B0001000, // 4
B0000100, // 5
B0000010, // 6
B0000001, // 7
B1111111, // 8
B1110011, // 9
Then tell us what is displayed for digits 0 to 7. Do this by drawing a diagram of the lit and unlit segments for each number. Then we can tell you what patterns to use.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mike,

I am completely lost even after changing the code it displays some funny characters and only digits  1 and 3 are enabled.
The lit segments on both digits 1 and 3 are a,b,c and d the rest of the segments are off. My verbose digitalwrite long counter
still works fine even after swapping the 37,38 and 39 pins for 25,26 and 27 on PORTA.  
Schematics to follow in a bit.

Steffano.

Code:
« Last Edit: December 16, 2012, 11:56:55 am by stefanoGizz » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8452
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you please put the code inside the CODE tags. You must know the drill by now.

Note what Mike said, run your code and have it put out the numbers 0-7, tell us what segments are lit for each of those 7 numbers.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8452
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why two schematics, they look the same.

You have

Code:
a  30  PC7
b  31  PC6
c  32  PC5
d  33  PC4
e  34  PC3
f  35  PC2
g  36  PC1

so you pin mapping should be

Code:
//ABCDEFG   
 B11111100, // 0
 B01100000, // 1
 B11011010, // 2
 B11110010, // 3
 B01100110, // 4
 B10110110, // 5
 B10111110, // 6
 B11100000, // 7
 B11111110, // 8
 B11110110, // 9

But it's 2AM here so I could be out. You could plug this in, but if it doesn't work out of the box go back to Mike's plan.

Stop trying to test everything at once, break the problem down into small pieces. You need to remove all the crap and just have a small program that outputs the bit patterns that Mike had, hardcode the number to 0 and record the lit segment, then hardcode the number to 1, record and repeat until 7.

This will identify exactly which bit in the array values is connected to which pin. Do things slowly and methodically, make one change at a time and ANALYSE the results then present them in a clear tabulated form.

______
Rob
« Last Edit: December 16, 2012, 11:30:44 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: 1 2 [3] 4   Go Up
Jump to: