Last time the prototype was moved from breadboard to perfboard. The schematic had a couple of components for the rain gauge and one additional ADC to compensate for the fact that the ESP8266 only has one ADC on board. These three components added a reasonable cost to the board and it was hinted that another microcontroller maybe added to the system to replace these components.
Enter the STM8S.
The previous schematic looked as follows:
Three components are being targeted for replacement:
- 74HC4040 – counter
- MCP23017 – I2C output expander
- ADS1115 – 4 channel ADC
These components come to several pounds (dollars) worth of components. It may be possible to replace these with the STM8S and a little software.
ESP8266 Low Power Mode
A long term goal of the project is to reduce the power consumed by the system in order to allow the system to work from a battery / solar energy source. In order to work towards this goal the system should be looking to shut off as much of the system as possible when they are not needed.
Initial thoughts are that the system should collect data every 5 minutes. This means that most of the system is only required for a few seconds (say 10 seconds) every five minutes.
One exception is the rain gauge. This needs to be counting all day, every day as a sample taken at a point in time is not representative of the rain fall for a full day.
Another exception is the Real Time Clock (RTC). This needs to be running all of the time for two reasons, firstly it keeps track of the current date and time. Secondly, the system can generate an interrupt to wake the system on a regular basis.
Adding Another Microcontroller
Regular readers will no doubt be aware that I have been a regular user of the STM8S. This microcontroller is available in packages starting at around £0.72 (about $1). Even the smallest packages have several ADCs and multiple digital input / outputs potentially reducing the system costs.
One other area that a microcontroller can help is with the chosen RTC, the DS3234. This RTC can generate an interrupt when an alarm time is reached. The interrupt generated is a simple high to low transition. The ESP8266 however requires a pulse. The STM8S can help by providing this conversion, detecting the falling edge and generating a pulse for the ESP8266.
Several previous posts have shown that it is possible to perform analog conversions and also capture interrupts. This makes it possible for the STM8S to gather several sensor readings for the Oak and replace some components, namely:
- ADS1115 4 channel ADC – The STM8S has several ADC channels and the system only requires 2 so far
- MCP23017 I2C Port Expander – Several digital channels remain available even after using some pins for the ADC
- 74HC4040 Counter – This functionality can be provided through software and a digital channel
Another attractive feature of this microcontroller is the ability to act as an I2C slave device. This will work well with the other digital sensors as they all use the I2C protocol, one protocol to rule them all.
A few changes to the schematic results in the following:
Focusing in on the STM8S:
The STM8S should be able to take over the reading values from the following sensors:
- Ultraviolet light
- Wind direction
- Wind speed
- Rain Gauge
All that is needed now is some software. Time to break out the compilers.
Adding a new microcontroller adds some complexity to the software development whilst reducing the cost of the final solution.
- Putting the Oak to sleep and using the RTC to determine when to wake the Oak
- Reading the sensors on the STM8S
- Communication between the Oak and the STM8S over I2C