Silicon ChipAn Arduino Data Logger with GPS - August 2017 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Australia’s energy outlook is dogged by political incompetence
  4. Feature: Radio Telescopes and Interferometry by Dr David Maddison
  5. Review: Rohde & Schwarz RTB2004 Mixed Signal Oscilloscope by Nicholas Vinen
  6. Project: An Arduino Data Logger with GPS by Nicholas Vinen
  7. Project: Mains Power Supply for Battery Valve Radio Sets by Ian Robertson
  8. Project: El Cheapo Modules: Li-ion & LiPo Chargers by Jim Rowe
  9. Serviceman's Log: Well-made 1980s amplifiers are worthwhile to repair by Dave Thompson
  10. Project: Deluxe Touchscreen eFuse, Part 2 by Nicholas Vinen
  11. PartShop
  12. Feature: LTspice Part 2: Simulating and Testing Circuits by Nicholas Vinen
  13. Project: Building and calibrating the RapidBrake by John Clarke
  14. Feature: Lithium-ion cells – What You Need to Know! by Jim Rowe
  15. Vintage Radio: STC’s 1946 model 512 5-valve radio by Associate Professor Graham Parslow
  16. Market Centre
  17. Notes & Errata: Arduino-based Digital Inductance/Capacitance Meter
  18. Advertising Index
  19. Outer Back Cover: Hare & Forbes Machineryhouse

This is only a preview of the August 2017 issue of Silicon Chip.

You can view 48 of the 104 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "An Arduino Data Logger with GPS":
  • Arduino Data Logger shield PCB with stackable headers [21107171] (AUD $5.00)
  • Arduino Data Logger shield PCB [21107171] (AUD $2.50)
  • VK2828U7G5LF TTL GPS/GLONASS/GALILEO module with antenna and cable (Component, AUD $25.00)
  • GY-68 Barometric Pressure/Altitude/Temperature I²C Sensor breakout board (Component, AUD $2.50)
  • Elecrow 1A/500mA Li-ion/LiPo charger board with USB power pass-through (Component, AUD $25.00)
  • Elecrow 1A Li-ion/LiPo charger board with USB pass-through (Component, AUD $35.00)
  • DS3231-based Real Time Clock & Calendar module with mounting hardware (Component, AUD $6.00)
  • Firmware (Arduino sketch) file for the Arduino Data Logger (Software, Free)
  • Arduino Data Logger shield PCB pattern (PDF download) [21107171] (Free)
Articles in this series:
  • An Arduino Data Logger with GPS (August 2017)
  • An Arduino Data Logger with GPS (August 2017)
  • Arduino Data Logger Part 2 (September 2017)
  • Arduino Data Logger Part 2 (September 2017)
Items relevant to "Mains Power Supply for Battery Valve Radio Sets":
  • Set of four PCBs for the Battery-operated Valve Radio Mains Power Supply [18108171-4] (AUD $25.00)
  • Battery-operated Valve Radio Mains Power Supply PCB patterns (PDF download) [18108171-4] (Free)
Items relevant to "El Cheapo Modules: Li-ion & LiPo Chargers":
  • Elecrow 1A/500mA Li-ion/LiPo charger board with USB power pass-through (Component, AUD $25.00)
  • Elecrow 1A Li-ion/LiPo charger board with USB pass-through (Component, AUD $35.00)
  • TP4056 1A Li-ion/LiPo charger with mini USB socket (Component, AUD $2.50)
  • TP4056 1A Li-ion/LiPo charger with micro USB socket (Component, AUD $2.50)
Articles in this series:
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • A Gesture Recognition Module (March 2022)
  • A Gesture Recognition Module (March 2022)
  • Air Quality Sensors (May 2022)
  • Air Quality Sensors (May 2022)
  • MOS Air Quality Sensors (June 2022)
  • MOS Air Quality Sensors (June 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Heart Rate Sensor Module (February 2023)
  • Heart Rate Sensor Module (February 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • VL6180X Rangefinding Module (July 2023)
  • VL6180X Rangefinding Module (July 2023)
  • pH Meter Module (September 2023)
  • pH Meter Module (September 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 1-24V USB Power Supply (October 2024)
  • 1-24V USB Power Supply (October 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
Items relevant to "Deluxe Touchscreen eFuse, Part 2":
  • Deluxe Touchscreen eFuse PCB [18106171] (AUD $12.50)
  • PIC32MX170F256B-50I/SP programmed for the Deluxe Touchscreen eFuse [1810617A.HEX] (Programmed Microcontroller, AUD $15.00)
  • 2.8-inch TFT Touchscreen LCD module with SD card socket (Component, AUD $25.00)
  • IPP80P03P4L-07 high-current P-channel Mosfet (Component, AUD $2.50)
  • LT1490ACN8 dual "Over-the-Top" rail-to-rail op amp (Component, AUD $10.00)
  • IPP80N06S4L-07 high-current N-channel Mosfet (TO-220) (Component, AUD $2.00)
  • Matte Black UB1 Lid for the Deluxe Touchscreen eFuse (PCB, AUD $7.50)
  • Software for the Deluxe Touchscreen eFuse (Free)
  • Deluxe Touchscreen eFuse PCB pattern (PDF download) [18106171] (Free)
Articles in this series:
  • Deluxe Touchscreen eFuse, Part 1 (July 2017)
  • Deluxe Touchscreen eFuse, Part 1 (July 2017)
  • Deluxe Touchscreen eFuse, Part 2 (August 2017)
  • Deluxe Touchscreen eFuse, Part 2 (August 2017)
  • Deluxe eFuse, Part 3: using it! (October 2017)
  • Deluxe eFuse, Part 3: using it! (October 2017)
Items relevant to "LTspice Part 2: Simulating and Testing Circuits":
  • Software for the LTspice Tutorial, Part 2 (Free)
Articles in this series:
  • LTspice – simulating and circuit testing, Part 1 (June 2017)
  • LTspice – simulating and circuit testing, Part 1 (June 2017)
  • LTspice Part 2: Simulating and Testing Circuits (August 2017)
  • LTspice Part 2: Simulating and Testing Circuits (August 2017)
  • LTspice Tutorial Part 3: Modelling an NTC Thermistor (September 2017)
  • LTspice Tutorial Part 3: Modelling an NTC Thermistor (September 2017)
  • LTspice Simulation: Analysing/Optimising Audio Circuits (May 2018)
  • LTspice Simulation: Analysing/Optimising Audio Circuits (May 2018)
Items relevant to "Building and calibrating the RapidBrake":
  • RapidBrake PCB [05105171] (AUD $10.00)
  • PIC16F88-I/P programmed for RapidBrake [0510517A.HEX] (Programmed Microcontroller, AUD $15.00)
  • Rapidbrake alignment jig pieces (PCB, AUD $5.00)
  • Firmware (ASM and HEX) files for RapidBrake [0510517A.HEX] (Software, Free)
  • RapidBrake PCB pattern (PDF download) [05105171] (Free)
  • RapidBrake lid panel artwork (PDF download) (Free)
Articles in this series:
  • RapidBrake - giving the guy behind extra stopping time (July 2017)
  • RapidBrake - giving the guy behind extra stopping time (July 2017)
  • Building and calibrating the RapidBrake (August 2017)
  • Building and calibrating the RapidBrake (August 2017)

Purchase a printed copy of this issue for $10.00.

Build An Arduino Data Logger with GPS This cheap and easy-to-build data logger has four analog and four digital logging channels and can log at intervals from one second to one minute. It runs off a lithium rechargeable cell for an operating time of up to one week (depending upon capacity) and this can be recharged by a small solar cell, so maximum logging time is virtually unlimited. It can also log coordinates from a GPS unit and interface with many different types of sensor. by Nicholas Vinen P erhaps its best feature is that it’s based on an Arduino with a few low-cost modules attached, so it’s easily customisable. Out of the box, it provides support for logging voltages, digital logic states, switch or relay states, temperature, latitude/longitude and frequency (eg, for a flow meter). If you want to log humidity, barometric pressure, light levels, RF signal strength or just about anything else, you just need to hook up a suitable sensor to the Arduino board and modify the software to read the data off that sensor. Our software will then 26  Silicon Chip do the background tasks of power management, saving data to the microSD card and so on. If you do build this data logger and expand its capability, we hope that you send us the circuit details and revised software so that we can publish it in the Circuit Notebook section of the magazine. That way, others who want to log similar data can do so easily. Our last data logger project was published in the December 2010, January 2011 & February 2011 issues. That design is now obsolete and we no longer recommend it. Our new design is much easier to set up and we are able to support it with bug fixes, should the need occur. Constructors can easily install updated software using the Arduino IDE and a USB cable. The old design was also notoriously difficult to interface to a PC, especially if you’re using a newer version of Windows than was available at the time (it was designed for Windows 7). The Arduino IDE and drivers are kept up to date for recent operating systems and in fact, since they run on Mac and Linux too, that means this data logger is suitable for a wider audience. siliconchip.com.au Data logger design We could have used an Arduino shield specifically intended for data logging which would include an SD card socket, real-time clock and a prototyping area. Instead, we decided to use separate microSD card and realtime clock modules. We had several reasons for this approach. First, the combination of individual modules costs less, even if you take into account the separate PCB and headers. Second, we are using the DS3231 realtime clock module which is more accurate than the DS1307 often installed on Arduino data logger shields. And we have used a higher capacity backup battery that’s more readily available (CR2032). Third, we may decide to produce a Micromite-based version of this data logger as well, which would be easier to do with individual modules that aren’t specifically tied to the Arduino format. With that in mind, it wouldn’t be hard to modify the software for this project to work with Jaycar's XC4536 data logging shield. For example, should you wish to build it using Jaycar's shield, the pins used by the realtime clock and SD card socket on the Jaycar XC4536 are identical to those we’re using here. So all you’d really have to change would be to swap the DS3231 library for the DS1307; a pretty simple change, but one we’ll leave up to the reader. The DS3231 module we’re using for timekeeping was described in detail in a separate article in the El Cheapo Module series, in the October 2016 issue, starting on page 33. You can view that article at www.siliconchip.com. au/Article/10296 Similarly, the microSD card interface module we’re using was described on pages 74 and 75 of the January 2017 issue and you can view that article at www.siliconchip.com.au/ Article/10510 Having decided to use those two modules, we then decided to use two more modules to round out the design. For the power supply, we’re using the Elecrow Mini Solar LiPo Charger module which is described in detail in a separate article in this issue, starting on page 44. A single-cell Li-ion or LiPo cell is hooked up to this board and provides power to the Arduino via a 5V boost regulator, ensuring it has a steady voltage supply even as the cell discharges. siliconchip.com.au This cell can be charged either from a 5V USB source, such as a computer or mains charger or via a small optional solar panel. That means the data logger can be used in a remote location and left for months at a time; as long as it gets enough sun, it will operate continuously. The other module we’re using is an optional GPS receiver. We’re recommending the VK2828U7G5LF which we’ve used on several occasions previously as it is inexpensive but works well. This is used both to ensure the real-time clock is kept accurate and to log the unit’s position. You could use a different GPS receiver but then you will have to figure out how to modify the connections. Or you can leave it off entirely if you don’t need the features it provides; the real-time clock will typically gain or lose less than one second per month without it. Features and Specifications Power supply: single Li-ion/LiPo cell with solar charging or 4.5-5.5V USB source (eg, computer or mains charger) Supply current: average ~30mA; peak ~100mA (with GPS fitted), ~50mA (without GPS) Battery life: around four days with recommended cell (3Ah); larger capacities can be used Analog inputs: 4 x 0-15V; protected up to ±60V (maximum voltage can be increased up to 60V) Circuit description The full circuit of the data logger is shown in Fig.1. For our prototype, most of the components are mounted on a prototyping shield which simply plugs into the Arduino (MOD1). The four analog inputs are available on CON1, along with a ground pin, and connect to the Arduino’s A0-A3 analog input pins via 100kW/47kW resistive voltage dividers. These allow the Arduino to sense voltages up to 15V and protect it from damage from even higher voltages, up to about 60V or -60V. These set the analog input impedance to around 147kW. The digital inputs are on a similar header, CON2 and again, a ground pin is provided. These feed through to digital input pins D2-D5 via 1kW series resistors. These are to protect the Arduino from voltage spikes, or voltages outside the range of 0-5V (up to approximately ±15V). Each of these inputs has an internal pull-up current so they will be high if unterminated. As a result, the digital inputs can be used to sense the presence of a voltage (as long as it is at least 3V) or the state of a switch or relay contact, by connecting one end to the input and the other end to ground. They can also be used to count pulses, for example, from a flow meter, up to about 10kHz. Digital inputs D0 and D1 of 1 are not used because these are also used as the serial transmit and receive pins for the console. The serial console can Digital inputs: four, compatible with 3.3V/5V logic or contact closure; protected up to ±15V Other inputs: optional GPS lat/lon logging plus 10kHz frequency counter and/or digital temperature sensor. Other sensors (I2C etc) can be used with software changes Accuracy: analog inputs ±1% typical with supply voltage calibration; frequency input ±2% typical Logging interval: defaults to six seconds between entries; 1-60 seconds range is possible Logging medium: CSV (comma separated value) format text files written to microSD card, up to at least 32GB Timekeeping: DS3231 real-time clock with battery backup, giving less than one second drift per month Other features: RAM buffering to reduce power draw; automatic time updates from GPS; logged data can be downloaded via USB serial interface August 2017  27 Fig.1: complete circuit for the Arduino Data Logger, including the optional GPS unit and DS18B20 digital temperature sensor. The rest of the circuit is comprised mainly of modules, such as the Arduino Uno, DS3231 real-time clock module, microSD card interface module and Mini Solar LiPo Charger board. be used to load data from the unit, via the USB port of a PC, avoiding the need to physically remove the microSD card. Digital pin D6 is set as an output and drives blue LED1 via a 47kW current-limiting resistor. This prevents it from drawing very much current (only about 0.1mA) but it’s only lit for a very brief period anyway, so the actual drain on the battery from driving it is almost nothing. GPS receiver interface Digital pins D7 and D8 are used to interface with the optional GPS receiver. We’re recommending the VK2828U7G5LF as it’s a good performer for the price. Keep in mind, that it has an inbuilt ceramic patch antenna so if you are operating indoors, you might get better results using a comparable unit with an external antenna. Having said that, the VK2828 works fine in typical indoor locations. 28  Silicon Chip D7 is used to drive the module’s enable (EN) pin; it’s held actively low to keep the unit in standby most of the time, resulting in a microamp-level current drain on the battery. Periodically, at a programmable interval that defaults to one hour, the Arduino will bring this pin high to switch on the GPS unit until it gets a lock (usually after about 30 seconds) or if there’s insufficient signal, until a timeout occurs (by default, after five minutes). The GPS module draws around 30mA during the time it’s powered up; if we assume the average time will be 45 seconds every hour, that works out to 30mA × 45 ÷ 3600 = 375µA average. That’s just 0.375 × 24 = 9mAh per day. Data from the GPS module appears at its TX pin (pin 3) and this is fed to digital input D8. It needs to go to this pin; we explain why below, when describing the operation of the software. The GPS module’s RX pin is left unterminated (it has an internal pull-up) as there’s no need to send any data to the module. We simply decode its "GPGGA" and "GPRMS" NMEA messages which are sent out by default once per second, at 9600 baud. The micro can detect whether a GPS module is present based on activity on the D8 pin, or lack of it. D8 has an internal pull-up enabled so that if there is no GPS module connected, it will simply sit high and so the unit will not log GPS co-ordinates. If a GPS module is detected and is giving sensible output, the latitude, longitude and number of satellites visible will be logged with each entry, along with the number of seconds since a good lock was achieved. If the GPS module fails to achieve a lock during its power-on period (ie, it times out), the last valid set of readings will continue to be logged and the number of seconds since lock will continue to increase, indicating how “fresh” or “stale” the data is. siliconchip.com.au The VK2828U7G5LF GPS module shown is an optional extra, if you want to log the unit’s location or for greater accuracy in timekeeping, as without it there will be about ±1s of drift in the clock per month. Digital pin D9 is set as an input, again with an internal pull-up, and connected to external switch S1, which is used to enable or disable logging. This is useful if you want to remove the microSD card to off-load some data; you can simply flick S1 to the off position (where it pulls D9 down to 0V) and the unit will flush any data in its RAM buffer to the SD card and then flash LED1. You can then remove the card, offload the data, plug it back in and switch S1 back on to re-enable logging. Or you can simply swap the microSD card for another card to minimise the time without logging. D9 can also be used where you have a situation where you may only want to log data some of the time. You just need to have it to be pulled low when you don’t want to log data, and pulled high or left floating when you do. This can be done with an external relay, switch, microswitch, discrete logic, another microcontroller etc. hardware in master mode so we could have used any pin. But it’s conveniently next to the other three so we connect this to the CS/SS (Chip Select/Slave Select) pin on the microSD card module. The only other two connections on that module are to 5V and ground. It has an onboard 3.3V regulator and level shifting circuitry. The DS3231 real-time clock and calendar module (MOD3) allows the Arduino to keep accurate track of time for time-stamping the log entries, even if power is lost. That module has an onboard battery backup that will last several years and its timekeeping accuracy is very good, at around ±1ppm or about one second per month. This module has 32kHz and square wave (SQW) outputs which we are not using. We’re just connecting the module to a source of 5V power and the Arduino’s I2C serial interface which is hard-coded to analog pins A4 and A5 (unfortunately, limiting us to four analog inputs if we want to use I2C). These two pins are enough to allow us to set and query the time and date from the real-time clock module. That just leaves the battery-backed power supply which is provided by the off-board Elecrow Mini LiPo Charger module. This connects to the Arduino via a standard USB cable, terminated in whatever connector your Arduino module requires; in the case of an Uno, it’s a full-size Type B (square) plug, but some Arduino clones use a mini or micro Type B connector instead. The Charger module can connect to your PC, or a USB charger, via a standard microUSB cable. When connected, it will pass through power to the Arduino but it will also charge the connected Li-ion or LiPo cell from the USB supply. Then, when USB power is removed for whatever reason (whether it’s unplugged, or a blackout etc), it will run the Arduino from that cell. SD card interface Digital pins D10-D13 are wired to the microSD card module and used to read data from and write data to the card. Pins D11, D12 and D13 are hard-wired to the SPI (serial peripheral interface) communication pins MOSI, MISO and SCK on the Arduino respectively. MOSI stands for “Master Out, Slave In”, MISO for “Master In, Slave Out” and SCK for “Serial Clock”. While D10 is designated as SS, the hardware Slave Select pin for the SPI bus, in actual fact it is not used by siliconchip.com.au The charger module that can be used with the Data Logger lets a small 5V solar panel be connected in conjunction with a Li-ion/LiPo cell, powering the module and charging the cell. The charger module will favour power coming from the micro-USB port over a cell, meaning you can also have it hooked up to a computer to act as the primary power source, with the cell being a backup. August 2017  29 Note that a Li-ion/LiPo cell has a voltage usually in the range of 3V (flat) to 4.2V (fully charged), while the Arduino expects a steady 4.5-5.5V input. The Elecrow module has an onboard switch-mode step-up regulator to provide this regulated supply. For more details, see our article on LiPo chargers, including that module, elsewhere in this issue. The Solar Charger naturally also has provision for a solar cell which can run the Arduino and charge the cell in the absence of DC or mains power. We tested our unit with a small 5V, 0.5W solar cell from Oatley Electronics which worked fine. However, we are recommending that you use a 0.8W cell which we can supply (see Parts List) as it costs about the same and will charge the battery faster, which may be important when the weather is poor. Software The software makes use of various Arduino libraries to do all the heavy lifting but even so is quite complex, partly due to the power saving features employed. We won’t fully describe how to utilise and customise the software; but we do detail how to install and run it in the panel “Software Installation”. Instead, next month we will have a detailed description of how the software operates. In the meantime, you can download and examine the source code if you already understand C++ software. Construction As you will notice from the earlier photos, our unit was built on a protoboard shield and you certainly can do the same. If you’re experienced, it will only take you a couple of hours to solder the components onto the shield and complete the point-topoint wiring on the underside to get it all working. However, it’s quite easy to make a mistake when assembling a board this way. So to make it easier and quicker, we’ve designed a double-sided, shield PCB which you can purchase from our online shop. This comes with a set of stacking headers and costs less than many suppliers charge for a protoboard. If you do decide to build the unit on a protoshield, note that it’s easier if you use 0.25W resistors with thinner leads, since then it’s possible to Fig.2: while the Data Logger can be built on a protoshield, it’s much easier to use our customdesigned shield PCB. The two main modules, connectors, LED and resistors are fitted to this shield which then plugs into the Arduino board. Refer to the text for our notes about the importance of good connections for MOD2. When using an Arduino prototyping shield, some of the connections shown in Fig.1 are made by soldering jumper wire between the solder joints on the underside of the shield. 30  Silicon Chip feed two leads into a single hole on the board when wiring up the analog input dividers. Assuming you’re going to take the easier approach and use our custom board, all you really have to do is following the PCB overlay diagram, Fig.2, and the PCB silkscreen to solder each component in place. Start with the resistors, then the rightangle headers, then LED1 (ensuring it’s orientated correctly), CON3 and then the two modules. The DS3231 module normally comes fitted with a right-angle 6-pin header and empty pads at the opposite end. You will therefore need to straighten the right-angle header pins using a pair of pliers and solder a vertical 4-pin header to the other end before soldering the module onto the shield board. This leaves the backup cell on the top, so you can change it easily if necessary. Note that if you’re using the DS3231 with a primary (non-rechargeable) CR2032 cell, you will need to de-solder the small surface mount diode on the board, in a red-tinted glass package. This prevents the module from trying to recharge the non-rechargeable cell. Having said that, the unit that we recommend you purchase from our website comes with a lithium-ion rechargeable cell so this modification is not required. We used a 6-pin female header socket with long pins, bent at right angles, to mount our microSD card module on the board. However, we found that this created intermittent problems due to the high-speed nature of the signals carried through these pins. If using this type of socket, at the very least, you should use some M2 machine screws, nuts and spacers to attach the module rigidly to the shield PCB. However, we feel that a more reliable approach would be to physically mount the module on the shield PCB using either screws and spacers or double-sided tape, then solder rigid wires (eg, from resistor lead off-cuts) between the six pads and the six pins of the module. It won’t be removable but, assuming you’ve made good solder joints, it should operate reliably. Once all the components have been fitted to the board, it’s simply a matter of soldering the four stacking headers in place and then plugging it into the Arduino board. Insert the headers from the top side of the board. siliconchip.com.au Note that soldering these headers is a little tricky since you need to make the solder joint around the long, protruding pins without getting too much solder on those pins, since they need to plug into the sockets on the Arduino board. When you do plug the shield in, be careful that the pins go into the right locations on sockets – check the markings on the board. Some Arduino boards have an extra two pins on the lower-left header which can lead to confusion. If using a GPS receiver, you will need to wire it up to a 5-way polarised header plug to mate with CON3. For the recommended VK2828U7G5LF module, first cut the white (1pps) wire on the supplied cable short, or insulate it (eg, with heatshrink tubing) like we did. You can then crimp and solder the five remaining wires to the polarised header pins. The colour coding for the wires is shown in the labelling for CON3 in Fig.2. If in doubt, refer to the VK2828U7G5LF data sheet. When finished, push each pin into the polarised block in the correct location using a very small jeweller’s screwdriver or similar implement. Troubleshooting The first thing to do if the data logger isn’t working is to plug it into your Parts List 1 Arduino Uno or equivalent, with suitable USB cable (MOD1) (eg, Jaycar XC4410, Altronics Z6240) 1 double-sided shield PCB, 68.5 x 53.5mm, coded 21107171 (supplied with set of four long pin headers) OR 1 Arduino prototyping shield (eg, Jaycar XC4482) 1 DS3231-based real-time clock module with backup battery (MOD3) (eg, Silicon Chip online shop Cat SC3519) 1 microSD card module (MOD2) (eg, Silicon Chip online shop Cat SC4019) 1 Elecrow Mini Solar Lipo Charger module with two 2-wire JST 2.0 leads (MOD4) (Silicon Chip online shop Cat SC4308) 1 Li-ion or LiPo cell with built-in protection, capacity around 3Ah (eg, from an old mobile phone or https://hobbyking.com/en_us/ turnigy-icr-18650-10c-2000mah-3-7.html or similar) 1 microSD card, capacity to suit application 1 5V solar panel of around 0.8W (optional; eg, Silicon Chip online shop Cat SC4339) 1 VK2828U7G5LF GPS module (optional; Silicon Chip online shop Cat SC3362) 1 USB charger with microUSB output (optional, for mains-powered use) 2 5-way right-angle polarised headers (CON1,CON2) 1 6-pin header socket with long pins, 2.54mm pitch (for MOD2) 1 6-pin header, 2.54mm pitch (for MOD3) 1 5-pin polarised header with matching socket (optional; CON3, for GPS module) 1 3mm blue LED 1 SPST or SPDT toggle or slide switch (S1) 1 single male-male jumper lead (for S1) various length of Kynar (wire wrap wire), ribbon cable strands, light-duty hookup wire or resistor lead off-cuts (if using a protoshield) Resistors 4 100kW 5 47kW 4 1kW The finished project with optional GPS module attached. The switch shown at centre allows you to enable/disable data logging, which lets you hot swap the microSD card or off-load data if it runs out of storage. siliconchip.com.au August 2017  31 Software Installation Once you’ve finished assembling the unit, download and install the latest Arduino IDE (if you don’t have it already). Plug the Arduino main board into your PC and launch the IDE. Before you can upload the sketch, you need to select the port on which the main board is connected. Click on the Tools menu, then Ports and select the right port from the list. It’s typically the one at the bottom. If you haven’t already, download the sketch from our website. In the ZIP package, you should find a number of libraries, each of which is also in a ZIP file. Open the Sketch menu in the Arduino IDE, then Include Library and select “Add .ZIP Library”. Navigate to the location where you saved the supplied libraries and select the first one. Repeat this process for all the libraries. You can then open our sketch (using either File→Open or by launching it from your file manager) and select the “Upload” option in the Sketch menu. You should see a progress bar in the lower right corner of the IDE fill from left the right. This will take around 15-30 seconds, depending on the speed of your computer, as it involves compiling the sketch and then uploading it to the Arduino board. If there are any errors, they will appear in the small window at the bottom of the IDE. The sketch as supplied should compile the first time. If it doesn’t, the most likely reason is that you forgot to install one of the libraries, or you already had an incompatible version installed. More likely errors are communications problems, which may suggest that you had wrong port selected. If everything seems OK but it still won’t upload, try unplugging and re-plugging the Arduino board and restarting the IDE. Assuming the upload was successful, you can check the operation of the logger using the Serial Monitor, available under the Tools menu. If you don’t see anything in the Serial Monitor, try pressing the reset button on the Arduino board. You should get an output similar to the following: SILICON CHIP Arduino Datalogger powering up RTC time updated Calibrating counter Counter calibration complete (999.30) Initialising SD card SILICON CHIP Arduino Datalogger ready GPS module might be present, checking... GPS module detected Opening log file ArduinoLog_2017-06-29_112624.csv ArduinoLog_2017-06-29_112624.csv 29/06/2017,11:26:24,0.00,0.00,0.00,0.00,1,1,1,0,20.4,1.004,,,, … Here’s a 3D render of the finished project using the shield PCB that we will supply at a later date. 32  Silicon Chip computer and use the Arduino Serial Monitor to look at the debugging messages that it’s producing. Press reset and you should get messages similar to that shown in the adjacent panel. If you get nothing, check that the port setting is correct and try re-uploading the firmware. Normally, if the firmware gets “stuck”, you can tell where based on the last message displayed on the console. If you find it’s re-starting repeatedly, or randomly rebooting, the most likely problem is in the connections between the Arduino and the microSD card. Note that the unit will refuse to start up at all if there is no microSD card inserted. If LED1 is flashing rapidly, this indicates a problem with the RTC module (2Hz) or the microSD card (4Hz). Note that, because of the buffering, you may not get any logged data output over the serial monitor or written to the microSD card for some time after start-up. If unsure, try changing the state of S1 as this will normally force the unit to flush out any logged data which is buffered. By default, you will need to wait 36 seconds (6 seconds x 6 buffer entries) after the “Datalogger ready” message to see any logged data. What happens if the battery goes flat? If you’re powering the unit from a mains USB charger and using the rechargeable cell as a back-up, you shouldn’t have to worry about this (unless your area is prone to weeklong blackouts!). But if you’re using the solar cell, it is possible that a long period of bad weather could result in the cell going flat. The power supply module does not appear to have a low-battery cut-out feature, which is why we’ve specified a cell with built-in protection. This will normally prevent it from being over-discharged. Eventually, the protection circuitry will simply cut power and the logger will shut down, leaving a slightly truncated log file. When power is restored, the cell should begin to charge and the logger should resume operation, opening a new log file. Fully discharging a lithium-ion/ LiPo cell repeatedly can shorten its life but if this happens occasionally, it should not cause any serious probSC lems. siliconchip.com.au