Pages: 1 [2]   Go Down
Author Topic: tx & rx pins  (Read 2796 times)
0 Members and 1 Guest are viewing this topic.
South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pins   Description   Arduino Pin#
2   Serial to PC (debugging)   0,1
2   Shift LCD               12,13
1   Motor (on/off)            A4 (18)
1   Motor Relay 2P2T (reverse)   A3 (17)
1   Optical Detector           A2 (16)
1   I/O Knock sensor        A1 (15)
1   I/O Photocell              A0 (14)
1   Solenoid (water valve)   10
1   Flow Sensor                  2
7   Keypad                         3,4,5,6,7,8,9
1   I/O for Audio                  11
19   Total   

This is my pin line up
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's my rough draft.  Ugh.  If anyone would like to re-model it into real code I would be VERY happy.  I've only ever coded in basic before a week ago, so this probably looks 'basic'.
All I worked on was the actual water flow part of the code.  I figured I should get that up and running first, before adding any frills like audio feedback or light sensing photocells...



attatchment removed, it was terrible!
« Last Edit: February 23, 2011, 03:50:06 pm by SouthernAtHeart » Logged

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

At a quick glance the code looks reasonable but I doubt you have compiled it yet.

Quote
so this probably looks 'basic'.
Yep

//Load Settings from eeprom
LoadSettings;

try

LoadSettings();

I'll look a bit more later.

______
Rob

Logged

Rob Gray aka the GRAYnomad www.robgray.com

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think my code needs a LOT of help!  If anyone can tell what I'm trying to have it do and can fix it up a bit in a few minutes, they'll save me hours...
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My first attempt was pretty bad, so I deleted it.  This seems a lot more concise.  It even compiles!
Could someone please look it over and tell me if it will work? 
My Uno will be here tomorrow.

* Coffe_Project_V_2.zip (3.53 KB - downloaded 13 times.)
Logged

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

For someone who's never written any C I think you've done well.

I have not looked at the overall logic, just the syntax and local issues.


In Confirm_Pour()

Code:
do
  {
    if (key == '*') PourWater;  //turn on the water
    if (key == '#')
    {
      srlcd.clear();
      srlcd.print("Action canceled");
      delay (5000); //wait for user to read message
      return;  //go back to the main loop routine
    }
  }
  while(key = NO_KEY);   

Two problems here. "key" is never updated here so there's no need for a while loop.

  while(key = NO_KEY);   

Assignment instead of comparison.

 PourWater =>  PourWater()

Code:
   while (key != NO_KEY)
    {
      key = keypad.getKey();
      //just waiting for a key press here to start water flow...
    }
Shouldn't these be "key == NO_KEY"?

Code:
void CountPulse()
{
   FlowSensorCount++;  //increases the count from the interupt pin 2
}
Is the interrupt signal debounced?

in UserSettings()

 while (key != '1' || key != '0'); =>  while (key != '1' && key != '0');

I'll keep browsing.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!  I'm trying to take in everything you said, I got most of it.
What about the Confirm_Pour() function, I will need the while statement or some kind of loop statement, won't I.  It's to give the user the option to cancel, after they enter a number.
How does this look:
Code:
void Confirm_Pour()
{
  srlcd.clear(); // Clear display, set cursor position to zero
  srlcd.print(key);  //LCD display the number they selected
  srlcd.print(" cups"); //plus cups
  srlcd.setCursor(0, 1); // Sets cursor position to the 2nd line
  srlcd.print("Press '*' to start or # to cancel"); //This needs to scroll across the 2nd line somehow so it can all be read
  do
  {
    key = keypad.getKey();
    if (key == '*') PourWater();  //turn on the water
    if (key == '#')
    {
      srlcd.clear();
      srlcd.print("Action canceled");
      delay (5000); //wait for user to read message
      return;  //go back to the main loop routine
    }
  }
  while(key == NO_KEY);   
}

Quote
while(key = NO_KEY); 
fixed

Quote
PourWater =>  PourWater()

fixed

Quote
Code:
   while (key != NO_KEY)
    {
      key = keypad.getKey();
      //just waiting for a key press here to start water flow...
    }
Shouldn't these be "key == NO_KEY"?
yes, fixed


Quote
Code:
void CountPulse()
{
   FlowSensorCount++;  //increases the count from the interupt pin 2
}
Is the interrupt signal debounced?
I reckon it doesn't need to be, does it?  It's an interrupt signal on pin 2 coming from this flow sensor (hall effect):
http://www.seeedstudio.com/depot/datasheet/water%20flow%20sensor%20datasheet.pdf


Quote
while (key != '1' || key != '0'); =>  while (key != '1' && key != '0');
Are you sure?  That's actually what I had first, but then I thought, key will NEVER be 1 and 0 at the same time so the while statement will never end...  I'll go back and re-reason through it.

Quote
I'll keep browsing.
THANKS!
Logged

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

I said

Quote
Two problems here. "key" is never updated here so there's no need for a while loop.

because at the time there was no

Code:
key = keypad.getKey();
inside the loop. Now there is so yes you need the loop.

The flow sensor data sheet doesn't spec the exact nature of the output signal. However for the moment I think it's safe to assume it's clean, you can always add debouncing later if needed.

Quote
That's actually what I had first, but then I thought, key will NEVER be 1 and 0
Maybe, I always have trouble getting my head around these multiple !=, ==, !!, && constructs. So how about we remove the ambiguity and do this.

Code:
do
    {
      key = keypad.getKey();  //check for key event
      if (key = '0') return;       //action canceled
      if (key = '1')
      {
        for (int i=0; i < 5; i++){
          MySettings.mySensVals[i] = 0;  //reset sensor values
        }
        EEPROM_writeAnything(0, MySettings);  //save the settings
        srlcd.print("Completed!");
        delay(4000);  //wait for user to read message
        return;
      }
    }
  while (1);

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
do
    {
      key = keypad.getKey();  //check for key event
      if (key = '0') return;       //action canceled
      if (key = '1')
      {
        for (int i=0; i < 5; i++){
          MySettings.mySensVals[i] = 0;  //reset sensor values
        }
        EEPROM_writeAnything(0, MySettings);  //save the settings
        srlcd.print("Completed!");
        delay(4000);  //wait for user to read message
        return;
      }
    }
  while (1);

I like it.  I can read it.  I looked at the conglomeration of NOTs, ORs, AND's, and WHILEs, and still couldn't get it.
I can follow this!
Logged

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

Yes it's important for code to be clear to a human as well as correct for the computer. And just to show that I don't practice what I preach, here's a line from the app I'm writing now.

Code:
Serial.print (isprint(((*(start + i)) & 0xFF)) ? (*(start + i)& 0xFF) : '.', BYTE);

Quick, you have 5 seconds to tell me what this does smiley

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes it's important for code to be clear to a human as well as correct for the computer. And just to show that I don't practice what I preach, here's a line from the app I'm writing now.

Code:
Serial.print (isprint(((*(start + i)) & 0xFF)) ? (*(start + i)& 0xFF) : '.', BYTE);

Quick, you have 5 seconds to tell me what this does smiley

______
Rob

...errrr, ummmm...
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want to use rx tx pins, why breaking head when there is software serial available. Anyway good effort.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@graynoman
writes printable chars in a hex(?)dump from some start address  ...

You can sent it to - http://www.ioccc.org/ - but I guess it is to readable smiley
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

He he, yes it's the bit at the end of a HEX dump that prints a character or a dot if the value is non-printable.

I remember those obfuscated C contests, code in the shape of an hour glass etc. I'll have to see if I can make my code harder to understand in future smiley

I also remember when C++ first came out, I saw a program that was something like this

Code:
main () {
   int i;
}

The entire program was written in the constructor for an integer or something.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The nicest I recall was

#include "/dev/tty"

so you could type in the whole application (no errors allowed) from your head into the command console. never succeeded

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: 1 [2]   Go Up
Jump to: