Simple EMC-Arduino HOWTO

OK, so, the PCBs I was supposed to get early this week got stuck in customs in Shanghai, so I decided to take a few hours and put together a minimal Arduino-EMC case study with source code for those of you trying to follow along at home.

This example code is designed to control a normally-open switch and two LEDs, and is wired up to the machine on/off switch. I chose that configuration to test a cool new doohickey I got with my last Digikey order, which is a two-color illuminated pushbutton switch from NKK Switches (see here). It’s got a pushbutton plus two LEDs in a nice little package. It’s not sealed up the wazoo like a true industrial component, but it shouldn’t do any worse than the mice and keyboards people use in their shop. Either way, you should be able to replicate this example with any two LEDs and switch you have laying around–the Arduino and EMC parts won’t be any different.

I’ve attached all the code for this example as pages on this blog (WordPress is annoyingly whiny about file attachments other than common types like JPG, DOC, etc.). Here’s a basic outline of how to do this for yourself:

  1. Create the Arduino sketch using my sample code. Wire up a breadboard with 2 LEDs and a normally-open switch and connect them to the Arduino. Just to be safe, I strongly suggest firing up the Arduino serial monitor and trying to send and receive commands there just to be sure you have the circuit and Arduino working properly before proceeding.
  2. Once that’s known good, you’ll want to install the Python module in your /usr/bin directory. First, copy and paste the source code into a text file and save it as “simple_arduino” without any file extension. Then, move that file to your /usr/bin directory and make it executable using these commands:sudo cp simple_arduino /usr/bin
    chmod +x /usr/bin/simple_arduino
  3. Configure your HAL file: This uses the HALUI module to pass commands to EMC. See here for my sample HAL configscript. Make sure that your machine .ini file loads the HALUI module and runs the script.

If the comments in my code don’t answer all your questions about how it works, feel free to leave questions in the comments. Good luck and have fun experimenting!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: