03.05
uLog
WHAT IS THIS?
uLog is a tiny analog logging device from Sparkfun. The uLog have an onboard flash memory mated with a ATtiny24. It don’t need a microcontroller, but can only take data on three analog inputs.
Feature:
- small size
- have 3 analog inputs
- on/off switch on board
- designed for 3-axis accelerometer
- 16MB data size
- 50Hz sampling rate
- about 2 hours logging space
- battery usage about 4mA per hour
HOW TO LOG:
Let’s use a photo cell as an example:
Connect to your battery, you will see the red light flashes. Then connect your sensor to one of the three input pins, use your breadboard to help you wire it up. Then you are ready to go. Turn on the on/off switch on the back to log the data. (Remember, don’t wire any thing on the Tx/Rx when you log your data, any wire on them will cause the Logger into configuration mode). The uLog only have 16MB space for data, it automatically append the new data into the ends and overrides the old one (from the beginning) if the memory full.
HOW TO READ THE LOG:
Use a USBtoSerial adapter to wire your uLog. Need 3.3 voltage one, not 5 voltage.( If you don’t have one, you can use your arduino instead, either pulling out the ATMEL chip or upload a code without any serial communications,check this as reference). Here is how your wire it. (If you use arduino, Tx<->Tx Rx<->Rx, connect your Tx to Tx, Rx to Rx).
Basically, if you send ‘r’ to your serial port, the uLog will send all the logged data, if you send ‘e’ to your serial port, the uLog will erase the memory.
Based on Tom Igoe’s processing code, I filter the noise data and convert hex into integers.
Run the sketch, type ‘r’ in the opened window to read the data, type ‘e’ to erase the data.
import processing.serial.*;
Serial myPort; // instance of the serial library
String dataString = ""; // string of data for each set of readings
String[] data = {""}; // array to save strings to a file
boolean reading = false; // whether or not you're reading from the logger
String filename = "datalog.txt"; // string to save the file to
int lineCount = 0; // count of the number of lines in the file
void setup() {
// open the serial port:
myPort = new Serial(this, Serial.list()[0], 38400);
// flush the serial buffer:
myPort.clear();
}
void draw() {
}
void serialEvent(Serial myPort) {
// get a byte:
int inByte = myPort.read();
// do something different depending on what the byte is:
switch(inByte) {
case '?': // response prompt
// if you're already reading from the logger,
//save the results to a file:
if (reading) {
saveStrings(filename, data);
// you're done reading:
reading = false;
// print the linecount:
print("lineCount: " + lineCount + "\0\r");
}
// print the prompt:
println(char(inByte));
break;
case '\r': // carriage return at the end of each line:
// make sure you have at least four characters:
if (dataString.length() > 4) {
//filter the data and covert from hex to integer
String[] t = splitTokens(dataString);
String newData = "";
try{
for(int m = 0; m < t.length; m ++){
if(t[m].length() == 4){
int value = unhex(t[m]);
newData = newData + ' ' + value;
}
}
}
catch(Exception e){
break;
}
// add this string to the data array:
data = append(data, newData);
println(newData);
// increment the line count:
lineCount++;
}
// clear the string variable for the next string:
dataString = "";
break;
case '\n': // newline: get rid of them
break;
default: // any other character:
// add character to the string:
dataString += char(inByte);
break;
}
}
void keyReleased() {
if (key == 'r') {
reading = true;
println("Reading from logger...");
// send keystroke to the logger
myPort.write(key);
}
if (key == 'e') {
println("erasing data from logger...");
// you're erasing all the data on the logger
// wait until the LEDS stop flashing before you disconnect it!
// send keystroke to the logger
myPort.write(key);
}
}



