Show Posts
|
|
Pages: [1] 2 3
|
|
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 #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 goto mode goto mode 4 (index < 7) , (index < 7) 2 (index < 7)
|
|
|
|
|
4
|
Using Arduino / Programming Questions / Re: read two values
|
on: February 14, 2012, 11:25:17 am
|
to test the 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
|
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?
|
|
|
|
|
7
|
Using Arduino / Programming Questions / Re: read two values
|
on: February 14, 2012, 06:38:45 am
|
so ... my code is crap  expecting this... 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. 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  , so pleaaaaase have patience.. 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; }
|
|
|
|
|
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 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
|
|
|
|
|
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  ) Well it blinks but for about 9 or 10 sec ,but if i chanche the value of if (++myCounter == 100) { //has a second elapsed? to if (++myCounter == 10) { //has a second elapsed? is seems to be working  for the blinky im sorry, doesn't work on the project... i tried to play with the values but with no success...
|
|
|
|
|