Close

​Electronics

A project log for Reagent Tracker

Track reagent usage and get timely notifications to re-order.

stephen-harrisonStephen Harrison 06/08/2017 at 03:080 Comments

The electronics side of the scales is made up of the following modules:

Also covered are:

Schematic:

Micro-Controller:

A Photon from Particle.io is used in this project for the micro-controller and internet access. I've used Photons in numerous other projects and they work really well and are very easy to work with.

The core features of the Photon for this project are:

The Photon can be put into deep sleep which stops all functionality but allows it to be woken by a RTC timer (x seconds after sleeping) or a rising edge on the WKP pin. (Special care needs to be taken when using the WKP pin as the RTC also uses this, if the pin is prevented from going high it will block the RTC wake as well).

The Photon has various digital GPIO's, 7 Analog (also digital) GPIO's, two serial pins (Tx/Rx) as well as the serial port exposed over USB, possible battery back-up of SRAM variables via a dedicated VBAT input and 2k onboard "EEPROM" flash memory.

As the Photon is designed to be always powered by the VIN pin from battery or external power we don't need to supply anything to VBAT and any retained variables stored in SRAM will be kept as long as we have power. Long term variables such as load cell calibration values can be stored in the EEPROM to survive power loss.

Like most micro-controllers, when the Photon is in deep sleep mode we lose control of the GPIO and cannot guarantee the state of the pin so special attention needs to be paid to GPIO pins

The Photon is intended to be in deep sleep most of the time with only occasional waking when a reagent bottle is to be measured. It may be desirable to have the RTC wake the unit to send a signal to indicate that the unit is still functional and monitor battery charge but this will need to be balanced with battery usage as WiFi connectivity draws a lot of power.

For the first version of the PCB I used the "header" through hole version of the Photon but switched to the headerless SMD version for V1.1 as this reduced vertical height and saves trimming the legs of the Photon (they are long and protrude a long way though the PCB where space is at a premium).

RFID Reader

As mentioned in the 3D case design the RFID reader was one of the more troublesome selections and I finally settled on the PN532 small red board version available through eBay. This supports NTAG2 tags (these appear to be the only format ones I can get that are stick-on type suitable for the bottom of the bottle).

The PN532 supports I2C, Serial and SPI modes. We're going to use I2C as it simplifies the design needing only 2 wires for the bus and is used for other components. This means that the DIP switch seen upper left in the picture needs to be set to I2C mode (the switch on the right needs to be set towards us). However during final build this will be encapsulated in epoxy so it's going to be better to remove that switch and hard solder the connection to prevent possible vibrations changing the switch which we then can't change, or epoxy getting in and forming an insulation barrier between the switch contacts - it will also reduced the height of the unit by 1.6mm.

In addition to the I2C and power connections (top centre in the picture) we also need IRQ and RST. These are available bottom right (although this is RSTO and not RSTPDN so further investigation is needed to check which RST the driver actually needs as it is unclear).

The PN532 has RSTPDN pin which is broken out on the bottom left in this picture of the PCB which when pulled to shuts down the PN532 and RF circuits. This gives a much lower current consumption than the software shutdown option so we want to use this to save power, when the micro-controller is in shutdown we have no control of the GPIO pins and these may not be in the desired state so an external resistor (R19) is used to ensure the PN532 defaults to this state.

Unfortunately the NFC PCB has a 10k pull-up resistor on the RSTPDN line (understandable as it wouldn't work out of the box otherwise), but this means we need a smaller resistor to ensure the line is pulled low, with this resistor fitted I'm using a 2k2 resistor to pull the line low, this means we have 410uA (I = V/R -> 5v/12.2k -> 0.000409A) current consumption just from those resistors which is undesirable. Hence for final assembly R19 should be replaced with a higher value (10k+) and the NFC RSTPDN pull-up resistor removed as shown in the above picture.

According to the datasheet the PN532 will run at 2uA in a hard power down and 10uA in soft power down. However for soft power down the PCB has the LED lit which increases the power consumption, but the hard power down significantly reduces the power consumption.

I elected to have the NFC PCB component side up on the case, this allows a good fit with the print underneath to (hopefully) stop epoxy running through before curing, it also means that the LED on the PCB is visible and as this is controlled by the RSTPDN option it results in a nice feature of being able to tell if the system is powered and functioning.

When running with RF enabled the NFC PCB can consume bout 100-200mA so minimizing this time through software is obviously going to help improve battery life.

Load cell and amplifier

Their are a few options for load cells, the type typically used in bathroom scales are different from the one used in this project, they use 4 sensors to spread the load, this then requires additional wiring to get them connected. The type used in the Reagent Tracker is fairly common for kitchen scales as it has a small design and good weight range and sensitivity. Whilst the load cell should be capable of sub-gram measurements this project needs only 1-2g (and maybe less) accuracy as we are looking for a large range of difference (e.g. a full bottle may be 1kg compared to 100g for an empty bottle with and a re-order trigger at 250g, hence a few grams error isn't really going to make a difference).

A quick look at the SparkFun Force sensors category shows the various options. The load cell selected was based on lower cost, easier to connect up and mount as well as sensing range and sensitivity. A lot of force sensors merely indicate a force is applied and are unable to give any kind of accurate measurement.

The load cell and amplifier were sourced (like a lot on this project) from random sellers in China from eBay. Each load cell will have it's own characteristics as they are essentially individually drilled blocks of Aluminum with hand placed strain gauges, hence loads will place different strains on the strain gauges. I would expect the load cell used in this project to be very similar (if not identical) to the load cell available through SparkFun and they have a good guide to hooking up load cells which is well worth a read (https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide).

It is possible to buy 1Kg as well as the 5Kg range load cells, however the 1Kg cell would not be enough for a full 1L bottle of resin so the 5Kg version is used which means we have a very slightly reduced sensitivity but not enough for concern for this project. If you are building your own and are interested only in light bottles you may wish to swap to a 1kG load cell.

The load cell amplifier was a little problematic to source, again a few versions exist, I tried the blue PCB versions available on eBay but didn't have much luck and eventually settled on the red PCB version. This looks to be identical to this Spark Fun version, however I've not tried this. It appears all the commonly available amplifiers are based on the HX711 IC, this proved difficult to source alone so I opted to piggy back the red load cell amplifier onto the main PCB rather than try to source the amplifier, let alone develop the correct PCB layout for such a sensitive ADC.

The amplifier is used in its default state (10 samples per second), again special care has been taken for power down. The HX711 will sleep when the CLK pin is pulled high, so R18 pulls this pin high by default to allow the amplifier to sleep when the Photon is in deep sleep.

Normal operation of the HX711 uses about 1.5mA and sleep is down to 1uA so again ideally we will keep the amplifier in its sleep state.

One initial intended use of the Reagent Tracker was that it would also be where the reagent was stored, e.g. with 5 Form1 resin bottles, 5 Reagent Trackers would be used to store the bottles in a nice shelf configuration, this would mean that tracking reagent usage was automatic once the bottle was returned to it's location. However initial tests showed that the load cell drifts (without load and with small temperature changes I observed about +/-10g drift) and this can be more with load applied to the strain gauge. Whilst this mode of operation is still possible by continuous measurement and checking for the bottle removal so a tare and loaded weight are measured at a similar time it does make operation more error prone).

Load Cell Drift:

Accelerometer

The use of an accelerometer wasn't part of the original (V1.0) design and was introduced when realizing that a better mode of operation was to have a single Reagent Tracker that bottles were placed on as and when used.

With typical kitchen and laboratory scales, after switching them on you tare the scales, then place the item to be weight onto them and observe the weight. However Reagent Tracker is designed to have as little user interaction as possible, we don't want to ask the user to switch on the scales and tare them, and certainly not write down the bottle weight!

This is where the accelerometer comes into it's own. A MMA8452Q is used, this has 2 programmable interrupt sources and can generate an interrupt when tapped. This is ideal for our use as putting a bottle onto the unit will generate the equivalent of a tap, this then creates a rising edge interrupt to the WKP pin of the Photon which will bring the Photon out of deep sleep.

Once the Photon is awake we can check that we have a bottle though the NFC sensor (the accelerometer is sensitive and will also be triggered from other "taps" that occur when things are put onto the bench next to it - i.e. my mug of tea!).

Using this tap to wake scheme allows us to put all the other components into a deep sleep mode and just run the accelerometer, current consumption is in the 6uA to 165uA range for the accelerometer which will help improve battery life. (With just the accelerometer running at about 100uA a 3000mAh battery would last > 3 years, however we have lots of other things going on!).

Again the accelerometer is sourced from a random seller on eBay (the blue version of the PCBs gives the correct pinout as used on the PCB). SparkFun also sell breakout boards however the pinout is not the same as the blue ones on eBay and for myself these can be difficult and expensive to try and source in the UK (for example, CoolComponents.co.uk have none in stock at present), hence the purchase from eBay rather than a SparkFun unit (Sorry SparkFun!).

Environmental sensors

As a basic start a 1-Wire DS18B20 TO-92 device is used to sense temperature. This may or may not be useful in the long run, but as the load cell drifts with temperature it was added to the design to try and keep an eye on this. The sensor was introduced for V1.1 of the PCB so it doesn't feature on the original version, it is placed next to the fixed end of the load cell, hopefully this will allow it to be in contact with the cell by careful (wonky) insertion into the PCB.

Additionally a 6 pin socket is provided for (again eBay sourced) BME280 breakout PCB. The BME280 will measure temperature, humidity and relative pressure. This part is totally optional but may allow for compensation due to environmental issues, or where reagent storage has critical environmental requirements this could be used to track storage conditions.

User interaction

User interaction with the Reagent Tracker is designed to be as minimal as possible, as described in the accelerometer section ideally the user will just drop the bottle onto the system and remove when the bottle has been identified, weighted and data successful send to the cloud.

To notify the user that the bottle can be removed a buzzer and LED combination are used. A short double beep is emitted to indicate that the bottle can be removed and a longer single beep that the tare (empty) weight has been measured and the bottle weight has been published. Problems connecting to the internet result in a series of error beeps.

No other user interaction is intended. It may be that in a Goods In style use case where the new bottle of reagent is received some other hardware may be used to print a more human readable label to stick to the bottle to indicate date of receipt, perhaps the RFID serial number and possibly even photograph the bottle (and automated identification of the reagent) as well as get information about the bottle. However for this simple version no other interaction is intended.

The buzzer is a piezo buzzer and is driven from a PWM pin on the Photon, as we are driving it at 3v3 only this will mean it's not very loud (esp. when inside the printed case), this is somewhat out of our control so a LED is also used. As the Piezo is PWM'd it allows us to change the frequency of the PWM and hence the note that the piezo will play should we wish to have a little fun with this!

The LED is a reverse mounted PCB LED and aligns with the hole through the top half of the case at the front of the unit. This hole goes both vertical and out the front at a slight angle. When covering the unit with Epoxy it will be desirably to block the hole from underneath and the front allowing the epoxy to form a light pipe (and not run into the inside!). The hole is 3.2mm allowing a standard 3mm LED to be pushed in snugly, or some kind of tape can be used.

If the case is printed larger than the default 100mm size, this hole can be moved forward and a normal 3MM LED fitted and wired back onto the PCB.

The buzzer and LED will only be used when in full operational mode so should not cause any drain on the battery in standby.

Power

This part of the system is still being worked on. It is intended that the battery would be a 3000mAh Lithium Ion battery similar to this one from SparkFun. Being flat gives it a good fit within the case and it's just about the right size to fit beside the load cell.

It is intended that this will be charged by something like the AdaFruit PowerBoost, however the boosting of the battery to power the circuit isn't needed as the Photon will happily work from the raw battery and everything else uses the 3v3 from the Photon.

It should be possible to use a wireless QI charger to power this, hence removing the need for an external connector however this isn't suitable for day to day operation due to the magnetic field and sensitive metal rod of the load cell not being a good combination). More investigation is needed for this.

The main PCB features placement for a MAX17043 (U2), however this is going to be difficult to solder so probably wont be fitted, likewise there was little room for the breakout board version of this, however it has been left on the PCB for possible future use and experimentation.

Resistors R2 and R5 form a potential divider across the battery input to the main PCB which will allow battery voltage sensing, however this comes at the cost of current consumption (60k across a 4V-ish input => 67uA), which when we are trying to run on battery for as long as possible is not ideal so these may be omitted (however the current used just for these will take about 5 years to flatten the battery so it's a small price to pay for being able to actually monitor the battery voltage).

NeoPixels

The PCB also includes a P-Channel FET to control the power to a possible NeoPixel ring and a level shifting buffer to bring the 3v3 signal from the Photon to the required level of the NeoPixels. Given the high current consumption and obscured view of these they are unlikely to be used but V1.1 of the PCB has the option for these anyway.

PCB and System Design

When I designed the second version of the PCB I initially went with putting the MMA8452 and BME280 onto the PCB to reduce space required inside the system as vertical height is at somewhat of a premium to allow for battery space, however to simplify PCB population I've gone with the breakout PCBs and pins to connect these to the main PCB to make assembly easier (at-least for this version). As the Photon and load cell PCB will be sitting on top of the PCB hopefully this compromise will have little effect on the internal height restrictions and a smaller battery may prove a good substitute for easier assembly.

I also elected to have a thinner than normal PCB (0.8mm cf. 1.6mm), this buys us an extra 0.8mm internally. Whilst it doesn't sound much reducing the size of each of the parts like this can add-up to a real saving in the end.

The PCB is designed in Eagle, it fits in a 10x10cm square but is a round design with a centre cutout for the load cell (Note that the load cell is slightly off centre to allow for the mounting screws to be away from the vertical RFID magnetic field). Eagle files are in the GitHub repository and on this project.

When mounted onto a PCB the headerless photon USB connector can be difficult (impossible) to connect to, the Photon exposes two pads on the underside that are brought out to test point pads on the PCB should these be needed. Likewise the Photon Setup pad is also exposed as a test point, these obviously can't be hand soldered so will require some solder paste and a trip to the reflow oven if they are required.

Pin A2 of the Photon is also connected to a test point, this is used as a "Keep Awake" indicator and when tied high (3v3) the firmware will not go into deep sleep mode, allowing for easier firmware updates or continuous operation mode and debugging.

The TX and Rx pins of the photon are broken out to JP1 (3 pin 0.1" pitch) for future expansion should so this can be connected to a 3v3 serial connector or serial display or something else.

Power is delivered to the main PCB via a 2 pin JST connector (JP2), this the same type used for the Lithium batteries so a battery can be directly connected if desired, however care needs to be taken to ensure the cable does not pull on the PCB as this will cause noisy readings and also make battery charging difficult.

The Battery and charger are expected to be fitted into the lower half of the case.

V1.1 PCB:

Prototyping

In addition to the PCB developed for the Reagent Tracker I also assembled a Prototype PCB to sit on the desk with components easily accessible by probes and a few extra LEDs to help view the state of the system. Whilst this makes it difficult to weight bottles, it is incredibly useful for debugging.

The blank prototype PCB will be available through my ThingySticks Tindie Store soon.

The 3D printed foot for this which holds the PCB, battery and the load cell is available in the files section or from the GitHub repository.

It's also possible to hack the V1.0 PCB and bodge on the appropriate sensors but it gets messy:

The electronics and PCB design are release under Creative Commons Share-Alike 4.0 License, many of Eagle parts and footprints and information on breakout board usage are from SparkFun used under the CC-SA-4.0 license. Thank you SparkFun!

Discussions