Show Posts
Pages: 1 [2] 3 4 ... 7
16  Using Arduino / Programming Questions / Re: Passing a function another function on: February 10, 2013, 11:49:02 am
Thanks guys!

I worked your code into mine Johncc, and it is telling me
Code:
barbotV18:40: error: variable or field 'checkglass' declared void
barbotV18:40: error: 'drinkfunction' was not declared in this scope

How should I declare drinkfunction- what type of pointer is it?


Edit:  spelling.  Drives me nuts lol
17  Using Arduino / General Electronics / Re: Too many shift registers? on: February 10, 2013, 11:38:34 am
I fixed it.

First I moved the caps much closer to the Vcc pins, and even shortened their leads since I read that is advisable.

That didn't fix it (although I'm sure it's good practice) but while doing it I noticed that when the arduino is reset, when it comes back online it shifts the last bit that it was given out to the registers.

This got me thinking...  the problem must be with my latch!  The fact that it shifts the last bit it had out means that the data and clock pins are doing what they should, but latch sure as hell isn't!

I started my 8th check of my connections, but this time I put special emphasis on checking the signal chain of latch- and I found it.

on the very last (6th) register, output enable was accidentally tied to latch  smiley-small

Apparently it just slipped into the wrong row as they are adjacent, and it can be difficult to see if you are not looking exactly for it.

I re-routed the OE to the row it should be in, and all is well again.  Thank you to all who helped me find it- as by examining my code and telling me it wasn't the issue, and by letting me know that 6 shift registers are NOT too many, you got my mind focusing on the real problem.

I'm back in business!!!
18  Using Arduino / Programming Questions / Re: Passing a function another function on: February 10, 2013, 02:21:22 am
So I should try

Code:
typedef void f_type(void);

void glasscheck( f_type *f) {
  switch (dataread)
  {
  case 1:
   Serial.println("1 shotglass present");
   turnwheel(1);
   (f);
   turnwheel(0);
    break;

  case 3:
   Serial.println("2 shotglasses present");
   turnwheel(1);
   (f);
   turnwheel(2);
   (f);
   turnwheel(0);
    break;
   
  case 7:
   Serial.println("3 shotglasses present");
   turnwheel(1);
   (f);
   turnwheel(2);
   (f);
   turnwheel(3);
   (f);
   turnwheel(0);
    break;
   
  case 15:
   Serial.println("4 shotglasses present");
   turnwheel(1);
   (f);
   turnwheel(2);
   (f);
   turnwheel(3);
   (f);
   turnwheel(4);
   (f);
   turnwheel(0);
    break;
   
  case 31:
   Serial.println("5 shotglasses present");
   turnwheel(1);
   (f);
   turnwheel(2);
   (f);
   turnwheel(3);
   (f);
   turnwheel(4);
   (f);
   turnwheel(5);
   (f);
   turnwheel(0);
    break;
   
  case 32:
   Serial.println("1 old fashioned glass present");
   turnwheel(6);
   (f);
   turnwheel(0);
    break;
   
  case 64:
   Serial.println("1 highball glass present");
   turnwheel(7);
   (f);
   turnwheel(0);
    break;

     }
}


void VodkaOnRocks(void) {
    pour(1, vodkas, 8);
     End();
}


And then call it like

Code:
glasscheck(VodkaOnRocks);

?
19  Using Arduino / General Electronics / Re: Too many shift registers? on: February 10, 2013, 02:12:07 am
Proof that when passed

Code:
      digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, 255);
  shiftOut(data, clock, MSBFIRST, 255);
  shiftOut(data, clock, MSBFIRST, 255);
  shiftOut(data, clock, MSBFIRST, 255);
  shiftOut(data, clock, MSBFIRST, 255);
  shiftOut(data, clock, MSBFIRST, 255);
      digitalWrite(latch, 1);

All registers WILL work, but as stated before, not as expected. For example- this code WILL light all the register's LEDs, but not at first...  it first lights the last five registers, then a minute later the first will light up.  Also, if I then pass it

Code:
digitalWrite(latch, 0);  // This should turn off all lights on all registers... it doesn't for some reason- they just stay on...
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 0);
      digitalWrite(latch, 1);

they won't turn off... they just stay on.  OR if I try to just turn on ONE LED somewhere- no dice.  It's weird, I'll see the correct one flicker for a split second right after loading the code, and again if I open the serial monitor, but thats it.  Sometimes if I reset the arduino then the correct single LED will light, but once again it will not respond to shiftOut commands designed to shut it off again. 

It's frustrating because with only 3 shift registers I had this thing running perfectly, and now I can't figure out whats wrong. 

Anyways, here is the proof that the shift register WILL light everything up when passed the code above- so they ARE wired correctly enough to address all their outputs at least...

20  Using Arduino / General Electronics / Re: Too many shift registers? on: February 10, 2013, 01:48:39 am
Ha!  Yeah, that would be a bad idea.
21  Using Arduino / Programming Questions / Passing a function another function on: February 10, 2013, 01:45:41 am
Hello everybody!

So, I am trying to get my checkglass(); function to accept another function as an input condition, so it can use it throughout it's switch case parameters.  In my usage, the function I will be passing will be a drink recipe.  If the recipe is a shot, dataread counts how many shot glasses are present via switches attached by ShiftIn.  It then rotates the wheel between each shot, pouring the passed recipe each time before finally returning the wheel back to it's starting position.  If I can figure out how to pass a function another function, I can use the checkglass(); function like this:

Code:
checkglass(adiosMFer);

And that will make things very simple for me when I am typing up 200 some recipes.  The recipe functions have no input conditions.
Here is what I tried, and it didn't work:

Code:
void checkglass(void (*f))
{

 switch (dataread)
  {
  case 1:
   Serial.println("1 shotglass present");
   turnwheel(1);
   (*f);
   turnwheel(0);
    break;

  case 3:
   Serial.println("2 shotglasses present");
   turnwheel(1);
   (*f);
   turnwheel(2);
   (*f);
   turnwheel(0);
    break;
   
  case 7:
   Serial.println("3 shotglasses present");
   turnwheel(1);
   (*f);
   turnwheel(2);
   (*f);
   turnwheel(3);
   (*f);
   turnwheel(0);
    break;
   
  case 15:
   Serial.println("4 shotglasses present");
   turnwheel(1);
   (*f);
   turnwheel(2);
   (*f);
   turnwheel(3);
   (*f);
   turnwheel(4);
   (*f);
   turnwheel(0);
    break;
   
  case 31:
   Serial.println("5 shotglasses present");
   turnwheel(1);
   (*f);
   turnwheel(2);
   (*f);
   turnwheel(3);
   (*f);
   turnwheel(4);
   (*f);
   turnwheel(5);
   (*f);
   turnwheel(0);
    break;
   
  case 32:
   Serial.println("1 old fashioned glass present");
   turnwheel(6);
   (*f);
   turnwheel(0);
    break;
   
  case 64:
   Serial.println("1 highball glass present");
   turnwheel(7);
   (*f);
   turnwheel(0);
    break;

     }
}

any suggestions?  The error code comes up as:
Code:
barbotV18.ino: In function 'void loop()':
barbotV18:218: error: 'checkglass' was not declared in this scope
barbotV18.ino: In function 'void checkglass(void*)':
barbotV18:1288: error: 'void*' is not a pointer-to-object type

However it only tells me "'checkglass' was not declared in this scope" when I make it
Code:
void checkglass(void (*f))

if I leave it
Code:
void checkglass()

It doesn't give me any crap about not being declared in this scope.  Additionally, "'void*' is not a pointer-to-object type" is a mystery to me... I still absolutely blow at using pointers.  I'll get it eventually... I hope. 
22  Using Arduino / General Electronics / Re: Too many shift registers? on: February 09, 2013, 11:59:05 pm
Also, as noted above, I have decoupling 0.1uF capacitors plugged in just before each registers Vcc in.  The caps are bridging Vcc and Gnd.

Here are a few pic of the full setup- it's difficult to see exactly what my wiring is doing in a picture, but I think the BarBot is getting pretty awesome!

The LEDs on the far left are standing in for three transistor array chips.  I had to remove the chips once I discovered the shift registers acting funny- I put the LEDs in for ease of troubleshooting for now.  The LEDs you see on the far right are RGB LEDs- they will be for effect lighting in the finished project.  The switches will sit in the glass holsters to let the BarBot know if a glass is in place.  That way it won't just pour booze on the counter  smiley-eek  In addition, if there is more than one shot glass present it will turn the wheel to the next present glass and repeat the recipe- up to five shots at a time!







Here is a close up shot so you can see (kinda) where I have my decoupling caps.  The green leads (or in the case of register #1 and #3, yellow) right next to the caps are going to the chip's Vcc line.



And here is a mock-up of the wheel!
23  Using Arduino / General Electronics / Re: Too many shift registers? on: February 09, 2013, 11:36:31 pm
I mess around with output enable because in my main project, should power loss occur this will help to keep my liquor pumps from arbitrarily spewing liquor when power returns.  I just snagged this code section from the main project, and my arduino is still wired for the main project, so since I have a pull-up resistor on it I at least have to control it or it won't let anything out.

As far as the wiring...  I don't have a diagram, it would take too long to create.  What I have done is make sure all the registers work properly.  I have went over their wiring 5 times now just to be extra sure they are wired up correctly.  When I was daisy-chaining 3 of them it worked like a charm, but as soon as I added 3 more it's miss-behaving.

If I send out six bytes of 0XFF it lights up the furthest FIVE registers, but not the 1st one (closest in the chain to the arduino) Which makes no sense to me either- six bytes should hit all six registers!  Even stranger still, if I send EIGHT bytes out, then all six registers light all of their LEDs to include register #1 (the one closest to the arduino)

Why would eight bytes be required to light up six registers?  Should I put a slight delay between ShiftOut commands you think, so it can keep up or something?
24  Using Arduino / General Electronics / Re: Too many shift registers? on: February 09, 2013, 10:45:58 pm
I have decoupling caps installed just before each registers incoming voltage, (0.1uF)

As for the "copy for forum" business, I'll make sure I do it the other way from now on.
25  Using Arduino / General Electronics / Too many shift registers? on: February 09, 2013, 09:55:21 pm
Hello again everybody!

I have 6 74HC595 Shift Registers daisy chained...  Is that too many?  It seems to be acting screwy.  By "screwy" I mean it is not lighting the LEDs I would expect, when I would expect it to do so.  Perhaps I am missing something code-wise?  I have tested and verified the chips and connections individually, and all is well.  Additionally, when the arduino 1st loads I have noticed that the intended LEDs flicker for a split second, then never come on again.  OR after a reset the intended LEDs will come on if they are in registers 4, 5, or 6- but then they just stay on ignoring the ender(); function altogether.

Here is my debug code, to try to figure out what is going on:

Quote

const int data = 6;           
const int clock = 7;
const int latch = 8;
const int outputenable = 5; 
const int masterreset = 4;
const byte shiftoutarray[] = {0, 1, 2, 4, 8, 16, 32, 64, 128};  // NOTE: I only want to light one LED from any given register at a time, which is why these bytes are like this
const int ON = HIGH;
const int OFF = LOW


void setup()  {
 pinMode(data, OUTPUT);  //begin shift register pinmodes
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
  pinMode(outputenable, OUTPUT);
  pinMode(masterreset, OUTPUT);
  Serial.begin(9600);

 digitalWrite(masterreset, 0);
  digitalWrite(outputenable, 1);
delay(20);

  digitalWrite(masterreset, 1);
  digitalWrite(outputenable, 0);
  digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]); 
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]); 
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  digitalWrite(latch, 1);
  digitalWrite(outputenable, 1);
  
  delay(20); 
  digitalWrite(outputenable, 0);  // All of this was just to make sure the registers are clear at startup
  
}

void loop()  {
  
  light();
  delay(5000);
  
  ender();
  delay(1000);
  
}



void light()
{
      digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[1]); //This should light the 1st LED in my 3rd register
  shiftOut(data, clock, MSBFIRST, shiftoutarray[4]); //This should light the 4th LED in my 2nd register
  shiftOut(data, clock, MSBFIRST, shiftoutarray[5]); //This should light the 5th LED in my 1st register
      digitalWrite(latch, 1);
             Serial.println("should be lit");

}
  
  void ender()
{
      digitalWrite(latch, 0);  // This should turn off all lights on all registers... it doesn't for some reason- they just stay on...
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
      digitalWrite(latch, 1);
            Serial.println("should be off");


}
 


Any insight you can provide would be greatly appreciated!
26  Using Arduino / General Electronics / Re: Digital pins 0-3 on: February 03, 2013, 06:41:24 pm
That would be the reason, then!  I AM using Serial.begin(9600); and Serial.printin(); commands.

That must be why it's not responding to my other requests of it.  You just taught me something new- thanks!
27  Using Arduino / General Electronics / Re: Digital pins 0-3 on: February 03, 2013, 04:17:27 pm
Well, through shiftin experiments I have found that both pins 0 and 1 are useless for a clock or latch pin, but that pin 0 works very well as a data pin IF disconnected during upload as mentioned above.  Pins 2 and 3 seem to be able to run the clock and latch pins just fine.

Pin 1 is just plain useless.  It doesn't care if you set it to input or output, or try to digitalWrite to it or anything... it just does whatever it wants to do.  Would be nice to be able to put it to work.  "Get a job Pin 1!"  lol

28  Using Arduino / General Electronics / Re: Digital pins 0-3 on: February 03, 2013, 03:39:26 pm
Upload as in, a new version of the program from the Arduino IDE software, or upload data to/from the arduino via the Ethernet shield?

I am thinking you mean the former, which would mean I was good to use pins 0 and 1, but before pressing the upload button in the IDE, I should disconnect any connections there first, and re-attach them after upload is complete.  Right?
29  Using Arduino / General Electronics / Digital pins 0-3 on: February 03, 2013, 12:54:31 pm
Why do I never see them used in code?  Are they OK to use?

I am using them for a shiftin operation because all my other digital pins are used up, and I can't seem to get it to work properly.  I am asking here to see if maybe there is something special about those pins that I don't know...  I always thought it was funny no one seemed to use them in any sample code I have come across.

For full disclosure, I am using them through an Ethernet shield, but I think the Ethernet shield only uses pins 10, 11, and 12 for comunication so 0, 1, 2, and 3 should be OK?
30  Using Arduino / Programming Questions / Re: Triple Shift Register question on: February 02, 2013, 09:19:24 pm
Hmm, some interesting results:

So I did the OE/pull-up resistor method, and it definitely kept the outputs off, but as soon as they were turned back on- there were those arbitrary bits staring me in the face...  The OE just stopped them from going out, but they were there waiting once output was enabled again...

So I did a combination of both, I used a pull-up resistor on the OE, and a pull-down resistor on the MR, using arduino pins to control both.  This is more I/O than I would LIKE to use for these registers...  but I guess it is a necessary evil if I want to guard against the inevitable "power-outage-liquor-spewing-barbot" incident.

HOWEVER- while this measure DRASTICALLY reduced the issue, it has not made it go entirely away!  Not every time, but say, one out of every three times I plug the arduino back into power, the LEDs will flicker on very briefly, in the same arbitrary manner as before except much briefer in duration (heck, they used to just remain on permanently until reset!  So this is a huge improvement.)

I am currently unsure if this is even a concern- the output may be too fast for my pumps to even move any liquid past the check valves at all (which is probably the case, so I am not very worried about it.)  I am going to consider this problem FIXED unless I notice otherwise later in pump testing.

I just thought it was interesting to note for anyone interested- that even with all these measures in place, the arbitrary flicker remains!  (Albeit reduced to acceptable levels of operation)

Pages: 1 [2] 3 4 ... 7