ParcelSat Breadboard Model Documentation

It's nearly 4 am in the morning, I haven't had much sleep because Arsenal's game is in half an hour, and I have a long long blog to write here. They better not lose.

[Edit: They lost.]

Anyways..a former lab mate of mine, who is now in Switzerland herding cows and milking them to make those delicious milka chocolates, put forth this idea of sending each other parcels (No, we are not gay for each other). Not just any ordinary parcel though; he wanted a parcel that is smart and could basically sense its environment as it went along. An interesting experiment to understand what environment(s) a parcel goes through in order to land on your very front door. 

That decision, however, was made about a month ago. After some serious delays, and more delays, I took time from last week to work on a couple of sensors lying around to build up a arduino powered parcel or ParcelSat, if you would like a more technical-but-not-so-technical name (because you know, we both went through serious hell making satellites that partially work). The idea that I could use the same system to teach CanSat next week was also appealing, so I made it my week's goal to make all the sensors work in unison.

Mission Requirements

Arrive in Switzerland, log sensor data on an SD or flash storage without getting quarantined or one of us getting our ears deaf with the police shouting "THIS IS NOT YOUR COUNTRY!" I dont want to go through that again. Story [HERE].

Also importantly, the system has to survive at least 3 days, given that both cities that we live have international airports. Just to be safe 5 days, in more extreme cases, 10 days (including weekends). That means that the battery that I have, a 2200mAh battery, with a consumption of 100mA can have a run time of 22 hours (which turned out to be a good estimate as the test will show). The rest? well, the power has to be managed by placing the processor in low power/sleep mode, which I will discuss later. 


1) Proto-board (Arduino Uno with Atmega328p)

the 8-bit atmega328p has a 5V logic level
need to be careful when interfacing with 3V3 input sensors
Arduino Uno has revolutionized how we rapidly prototype designs these days. The Arduino IDE is simple, easy and takes about a minute to get a LED blinking. Ask anyone who has had to work with a STM32 and they will most definitely tell you that it took all day. The sensors we are going to use here interface through I2C and SPI and the basic Uno will do a fine job. We want to put the power consumption low and with the nominal clock ticking at 16MHz and with not much of float calculations going on, the processor should be fine. 

One thing we wanted to do with the project was also to put the cost down. This UNO clone cost us $6. And we didn't even order from aliexpress. How good of a deal is that?

2) Real Time Clock (DS3231)

DS3231 breakout board 
Real Time Clock (RTC) helps to keep track of time and place a time stamp on any data. The RTC is usually equipped with its own coin cell meaning that even if the power source is cut off, the clock still keeps ticking. The information from the clock can then be merged with the data from sensors which makes it way easy to analyze data later. 

DS3231 does not have external pull ups for I2C
The DS3231 RTC module also incorporates an AT24C02 EEPROM which can be used as well.  In this project we have decided not to. An important thing to notice though is that the I2C line does not have pull up resistors which means external pullups are necessary. Learn about pull ups [HERE].

To test the module, you can use this library by Adafruit [HERE] which works fine. The full integrated code will be provided at the end of the post.

3) micro-SD Card (1/2 GB)

SD cards are great for time-scale datalogging because the data stored is peanuts to the space available. One downside though, is the consumption and can go all the way up to 100mA while writing. On average, with the whole system in place, I was able to see an average current draw of about 60mA during continuous writes. 

Adafruit's micro-SD card breakout boards are expensive (cost 3x as much as the arduino) but they come with premium parts including an LDO to regulate the 5V to 3.3V and a voltage-level shifter. Usually because of high current draw, it's best practice to connect the 5V source of Arduino because the pin can supply a current of upto 150mA. Furthermore, the cards work at a logic level at 3.3V and Arduino at 5V and having a level shifter pays. Yes, pull up resistors can be used, but this is stable. The module also comes with a green LED to indicate when it's being written or read from. Useful for debugging, quiet useless for actual mission. 

Taken from Adafruit's website; shows connection 
SD cards can use both SDIO for fast access or relatively slower SPI. The SPI library for Arduino is quite stable and there are plenty of examples in the internet for datalogging, so I chose to stick with where the herd of sheeps are and focus in SPI. One thing you do have to make sure is that you have to change the code for which ever CS pin you choose. For instance, in the picture, the CS pin is 10. As an example, in the software, one has to define:

pinMode (Your_CS_Pin (in this case 10), HIGH);

That way, the CS pin gets pulled up and SPI can then become active. 

Other important thing to make sure is that if you supply 5V to 3.3V input, the SD card will most probably fry up. You would think that most electronics these days  are at least 5V input pad tolerant but you will be surprised, if you have a habit of looking at the datasheet (which you should), you will notice the range can be limited to 4V or 4.5V for 3.3V logic devices. Which makes sense but still, even pros are prone to rookie errors. 

4) Temperature and humidity sensor (Si7021) 

Si7021 breakout board from Adfruit
Temperature and humidity sensors allows us to see what temperature/humidity changes a normal parcel undergoes while it's travelling. The Si7021 sensor has an error of 0.4 degrees while the sensor embedded on the RTC has an error of 3 degrees. The precision and accuracy in this case, does help.

Schematics of module
The module schematics shows that use 5V or 3.3V for power can be used. The lack of I2C pull ups are crystal clear and while testing, a 10K pull up was used. I got the chance to test the sensor at my home and reveals some interesting characteristics about how temperature and humidity changes in my room during the night. What's clear though is that I don't need a humidifier. 

The box shows exact moment of the time I opened my bathroom door in the morning (7:44 am KST)
Notice the small spike. Bathrooms are usually colder and have higher humidity
The most interesting aspect of the graph is how the temperature increases and then decreases before increasing some more (see those bumps?). Thermal equilibrium, unfortunately, wasn't reached by the time I collected the data. 

One rookie mistake would be to take sensor values at face value. Normally, the sensors need calibration before they can actually be used. However, in the project's case a few degrees off reading will not cause critical problems to the system (unlike space systems where temperature readings need to be accurate). Just to be sure though, I had my commercial humidity and temperature device right next to the sensor and the values matched when I took the time to check. 

5) Barometer (BMP280)

BMP280 pressure sensor on the right

Barometer aka Pressure sensors can be used in case that you want to calculate the altitude at which the parcel could be flying. Since I expect the parcel to reach there anywhere between 3-10 days, my genius conclusion is that the parcel could only be couriered through flight. Assuming the cabin is depressurized, the height at which the mail will be flying can be ascertained. Very cool.

Schematics for BMP280

The sensor breakout for BMP280 (purple PCB) has connections for both SPI and I2C serial communications. The schematics shows that there are, indeed, 10K pull ups for I2C. The sensor is not tolerant to 5V input. That meant that I had to change all the other sensor volatage input to 3.3V even though the logic level for Arduino 5V and also remove any external pull-ups I had in the beginning. It's working fine, surprise surprise!

The 7bit I2C address changes according to SDO being pulled up or down. The datasheet [HERE] states that SDO HIGH is 1110111 (0x77) and SDO LOW is 1110110 (0x76). Also an important thing to remember is that the library that Arduino uses for I2C requires only the 7bit address. No need to write where it's read more or write mode. In case of STM32's an 8bit address is necessary. 

The library from Adafruit [HERE] that I was using had assumed SDO HIGH when my hardware showed that SDO was LOW. So making a quick change in the library to place the default address 0x76 solved my I2C-is-not-working problem. Just, in case you run into similar problems. 

6) Battery (2200mAh)

2200mAh generic power backups
The power bank we are going to use for the project is the white version of the battery shown above. It packs in a respectable 2200mAh of battery for 5V, 1A supply. A quick over-the-weekend battery testing showed the initial and final logs to be:

Initial: 20.75* C 2016/12/09 20:30:17
Final : 16.25* C 2016/12/10 17:50:39

Subtracting the time provided by our reliable RTC, I can see that the fully charged battery ran about 22hours and the current consumption can be roughly calculated at 100mA. In order to extend the battery life, I have implemented the Arduino Low Power Library [HERE] which has a sleep mode for maximum of 8s because the watchdog timer has a maximum delay of 8 seconds before becoming active. The code, given at the end of the post, shows how I have tried to extend the sleep mode.


Arduino IDE makes life simple for simple hobbyists 

1) Libraries
Libraries are set of common codes specifically designed for a hardware that can be utilized in the main code to call those functions in the library and make that hardware do programmed tasks. The <Wire> library for Arduino, for instance, is the I2C library which deals with registers of I2C only. If you need to learn how to install a library in Arduino [HERE] is the guide. 

External Libraries used: 
1) RTC library [HERE]
2) Si7021 Temperature/Humidity sensor library [HERE]
3) Adafruit's combined sensor library [HERE]
4) BMP280 Barometer sensor libary [HERE]
5) Low power library [HERE]

Each library comes with an example. You can then play around and fit that into your system. Very neat.

2) Code
The way I work with the code is that I build the hardware and circuit for each sensor, test the software individually and then proceed to add one sensor at a time while combining the software similarly. This way, it's easy for debug for any problems that might occur. There will be unforeseen problems, that's quite guaranteed.

Shows how the software logs the data on to the SD card with the source code below
The source code is for debugging and datalogging purpose. That means it will also use the UART to send data to the USB of the computer which can then be observed on the serial monitor. Click the DOWNLOAD RAW button below to get the full screen source code for Arduino based Parcel Sat.

IMPORTANT: The software is programmed to sample 2 data continuously for 2 seconds and then moves on to sleep mode for the rest for every 15 minutes. That's done to save battery. I have left the system for testing for the night and will see how the test goes tomorrow. Might have an update on that.


Popular Posts