Logging to Serial

One of the special features of the Log4.USB device is its ability to send and receive Serial information from an external device, for example an Arduino. This example will explore how to use the Log4.USB in conjunction with an Arduino to view the measurement readings on the Arduino Serial monitor. The measurement readings can then be used to perform protection related tasks. For example, sending commands back to Log4 to turn off power.

Tutorial Objective:

Send information from Log4 to Arduino via serial pins, then view the measurements on Arduino Serial Monitor.

Log4.USB Serial monitor output of Arduino and the system setup

Fig. 41 Serial monitor output of Arduino and the system setup

Before setting the system up, please note the Log4 serial pin configurations (Fig. 42).

Warning

DO NOT reverse bias the VCC and Ground pins.

Log4.USB Serial monitor output of Arduino and the system setup

Fig. 42 Log4.USB serial pin configuration

Fig. 43 shows an overview of the overall system set up.

  • Connect Arduino to the PC via a USB cable.

  • Set up the USB device to be measured by connecting it to the Log 4 USB OUT port.

  • Connect Log4 USB IN to Power supply (In this case, we just used the laptop’s USB port as Power Supply).

  • Connect Arduino 5V pin or 3.3V pin (depending on logic level of Arduino) to the Log4 VCC pin.

  • Connect Arduino GND pin to the Log4 GND pin.

  • Connect Arduino Tx pin to Log4 Rx pin.

  • Connect Arduino Rx pin to Log4 Tx pin.

Log4.USB Serial monitor output of Arduino and the system setup

Fig. 43 Log4.USB serial pin configuration

  • The Log4.USB device sends out measurement readings through the Tx pin. The measurements are sent out in packets (25 bytes per measurement).

Here is the Packet Structure

Byte 0

Start byte ‘:’

Byte 1

Address (1 byte) (currently unused, set to 0x01)

Byte 2

Command (0x0B for slave data)

Byte 3

Data byte count

Byte 4-11

Uint64_t Timestamp in milliseconds since epoch (midnight 01/01/1970)

Byte 12-15

Int32_t Current in micro amps

Byte 16-19

Int32_t Bus Voltage in millivolts

Byte 20-23

Int32_t Power in microwatts

For more information regarding command protocols, please refer to the Serial Protocol Documentation.

To view the measurement readings on the Arduino Serial port, please upload the code, provided in the Appendix, onto the Arduino.