Show Posts
|
|
Pages: [1] 2
|
|
1
|
Using Arduino / Programming Questions / Stepper library - continuous stepping
|
on: June 04, 2013, 01:33:03 pm
|
Hello, I've been trying to create a continuous rotation with Stepper library, but no luck. The command (is sent over serial connection - right now I am using Serial Monitor) is in this format: <dir, speed, steps> or dir can be 0 or 1 (direction). So, if I use <1,60,200> I get 200 steps at 60 rpm in 1 direction (ccw or cw, no mather). I was thinking, why not make continuous rotation until it receives another command over the serial connection? So I use 0 for steps like a code message for this. That means <1,60,0> should make the stepper run continuously at 60 rpm in 1 direction. And when I send the stop message, (steps = 1), like <1,60,1> the stepper should make just one step and then stop. But it doesnt work and dont know why, please help. Thanks in advance. Code: http://pastebin.com/Qz9S2UHdor https://gist.github.com/anonymous/5708849or bellow. Thank you! // libraries #include <Stepper.h>
// buffer containing the data char inData[50]; // index used for buffer byte index; // set start and end of packet of data sent #define SOP '<' #define EOP '>' // and it's semaphore lights bool started = false; bool ended = false; // led int led = 13; // the 3 variables of interest (default values) int _dir = 0, _speed = 60; unsigned int _steps = 1; // the stepper Stepper myStepper(_steps, 7,8);
// setup void setup(){ myStepper.setSpeed(_speed); Serial.begin(9600); pinMode(led, OUTPUT); memset(inData, '\0', 50); }
// loop void loop() { readSerialData(); processPacket(); if (_dir == 0 && _speed == 0 && _steps == 0) { digitalWrite(led, HIGH); Serial.println("arduino found"); } else { digitalWrite(led, LOW); // Print check for values Serial.print("direction: "); Serial.print(_dir); Serial.print(" speed: "); Serial.print(_speed); Serial.print(" steps: "); Serial.println(_steps); // command the stepper // continuous rotation (_steps == 0) if (_steps == 0) { myStepper.setSpeed(_speed); if (_dir == 0) { while (_steps != 1) { myStepper.step(1); readSerialData(); processPacket(); resetPacket(); } } else { while (_steps != 1) { myStepper.step(-1); readSerialData(); processPacket(); resetPacket(); } } } // explicit rotation (_steps == other value than 0) else { myStepper.setSpeed(_speed); if (_dir == 0) { myStepper.step(_steps); delay(500); } else { myStepper.step(-_steps); delay(500); } } } resetPacket(); }
// saving serial data into buffer void readSerialData() { 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 < 49) { inData[index] = inChar; index++; inData[index] = '\0'; } } } }
// process the packet void processPacket() { // check packet if (started && ended) { // find _dir, _speed and _steps char * pch; pch = strtok (inData, ","); if (pch != NULL) { _dir = atoi(pch); _speed = atoi(strtok(NULL, ",")); _steps = atoi(strtok(NULL, ",")); } } }
// reset for the next packet void resetPacket() { started = false; ended = false; index = 0; inData[index] = '\0'; // _steps = 1; }
|
|
|
|
|
2
|
Using Arduino / Programming Questions / Serial Communication Problem
|
on: June 04, 2013, 11:07:45 am
|
|
Hello, I have an interface written in c#. The full c# code and arduino code may be found in the attached archive.
The program is simple: it sends via serial conection a message to arduino that tells it how to command a stepper motor. The message format is something like this: <0,60,200>, where 0 stands for direction (cw - 0 or ccw - 1), 60 for the speed and 200 for the number of steps. I have included a "check for arduino port" message that is <0,0,0>. When you press "conexiune" (conection) button and then scan (scanare) for ports, the application will send this message and receives (if any Arduino) the message "arduino found".
I have included a led check also. From serial monitor works fine.
The problem is with the interface: after sending the check message <0,0,0> from it and then a normal message like <1,20,300> the application (scan for port, led blink and also the command) wouldnt work anymore. It's like the application is getting stuck when receiving the confirmation "arduino found" message. Can you guys pritty please help me? Thank you in advanced.
PeterH: nope.
|
|
|
|
|
3
|
Using Arduino / Motors, Mechanics, and Power / Re: Anyone ever use one of these stepper drivers? Ebay 2M542
|
on: May 29, 2013, 05:21:07 am
|
1. I can't test everyday the driver and the stepper, because they are in a lab where I do not have access. That means I have to get things right without testing. Frustrating (to say the least). Depends what you need to test but using an ultra-cheap miniature stepper from eBay might be a way forward. [ Its a good discipline to program with the aim of getting it to work first time its tested  ] I quote from my self: Arduino commands correctly other stepper with other drivers (same code). ] That means that Arduino with the same code, an cheap driver and a scrap stepper from an old CD-ROM make the correct steps required. The 2M542 + turning table doesn't.
|
|
|
|
|
4
|
Using Arduino / Motors, Mechanics, and Power / Re: Anyone ever use one of these stepper drivers? Ebay 2M542
|
on: May 27, 2013, 05:01:36 am
|
Mark, ty very much. BTW guys, I have a serious problem with this driver. I won't start another topic on this to keep forum clean, but please help. These are the details: 1. I can't test everyday the driver and the stepper, because they are in a lab where I do not have access. That means I have to get things right without testing. 2. Board is Arduino Leonardo. 3. Driver is, as mentioned above, 2M542. http://www.hi-end.ro/pdf/motoare/CMP5042.pdf4. Driver settings are (watch the image: http://img2.dib-bid.com/gallery/cnc-motor-driver-2m542_03.jpg ) 1.0 A, 400 steps per revolution, Sw4: off (half-current) 5. Stepper is a big 1A turning table, 1.8 degree step. That means 200 steps per revolution. 6. Arduino commands correctly other stepper with other drivers (same code). Driver 2M542 works correctly the turning table, with other input. All wiring is good. 7. Code for Arduino is here: https://gist.github.com/fulminator/5656149 , but that's beyond of my questions. It's suffice to know that I try to control the stepper with Stepper.h library with this commands: myStepper.step(_steps); delay(500); where myStepper is myStepper(200, 7,8); , 200 means that are 200 steps by revolution. Speed is 60. Problem: stepper doesn't make correct number of steps. I give it to make 400 steps, but it doesn't make the full rotation; it turn like less than a quarter or a quarter of revolution. Then I tried to give 1 step, but no motion was detected. I give it 10 steps and the turning table made only 1 step or so. I believe there is a non-syncronize between Arduino and driver, and not between driver and stepper, because driver and stepper works correctly with other input. The Arduino supplies the 400 steps for the one revolution, but somewhere in between is not recognized as 400, more like 40. Probably because of the library? Question: 1. What's wrong? 2. Forget the code and the problem. Can you please supply a correct code? I hope the author of this topic would see this post. Thanks in advanced and God bless. I have finish until Thursday.
|
|
|
|
|
7
|
Using Arduino / Programming Questions / Re: Arduino Stepper Control via Serial Command
|
on: April 19, 2013, 05:23:01 pm
|
Thank you both, especially to PaulS. This is my final code: https://gist.github.com/fulminator/5423613It's working great. It's modified with both SOP EOP included. I will not include ',' between different data because it's unnecesary: speed and steps will never be bigger than, let's say, 999. So I can send 023 if I want only 23 steps; this way I will have a fixed 3 char length. I have found out why stepper wouldn't start. It wasn't because memory overwriting at temporary char arrays declarations. It was because of memory overwriting at memset from the setup(). I will start building the c# application for sending the data. Any other help, hint and tips are welcome. Thank you! And all have a good night tonight. It's 1:30 in the night for me right now.
|
|
|
|
|
8
|
Using Arduino / Programming Questions / Re: Arduino Stepper Control via Serial Command
|
on: April 19, 2013, 04:33:52 pm
|
|
Thank you. I actually was thinking of how to send correctly data via serial. One more question on serial data: you can see that I have to send a boolean value (direction) a 0 -> 99 numeric value (speed) and a 0 -> 999 numeric value (steps). If direction and speed can be send and received as bytes, step cannot because it can be bigger than 255, maximum value of a byte. (I always tought that sending in bytes is ideal). That's why I have used the string approach: just send all data in one string (or char array) and sort it after. My questions is: did I did good? Or there is other better method?
And now, let's get to the issue. I have mentioned that reading the data works fine. I have send trough serial monitor strings like 060100 and got the correct results back: direction=0 speed=60 and steps=100. Not the serial communication is my issue. It's the stepper. It won't start.
|
|
|
|
|
9
|
Using Arduino / Programming Questions / Arduino Stepper Control via Serial Command
|
on: April 19, 2013, 03:38:20 pm
|
Hello, I have a very strange issue. I have an Arduino Leonardo, a L293D driver (but that can be anything), and a scrap 4 wire stepper motor. I am trying to control the motor trough serial (I am using serial monitor for now). So, I am sending 3 variables: sens (direction), viteza (speed), pasi (steps) trough serial. I am reading it as a char array and then formating them and print them (and it's working this far). If I will send 060100 trough serial I will have 0 for direction, 60 for speed and 100 for steps. If I will send 130256 then: sens=1; viteza=30; pasi=256. So this is working. Then, I am trying to setSpeed(viteza) and make myStepper.step(pasi) if sens=0 or else myStepper.step(-pasi). This is the part that doesn't works. It's very important to say that stepper_oneRevolution example (modified accordingly: myStepper(pasi, 7,8)) WORKS JUST FINE. I have tried: - instead of pasi=0 at declaration, I've put pasi=200
- make pasi a constant int and give it 200
- put a myStepper.setSpeed(60) in the setup()
- put the print and comand blocks outside the if(serial.available) block
- somebody on irc told me I haven't allocated enough space for the temporary char arrays used for formating data, so I added them +1 buffer[7] vitezaArr[3] and pasiArr[4], though the program runned fined without this surplus
- I have put myStepper.step(200) first line in the loop() AND STILL NO RESULT
This is becoming very frustrating. Please help ASAP, I guess it's a very minor bug that I can't probably see right now. Thanks in advance. Here is my full code: https://gist.github.com/fulminator/5422506edit: after the prints block there is a myStepper.step(pasi); line. Ignore it, it was only for testing. edit2: corrected the number of wires of the stepper. 2 wires for Arduino: pin 7 and 8.
|
|
|
|
|
10
|
Using Arduino / Programming Questions / Re: Sending a string via serial communication Leonardo
|
on: March 07, 2013, 03:02:34 am
|
I wonder what you would get if you echo out what you put in? while (Serial.available() > 0) { incomingString[i++] = (char)Serial.read(); Serial.print(incomingString[i]); delay(10); } Maybe your if statements dont like double quotes, try single quotes. squares. I get simple squares. Can somebody please show me a clear example of SENDING and RECEIVING CHAR ARRAYS please? I got stuck at this problem and I can't go forward. Thanks!
|
|
|
|
|
12
|
Using Arduino / Programming Questions / Re: Sending a string via serial communication Leonardo
|
on: March 04, 2013, 03:54:28 pm
|
This is the correct link, I do not see why it isn't working: https://gist.github.com/fulminator/5084117This is the code, anyways: const int ledPin = 13; // the pin that the LED is attached to char incomingString[10]; void setup() { // initialize serial communication: Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); } void loop() { // see if there's incoming serial data: int i = 0; while (Serial.available() > 0) { incomingString[i++] = (char)Serial.read(); delay(10); } // turn on the LED: if (incomingString == "Ican2") { digitalWrite(ledPin, HIGH); } // turn off the LED: if (incomingString == "Ican22") { digitalWrite(ledPin, LOW); } } I just can't make this work. I am sending the Ican2 or Ican22 string, RX led is liting, but the led is not get put on HIGH or LOW.
|
|
|
|
|
13
|
Using Arduino / Programming Questions / Sending a string via serial communication Leonardo
|
on: March 04, 2013, 01:51:49 pm
|
Hello, guys, I have an Arduino Leonardo Board. Today I've been playing with different data format sent and received via serial USB communication. Based on PhysicalPixel example, I have succesefully sent data: bytes and chars. But I cannot make use of char array. This is my code: https://gist.github.com/fulminator/5084117After asking on mIRC, a fellow give me this and tried with nada results: http://pastebin.com/Q51VzU9JIt is funny, because i'ts looking correct, but it doesnt work. I have tried sending the "Ican2" from a c# GUI and from Serial Monitor. The ratebaud is the same everywhere: 9600. The RX led from the board is liting like is suppose to when receiving data. Help? btw, I've just tested integers. The same as char arrays.
|
|
|
|
|
14
|
Using Arduino / Motors, Mechanics, and Power / Arduino and driver
|
on: January 30, 2013, 06:39:10 am
|
Hello, I am new to Arduino and electronics. Right now I am making some experiences with: 1 DC small motor (here: http://dx.com/p/mini-electric-motors-set-black-3-pcs-154836) and a big old 9V stepper motor (4 wires: blue, white, red, yellow). I have this driver: http://dx.com/p/l9110-dual-channel-h-bridge-motor-driver-module-for-arduino-black-157149. I think I figured out how to make the connections, but I am very scared of burning my Arduino or something. I am new to electronics, as I said, and I manifest the fear of "don't burn anything". So can you guys please guide me to make the connections? And a part of the code? edit: I've put a scheme for the 9V stepper made in paint. Is that good?
|
|
|
|
|
15
|
Using Arduino / Programming Questions / Re: Csharp playground
|
on: January 28, 2013, 03:24:25 am
|
To attach a file to a post...
• Start a post (click Reply) or modify one of your existing posts • Click Additional Options... (below the edit window to the left) • Click the Browse button • Select the file • Click Post
As I said in my first post... "Hello, I am new to forum, so please be indulgent.". But I was going to ask that, so thank you. I have attached the working project to this post. It works thanks to Paul. It was DtrEnable, like he said. I have included a pic how my C# GUI looks like. It's easy to custom afterwards. Mayby someone could use it. I forgot to include a comment, though, in the DtrEnable line, because that can be a real frustration. Not necessary. The Playground is a public wiki. Now I get it why there were a buzzlion errors, and the nature of those errors! There are errors like pin_4 instead of pin_3 and commented lines, brackets missing... a jackass modified with bad intentions the code. I didn't really observe it was a wiki. I'll try to insert a link to this topic. Thanks again, Paul and fellas. edit: I have modified the article, but I didn't touch any of the code, I didn't really wanted to edit the man's code. So I just posted a link at the bottom of the page to this topic. Is that good? This is my first wiki that I've edited ever. See here: http://playground.arduino.cc//Csharp/SerialCommsCSharp
|
|
|
|
|