Hardware Evaluation of a Custom Programmable Wi-Fi Controller: The WiCardJune 01, 2018 by M. Mahdi K. Kanan
This article explores the schematic design and basic features of a smart programmable wireless controller module I designed: the WiCard.
This article will explore the design elements, challenges, and features of a custom programmable Wi-Fi controller. Here's a guided tour to the WiCard, in the words of its designer.
WiCard is a smart programmable wireless controller module that I created to support a variety of features. While the module can be programmed with JTAG, I designed it to receive over the air (OTA) updates from a local computer or a central server. The WiCard module can be configured with an IDE that resembles Visual Basic and allows me to make "control boxes" for the module with a simple drag-and-drop interface. This article explores the schematic design and basic features of my module.
WiCard connects to the user control panel or application via Wi-Fi, allowing system designers to access its features. I designed the module as to not need a JTAG programmer after initial programming. Instead, WiCard modules can be programmed offline with the module’s hot spot, or online with a WiCard.Net account. The Integrated Development Environment (IDE) for this module resembles Visual Basic, which I am most comfortable with, and the GUI and code generation can be accessed at the WiCard Simulator.
In the simulator, I can make a control box for the module, and have access to the module control box from the module hotspot (via the module’s Wi-Fi access point), the module IP (via port forwarding), and the WiCard.Net account panel.
I created the module in such a way that it updates via WiCard.Net servers automatically and assembly requires a breadboard, three integrated circuits, and an assortment of passive components.
|ATMega8A||16 MHz microcontroller from AVR family (PCI Core)||Datasheet|
|ESP8266EX||High speed Wi-Fi controller and processor with Xtensa core||Datasheet|
|W25Q32F||32 Megabit flash memory to save firmware||Datasheet|
The Wi-Fi core controls Wi-Fi transactions, reads the flash memory, and executes my programs. The PCI core controls peripheral components. Initial programming takes places with standard JTAG programmers. For simplicity sake, I designed all subsequent firmware upgrades to take place wirelessly via WiCard's over-the-air (OTA) upgrade process.
The Xtensa core uses an external 26 MHz crystal and the AVR core has an internally configured oscillator.
WiCard Module and Pin Configuration
The WiCard module has 30 pins, including two 3.3 V VCCs, 2 GNDs, 22 GPIOs, 3 status LEDs, and one reserved pin for future features. The pins are divided into two 15-pin sides. I can put this module at the center of a breadboard and use it for my different experiments.
The module has a 50Ω antenna located at the bottom of the PCB.
The figure below provides an overview of my pin configuration for the WiCard module.
About the Schematic
My goal when designing the WiCard module was for it to be as straightforward as possible. In the end, I made it so the ESP8266EX connects to the W25Q32 and ATMega8A, and the ATMega8A microcontroller connects to the pin headers.
WiCard module schematic diagram. Click to enlarge.
The resistor and capacitor values used in my schematic have been tested, and so I recommend these values. However, I've designed it so changes to component values and footprints can be made for custom PCB layout or to simplify the production process.
C5 and L1 form a matching network for the antenna and will vary from layout to layout. Based on the chip's stated impedance of (39+6j)Ω, a capacitive value of C5=0.7 pF and an inductive value of L1=1 nH provide a theoretical VSWR of 1:1 (0% reflected loss). A single 5-10pF series capacitor (inductor omitted entirely), provides a VSWR of 1.34:1 (~2% reflected loss). For the purpose of my initial experimentation, I made sure that the single capacitor sufficiently matched the impedance between the antenna and the chip which allowed 98% of the power from the chip to be transferred to the antenna.
In my production environment, C5 and L1 were determined experimentally with a network analyzer and applied to all identical boards.
I assembled the PCB shown below with 0603-sized components. For production, I used 0402-sized 12 kΩ resistors so that decoupling capacitors C8, C9, C10, and C11 could be placed closer to the ICs.
The onboard antenna I chose is a Meandered Inverted-F Antenna (MIFA) (PDF). I chose this antenna because it has been designed for 2.4 GHz signals with 150-250 MHz bandwidth range on 20-60 mils (0.5-1.6 mm) thick, two-sided PCBs. When I tested the working distance of the onboard antenna of this module, I reached 170 ft (50 m).
This image shows the overall layout of the topside of the WiCard Module.
Firmware and Flash Programming
After I assembled the parts on the PCB, I programmed the initial firmware onto both of the cores, making sure to program the ESP8266EX before the ATMega8A.
Programming the ESP8266EX
I followed the standard steps of programming the ESP8266EX, which is with a USB-to-UART converter and the ESP Flash Download Tool, and used the following connections:
|Pin / Test Point||Connect To|
|TP1||ESP Tx (COM port RX)|
|TP2||ESP Rx (COM port TX)|
|TP3||220Ω Pull Down (to Ground)|
|TP4||220Ω Pull Up Resistor (to +3.3V)|
There are two approaches for programming the firmware on the module: the WiCard-specific programmer I created or a standard USB-to-UART programmer, such as the FT232RL FTDI USB to TTL Serial Adapter.
This close up shows the test point connections for the initial programming of the WiCard module.
The ESP Flash Download Tool Screenshot shows my suggested settings for programming the chip.
I've provided all necessary files in the .zip at the end of this article, and also made them accessible from the WiCard's trial page.
The firmware for ESP8266EX includes 6 files:
- ESP8266EX_0x000000: Must be copied at address 0x0 in the 32Mbit flash memory. This file includes some initial system settings.
- ESP8266EX_0x001000: Must be copied at address 0x1000 in the 32Mbit flash memory. This file includes the firmware program data.
- ESP8266EX_0x0FE000: Must be copied at address 0xfe000 in the 32Mbit flash memory. This is a 4KB blank file for the system settings.
- ESP8266EX_0x300000: should be copied at address 0x300000 in the 32Mbit flash memory. This file includes internal webpage data.
- ESP8266EX_0x3FC000: should be copied at address 0x3fc000 in the 32Mbit flash memory. This file includes some initial wireless/WiFi settings.
- ESP8266EX_0x3FE000: should be copied at address 0x3fe000 in the 32Mbit flash memory. This is a blank file for the system settings.
Programming the ATMega8A
When it came time to program the ATMega8A, I knew I could use either an SPI programmer or a high voltage programmer (parallel programming mode). For SPI mode, I set the pins according to the following table:
I did not connect the other pins. I set the “Fuse High Byte” to 0xD8, the “Fuse Low Byte” to 0xA4, and the “Lock Bits Byte” to 0xFC — all necessary settings for the SPI to program correctly. SPI programming requires pulling PIN A10 up (e.g., 10 kΩ) during use of the module.
Programming the module in high-voltage mode was different from programming in SPI mode. For high voltage mode (parallel programming mode), I set the pins as shown below:
Again, I did not connect the other pins. I discovered that C7, C8, C9, C10 somehow interfere with the high voltage programmer and need to be installed after the initial flash programming process.
I set the “Fuse High Byte” to 0x78, the “Fuse Low Byte” to 0xA4, and the “Lock Bits Byte” to 0xFC. There was no need to use a pull-up resistor for A10—this pin worked as a normal input.
I designed the WiCard in such a way that programming the ATMega8A in the high voltage mode allows both the registration of new modules on the WiCard.Net servers and server access. Or, if users decide to go the route of SPI programming mode, I made it so upgrading modules over the air and using all of the trial features is possible—except anything regarding pin A10, such as PCInt 7.
It was important to me to make sure the WiCard module was suitable for industrial wireless control, IoT devices, home appliances, home automation, security systems, smart outlets and lights, infrared remote controllers, and sensor networks. This enables users to make products controllable by adding this module to existing circuits, thereby controlling a variety of devices via a computer or smartphone.
Programming and using this module requires only a stable 3.3 V power supply and a Wi-Fi compatible laptop, PC, or phone. The WiCard IDE software is still a work in progress. For now, if you're interested in giving the module a try, you can use the simulator page as the module compiler.
On that simulator page, there’s a compiler, a control box maker with some visual tools, and a WiCard simulator. A graphical user interface allows for programming without learning the underlying language—simply drag the items into the control box and edit the pin by double-clicking on the item.
My programs can be compiled in debug mode, which allows reprogramming of the module, and release mode, which requires a password to unlock and program the module. I can also use the module as a product controller (usually for public products). For a product controller, I simply need to compile in release mode so users won’t be able to edit or erase any of my other existing programs.
Here are the programming options:
- Use a WiCard.Net account
- Upload the program via the module IP (port forwarding)
- Upload the program via the router IP (offline)
- Upload the program via IP address 192.168.4.1 (using the module Wi-Fi hotspot to create an ad-hoc network)
- Export the program file and upload it to the module via the module internally hosted server page
After uploading the program, the module will execute and run the program automatically, and the control box is available in both the WiCard.Net account panel and the module's internal page. Registering the module and creating an account on the WiCard.Net server is not necessary for using and programming the module. The account simply provides server access and some extra features. The free version of the module will not connect to the server unless the firmware update button gets clicked on the module internal page, which causes it to check for the latest free software revision to update. If you decide to connect to the server, the default password is "0123456789."
The schematic for my example project is simple. Pins A1 and B15 have been connected to the 3.3 V VCC, and pins A2 and B14 have been connected to GND. Pin A3 (port bit 0) has been connected to an LED with a 470 Ω series resistor.
The compiler will automatically generate the source code. The video below shows the WiCard in action.
Overall, my team and I created the WiCard in an effort to make products smart, controllable, and Wi-Fi compatible. I believe it's easy for beginners to use while also providing a wide range of features for professional system designers. You don't need to be a programmer to know how to write and upload a program, because the user-friendly GUI will generate the required code.