PDA

View Full Version : How to go about interfacing a sensor to USB?



flyingsliverfin
October 3rd, 2011, 01:33 AM
I was wondering where or how I can learn the basics of interfacing a sensor to USB for a project of mine. Eventually i would want to connect an accelerometer (for testing for very small vibrations) to a port, then somehow grab that input in a program (which i also still have to figure out how to write :))

Also something that doesn't go into nitty gritty details would be nice :) I've got about 3 months for this (but i also have to do schoolwork/sports/instrumental practice) which leaves about every weekend free...

alphacrucis2
October 3rd, 2011, 02:12 AM
I was wondering where or how I can learn the basics of interfacing a sensor to USB for a project of mine. Eventually i would want to connect an accelerometer (for testing for very small vibrations) to a port, then somehow grab that input in a program (which i also still have to figure out how to write :))

Also something that doesn't go into nitty gritty details would be nice :) I've got about 3 months for this (but i also have to do schoolwork/sports/instrumental practice) which leaves about every weekend free...

What sort of electrical ouput does the accelerometer have? Some are available with USB. Older ones might output RS 232 style serial for which you could use a serial-usb converter. You will also need software to read the data from the USB port.

euler_fan
October 3rd, 2011, 02:37 AM
What sort of electrical ouput does the accelerometer have? Some are available with USB. Older ones might output RS 232 style serial for which you could use a serial-usb converter. You will also need software to read the data from the USB port.

+1: If you have already picked up the sensors, then posting the specs would be a big help.

On the other hand, there are development boards for various processors which have analogue inputs that could be used. Arduino is one example of such a family. I have also messed around with ARM-based development boards where the analogue input is written to a memory address which can then be read. Either will require learning assembly or something like it.

compubob
October 3rd, 2011, 03:26 AM
your best bet is getting an Arduino
you can read many types of sensors, hook up a LCD display if you want and readout whatever info you want. You can output all your data to serial and write a program in whatever language you want to capture it and even output back to the arduino.
I have done many things with Arduino's which include controlling climate in small greenhouses and even controlling the all wheel drive system on a race car with a G-Sensor.

flyingsliverfin
October 3rd, 2011, 04:22 AM
What sort of electrical ouput does the accelerometer have? Some are available with USB. Older ones might output RS 232 style serial for which you could use a serial-usb converter. You will also need software to read the data from the USB port.


I haven't got one yet, I'm still gathering general info. First time I'm doing something like this, so i figured research first then actually start

flyingsliverfin
October 3rd, 2011, 04:23 AM
your best bet is getting an Arduino
you can read many types of sensors, hook up a LCD display if you want and readout whatever info you want. You can output all your data to serial and write a program in whatever language you want to capture it and even output back to the arduino.
I have done many things with Arduino's which include controlling climate in small greenhouses and even controlling the all wheel drive system on a race car with a G-Sensor.

Sounds like a place to start. I'll look into this next weekend (its already sunday night!!! :( )

red_Marvin
October 4th, 2011, 12:27 AM
Be aware that moust if not all accelerometers available are surface mount,
and on the trickier side of the surface mount scale too, are you proficient
with a soldering iron?

I think sparkfun has some breakout boards for various sensors though, probably other places too.

A minimal setup would likely consist of the sensor chip, a microcontroller
and an ft232 rs232 to usb converter. The microcontroller is needed since
you are unlikely to find a sensor chip that you can connect directly to
the ft232 circuit. The microcontroller would need to be programmed, so you'd
need hardware for that too.

By the level of your questions I'd guess that you are new at this, so an
arduino as mentioned above is probably a good idea, you get the microcontroller,
the computer interface as well as the programming hardware in one package.
As for the sensor, I'd suggest you'll try to find one with an SPI interface
and mounted on a breakout board. Make sure that it is 5V tolerant, or that
neccesary circuitry is mounted on the breakout board.

flyingsliverfin
October 4th, 2011, 12:48 AM
I'm a fairly competent solderer, but I don't know much of the other stuff... sounds like Arduino is the best bet.
Too bad they don't teach any of this stuff in high school, seems like it could get really interesting.

flyingsliverfin
October 10th, 2011, 05:05 AM
So according to my math, I'd be measuring a ~1 mHz vibration... possibly lower depending on what kind of material i decide to use in the end. That seems like a good number to start with though :)
Depending again on the material the amplitude of the wave would be around 1 micrometer.

Out of time again... next weekend ill continue

red_Marvin
October 10th, 2011, 12:46 PM
I'm usually not nitpicky when it comes to capitalization of m/M prefixes,
since it is usually obvious from context what wether milli or Mega is
meant. But since it would here mean two very different measurement
situations; do you mean milliHz or MegaHz?

Also, since it is a question of movement on the micrometer scale,
you would do well to check the sensitivity of any sensors you
consider.

flyingsliverfin
October 10th, 2011, 11:44 PM
oops yes its 1 MHz

also just found out the ADC sampling rate of the arduino is ideally 10 KHz... might need to find an external board then.

red_Marvin
October 11th, 2011, 01:47 PM
Well, if you can find a sensor that is digital (e.g. communicates with SPI)
and has high enough sampling rate, there should be no problem, in that respect.

However, how many points per oscillation period do you need? If you want to
measure frequency, the nyquist theorem says that you will need two points
per oscillation of the highest frequency that you want to be able to measure,
in your case with a 1MHz upper bound, it would mean sampling at 2MHz,
which in turn, assuming SPI, and 8bit resolution would imply 16MHz continuous
data transfer, ignoring things like the slave select toggling, and sending
command words that you likely will need to do.

Now imagine 1MHz not being the upper bound, but somewhere in the middle,
and you want up to 2MHz with 16 bit resolution - then you need 64MHz
data transfer rate at the least, out of the league of any avr.

However, the digital electronics is not your problem, there is always a
bigger and faster (and more expensive) controller you can get,
however your requirements for the sensor seems tough (high frequency,
high sensitivity), have you considered other things than an accelerometer?
Maybe piezoelectric materials?
Edit: another suggestion I got from #electronics was strain gauges.

In other words, find a suitable sensor, before locking yourself to a processor
architecture and setup.

Also, what is your budget for this? Can you borrow equipment?
Is this for school? (it sounds like it) If so, on what level?
What is it that you actually want to measure?

Paqman
October 11th, 2011, 02:12 PM
oops yes its 1 MHz


Yeah, 1mHz would be less of a vibration, and more of a very leisurely swaying.

flyingsliverfin
October 12th, 2011, 03:12 AM
Yea i was looking at piezoelectric sensors actually - using an accelerometer seems too complicated. I think these analog(?). Therefore I need an ADC.
Its part of a personal project that I may submit to science fair, I'm still thinking about it.
Its not for school... my high school doesn't offer anything Electrical engineering and not much in terms of CS (only 2 classes, computer programming (basic) and AP comp sci which I'm taking in 11th grade -next year- but I doubt they teach anything like this). I wish they did but I don't think many people would sign up. Our programming club only has about 20 members (of 2400 students across all 4 grades), if that's a good indicator for interest




Now imagine 1MHz not being the upper bound, but somewhere in the middle,
and you want up to 2MHz with 16 bit resolution - then you need 64MHz
data transfer rate at the least, out of the league of any avr.


Just wondering, wouldn't that be 16*2 = 32 MHz? maybe I'm wrong, just started learning about all this resolution/MHz stuff

red_Marvin
October 13th, 2011, 12:39 PM
If the highest frequency signal you want to measure is 2MHz you need to sample at 4MHz, as per the Nyquist theorem.

flyingsliverfin
October 13th, 2011, 11:19 PM
ah now i see where u got that number :)

flyingsliverfin
October 15th, 2011, 12:02 AM
Im having trouble finding out how to convert my 1 um (the amplitude of the vibration) to something I can apply to sensitivity of sensors. Piezoelectric sensor sensitivity always seems to be given in mV/g. How does this relate to the amplitude of the wave I'm measuring? Why do they show in terms of g?

flyingsliverfin
October 15th, 2011, 01:28 AM
Actually I figured it out with some help from my dad:
Assuming its 1 Mhz and 1 um amplitude (no longer sure about these values esp amplitude):
time for 1 period = 1/10^6th of a second
z(t) = 1um * sin(t*2pi/(1/10^6))
take second derivative:
z" = -4pi^2*1um*10^12 (sin(2pi*t/T))

the sin part can be ignored since we're concerned with the max height and that turns to 1 so:

z" = -4pi^2 * 1m * 10^6 = m/s^2
(ignore - part)
−39478417.6/9.18 (g) = 4300481 g's

that's a pretty huge acceleration

euler_fan
October 16th, 2011, 11:41 PM
If you really believe you know where most of the energy in the signal is (for instance, you have some good reason to believe that there are no significant vibrations outside 0.75-1.25 MHz) then you could also intentionally under-sample the signal and then use aliasing to retrieve data in the correct frequency band.

Just bear in mind that you need to be very sure about the signal or else your data will be useless because you will never be able to pull out just the part you are looking for from the lower frequency signals in the aliased band.

Roberto Christi's Digital Signal Processing book gives a good introduction to this process.

HermanAB
October 17th, 2011, 05:56 AM
Here you go:
http://labjack.com/products

red_Marvin
October 17th, 2011, 01:26 PM
It seems that the labjack has too low sample rate unless 1) I have missed something or 2) one goes the aliasing route.

flyingsliverfin
December 10th, 2011, 04:43 AM
ended up getting one of these (http://www.ti.com/product/ads7886) ADC's to play around with. Looked like one of the simplest I could find (only 6 pins :D; less confusion for me)