Reading Analog Signals Into a Mac?

Discussion in 'Mac Programming' started by Earendil, Mar 7, 2009.

  1. macrumors 68000


    Quite simply put, I'd like to explore and make sure of analog signals, by reading them into my Apple computer.
    I'm a CS major, so have programmings knowledge (without the in-depth industry know-how), and am just now taking an intro electronics class (building simple circuits).

    What I can't find using google, is the difficulty level of getting an analog signal into a computer, and how much such a venture would cost. I'm a curious student, not a business man with capital and an idea to sell :)
    Are there Libraries built into Object-C to handle such a task? Or will devices come with an SDK to make that software to hardware mesh?

    Could someone lay the general idea down for me?
    Bonus points for sticking around to answer any specifics I might have.
    Bonus points and a brownie if you tell me that it's as easy to interface an analog signal with a Mac, as it is with an iPhone ;-)

  2. macrumors 68040


    You need to be a bit more specific. Is this analog signal a sound? If so you could just record it via the mic, then do whatever you want with the resulting digital data. I am guessing this is not it, but you didn't mention at all, so who knows? Essentially the first "hard" part of this is getting the analog signal digital and getting the digital signal in to your machine. Do you know if there's already something like this for the device in question that converts the signal into a digital format? If so, what interface is available (USB, Firewire, serial, parallel, etc)? If not, are you going to have to construct your own?

    Once you have a means of digital acquisition of the raw data, you'll need a "driver" to actually gather this up and make it available on the system. I don't know much about how one goes about writing such a thing, but i'm betting others do.

    Once you have this done, i would guess that the easiest step would be to interact with the device via C and system calls of some sort. Since Objective-C can call into C, C is Objective-C, etc. that seems like the most straight-forward to me. Once you have a means of pulling data from the device into a C routine, it should be pretty easy to manipulate in Objective-C from that point on.

    Give some more information, and maybe someone will be able to point you in the right direction.

  3. macrumors 68000


    I would love to give more details!
    I have a couple analog signals I want to record. One is something like 0-5v and powers a gauge, the other is something more like 0-1v and can be thought of as something similar to a temperature sensor.

    You are correct, it isn't sound. I'm aware of those kinds of input devices ;-)
    But hey, if I could take the signal down to a safe voltage/amperage, and put it through the Mic jack and get the information I wanted from that, I suppose that could work...
  4. macrumors 603


    You might be able to do something using a microcontroller with a USB port and an ADC (Analogue to Digital Converter). Could be quite a fun project actually.
  5. macrumors 6502


    As lee said, for a real advice, we'd need to know more about the type of measurements you want to take - especially accuracy and sample rate.

    One thing that I could suggest for near-static signals is buying a multimeter with RS232 interface plus a RS232 to USB adapter (all together $100 or less). If you are serious about playing with electronics, you'll need a good multimeter anyway, and communicating over the serial port is straightforward. Just make sure that you have documentation for the commands needed to control the instrument (and not only some Windows software).

    For measurements of dynamic signals, you should probably first read up on data acquisition and A/D conversion; then you can look more specifically for suitable solutions. National Instruments ( offers a range of USB multifunction acquisition devices with OS X support; the cheapest is at $170 without academic rebate. Other than that, Google is your friend :)
  6. macrumors 6502a

    How about one of these little things:-

    I've a friend who's been playing around with one and he's been hooking it up to do all sorts of things on his Mac. It's got 6 analogues inputs 0 - 5v. The board is very cheap, Around £20 I think. It's well supported in Processing (the Java based IDE) on the Mac so is easy to program. Not sure about controlling one in Objective-C though.

    b e n
  7. macrumors 6502


    I think we have a winner here...
  8. macrumors 6502


    They have a few kits. Basically you need something with a USB/Serial interface that your computer can 'talk' too, this something then takes care of the ADC tasks. There are plenty of kits that do this, but normally they are DOS/Windows focused so you may need to find Mac drivers or write your own.

    Linux driver that could work under mac
  9. macrumors 603


    My Dad has got one of those. They are pretty damn slick, and have an AVR microcontroller so technically you should be able to use them in the same way. They also come with their own Mac OS X IDE which actually works and uses a very C like language.
  10. macrumors newbie

    another vote for Arduino

    I agree that the arduino boards seem like the best solution. Processing is easy to use and from what I've seen with a friends project the boards are well made too.
  11. macrumors 6502a

    Sounds like you've got a pretty cool dad Cromulent!

    Yeah the Arduino looks good. Think I'm going to get one myself.

    b e n
  12. macrumors 6502a


    Ugh... Arduino's...

    I'm kind of an elitist when it comes to microcontrollers/microprocessors. What I don't understand is why don't you hook the circuit up to a Logic Analyzer or Oscilloscope with a USB attached to it?

    From what I am reading it seems like you are just testing to see the data from a PWM (Pulse Width Modulator) and a temperature transducer...

    Trust me on this one, being an ECE student (and in his senior year) you'd be better off using a Logic Analyzer, saving it as raw data onto a jump drive then analyzing that on your Mac. It's not a good idea to be using your Mac for grabbing signals without the proper system between the two to make sure your Mac or your circuit to be destroyed. Plus, once you understand how the data is working from a raw point, you can then develop a system to translate it for you to your Mac.

    On a side note, it sounds really familiar to my senior design project... Hmmm... :rolleyes:
  13. macrumors 6502a

    That little board above looks good but just in case you can't get hold of one, how about taking apart an old game controller and using the analogue axis controls for your own purposes? I would expect that the axes will simply be controlled by potentiometers which will "wipe" from +5v to 0v. You should be able to just connect the wiper to your 0-5 volt source and connect your ground to the game controller ground. Same with the 0-1v signal.

    If you then use the drivers which came with the game controller then you should be able to use the OS X game controller API's to read the values. Note, I don't know anything about OS X game controller API's by the way... Maybe someone else can help with that. :)

    I would suggest that you be very careful when interfacing to your Mac to avoid damage. Ideally use zener diodes or clamping diodes and current limiting resistors to prevent your inputs from going beyond the working voltage of the interface. Something like a 5v1 reverse biased zener across the input with a 100 ohm resistor in series with your input signal.

    I hope this helps,
  14. macrumors 68000


    Cost? Don't Oscilloscopes and Logic Analyzers at least $100, with good ones being $500-$1000?
    I'm all for being elitist (I'm on a Apple forum, right? ;) ) but cost is a prohibiting factor.

    Besides, as long as I'm using a common board like the Arduino, shouldn't that be adequate protection for my computer? Assuming the signals going into the board are already pretty docile, the output can't get too out of wack.

    I'm in an Electronics class for my senior year in CS, so I'm getting my feet wet with this type of stuff. But there is still a our knowledge base that I lack when it comes to getting instrument signals into a computer where I can access them with my code :)
  15. macrumors 6502a


    Your university should have Oscilloscopes and Logic Analyzers for you to use. Also, yes the Arduino has sufficient protection against weird signals to your Mac, but the Arduino has a different C syntax than what most microcontrollers use, which in my opinion is bad.

    The Arduino is a great dev board for a hobbyist, but if you want to learn things properly, you should be doing it the hard way of programming, and learn straight up C, not this hybrid BS for people who don't know how to program.

    To help you out understanding signals, look into getting a couple of my professor's text books.

    His book mainly focuses on the Motorola Freescale line, but a lot of subsystems are in all the other controllers. Plus, there are timing diagrams for you to look at!

    BTW, what kind of Electronics class is this? A Microprocessor's class, basic transistor/VLSI class? Etc...
  16. macrumors 603


    There is nothing stopping you from dropping down into ASM as far as I know. The Arduino is after all an AVR microcontroller.
  17. macrumors regular

    I haven't used it, but the Teensy USB ( is a $20 board with an AVR microcontroller, a full-speed USB interface, and Mac software. Code can be uploaded via the USB cable, so no expensive programming cable is required.

    You'll probably want to read the AT90USB162 datasheet to find out how to use the analog-to-digital converter (ADC). If you find the datasheet too scary, you might be better off with an Arduino :p
  18. macrumors 6502a


    Very true. All I'm saying is that to learn things properly, it's better to know exactly how and why it's working rather than have a board handed to you with a few pages of documentation.

    Doing it in ASM would definitely be awesome to do on the board, but you might run into an issue with ADC (Analog-to-Digital Converter) processing. Mainly if you want to have the thing interrupt based rather than polling.
  19. macrumors newbie


    Or alternatively, you could use this one along with its nifty looking test UI application. The 8055 board only has 2 analog inputs though and they aren't terribly sensitive as the device only has an 8-bit DAC.
  20. macrumors 6502


    I'm an arduino as a model railway controller, I use the analog pins to detect and measure the back emf of a locomotive. It even sends/recieves UDP packets with data to/from my macbook via my network using an ethernet shield.

    It's not hybrid BS, you can use normal C with arduino. Personally I don't like the arduino IDE, and prefer working in straight normal C or ASM. I use a plug in for textmate and a modified makefile to compile my C/C++/ASM code from the command line. It is also possilbe to use the eclipse IDE as well. At the end of the day you can code and program it as you would any AVR chip using avr-gcc and avr-dude.

    I would recommend getting the seeeduino variant of the arduino , as it has two extra ADC pins. I'd download the arduino software, at least it has example code for reading in analog values from things like temprature sensors amongst other things.

    PM me if you want a copy of the makefile, or a hand getting started with arduino
  21. macrumors 6502a


    If you use the Arduino IDE with default, it is hybrid. It uses a hybrid C and their language to do the job, but that's getting into symantics. Besides, why use one of those when you can get your own microcontroller/microprocessor for like 20 bucks and make a customized layout/board for it? You'll have better known and more appreciation for doing it that way.
  22. macrumors 68000


    Well to name one of millions... I want to learn more than I have time and resouces for. So, my options are to not mess around with the electronics world for fear I won't "fully appreciate it", or that I won't understand it "fully". Or I can get a general understanding, and use electronic devices as additions to MY world and choice of education, computer science/software engineering.

    I understand where you're coming from, as I feel the same about visual basic vs c++ etc. How ever I would be happy if every human new visual basic than what the current situation is(that is one of worse that no knowledge, but misconception). Any, that is mho, take it or leave it :)

Share This Page