Irrigation Part 7 – ESP8266 Breakout Board

When I started layouting the PCB for my irrigation sensor I realized the advantages of a breakout board. They are handy for developing, sure. But they also bear the big advantage that you do not have to take care about repetitive tasks (such as pull-up resistors). Additionally they ease up layouting by adding two additional layers to your design. That simplifies the design and it also minimizes the footprint of the final PCB.

When I started layouting the PCB for my irrigation sensor I realized the advantages of a breakout board. They are handy for developing, sure. But they also bear the big advantage that you do not have to take care about repetitive tasks (such as pull-up resistors). Additionally they ease up layouting by adding two additional layers to your design. That simplifies the design and it also minimizes the footprint of the final PCB.

Size was the most important factor for me. It isn’t just a question of space, it is also a question of price (PCB cost ist based on cm²). Beside the pull up resistors for CH_PD, GPIO_0, GPIO_2 and RESET and the buttons to ground RESET and GPIO_0 (PROG) I have also foreseen a pin header for connecting my XCSOURCE FT232RL USB<->TTL. The voltage supply of the USB-TTL converter can be enabled or disabled with a jumper. Additionally I have foreseen solder jumpers CTS->REST and DTR->GPIO_0. I’ve not tried personally but some sources say that this connections make the manual buttons obsolete by handing over this task to the USB-TTL converter. Finally there is also a solder jumper to connect GPIO_16 and RESET (for wake up after deep sleep) and a capacitor as voltage stabilizer. Other boards like the Huzzah Board use a voltage converter for this but I have made good experience with the capacitor.

My followers on twitter know that it took several attempts before I got my final version ready (special thanks here to @ccxx72, @i_grr, @bdcatalin und @tzapulica for their help).  I also faced some troubles with  Fritzing but finally you can download my result at Github: https://github.com/Stromspielplatz/misc/tree/master/ESP8266%20ESP-12%20Breakout

ESP8266-ESP12 Breakout Board Circuit Diagram
ESP8266-ESP12 Breakout Board Circuit Diagram
ESP8266-ESP12 Breakout Board PCB
ESP8266-ESP12 Breakout Board PCB

Tracking Motion Level using Raspberry PI and MATLAB/SIMULINK

Some days ago I have already confessed to be somehow fascinated of the Netflix Socks. Every evening I have to search for the episode (actually I look “The Man in the High Castle” based on the novel from Philip K. Dick) and the time I fell asleep. So something like the Netflix Socks was ideal but I have some major doubts.

First of all I have no problem with cold feet. So I rather take my socks off. Then there is the issue with the battery. I really don’t want wo have another wearable I have to take care about. And last but not least I often watch movies with my wife. And to be honest I’m not even a Netflix customer. For me is Amazon Prime in combination with a Fire TV Stick the better choice but that is another story. So I had the idea to make something video based. I’m not sure if this will work, because if it would be so easy, I’m sure my Samsung TV would have such  function. But I want to give it a try and start with a little feasibility study.

The idea of all the sleep tracking is to measure movements. Wearables to this with acceleration sensors. I want to do this with a Raspberry PI and the Raspberry PI Cam. I will use MATLAB/SIMULINK for programming. MATLAB/SIMULINK is a rather more a platform than a programming language and in my opinion predestined for engineers. They follow a common marketing  approach and sell it cheap for students and make expensive (really expensive) for professionals. Fortunately there is a Home Edition since some years. When I found it I was a bit disappointed because it is still rather expensive for private persons (for the basis and some toolboxes you pay already more than 200$) But I really like the system and as they support Raspberry, Arduino, Lego Mindstorms, and other platforms and therefore it is a nice playground for makers like me.

After following the installation procedure of the development software itself you have to get the Hardware Support Package for Raspberry. A wizard will lead you through the installation process and at the end you will have SD card with Raspbian and the MATLAB software. In my case the network setup afterwards didn’t work so I had to connect a monitor, keyboard and mouse and make the network setting manually. For programming you have to use SIMULINK to run your software permanently on the Raspberry. I will not explain how to use the software. They have tons of tutorials on their website and in the meanwhile you find a lot of resources in the internet. Before you can use the Raspberry PI Cam you have to follow a few steps.

simulink model
SIMULINK model for motion measurement

The SIMULINK model is really easy. I just connect the camera with  “Sum of absolute metrics” directly and through a  delay block. Then make a small type conversion and put it to a UDP socket. Additionally I connect an Image Viewer to align the camera. For testing I use a socket server I’ve downloaded from the internet.

Matlab
Testing the model

For data acquisition I use the server of my irrigation project. I create a table tblmotion to store my measuring values.

Beside the motion measurment value I also store the raw bytes coming from my model because it was late in the evening when I did this and so I was not sure if my type conversion was working. I didn’t want to loose the data from the trial and with raw data I could have corrected the type conversion afterwards if it would have failed.

As socket server I use a PHP script. To run a PHP script in the Raspberry shell you have to install the PHP-CLI.

After having a nap in front of the TV I did the data analysis the next day with MATLAB. I did not invest in the database toolbox so I just query the data, export it to CSV and import it in MATLAB. I’ wearing a Garmin Vivosmart so I knew I felt asleep approx. 01:00. Looking at the data there seems to be a trend in the motion value.

Motion value
Motion value

So I do a bit of data analytics. I build some statistic values (STDDEV, AVG, VARIANCE) over different periods (1min, 5min, 10min, 20min) in SQL and import the data in MATLAB

The result makes me quite confident.

aggregate data

The data show a significant change in the movement value between 00:30 and 01:00. So the challenge will be to put this information in a reliable algorithm. Most properly I will have to get the neuronal network toolbox soon to make some trials.

Stay tuned!

Irrigation – Part 6: Fuzzy Control

The easiest way to control automatic irrigation would be using the soil moisture as threshold value and start a pump with that. But I don’t think that this is a suitable approach to control watering of plants. The measuring value coming from the soil probe is rather more a reference point than a value to be used for a controller. I also want to implement a real controller keeping my soil moisture rather constant because I think that will lead to a better yield. The standard controller everybody knows is the PI-Controller. It is an ideal solution for many situations but in my case the disadvantage is that it can only process one measuring value. For sure there are some ways to deal with additional values such as feedforward or cascading but I won’t do that. I will use a Fuzzy Controller instead.

The Fuzzy Controller is a multi-input-multi-output (MIMO) control algorithm working with indistinct (fuzzy) definitions. That sounds very creative but the history goes back to 1965. In the 1990s there was a real hype about Fuzzy Control but then this concept sank into oblivion. In my opinion this control concept is still quite underestimated and unknown today and that’s very unfortunate because it deals well with the most common problems in controller design: no exact model and inly empirical knowledge about the needed algorithm.

I want to use our existing webserver so I will implement the controller in PHP. I have found a very nice class from Wojtek Jarzecji. The idea is that later on an Arduino will call the PHP script. The script will return a change request for the water setpoint (-10%…+10%). The Arduino will add this to the actual pump setpoint (0….100%) and transfer it to a pwm signal.

For the parameters I do some measurements in wet (~400) and in dry soil (~800). Google tells me that in my hometown average humidity is between 50% and 90% and temperature in summer times is between 8°C and 36°C. I take this values to define my input membership functions as follows:

fuzzyparameter_en

That’s my script:

 

 

Irrigation – Part 5: Software Update

Having my first results in hand I have to modify my software a bit. The DHT11 sometimes give strange measuring values (0°C, 6°C) and I want to change my measuring procedure. I will measure 3 values for temperature and humidity and I will take the middle values. The soil moisture measurement is quite unstable so I will take the average of three measurements.

Additionally I have cleaned up the code structure.

I had troubles with two issues:

  • My measurement values are stored in arrays of struct. I learned that the typedef must be done in a header.
  • The ESP8266 does not support the std library. So I use a macro for the min function

That’s the result: