my wheel goes round

For issues with communication ports, protocols, etc.
jiranz
Posts: 73
Joined: Sep 22, 2006 3:56
Location: New Zealand

my wheel goes round

Post by jiranz »

I have a wheel rotating every minute or and a magnet stuck to it. There is a reed switch which closes momentarily everytime the magnet comes round. I need to measure the time between successive events (contact closures).

I have a USB to Serial adapter that I use with a FB program to control an external relay. This is simple port ON/OFF voltage switching control and no data transmission is involved so port defaults are used.

Example FB external equipment critical timing delay program
(assume #LANG "fblite" , #include "vbcompat.bi", OPTION GOSUB)

Code: Select all

  OPEN "com9:"  AS #1    
  t = TIMER + 10
  DO    
    IF TIMER >= t THEN EXIT DO    
    GOSUB dostuff:     
    SLEEP 10    
  LOOP
  CLOSE   
Questions:
1. Which contacts on the serial DB9 do I take the reed switch contacts to to send a signal back to my FB program so I can record the exact time that the reed switch contacts have closed?
2. How do I modify the above program just to get a recognition in my FB that an event has happened?

I have searched for answers. Even a link would be appreciated but nobody seems to have done things like this?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: my wheel goes round

Post by MrSwiss »

In short: you need a *MicroController, that reads the switch, and sends the Data (switch state)
to the PC, where the FB program is running (the communication is RS232-C, over USB).

*something like a Arduino, or similar ... (since it already has, a USB-port)
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: my wheel goes round

Post by Dinosaur »

Hi All

The cheapest and easiest way is to get yourself a USB I/O board that has Inputs and outputs.
Typically they can be opened using the Open Com Statement, and then using their commands read the inputs
or set the outputs.
Modern computers rarely allow direct inputs unless they have a True Parallel printer port or RS232 port.(usb to parallel or RS232 won't work).

Regards
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: my wheel goes round

Post by grindstone »

If you only want to check one switch, there's an easier way: Connect the reed switch to pins 2 + 3 of the RS232 plug (RxD / TxD). Then, in a loop, periodically send the actual TIMER value to the COM port and check if it is sent back. If so, the switch is closed.
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: my wheel goes round

Post by Dinosaur »

Hi All

That's clever
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: my wheel goes round

Post by MrSwiss »

Dinosaur wrote:That's clever
Sorry, but I think it's rather stupid, because:
to catch a fast switch (OP stated: reed-switch), you'd have to rapidfire the com-
port to actually ever 'get' a state change (it may still be missed!).

A µC can send, as the state change occures (without polling, by the host), by it's
own program, which takes plenty of load, off the host-program (and system).
IMHO, the only 'safe way' to solve the problem (not a tinkerer solution!).
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: my wheel goes round

Post by BasicCoder2 »

jiranz wrote:I have a USB to Serial adapter that I use with a FB program to control an external relay. This is simple port ON/OFF voltage switching control and no data transmission is involved so port defaults are used.
Care to share more about exactly what your project is about?
Why use a computer to control such a simple thing as the speed of a wheel?
You say you have FB code that allows you to control a relay via the USB to Serial adaptor? Seeing that code might help.
I controlled a robot via the K8055 board but that would cost money.
For simple on/off input (no output) you can hack an old joystick and use GETJOYSTICK to read on/off switches.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: my wheel goes round

Post by grindstone »

@MrSwiss:
jiranz wrote:I have a wheel rotating every minute...
I would suppose the computer can keep up with that wheel.
BasicCoder2 wrote:For simple on/off input (no output) you can hack an old joystick and use GETJOYSTICK to read on/off switches.
That's even better! :-)
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: my wheel goes round

Post by MrSwiss »

@grindstone and other tinkerer's,

this is probably the difference between pro's and amateur's:
amateurs are "taking chances", while pro's do it "safety first" ...
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: my wheel goes round

Post by lizard »

BasicCoder2 wrote:
jiranz wrote:For simple on/off input (no output) you can hack an old joystick and use GETJOYSTICK to read on/off switches.
That sounds good.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: my wheel goes round

Post by grindstone »

MrSwiss wrote:@grindstone and other tinkerer's,

this is probably the difference between pro's and amateur's:
amateurs are "taking chances", while pro's do it "safety first" ...
There's another difference: Amateurs usually don't have the budget of a company.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: my wheel goes round

Post by MrSwiss »

grindstone wrote:There's another difference: Amateurs usually don't have the budget of a company.
You don't really belive the nonsense above. I don't need a Company Budget, to buy an Arduino!
You probably carry more Money, than an Arduino costs, in your Pocket, on a dayly basis ...
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: my wheel goes round

Post by caseih »

I agree with a few of the posts here that your best bet is either a USB I/O board (they are very cheap and easy to interface with), or an Arduino that can either act like the USB I/O board[1] or just do the calculations and monitoring on the Arduino itself and spit out the information you need on the serial port.

[1] a system called Fermata allows the arduino to be a generic, serial-controlled, I/O device, but the protocol is a bit overkill.

Off-topic, but I discovered this cool piece of software that might fill the bill, though without using FB:
http://www.chemie.unibas.ch/~hauser/ope ... index.html
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: my wheel goes round

Post by grindstone »

MrSwiss wrote:I don't need a Company Budget, to buy an Arduino!
That's right, but on the other hand I don't need to buy (and program) an Arduino to monitor one single switch.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: my wheel goes round

Post by MrSwiss »

grindstone wrote:I don't need to buy (and program) an Arduino to monitor one single switch.
You've still not provided, a foolproof way of implementation ... (polling is definitely not it!).
There are far to many inconsistencies, in a multitasking OS like WIN or LIN.
Post Reply