Serial Port Data Logger Circuit

Some of you might be aware that I’ve created a new energy monitoring breakout board that I call Dr. Wattson (which is based on the #Microchip #, a power monitoring IC) along with an #Arduino library and #Python library (for boards like #RaspberryPi and #BeagleBoneBlack) for easy integration of quality energy data into your next project! If you haven’t heard of it and would like more information, check out for more information. It is also available on.To help me study the energy characteristics of different loads, I went ahead and created an Arduino Energy Monitor and Data Logger, which is the subject of this post!It consists of an Arduino (of course!) talking to the Dr.

Wattson board to get energy data, along with an SD card to write the data to. I’ve also added a button to toggle the data logging, along with an LED indicator to show when data is being logged. The button along with the LED made it really easy to initiate data logging when I had the appropriate load plugged in.To facilitate the logging and subsequent analysis, I also implemented a log rotation scheme, so each run will be logged to a different file. The output is in CSV format, which means it can be easily imported to Excel (or Numbers on Mac or other equivalent), and the data plotted.

I have prepared a User Manual showing how the wiring is to be done, which is now available on.The digital out that is coming from Dr. Wattson is completely isolated from the mains, as the energy measurement is done in an isolated manner using current and voltage transformers, so the digital out is perfectly safe to handle.Once in the enclosure, all you need to do is plug the cable into an existing outlet, and plug any device into the outlet on the enclosure — the PCB is designed for currents up to 12A, so it is quite well built! It is calibrated to measure currents up to 4A (so I could be able measure really small currents for measuring standby power — the MCP39F521 chip on which it is based has a 4000:1 dynamic ratio, meaning it can measure from 4A down to 1mA). CircuitHere is the circuit I used:I used an SD card breakout similar to the Adafruit one (so I used that in Fritzing, as that was the closest part). The connection is pretty standard — CLK (Arduino Uno pin 13), MISO (Arduino Uno pin 12), MOSI (Arduino Uno pin 11) and CS (Chip select). CS is configurable, though it defaults to pin 10 for hardware CS — I just use that.For the button, I use the Button library by Jack Christensen, which provides debouncing and a variety of useful stuff in an easy to use package.

The button is using the Arduino’s internal pullup, so it doesn’t have any external pullups and also uses inverted logic (high is OFF, low is ON) — all of these are configurable as parameters to the Button constructor! I’ve hooked up the button to pin 4, but you can use any available pin you like.I really did not have the time and patience to model Dr.

Wattson as a new part in Fritzing, so I cheated, and used the advice of Z-HUT to easily whip up a custom part without much ado. I highly recommend watching it! — thanks Z-HUT!:-). How to make custom parts in Fritzing the quick and easy wayThe only downside is that I have to be content to use the breadboard image of the “generic IC” part that I modified to represent Dr. C’est la vie!Here is a look at Dr. Wattson’s pins (from left to right):. SCL — for I2C communication, goes to Arduino Uno A5.

SDA — for I2C communication, goes to Arduino Uno A4. ZCD — Zero Cross Detection — we are not using this feature in this example. Event — Event indicator — we are not using this feature in this example.

GND — Connect to Arduino GND. VIN — Connect to Arduino 5V.

Port

3.3v — Connect to Arduino 3.3v. GND — Connect to Arduino GND (you only need to connect one of the GND pins). #define BUTTONPIN 4 //Connect a tactile button switch (or something similar)//from Arduino pin 4 to ground.#define PULLUP true //To keep things simple, we use the Arduino's internal pullup resistor.#define INVERT true //Since the pullup resistor will keep the pin high unless the//switch is closed, this is negative logic, i.e.

A high state//means the button is NOT pressed. (Assuming a normally open switch.)#define DEBOUNCEMS 20 //A debounce time of 20 milliseconds usually works well for tactile button switches.Button myBtn(BUTTONPIN, PULLUP, INVERT, DEBOUNCEMS); //Declare the button.

Data Logger Circuit Diagram

This is a demo of a data logging sketch that is capable of logging serialdata to an SD card at up to 115200 baud.You must install the SdFat library to use the SerialPortLogger. SdFatcan be downloaded from:Normally the maximum rate for a 328 Arduino is 57600 baud.It is possible to log data at 115200 baud with a 328 Arduino if you use a highquality SD card.Lower quality cards can have an occasional write latency of over 100milliseconds. This will cause a receive data overrun at 115200 baud sincethe RX buffer on a 328 Arduino is 1024 bytes. You need to reduce the baudrate to 57600 if your SD card causes receive overruns.Most SD cards will work with a Mega Arduino at 115200 baud since the RXbuffer is set to 4096 bytes.It is possible to use software SPI on a Mega by setting MEGASOFTSPI nonzeroin SdFatConfig.h. This will allow a shield like the Adafruit Data Loggingshield to be used on a Mega without jumper wires.The two programs, SerialPortLogger.ino and SerialDataSource.ino, demonstratehigh speed logging of serial data.To run this demo, you need two Arduino boards and an SD shield or SD module.The board with the SD shield should have an LED and series resistor connectedfrom pin 3 to ground. This LED will blink an error code if an error occurs.Make sure BAUDRATE has the same value in SerialPortLogger.ino andSerialDataSource.ino.Load SerialPortLogger.ino into the board with an SD shield or module andSerialDataSource.ino into the second board.Connect a wire between GND pins on the two boards.Connect a wire between the serial RX pin (Pin 0) on the SD board and theserial TX pin (pin 1) on the data source board.It is best to power the two boards with an external 9V supply.After the boards are powered up, wait until the pin 13 LED on the data sourceboard goes out.

Openlog Serial Data Logger

Serial port data logger

This will take up to 50 seconds.Insert an SD into the logger board. Press reset on the logger board.

Theerror LED connected to pin 3 should not light.Press reset on the data source board. The pin 13 LED on the data sourceboard should light for about 50 seconds at 57600 baud or 25 seconds at115200 baud while 280,000 bytes are transferred.If an error occurs, the error LED on the SD board will flash an error code.See the SerialPortLogger.ino source for definitions of error codes.Remove the SD and check the file SERIAL.BIN. In this case it is a text file.