UPDATE: Here’ the BOM file, I forget upload it: BOM_PIC_DATALOG_V1.0_WEB
UPDATE: Also in Adafruit’s blog. Thanks!
Hi all! I’m continuing here with the last board I design and now I’m continuing testing. It’s a battery-powered small datalogger based on a PIC18F2620 microcontroller. The idea comes a few months ago, talking with a friend. He needs something to monitoring temperature and humidity inside a sea container, for a three weeks travel from Spain to China. Low consumption is important, in order to have maximum autonomy with a small battery. I use a HDC1050 temperature and humidity sensor, and a TEMT6000X01 ambient light sensor. The collected data is stored on a micro SD card. Also the board has a RTC for timestamp, a Li-Ion battery charger, user pushbuttons and leds, and a MCP2221 USB bridge to communicate with the board and configure some parameters through software. Let’s see the board in detail!
First of all, here’s a view of the board with the main components. After I’ll talk about the case 😉
The schematic of the board is available here: EEL_PIC_DATALOG_V1.0. It’s divided in the following parts:
- Main diagram: Includes the mini-B USB connector, TVS diode for protecting the USB line and the rest of the connections.
- Power supply stage: The board can be powered using a 3.7V Li-Ion battery or through USB port. I use a 3.7V/1100mAh battery for this first prototype (LP603450). USB port is also used to charge the battery. I use the MCP73832-2ACI/OT regulator from Microchip with a Rset of 4K7 (not 10K as appear in the schematic). This allows a current charge of around 220mA/h. D4 (red) and D5 (green) leds indicate the status of the charge. Also, D1 (green) lights when USB power is present:
The hot point is the battery manager, when charging the battery. Although is a high temperature, is not critic and with this setup, the battery is fully charged in around 5 hours.
System voltage is 3.0V, so I use a TPS76930DBVR LDO regulator. with a maximum output current of 100mA and a typical dropout voltage of 115mV at 100mA output. Also, there’s another LDO regulator, U10. This one is used to power the USB – serial converter. The input of this regulator comes from the USB port, so when there’s no connection with the USB, the regulator and also the USB converter are not powered, increasing the battery life.
Battery voltage is measured with the RA3 analog input of the microcontroller. I just set a voltage divider to adjust the maximum battery value (4.2V at the end of the charge) to the 3.0V maximum voltage on the PIC pins.
At this time, duration of the battery is around 10 days. With the actual software, there isn’t any low power implemented yet. The consumption is around 5-6 mA, including the DS18B20 sensor that I don’t use. I think that unassembly this sensor and forces SW to low power consumption, the goal of three weeks of autonomy is easy to reach.
- PIC18F2620 microcontroller: The brain of the board!. 64KB Flash, 3968 RAM bytes, 1KB EEPROM, 25I/O, I2C, UART,…all condensed on a 28-pin soic package. Enough for this project! Of course, the board has the ICSP connector and also J4 and J5 connectors with accesible VCC, GND and three not used pins. I also let in the board the footprint for a DS18B20 temperature sensor. Originally, it’s on the board because I’m not sure if I’ll be able to solder the HDC1050 sensor, so if I can’t, at least I can obtain the temperature from this sensor.
- I2C bus: On the 3.0V I2C bus are the HDC1050 temperature and humidity sensor and also the M41T00SM6 RTC. The RTC has a CR1220 battery for backup date and time. Also there’s a connector available with these signals for future uses. The I2C bus is implemented by software, because the I2C lines are shared with the SPI port, and I need it for the micro-SD card.
- Micro-SD Socket: I use this one from Molex because is easy to solder by hand. Not much to say here, just and SD card connected to the SPI port. You can check here the SD card specs.
- User interface: Two pushbuttons (active low) and two led’s (D2 Green / D3 Red) for what user wants!.
- LDR: A TEMT6000X01 ambient light sensor. It reads with the analog RA0 input. Because the internal ADC of the PIC has 10-bit resolution, maximum value will be 1023 that corresponds with maximum level of illumination.
- USB-Serial bridge: Based on the MCP2221 chip that I use before.
I design the board with components only on top layer, it’s easy to assemble. I use the DP5050 sick of beige PCB format from DangerousPrototypes. The gerber files of the board can downloaded here: GBR_PIC_DATALOG_V1.0. And here’re a couple of 3D-previews images from Altium:
I order the boards to DirtyPCB company, and like always, the quality is excelent for the price. The one con I notice this time is that yellow board with white silkscreen is not easy to read, but I never make a yellow board ;-):
For first time, I make a 3D case for the board. To make this job, one of my best friend helps me in this design. He has his own company and has a lot of experience designing cases for electronic equipments. I send him the step model of the board and he designs the case, to fit the board and also the battery. This was the first attemp:
The board fits perfect, but you can show the battery. Also, I need a small space to take out the wires from battery, and also add a method to fix the datalogger. We implement all this changes on the second version:
Yes! I use two Neodymium Magnets to fix the board to any metallic surface. It’s a transparent method of fixing and the final result looks great. Now I can put it in my fridge door:
Now the electronics fits better and you can’t show the battery, so the datalogger seems a bit more professional:
The .stl file of this last case is available here: BOX_DATALOGGER_V02
The software (*) for the datalogger is here: PIC_DATALOG_V00d. I use Mikroc Pro PIC compiler, the libraries of this compiler are great! Especially the FAT32 library, it allows to manage the micro SD card on a very easy way. Current version is 00D, and I’m still working on it. I know there’re many things that I can optimize, process that could be simpler…..but the board is still on debug!
There’re many considerations on this SW, I’ll try to explain some important points, but if you have any doubt with something, please comment it and I’ll try to answer!
- At power-up, system configures and check all the peripherals: configure GPIO’s, UART, I2C, SPI, RTC status and set the time for the files on the SD card. Also reads the device ID, a parameter that identifies the datalogger (value stored in microcontroller EEPROM).
- Files on the SD has the following name format: yyyymmdd.ext . That is, year, month and day. The extension file is initially ‘000’. Every new day, system creates a new file with the same format, so every 24 hours, you’ll have a new file.
- System has defined a time to update all the parameters and store it on the SD. This time is configurable by user, and can go between 1s and 999s. When a update event occurs, the system reads all the sensors and parameters and store data on the SD.
- With the P1 pushbutton, you can put a mark on the file. That means that in this moment, you force a update event, so sensors are read and store on the SD card. With the P2 pushbutton, you can make a new file. Filename will be the same but extension changes to 001, 002….and so on. Every push on P2 makes a new file.
- Data fomat: on the SD card files. you’ll find a new file for every day. This files has plain-text format and separated by ‘;’, for an easy import with excel or similar software:
.Software name and version
.Time (s) when system updated the data and store it
.Event (Power Up, Mark, Update)
.DS18B20 temperature (now it’s fixed because I don’t read it)
.HDC1050 temperature (in ºC)
.HDC1050 humidity (%)
.Rest of bytes are reserved for future uses.
- Every days a new file is created. To merge all the files in only one to easy import into excel and make graphics, you can use the following command:
type *.* >> out_file.txt
- As you can see, I implement a command-line commands to have info or set parameters of the datalogger. To connect with the board, just plug the USB cable and install the virtual COM port driver of the MCP2221. I use Tera term software for this. Baud rate is 9600 bps, 8, N,1. Important! Set ‘Local Echo’ to see the commands you send to the board. The command list I implement on the board is the following one:
– reset -> Perform a software reset of the datalogger
– set time -> Update time of the board (hour and minutes, seconds set to 0).
– set date -> Update date of the board (year, month, day and day of week).
– set update -> Set the time to update the system (from 1s to 999s)
– set id-> Set the datalogger ID (from 000 to 999)
– temp-> Perform a HDC1050 temperature measure
– hr-> Perform a HDC1050 humidity measure
– ldr-> Perform a LDR measure (mean of 10 samples)
– batt-> Perform a battery voltage measure (mean of 10 samples)
– date-> Shows the datalogger date
– time-> Shows the datalogger time
– id-> Shows the datalogger identification
– upd-> Shows the datalogger update time (in s)
(*) THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This post is also available in: Spanish