Show Posts
Pages: 1 [2] 3 4
16  Using Arduino / LEDs and Multiplexing / Re: Digital Dice project on: January 19, 2013, 07:53:23 am
Wow, I have no idea how I missed those last two replies from marco_c and Grumpy_Mike...
I must have clicked on the thread and got distracted without checking down to the bottom or something.
Grumpy_Mike completely solved my last issue, and I had no idea it was even here.
I ended up going with what I call a "cop out" and using an 16x2 LCD with the liquidCrystal library.  Made finishing the project a snap.
I really do like the LCD option, due to ease of use, and more display functionality, but a big part of me really wanted to make the 7segs work.

With this new information in hand, I will likely give it another go, and see if I can't get the 7seg working properly.  Someone else on this forum is having similar issues, and if nothing else, I might be able to help him solve his 7seg problem if I can get mine working right.
I understood the multiplexing code structure I needed to use, but couldn't for the life of me figure out how to make it WORK.
Now I even feel a bit more foolish, because I have run into that same code to break down the answer into it's individual components, but couldn't seem to find it when I needed it.

I do intend on picking up some shift registers, but honestly, I am not patient when it comes to ordering parts online.  When I have an idea, I like to just go with it, and see if I can make it work with on hand parts.  The waiting for mail delivery kills me smiley-razz  It's kind of funny because I am usually a very patient person, but mail order just isn't me speed I guess. 

Thank you very much for adding some sample code to work from marco_c, I will absolutely check it out, and make myself do a little online shopping.  Will I also need a BDC or can I make this work with just the arduino and the shift register?  I have seen youtube videos of people using shift registers, and a BDC together for multiplexing, but not sure I have seen anyone using a shift register alone.  I do have a handful of 4026 ICs which might work, but I am not sure if the two are compatible.  I am not even sure the 4026 isn't a BDC, but I don't think so, will have to look that one up again....

Thank you guys so much, and I am sorry I missed your posts!  I like to at least respond to everyone who comments on a thread of mine.  I figure it is common curtsey, if someone takes the time to provide information, I should respond in kind.  I will have to be a bit more diligent in the future, don't want anyone thinking I ignored them, that is not the way to inspire people to lend you a hand when you need it.

Ok, I have been long winded enough, off to get some rest, got to work all this weekend, but monday and tuesday might find a little bit of new life breathed into my 7seg project!

Thanks!
N8
17  Topics / Device Hacking / motion detector hack? on: January 18, 2013, 04:05:05 am
Hello Hackers!

I have a question about something I would like to re-purpose to use in some other (not yet defined) project.  You know I wanna hack me up a new toy...

The house I live in has an old security system in it, that is no longer in use, and looks fairly old and outdated.  I have already pulled the board out of the control box for components.  I have been taking apart discarded electronics for some time now, but haven't actually used something as it was built for another purpose.
I have enough electronics experience to identify many of the parts, read a circuit diagram and build a circuit, but not enough to look at an existing board and make it do what I want.

There is a motion detector (which I am assuming by looking at the sensor is PIR) that I took apart today, that was mounted on the wall close to the front door.
Looking at the board, it has 4 wires on it, power ground, and I am assuming in/out data lines to communicate with the control box.  It also has three dip switches on it, two of which I am not sure what they do by their description on the inside of the cover.  the third turns an LED on or off.
It has a handful of small caps, 4 diodes, a (according to the datasheet) reed relay (part # dss41a12), transistor, and the sensor on one side.  The other side has a host of SMT parts on it, two of which are ICs (LM339 and a 27L2C rail to rail output op amp).

I know, without a diagram or a good look at the board this might not be useful information, but right now I have no way to upload photos to my computer (long story).
My question is, is there a way to hook this up to my arduino without running the risk of ruining it, and make use of the board as it is, or would I be better off just removing the sensor and maybe the reed relay (which I could use for another project down the road) and making use of the parts I can identify.

The sensor doesn't have any markings on it, it just has three pins and the sensor window in the case.  I am not sure how to identify which pins do what on the sensor without a datasheet to identify them, and I have never used an IR sensor before to know what they would be (though I would guess they would be power ground and data pins).
If I can't make use of the board as is, is there an easy way to determine which pin on the IR sensor does what, so I can hook it up to a circuit  without breaking the sensor?  Multimeter maybe?

I understand this is a fairly vague (even with the length of this post) question, but I have provided all the information I can gather just by looking at the parts.  If anything needs clarification, please let me know and I would be happy to answer any questions to the best of my limited ability.

Any suggestions or advice would be greatly appreciated!
thanks
N8
18  Using Arduino / Displays / Re: LCD background color options? (solved) on: January 17, 2013, 09:33:25 pm

The 8-bit mode is really just a carryover from the olden days when the LCD was hooked onto the data bus of an 8-bit microprocessor and treated just like any other memory mapped device.  It does not provide any added features and there is little reason to consider it except when you are starting out to learn how to control one of these displays on your own, without using a library written by others.

Don



Thanks for the information Don smiley

That does explain the last of my questions when dealing with this LCD screen.
I really should sit down and learn the steps that are covered in the LiquidCrystal library so I know what is going on behind the scenes of the sketch, but for the moment, I am happy to have the library to use and be able to get my current project working with little trouble.
This particular project has been a bit of frustration, and having it working right so far is a relief.
Thank you for filling in some gaps for me, I very much appreciate it!
N8
19  Using Arduino / Displays / Re: LCD background color options? on: January 17, 2013, 05:52:15 pm
Page 3 tells you about 2 colors.
You have the option to have Deep blue by switching on the pixel, or the alternative of Yellow green by turning it off.
It is a monochrome display.

Just take a peek at the remarks to those lines where it says "The Color is defined as the inactive/background color"

ok, so if I understand this correctly, the color deep blue is just a descriptor for when a pixel on the display is on.  otherwise the pixel is the default background color.

the pixels that are on do not look any shade of blue to me, but I guess that is neither here nor there how I would describe it.

That does make sense, even if I don't agree with them on what they are calling deep blue smiley-razz

Thank you for clearing this up for me.  I was about to ask if this might be a feature of 8 bit mode, because I can't seem to find an application where 8 bit mode would even be used.  It was making me wonder if 8 bit was for two color mode. 
This thing sure looks monochrome to me, and it was a bit confusing that they were describing it otherwise.

Very much appreciate both of you taking the time to help me investigate this!
Thank you
N8
20  Using Arduino / Displays / Re: LCD background color options? on: January 17, 2013, 04:35:57 pm
Saw no mention of the display data command in the documentation.
Maybe the same lcd is available elsewhere with another datasheet?


I didn't see it again after it was mentioned on page 3.  I have scoured the data sheet, and even read all three revisions of the manual that have been released.  minor changes made in each revision, but no mention of background color after page 3 in any of them.

I have dismissed this idea twice in the last week, but something keeps drawing me back to it.  It would be a fun addition to my dice roller if the screen could change colors based on mode, or when the dice are "rolling".  it would just be for fun, and the unit works just fine without the addition of a color changing screen, but I do like the idea.  If it wont work, it is really no big deal, I am mostly just following my curiosity at this point.
21  Using Arduino / Displays / Re: LCD background color options? on: January 17, 2013, 04:08:14 pm
Ok, I have played with this a bit, and gotten nothing new to work from.
tried using some code to turn on and off the LED back light, and also used a PWM pin to fade it on and off, and no color change.  all that happens is the LED turns on and off, or fades on and off, which is what I expected, but what the hell, worth a shot, right?

not sure what to make of it, and I don't have enough experience with LCD displays or Arduino in general to know where else to begin trying.

one good thing I got out of this process so far, I am going to use a timer to turn the back light off after some period of inactivity.  save me some battery power.  This is a digital dice project for gaming, and this thing could be sitting on a table left on for quite some time, but only used intermittently, so this makes a nice addition to my code to save the battery and not have to turn the unit on and off for each use smiley
22  Using Arduino / Displays / Re: LCD background color options? on: January 17, 2013, 03:24:16 pm
going to play with some code for this to try it, but at the moment I have the LED back light wired through a toggle switch, to be able to manually turn it on and off, and when the switch is off, all it does is turn the LED off, it doesn't change colors when the back light is off.
The way I read it, there should be some line of code I could write to change the "Display Data" to either 1 or 0 and thus change the color.

it also says that yellow-green is the inactive background color, which would also indicate you have to do something to change the active background color.  though looking at the background on this display, it really doesn't look like it would change color.

The whole wording of it is a bit confusing if you ask me.

I will try and write some code to turn on and off the LED back light and see if that makes a difference over a physical switch, but I don't understand why that would matter.  maybe using PWM to fade it down to off might make a difference?

eh, I honestly have no idea, but thank you for your input, I greatly appreciate it!
23  Using Arduino / Displays / LCD background color options? (solved) on: January 17, 2013, 12:23:01 pm
Hello everyone smiley

I have this LCD - lmb162abc

here is the data sheet

http://www.topwaydisplay.com/Pub/Manual/LMB162ABC-Manual-Rev0.2.pdf

on page three of the data sheet it seems to indicate there are two options for the background color, green and deep blue.
I have been searching the internet for a while now to try and find out how this works, and how to write the code to make it happen, but everything I can find is for RGB LCD's mostly from adafruit.
Am I reading the datasheet wrong, or are there actually two colors available.  It is very possible I have misunderstood what I read and there is only one color available, and it would be model dependent on which color you have.

I am using the LiquidCrystal library to control the LCD, and if it actually does change color, I would very much enjoy being able to do so.  If anyone could show me how to do this, or let me know if I am wrong on my understanding, that would be great!

Thanks in advance for any help provided
N8

edit to correct myself, wrote my post as backlight color, but it's actually the background color

24  Using Arduino / Project Guidance / Re: (not a ) switch case question (anymore...) on: January 14, 2013, 05:14:17 pm
it hangs on 20 for two pushes, then goes to 40, 60, 80, 10, 12, 20, 20, 40, 60.... on like that.
after the first time though, it starts displaying the modes in tens, instead of single and double digits.
This one I know smiley

What's happening is you're overwriting the two digit number with a one digit number... with nothing to write in the second digit, the LCD continues to display what was already there.  Try using sprintf to format your number.  That should get rid of the unwanted 0

HA!  you were right smiley-grin
I should have seen that, it wasn't the first time I ran into that problem, but last time it was much more obvious, I had a whole word that never left the screen.
I took the easy way out for a fix though, I just added a couple of spaces next to the result so it turns off the couple of spaces after every number.

Not sure why that started all of a sudden, but it's fixed now, and I probably just accidentally deleted something when I was rearranging the code...

Thank you so much for pointing out my error!

Now to start having fun with the display, make it a little more showy smiley
25  Using Arduino / Project Guidance / Re: (not a ) switch case question (anymore...) on: January 14, 2013, 10:54:09 am
thinking about an enclosure for this one, and making something permanent out of it.  It's been a struggle, and it would make a fun souvenir when I get it all done.

Have you considered using a cup of some sort as the enclosure? Perhaps with the display in the base so that you shake it, put it down upside down, and see the rolled values displayed in the base? Just make sure nobody tries to drink out of it. smiley


Man, you are full of great ideas!
I have been looking into 3D printers lately, and could even design and print something that could fit the hardware and battery in nice and secure.
very cool, I really did hope this project would turn into something fun and long term, that I could actually use.  I really liked the idea, and its only getting better as I move on!
26  Using Arduino / Project Guidance / Re: (not a ) switch case question (anymore...) on: January 14, 2013, 10:32:57 am
guess I am not doing as well as I hoped...

Tried rearranging the code to take out some elements I thought were redundant (like having the mode select code in both cases.)
now, the dice values displayed are not right again.
The roll results are still good, and the rate they cycle through the dice modes when you push the button is still correct also.
now, when you turn it on, it shows you are in D2 mode, which is correct, from there it goes through D4, D6, D8, D10, D12, then D20 which is also right. 
Here is where it gets odd.
it hangs on 20 for two pushes, then goes to 40, 60, 80, 10, 12, 20, 20, 40, 60.... on like that.
after the first time though, it starts displaying the modes in tens, instead of single and double digits.
on the second pass, the dice modes are still right, but the name for them is wrong.
once again, I cannot see where the code is making the error, so without further ado...

Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(2,3,4,5,6,7);

const int nButton = 11;
const int mButton = 9;
int mode = 0;
int oldMode = 0;
const int Tilt = 8;
int val = 0;
int oldVal = 0;
int state = 0;
int number = 0;


int dValue[] =
{2,4,6,8,10,12,20};

long result;
long resultA;
long resultB;


void setup()
{
  pinMode(Tilt, INPUT);
  pinMode(mButton, INPUT);
  pinMode(nButton, INPUT);
 
  lcd.begin(16,2);
 
  randomSeed(analogRead(0));
}

void loop()
{
  {
    mode = digitalRead(mButton);
    if ((mode == HIGH) && (oldMode == LOW))
    {
      state++;
    }
    if (state >= 7)
    {
      state = 0;
      delay(10);
    } oldMode = mode;
  }
  {
    number = digitalRead(nButton);
    switch(number)
    {
      case 0:
      {
        {
          lcd.setCursor(0,0);
          lcd.print("DigiDice - D");
          lcd.print(dValue[state]);
        }
        val = digitalRead(Tilt);
        if ((val == HIGH) && (oldVal == LOW))
        {
          result = random(1, (dValue[state] + 1));
          lcd.setCursor(0, 1);
          lcd.print("Result = ");
          lcd.print(result);
          lcd.print("       ");
          delay(3000);
        } else
        {
          lcd.setCursor(0, 1);
          lcd.print("Give Me A Shake!");
        }
      }
      break;
   
      case 1:
      {
        {
          lcd.setCursor(0,0);
          lcd.print("Roll Two - D");
          lcd.print(dValue[state]);
        }
        val = digitalRead(Tilt);
        if ((val == HIGH) && (oldVal == LOW))
        {
          resultA = random(1, (dValue[state] + 1));
          resultB = random(1, (dValue[state] + 1));
          lcd.setCursor(0,1);
          lcd.print("R1 = ");
          lcd.print(resultA);
          lcd.print("   R2 = ");
          lcd.print(resultB);
          lcd.print("     ");
          delay(3000);
        } else
        {
          lcd.setCursor(0, 1);
          lcd.print("C'mon...Shake Me!!");
        }
      }
      break;
    }
  }
}

This is where I have it at now.
The mode select part of the code seems to be working right, and I have wrote it several different ways, to test it. 
The code to show the dice value isn't something I changed, and it went from working fine to not.  Don't know what happened.
any help would be awesome.
it is possible I just need fresh eyes on it, and the problem is fairly obvious, but for right now, I am stumped.
27  Using Arduino / Project Guidance / Re: (not a ) switch case question (anymore...) on: January 14, 2013, 09:54:49 am
Rather than adding physical dice, you might continue the Arduino theme and see whether you can make your Arduino output the sound of dice rolling in a cup.

You might also add an accelerometer/tilt switch so that it makes the 'rolling' sound when you shake it, and rolls the dice when you put it down.

sounds like another shopping trip to me smiley-razz

First thoughts on that would be a music shield, or build my own, with an mp3 on an SD card of a dice rolling sound.

I have been wanting to pick up an accelerometer and play with it, and this is as good an excuse as any!

Great ideas BTW, and thanks for the suggestions.  It would keep the project that much more compact not having to build a chamber large enough for a die to roll around in.

I also like the shake then put down to roll idea quite a bit.  Anything to increase the sensation of rolling dice would be a good thing in my opinion.
thinking about an enclosure for this one, and making something permanent out of it.  It's been a struggle, and it would make a fun souvenir when I get it all done.  Could even have two larger modes, one for d2 - d20 for strategy gaming, and one that is just a set of multiple six sided dice for yatzee style, so you can roll both ways if you choose.
Lots of expansion could be done on this project, and this could really be a neat addition to any game where dice are involved smiley
Heck, I might even try for a third option, and come up with my own dice based game that could be played with two (or more?) players, and could be played all on the arduino with no external game mechanics involved.
Wonder how long it would take me to find the limits of the arduino with a dice rolling project?...
28  Using Arduino / Project Guidance / Re: (not a ) switch case question (anymore...) on: January 14, 2013, 08:08:55 am
actually, I might not even need the "    " anymore.
that was there to clear the rest of the line earlier on.

I did fix the flicker problem after all.
at some point I must have deleted the line of code that initializes the screen size and positions
(lcd.begin(16,2))
without that, it was writing the data over and over on the whole screen.  The only reason text was visible at all is because of the repetitiveness of the message...

Now that I have put the initialization code back in the setup, it works like a charm, and is quite beautiful if you ask me smiley-razz

May not be the most efficient way to do it ( I am assuming it isn't anyway)  but it works perfectly, and I quite enjoy it.
Now to add some effects to make it a bit more fun to watch.
trying to figure out some simple animation to represent the dice rolling for a moment before displaying the results.

Even had an idea to mount this in a project box, and make a small box inside the project box that would hold an actual dice.  That way, when you shake the dice roller, there is a real dice rolling sound to go along with the shaking smiley  (kind of like the sound when you shake dice in a cup while playing yatzee.  Matter of fact, this kind of makes me want to make a whole new code specifically to handle dice rolling for yatzee.  building the new one around a full set of yatzee dice, and being able to roll them all at once, just like in the real game.

which makes me wonder how hard it would be to write code to play actual yatzee on the arduino would be....
good lord, I am getting ahead of myself here (to be honest, I have never played yatzee, so I don't know all the rules, but I know the game is structured around dice, so it has my brain spinning)

29  Using Arduino / Project Guidance / Re: (not a ) switch case question (anymore...) on: January 14, 2013, 07:34:14 am
This bit of code does things in the wrong order:
Code:
     state++;
      {
        lcd.begin(16,2);
        lcd.print("DigiDice - D");
        lcd.print(dValue[state]);
      }
    }
    if (state > 6)

You print the new dice value before you do the 'if(state > 6)' check to reset it to zero. The '1' you're seeing on the display is just whatever happens to be in the memory location after the last dice.

A better way to do this would be like this:

Code:
     // DICE_COUNT is the number of elements in the dValue array
      state = (state+1) % DICE_COUNT;
      lcd.begin(16,2);
      lcd.print("DigiDice - D");
      lcd.print(dValue[state]);

you are 100% correct sir!
while you posted that, I had accidentally stumbled on the answer myself, but hadn't realized it yet, or why.
I am very nearly successful at my next stage of complexity with this project.
here is what I am doing with it now....

There is a push button to select through the range of dice modes.
there is a toggle switch to select rolling one dice or two dice at a time. (both dice must be of the same value though, ex - two d6.)
I can get the LCD to display the correct dice mode all through the count now, and I can get two different results with one shake of the dice.

my only problem now is the LCD seems to be trying to display both modes at the same time, and it makes the words flicker like mad, and is a bit hard to read everything.
I am using a switch case at the moment to handle switching between one and two dice per throw.  I originally wrote it as an if/else, but changed it to a switch to see if that would cure my screen flicker.  It seems to have helped a bit, but it is still very much an issue.
I am working my way through the LCD examples now trying to find out how to change the number of dice, and print two completely different screen readouts, without the flicker
if that makes any sense...

here is the code as I have it wrote now...
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(2,3,4,5,6,7);

const int nButton = 11;
const int mButton = 9;
int mode = 0;
int oldMode = 0;
const int Tilt = 8;
int val = 0;
int oldVal = 0;
int state = 0;
int number = 0;

int dValue[] =
{2,4,6,8,10,12,20};

long result;
long resultA;
long resultB;


void setup()
{
  pinMode(Tilt, INPUT);
  pinMode(mButton, INPUT);
  pinMode(nButton, INPUT);
  
  randomSeed(analogRead(0));
}

void loop()
{
  mode = digitalRead(mButton);
  if ((mode == HIGH) && (oldMode == LOW))
  {
    state++;
  }
  if (state > 6)
  {
    state = 0;
    delay(10);
  }
  oldMode = mode;
  {
    number = digitalRead(nButton);
    switch(number)
    {
      case 0:
      {
        {
          lcd.begin(16,2);
          lcd.print("DigiDice - D");
          lcd.print(dValue[state]);
        }
        val = digitalRead(Tilt);
        if ((val == HIGH) && (oldVal == LOW))
        {
          result = random(1, dValue[state] + 1);
          lcd.setCursor(0, 1);
          lcd.print("Result = ");
          lcd.print(result);
          lcd.print("       ");
          delay(3000);
        } else
        {
          lcd.setCursor(0, 1);
          lcd.print("Give Me A Shake!");
        }
      }
      break;
      case 1:
      {
        {
          lcd.begin(16,2);
          lcd.print("Roll Two - D");
          lcd.print(dValue[state]);
        }
        val = digitalRead(Tilt);
        if ((val == HIGH) && (oldVal == LOW))
          {
            resultA = random(1, dValue[state] + 1);
            resultB = random(1, dValue[state] + 1);
            lcd.setCursor(0,1);
            lcd.print("R1 = ");
            lcd.print(resultA);
            lcd.print("   R2 = ");
            lcd.print(resultB);
            lcd.print("     ");
            delay(3000);
          } else
          {
            lcd.setCursor(0, 1);
            lcd.print("C'mon...Shake Me!!");
          }
        }
        break;
      }
    }
}

I seem to be off on my curly brackets somewhere, because my indenting is messed up a bit, but I will fix that when I have the whole code in working order.

off to keep researching, but will be happy to hear any suggestions to stabilize my display smiley

ETA:  I should mention that when you shake the "dice", the display does stabilize, and very clearly prints everything it is supposed to.
This makes me think I should have the mode selecting code in both cases, like the Tilt code, and maybe that will work it out.
seems very redundant to me, but this is how we learn smiley-wink

Again, very happy to take suggestion improvements and general criticism on the project!
be brutal if need be smiley
30  Using Arduino / Project Guidance / Re: (not a ) switch case question (anymore...) on: January 14, 2013, 06:24:01 am
I am having trouble pinning it down also.
if you push the button again, it goes to D4 like it is supposed to.
The only mode that doesn't display correctly, no matter how many times you cycle through, is D2.

I have tried adding and subtracting 1 at various points in the code where the display is called, but that only seems to effect my dice results, or limits my results by one.
I am honestly stumped, but for the moment it is a minor issue, and I have moved on.
When I get the rest of the functions I am trying to work out done and working correctly, I will probably go back and see if I can fix it.
If it can't be fixed, then so be it, I could have done worse in my opinions smiley-razz

Out of curiosity, do you mind explaining how you would have handled it?
I am always interested in learning other ways to do things with the Arduino.  The more ways you can do one things, the more tools you have in the toolbox smiley

I seem to be nutty for curly brackets, I always end up with many of them smiley-razz
Pages: 1 [2] 3 4