Prototype: Web platform
This is an old version, see the latest version on the documentation wiki.
The Dangerous Prototypes web platform is a tiny server designed for networked hacks where a full PC is inconvenient. There’s lots of interesting projects that bridge the internet to microcontrollers, but most of them have a PC in the middle to handle network stuff. This business card size internet appliance can connect to web services, control physical objects from a browser interface, or email sensor status reports; no PC intermediary required!
This isn’t our first small server. Ian designed a popular web server on a business card featured at Hack a Day. The new web platform is also in the profile of a business card, but everything else is kicked up a notch. The microcontroller is a fast dsPIC33 (80MHz/40MIPS) with twice as much program space, DMA, and hardware math assistance. There’s also a simple USB connection for firmware updates and communication with a PC.
This article introduces the hardware. We demonstrate it with an small web server that controls I/O pins and accepts new web page uploads through a web browser.
The Web Platform is available as a kit for $35, including worldwide shipping. Seeed Studio will assemble yours for $5 more.
A dsPIC33FJ128GP204 3.3volt microcontroller (IC1) provides a lot of muscle to this tiny web server. dsPICs run up to 80MHz/40MIPs, and have some advanced features like DMA and hardware math assistance. The chip we used has 128Kbytes of program space, twice the storage of the 24F PIC in the Bus Pirate.
The dsPIC33- series also has peripheral pin select, a feature that allows custom pin assignments for the various hardware modules. This feature makes the simple, clean PCB layout possible. We considered using a 32bit PIC32, but these chips lack peripheral pin select and some key software support like an open source bootloader.
The PIC requires a 0.1uF bypass capacitor on each power pin (C2,3,4), and a 10uF capacitor (C31) for an internal 2.5volt regulator that powers the core. PICs are programmed through a five pin ICSP header (ICSP). A 2K pull-up resistor (R20) to the MCLR pin enables the PIC, a button (S1) temporarily grounds MCLR to cause a reset.
ENC28J60 network MAC & PHY
A 25MHz external crystal (Q1) and two 27pF capacitors (C22,C23) provide the clock source. Like the PIC, the ENC28J60 has an internal 2.5volt regulator that requires a 10uF capacitor (C32). Each power pin also gets a 0.1uF decoupling capacitor (C5-8).
R21 is a bias resistor for the ethernet PHY. The value depends on the ENC28J60 revision you’re using, current chips require a 2.32K 1% resistor. The PHY also requires a simple termination circuit (R10-13, C9-10, L1).
Pinouts are inconsistent among ethernet jacks. We used a jack (J3) with integrated magnetic provided by Seeed Studio. Verify that your jack has the same pinout, or modify the PCB to fit a jack available to you.
The EEPROM pins are brought to a header (EP) so it can be dumped with an external programmer like the Bus Pirate.A 0.1uF capacitor (C12) decouples the chip’s power supply. Hold and write protect are tied high to permanently disable these features.
A microSD card provides a massive amount of removable storage that can be used raw, or with a PC-readable FAT file system. The latest Microchip web server demos can read files directly from a FAT-formatted SD card.
SD card holders are another part with really inconsistent footprints. We used a holder provided by Seeed Studio. Make sure you can get a similar holder, or modify the PCB to fit one you can find. We always use a 0.1uF capacitor (C11) on SD card supply pin, but it’s probably not necessary because the cards are decoupled internally.
FTDI 232R USB->serial chip
The Web Platform has a serial port-based bootloader to flash new firmware without a programmer. Serial ports are dead simple, but they’re getting antiquated and the connectors are huge by modern standards. An FTDI 232R (IC4) provides a USB->serial interface for loading new firmware in bootloader mode, and for simple USB connectivity from user programs.
The FTDI chip is powered by the USB supply. A ferrite bead (L2) and 10uF capacitor (C33) reduce electrical noise, and the supply pin gets a 0.1uF bypass capacitor (C13). A 0.1uF capacitor (C14) is also required for the internal 3.3volt regulator. A single LED indicates the connection status and activity (R7, USB).
The FTDI232R has a separate supply pin for the I/O pins. While the chip runs from the 5volt USB supply, the I/O pins operate from the voltage connected to the VCCIO pin. We connected the VCCIO pin to the internal 3.3volt regulator so the chip interfaces the PIC at 3.3volts. We decoupled the VCCIO pin (C15), though the datasheet doesn’t explicitly specify this.
The chip is only powered when a USB cable is connected, and the chip can get hit with 3.3volts from the PIC when it’s powered down. A letter to FTDI tech support confirmed that this scenario is acceptable. However, we’re still a bit concerned it might be a weak point in the design. Out of an abundance of caution, our code only activates the UART transmitter after a value is received from the FTDI chip (indicating an attached PC). We recommend you do the same.
Auxiliary I/O pins and LEDs
We felt a major shortcoming of our previous mini-servers was the lack of enough I/O pins and LEDs. This design has a 10 pin I/O connector with 8 data pins, 3.3volts, and ground. All 8 data pins are 5volt tolerant, and all but RA9 (pin 1) can be assigned to hardware modules like SPI, UARTs, PWMs, counters, etc. using peripheral pin select. Be cautious with external connections because the dsPIC outputs are rated for 4mA maximum sink and source.
The PWR LED is hardwired to the 3.3volt supply to indicate that the circuit is powered. ACT and LNK display the ethernet link and activity status from the ENC28J60. Three LEDs are available for for any purpose: LD1, LD2, and SD (not shown). LD2 shares a connection with pin 1 of the I/O header. Each LED has a 1K1 current limiting resistor (R1-3).
The circuit requires a fairly hefty 3.3volt power supply to cover the needs of the ENC28J60. We used a large low-dropout regulator (VR1) that can supply 1amp+. The regulator has a 0.1uF input capacitor (C1) and a 10uF output capacitor (C30).
5volts is the ideal supply input. Higher voltages will work, but they also increase the amount of heat that the regular must dissipate. The power supply jack (J1) mates with a common 2.1mm DC barrel connector, the center tab is positive.
The PCB is double sided, but most of the action is on the top layer. Hardware module pin assignment makes all the routing clean and straightforward. The bottom layer is primarily a power connection to all the chips, and a large ground plain. We had our PCBs made with Seeed Studio’s Fusion PCB service (formerly propaganda). You can buy the extras PCBs from our order in the Seeed Studio store.
Click for a full size placement image [PNG]. Most parts are surface mount, be sure to use flux and have solder wick handy to clean up any bridges. Our strategy is to start with the ICs (IC1-4), then attach larger surface mount components like S1, Q1, Q2, VR1, and the uSD card holder. After the major SMDs are attached, we start adding passive components like resistors, capacitors, and ferrite beads. Finally, we solder the through-hole parts like J3 and the headers.
|C1-15||0.1uF capacitor (0805)||15|
|C20-23||27pf capacitor (0805)||4|
|C30-33||10uF capacitor (SMC A)||4|
|L1,L2||200mA+ ferrite bead (0805)||2|
|Q1||25Mhz crystal (HC49U)||1|
|Q2||32.768khz crystal (SMD)||1|
|R1-7||1,100 ohm resistor (0805)||6|
|R10-13||49.9 ohm 1% resistor (0805)||4|
|R20||2,000 ohm resistor (0805)||1|
|R21||2,320 ohm 1% resistor (0805)||1|
|VR1||3.3volt regulator (D2PAK/TO-263)||1|
|S1||Tact switch (DTSM-6)||1|
|J1||2.1mm power jack (SMD)||1|
|J2||MINIB USB jack (SMD)||1|
|J3||HR911105A ethernet jack||1|
|USD||Seeed Studio microSD holder (SMD)||1|
|EP||0.1” pin header (03×2)||1|
|ICSP||0.1” pin header (05×1)||1|
|I/O||0.1” pin header (05×2)||1|
In this initial demonstration we’ll introduce the bootloader firmware and a simple network function test with HTTP server. Over the next few weeks we’ll post shorter how-tos that demonstrate other features and uses for the web platform.
We ported the open source ds30 Loader bootloader to the web platform so it can be programmed through the USB connection; no PIC programmer required. The ds30 Loader project has serial bootloader firmware for most PICs, and bootloader software for most computer operating systems. The bootloader is programmed into the chip once with a PIC programmer like an ICD or PICKIT, then future updates can be done over the USB port.
The bootloader resides in the uppermost page of the PIC program memory. It activates immediately after power on and waits for a commands entering the UART connected to the FTDI USB->serial converter. The bootloader passes control to the main firmware if it doesn’t detect an update request after three seconds.
To use the bootloader:
- Power up the web platform.
- Attach a USB cable from a computer to the web platform.
- Start the bootloader client software.
- Configure the bootloader to communicate with a PIC 33FJ128GP204 at 115200bps on the appropriate serial port for your system. See the image above.
- Press the reset button on the web platform. Next, click download on the bootloader software within 3.5seconds. Always follow this order or the bootloader may be damaged. The new firmware will be loaded into the PIC.
- The bootloader will automatically pass control to the main program when the upload completes.
If the client warns you that the bootloader will be overwritten, ALWAYS CANCEL. If the bootloader is overwritten you’ll need to program it into the chip again with a PIC programmer.
Export firmware for the bootloader
Update: ds30 Loader author Mikael Gustafsson let us know that exporting the firmware isn’t required. You can bootload the .HEX file created by MPLAB directly. This method also works.
To use firmware compiled in MPLAB with the bootloader, export it with the end address set to 0x153fe. The bootloader resides in the page starting at 0×15400, and the client will refuse to upload new firmware that overwrites the bootloader.
Network test and HTTP server
Our first firmware example is a simple network function test with an HTTP server. Over the next few weeks we’ll post shorter how-tos that demonstrate other features and uses for the web platform. This demonstration verifies that the network, EEPROM, and USB->serial connection are functioning correctly.
Microchip’s ‘free’ TCP/IP stack provides all the network functions we need to exist on an ethernet network and work with internet resources. The stack is open source and free-as-in-beer, but the Microchip license prohibits distribution. Due to licensing issues, we compiled firmware and our original source code in the project Google Code SVN. If you want to compile the firmware yourself, you’ll need to download the Microchip TCPIP stack and follow the instructions in the source files.
A compiled version of the network function test is included in the project archive. Program it into the PIC via the bootload procedure described above.
DHCP and IP announce
The demo includes a Dynamic Host Configuration Protocol client that automatically configures the network settings using the DHCP server on your local network. The vast majority of networks and routers support DHCP.
Ping the web platform at the IP address shown in the broadcast packet to check if the web platform is alive on your network. The dsPiC is really fast, it has sub-millisecond response times on our network.
Any character received through the FTDI USB->serial connection is echoed back. Use a serial terminal to verify that the UART and FTDI232R function correctly. The USB LED should blink.
EEPROM-based web server
The demo includes Microchip’s HTTP web server with “out of the box” ability to read and control pins on the IO header from a web page. Web pages are uploaded with a web browser and stored in the EEPROM.
Open the server’s IP address with a web browser. If there’s no existing pages in the EEPROM, you’ll be redirected to the website upload page (http://192.168.1.129/mpfsupload, for example). Upload the demo website from the Microchip TCPIP stack (Microchip Solutions\TCPIP Demo APP\MPFSIMG2.bin). We’ve included our own, much simpler demo if the Microchip image isn’t available.
Navigate to /mpfsupload again at any time to upload a new website image.
After the image is uploaded, navigate to the base web address (http://192.168.1.129/) and view the demo page. You may need to control-refresh to clear your browser’s cache.
Microchip’s demo page is a super easy way to control outputs and read digital sensors from a web browser. The demo site uses AJAX to control LEDs and the I/O header pins. We mapped the LEDs to LD1, LD2 (IO1), and IO2-4 on the web platform I/O header. The buttons are mapped to I/O header pins 5-8.
Taking it further
Over the next few week’s we’ll release other firmware examples for the web platform, including more demos with the Microchip TCPIP stack such as an SD card-based web server, and custom demos like a port of the #twatch firmware. Feel free to request specific demos in the comments or the web platform forum.
The web platform is available as a kit for $35, including worldwide shipping. For an extra $5 Seeed Studio will assemble it for you.
Thank you for your support! Your purchase of our open source hardware keeps the new projects rolling.
ResourcesPrototypes, web platforms and tagged networking, PIC, web server.