This code reads three sensors and sends them out serially when prompted by another computer. It works with this Processing example. Arduino/Wiring, PicBasic Pro, and BX-24 versions are shown.
Continue reading “Serial Call-and-Response (Microcontroller side)”
This program controls a stepper motor from an analog input. In testing it, I used a potentiometer, which gives a persistent value. An analog input that changes when it’s not contacted, like a SpectraSymbol linear or circular pot, wouldn’t work with this example.
Thanks to the Fall ’05 Wednesday morning class for the early experimentation on this code.
Written in PicBasic Pro, tested on a PIC18F252
Continue reading “Stepper motor controller from analog input”
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: networked objects, networks
Continue reading “Xport to SQL”
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: networked objects, networks
Continue reading “Network Data Logging Suite”
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 “Linearizing Code for Sharp GP2D120 Infrared Ranger”
Here’s how to find the average of 9 samples, or the median number of a sorted list of samples. Arduino/Wiring and PicBasic Pro examples follow.
Thanks to Zach Layton for correcting my bubble sort code and Zach Lieberman for the correction.
Continue reading “Averaging and Finding the Median”
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 C for Arduino
Continue reading “Weighted averaging of an analog input (Smoothing)”
updated 9 Sept 2014
This example finds the peak value of an analog sensor over time. It assumes the sensor is moving in a simple curve.
The peak value is initially set at zero. The program checks to see that the current value is greater than the current peak value. If so, then it saves the current value as a peak. If the current value is below a given threshold and the current peak value is above it, then the current peak is taken as the final peak. This example also includes a noise value, that allows you to adjust for sensor fluctuation.
The graph below gives you a visual sense of how the program operates. At readings 1, 2, and 3, the latest reading becomes the new peak. At reading 4, the peak remains unchanged because reading 4 is less than the last recorded peak. But the peak isn’t reported until reading 5, when the current reading goes below the threshold. This is the one disadvantage to this peak finding method: you don’t know you’ve had a peak until after it’s over.
Continue reading “Peak Finding”
For those applications where you want to sense a person touching an object, but can’t use a switch or a force-sensitive resistor, charge-transfer touch sensors can often be very useful. The one used in this example is made by Quantum, and it’s very simple to use.
Continue reading “Qprox Capacitive Touch Sensors”
Most of the time, you don’t need to know whether a switch is on or off so much as you need to know when it changed. You want to know when it turned on or when it turned off. In other words, you want to find the edge of the transition from on to off, or vice versa. This is often called edge detection.
The basic idea is that you check not only what the state of the switch is, but what the state was the last time you checked, and compare the two. Here’s an example in PicBasic Pro:
Continue reading “Edge Detection”