Gaming Community
Forum
 
Go Back   D3scene > Software/Hardware > Mac and Linux > Mac > Mac discussion
Register Blogs Live view Downloads Marketplace FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Microcontrollers connect hobbyist hardware to your Mac

This is a discussion on Microcontrollers connect hobbyist hardware to your Mac within the Mac discussion forum part of the Mac category; Your Mac can already talk to all kinds of electronic devices, including digital cameras, camcorders, printers, external disk drives, mobile ...


Welcome on D3scene.com! Make sure to register - it's free and very quick! You have to register before you can post and participate in our discussions with 70000 other registered members. Downloads, user profiles and some forums can only be seen by registered members. After you create your free account you will be able to customize many options, you will have the full access to new hacks, latest cheats and last but not least will see no advertisements at all. We would love to see you around in our community!
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 05-18-2008, 01:10 PM
Poosc's Avatar
Mac Mod :D

 
Join Date: Jan 2008
Location: In your computer :)
Posts: 344
Blog Entries: 1
Thanks: 2
Thanked 2 Times in 2 Posts
Reputation: 425
Rep Power: 4
Poosc is just really nicePoosc is just really nicePoosc is just really nicePoosc is just really nicePoosc is just really nice
Microcontrollers connect hobbyist hardware to your Mac

Your Mac can already talk to all kinds of electronic devices, including digital cameras, camcorders, printers, external disk drives, mobile phones, and other computers. But there are plenty of other gizmos that your Mac can’t communicate with: motors, robots, external LCD displays, and sensors of all sorts.
For your Mac to talk to one of these items, it needs something to act as a translator. That’s what microcontrollers do. Connect one of these programmable computers-on-a-board to your Mac’s USB port, and you can then hook an external device to the board and program it to tell that device what to do.
To show you what’s possible with microcontrollers and the Mac, I came up with a demonstration project that I call BreakTimer. This system enables your Mac to detect whether you’re sitting in your chair and, if you’ve been sitting too long, to tell you it’s time to get up and take a break.
Assemble the components

There are three components to any microcontroller system for the Mac: the microcontroller board, its OS X software, and the hardware you’re connecting to the microcontroller.
The most popular Mac-compatible microcontroller board is the Arduino. It’s open source (you can get the schematics and build your own), it’s very afford-able ($35 for a fully assembled board), and it works wonderfully with Mac OS X. The board itself is available from several sources; make sure you get the newer Diecimila model.
Once you have the board, you need the software that goes with it: go to this site, click on the Mac OS X link, extract the file that downloads, and then drag the resulting folder to your Applications folder. Next, install the board’s drivers. The most up-to-date driver software is also available; just make sure to get the right version for your particular Mac.
Connect the hardware

Now, if you’re trying my BreakTimer project, you’re ready to connect the seat sensor to your Arduino board. I’ve suggested some suppliers and part numbers, but you can source the hardware anywhere you like as long as it matches my description. Also, if you’re not already familiar with the process of wire wrapping, check out an online tutorial (alternate) before you start.
Once you’ve assembled your materials, cut two pieces of wrapping wire long enough to reach from your Mac to your chair. Using the wire stripper that comes with the wire-wrapping tool, strip about an inch from one end of each wire. Then, with the wire-wrapping tool, wrap one wire around each of the pins on the sensor.
Next, strip an inch from the other end of each wire. Using the wire-wrapping tool, wrap one of them to one lead of the resistor; wrap as high up on the lead as you can. With your cutters, detach a single pin from a row of male header pins. Wrap the end of the other wire to the short end of that pin.


Hardware Connections: This is the hardware you’ll be working with—the pressure sensor and a resistor connected to the Arduino board.

Now it’s time to hook it all together: Plug the end of the resistor that’s connected to the sensor pin into the hole on the Arduino board labeled Analog In 0. Put the male header pin that’s connected to the other sensor pin into the hole marked 5V. And the end of the resistor that isn’t connected to anything goes into one of the two connectors marked Gnd. (Your board should look like the one shown to the right.) Make sure that the pieces of hardware in Gnd and 5V aren’t touching, or you might get a short circuit. Finally, connect the Arduino board to your Mac through any standard USB A-to-B cable; avoid using a USB hub.
Program the software

With the hardware connected, launch the Arduino application. Open the Tools menu and select your board from the Board submenu. Then open the Serial Port submenu and look for an entry that reads something like /dev/tty.usbserial-A4001LBP. If there’s just one such entry, select it. If there’s more than one, quit the Arduino program and unplug any nonessential USB gear. When you restart the application, you should see just one entry beginning with /dev/tty.usbserial.
Now you’re ready to program the Arduino. The board uses a relatively straightforward programming language; if you’ve done any programming or scripting at all, you should be able to figure it out. (You’ll find a good reference guide.)
For this demonstration, I wrote a program (a sketch, in Arduino argot) that uses the sensor to detect how long you’ve been sitting down.
Begin by choosing File: New in the Arduino software. A window should appear with a tab at the top. Click on the right-facing arrow in the upper right corner of that window, type a name (in my example, BreakTimer ), and click on OK. Copy this code, and paste it into the code window.
Next, select File -> Upload To I/O Board. Some lights on the Arduino board (labeled TX and RX) should flash. When the upload is complete, the out-put pane of the Arduino program should show something along these lines: “Binary sketch size: 3046 bytes (of a 14336 byte maximum).”
Now it’s time to test your sensor: If you’re attempting my BreakTimer project, click on Arduino’s Serial Monitor icon and apply pressure to the sensor. A letter D should appear in the Arduino status window. When you release the pressure, you should see a U. Apply pressure for 15 minutes (you can adjust that to a shorter interval for testing purposes), and you should see a B. Click on the Serial Monitor icon again to stop monitoring these messages.


ASProxy at Work: Using Massimo Banzi’s free ASProxy, you can trigger simple AppleScript actions based on Arduino input.

Now that the sensor is successfully communicating with your Mac through the Arduino board, you need to tell your Mac how to respond. One way is to use Massimo Banzi’s free ASProxy, which monitors your serial port for single-character messages and triggers AppleScript actions based on those messages (see the screenshot on the right for an example). Or you can download the AppleScript add-in SerialPort X. After copying it into your user folder/Library/Scripting Additions, you can use it to write an AppleScript in Script Editor that monitors your serial port for input and triggers specific actions. Just make sure to save the script as an application and select Stay Open. (See a downloadable example of such a script for BreakTimer.)
The final word

This project is just one demonstration of the many things you can do with a microcontroller connected to your Mac. The Arduino board can talk to all kinds of sensors and other devices available from places such as SparkFun Electronics and Trossen Robotics. For more ideas, check out the Arduino site, particularly the Playground and Exhibition areas. From Macworld | Apple, Mac, iPod and iPhone News, Reviews, Help and Tips
Reply With Quote
D3scene
Welcome to D3scene - probably the best location for all Gamers.

To participate in our friendly environment you have to register. After completing registration you will have full access to all threads and features. We care about members and try to make your stay as pleasant as possible. We are unique with the following feature for members - you will not see a single Advertisement!


The best: registration is completely free. It will not cost you a single penny or harm you in any way. You will lose nothing except 1 minute of your time. So why not register? We would be happy to see you around!
Reply

Tags
hardware, mac, project

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A guide for switching to a Mac Poosc Mac discussion 0 05-08-2008 06:05 PM
Build a Hackintosh Mac for Under $800 Poosc Mac hacks 0 05-08-2008 03:07 PM
TOns of free software, tools, and some websites I wanna share :P (Mac users mainly) Velocity Software 13 08-27-2007 07:08 PM


All times are GMT +1. The time now is 10:16 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0 ©2009, Crawlability, Inc.
vBulletin style developed by Transverse Styles