User Tools

Site Tools


prensf2010:arduino

Arduino <-> USB Project Page

The purpose of this project is to adapt the existing Arduino-to-USB project to work as a data-collection device when hoisted on a weather balloon. This idea originated with Dr. Peterson.

Messed up version of the original code from the playground
*Sigh*

This one works as an interpreter for a user talking to the VDIP1

Current Revision

The current state of this project has been reviewed as of 7/12/2010.

The circuit design is functional and the form factor modified from the original full size breadboard to a smaller development shield for the Arduino Deumilanove



A photo-resistor has been added to test data-gathering, and it shows promise, though there are still problems with the data write facility. More to come.

// NAO
// 2010
// Programmatic access to the VDIP1 usb controller
// Implemented commands:
// 
//  IPA => extended command set.
//  OPW => open for write
//  WRF => write to file
//  CLF => close file
//  IDD => identify disk drive
//  FS  => free space
//  RD  => read
//
// These are a basic subset of the commands available 
// for communicationg with the VDIP1 chip.
#include <NewSoftSerial.h>
#include <string.h>
#include <stdio.h>
NewSoftSerial usb(2,3);
int sensorPin = 0;
int data[50];
void setup(){
  usb.begin(9600);
  Serial.begin(9600);
}
int r=0;
int idx=0;
void loop(){
  //debug();
  if(idx<50){
    data[idx]=analogRead(sensorPin);
     //Serial.println(analogRead(sensorPin));
     delay(100);
    idx++;
  }else{
    idx=0;
    char name[25];
    int n;
    n=sprintf(name,"%d.txt",r);
    ipa();
    openFile(name,n);
  
    writeToFile(50 , data);
    usb.print(13,BYTE);
    debug();
    closeFile(name,n);
   
    debug();
    r++;
  }
}
// Returns any output available in the serial buffer of the VDIP1.
int debug(){
  Serial.println("\n##VDIP##");
  usb.print(13,BYTE);
  while(usb.available()){
    Serial.print(usb.read(),BYTE); 
  }
  Serial.println("");
}
// Just used as a tester function.
int ipa(){
  Serial.println("\n##Nove##");
  char o[]="IPA";
  for(int i=0; i<3; i++){
    Serial.print(o[i]);
    usb.print(o[i]);
  }
  usb.print(13,BYTE);
  debug();
}
// Give it a filename and all will be well. 
// This function creates a new file on the 
// disk for writing to. When the write is finished, closeFile
// MUST be called or the data written will likely be corrupted.
int openFile(char fileName[],int len){
  Serial.println("##Nove##");
  char o[]="OPW ";
  // Send command
  for(int i=0; i<4; i++){
    usb.print(o[i],BYTE);
    Serial.print(o[i],BYTE);
  }
  // Then filename
  for(int j=0; j<len; j++){
    usb.print(fileName[j],BYTE);
    Serial.print(fileName[j],BYTE);
  }
  // Terminate command
  usb.print(13,BYTE);
  // Listen for debug
  debug();
  // return...
  return 1; 
}
void writeToFile(int numBytes, int dat[]){
  Serial.println("\n##Nove##");
  char o[]="WRF ";
  // for every data point
  for(int i=0; i<numBytes; i++){
    int n;
    char buffer[10];
    n=sprintf(buffer,"%d \n",dat[i]);
    // Declare file write
    for(int h=0; h<4; h++){
      usb.print(o[h],BYTE);
      Serial.print(o[h],BYTE);
    }
    // With n bytes of data
    usb.print(48+n,BYTE);
    Serial.print(48+n,BYTE);
    // Terminate WRF command
    usb.print(13,BYTE);
    Serial.println("");
  
    // Send data char by char 
    for(int j=0; j<n; j++){
      usb.print(buffer[j],BYTE);
      Serial.print(buffer[j],BYTE);
    }
    Serial.print("");
    debug();
  }

}
// Requires the filename of a currently open file
void closeFile(char fileName[],int len){
  Serial.println("\n##Nove##");
  char o[]="CLF ";
  
  for(int i=0; i<4; i++){
    Serial.print(o[i],BYTE);
    usb.print(o[i],BYTE);
  }  
  for(int j=0; j<len; j++){
    usb.print(fileName[j]);
    Serial.print(fileName[j]);
  }
  usb.print(13,BYTE);  
  debug(); 
}
// Prints the identifying information 
// of the slave disk attached to the
// VDIP1
void idd(){
  Serial.println("\n##Nove##");
  char o[]="IDD";
  for(int i=0; i<3; i++)
    usb.print(o[i],BYTE);
  
  usb.print(13,BYTE);
  debug();
}
// FS checks the freespace on a disk,
// only returns a good value if the 
// amount of freespace is < 4 gigs.
void fs(){
  char o[]="FS";
  for(int i=0; i<2; i++){
    usb.print(o[i],BYTE);
  }
  usb.print(13,BYTE);
  debug();
}
void rd(char fileName[]){
  char o[]="RD ";
   
  for(int i=0; i<3; i++)
    usb.print(o[i], BYTE);
  
  for(int i=0; i<7; i++)
    usb.print(fileName[i]);
   
  usb.print(13,BYTE);
  debug();
}

These are links (posted as they turn up) to other projects using this as a fundamental component of their design.

prensf2010/arduino.txt · Last modified: 2010/07/12 19:05 by nels_oscar