AXIS: EMC2 Blog
Blog
About AXIS
Get EMC2
Documentation
Translations
ETCH CNC
Developer Homepages:
Chris Radek
Jeff Epler
Related sites:
linuxcnc.org
linuxcnc wiki

« Analog inputs with Arduino and EMC | Newest entries | Generating HAL files from Eagle schematics »

Building on my earlier work, I've now improved the interface between HAL and the Arduino board to have:
  • 6 10-bit analog inputs
  • 6 8-bit PWM "analog" outputs
  • 6 digital inputs/outputs (partition chosen when component is loaded)
  • GPL license statement in source files
As before, the driver consists of an Arduino Sketch (halintf.pde) and a HAL Userspace Component written in Python (arduino.py).

First, load the sketch (firmware source code file) in the Arduino GUI, compile it, and transfer it to the board. The program will remain in the microcontroller's flash rom until it is replaced by another one.

Now, if you don't already have it installed, install python-serial using apt-get or Synaptic Package Manager. (if this command doesn't print an error, python-serial is installed: python -c 'import serial')

Next, copy arduino.py to the name arduino (no extension) in a directory on your PATH. Make it executable: chmod +x bin/arduino

To demo it, in the sample hal script, change the loadusr -W arduino line to reflect the serial port where the arduino is connected. In the directory with the hal file and the pyvcp definition file, halrun arduino-vcp.hal. A control panel should appear which shows the arduino's inputs and allows the outputs to be manipulated.

Arduino 'halintf' pinout
Silkscreen Text
(Diecimila board)
HAL pin name
ANALOG IN 0, 1, 2, 3, 4, 5arduino.analog-in-##
DIGITAL 2, 4, 7, 8, 12, 13arduino.digital-out-##
or arduino-digital-in-##
PWM 3, 5, 6, 9, 10, 11arduino.analog-out-##

In addition to the standard pins and parameters for digital and analog inputs and outputs, the digital inputs offer the '-pullup' parameter. Setting this to TRUE enables the corresponding weak pull-up built into the AVR microcontroller.

For the analog inputs and outputs, the default gain/scale of 1.0 makes 1V correspond to 1.0. The effective range is thus 0.0 to 5.0.

The items on the 'loadusr' commandline are: the serial port where the Arduino is connected to the PC, and the number of digital I/O pins to use as outputs. The lower-numbered digital pins are outputs, and the higher-numbered pins are inputs. If not specified, these pins are split 3 "in" and 3 "out".

Technical details

The protocol is similar to the earlier revision: 2-byte packets with the top bit signifying "first" or "second" byte. 3-bit address. 11 bit payload. 6 of the 8 addresses are used.

For the 6 "input" addresses, the low bits of the payload are an ADC input value. The high bit of the payload is an input pin value.

For the 6 "output" addresses, bits 7..0 of the payload are a PWM output value. Bit 8 is the pin direction, and bit 9 is the pin value (or pull-up enable for inputs).

Arduino 'halintf' packet format
ByteBit 76543210
01address 2..0payload 10..7
10payload 6..0

Files currently attached to this page:

halintf.pde1.8kB
arduino.py4.1kB
arduino-vcp.xml2.5kB
arduino-vcp.hal1.5kB



Entry first conceived on 25 December 2007, 14:51 UTC, last modified on 26 December 2007, 1:50 UTC



Copyright © 2004-2009 Jeff Epler
[æ]