Cytron Maker Pi RP2040 features the first microcontroller designed by Raspberry Pi – RP2040, embedded on a robot controller board. This board comes with a dual-channel DC motor driver, 4 servo motor ports and 7 Grove I/O connectors, ready for your next DIY robot/motion control project. Now you can build a robot while trying out the new RP2040 chip.
The DC motor driver on board is able to control 2x brushed DC motors or 1x bipolar/unipolar stepper motor rated from 3.6V to 6V, providing up to 1A current per channel continuously. The built-in Quick Test buttons and motor output LEDs allow a functional test of the motor driver in a quick and convenient way, without the need of writing any code. Vmotor for both DC and servo motors depends on the input voltage supplied to the board.
Maker Pi RP2040 features all the goodness of Cytron’s Maker series products. It too has lots of LEDs useful for troubleshooting (& visual effects), is able to make quite some noise with the onboard piezo buzzer and comes with push buttons ready to detect your touch.
There are three ways to supply power to the Maker Pi RP2040 – via USB (5V) socket, with a single cell LiPo/Li-Ion battery or through the VIN (3.6-6V) terminals. However, only one power source is needed to power up both controller board and motors at a time. Power supply from all these power sources can all be controlled with the power on/off switch onboard.
Cytron Maker Pi RP2040 is basically the Raspberry Pi Pico + Maker series’ goodness + Robot controller & other useful features. Therefore this board is compatible with the existing Pico ecosystem. Software, firmware, libraries and resources that are developed for Pico should work seamlessly with Cytron Maker Pi RP2040 too.
CircuitPython is preloaded on the Maker Pi RP2040 and it runs a simple demo program right out of the box. Connect it to your computer via USB micro cable and turn it on, you will be greeted by a melody tune and LEDs running light. Press GP20 and GP21 push buttons to toggle the LEDs on/off while controlling any DC and servo motors connected to it to move and stop. With this demo code, you get to test the board the moment you receive it!
While connected to your computer, a new CIRCUITPY drive appears. Explore and edit the demo code (code.py & lib folder) with any code editor you like, save any changes to the drive and you shall see it in action in no time. That’s why we embrace CircuitPython – it’s very easy to get started. Wish to use other programming languages? Sure, you are free to use MicroPython and C/C++ for Pico/RP2040. For those of you who love the Arduino ecosystem, please take a look at this official news by Arduino and also the unofficial Pico Arduino Core by Earle F. Philhower.
In August of 2021, MakerIoT2020 released the MCU-8266-12E IoT Controller PCB, (part 1 is available here in case you missed that). Shortly after that, we started working on an expansion add-on card, that would work with the APE (Arduino Port Expander) protocol in ESPHome.
While I could have used a standard Arduino board for this, and in fact, I have done so during many of the testing stages, I decided to design a custom PCB specifically for this task, in order to achieve two specific things…
1). The standard Arduino Board comes in either a 5v logic or 3v logic device. While this is perfect for many projects, it is still sometimes required to use a logic level converter with some sensors and devices. LORA is a good example of that. As I really dislike using a breadboard, due to their inherent unreliable connections and the ever-present mess of wires going everywhere, I wanted an Arduino or ATMEGA328 based device that already has a level converter built-in.
As I could not find anything like that for sale, I decided to build my own, as you will see shortly.
2). I wanted to start moving away from using the Arduino IDE as much as possible. While the Arduino IDE is great for most tasks, It does lack in a few areas. I thus want to slowly ease myself back into using AVR C, and that requires a board that can be flashed via ICSP. ( yes, yes, you can flash an Arduino with ICSP as well. ) In the case of the planned expansion card, it would basically be a device that is flashed once and then left alone. Serial flashing would be quite unnecessary on there anyway.
The other reason, still part of point 2, is that it seems like everyone else is having all sorts of problems with fuses on the ATMega328 on custom boards etc… I wanted to see if that is really the case or not…
The PCB should also be useable as a standard “Arduino” type device to assist in prototyping and development.
ATMega328P Custom PCB – as a prototype add-on card to the MCU-8266-12E IoT controller
a Quick description of the PCB:
Standard Arduino type headers and pins are provided, with pin labels as for the Arduino Nano. This gives us:
ATMega 328P MCU running at 16Mhz 12 Digital IO (D2 to D13) [ 14 if we use D1 and D2 as well ] 8 Analog Inputs (A0 to A7) [ A4 and A5 are used for I2C ] ICSP header for uploading code USB Port with CH340G for Arduino style serial flashing [This will be removed on the next version] A Dedicated LDO 3.3v Voltage regulator, with a selectable input source (5v from USB, or directly from VIN – for high current use applications – MAX of 800mA)
An 8 Channel Bi-Directional Logic Level Converter, for now, the converter is fixed at bi-directional 3v to 5v conversion. Additional 5v (x4), 3v (x4) and Ground pins (x8), as well as 2 general use bus connections (G1, G2) which I added for use with I2C
Led’s are provided on 5v, 3v, Serial Rx, Tx, as well as on pin D13.
Dimensions: 86mm x 51mm
Assembly – During Reflow on a hotplate.During Reflow
Manufacturing the PCB
This PCB was manufactured at PCBWAY. The Gerber files and BOM, as well as all the schematics, will soon be available as a shared project on their website. If you would like to have PCBWAY manufacture one of your own, designs, or even this particular PCB, you need to do the following… 1) Click on this link 2) Create an account if you have not already got one of your own. If you use the link above, you will also instantly receive a $5USD coupon, which you can use on your first or any other order later. (Disclaimer: I will earn a small referral fee from PCBWay. This referral fee will not affect the cost of your order, nor will you pay any part thereof.) 3) Once you have gone to their website, and created an account, or login with your existing account,
4) Click on PCB Instant Quote
5) If you do not have any very special requirements for your PCB, click on Quick-order PCB
6) Click on Add Gerber File, and select your Gerber file(s) from your computer. Most of your PCB details will now be automatically selected, leaving you to only select the solder mask and silk-screen colour, as well as to remove the order number or not. You can of course fine-tune everything exactly as you want as well.
7) You can also select whether you want an SMD stencil, or have the board assembled after manufacturing. Please note that the assembly service, as well as the cost of your components, ARE NOT included in the initial quoted price. ( The quote will update depending on what options you select ).
8) When you are happy with the options that you have selected, you can click on the Save to Cart Button. From here on, you can go to the top of the screen, click on Cart, make any payment(s) or use any coupons that you have in your account.
Then just sit back and wait for your new PCB to be delivered to your door via the shipping company that you have selected during checkout.
Conclusion
In conclusion, the PCB works quite well, with no issues with flashing the ATMEGA328P with an ICSP programmer from the Arduino IDE, as well as via USB from the Arduino IDE.
The level converter works as expected, successfully translating bidirectional signals on I2C and SPI to and from 3v and 5v devices.
In the next stage, we will focus on the stock APE protocol sketch, as provided by ESPHome, and then, once that is working perfectly, modify it to suit our needs.
By being a part of Makrverse, you are joining a community of Makers. Makrs are the tech enthusiasts who cannot wait to have their hands on the newest inventions, the early adopters, the innovators. Makrverse is the place for everyone who wants to be a part of a making universe.
MakerIoT2020 was recently contacted by the creators of this exciting new startup. The platform aims to connect Makers and Tech Enthusiasts, thereby solving the need to get hold of the latest gadgets directly from their inventors.
With the initial prototyping of my IoT Controller now completed, and software performing as expected, I have started with the development of an add-on shield. The base device offers 2 built-in relays, and access to another 6 IO Ports on the PCF8574, as well as all the GPIO on the ESP-12E. This is all good and well and suits my initial purposes well, but
I do however now see a need to add more sensors to the device, as well as find an elegant way to power it directly from mains power, while not having lots of wires going anywhere.
So the next steps will be:
Design an add-on-shield to provide me with the following: – Analog inputs. The ESP-12E has only one, and that will be very limiting in some situations. -Digital Inputs and Outputs While there are still unused GPIO ports on the existing board, native to the ESP-12E, having the ability to connect additional devices and sensors will definitely be a good option to have in future. -Some sort of Display Small OLED I2C displays are cheap and easy to use. I can also go full colour with an SPI display…
From here on, I have to decide on how and what. I can go the discreet chip route, by using dedicated I2C chips that provide all these functions, or I can add a secondary micro-controller to the shield, which would provide more flexibility, but can also add complexity to the final design…
Please follow along and join me on the next part of this design journey. I can not promise anything yet, but I do guarantee that it will be exciting…
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, 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. 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.
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… 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…
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.
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… with no definite ETA.
Error on I2C labelling, as well as I2C Pins at IC2
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’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…
How to fix: 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! 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.
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…
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).
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.
Powering on 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.
The board was then flashed with ESPHome, using the procedure described in Part 1. I then proceeded to measure the current required by the board, to make sure that it is as designed.
Current Requirements Powered from 9V to 12V DC via the DC Barrel Connector
Standby, Wifi Connected to Home Assistant, All relays and LEDs off 75mA All relays energised, status LEDs all on 255mA
Integrating and Testing with EspHome and 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. The updated code is available below
esphome:
name: iot-controller-8266-01
platform: ESP8266
board: nodemcuv2
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "2f8a73f47f1893f3f7baa391c4d0ba96"
wifi:
ssid: "<your ssid>"
password: "<your password>"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Iot-Controller-8266-01"
password: "y4aaH7vMITsC"
captive_portal:
#--- DO NOT COPY ANYTHING ABOVE THIS LINE ---
# when using this, you need to reassign the status LED to another GPIO
#deep_sleep:
# run_duration: 5min
# sleep_duration: 2min
i2c:
sda: GPIO5
scl: GPIO4
scan: true
id: i2c_bus_a
pcf8574:
- id: 'pcf8574_hub'
address: 0x22
pcf8575: false
status_led:
pin:
number: GPIO16
inverted: true
# Reassign this LED to another GPIO when using deep sleep mode !
sensor:
# Monitor VCC on the ESP12-E
- platform: adc
pin: VCC
name: "Device Input Voltage"
unit_of_measurement: "V"
# Monitor the WiFi Signal Strength at the device
- platform: wifi_signal
name: "WiFi Signal Sensor"
unit_of_measurement: "dBm"
update_interval: 240s
# Add Temperature and Humidity Sensor
- platform: dht
pin: GPIO2
temperature:
name: "Room Temperature"
unit_of_measurement: "°C"
icon: "mdi:temperature"
device_class: "temperature"
state_class: "measurement"
accuracy_decimals: 2
humidity:
name: "Room Humidity"
unit_of_measurement: "%"
icon: "mdi:water-percent"
device_class: "humidity"
state_class: "measurement"
accuracy_decimals: 2
update_interval: 60s
# Outputs to control relays and led's
output:
- platform: gpio
id: relay_1
pin:
pcf8574: pcf8574_hub
number: 0
mode: OUTPUT
inverted: true
- platform: gpio
id: relay_2
pin:
pcf8574: pcf8574_hub
number: 1
mode: OUTPUT
inverted: true
- platform: gpio
id: led_status_1
pin:
pcf8574: pcf8574_hub
number: 2
mode: OUTPUT
inverted: true
- platform: gpio
id: led_status_2
pin:
pcf8574: pcf8574_hub
number: 3
mode: OUTPUT
inverted: true
# Monitor the two local control pushbuttons on the device
binary_sensor:
- platform: gpio
id: push_button_1
name: 'Relay1 Pushbutton'
device_class: ''
pin:
pcf8574: pcf8574_hub
number: 4
mode: INPUT
inverted: true
on_press:
then:
- switch.toggle: switch_relay1
filters:
- delayed_on_off: 50ms
- platform: gpio
id: push_button_2
name: 'Relay2 Pushbutton'
device_class: ''
pin:
pcf8574: pcf8574_hub
number: 5
mode: INPUT
inverted: true
on_press:
#min_length: 50ms
#max_length: 500ms
then:
- switch.toggle: switch_relay2
filters:
- delayed_on_off: 50ms
# Allow control from inside Home Assistant
switch:
- platform: output
id: switch_relay1
name: "Relay No. 1 (#0)"
output: relay_1
on_turn_on:
- output.turn_on: led_status_1
on_turn_off:
- output.turn_off: led_status_1
- platform: output
id: switch_relay2
name: "Relay No. 2 (#1)"
output: relay_2
on_turn_on:
- output.turn_on: led_status_2
on_turn_off:
- output.turn_off: led_status_2
# Add a remote Reboot switch
- platform: restart
name: "Reboot Me"
After uploading this configuration, Home Assistant was configured to reflect the changes.
Home Assistant showing the IoT Controller status ( EE Lab Area ) as well as Admin stats (Master Control Panel)
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
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. I thus abandoned it, and won’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?
Order this PCB for yourself
You can order this PCB from PCBWay as a shared Project, by clicking here. 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.
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 PCBWay for your next PCB order.
Conclusion and further steps
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. Thank you for following along, I hope that you found it educational and entertaining. Please consider joining us on Patreon. 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.
In my previous post, available here, I have shown you the initial stages of designing and developing our own IoT controller. Today, while the PCB has just arrived from PCBWay, and while we wait for the rest of the components to arrive, we will continue with the software development of the device. I will also show you the beautiful PCB that I got from PCBWay!
For today’s post, we will focus on configuring ESPHome, get it to work together with Home Assistant, as well as have a look at those PCB’s!
Our next step will be to write the YAML configuration file…
YAML configuration
ESPHome uses the YAML language to define IO and automation. These files are then parsed, converted into C/C++ and compiled. The resulting Binary File is the uploaded OTA to the device via WiFi.
We will still be using our Virtual Machine Image of Home Assistant, running inside VirtualBox on our PC. Go ahead and start that, and then open Home Assistant in your Web Browser. Then click on ESPHome. You will see a screen similar to the one above.
While we are at this point, I believe it is a good time to clarify why we do the development in a virtual PC, and not directly on our Home Assistant instance running on a Raspberry Pi. The reason is actually very simple. Home Assistant seems to have issues with completely removing unused entities. This is not a problem, but you could potentially end up with a lot of stale entries in your production Home Assistant Server. The VM solution allows us to test everything away from the actual server, and then, when we are done, recreate the working device on the actual server. That way, there is almost no chance of damaging your existing Home Assistant Server, which you may already have spent some time on to set up just the way you want it…
Continue by clicking on the EDIT link, in the iot-con-prototype device that we created in the last tutorial. You will see a file similar to this …
This is the default configuration file generated by ESPHome. We will build on this file… Note that your OTA Password will be different. DO NOT CHANGE OR MODIFY IT IN ANY WAY!
When we edit YAML, indentations are extremely important, so try to follow exactly what I am doing.
Our IoT Controller uses I2C to communicate with the PCF8574 chip. Let us assume that you have set your address to 0x22h by using the dip switch on the PCB, you could of course set any other address, just make sure that you know what it is.
We now need to tell ESPHome that we have an I2C Bus and that it needs to scan this bus for devices. That way, we can see in the logs if it actually detects our device or not.
We give this device the id of pcf8574_hub and specify its address as 0x22. We also NEED to specify that it is NOT the 16 port pcf8575 variant.
Now we can start configuring our outputs. for our purposes, we will have two relay outputs, as well as two status LEDs. In the actual circuit, the pcf8574 will sink the pins connected to these, as the chip can sink more current than it can safely source. Refer to the relay driver schematic for more information on that.
The syntax should be straightforward, every output will have a platform, in this case, gpio. Then we will need a unique ID, let us say relay_1 Now, we need to specify the physical pin to use. Now here, you could also specify a native pin on the actual NodeMCU device that we are using for testing, but we will specify a pin on the pcf8574 instead. This is done with the pin: directive pin: pcf8574: pcf8574_hub // This tells the parser to use the device at address 0x22 that we specified before. number: 0 // use GPIO 0 mode: OUTPUT // this can be either INPUT or OUTPUT, for our case, it should be OUTPUT. inverted: true // Invert the logic of the pin.
Once again, it is needed, as we are sinking current into the pin, and the circuit was designed that way… You can however use it noninverted if you really want, it will just look a bit odd on Home Assistant, if your On state, actually meant Off
The next section will be called binary inputs and may seem a bit confusing at first. But, trust me, it is not. This is just the way that we define our physical push buttons on the device. We need those, in the event that our Home Assistant Server is offline, or when we need to physically press a button on the device.
What? Why? Are we not building an IoT Controller? Why should we press any physical buttons on it? Well, the answer to that is quite obvious. There will definitely be times that you want to control an attached device by pressing a physical button. It does not make sense to scurry around, swiping through apps on your smartphone, while you are standing right next to the device in question. To leave out this basic functionality, would be plain silly, and in my view, bad engineering.
The syntax is almost the same as the outputs above, but we are also adding automation: We want the relay to be toggled each time the button is pressed. This will allow us to use only one button per relay to switch it on or off. We are also adding a filter, in this case, a bit of debouncing, of 50ms. This will prevent the chattering of the contacts on the switch from generating more than one event for each button press.
The final section of the file will be a switch: section. This will allow you to control the relays from inside Home Assistant. ( The outputs are considered an internal to ESPHome function, and will thus not be exposed to Home Assistant. Add the following lines to the file
You can see that the syntax is once again very easy to understand. We also specify that the status LED for the relevant relay channel be switched on or off with the relay. This also happens when you press the physical switch. The name element will be the Name of the Output that will be displayed in Home Assistant. You can change it to your liking here, or you can also change it inside Home Assistant itself.
The completed file should now look like this. NOTE that if you decide to copy-paste the file from here, as I would recommend, you should only copy from the i2c section to the end of the file. Do not copy the WiFi and other sections. Your own file already has your own settings.
Well done, That was quite easy. Copy and paste the file into the edit screen that you have opened in ESPHome.
If everything went well. you should see an option to save or install as in the picture below.
YAML configuration file. ESPHome
If you can see both Save and Install, it means that your file syntax is correct. If not, go back and carefully check your indentations, as well as the spelling of the commands. It should not be a problem if you copied it from above…
Now click on save. You will get a confirmation. Make sure that the prototype is connected to the USB port of the computer, or to another power source. Wait a few seconds to make sure that it is connected to the network, and then click Install.
ESPHome will now parse your YAML file, generate the needed code, and compile it. After that, it will upload the new firmware to your device. Wait until you can see the device restart and connect to the network in the log window.
The Firmware is compiled and the uploaded OTA
The device had booted, note that the PCF8574 has been detected and that we can see our configuration data (in purple text)
Configuring Home Assistant
We can now start to add this all to Home Assistant. It is also very likely that you will be prompted to add the device by Home Assistant itself. If this did not happen, or like with my testing image on the VM, you have a lot of old stuff floating around as well, we can do it manually …
Go to the Configuration Menu, and click on Integrations.
Click on the esp8266-nodemcu option on ESPHome
Click on the entities, next to the device …
The available entities ( selected with a blue checkmark ). Entities with a red warning are stale, meaning old, unavailable or offline… You can remove them, but they tend to show up again on their own…
We can now select the two relays, as well as the Pushbuttons. Then click on Enable selected.
When you now go back to the Home Assistant Home screen, you will see your device with its controls, on the screen. You can now control the device from Home Assistant. You will note that the two push-buttons are also present in Home Assistant, but, they are only indicators. This means that while they will change state briefly when you press the physical switches, they can not be controlled directly from Home Assistant. They can however be used in automation, or at least I believe so. The debouncing times are however rather short, so I would recommend that you base any automation on the actual relay states instead. A sneak preview of the PCB
As promised above, I will now give you a quick preview of the PCB’s. They were manufactured by PCBWay
I am once again awed by the precision of these bords. They are absolutely flawless and exactly true to my design. The irregular isolation cut-outs are exactly to speck and size, the silkscreen is crisp and not blurred. All component footprints are correct, and there seem to be no shorts or open circuits on initial testing with a multimeter.
You can get your own version of these for only $USD 5.00 excluding shipping from here I believe you will be just as impressed as I am.
So let us look at these boards…
PCB’s in packaging
Securely packaged in vacuum-packed bubble wrap
Topside of the PCB
Top Side of PCB
Back of PCB, isolation cutouts clearly visible
The PCB’s have arrived.
My biggest frustration now will be to wait for the rest of the components to arrive. I already have some of them in stock, and can repurpose some others, but I think that I will rather wait for everything to arrive so that I don’t have to assemble them in stages. I plan to assemble 2 of the 10 boards and make some of the remaining 8 available to interested people. Contact me on messenger if you are interested.
Conclusion
This concludes part 2 of this series. In part 3, we will look at the assembled PCB’s, as well as take a more detailed look at using them together with Home Assistant. I will also attempt to do the Tasmota integration, this will involve compiling my own special version of Tasmota.
I am also planning to release the assembly process as a series of pictures or maybe a video on Patreon.
If you like what I do, I want to ask you to consider becoming a Patron. With some assistance from generous people like yourself, I can create some more interesting projects.
The Internet of Things (IoT), as well as Home Automation, are steadily gaining popularity all the time. You can already buy quite a lot of commercial products or do your own D.I.Y implementation. Many different companies offer various devices and modules to help you do your project easily. But many of us will know that these modules always come with a lot of wires and connections, which can be very unreliable, and also unsightly to look at.
Most of these solutions are also relying on you placing some stuff on an electronics-breadboard, or strip-board for more permanent installations. You can also decide to design and manufacture your own custom PCB.
On the software side of this problem, there are many commercial and open-source solutions available, and most of them work with almost anything on the market (With various degrees of complexity and a varying learning curve).
Having access to a few ( four to be exact ) Raspberry Pi Computers, as well as a huge number of ESP8266, ESP32, Arduino and STM32 Development boards that are lying around in my working area, as well as being quite lazy to do repetitive tasks, I have been playing with the idea for quite a while to automate some or maybe all of the lights in my house. I have also built quite a few device prototypes, only to tear them down again after testing them.
The reason for this, and this is only my own opinion, is that an electronics breadboard is meant for prototyping only. They are not reliable in the long term, and they look extremely messy. Using a certain development board, and connecting all of the supporting components and modules to it, also leaves quite a mess. So,
1) The project must be contained on a single PCB. 2) It must have WiFi and or Bluetooth support (ESP8266 does not have this [ Bluetooth ]) 3) It must be able to be powered from 220v mains directly, OR, through a single Plug Type AC to DC converter, preferably something already available on the market. 4) The power supply unit must supply adequate power to the unit. 5) I want to make some actual use of a Raspberry Pi, as they were not meant to lie around gathering dust 🙂
6) Once completed, the project should be able to be updated OTA or with as little fuss as possible. 7) The freedom to code in whatever language I want, as well as be easy to use with prebuilt firmware like ESPHome and or Tasmota and the likes.
Taking into consideration cost, as well as flexibility, I decided on using the ESP8266 and in later versions ESP32. These have WiFi and Bluetooth already built-in but have a nasty breadboard form factor. The popular NodeMCU is a great starting point, but it has many small design flaws, most of which were fixed in later versions, but, as I live in SE Asia, and electronics are super cheap, you never know what you get.
With this in mind, I have decided to design my own controller, based on the ESP-8266 12E Module. This will give me the flexibility I need while allowing me to add custom components and features as needed, which is not possible with a stock version.
As far as Software is concerned, Home Assistant, running on a Raspberry Pi 4B with 4Gb Ram will be sufficient to control all of this. Firmware on the ESP12-E can be either ESPHome, Tasmota, or something that I write on my own, connecting to the internet and using MQTT for communication. (The options here are also almost too many to mention, but, IFTTT, Adafruit IO, and Blynx come to mind… Alexa and Google Assistant support are also possible, but definitely not required in my application at this moment.
Any permanent project grows on you, and over time, you will want to add features and functions. Keeping this in mind when you start designing saves a lot of headaches later. I will thus definitely make sure to provide access to the I2S, SPI and Serial Peripherals.
Prototyping and Initial Testing
Software It is quite impossible to design something without building a prototype, and doing some very rigorous testing. To do this, I have started with a copy of Home Assistant running in a VM on my HP ML350G Debian server computer. This way, I can quickly test Home Assistant, and make sure everything works as I want it to, without having to do it on the PI. This will mean that I will have to re-do most of the software configuration again on the PI, but it gives me the flexibility to take snapshots and restore them if something goes wrong.
The procedure that I followed, for VirtualBox, can be found here. I am sure that it will be very similar for Windows users.
Start Home Assistant
When you have completed the installation, you can go ahead and start Home Assistant.
You may now open Home Assistant in your browser by going to http://<your-ip-address>:8123 and pressing enter. You will see something similar to this:
Install ESPHome
You may now scroll down to the Supervisor Menu Item, Click on the Addon Store link, and Install ESPHome.
Please make sure that you select “start on boot”, “watchdog”, “auto-update” and “show in the sidebar” Also, make sure to start the add-on
You are now ready to flash ESPHome onto your development board. Please note that you will have to repeat this step on the actual PCB device that we will design and build later. For now, we will however use a standard NodeMCU v3 module, as it contains the ESP-12E module that we require.
As we have not configured HTTPS in our Home Assistant installation, we can only flash the initial firmware using an external application. This application is called ESPHome Flasher, and you can download it here.
Prepare to Flash
We need to create an initial device in ESPHome. to do this, you need to click on the ESPHome Menu Item in the Home Assistant sidebar. Then click on the Green and White + sign at the bottom right corner…
Give your device a descriptive name, I went with iot-con-prototype. Also, add your WiFi network credentials (SSID and Password). Then click on NEXT.
You now have to select your ESP board. I went with NodeMCU.
Click on NEXT when you are done. You will now be alerted that a configuration has been created. Click on the Close button.
You will now see your device in the list. The red line means that the device is OFFLINE.
If you have not installed ESPHome Flasher yet, now is a good time to do it. When you are done, connect the NodeMCU module to the computer’s USB port and start ESPHome Flasher. Note: On Linux, you dont have to install it. you can just start it from the terminal using ./ESPHome-Flasher-1.3.0-Ubuntu-x64.exec ( this example is for Debian ) yours may differ … sudo may be required
Select the communications port from the dropdown menu. Now go back to Home Assistant, ESPHome Screen. Click on the Install link (in yellow) of the device that we added previously. Then click on Manual Download
ESPHome will now compile your initial firmware and prompt you to save the .bin file it has generated.
Take note of the location of this file, we will need it for the next step.
Now you can go back to the ESPHome Flasher window, and browse to the .bin file that you have just generated and downloaded.
When this is done, you can click on Flash ESP. The firmware will now be flashed onto the NodeMCU device that we will use as our prototype.
You can close the Flasher application when you see predominantly purple text in the console window. This means that the device has connected successfully with your WiFi network, and by extension, also with ESPHome and Home Assistant.
If you now go back to ESPHome, you will see that the device has a green line above its name, which means that it is online. Please note that at this stage, the device does not do anything, as we have not yet configured it. That will be our next task, but before we do that, we will have to start playing with some of the physical hardware yet.
Designing the Hardware
I have decided to base this controller on the popular NodeMCU v3 development board. This little board makes use of the ESP12-E module, designed by AITinker, from whom I have bought many well-designed modules before. The module (NodeMCU) is in a BreadBoard form factor, and thus clearly meant for prototyping, or use on a base-board of some kind. I do however have some issues with this module, namely:
1. Many of these units are in fact clones. Some of these does not have proper protection between the board and the USB port to power them. This makes it dangerous to connect power to the VIN pin. 2. The board does not have a built-in 5v regulator. The 5v output (VIN) is thus taken directly from the USB port that powers it. This limits the total available current to the board and all peripherals to the 500mA available from the USB port.
All of these issues are however easy to overcome, as Espressif has made available excellent documentation on using their modules. I will thus be using this documentation as a reference design for my own device.
Another issue is expandability. The module provides many broken out GPIO pins (D0 to D8), but in order to remain super flexible for future expansion, I would have to make sure that I keep the built-in peripherals, like i2c, spi, and uart free for connection to external addon components in future. To solve this, I have decided on using the PCF8574 I2C IO Expander. This means that…
D0 (GPIO16) needs to be kept free for Wake up from deep sleep mode D1 (GPIO5) SCL line of I2C Bus D2 (GPIO4) SDA line of I2C Bus D3 (GPIO0) connected to Flash Button, and also a strapping pin D4 (GPIO2) Tx of UART 1 D5 (GPIO14) HSCLK – SPI Clock D6 (GPIO12) HMISO – SPI MISO D7 (GPIO13) Rx UART 2 / HMOSI – SPI MOSI D8 (GPIO15) Tx UART 2 / HCS – SPI CS as well as a strapping pin D9 ([Rx] GPIO03) Rx UART 0 D10 ([Tx] GPIO01) Tx UART 0
Looking at this, it is thus very clear that I2C is the way to go, as it will use only two pins, leaving the other GPIO’s free for future expansion.
Relay Driver Circuit, status led(s) and user control
The PCF8574 has very weak current sourcing capabilities, but it can sink 25mA per IO pin. As I will be driving the chip from 3v, this will however not be enough to drive a 5v relay. I will thus be making use of an optocoupler to drive the relay from 5v, using a general-purpose NPN transistor. That way, I can make sure that I do not overload the IO line on the PCF8574, as well as keep the 3v and 5v lines isolated from each other. (They will however still share a common ground).
Relay Driver Schematic
As you can see from the schematic above, the relay driver(s) will be connected to P0 and P1 of the PCF8574. A 200-ohm resistor will limit the current to about 16.5mA @ 3.3v. This is well within the tolerance of 25mA for the PCF8574 as well as the 50mA limit of the EL357N Optocoupler chip.
On the output side, I made use of the S8050 general purpose NPN transistor, capable of a 25v collector-emitter voltage, ant a continuous current of 500mA. Move than sufficient to drive the +/- 70mA to 80mA of current required by the relay coil. The current through the phototransistor side of the optocoupler is limited by a 1k resistor to the base of the transistor, to 5mA.
PCF8574 IO Expander Status LED(s) and User Input Schematic
Provision is made for up to four (4) pushbuttons, by pulling pins P4 to P7 down to ground, through an external push-button connected to a 2-way pin header. The design allows for the pin to be used for another function as well, with an additional breakout pin provided on the edge of the board.
Likewise, the two status LED’s on P2 and P3 is connected via a 470-ohm resistor each, driving them at approximately 7mA each. This is once again within the 25mA sink limit of the PCF8574. These pins can also be used to connect to other hardware instead via the breakout header at the edge of the board.
The user input(s) and status led circuit was purposefully kept as plain as possible, as it is very likely that the additional 6 ports taken up by these will be used for other purposes instead.
USB to Serial Interface
The USB-to-Serial interface is done by using a CH340G. I have not modified the reference design from the original NodeMCU v3 too much, as it works well, and thus need no changes. I did however make sure that there is a protection diode between the USB 5v line and the VIN line on the PCB. Most of the existing NodeMCU boards does not do this, or when they do have the protection diode, that line is directly connected to the VIN pin. in my view, that is not ideal, and can cause unnecessary damage to your computer’s USB port or NodeMCU board in the event that you power it from an external source, and also use USB power to upload code… Not that it should be done that way anyway, but rather safe than sorry later.
USB-to-Serial Schematic
The two transistors (VT1, and VT2) is used to do very cleverly put the board into programming mode, as well as reset it after flashing, without the end-user having to press any of the flash or reset buttons. This is also part of the reference design on some of the NodeMCU boards. I can not comment if it is standard. I found it useful, so decided to include it as well.
ESP-12E with strapping pins and power supply
The ESP-12E module, as manufactured by AITinker, seems to be quite stable and easy to use. It does however have a couple of caveats, to enable it to function as intended. The strapping pins (discussed later) should be in a certain state at bootup time, and failure to adhere to that will definitely cause a failed boot or wrong startup mode.
GPIO0, GPIO2, EN and RST should be pulled HIGH for a NORMAL boot, while GPIO15 should be pulled LOW. Pulling GPIO0 LOW at boot, will put the board into FLASH mode.
Another change that I made is that I did not break out the raw Analog input pin, as is done on some of the boards ( as a VV pin, or sometimes as an unlabeled, or reserved pin). The Analog input pin on the stock module is designed for around 1.0v input. This is fed from a resistor divider, to effectively scale your 5v input down to valid levels.
ESP-12E and Power Supply Schematic
GPIO16 (D0) is used internally by the ESP-12E to wake the module from deep sleep. This is done by connecting GPIO16 to the reset pin. To wake up the module, GPIO16 is internally pulled LOW, thereby resetting the module. I have decided to add a user-selectable jumper that can be enabled to connect GPIO16 to RESET, that enabling this functionality. It is however to be noted that the jumper must ONLY be set AFTER the relevant deep sleep mode has been enabled in the firmware for the module.
The standard NodeMCU has only a single 3.3v voltage regulator installed. I added a dedicated 5v voltage regulator as well and powered it directly from the VIN pin. This regulator will only function when the device is powered from an external power source, with an upper voltage limit of 15v DC. Protection for the USB port is provided by a diode between VCC_USB and VCC5V.
As I have mentioned at the start of the article, this is a show and tell, of how I solved a particular problem that I had. I do not believe in re-inventing the wheel, but to adapt and improve as and where I see fit, to my own purpose. This project will by no means be unique, or better or worse than other similar devices on the market today. It is however designed to suit my particular needs for my particular project.
The design of the PCB and Schematics was done in EasyEDA, which I believe to be quick and easy to use, as well as Linux friendly. (There does not seem to be many of those around, KiCAD being the exception to that rule. I have however not been too successful in using that before, to no fault of KiCAD at all. I am just not prepared to learn a new EDA CAD package just for the sake of doing it. Time is precious, and I can get everything I need to do done with EasyEDA).
PCB Layout
The PCB is dual-layer 99.06mm x 83.058mm. Six mounting holes are provided. The ESP-12E is placed at the top, roughly in the left-hand corner. As per Espressif design recommendations, no tracks are routed underneath the antenna area. An approximate 15mm x Board width area is also kept clear of any tracks or ground plane(s) to also prevent interference with the RF signal generated by the device. All components are mounted on the top payer of the PCB and are as far as possible grouped together by their function and purpose in the circuit. As the two onboard relay modules will very likely be used to switch mains power, they have also been excluded from the ground plane(s). Cutouts around all possible mains power carrying pads and tracks were also added to prevent tracking.
A DC Power Socket, and USB port, as well as access to the single Analog Input, Enable, Reset Pin and Button and VIN pin is provided on the left-hand side of the PCB. All other IO pins, as well as the six remaining ports on the PCF8574 IO expander, is accessible on the right. Note that GPIO4 and GPIO5 ( D1 and D2 ) were hard-wired as I2C lines. They should thus not be used for any other purpose. All other pins are accessible and broken out, clearly labelled with their GPIO numbers, as well as NodeMCU style Dx numbers. There are also an additional 6 IO pins broken out at the bottom of the ESP-12E module, to provide access to the seldom-used SDCard interface.
PCB Top Layer ( Rendered )
PCB Bottom Layer (Rendered)
3D Render PCB from Left
Manufacturing the PCB
This PCB will be manufactured at PCBWAY. The Gerber files and BOM, as well as all the schematics, will soon be available as a shared project on their website. If you would like to have PCBWAY manufacture one of your own, designs, or even this particular PCB, you need to do the following… 1) Click on this link 2) Create an account if you have not already got one of your own. If you use the link above, you will also instantly receive a $5USD coupon, which you can use on your first or any other order later. (Disclaimer: I will earn a small referral fee from PCBWay. This referral fee will not affect the cost of your order, nor will you pay any part thereof.) 3) Once you have gone to their website, and created an account, or login with your existing account,
4) Click on PCB Instant Quote
5) If you do not have any very special requirements for your PCB, click on Quick-order PCB
6) Click on Add Gerber File, and select your Gerber file(s) from your computer. Most of your PCB details will now be automatically selected, leaving you to only select the solder mask and silk-screen colour, as well as to remove the order number or not. You can of course fine-tune everything exactly as you want as well.
7) You can also select whether you want an SMD stencil, or have the board assembled after manufacturing. Please note that the assembly service, as well as the cost of your components, ARE NOT included in the initial quoted price. ( The quote will update depending on what options you select ).
8) When you are happy with the options that you have selected, you can click on the Save to Cart Button. From here on, you can go to the top of the screen, click on Cart, and make any payment(s) or use any coupons that you have in your account.
Then just sit back and wait for your new PCB to be delivered to your door via the shipping company that you have selected during checkout.
Conclusion of Part 1
This is the end of a very long part 1. We have started to look at the steps involved to get started with designing our own IoT Controller, did some initial software installation, and took a detailed look at the schematics and PCB…
In part 2, we will look at
1) Writing the configuration for ESPHome to control your device 2) Look at Tasmota as an alternative way to control the device 3) Integrating the device into Home Assistant 4) Have a go at writing our own firmware using the Arduino IDE to control the device using MQTT 5) Depending on how long shipping of the components and PCB takes, assembly and testing of the actual device
Thank you for your time. This is a very long article, and I appreciate your interest.
Welcome to the final instalment of my 8 DI Optically Isolated Arduino Shield. Today I will show you some of the assembly pictures, as well as look at the coding to use this shield. I will also provide you with a link to the manufacturing files, in case you want to make your own.
You can order your own version of this board for just $5 USD if you click here
PCBWay makes it quite easy to order prototypes for your PCB’s… Just upload the Gerber files on their website, select your desired options for the PCB and order. The turn-around time is great. I received these boards, ordered together with a stencil for SMD assembly, in exactly 5 days, shipping from China to Thailand 🙂 That is super fast, as it arrived 4 days faster than the components that were ordered locally from Bangkok! Be sure to consider using their services next time you need a PBC made…
Top and bottom layout of completed Shield
Bottom of Shield
Top Layout
Some notes on assembly: The reset switch will seem misplaced, and indeed, it is 🙂 The reason for this is that I could not get any 4 pin tactile switches 🙁 So I had to either leave it unpopulated or use a two-pin tactile switch. As I will be using these shields myself, I decided that although it doesn’t look perfect, the two pin switch will still provide me with the functionality that I want.
On the bottom of the board, you can still see some blobs of flux, as the pictures were taken right after assembly, and have not been cleaned up yet. Some solder joints have also not been cleaned up yet.
The top of the unpopulated PCBThe bottom of the PCB
Testing and Coding
The testing of the board is quite straightforward. I first checked all the power rails with a multimeter to make sure there are no open circuits of shorts. Then I checked connections to all the chips and other components, yes, it takes a while to do that, but rather safe than sorry. After assembly, I repeated this process, making sure that all the components receive the correct power level, and that all switches ( like for addressing and the reset button ) actually do what I intended them to do. The next tests were the individual inputs with the optocouplers. This is done by connecting an input source (between 5.5v and 32v) to each individual input and then physically testing on the pins of the optocoupler in question, for the correct voltage input.
The shield is then powered from 5v and the input test is repeated while checking with a multimeter that the input signal does indeed get transferred by the optocoupler to the PCF8574 chip. I found that with the particular batch of PCF8574 chips that I got, that the IC would only respond reliably with a voltage between 5.5v and 32v. The original design was for 3.0v to 32v. I found that the Optocoupler EL357N seems to be unable to switch itself on at the low current allowed through the resistor divider at the input. This can be fixed by lowering the value of R1, R5, R9, R13, R17, R21, R25, R27 from 4k7 to whatever value you need. Note that that will reduce the top-level input voltage that you can safely use. For my application, however, 5.5v to 24v will be perfect, so I will leave it as is.
The shield is now connected to an Arduino with DuPont Wires, to test the I2C addressing of the PCF8574. The chip address is changed with the 3-way dip switch at SW1. All eight addresses are available. It should be noted that I have used a pull-up configuration on the address lines. That will reverse your logic.. Switching the dip switch on will pull the pin to GND, not to VCC as you would normally expect. Thus as an example, all switches off will give an address 0f 0x3f, while all on will give 0x38.
Coding
You can use the standard Arduino IDE with the Wire.h library to code the shield, or you can use one of the many PCF8574 libraries that are available. I coded my tests with the Embeetle IDE, as it gives me much better control over my code. I will show you a short, interrupt enabled sketch, in Arduino C++ below
#include <Wire.h>
byte _portStatus = 0b00000000;
boolean _readI2C = false;
void MyISR() { // Interrupt service routine
//Serial.println("Interrupt Occured on Pin2");
if (_readI2C != true) {
_readI2C = true;
}
}
void setup() {
// put your setup code here, to run once:
pinMode(2,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2),MyISR,FALLING);
Serial.begin(115200);
Wire.begin();
Wire.beginTransmission(0x20);
Wire.write(0xFF); // set all pins to 1, needed to make them inputs
Wire.endTransmission();
}
void loop() {
// put your main code here, to run repeatedly:
byte _data;
if (_readI2C == true) {
_readI2C = false;
Wire.requestFrom(0x20,1);
if (Wire.available()) {
_data = Wire.read();
}
}
if (_portStatus != _data) {
Serial.print("Port Data Changed : 0xb");
Serial.print(_portStatus,BIN);
Serial.print(" changed to : 0xb");
Serial.println(_data,BIN);
_portStatus = _data;
delay(50);
} else {
_portStatus = _portStatus;
}
}
Conclusion
This turned out to be a very interesting and fun project to do. From designing the circuit to getting it manufactured and hand assembling it myself was a very satisfying experience. I would like to take this opportunity to thank Wendy Wu, from PCBWay‘s Marketing department, for her assistance with the manufacturing of the board. The speed and efficiency with which she handled this project were fantastic.
In part 1 of this article, I introduced my new I2C 8DI Optically Isolated Arduino Shield. Today, I will show you how the full design, as well as the circuit diagram.
This shield was designed to allow an input of between 3.0v and 32.0v to be applied to the various inputs. This will be completely galvanic isolated from the rest of the circuitry on the shield, and thus also from your Arduino, or other micro-controller if you choose to use another one 🙂 Yes, This is possible, as long as you power the shield with 3.0v to 5.0v. You will also have to connect your I2C bus to the SCL and SDA Lines marked on the shield.
Please note that, if you decide to do that, the other Arduino specific pins, as broken out on the shield headers, will have no connections to anything else. :), an obvious fact, but it should be stated, it seems 🙂
The Circuit Diagram
Circuit Diagram, Page 1 of 2
As you can see on page 1, each optically isolated input has a voltage divider resistor network in front of the Opto Coupler. This resistor network also limits the current that can be used by the infrared LED inside of the EL357N chip to 5mA at 32v DC. ( The chip can accept up to 50mA, but it should not be driven so hard 🙂 ) A diode provides reverse-polarity protection to each input as well.
Another voltage divider on the output side limits the current to the PCF8574 Chip. This can also only source or sink 25mA per IO.
Note that there is NO common ground between the input and output sides of this circuit. That means that you have to provide another ground, usually from your external device… This ensures that galvanic isolation between the two circuits is maintained.
Circuit Diagram, Page 2 of 2
On page 2, we can see the various net connections to the connectors, PCF8574 chip, as well as various jumper headers, to select the interrupt pin [H3] ( For Arduino, D2 or D3, other micro-controllers: you are free to select any GPIO to connect to the D2 or D3 header pin ).
You can also select to enable or disable the pull-up resistors on the I2C bus, by shorting the jumper on [H2]. This is usually only needed on the first shield, or in other words, you need one pair of pullup resistors per i2c bus, not one pair per device!
Device addressing is selected with SW1. 8 addresses are available but switching this switch as per the table on the back of the PCB. It is worth mentioning that depending on the version of the PCF8574 chip that is on the shield, there are 8 addresses available, with 0x20h to 0x27h being common on the PCF8574, and 0x38h to 0x3fh being used on the PCF8574A/T version.
Typical Connection
Typical connection of input. Note that there are no common ground between the two devices
The PCB
The shield is built on a double-sided PCB or 71.12mm x 61.72mm. This is only slightly bigger than the standard Arduino Uno. All resistors, capacitors and LED’s are of 0805 sizes. ( smaller than that is a bit hard on my eyes, although it can be done, just takes longer 🙂 ). A ground plane is provided on both sides of the PCB.
PCB design file
All Arduino pins are broken out on a double row of 2.54mm headers. This allows you to use either the outside row with stack-able male-female headers, like on most shields, or you can use dedicated male and female headers, in a zig-zag pattern to stack the shields.
I have done the same with the ICSP header, as on many other commercially available shields, there is only a single female 3×2 header on the bottom, making it quite annoying to use on another shield.
PCB Topside
PCB Bottom side
Manufacturing
This shield is currently being manufactured by PCBWay.
PCBWay provides a rapid and affordable PCB manufacturing service. They also provide PCB assembly, and even a 3D printing and CNC service. This can really help to bring new electronic prototypes to market quickly, as PCBWay can provide you with a complete turn-key solution to bring your product to market. The process to order a PCB is also completely automated, and you can easily do it online in a few minutes. Just upload your completed Gerber Files onto their system via their web interface, and you will get a quote in seconds. You can then pay and place your order immediately from the same page. They also have various shipping methods available, That really helps, as no one wants to pay for excessively expensive shipping, or be stuck having to use only one company.
The design files for this project will be made available as a project on the PCBWay website soon after the release of part 3, which will cover the assemble, testing and programming of the shield.
All of us Makers like to tinker with stuff, and in this process, we may find ourselves thinking about how to connect device A to my Arduino… Device A may operate at a different voltage from the Arduino, and may thus damage it badly….
Many different solutions exist to do this, but, many of them, like relays, can be quite bulky, increasing the overall size of your project, as well as putting bigger demands onto your power supply unit.
Having worked in the Industrial Automation sector for a few years, I remember that we used to have dedicated hardware to protect our sensitive controllers from the harsh outside signals that we needed to monitor. These devices were called isolators, and today I will show you how to construct your own version of this essential device.
But some theory is needed first…
What does it mean to isolate a signal? In the electronics world, you might have seen that you usually have to use a common ground between all your devices to make them work together properly. While this is definitely true, let us look at another example…
Let us say you have some device, that will send you a voltage signal when it switches on, and another voltage signal when it is switched off. This device runs on 24 volts, so some of the more informed of us will immediately say you need a level converter, meaning a device that changes the 24v signal into a 5v signal… Others will try to use a relay to convert the signal ( A relay is also a type of isolation device ). A much more elegant way of doing this will be by using an Optic Isolator chip.
A simple Optic Isolator Chip
This chip provides complete isolation between your device and the Arduino or other microprocessor. It does that by using infrared light to transmit the signal. Light, as we all know, does not conduct electricity 🙂
Whereas a relay will only give you a on or an off state, the Opto-coupler or Optic Isolator can also do linear current transfer, meaning that the more IR light it transmits, the more current the photo-transistor will allow to pass as well.
A good tutorial on Opto-Couplers can be found here
Opto Isolator Circuit
In my circuit, I made use of the following circuit…
Two Optic Isolator Level converter Circuits
As we can see in the two circuits above, there is no common ground between the input and output sides of the circuit. This is ideal, as noise and other undesirable signals will not be transferred from one circuit to the other. It also allows you to use a very high input voltage, at a frequency of up to 2kHz.
I have also decided to combine this with the PCF8574 I2C Port Extender. That way, I can cascade up to 64 inputs on the I2C bus. In a later version, I will also do an Opto-Isolated Output module.
The Shield is only slightly bigger than the standard Arduino Uno, and all Arduino pins are broken out on headers. It is important to remember that A4 and A5 should not be used for any other purpose (They provide access to the I2C bus). Likewise, the interrupt pin of the PCF8574 can be connected to either D2 or D3 with a jumper, or left disconnected by completely removing the jumper. Device addressing can be set with the 3-way DIP switch on the board.
8 DI Optically Isolated I2C Arduino Shield
This device is currently being manufactured. In Part 2 of this article, I will show you the completed PCB, as well as give you access to the Gerber design files if you want to manufacture your own. I will also make a limited amount of these boards available for sale from my website ( this site ) as well as from https://www.facebook.com/makeriot2020