opto sensor, microcontroller, led display

tshuck

Joined Oct 18, 2012
3,534
Yea I planned on getting the 20M2. So if I wanted to add features in the future I wouldnt need a whole new chip. I downloaded the flowchart program and I have to say, I have no idea what Im looking at.
For right now, I'd say look up a couple tutorials for your program, there are bound to be a few. When I get some free time, I'll have a go at it and see if I can understand it myself...
 

Thread Starter

akramer08

Joined Jan 23, 2013
113
No worries, take your time. I just want to clarify what I will be needing first.

20M2 microcontroller
breadboard(I have a 400 pin, will that suffice?)
serial link
programming adaptor(not sure about that one)
 

tshuck

Joined Oct 18, 2012
3,534
No worries, take your time. I just want to clarify what I will be needing first.

20M2 microcontroller
breadboard(I have a 400 pin, will that suffice?)
serial link
programming adaptor(not sure about that one)
Don't forget the LCD;)...
The breadboard should be fine...
do you have a link to the PICAXE products you are looking at? I'm not sure what you mean by the programming adapter...
 

Thread Starter

akramer08

Joined Jan 23, 2013
113
Ill have to check to see if my laptop has the serial port when I get home. All that stuff makes sense now, thanks for clearing it up with the links. I can only trust the results I get from google so much.
 

tshuck

Joined Oct 18, 2012
3,534
Ill have to check to see if my laptop has the serial port when I get home. All that stuff makes sense now, thanks for clearing it up with the links. I can only trust the results I get from google so much.
It's good to be wary. You should always ask, "Given what I know, does this make sense?". It's something a lot of people don't do...:(

Anyway, I think that is all you'd need, but like I said, I've never used PICAXE before, so thatoneguy should be the final word on the matter...
 

Thread Starter

akramer08

Joined Jan 23, 2013
113
Yea ill wait for his next response. Its unfortunate that Im such a beginner. Half of the stuff you guys have helped out with makes little to no sense. But you guys are helping a tremendous amount so far and I feel more comfortable with the terms of the hardware and project overall.
 

tshuck

Joined Oct 18, 2012
3,534
Yea ill wait for his next response. Its unfortunate that Im such a beginner. Half of the stuff you guys have helped out with makes little to no sense. But you guys are helping a tremendous amount so far and I feel more comfortable with the terms of the hardware and project overall.
Hey, no worries! I can't speak for thatoneguy(but I think I might in this case;)), but I enjoy helping people learn and understand electronics. This stuff is pretty involved and you almost need a guide to help you do anything. Don't worry about not knowing this stuff, it comes with time and exposure to the topics.

What makes little to no sense? Perhaps we could clarify what you are hazy with. Simply following what we say may work, but if you don't understand what you are doing, it doesn't benefit anyone(save for the fact you get a sweet mod to your gun:p)...
 

Thread Starter

akramer08

Joined Jan 23, 2013
113
I think Im pretty clear so far, but Ive been lost here and there. I like to research a lot if I dont understand something or if I just dont know what it is. So Ill do something like google for images(lets take the programming adapter for example), but if there a ton of different images on there I dont know which one it is. I dont think there were any that looked anything like the on e on aztec. But you guys have kept me pretty clear so far, and the links you provided helped clear up what the adapter is.
 

tshuck

Joined Oct 18, 2012
3,534
I think Im pretty clear so far, but Ive been lost here and there. I like to research a lot if I dont understand something or if I just dont know what it is. So Ill do something like google for images(lets take the programming adapter for example), but if there a ton of different images on there I dont know which one it is. I dont think there were any that looked anything like the on e on aztec. But you guys have kept me pretty clear so far, and the links you provided helped clear up what the adapter is.
Yeah, programming adapter is pretty vague for Google, perhaps "PICAXE programming adapter", or "Aztec PICAXE programming adapter" would have given better results...
 

thatoneguy

Joined Feb 19, 2009
6,359
@tschuck, yes, the M2 line supports I²C, handy on the 8 pin so it can talk to a few MAX6956 LED drivers for a big display, as well as a shift register on two other pins for a 2 dimensional display.

This is the kit I was thinking of to get started Programmer, breadboard, 20M2, and some components to play with until you figure out the final project.

The Logicator software (which I haven't used, but can, BASIC really is simple), includes Serial Transmit "action blocks" that can be dropped onto the chart.

Drag and drop your program, start at Start, declare a "shots" word variable, enable LED, delay or wait for change on phototransistor input, subtract one from counter, send "Shots=" shots variable on serial out to LCD. Loop back to wait for another shot, add in your battery monitoring code after each shot.

I Forgot to mention the other limitation of PICAXE: Doesn't directly support negative numbers in variables, or floating point numbers, only integers. You can work around this by making your own routines to convert, but that is beyond the scope of the OP at this time.

Just remember all variables are 0 to 255 for byte, or 0-65535 for words (2 bytes). Byte names overlap word names. I usually use words from "top" of memory, and bytes from b4 and up. b0-b3 allow 32 bits to be directly accessed as boolean flags, so I don't overwrite those. w0 is made up of b0,b1 (bits 16:0), w2 is made up of b2,b3 (bits 32:17). See Attached Variable Map and it makes MUCH more sense. In summary, Use words starting at w13 and go lower, bytes starting at b4 and work upward, and bit flags from bit0-bit32


This post probably confused you more than helped, but it will all make sense after you use it a bit.
 

Attachments

tshuck

Joined Oct 18, 2012
3,534
@tschuck, yes, the M2 line supports I²C, handy on the 8 pin so it can talk to a few MAX6956 LED drivers for a big display, as well as a shift register on two other pins for a 2 dimensional display.

This is the kit I was thinking of to get started Programmer, breadboard, 20M2, and some components to play with until you figure out the final project.

The Logicator software (which I haven't used, but can, BASIC really is simple), includes Serial Transmit "action blocks" that can be dropped onto the chart.

Drag and drop your program, start at Start, declare a "shots" word variable, enable LED, delay or wait for change on phototransistor input, subtract one from counter, send "Shots=" shots variable on serial out to LCD. Loop back to wait for another shot, add in your battery monitoring code after each shot.

I Forgot to mention the other limitation of PICAXE: Doesn't directly support negative numbers in variables, or floating point numbers, only integers. You can work around this by making your own routines to convert, but that is beyond the scope of the OP at this time.

Just remember all variables are 0 to 255 for byte, or 0-65535 for words (2 bytes). Byte names overlap word names. I usually use words from "top" of memory, and bytes from b4 and up. b0-b3 allow 32 bits to be directly accessed as boolean flags, so I don't overwrite those. w0 is made up of b0,b1 (bits 16:0), w2 is made up of b2,b3 (bits 32:17). See Attached Variable Map and it makes MUCH more sense. In summary, Use words starting at w13 and go lower, bytes starting at b4 and work upward, and bit flags from bit0-bit32


This post probably confused you more than helped, but it will all make sense after you use it a bit.
Ah, I didn't even look into the kits...

@OP,We can work on the battery portion once the counter works, so don't feel too overwhelmed by this!
 

Thread Starter

akramer08

Joined Jan 23, 2013
113
I feel way more comfortable than I did when I originally posted the question. You guys make it sound so easy to do ANYTHING with a controller. Lets get some satellite tv on this thing! In all seriousness it sounds like this flowchart program wont be too intense. Ill just have to take another look at it when I get home.
 

tshuck

Joined Oct 18, 2012
3,534
I feel way more comfortable than I did when I originally posted the question. You guys make it sound so easy to do ANYTHING with a controller. Lets get some satellite tv on this thing!
I'm not sure you'd want THAT expensive of parts mounted onto a device whose sole purpose is to launch high-velocity projectiles at opponents doing the same to you:p

Almost everything you touch that is electronic contains a microcontroller, so there are quite a few things to be done with them!

In all seriousness it sounds like this flowchart program wont be too intense. Ill just have to take another look at it when I get home.
Yeah, it's just a matter of deciding what you want to do with the uC, figuring out what needs to be done, and describing it in s way the microcontroller understands...
 

SPQR

Joined Nov 4, 2011
379
akramer08,
I wanted to thank you for this thread. I always learn a lot from these types of discussions.
But more importantly, it galvanized me to make a few things and work with some new components.

I bought some LED displays from Amazon - had never worked with displays before. (Microtivity, 3 digit, dynamic, 7 segment).

I built a little "debounce" board with 6 switches that I can insert temporarily into any breadboard I happen to be playing with.
I had used hardware debounce in the past.

I coded a bit to learn about driving a dynamic LED display, and how to "delay" the effects of a switch.

So I built 90% of your device.

It's basically two switches - one for "Reset" and one for "Increment" the number of balls.
"Reset" sets the count to an initial number that you decide.
"Increment" can be programmed for any number - I have it at "1" not so when you hit the button, the display goes up by 1.
You can add as many switches as you like - only limited by the number of input pins.

So I have an Arduino Uno.
The 7 LED segments to into ports 2-8.
The digit control pins go into ports 11-13.
"Reset" goes to port 9.
"Increment" goes to port 10.

HERE is the debounce circuit.

and HERE is the code:
Rich (BB code):
/*
  7 segment LED display with three digits.
  Pin  2=A : Pin  3=B : Pin  4=C : Pin  5=D
  Pin  6=E : Pin  7=F : Pin  8=G
  Pin 11 = Digit 1 : Pin 12 = Digit 2 : Pin 13 = Digit 3
*/
int pinarray[]= {2, 3, 4, 5, 6, 7, 8};
int digitarray[] = {11, 12, 13};
int startingballs = 157;
int balls;
int inc;
int res;
const int Increment = 10;
const int Reset = 9;
int numberarray [10] [7] =
{
{1, 1, 1, 1, 1, 1, 0}, //0
{0, 1, 1, 0, 0, 0, 0}, //1
{1, 1, 0, 1, 1, 0, 1}, //2
{1, 1, 1, 1, 0, 0, 1}, //3
{0, 1, 1, 0, 0, 1, 1}, //4
{1, 0, 1, 1, 0, 1, 1}, //5
{1, 0, 1, 1, 1, 1, 1}, //6
{1, 1, 1, 0, 0, 1, 0}, //7
{1, 1, 1, 1, 1, 1, 1}, //8
{1, 1, 1, 0, 0, 1, 1}  //9
};
void setup()
{                
  int count = 0;
  for (count=0; count<9; count++)
    {pinMode(pinarray[count], OUTPUT);}    
  for (count=0; count<3; count++)
    {pinMode(digitarray[count], OUTPUT);}
  pinMode(Increment, INPUT);
  pinMode(Reset, INPUT);
  balls = startingballs;
}
void loop()
{
  if (balls < 0) {balls = 0;}
  if (balls >250) {balls = 250;}
  res = digitalRead(Reset);
  if (res == HIGH) {balls = startingballs;
                    delay(200);}
  inc = digitalRead(Increment);
  if (inc == HIGH) {balls = balls + 1;
                    delay(200);}
  displaynumber(balls);
}
void displaynumber(int ballnumber)
{
  int i = 0;
  int digit1 = 0;
  int digit2 = 0;
  int digit3 = 0;
  int decimalcounter = 0;
  int tenscounter = 0;
  int hundredscounter = 0;
  for (i=1; i<ballnumber+1; i++)
    {
      digit1 = digit1 + 1;
      digit2 = digit2 + 1;
      if (digit1 > 9)  {tenscounter = tenscounter + 1;
                        digit1 = 0;}
      if (digit2 > 100) {hundredscounter = hundredscounter + 1;
                         digit2 = 0;
                         tenscounter = 0;}
      digit3 = digit1;
    }
  writeanumber(1, hundredscounter);
  writeanumber(2, tenscounter);
  writeanumber(3, digit3);
}
void writeanumber(int digit, int digitvalue)
{
  int count = 0;
 
  digitalWrite(digit+10,0);
  for (count=0; count<7; count++)
      {digitalWrite(count+2, numberarray [digitvalue] [count]);}
      delay(2);
      digitalWrite(digit+10, 1);
}
It's not elegant but it works.
I'm sure others can chime in and improve it.
I had to do the fancy loops to parse out the number into three separate digits to display.

Basically it takes the number of balls that you put in (variable "balls" - I thought that was VERY imaginative!:D) and waits for input from one of the buttons or sensor - then does what it's supposed to do.

This part doesn't include the sensor, but I need an IR sensor for another project, so I'll work on yours, then move it to mine.

I also bought some of the Teensy boards, and after I finish a few more projects, I'll buy a PIC programmer.

I present this to perhaps help get you started, and allow others to improve it.

Thanks again!
 

Attachments

Last edited:

Thread Starter

akramer08

Joined Jan 23, 2013
113
No problem, glad it was useful to someone other than myself. I cant wait to start working on the coding tonight. I didnt get a chance to last night. Hopefully it all goes pretty smooth.
 

tshuck

Joined Oct 18, 2012
3,534
No problem, glad it was useful to someone other than myself. I cant wait to start working on the coding tonight. I didnt get a chance to last night. Hopefully it all goes pretty smooth.
Make sure you look at the user's guide... I was messing with it last night and needed to consult it more than once...
 

thatoneguy

Joined Feb 19, 2009
6,359
Make sure you look at the user's guide... I was messing with it last night and needed to consult it more than once...
I'd suggest getting all 3 user manuals, and the memory map above, especially for a beginner.

Manual 2 covers the commands (and what you'll pay the most attention to, typically), and Manual 3 has some good examples in BASIC.
 
Top