about
This demo is meant to show how to control and monitor equipment attached to the
FlexStack via a web interface. While this is a simple demo that I'm throwing together in my free time, the power of opensource is in full effect. I am also using this project to finally dive into AJAX so I can add another buzz word to my resume.
The final demo uses the
FlexStack core module, communications board (ethernet), and DAQ board (AIN). Additionally the web interface allows the user to control 3 of the 4 leds on the core module (LED0 effects the DAQs operation so I had to remove control over it). I borrowed an IR thermal sensor outputs 1mV per degree F from a friend. This device also an external digital display that shows the reading so you can verify that what you see on the
FlexStack web interface is the same as the thermal sensor. Lastly some system stats are displayed so you can see what's happening on the
FlexStack (
free shows the system memory state, and
uptime shows uptime and system load).
- full demo source - This probably isn't of much actual use to you but may help you understand how to control hardware with python, or how to control hardware from a web interface.
web server
I am currently using
boa's CGI interface and developing everything in
python,
javascript, and
shell scripting. A few things turned out to be easier to do as shell scripts even though its a cumbersome CGI tool. I have a nice AJAX page that allows me to control/monitor hardware attached to the
FlexStack (or do anything else it can do for that matter) and maintain a slick 'web 2.0' interface (sans the round edges).
python
The entire application is written in python with only a few exceptions. The background processes called by the
javascript are
shell scripts. Additionally I already had some programs written in C to handle Blackfin DIO so I just wrapped those with python rather than recode them (its a demo after all, I had to get it done quickly).
Most functionality in the objects is implemented with python properties so assigning and reading the property calls the appropriate get and set methods.
PyWeb
I put together a small web library for use with the
FlexStack (or other blackfin systems). It has few features and is specialized to this demo but will be small and meet the requirements of this and other demos.
MIO
This object abstracts the multipurpose board interface. This should allow you to control the 16 DIO lines, 8 single-ended/4 differential analog inputs, and 2 digital outputs. Of course I don't need all of this functionality for the NI Week demo so I only implemented the SPI stuff (AIN and limited AOUT). The I2C based IO chips control DAC gain so the DAC acts funny but I can set voltages from 0 to 1.25V. This is because the IO chip comes up as pulled up inputs and I don't configure it so the DAC isn't really setup correctly.
MioDio
This defines the IOBit and DIO objects to control the I2C DIO chips on the DAQ board. The IOBit is an individual bit on the IO chip and the DIO object is made up of 16 IOBits. Since I didn't take the time to implement this these are just stub objects that go through the motions but don't really do anything.
Bfin
This module defines the PFlags, SPI and I2C classes that handle direct hardware access on the blackfin. The I2C object is just a stub since I didn't take the time to implement it.
PFlags
This object is also a stub since I had existing programs that gave me the functionality I needed for the demo. If implemented it would form the command need to set and clear IO bits on the blackfin (not I2C based IO). This would mainly be a wrapper around a program written in C but would also be easy to implement in pure python.
SPI
This object handles reading and writing to SPI based devices. I does so by directly accessing the
/dev/spi device on the blackfin. Additional flexibility is added by changing the chip select line although this method of using the SPI device may not be the best approach in a fully developed product.
mioMonitor
This is a simple python script that shows how to use the MIO object. In the demo this runs as a background process that continuously reads the ADC and formats the output for display on the website. The power of the object oriented abstraction is seen here. As a client using the DAQ board you only need to issue a few commands to use the board.
#create 't', an MIO board with configuration '1'
t=FlexStack.PyMio.MIO(1)
#enabled the board by turning power on
t.enabled = True
#prime the SPI bus with the command you want to issue, ADC only
t.primeAdc('\x88\x88')
#read the ADC (reading 16bits from 12bit adc)
adcVal = t.adc
#every thing below here is needed to understand the value the ADC spit out
#translate the read value to a real 12bit reading
adcRaw = (struct.unpack('H',adcVal)[0] & 0xfff0) >> 4
#translate the raw value to a percentage
percent = float(adcRaw)/(pow(2,12)-1)
#scale percentage to a voltage
volts = percent * 5.0
Install
Requirements
- Working blackfin toolchain and source (this demo used 2006R2-rc2)
- Python 2.4 or newer (see here or use 2007R1 release)
- boa webserver
- Generic SPI driver (provides /dev/spi)
- PFlags Driver
- PFlags interaction programs provided in the tarball on this page
Default System Setup
Install Guide
- Unzip the tarball linked above
- Copy the bin directory contents to uClinux-dist/romfs/bin
- Copy the cgi-bin and static directories to uClinux-dist/romfs/home/httpd
- Add to the appropriate rc file (likely in uClinux-dist/AnalogDevices/BF537-STAMP/rc)
ifconfig eth0 192.168.4.50 up
boa -f /etc/boa.conf &
echo export PYTHONPATH=/usr/lib/python2.4 > /root/profile.msh
echo export PYTHONHOME=/usr/lib/python2.4 >> /root/profile.msh
sh /bin/startMioMonitor.sh
- Add CGI handlers to the boa config file (likely in uClinux-dist/AnalogDevices/BF537-STAMP/boa.conf)
AddType application/x-httpd-cgi cgi
AddType application/x-httpd-cgi py
--
ChristopherPepe - 20 Jul 2007