Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Serial.print not printing... on: January 09, 2013, 10:40:24 pm
Well, now it works!  That was a stupid mistake, must be getting late lol. 

Thanks Pete!

Ryan
2  Using Arduino / Programming Questions / Re: Serial.print not printing... on: January 09, 2013, 10:29:23 pm
Better question, can I simply make a math statement that converts 56 into 0056?
3  Using Arduino / Programming Questions / Re: Serial.print not printing... on: January 09, 2013, 10:27:55 pm
Well, actually, NOW I;m getting something, just not the right thing...  I'm getting 054?
4  Using Arduino / Programming Questions / Re: Serial.print not printing... on: January 09, 2013, 10:23:09 pm
Thanks, went in and corrected, but still nothing smiley-sad
5  Using Arduino / Programming Questions / Serial.print not printing... on: January 09, 2013, 10:15:50 pm
Heres is my whole code:
Code:
//declare variables
int TX = 3;
int RX = 4;
int LC = 5;
int LC_IN = 0;
int AB_IN = 1;
int MB_IN = 3;
int AMP_RELAY = 6;
int loadcell;
int ampbatt;
int mainbatt;
int compread;
int compCONNECT = 0;
int count = 0;

void setup()
{
  Serial.begin(9600); //Begin arduino-computer serial communication at 9600baud.
 
  //declare pin modes
  pinMode(TX, OUTPUT);
  pinMode(RX, OUTPUT);
  pinMode(LC, OUTPUT);
  pinMode(AMP_RELAY, OUTPUT);
 
  //turn on amp relay
  digitalWrite(AMP_RELAY, HIGH);
 
  //flash LEDs rapidly 3x
  while (count < 4)
  {
    FLASH(TX, 10);
    FLASH(RX, 10);
    FLASH(LC, 10);
    delay(200);
    count++;
  }
 
  //send initialization code to the computer and wait for
  //a response before continuing
  while (compCONNECT == 0)
  {
    Serial.println("12345"); //send initialization code
    FLASH(TX, 100);
   
    loadcell = analogRead(LC_IN); //get loadcell signal
   
    //check for loadcell voltage
    if (loadcell > 0)
    {
      FLASH(LC, 100);
    }
   
    delay(1000);
    compread = Serial.read(); //check for computer response
    Serial.flush();
    if (compread > '0')
    {
     compCONNECT = 1;
     FLASH(RX, 100);
    }
    else
    {
      compCONNECT = 0;
    }
  }
}

void loop()
{
 
  loadcell = analogRead(LC_IN); //get loadcell signal
   
    //check for loadcell voltage
    if (loadcell > 0)
    {
      FLASH(LC, 6);
    }
 
  mainbatt = analogRead(MB_IN);
  ampbatt = analogRead(AB_IN);
 
  compread = Serial.read(); //check for computer response
    Serial.flush();
    if (compread > '0')
    {
     compCONNECT = 1;
     FLASH(RX, 6);
    }
   
  FLASH(TX, 6);
  if (loadcell = 0)
  {
    Serial.print("000");
    Serial.print(loadcell);
  }
  else if (loadcell < 10)
  {
    Serial.print("00");
    Serial.print(loadcell);
  }
  else if (loadcell < 100)
  {
    Serial.print("0");
    Serial.print(loadcell);
  }
 
 
 
  if (ampbatt = 0)
  {
    Serial.print("000");
    Serial.print(ampbatt);
  }
  else if (ampbatt < 10)
  {
    Serial.print("00");
    Serial.print(ampbatt);
  }
  else if (ampbatt < 100)
  {
    Serial.print("0");
    Serial.print(ampbatt);
  }
 
 
 
  if (mainbatt = 0)
  {
    Serial.print("000");
    Serial.println(mainbatt);
  }
  else if (mainbatt < 10)
  {
    Serial.print("00");
    Serial.println(mainbatt);
  }
  else if (mainbatt < 100)
  {
    Serial.print("0");
    Serial.println(mainbatt);
  }
 
 
  delay(1);
}

int FLASH(int LED, int time)
{
  digitalWrite(LED, HIGH); //turn on TX_LED
  delay(time); //wait TIME
  digitalWrite(LED, LOW); //turn off TX_LED
}


My problem is in here (I think):
Code:
if (loadcell = 0)
  {
    Serial.print("000");
    Serial.print(loadcell);
  }
  else if (loadcell < 10)
  {
    Serial.print("00");
    Serial.print(loadcell);
  }
  else if (loadcell < 100)
  {
    Serial.print("0");
    Serial.print(loadcell);
  }
 
 
 
  if (ampbatt = 0)
  {
    Serial.print("000");
    Serial.print(ampbatt);
  }
  else if (ampbatt < 10)
  {
    Serial.print("00");
    Serial.print(ampbatt);
  }
  else if (ampbatt < 100)
  {
    Serial.print("0");
    Serial.print(ampbatt);
  }
 
 
 
  if (mainbatt = 0)
  {
    Serial.print("000");
    Serial.println(mainbatt);
  }
  else if (mainbatt < 10)
  {
    Serial.print("00");
    Serial.println(mainbatt);
  }
  else if (mainbatt < 100)
  {
    Serial.print("0");
    Serial.println(mainbatt);
  }

What I want it to do is to add zeros on to each integer to make then four digits... ie if loadcell was 1, ampbatt was 834, and main batt was 56, the line would read as: 000108340056.

Now, the zeros come up, but the integers themselves do not...

Help!?

Thanks,
Ryan
6  Using Arduino / Programming Questions / Re: While loop falsely ends... on: January 09, 2013, 07:53:51 pm
Thanks for the responses.  Was very pressed for time and totally forgot about code snippets smiley-sad  Also, very new to C++, very used to VB.net, so I was used to:
Code:
count = count + 1
  Will go through and change that.  Arrch, thanks for bring those to my attention.  Its works now smiley
7  Using Arduino / Programming Questions / While loop falsely ends... on: January 09, 2013, 06:08:00 pm
In the following code, the while loop only runs once, then stops?

//declare variables
int TX_LED = 3;
int RX_LED = 4;
int LC_LED = 5;
int LC_IN = 0;
int AB_IN = 1;
int MB_IN = 3;
int AMP_RELAY = 6;
int loadcell;
int ampbatt;
int mainbatt;
int compread = -1;
int compCONNECT;
int count = 0;

void setup()
{
  Serial.begin(9600); //Begin arduino-computer serial communication at 9600baud.
 
  //declare pin modes
  pinMode(TX_LED, OUTPUT);
  pinMode(RX_LED, OUTPUT);
  pinMode(LC_LED, OUTPUT);
  pinMode(AMP_RELAY, OUTPUT);
 
  //turn on amp relay
  digitalWrite(AMP_RELAY, HIGH);
 
  //flash LEDs rapidly 3x
  while (count < 4)
  {
    TX_FLASH(10);
    RX_FLASH(10);
    LC_FLASH(10);
    delay(200);
    count = count + 1;
  }
 
  while (compCONNECT = 0);
  {
    Serial.println("12345");
    TX_FLASH(100);
    delay(1000);
    compread = Serial.read();
   
    if (compread > 48)
    {
     compCONNECT = 1;
     RX_FLASH(100);
    }
    else
    {
      compCONNECT = 0;
    }
  }
}

void loop()
{
}

int TX_FLASH(int time)
{
  digitalWrite(TX_LED, HIGH); //turn on TX_LED
  delay(time); //wait TIME
  digitalWrite(TX_LED, LOW); //turn off TX_LED
}

int RX_FLASH(int time)
{
  digitalWrite(RX_LED, HIGH); //turn on RX_LED
  delay(time); //wait TIME
  digitalWrite(RX_LED, LOW); //turn off RX_LED
}

int LC_FLASH(int time)
{
  digitalWrite(LC_LED, HIGH); //turn on LC_LED
  delay(time); //wait TIME
  digitalWrite(LC_LED, LOW); //turn off LC_LED
}
8  Using Arduino / Sensors / Re: Analog inputs are averaging? on: January 07, 2013, 09:36:27 pm
Checked with a multimeter, voltages are what they should be.  I dont know why the Serial monitor is showing them as averaged...  The diagram is real complex, not sure how I'd post it.  It has three batteries, a load cell, amplifier, and LEDs.  But the battery and loadcell are on totally different circuits.
9  Using Arduino / Sensors / Analog inputs are averaging? on: January 07, 2013, 06:01:35 pm
So, I have two analog inputs, on separate circuits, one should read 10 and the other 34, but they are both coming up as 22? 

Code:
int loadcell;
int battery;

void setup()
{
Serial.begin(9600);
}

void loop()
{
loadcell = analogRead(0);
battery = analogRead(1);
Serial.print(loadcell);
Serial.print(" ");
Serial.println(battery);
delay(100);
}

????? Help ???

Thanks, Ryan
10  Using Arduino / Networking, Protocols, and Devices / Re: Xbee to Xbee Communication Issues on: January 06, 2013, 08:31:17 pm
Thanks guys,
will take a look. smiley
11  Using Arduino / Sensors / Re: Analog reading negative voltage... on: January 05, 2013, 10:13:51 am
Using the TI INA125P Amplifier...

Magician, can you post a diagram of that? smiley
12  Using Arduino / Sensors / Analog reading negative voltage... on: January 04, 2013, 11:09:30 pm
My load cell unfortunately starts at a negative voltage (-8 to 0 volts depending on amplifier gain).  I dont believe the Arduino UNO will read negative voltages (i just get a value of 0).  My issue is compunded by the fact that when force is applied the voltage goes ABOVE 0 (up to +8v depending on amp gain).  So, my question is, how can i "reverse" a circuit while the value is a negative and then "unreverse" the circuit when it becomes positive again?

Thanks,
Ryan
Pages: [1]