Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: read two values on: February 14, 2012, 01:52:51 pm
feeling sooo stupid.. Thanks one more time PaulS..
Works fine
2  Using Arduino / Programming Questions / Re: read two values on: February 14, 2012, 01:33:19 pm
ok if i modify the code like so
Code:
#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[7];
byte index;
int k;
int i;
void setup()
{
   Serial.begin(9600);
   // Other stuff...
    pinMode(13, OUTPUT); 
   
}
void loop()
{
  // Read all serial data available, as fast as possible
  Serial.println("goto mode");
  delay (1000);
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    Serial.println(inChar);
    if(inChar == SOP)
    {Serial.println("SOP");
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {Serial.println("EOP");
       ended = true;
       break;
    }
    else
    {
      if(index < 7)
      {
        Serial.println("(index < 7)");
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

int step1 = 0, step2  =0;
char *token = strtok(inData, ",");
if(token)
{
   k = atoi(token);
Serial.println(k);
   token = strtok(NULL, ",");
   if(token)
   {
      step2 = atoi(token);
     Serial.println(step2);
   }
}
// Now, you can use step1 and step2.
for (i=0; i<k; i++){
 Serial.println("led-loop");
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);     

}

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}


and insert   4,2 
i get

Code:
goto mode
goto mode
4
(index < 7)
,
(index < 7)
2
(index < 7)

3  Using Arduino / Programming Questions / Re: read two values on: February 14, 2012, 12:33:26 pm
sorry, no idea how to do that ..
could you please help me out?
4  Using Arduino / Programming Questions / Re: read two values on: February 14, 2012, 11:25:17 am
to  test the code
Code:
#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;
int k;
int i;
void setup()
{
   Serial.begin(9600);
   // Other stuff...
    pinMode(13, OUTPUT); 
   
}
void loop()
{
  // Read all serial data available, as fast as possible
  Serial.println("test");
  delay (1000);
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

int step1 = 0, step2  =0;
char *token = strtok(inData, ",");
if(token)
{
   k = atoi(token);

   token = strtok(NULL, ",");
   if(token)
   {
      step2 = atoi(token);
   }
}
// Now, you can use step1 and step2.

// test with led13
for (i=0; i<k; i++){
 
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);     

}

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

although it compiles fine the led doesn't blink.... Am i missing something?
PS i changed the baud rate because freezes my serial motitor
5  Using Arduino / Programming Questions / Re: read two values on: February 14, 2012, 08:26:58 am
Quote
Did you look at the strtok() documentation? If you had, you would see that it returns a pointer to a token. It is that pointer that gets passed to atoi().
actually i  did... I didn't understand many things though...   Im trying here, ok?

So
strtok( inData, "," ) ; is the first command
 now what i must put into atoi?
6  Using Arduino / Programming Questions / Re: read two values on: February 14, 2012, 08:00:27 am
THANK YOU!(did not understand well the code, but.... )
so you mean something like

strtok( inChar, "," ) ;
int step1 = atoi(inData[1]);
int step2 = atoi(inData[2]);
7  Using Arduino / Programming Questions / Re: read two values on: February 14, 2012, 06:38:45 am
so ... my code is crap smiley-zipper expecting this...
Quote
You know that there is serial data available. What are you waiting for?
actually go-to mode is one of the modes im using activated by a switch. So it seemed logic to  wait  so there is time for the previous action to be completed.
Quote
Serial.read() reads one byte. It is unlikely that the character/byte you read is the number of steps to step. What is sending the serial data?
I didn't know that.So how can i read an integer positive or negative , and maybe read 2 of them ?since we are talking about to steppers.Maybe with a "," semicolon separator? And how can i assign these two numbers to  2 variables so i can use them in   stepper1 and stepper 2?

 stepper1.step(variable1);
 stepper2.step(variable2);
8  Using Arduino / Programming Questions / read two values on: February 13, 2012, 04:44:24 pm
Hi  guys
Im trying to control 2 stepper motors using the function read().
I must give in serial monitor 2 values , one for each motor ,and they must move to the specified angle (go-to mode). My code  doesn't seem to  work...
im a terrible  programmer smiley-red  , so  pleaaaaase  have patience..
Code:
if (buttonState == HIGH) {  
    
     Serial.println("GO-TO MODE");

    // send data only when you receive data:
        if (Serial.available()) {
            delay(1000);
              
    
                // command to stepper1
                 stepper1.step(Serial.read());
              Serial.println(" stepper1:");
              Serial.print(Serial.read());
                
                  Serial.println("stepper 2");
              
        }
            if (Serial.available()) {
            delay(1000);
              
    
                // command to stepper2
                 stepper2.step(Serial.read());

              Serial.println(" stepper2:");
              Serial.print(Serial.read());  
                  Serial.println("end go-to  mode");
              
        }
    
    
    buttonState == LOW;
}
9  Using Arduino / Microcontrollers / Re: ####ing attiny85 on arduino... on: January 26, 2012, 05:20:56 pm
After loooong time of frustration i solved it!!!
I use ubuntu linux. So if i burn the Arduinoisp from arduino 0.22 from windows and then continue the process ftom arduino 1.0 from windows or linux (doesn't  matter) everything is fine! smiley-cool smiley-cool smiley-cool smiley-cool
10  Using Arduino / Microcontrollers / Re: ####ing attiny85 on arduino... on: November 28, 2011, 11:41:07 am
ok tried both solutions.. none worked...
Keep  getting sync error messages
11  Using Arduino / Microcontrollers / Re: ####ing attiny85 on arduino... on: November 22, 2011, 09:14:30 am
hi  i have tha same problem
[quote
It was the reset. 2 by 2 220 ohn resistors from live to reset sorted it  smiley-mr-green happy bunny again
[/quote]
 you mean the reset pin on arduino or the reset pin on the attiny?(i assume live is the 5v pin)
12  Using Arduino / LEDs and Multiplexing / Re: attiny85 and TimerOne.h on: November 05, 2011, 07:24:35 am
hi again..
wow! you did some  work! I apologise again for the delay  but i've been craaazy running...
so i tried your code with the attiny85 and i get this error on compile
Code:
In file included from /usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h:44:0,
                 from /usr/lib/gcc/avr/4.5.3/../../../avr/include/avr/delay.h:37,
                 from /home/pyrforos/Documents/electronic projects/hardware/attiny45_85/cores/attiny45_85/wiring_private.h:32,
                 from /home/pyrforos/Documents/electronic projects/hardware/attiny45_85/cores/attiny45_85/WInterrupts.c:36:
/usr/lib/gcc/avr/4.5.3/../../../avr/include/math.h:426:15: error: expected identifier or ‘(’ before ‘double’
/usr/lib/gcc/avr/4.5.3/../../../avr/include/math.h:426:15: error: expected ‘)’ before ‘>=’ token
13  Using Arduino / LEDs and Multiplexing / Re: attiny85 and TimerOne.h on: October 21, 2011, 01:55:33 pm
sorry for the delay...
No i did not touch any of the fuses... i don't know how to...
im on linux so i cant use avrdude, only arduino IDE, and the only option in boards is the name of the chip am using.
14  Using Arduino / LEDs and Multiplexing / Re: attiny85 and TimerOne.h on: October 19, 2011, 08:56:57 am
it works but the flickering stays... its like the update function is actually enough slow to mess up your eyes
 
15  Using Arduino / LEDs and Multiplexing / Re: attiny85 and TimerOne.h on: October 19, 2011, 07:42:46 am
a veryy big thanks mate!(LOL Scotchware License smiley-lol smiley-lol)

Well it blinks but for about 9 or 10 sec ,but if i chanche the value of
Code:
  if (++myCounter == 100) {       //has a second elapsed?
to
Code:
  if (++myCounter == 10) {       //has a second elapsed?
is seems to be working smiley for the blinky

im sorry, doesn't work on the project... i tried to play with the values but with no success...
Pages: [1] 2 3