{"id":13624,"date":"2021-08-30T13:52:18","date_gmt":"2021-08-30T06:52:18","guid":{"rendered":"https:\/\/www.makeriot2020.com\/?p=13624"},"modified":"2021-08-30T15:49:39","modified_gmt":"2021-08-30T08:49:39","slug":"design-and-build-an-esp8266-iot-controller-part-3","status":"publish","type":"post","link":"https:\/\/www.makeriot2020.com\/index.php\/2021\/08\/30\/design-and-build-an-esp8266-iot-controller-part-3\/","title":{"rendered":"Design and build an ESP8266 IoT Controller, Part 3"},"content":{"rendered":"\n<p>Welcome to Part 3 of this build. If you are new to this series, <a rel=\"noreferrer noopener\" href=\"http:\/\/144.126.248.244\/index.php\/2021\/08\/16\/design-and-build-an-esp8266-based-iot-controller-part-1\/\" target=\"_blank\">Part1<\/a> and <a rel=\"noreferrer noopener\" href=\"http:\/\/144.126.248.244\/index.php\/2021\/08\/21\/design-and-build-an-esp8266-iot-controller-part-2\/\" target=\"_blank\">Part2<\/a> can be found by clicking on the respective links. Today, we will look at the completed PCB for our IoT Controller. Full disclosure, There are some issues, ranging from components that have still (15 days after being ordered, not been delivered), as well as 3 minor errors on the PCB ( That is entirely my fault ). We will look at how I have overcome the problems to still end up with a functionals PCB. <strong>Please note that the errors in the PCB Artwork have BEEN CORRECTED and that the version for public download does not contain any errors. You can thus order it with confidence.<\/strong><\/p>\n\n\n\n<p>Let us get started<\/p>\n\n\n\n<p><a href=\"#error-on-pcb\">Errors on the PCB<\/a><br><a href=\"#powering-the-pcb\">Powering on the PCB<\/a><br><a rel=\"noreferrer noopener\" href=\"#testing-with -home-assistant\" target=\"_blank\">Integrating and Testing with Home Assistant<\/a><br><a href=\"#tasmota\">Tasmota<\/a><br><a href=\"#order-this-pcb\">Order this PCB for yourself<\/a><br><a href=\"#conclusion\">Conclusion and Further steps<\/a><\/p>\n\n\n\n<p id=\"error-on-pcb\">Errors on the PCB<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-medium\"><img decoding=\"async\" width=\"162\" height=\"300\" data-src=\"http:\/\/144.126.248.244\/wp-content\/uploads\/2021\/08\/C10-C11-U2-Ground-Error-162x300.jpg\" alt=\"\" class=\"wp-image-13627 lazyload\" data-srcset=\"https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/C10-C11-U2-Ground-Error-162x300.jpg 162w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/C10-C11-U2-Ground-Error-600x1108.jpg 600w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/C10-C11-U2-Ground-Error-554x1024.jpg 554w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/C10-C11-U2-Ground-Error.jpg 680w\" data-sizes=\"(max-width: 162px) 85vw, 162px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 162px; --smush-placeholder-aspect-ratio: 162\/300;\" \/><figcaption>Ground Error on C10, C11 and U2<\/figcaption><\/figure><\/div>\n\n\n\n<p>During the design phase, I have forgotten to add a ground to the 5v regulator, and its supporting smoothing capacitors. These components were not initially included in my design, but, while added in later after I decided that since I will be designing the PCB to operate from many different voltage inputs, a reliable 5v source that is not dependent on USB power should be added&#8230; The components were added to the schematic, and I forgot to add the ground. It went undetected on the PCB design, as the Ground plane is a copper area&#8230; <br><br>In the picture above, you can see that I have temporarily fixed it with two wire links from the ground of C1, to the grounds of C10 and C11 respectively. These grounds connect back to U2. <br><br>C1 is another issue. Originally designed as a 100uf Electrolytic capacitor, I had to settle for a 10uf Tantalum. The reason being that the ordered capacitors are still floating in logistics space&#8230; with no definite ETA. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"1006\" data-src=\"http:\/\/144.126.248.244\/wp-content\/uploads\/2021\/08\/Error-1024x1006.jpg\" alt=\"\" class=\"wp-image-13628 lazyload\" data-srcset=\"https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/Error-1024x1006.jpg 1024w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/Error-600x589.jpg 600w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/Error-300x295.jpg 300w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/Error-768x754.jpg 768w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/Error-1536x1508.jpg 1536w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/Error.jpg 1784w\" data-sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/1006;\" \/><figcaption>Error on I2C labelling, as well as I2C Pins at IC2<\/figcaption><\/figure><\/div>\n\n\n\n<p>The following error was not so easy to spot. It gave me quite a headache to find. As I normally use netlabels on all the pins of any IC that I use, I have correctly labelled ESP12-E GPIO5 as SCL and GPIO4 as SDA. These netlabels were then transferred onto the PFC8574&#8217;s pins but in reverse! Note to self: Always re-read the pinout in the datasheet! To make matters worse, I flipped the SCL and SDA labels on the pin header&#8230; <br><br>How to fix:<br>I am fortunate that the ESP12-E, like all other ESP Modules, does not have fixed I2C pins. If this was an Atmega based project, the boards would have been useless if tracks could not be cut and reconnected! <br>On the ESP12-E, I2C is however software allocated to any desired GPIO pin. It was thus easily fixed by just swapping the two pins in software. <\/p>\n\n\n\n<p>The third problem encountered is another logistics issue. This is in the process of being resolved, but, as you will soon see, is not actually a problem at all&#8230; <br><br>I have added support for an onboard USB to Serial converter, via a CH340G chip. The chip requires a 12Mhz resonator or crystal. My dear supplier accidentally sent me an 8 Mhz version. I have thus decided to depopulate the entire USB to Serial circuit, leaving just the USB Port and protection diode on the board.  (To allow for powering via USB).<br><br>This does mean that programming the board becomes a little more complicated, connecting an external USB to Serial Adapter, and pressing and holding the flash button while pressing and releasing reset for each upload, followed by a manual reset afterwards. This is a pain, but, as I will be using these boards with ESPHome, only required once. All future uploads will be OTA anyway, and the correct components can be retrofitted when they arrive at a later stage.<\/p>\n\n\n\n<p>Powering on the PCB<\/p>\n\n\n\n<p id=\"powering-the-pcb\">The PCB was first powered on with an external USB to serial converter and using the Arduino IDE, a simple sketch testing the I2C addressing of the chip, as well as the functioning of all onboard relays and LEDs.<\/p>\n\n\n\n<p>The board was then flashed with ESPHome, using the procedure described in<a rel=\"noreferrer noopener\" href=\"http:\/\/144.126.248.244\/index.php\/2021\/08\/16\/design-and-build-an-esp8266-based-iot-controller-part-1\/\" target=\"_blank\"> Part 1<\/a>.<br>I then proceeded to measure the current required by the board, to make sure that it is as designed. <br><\/p>\n\n\n\n<p>Current Requirements<br>Powered from 9V to 12V DC via the DC Barrel Connector<br><br>Standby, Wifi Connected to Home Assistant, All relays and LEDs off <strong>75mA<\/strong><br>All relays energised, status LEDs all on <strong>255mA<\/strong><br><br>Integrating and Testing with EspHome and Home Assistant<\/p>\n\n\n\n<p id=\"testing-with-home-assistant\">The configuration for ESPHome was updated and uploaded to the device OTA. I decided to add a monitor for the VCC input of the ESP12-E, a remote Restart button, and an external DHT11 Temperature and Humidity sensor.<br>The updated code is available below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>esphome:\n  name: iot-controller-8266-01\n  platform: ESP8266\n  board: nodemcuv2\n\n# Enable logging\nlogger:\n\n# Enable Home Assistant API\napi:\n\nota:\n  password: \"2f8a73f47f1893f3f7baa391c4d0ba96\"\n\nwifi:\n  ssid: \"&lt;your ssid&gt;\"\n  password: \"&lt;your password&gt;\"\n\n  # Enable fallback hotspot (captive portal) in case wifi connection fails\n  ap:\n    ssid: \"Iot-Controller-8266-01\"\n    password: \"y4aaH7vMITsC\"\n\ncaptive_portal:\n#--- DO NOT COPY ANYTHING ABOVE THIS LINE ---\n\n# when using this, you need to reassign the status LED to another GPIO\n#deep_sleep:\n#  run_duration: 5min\n#  sleep_duration: 2min\n\ni2c:\n  sda: GPIO5\n  scl: GPIO4\n  scan: true\n  id: i2c_bus_a\n  \npcf8574:\n  - id: 'pcf8574_hub'\n    address: 0x22\n    pcf8575: false\n\nstatus_led:\n    pin: \n      number: GPIO16\n      inverted: true\n# Reassign this LED to another GPIO when using deep sleep mode !\n\nsensor:\n# Monitor VCC on the ESP12-E\n  - platform: adc\n    pin: VCC\n    name: \"Device Input Voltage\"\n    unit_of_measurement: \"V\"\n# Monitor the WiFi Signal Strength at the device\n  - platform: wifi_signal\n    name: \"WiFi Signal Sensor\"\n    unit_of_measurement: \"dBm\"\n    update_interval: 240s\n# Add Temperature and Humidity Sensor\n  - platform: dht\n    pin: GPIO2\n    temperature:\n      name: \"Room Temperature\"\n      unit_of_measurement: \"\u00b0C\"\n      icon: \"mdi:temperature\"\n      device_class: \"temperature\"\n      state_class: \"measurement\"\n      accuracy_decimals: 2\n      \n    humidity:\n      name: \"Room Humidity\"\n      unit_of_measurement: \"%\"\n      icon: \"mdi:water-percent\"\n      device_class: \"humidity\"\n      state_class: \"measurement\"\n      accuracy_decimals: 2\n    update_interval: 60s\n\n# Outputs to control relays and led's\n\noutput:\n - platform: gpio\n   id: relay_1\n   pin: \n      pcf8574: pcf8574_hub\n      number: 0\n      mode: OUTPUT\n      inverted: true\n - platform: gpio\n   id: relay_2\n   pin: \n      pcf8574: pcf8574_hub\n      number: 1\n      mode: OUTPUT\n      inverted: true\n - platform: gpio\n   id: led_status_1\n   pin: \n      pcf8574: pcf8574_hub\n      number: 2\n      mode: OUTPUT\n      inverted: true\n - platform: gpio\n   id: led_status_2\n   pin: \n      pcf8574: pcf8574_hub\n      number: 3\n      mode: OUTPUT\n      inverted: true\n# Monitor the two local control pushbuttons on the device  \nbinary_sensor:\n  -  platform: gpio\n     id: push_button_1\n     name: 'Relay1 Pushbutton'\n     device_class: ''\n     pin:\n        pcf8574:  pcf8574_hub\n        number: 4\n        mode: INPUT\n        inverted: true\n     on_press:\n      then:\n        - switch.toggle: switch_relay1\n     filters:\n       -  delayed_on_off: 50ms\n       \n  -  platform: gpio\n     id: push_button_2\n     name: 'Relay2 Pushbutton'\n     device_class: ''\n     pin:\n        pcf8574:  pcf8574_hub\n        number: 5\n        mode: INPUT\n        inverted: true\n     on_press:\n      #min_length: 50ms\n      #max_length: 500ms\n      then:\n        - switch.toggle: switch_relay2\n     filters:\n       -  delayed_on_off: 50ms\n\n# Allow control from inside Home Assistant\n     \nswitch:\n  - platform: output \n    id: switch_relay1\n    name: \"Relay No. 1 (#0)\"\n    output: relay_1\n    on_turn_on:\n    - output.turn_on: led_status_1\n    on_turn_off:\n    - output.turn_off: led_status_1\n  - platform: output \n    id: switch_relay2\n    name: \"Relay No. 2 (#1)\"\n    output: relay_2\n    on_turn_on:\n    - output.turn_on: led_status_2\n    on_turn_off:\n    - output.turn_off: led_status_2\n # Add a remote Reboot switch \n  - platform: restart\n    name: \"Reboot Me\"<\/code><\/pre>\n\n\n\n<p>After uploading this configuration, Home Assistant was configured to reflect the changes.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"519\" data-src=\"http:\/\/144.126.248.244\/wp-content\/uploads\/2021\/08\/Screenshot-from-2021-08-30-12-57-06-1024x519.png\" alt=\"\" class=\"wp-image-13631 lazyload\" data-srcset=\"https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/Screenshot-from-2021-08-30-12-57-06-1024x519.png 1024w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/Screenshot-from-2021-08-30-12-57-06-600x304.png 600w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/Screenshot-from-2021-08-30-12-57-06-300x152.png 300w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/Screenshot-from-2021-08-30-12-57-06-768x389.png 768w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/08\/Screenshot-from-2021-08-30-12-57-06.png 1089w\" data-sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/519;\" \/><figcaption>Home Assistant showing the IoT Controller status ( EE Lab Area ) as well as Admin stats (Master Control Panel)<\/figcaption><\/figure><\/div>\n\n\n\n<p>I have decided to split the different status and control outputs from the device into two cards, One in the EE Lab Area, which will later be moved into the actual room(s) where the device will be deployed, as well as on a Master Control Panel. From here, I can reboot individual devices, see their voltages and WiFi Status<\/p>\n\n\n\n<p><strong>Tasmota<\/strong><\/p>\n\n\n\n<p id=\"tasmota\">As promised before, I did test the device with Tasmota. I had to do a custom compile to get support for the PCF8574. Performance was however VERY poor. ESPHome is snappy and quick, even in local mode. Tasmota seemed to have at least a one-second delay on doing anything.<br>I thus abandoned it, and won&#8217;t be making use of it in this project anymore. The flexibility of ESPHome to do what I want, how I want it, is definitely missing in Tasmota. Hopefully, that will change in the future?<\/p>\n\n\n\n<p><strong>Order this PCB for yourself<\/strong><\/p>\n\n\n\n<p id=\"order-this-pcb\">You can order this PCB from <a rel=\"noreferrer noopener\" href=\"https:\/\/www.pcbway.com\/setinvite.aspx?inviteid=403795\" target=\"_blank\">PCBWay<\/a> as a shared Project, by clicking <a rel=\"noreferrer noopener\" href=\"https:\/\/www.pcbway.com\/project\/shareproject\/Build_your_own_IoT_Controller.html\" target=\"_blank\">here<\/a>.<br>New users will get a $5 USD coupon for use with their first order if they follow the link below to sign up for an account.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.pcbway.com\/setinvite.aspx?inviteid=403795\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"408\" height=\"69\" data-src=\"http:\/\/144.126.248.244\/wp-content\/uploads\/2021\/07\/Screenshot-from-2021-07-22-18-45-42.png\" alt=\"\" class=\"wp-image-13166 lazyload\" data-srcset=\"https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/07\/Screenshot-from-2021-07-22-18-45-42.png 408w, https:\/\/www.makeriot2020.com\/wp-content\/uploads\/2021\/07\/Screenshot-from-2021-07-22-18-45-42-300x51.png 300w\" data-sizes=\"(max-width: 408px) 85vw, 408px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 408px; --smush-placeholder-aspect-ratio: 408\/69;\" \/><\/a><\/figure><\/div>\n\n\n\n<p>I would also like to thank Wendy at PCBWay for once again being a star. The project went smoothly and was very well produced. Make sure to consider using <a rel=\"noreferrer noopener\" href=\"https:\/\/www.pcbway.com\/setinvite.aspx?inviteid=403795\" target=\"_blank\">PCBWay<\/a> for your next PCB order.<br><br><strong>Conclusion and further steps<\/strong><\/p>\n\n\n\n<p id=\"conclusion\">I am in the process of building and assembling another 2 of these devices. I have also ordered and received PolyCarbonate enclosures to mount them in. As this is an ongoing project, I still plan to add I2C temperature measurement chips to each, to measure the temperature inside the enclosure. An Air quality sensor, as well as a CO2 sensor, is also planned, with a possible Display Shield to provide test output locally at the device. This display, at the moment at least, is planned as an I2C Oled or similar. There are also plans to do an option to directly power the unit from 220V AC via an additional base-board for now, or a complete redesign, incorporating everything on one board.<br>Thank you for following along, I hope that you found it educational and entertaining. <br>Please consider joining us on <a rel=\"noreferrer noopener\" href=\"https:\/\/www.patreon.com\/maker_and_iot_ideas\" target=\"_blank\">Patreon<\/a>. We are in the process of creating exclusive content for that platform, as well as for http:\/\/144.126.248.244. Most of the content will also remain free for all as usual. <br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to Part 3 of this build. If you are new to this series, Part1 and Part2 can be found by clicking on the respective links. Today, we will look at the completed PCB for our IoT Controller. Full disclosure, There are some issues, ranging from components that have still (15 days after being ordered, &hellip; <a href=\"https:\/\/www.makeriot2020.com\/index.php\/2021\/08\/30\/design-and-build-an-esp8266-iot-controller-part-3\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Design and build an ESP8266 IoT Controller, Part 3&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":13625,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89,44,53],"tags":[45,81,67,55],"class_list":["post-13624","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-custom-pcb-design","category-electronics","category-iot-devices","tag-electronics","tag-esp8266","tag-i2c","tag-iot"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.makeriot2020.com\/index.php\/wp-json\/wp\/v2\/posts\/13624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.makeriot2020.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.makeriot2020.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.makeriot2020.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.makeriot2020.com\/index.php\/wp-json\/wp\/v2\/comments?post=13624"}],"version-history":[{"count":0,"href":"https:\/\/www.makeriot2020.com\/index.php\/wp-json\/wp\/v2\/posts\/13624\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.makeriot2020.com\/index.php\/wp-json\/wp\/v2\/media\/13625"}],"wp:attachment":[{"href":"https:\/\/www.makeriot2020.com\/index.php\/wp-json\/wp\/v2\/media?parent=13624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.makeriot2020.com\/index.php\/wp-json\/wp\/v2\/categories?post=13624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.makeriot2020.com\/index.php\/wp-json\/wp\/v2\/tags?post=13624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}