How to connect and control a stepper motor and sensor connected to laptop using matlab?
5 次查看(过去 30 天)
显示 更早的评论
Kevin
2012-11-22
I have a stepper motor with driver and a through beam sensor, when an object passed my sensor I would like my program to run and the motor will also run by 90 degrees counterclockwise then after the object passed the second sensor my motor will turn clockwise again by 90 degrees. can anyone help me how to connect this using parallel port and the code for it? Thank you very much hope someone helps
2 个评论
Walter Roberson
2012-11-22
Which operating system and MATLAB version are you using, and are you using 32 bit or 64 bit MATLAB?
Newer versions of MS Windows have made it technically difficult and slow to access the parallel port. It is recommended that you do not start any new projects using the parallel port.
回答(1 个)
Walter Roberson
2012-11-24
There is a code output at http://www.mathworks.com/matlabcentral/answers/40042-how-to-input-data-from-data-port-of-lpt
33 个评论
Walter Roberson
2012-11-24
It would probably be better to indicate which make/model you are considering.
The one I just looked at a moment ago might need a resistor tossed in to limit the voltage, but it looked to me as if the current levels would be safe.
Walter Roberson
2012-11-24
That sensor appears to use TTL logic levels, which is the same as parallel ports expect as input.
What kind of stepping rates were you hoping for? I am concerned that MATLAB might not be able to output parallel port data fast enough to control the stepper motor for your purpose.
Were you hoping to do both the sensor input and the stepping motor control on a single parallel port, or to use two different ports? With that sensor, you need to "poll" the input: that is, you need to ask the parallel port do an input operation each time you wish to check the signal. There is no asynchronous mode with it: if you use the parallel port for input of the sensor line, you cannot have the sensor "interrupt" when it detects something, and instead need to keep checking checking checking. Which would interfere with PWM control of the motor I think (but would need to cross-check.)
Kevin
2012-11-24
what I would like to happen is that when a vehicle passed between the sensor, it will trigger my matlab program which is about ANPR, if the plate number is registered my motor must turn 90 degrees counter clockwise, if the vehicle passed the second sensor the motor must now turn 90 degrees clockwise. I am planning to connect it on one parallel port only
Walter Roberson
2012-11-24
The sensor you are planning to use is not suitable for that purpose, not unless the vehicles are toy cars. The maximum sensor distance for that sensor is 1 meter, and the sensor part must be on the opposite side of the object from the transmitter. A conveyor belt for example.
Possibly for your purpose you may wish to use a device that relies upon reflection of signal rather than on the beam being interrupted.
Parallel port input is usually not suitable for waking up a program: it cannot, by itself, interrupt the CPU. Not unless ECP (Enhanced Capabilities Mode) is enabled, which requires a lot more logic on the peripheral side, and is completely unsuited for just running a wire over from a sensor.
Technical reference:
http://retired.beyondlogic.org/spp/parallel.htm and the ECP documentation linked to there;
Kevin
2012-11-24
does this mean that I cannot use conditional codes like if else to trigger the program if an object is present between the sensor?
Walter Roberson
2012-11-24
If you use that architecture, then you need to have a program running and actively checking the port status periodically, and initiating action when it detects the presence of the object.
I recommend that you calculate how long a car would be in range after the sensor was triggered, so that you can determine the maximum processing latency. Taking into account that cars speed. How long does it take to start MATLAB? How long would it take, once in MATLAB, to capture and read the image? Does the ANPR need to be done by the time of the next car, or can it be done "at leisure" ? Or are the plate pictures to be taken and stored, and ANPR is to be done based on the recorded pictures?
I suspect you will find that you do not have the luxury of starting your MATLAB program when the sensor detects a car: I suspect you will find that the MATLAB program has to be ready and waiting, and probably even has to be the program which is scanning the parallel port to detect the car interrupting the beam.
Kevin
2012-11-24
Yes that is what I am planning to do, a program using a loop so that the program will periodically check whether the beam is interrupted and when it does, the ANPR will be done on the vehicle present in between the sensor, if it is registered in our database, the motor will run allowing entry of the vehicle, then a second sensor will trigger the code in the program that rotates the motor in the opposite direction, is it possible to do that?
Walter Roberson
2012-11-24
In that situation you are not very performance bound, so generally Yes, it can be done. You would need to use a different sensor, though, as that one is limited to 1 meter.
Kevin
2012-11-25
What do you mean by not performance bound? Could you also help me on how to program this?
Walter Roberson
2012-11-25
If you were doing license plate recognition on a highway, you would have only on the order of 20 milliseconds to do the detection and take the picture. Your choices would be bound by the performance requirements. But in your actual situation, you can afford to keep the driver waiting a few seconds, during which time the car is not going to move more than a few feet (if at all.) Your performance requirements are lax.
The link at the top of my Answer gives you the code outline of how to talk to a parallel port. The diagram you posted the link to gives an idea of how to drive the motor with the parallel port. For the sensor input, I recommend you connect the wire (ummm, the positive I think) to the Select pin of the parallel port. You need to read the control port to read that input, but that is pretty much standard for input from parallel ports and you should be able to find examples of that.
The ANPR part is something I do not have the resources to get into at this time.
Kevin
2012-11-25
Thank you very much for your advice, I will just follow the connection of the stepper motor and the sensor to the parallel port then use the link you posted above. So the output of the sensor is connected to any of the select pins of the parallel port then use the Matlab to find input from that pin? I already have my ANPR code, the only thing I need now is this hardware. Thank you very much for the insights
Walter Roberson
2012-11-25
There is only one Select input pin on the parallel port, pin #13. I should have said it was via the Status port rather than through the Control port. See http://retired.beyondlogic.org/spp/parallel.htm
You may have some work getting a common ground for the motor and the sensor, which you will need in order for the voltage from the sensor to be the same range as the other pins instead of floating. Also I am not at the moment sure how to handle the dual wires from the sensor (positive and negative), not sure whether those are independent and referenced to the ground or if a circuit needs to be made of them. On the other hand you are going to be changing sensor (because you need more than 1 meter) and the wiring might be different on the new one.
Kevin
2012-11-25
I think it is really 1.5 meters because that is what they said when I asked them. There are positive and negative wires to the sensor and the third one is the output voltage or the TTL. Can I use the ground on the parallel port as the reference ground for the stepper driver and the sensor?
Kevin
2012-11-25
also in the link I gave, there is the clock which is the main driving signal of the motor. Can Matlab output a clock to the parallel port?
Walter Roberson
2012-11-25
编辑:Walter Roberson
2012-11-25
You are right about the TTL output.
The 1.5m is "maximum". Unfortunately for you, you need more than that if the vehicles are cars: you will need at least 1.8 meters (allowing for mirrors)
Is this intended to be outdoors? If so then you should reconsider use of an infrared system, as you can get stray IR due to sunshine or re-radiation from heated objects; you would also need to worry about mist and rain or fog (or even high humidity), which are going to cut down on the maximum distance. The less control you have over the working conditions, the more you need to over-engineer. You don't want your system to break down because the wind swept some damp snow up onto the sensor (or transmitter) and it clung there: you need the system to be robust enough that a signal can get through even if there is a layer of freezing rain. A radio-frequency sensor can be more effective in adverse weather; that or at least an optical system that can stand to lose a few decibels due to bad conditions. (Though if you do use a radio-frequency sensor, you need to take into account whether motorcycles or bicycles will block enough of the signal to be reliably detectable.)
Kevin
2012-11-25
I'm from the Philippines and it is stated in our paper that our project's limitation is we will test in normal lighting condition. we are also testing on cars only.
Walter Roberson
2012-11-25
"Normal lighting" outside is pretty variable :-)
Anyhow, cars are more than 1.5m wide, or at least they are in Canada, USA, Western Europe, Central America, and Japan.
Kevin
2012-11-25
I mean it is not cloudy but a fair weather :)
afte I install the voltage refulator on the sensor I will test it on the actual car, if it is really not suitable I'm thinking at putting it under the car between the wheels just for testing
Walter Roberson
2012-11-25
My aunt born in the Philippines once mentioned in passing having semi-regularily experienced something she called "night", but perhaps she was just using an analogy ?
Kevin
2012-11-25
Where can i connect the data strobe of the parallel port? I saw your comment on the link you posted, you said that data strobe is needed
Walter Roberson
2012-11-25
For lines like that which are analog values that change relatively slowly, you do not need a strobe.
Kevin
2012-11-26
so i will just connect the output wire to pin 13 of the parallel port and the ground to the ground pins?
Walter Roberson
2012-11-26
I think so, but you should have someone with practical IC circuit experience check the work. ICs don't like me; if I were to touch your circuit, it would probably fail in a way that your instructor had never personally seen before :(
Kevin
2012-11-26
That's what I'm worried about, I might fry my laptop's motherboard. Our other option is to use a relay to turn off the camera everytime the sensor is not triggered but is it possible in Matlab to run an ANPR program continously while the camera is off then running the actual program when the camera is turned on?
Walter Roberson
2012-11-26
You could use a op-amp to limit the possibility of damage.
I am not sure what the point is of running the ANPR when you do not have a specific plate to recognize?
Kevin
2012-12-1
We decided to use a arduino microcontroller to send and receive signal to the motor and the sensor respectively, is there a way to connect the code from the matlab to the code in the arduino?
Walter Roberson
2012-12-1
There is an arduino package in the File Exchange that can be used for older MATLAB. Very new MATLAB (or is it Simulink?) have support for arduino built-in.
Kevin
2012-12-1
Thank you I think I have downloaded that arduino package. I think it will be safer than having the sensor input enter the laptop directly
Kevin
2013-1-28
hey man, I tried the arduino package and it says timeout error, c an you help me fix this?
社区
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sensors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)