Show Posts
|
|
Pages: [1] 2
|
|
1
|
Using Arduino / Project Guidance / Re: rotary encoder
|
on: October 11, 2012, 02:54:49 pm
|
i tried several sketches but the one that works for me is : /* (Copy and paste)
Rotary encoder decoding using two interrupt lines. Most Arduino boards have two external interrupts, numbers 0 (on digital pin 2) and 1 (on digital pin 3).
Program sketch is for SparkFun Rotary Encoder sku: COM-09117 Connect the middle pin of the three to ground. The outside two pins of the three are connected to digital pins 2 and 3 */
volatile int number = 0; // Testnumber, print it when it changes value, // used in loop and both interrupt routines int oldnumber = number;
volatile boolean halfleft = false; // Used in both interrupt routines volatile boolean halfright = false;
void setup(){ Serial.begin(9600); pinMode(2, INPUT); digitalWrite(2, HIGH); // Turn on internal pullup resistor pinMode(3, INPUT); digitalWrite(3, HIGH); // Turn on internal pullup resistor attachInterrupt(0, isr_2, FALLING); // Call isr_2 when digital pin 2 goes LOW attachInterrupt(1, isr_3, FALLING); // Call isr_3 when digital pin 3 goes LOW }
void loop(){ if(number != oldnumber){ // Change in value ? Serial.println(number); // Yes, print it (or whatever) oldnumber = number; } }
void isr_2(){ // Pin2 went LOW delay(1); // Debounce time if(digitalRead(2) == LOW){ // Pin2 still LOW ? if(digitalRead(3) == HIGH && halfright == false){ // --> halfright = true; // One half click clockwise } if(digitalRead(3) == LOW && halfleft == true){ // <-- halfleft = false; // One whole click counter- number--; // clockwise } } } void isr_3(){ // Pin3 went LOW delay(1); // Debounce time if(digitalRead(3) == LOW){ // Pin3 still LOW ? if(digitalRead(2) == HIGH && halfleft == false){ // <-- halfleft = true; // One half click counter- } // clockwise if(digitalRead(2) == LOW && halfright == true){ // --> halfright = false; // One whole click clockwise number++; } } } i found it here : http://home.online.no/~togalaas/rotary_encoder/just for other ones who have troubles with this. i am solved 
|
|
|
|
|
2
|
Using Arduino / Project Guidance / rotary encoder
|
on: October 11, 2012, 01:59:49 pm
|
hi there, i got a rotary encoder from sparkfun which i have connected to a arduino nano. i am using the following code: int pulses, A_SIG=0, B_SIG=1;
void setup(){ attachInterrupt(0, A_RISE, RISING); attachInterrupt(1, B_RISE, RISING); Serial.begin(115200); }//setup
void loop(){ }
void A_RISE(){ detachInterrupt(0); A_SIG=1; if(B_SIG==0) pulses++;//moving forward if(B_SIG==1) pulses--;//moving reverse Serial.println(pulses); attachInterrupt(0, A_FALL, FALLING); }
void A_FALL(){ detachInterrupt(0); A_SIG=0; if(B_SIG==1) pulses++;//moving forward if(B_SIG==0) pulses--;//moving reverse Serial.println(pulses); attachInterrupt(0, A_RISE, RISING); }
void B_RISE(){ detachInterrupt(1); B_SIG=1; if(A_SIG==1) pulses++;//moving forward if(A_SIG==0) pulses--;//moving reverse Serial.println(pulses); attachInterrupt(1, B_FALL, FALLING); }
void B_FALL(){ detachInterrupt(1); B_SIG=0; if(A_SIG==0) pulses++;//moving forward if(A_SIG==1) pulses--;//moving reverse Serial.println(pulses); attachInterrupt(1, B_RISE, RISING); }
and, as i am a newbee, i am in trouble  when i start serial monitor i get some numbers coming in and when i turn the encoder also something is happening but not what i want. also numbers are changing when i touch the cables sometimes. so my guess is that i need some kind of pullup oder pulldown resistors somewhere. would someone be so nice and help me out here? i connected the middle pin of the encoder to gnd on the arduino and the left and right pins to digital 2 and 3. and i do not know much about electronics. have a nice day!
|
|
|
|
|
3
|
International / Deutsch / Re: easydriver eine umdrehung pro minute
|
on: September 22, 2012, 01:11:53 pm
|
|
lieber uwe, danke für die antwort auch wenn ich sie nicht ganz verstehe (sorry bin nicht sooo bewandert).
(1) wo mach ich 2ms pause? ist das das delay 50?
(2) wenn du von rechtecksignal sprichst nehme ich an es dreht sich um den begriff pwm, mit dem ich noch nie zu tun hatte.
es wäre nett, wenn du mich noch ein wenig mehr aufklären würdest.
|
|
|
|
|
4
|
International / Deutsch / easydriver eine umdrehung pro minute
|
on: September 22, 2012, 11:22:49 am
|
hallo, ich habe folgende frage: ich habe einen schrittmotor über einen easydriver mit dem arduino duemilanove verbunden. es funktioniert auch alles soweit. nun hab ich mich bereits blöd-gegoogelt aber nichts gefunden - wie programmiere ich den arduino, dass sich der schrittmotor während einer minute einmal dreht (quasi als sekundenzeiger einer uhr). hier was ich bisher hab ist zu testzwecken ein kleines script, das theoretisch den motor einmal in der sekunde eine umdrehung machen lässt. das tut er allerdings nicht - er braucht länger. // Motor 200 schritte/umdrehung, 8 fach microstepping -> 1600 schritte / umdrehung
// Variablen deklarieren
int dirPin = 2; int stepperPin = 3; int LEDPin = 13;
// Ein-Ausgänge deklinieren
void setup() { pinMode(dirPin, OUTPUT); pinMode(stepperPin, OUTPUT); pinMode(LEDPin, OUTPUT); }
// Funktion für Schrittmotor
void step(boolean dir,int steps, int stp_int){ digitalWrite(dirPin,dir); delay(50); for(int i=0;i<steps;i++){ digitalWrite(stepperPin, HIGH); delayMicroseconds(stp_int); digitalWrite(stepperPin, LOW); delayMicroseconds(stp_int); } }
// Anweisungen
void loop(){ step(true,1600,1000); // schrittmotor 1 umdrehung in 1 sekunde delay(1000); // 1 sekunde warten
} es wäre wirklich supernett, wenn mir jemand auf die sprünge helfen würde.
|
|
|
|
|
5
|
Using Arduino / Project Guidance / read out usb
|
on: August 25, 2012, 05:34:22 am
|
|
hello there,
an idea came into my mind and i would like to ask if this is doable.
i habe a guitar effects pedal which can be edited with a software on pc over usb. in the software i can switch through the pedals presets - the pedal then also switches presets. the pedal itself is very uncomfortable to switch through presets (i have to hold one button for 5 seconds, then press another button and finally another one). the idea is to find out what commands are sent over usb to in- and decrease the presetnumber. my goal would be to build a little extra stompbox with two buttons which let me switch through the presets with one press of a button. therefor the extra stompbox would be connected over usb with the effectspedal and when one button is pressed, the command to jump to the next preset would be send (the command which goes over usb).
i hope i was able to make my idea clear and would be greatful if someone can give me some thoughts. i am arduino experienced, so the hardware, switches side is no problem. what i really dont know is how to find out how to (1) catch what the software sends over usb (when the next preset is called) and (2) how i would then program this command to be send from the arduino.
have a nice weekend you out there.
|
|
|
|
|
6
|
Using Arduino / Programming Questions / Re: looping problem
|
on: December 14, 2011, 02:43:29 am
|
got help in another forum but have to share here for other poor souls  the problem was using arduino 1.0 where some changes were made using serial communication. after this users tip i tried the code with arduino 23 and now serial.flush() works as expected. keep in mind that arduino 1.0 reacts differently to arduino 0.23 when it comes to serial!
|
|
|
|
|
8
|
Using Arduino / Programming Questions / Re: looping problem
|
on: December 13, 2011, 08:49:38 am
|
i tried this but it does not work. void loop(){
if (Serial.available() >0){ // prüft ob Kommunikation möglich Ser = Serial.read(); // com Port auslesen }
if (Ser == 'S'){ scan = 1; } if (scan = 1){
delay(5000); // ersten Scan abwarten Serial.println('3'); // auf Texturmenü springen delay(1500); // warten Serial.println('G'); // Textur aufnehmen delay(1000); // warten Serial.println('4'); // auf SL Menü springen delay(1500); // warten Serial.println('A'); // Scan zur Liste hinzufügen
for(int i=0;i<pos;i++){ step(true,stepstogo,500); // Schrittmotor zur nächsten Position bewegen Serial.println('S'); // nächsten Scan beginnen delay(5000); // Scan abwarten Serial.println('3'); // für Textur vorbereiten delay(1500); // warten Serial.println('G'); // Textur aufnehmen delay(1000); // warten Serial.println('4'); // auf SL Menü springen delay(1500); // warten Serial.println('A'); // Scan zur Liste hinzufügen } } scan = 0; }
|
|
|
|
|
9
|
Using Arduino / Programming Questions / Re: looping problem
|
on: December 13, 2011, 08:38:20 am
|
|
thats what i also thought. i tried setting a variable Scan = 1 when the "S" was received. then i did put the whole turntable motion into an if Scan == 1 loop but it did not work.
is there another way to set a flag and work with it?
|
|
|
|
|
10
|
Using Arduino / Programming Questions / looping problem
|
on: December 13, 2011, 08:29:11 am
|
hi there, i have a rotating table which listens to an "S" from serial. this "S" comes from a scannersoftware. when the table gets an "S" it moves 12 times. during this, the rotating table sends some characters to the scannersoftware to trigger some of its functions. when it made full 360 degrees it stops. and waits for another "S" of the scannersoftware. the program of the turntable works. if i send an "S" with serial monitor, the table behaves as it should. my problem with my code is that if the table gets another "S", while he is working, it will never stop again. unluckyly the scannersoftware does send additional "S" during its scanning process and i have no influence to change this. so i am sure there is a simple way of for example let arduino listen to serial only on certain times or flush the lasersoftware "S" out of the communication but i am not clever enough to find it. i am asking you nice people out there to help me. have a nice day. void loop(){
if (Serial.available() >0){ // prüft ob Kommunikation möglich Ser = Serial.read(); // com Port auslesen }
if (Ser == 'S'){ delay(5000); // ersten Scan abwarten Serial.println('3'); // auf Texturmenü springen delay(1500); // warten Serial.println('G'); // Textur aufnehmen delay(1000); // warten Serial.println('4'); // auf SL Menü springen delay(1500); // warten Serial.println('A'); // Scan zur Liste hinzufügen
for(int i=0;i<pos;i++){ step(true,stepstogo,500); // Schrittmotor zur nächsten Position bewegen Serial.println('S'); // nächsten Scan beginnen delay(5000); // Scan abwarten Serial.println('3'); // für Textur vorbereiten delay(1500); // warten Serial.println('G'); // Textur aufnehmen delay(1000); // warten Serial.println('4'); // auf SL Menü springen delay(1500); // warten Serial.println('A'); // Scan zur Liste hinzufügen } }
}
|
|
|
|
|
11
|
Using Arduino / Interfacing w/ Software on the Computer / flash talking serial
|
on: December 09, 2011, 05:32:11 pm
|
|
hi,
i used netlabtoolkit some times already and now i have a new idea followed by a question.
i have a rotating table which is arduino controlled. when the table receives an "S" it does some programmed movement. i use this with a laserscanning software which does send this "S".
now i want to create a nicelooking standalone programm in flash which also has some buttons and one of them should send an "S". can i do this with netlabtoolkit and its hub?
any help would make me very happy. have a nice day!
|
|
|
|
|
13
|
Using Arduino / Programming Questions / two steppers
|
on: December 09, 2011, 02:55:49 pm
|
hi i wrote the following code which turns one stepper one time and then (lets a led blink) and reverses - this loops. i am learning my way through... would anybody be so nice and explain to me how i can drive two steppers independently at the same time? for example i would have another easydriver connected to pins 4, 5 and would like to have this stepper turn only half while the original stepper turns like before. // Schrittmotorsteuerung mit Easydriver Library // MiPu 2011 // // Motor 200 schritte/umdrehung, 8 fach microstepping -> 1600 schritte / umdrehung
int dirPin = 2; int stepperPin = 3; int LEDPin = 13;
void setup() { pinMode(dirPin, OUTPUT); pinMode(stepperPin, OUTPUT); pinMode(LEDPin, OUTPUT); }
void step(boolean dir,int steps, int stp_int){ digitalWrite(dirPin,dir); delay(50); for(int i=0;i<steps;i++){ digitalWrite(stepperPin, HIGH); delayMicroseconds(stp_int); digitalWrite(stepperPin, LOW); delayMicroseconds(stp_int); } }
void loop(){ step(true,1600,3000); // 1 umdrehung in 5 sekunden digitalWrite(LEDPin, HIGH); // LED einschalten delay(3000); // 1 sekunde warten digitalWrite(LEDPin, LOW); // LED ausschalten step(false,1600,3000); // 1 umdrehung zurück in 5 sekunden
digitalWrite(LEDPin, HIGH); // LED einschalten delay(3000); // 1 sekunde warten digitalWrite(LEDPin, LOW); // LED ausschalten } it would be great if somebody could help. have a nice day.
|
|
|
|
|
15
|
Using Arduino / Interfacing w/ Software on the Computer / flash send "S" over com port
|
on: November 15, 2011, 06:33:27 pm
|
|
hi there,
i have a rotating table which i use for a laserscanning system. i consists of an arduino uno, easydriver and a stepper motor. the code on the arduino listens to the com port. if it receives a "S" the table moves 30degrees. the "S" is sendt by the laserscanning software. this works.
i would like to create a flashfile which has one button. if this button is pressed it should send a "S" to the arduino and the table should move 30degrees.
does anybody know how to do this or give me some starting links? this would be great! have a nice day.
|
|
|
|
|