How to add USB pen data logging
If you want to add USB pen drive data logging to your system the Vinculum VDIP1 USB host controller works really well.
There are a couple of places you can get the board, farnell stock them for £13.94.
There are already some good guides on using the board with an Arduino. I found these two most useful. I recommend reading these to start with to get a good idea of how it all works. I've added a couple of things to increase the functionality and get rid of write errors which are documented below.
Guide 1 - Writing data to Usb Memory Stick – by Nick on the Arduino playground.
Guide 2 – Usb Storage and Arduino – by Sven Steinbauer
Additions
Wait for 'ok' response
The Vinculum board is controlled using DOS commands and so every time you send a command if the command is executed successfully the board sends a “D:\> ” response that indicates its ready for the next command. If you try and send commands faster than the Vinculum board takes to execute them and don't wait until after the Vinculum board has sent the “D:\> ” ready for new command response, I found I would get errors in the data stored and it would sometimes crash.
To solve this the arduino sketch code listens for a response from the Vinculum board after it sends each command, if it receives “D:\> ” which I've called the ok response then it can go on to send the next command. If it receives “No disk” it stops trying to write to a non existent disk and waits until a disk is inserted and the start write button is pressed.
Start/stop write button and led indicator
Just a simple start/stop write button. To start writing you hold the button down for 2s and the led comes on to indicate writing. To stop writing you hold it down again for 2s and the led turns off. If the arduino wait for 'ok' response code receives a 'no disk' response. The led is automatically turned off.
Hardware
Vinculum VDIP1 wiring diagram:

Start/stop push button + led indicator circuit diagram:

Layout suggestions
A piece of stripboard to mount the Vinculum VDIP1.
Start/stop push button + led indicator
Installation example in the home energy monitor main unit
Arduino software:
The arduino sketch here works with the board independently of any of the other energy monitor hardware and code. It will just write the values set in the variable declaration to the board as an example.
- Download the Data logger Arduino sketch
- Compile and upload the Arduino sketch to the Arduino. For a guide on compiling and uploading the sketch to the Arduino have a look here.
- Check your Arduino serial monitor for write status. Once you have pressed the button you should see the following output if its all working correctly:
Started
O D:\>
W D:\>
C D:\>
O D:\>
W D:\>
C D:\>
...
If your getting the above, press the button again to stop writing (you should see "stopped" come up)and check the usb pen to make sure the data is there.
| Attachment | Size |
|---|---|
| SAusbmemory.tar.gz | 3.42 KB |
SAusbmemory with Calculations.
Just changed the amount of spaces from 7 to 4 in Datalogger before program could work correctly.
speed
could you estimate wrining data transfer speed?
so if i can understand
so if i can understand correctly, than you should use the same arduino used in the measurement board with the same supply. however the two codes have to be programmed to work together.
THanks a lot
re measurement board
are you refering to joining the code of mains ac v3 with usb datalogging? if so and I have understood your question then yes
hello, how fast are you able
hello,
how fast are you able to write to the usb? I want to use it in another project with quite big data transfer.
have you experienced the problem with the buffer loosing data cause of the bridge hack in cts and rts lines to control flow ??
do you know how big this buffer is?
thanks a lot !!
Re: usb datalogger
Im not sure, it was a while back when I did this. It wasnt super fast if I remember. Roughly about 1-10 times a second rather than hundreds of times. The code I wrote checks for an ready reply from the VDIP to make sure data is not lost and this does take more time, Although stability is very much affected without it. It would be good to do a proper analysis of performance wouldnt it!
USB & Home Energy Monitor 3.0
Trystan,
I am a little confused on how to wire the Vinculum VDIP1 to the Ardruino and energy monitor. Isn't the energy monitor already using the 5v in the Ardruino? Are you using two Arduinos?
Thanks,
Paul.
Re: USB & Home Energy Monitor 3.0
Hello Paul, I just broke out the 5V wire into two ends one for the VDIP and the other for the energy monitor, using just the one arduino.
hello, thanks a lot for this
hello, thanks a lot for this information!!
I have build your power monitor 3.0, would it be possible for you to upload the sketch of power monitoring with USB storage all the code working together?
I have my arduino connected with the ethernet shield to internet to upload values to mysql database each 10 seconds, but sometimes it crashes and it goes offline, i loose all the data for that time. I would like to save that data to the usb so that later i can update the mysql database with the missing data.
thanks a lot !!!
Re: USB logging + Mains AC 3
Hey, Can I challenge you to have a go at bringing both pieces of code together? They should fit together without too much trouble. If you have a go and it doesnt work, send me your code and I will have a look.
Thanks alot for this post!
Thanks alot for this post! This is by far the best logging code I've seen for the VDIP! (Well that I can understand:D)
Good work!
Glad I could help, thanks!
Glad I could help, thanks!
I am trying to log this
I am trying to log this sketch onto a usb pen drive:
/* Arduino sketch for Inspeed Vortex windspeed instrument
The anemometer.
=========================================================
ANEMOMETER
=========================================================
This is connected to Arduino ground on one side, and pin 2 (for the
attachInterrupt(0, ...) on the other.
Pin 2 is pulled up, and the reed switch on the anemometer will send
that to ground once per revolution, which will trigger the interrupt.
We count the number of revolutions in 5 seconds, and divide by 5.
One Hz (rev/sec) = 2.5 mph.
*********************************************************************/
#define uint unsigned int
#define ulong unsigned long
#define PIN_ANEMOMETER 2 // Digital 2
// How often we want to calculate wind speed
#define MSECS_CALC_WIND_SPEED 5000
volatile int numRevsAnemometer = 0; // Incremented in the interrupt
ulong nextCalcSpeed; // When we next calc the wind speed
ulong time; // Millis() at each start of loop().
//=======================================================
// Initialize
//=======================================================
void setup() {
Serial.begin(9600);
pinMode(PIN_ANEMOMETER, INPUT);
digitalWrite(PIN_ANEMOMETER, HIGH);
attachInterrupt(0, countAnemometer, FALLING);
nextCalcSpeed = millis() + MSECS_CALC_WIND_SPEED;
}
//=======================================================
// Main loop.
//=======================================================
void loop() {
time = millis();
if (time >= nextCalcSpeed) {
calcWindSpeed();
nextCalcSpeed = time + MSECS_CALC_WIND_SPEED;
}
}
//=======================================================
// Interrupt handler for anemometer. Called each time the reed
// switch triggers (one revolution).
//=======================================================
void countAnemometer() {
numRevsAnemometer++;
}
//=======================================================
// Calculate the wind speed, and send to serial port.
// 1 rev/sec = 2.5 mph
//=======================================================
void calcWindSpeed() {
int x, iSpeed;
// This will produce mph * 10
// (didn't calc right when done as one statement)
long speed = 25000;//2.5 mph * 1000
speed *= numRevsAnemometer;
speed /= MSECS_CALC_WIND_SPEED;
iSpeed = speed; // Need this for formatting below
Serial.print("Wind speed: ");
x = iSpeed / 10;
Serial.print(x);
Serial.print('.');
x = iSpeed % 10;
Serial.print(x);
Serial.print(" mph");
numRevsAnemometer = 0; // Reset counter
}
But I cannot get it working, do you have any advice ?
I thought I would give your
I thought I would give your code a spin and hope that if it didn't work I could help you figure it out as well as being able to use the working code myself. However, your code works perfectly for me. I copy / pasted, so I know I didn't change anything. Thank you for your hard work on this. Consider approaching as I did with a blank sketch and copy paste it yourself, there maybe something like a space character present where it shouldn't be on your original sketch. Consider the version of the Arduino you are using too, mine is the ATMEGA 328. Again, thanks for sharing your hard work.
Hey, seems to compile ok for
Hey, seems to compile ok for me and I cant see anything obviously wrong, try renaming the variable speed as it seems to be syntax formatted.. could cause a problem. What do you receive at your serial monitor terminal? sorry that that's not particularly helpful.