-
Running out of space
01/28/2018 at 19:59 • 0 commentsThis display is so tiny that it takes a lot of work to arrange all the required pieces and still be able to tell what they are meant to represent. I just uploaded a new image with what I think will be the final layout. Most noticeable from the picture are the relay icons, which now show all 16 potential slots. To fit these I had to compress the icons to 6x7 pixels, and I still can't create an image for lights that I like. I have added a boolean array to keep track of the status of the relays, and have the icons blinking when the relay is turned on. Another bit you can't see from the picture is that the bottom row of text now scrolls to the left. I print two overlapping text fields to make the scrolling marquee continuous.
I'm still debating the idea of allowing this unit to try and auto-connect to any open wifi access points. Realistically the device would not move around much (if at all) so it should only connect to a known SSID. I added some code to re-check the connection and reconnect as needed every 30 seconds to make sure we stay online. I could also create a rotating list of SSIDs and passwords here if I wanted to try connecting to several known access points.
There is now a working clock displayed on the bottom status bar. When it sends data to the web server, I reply with a timestamp and time zone, and the ESP32 keeps track of the offset between real time and the internal millis() time. I added a function time() which returns the actual calculated unix timestamp and it seems to stay fairly accurate. I dropped the wifi signal overnight and the displayed time still appeared to be accurate in the morning. The time is updated as the status bar scrolls so you can see it updating each time it passes across the display.
I've been working a bit on how to represent the triggers for each relay. I think I can provide for all the possibilities with a 16-character string, but unfortunately arduino doesn't really handle string arrays. I'll probably have to keep all the triggers in a single string, but if they are always the same character length then it is easy to read one trigger at a time. Besides the current state of each sensor I also want to maintain an average and a trend for each. The averages would be over the past hour and would be more reliable that the current value for some items such as the amount of sunlight. The trends would represent rising, falling, or steady values and again would be calculated over readings from the past hour. I'm also thinking it would be better to average out each reading over a 5-minute period, in between each time the data is sent to the server, to ensure a more accurate reading.
Which brings me to another point... the idea of running this device from solar power. It occurred to me that having a solar-powered device and a device that runs a bank of relays is mutually exclusive -- you can have one or the other, and if you are triggering AC-powered devices then you probably don't care to run the ESP32 from solar power. However I still want the ability to collect data from other locations using solar. So while I am currently focusing on a powered device running continuously and able to control relays, I will also develop a second device that is just the bare ESP32 without a display, which still has the same sensor inputs but uses a low-power mode in between readings and only powers up wifi as needed. This second device then should be able to run from solar power and a battery to meet the originally-stated goals.
-
First pic
01/25/2018 at 16:20 • 0 commentsThe display is nearing its final version, I believe, and I thought it would be a good time to grab a picture of it. At the top-left is the temperature in Fahrenheit (also easily displayed in Celsius). Directly below that is the current humidity. To the right the four bars show the wifi strength, sunlight strength, and two bars for soil moisture inputs. Underneath that are icons for heaters, and a fan, and a water valve (in operation these would blink while each device is turned on). The bottom line is reserved for text showing such things as the current barometric pressure and the device's IP address obtained from the wifi network.
It turns out that creating the bitmap for images which are greater than 8 bits wide is rather a pain in the... The larger icons are actually 12x12, and after some experimenting I figured out that I have to take the last 8 bits first, and then the first four bits after that. So if your bitmap for a line was 000011111111 then the actual line of code to hold it would be: B11111111, B0000. Fun, eh?
So at this point the hardware connections have been mostly worked out, it's just a matter of fine-tuning the divider resistor for the light sensor and possibly the soil moisture sensors. There are enough pins exposed on this board to handle three analog inputs and eight relay outputs, however I would rather add in a TTL latch so I could control more relays and still have I/O pins left over on the ESP32 for more inputs. An example here would be a 74LS259, which only requires a 3-bit input plus an enable line and would also control eight relays. If I can find a similar chip with a 4-bit input then we could control 16 relays with only five I/O lines from the ESP32.
Within the code, the next step is enabling it to try and auto-connect to any available open wifi and if that fails, set itself up as an access point so you could connect to it directly from a phone or tablet and use its web page to set up the proper wifi credentials. As for the web page itself, I've had some ideas there... I would like to be able to associate each relay with a set of conditions. For example, turn on relay one (heater) if the temp drops below 50F. And if soil moisture sensor 1 drops below 20% then turn on the water for 5 minutes, but don't allow it to come back on again for another 55 minutes. Basically use the web page to set up multiple conditions for each relay based on the sensors we have available to try and regulate the greenhouse conditions. The worst problem will be in keeping the web page small enough that it still fits in the ESP32's memory.
-
Analog grumblings
01/24/2018 at 15:57 • 0 commentsI spent most of my evening trying to get an analog input working on the ESP32. The code is quite different from my previous experience with an ESP8266 in that the analogRead() command is no longer present. On the new processor you set up the port bit width and attenuation first, then read the port with adc1_get_raw(pin). Seems simple enough once you figure it out, but I had two things working against. The first was that in searching through Google results, EVERY single page I found where someone was presenting their example of how to use an analog port on the ESP32 (and they all even showed pictures of their ESP32 on a breadboard!) had code that still used the analogRead command. Yeah thanks guys, you obviously didn't actually test what you are presenting! Which brings me to the second problem...
After watching the temperature values yesterday I realized that even pulling data once every 20 seconds was still causing some heating in the BME280. I know, I know, the manufacturer recommends once every 60 seconds, but it's hard to remain patient when you're testing code. However since the temp functions and display are working well, I went ahead and shifted the data read to once every 60 seconds, which brought the measured temps down to almost exactly what my in-house digital thermometer was reading (not that I have much faith in THAT device's accuracy). And then I forgot I had made this change... While playing with the photoresistor I naturally dropped the code for taking measurements into the same function where I was reading the BME280 from, and then wondered why I wasn't getting rapid readings on the display. It finally hit me this morning what the problem was, so I made a quick change in the code, and then was able to swap out resistors until I found something that seems to work well with the photoresistor I have.
Another big difference in the analog ports on the ESP32 is that instead of accepting Vcc as the 100% level, these only require 1.1V to max out. That required quite a shift in the resistor divider, so instead of using the common 10k resistor I ended up with a 220ohm. Sitting here under room lights I am reading about 42%, but if I shine a light on the photoresistor it maxes out at 100%. And I believe it is still sensitive enough to detect bright moonlight.
I also ordered a 4-gang relay board yesterday. They all claim to be 5v devices, however each port couples with an opto-isolator which means it really only requires a digital signal strong enough to trip the isolator (although the board itself still requires a 5V source to latch the relays). I'm betting I will be able to trigger the relays reliably with a 3.3v signal, but if not I can just add some cheap transistors to switch the 5v source.
-
I'm not dead...!
01/22/2018 at 21:49 • 0 commentsIt's been quite awhile, but this project is not dead yet! However I have tossed the original hardware and made some significant upgrades to allow for a much broader range of functions...
I am currently using what is marked as a "Lolin32" board, however this appears to be mislabeled. The board was available on ebay for around $10.50US and contains an ESP32 with a 128x64 OLED display and USB port. The ESP2 offers a fantastic upgrade in I/O pins, most importantly including the ability to use many of these pins as ADC inputs. The impact on power draw appears to be minimal despite the huge increase in computing power, so we'll see what happens when I move the project over to battery and solar power.
The DHT22 has been replaced with a BME280. At about the same cost as the DHT, this chip communicates through a standard I2C bus using two wires, and adds a barometric pressure sensor along with more precise temperature and humidity measurements.
I have also had discussions with others regarding greenhouse operations, and believe there is a need to include a high-amperage relay board. With this a person could control heaters, fans, and water pumps. While 5amp relay boards are easily obtained, even the small heaters I use would require at least 12amp relays to operate. It would be handy for future expansion if I can find a relay board controlled through an I2C bus, but have not run across any yet.
With the expanded I/O of the ESP32 and the addition of a relay board, this opens up a lot of possibilities. For example, each relay could be defined to trip on a specific parameter... Temperature drops below 32F? Turn on the heater via relay 1. Soil moisture sensor reads below 25%? Turn on the water pump via relay 2. And so on... These are things that could easily be defined by a built-in web page on the ESP32 and stored to flash memory. Additionally we could define some built-in rules about certain things. The water pump is a good example in that as soon as the water starts flowing it will show 100% on the sensor. Your ideal setup may call for the water to run for five minutes, and then re-check the sensor again an hour later.
So I have one of these new 'Lolin32' boards plugged into a breadboard with the BME280 and have already run into some issues with heat. The ESP32 puts out a noticeable amount of heat while running, and raised the temperature of the sensor several degrees, so I put the sensor on some 4" leads to move it away from the board. Closer but still not quite right. It turns out the default setting of the sensor is to continually poll for new values, causing it to heat itself! Fortunately updates to the driver library have solved this, so I have new code to test which should only request one data sample and then shut off again. By only requesting data once per minute the sensor will not generate enough heat to affect the results. Having the onboard display is handy for testing, but would not be wanted for the final model as it would use excess power and drain the batteries faster. However there are a number of ePaper displays appearing on the market that would be ideal for a low-power solution. I have not had time to investigate this option though...
My biggest concern lies with data storage. For my own uses, I have several servers up and running that I could easily store data on... but what about the average home user? Adafruit has their own server set up for customers to log data to, perhaps I could also set up something for this particular project. Again, time will tell what happens. For now I just want to get this unit up and running in my greenhouse before I start planting seeds, then I can work on improvements on a live system. And OTA updates -- gotta get that working too!
-
And so it begins
09/15/2016 at 20:12 • 0 commentsGetting the project page set up today and thought I'd share some initial information about my progress. I began with an ESP-12E which I soldered into a socket so I could use it on a breadboard. I am using a 3.3v FTDI USB-to-serial converter for uploading code. All of the components I am using have been ordered from ebay to keep costs low. I have probably spent more on my breadboard and power supply setup than I spent on all the components for this project.
So far this week I have spent a lot of time working with a small OLED display. Although this likely will not be included in the final project, it is helpful in displaying immediate sensor data so I can see if I am reading the components correctly.
The DHT22 and soil sensors have been connected and I am getting solid data from both. However since there is only a single ADC port on the ESP-12E, I need to multiple it in order to add the photoresistor. Some examples I have seen make this an easy prospect, I just need to pick out 'enable' pins and write up the code to read each device individually. Once that is working, I will move on to collecting data on a web page.
Last night I received some new AAA battery holders. These hold three rechargeable cells, providing 3.6V to the circuit. I was rather disappointed to see that, although the wifi radio hasn't been enabled yet, the batteries did not last through the night. I'm not sure if the ESP is drawing that much power, or if the OLED display is doing the damage. The ultimate goal is to use deep-sleep mode, waking up once every 5 minutes to record data, then sleeping again, however I may also need to find a way to power off the DHT22 if I find it is drawing a lot of power. Solar power is the goal, but power consumption has to be low enough to run on batteries for several days without a strong recharge.
Finally, the completed module has to be enclosed in such a way that water from the sprinkler system doesn't get inside, but the case is still open enough to give accurate temperature and humidity readings. For this, I am thinking of creating a stake from PVC pipe with a chamber for the components. Because of the large number of available pipe pieces, I think I can put together something quickly without any machining other than using a drill. I want to keep the components about three feet off the ground so that air humidity isn't effected by ground moisture, and I can read the conditions at the same level as my garden plants.