October 2005

Xport to SQL

This program connects a microcontroller to a mySQL database via a Lantronix Xport and a PHP script.
The PHP script it uses is the SQL_datalog.php script in the Network Data Logging Suite.

Technorati Tags: ,


Continue Reading »

Lantronix
PicBasic Pro

Permalink

Network Data Logging Suite

This suite of programs takes data from a sensor and saves it to a text file on a network. Each sensor reading is time stamped. The suite illustrates the basic principles involved in sending sensor data to a networked file or database.
The first program involved is a microcontroller program, written in PicBasic Pro, tested on a PIC18F258. It waits for serial input from an external program. Then it reads its analog sensor, and sends the result out in two bytes.
The second program is the same microcontroller code in Wiring/Arduino, thanks to Jamie Allen for the cleanup.
The third program involved is a desktop computer program, written in Processing. It requests data via its serial port from the microprocessor and sends that data to a CGI program on a web server. It passes the data into the CGI using an HTTP GET request. This program only sends every three seconds, so as not to overwhelm the server with hits.
The fourth program is a CGI (common gareway interface) program, written in PHP. It takes in data from an HTTP GET request and appends it to a text file, along with the time the request was received. Note that this program does not check to see how big the file is, or whether the incoming data is properly formatted, so it isn’t terribly secure.
The fifth program is another PHP script that logs the data to a mySQL database. Running this doesn’t require any change in the microcontroller code, but it does require a slight change in the Processing code. The change is in the sentToNet() method, and is noted below.

Technorati Tags: ,


Continue Reading »

PicBasic Pro
Arduino/Wiring
Processing
PHP

Permalink

Linearizing Code for Sharp GP2D120 Infrared Ranger

This program takes input from a Sharp GP2D120 infrared ranging sensor and outputs the result in ASCII. The ranging formula comes from an excellent article on Acroname’s site, tweaked a bit to work with my circuit.

Continue Reading »

BasicX
PicBasic Pro
Arduino/Wiring

Permalink

Averaging and Finding the Median

Here’s how to find the average of 9 samples, or the median number of a sorted list of samples. Wiring and PicBasic Pro examples follow.

Thanks to Zach Layton for correcting my bubble sort code.

Continue Reading »

PicBasic Pro
Arduino/Wiring

Permalink

Weighted averaging of an analog input (Smoothing)

Here’s an example that filters an analog sensor reading by taking a weighted average of samples of the sensor. It’s based on this algorithm:

 filteredValue = x * rawValue + (1-x)*lastFilteredValue;

Where X is a value between 0 and 1 that indicates how reliable the new raw value is. If it’s 100% reliable, X = 1, and no filtering is done. If it’s totally unreliable, x = 0, and the raw result is filtered out. Examples for Wiring and PicBasic Pro follow:

Written in Wiring, tested on an Arduino board.

Continue Reading »

PicBasic Pro
Arduino/Wiring

Permalink