Show Posts
Pages: [1] 2
1  Using Arduino / Installation & Troubleshooting / Re: Can't choose serial port in Linux Mint 10 on: March 03, 2011, 12:33:33 pm
A lot of what you said went over my head. smiley-razz

However, upon connecting the arduino and using dmesg, the last entry in terminal says a usb device with ttyACM0.  I would assume this is it?

I downloaded the linux 32-bit 0022 version from the arduino.cc website.  How exactly would I do this symlink business?

smiley-razz

EDIT: Disregard my last reply, it has now started working, I can see the device in the serial port option.

Many Thanks!

smiley
2  Using Arduino / Installation & Troubleshooting / Can't choose serial port in Linux Mint 10 on: March 03, 2011, 09:44:41 am
Hey gang,

Got the 0022 version of arduino extracted to my home folder, loads up fine but the serial port is grayed out and as such I can't select my Uno board.  I'm pretty new to Linux and am unsure how to correct this.

Could someone preferably give me a simple way to do this?

I've searched already but some stuff went over my head. smiley-razz
3  Using Arduino / Programming Questions / Re: Simple problem with a menu type system on: February 05, 2011, 09:18:53 am
Lol, yep that was indeed the problem.  Many thanks! smiley

I knew what I was trying to do, I won't forget that =/== thing again.

smiley-grin
4  Using Arduino / Programming Questions / Simple problem with a menu type system on: February 05, 2011, 08:55:29 am
Greetings all.

I'm having a small problem, I think I know what the issue is but not sure how to fix it.  I'm basically trying a menu type thing.  Using 1 button it should go like this:

sequence0 (default)
press button
sequence1
press button again
sequence2
press button again
sequence3
press button again
back to sequence0   //here lies the problem

Here's the main code bit;

Code:
void loop(){
 
  state = (digitalRead(button)); //state is value of button
  delay(200);  //debounce(will be debounced in hardware later)
 
    if(state==1){  //if button is pressed
     newstate++;  //add 1 to newstate
       }
/*if(newstate==0){ //if newstate is 0 (default)
  sequence0(); //run sequence0
 
}
if(newstate==1){ //if newstate is 1
  sequence1();    //run sequence1
}
if(newstate==2){ //if newstate is 2
  sequence2();    //run sequence2
}
if(newstate==3){ //if newstate is 3
  sequence3();    //run sequence3
}
if(newstate>3){ //if newstate is higher than 3
  newstate==0;  //newstate is now 0 again, ie sequence 0
}
 */

//TRYING WITH SWITCH CASE

switch (newstate) {                 
  case 0:                               
    sequence0(); 
    break;                             
  case 1:
    sequence1();
    break;
  case 2:
    sequence2();
    break;
  case 3:
    sequence3();
    break;
   default:
    sequence0();
    //newstate==0;
  }
}     
 

Note that i've tried it both using IF statements and trying again with switch case statements.  The problem is at the same bit, getting the menu back to sequence0.  I'm sure it's to do with newstate incrementing and i've tried while newstate is <3 etc but i'm obviously misplacing a line or something.

Any ideas folks?
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Printing floating point numbers to LCD on: January 23, 2011, 06:15:48 am
Thanks guys that works great, it's now displaying the specified significant digits. smiley

However, i'm finding another issue, my result is still zero.  I'm assuming that you can't do sums with different variable types?  Ie I'm trying to divide a float by an unsigned long, i assume they both need to be floats?

EDIT:

I'v just tested this and this seems to be the case.

EDIT 2: Actually it seems I was wrong, I am dividing a float by an unsigned long.  Not sure what was wrong but it does work as expected now.

smiley-grin
6  Forum 2005-2010 (read only) / Syntax & Programs / Printing floating point numbers to LCD on: January 22, 2011, 12:19:58 pm
Hey gang, on a project i'm working on it all works fine except for printing floating point values.  I had been using serial.print for debugging until I discovered that serial.print can't print floats.

So as I was using an LCD anyway I thought I'd just use that for debugging, however, lcd.print(float value) doesn't seem to work either.  Now, alot of the numbers i'm using are very small, such as 0.00001 etc and I notice that when I print a float to LCD, it reads as 0.00, so I assume it can up to 2 decimal places.

I've tried taking my float and scaling it but multiplying by 1000, or 1000000 but this doesn't seem to make a difference.

Can anyone point me in the right direction/

smiley
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Qn about understanding capacitance meter code on: January 21, 2011, 05:37:29 am
pocketscience, that could be what is happening in my code for mine.  I'm a hardware guy and fairly new to software so i'm still learning the nuances. smiley-razz

I'll mess around a bit more and change my while bit to more like the original code and see what happens.  I might be back. smiley-razz

Thanks for the help guys.

smiley
8  Forum 2005-2010 (read only) / Syntax & Programs / Qn about understanding capacitance meter code on: January 20, 2011, 02:15:42 pm
Hello everyone, I have a question about the code found in the tutorial section of the site regarding a capacitance meter.  The code is:
Code:
/*  RCTiming_capacitance_meter
 *   Paul Badger 2008
 *  Demonstrates use of RC time constants to measure the value of a capacitor
 *
 * Theory   A capcitor will charge, through a resistor, in one time constant, defined as T seconds where
 *    TC = R * C
 *
 *    TC = time constant period in seconds
 *    R = resistance in ohms
 *    C = capacitance in farads (1 microfarad (ufd) = .0000001 farad = 10^-6 farads )
 *
 *    The capacitor's voltage at one time constant is defined as 63.2% of the charging voltage.
 *
 *  Hardware setup:
 *  Test Capacitor between common point and ground (positive side of an electrolytic capacitor  to common)
 *  Test Resistor between chargePin and common point
 *  220 ohm resistor between dischargePin and common point
 *  Wire between common point and analogPin (A/D input)
 */

#define analogPin      0          // analog pin for measuring capacitor voltage
#define chargePin      13         // pin to charge the capacitor - connected to one end of the charging resistor
#define dischargePin   11         // pin to discharge the capacitor
#define resistorValue  10000.0F   // change this to whatever resistor value you are using
                                  // F formatter tells compliler it's a floating point value

unsigned long startTime;
unsigned long elapsedTime;
float microFarads;                // floating point variable to preserve precision, make calculations
float nanoFarads;

void setup(){
  pinMode(chargePin, OUTPUT);     // set chargePin to output
  digitalWrite(chargePin, LOW);  

  Serial.begin(9600);             // initialize serial transmission for debugging
}

void loop(){
  digitalWrite(chargePin, HIGH);  // set chargePin HIGH and capacitor charging
  startTime = millis();

  while(analogRead(analogPin) < 648){       // 647 is 63.2% of 1023, which corresponds to full-scale voltage
  }

  elapsedTime= millis() - startTime;
 // convert milliseconds to seconds ( 10^-3 ) and Farads to microFarads ( 10^6 ),  net 10^3 (1000)  
  microFarads = ((float)elapsedTime / resistorValue) * 1000;  
  Serial.print(elapsedTime);       // print the value to serial port
  Serial.print(" mS    ");         // print units and carriage return


  if (microFarads > 1){
    Serial.print((long)microFarads);       // print the value to serial port
    Serial.println(" microFarads");         // print units and carriage return
  }
  else
  {
    // if value is smaller than one microFarad, convert to nanoFarads (10^-9 Farad).
    // This is  a workaround because Serial.print will not print floats

    nanoFarads = microFarads * 1000.0;      // multiply by 1000 to convert to nanoFarads (10^-9 Farads)
    Serial.print((long)nanoFarads);         // print the value to serial port
    Serial.println(" nanoFarads");          // print units and carriage return
  }

  /* dicharge the capacitor  */
  digitalWrite(chargePin, LOW);             // set charge pin to  LOW
  pinMode(dischargePin, OUTPUT);            // set discharge pin to output
  digitalWrite(dischargePin, LOW);          // set discharge pin LOW
  while(analogRead(analogPin) > 0){         // wait until capacitor is completely discharged
  }

  pinMode(dischargePin, INPUT);            // set discharge pin back to input
}

Particularly this bit
Code:
void loop(){
  digitalWrite(chargePin, HIGH);  // set chargePin HIGH and capacitor charging
  startTime = millis();

  while(analogRead(analogPin) < 648){       // 647 is 63.2% of 1023, which corresponds to full-scale voltage
  }

  elapsedTime= millis() - startTime;
 // convert milliseconds to seconds ( 10^-3 ) and Farads to microFarads ( 10^6 ),  net 10^3 (1000)  
  microFarads = ((float)elapsedTime / resistorValue) * 1000;  
  Serial.print(elapsedTime);       // print the value to serial port
  Serial.print(" mS    ");         // print units and carriage return

Can someone explain why the elapsed time bit is outside the {} for the while loop?  Am I right in thinking that this means that analogRead is constantly reading until it's >= 648?

Could this also be done similar to:
Code:
while(analogRead(analogPin) < 648){
        do something
}

if (analogRead(analogPin)>=648){
      do something else
}
I'm not great at programming and i'm trying to understand this as i'm doing something similar but i'm not getting what I expect.  I haven't posted it because it's for a uni project and would rather understand the issue so I can implement it.
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help with simple problem on: January 14, 2011, 01:39:27 pm
I'm always impressed by people who can code good. smiley
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help with simple problem on: January 14, 2011, 11:46:44 am
I just got somewhere as I read your post.  I tried your way but it didn't seem to work.  I put a delay before the If statements in your code but when the button was pressed or depressed the led just flickers but no latching occurs.

I found this solution works, I was focusing on my 4th If statement but then I looked at my 3rd and made the following changes:
Code:
//simple program to test making a latch
//button held low by 10k pull down, button pressed should latch led on
//button pressed again, led should latch off


//variables
boolean ledpin = 13;  //led on pin 13
boolean button = 12;  //button on pin 12
boolean state = 0;    //state of button pin
boolean newState = 0;  //new button state variable



void setup(){
  pinMode(ledpin, OUTPUT);  //led output
  pinMode(button, INPUT);  //button input
}

void loop() {

  state = (digitalRead(button));    //state is value of button
  delay(70);  //button debounce (not needed if debounce circuit exists)


 if(state == 0 && newState == 0){  //if state and lastState are both 0 (button unpressed)
   digitalWrite(ledpin, LOW);       // led is off
   newState = state;                  //lastState is still 0
    }
 else if(state == 1 && newState == 0){  //if state is 1 (button press) and lastState is 0
   digitalWrite(ledpin, HIGH);      //led is on
   newState = state;                   // lastState is now 1
 }
 else if(state == 0 && newState == 1){  //if state is 0(button unpressed) and lastState is 1
   digitalWrite(ledpin, HIGH);      //led is on
   //newState = 1;                    //lastState is still 1
 }
 else if(state == 1 && newState == 1){  //if state is 1(button pressed) and lastState is 1
   digitalWrite(ledpin, LOW);   //turn led off
   newState = 0;   //lastState should now be 0 again and loop repeats


 }

 }

//rinse and repeat
 

I basically just took out the 'newState' change in the 3rd If statement and now it works.  It should work better on my actual hardware debounce circuit.

smiley
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help with simple problem on: January 14, 2011, 10:38:56 am
I saw that yes.  I tried your way initially and have just redone it, but now nothing happens at all when I press the button.

Code:
//simple program to test making a latch
//button held low by 10k pull down, button pressed should latch led on
//button pressed again, led should latch off


//variables
boolean ledpin = 13;  //led on pin 13
boolean button = 12;  //button on pin 12
boolean state = 0;    //state of button pin
boolean newState = 0;  //new button state variable



void setup(){
  pinMode(ledpin, OUTPUT);  //led output
  pinMode(button, INPUT);  //button input
}

void loop() {
  
  state = (digitalRead(button));    //state is value of button
  
  
 
 if(state == 0 && newState == 0){  //if state and lastState are both 0 (button unpressed)
   digitalWrite(ledpin, LOW);       // led is off
   newState = state;                  //lastState is still 0
    }
 
 else if(state == 1 && newState == 0){  //if state is 1 (button press) and lastState is 0
   digitalWrite(ledpin, HIGH);      //led is on
   newState = state;                   // lastState is now 1
 }
 
 
 else if(state == 0 && newState == 1){  //if state is 0(button unpressed) and lastState is 1
   digitalWrite(ledpin, HIGH);      //led is on
   newState = state;                    //lastState is still 1
 }
 
 else if(state == 1 && newState == 1){  //if state is 1(button pressed) and lastState is 1
   digitalWrite(ledpin, LOW);   //turn led off
   newState = state;   //lastState should now be 0 again and loop repeats
  
  
 }
  }

//rinse and repeat
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help with simple problem on: January 14, 2011, 10:31:34 am
I have tried delays but to no avail. I have the switch debounced in hardware on my actual circuit.

I'm thinking it must be something to do with the last If statement.
13  Forum 2005-2010 (read only) / Syntax & Programs / Help with simple problem on: January 14, 2011, 10:16:21 am
So I've spent the last few hours with a ridiculously simple problem, but my logic appears to have an issue somewhere.  

I'm trying to make a simple software latch for another project:

push button, led stays on
push button again, led stays off
push button again, led stays on

etc

I have it working except for one last thing, here is the code
Code:
//simple program to test making a latch
//button held low by 10k pull down, button pressed should latch led on
//button pressed again, led should latch off


//variables
boolean ledpin = 13;  //led on pin 13
boolean button = 12;  //button on pin 12
boolean state = 0;    //state of button pin
boolean newState = 0;  //new button state variable



void setup(){
  pinMode(ledpin, OUTPUT);  //led output
  pinMode(button, INPUT);  //button input
}

void loop() {
  
  state = (digitalRead(button));    //state is value of button
  
  
 
 if(state == 0 && newState == 0){  //if state and lastState are both 0 (button unpressed)
   digitalWrite(ledpin, LOW);       // led is off
   newState = 0;                  //lastState is still 0
    }
 
 if(state == 1 && newState == 0){  //if state is 1 (button press) and lastState is 0
   digitalWrite(ledpin, HIGH);      //led is on
   newState = 1;                   // lastState is now 1
 }
 if(state == 0 && newState == 1){  //if state is 0(button unpressed) and lastState is 1
   digitalWrite(ledpin, HIGH);      //led is on
   newState = 1;                    //lastState is still 1
 }
 if(state == 1 && newState == 1){  //if state is 1(button pressed) and lastState is 1
   digitalWrite(ledpin, LOW);   //turn led off
   //newState = 0;   //lastState should now be 0 again and loop repeats
  
  
 }
  }

//rinse and repeat

Now, that code will make the led latch on after pressing the button but when i push it again, the led blinks off but stays on when i release the button.

The commented out bit of the last If statement was my attempt to fix this but i'm having a logic issue somewhere. smiley-razz  I'v also tried setting both 'state' and 'newState' to 0 when 'state' and 'newState' = 1 but to no avail.  

I know this will have a simple answer, can someone please tell me what i'm missing?

smiley
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: Dallas DS18B20 Temp sensor questions on: July 16, 2010, 08:41:59 am
AH! My apologies, i read your last post with the code as a part of my own, i didn't realise you had changed it. Thanks very much!   smiley-grin

There is now action on the display but i see i am going to have to make an array for the digits to display properly. I'm getting glitches which i think are to do with the delays of my number functions.

Thanks again.

smiley
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: Dallas DS18B20 Temp sensor questions on: July 16, 2010, 06:19:26 am
I don't get anything except that scope error using the above code. I did think of tying arrays. But isn't what i'm doing just a longer way of doing it? And so, would i not still get the same type of problem.

I only used the >=24 as an example to see if i was going to get anything.

I still don't quite understand how i 'fetch' the temperature info, is my above if function going along the right lines?

 smiley
Pages: [1] 2