final project -- weekly assignments -- about me -- fab academy
Week 05: Electronics Design
Phase 0: Making Tools
I'm still working on getting KiCad into my normal, everyday workflow, so one step was to work on getting more components into its library. Ferdi had suggested making a complete KiCad Fablab Inventory two weeks ago, and I was a bit reluctant - I believe any new components should be complete, including 3D models and testing. I'm quick putting in a footprint, even making schematic symbols, but the toolchain for getting 3D models into KiCad is still a massive PITA. Now, Ferdi offered to do those as he has the toolchain up and running, and Daniel offered to throw in his own footprints and symbols, so we should get that thing done a lot better than I alone could hope to. A new project was born - The Fablab Inventory KiCad Library.
Phase 1: The "Hello World" Board
I had started doing the Hello World board during Week 03 to do some additional testing with KiCad. Also, Daniel and me had a rather mad idea to do something funny and push the little ATtiny to (or, most likely, way over) its limits. That idea changed a bit when we found out that we can use other microcontrollers, too. After playing around with them, I don't particularly like AVRs, and the "imported" electronics I want to use for my final project are PIC based. So, the mad idea moved on to a different platform, leaving the schematic of the Hello World board orphaned:
It couldn't stay that way, of course, so I completed it with the minimum the assignment said: A button (or two) and an LED (or two), and threw together a layout:
It runs Neil's demo software, so... going on to the fun part. I dropped the project files here on the way in case anyone is interested.
Phase 2: The Fabboy
The Idea
The utterly mad idea two weeks ago had been to not only add one LED to the board, but a whole lot of them - a small and cheap OLED display. And a few buttons. And software for a game, like a primitive version of Tetris. My "everyday" 8 Bit PIC is a bit faster than the original Gameboy, but only has half the memory (roughly 4 kB). That should work out for Tetris, and it should work out for Cat Invaders, both of which are available in a heap of open source projects. Porting one of those to the PIC can't be that bad, can it? (Yes, it can. But I don't care!) Embedded Programming will be another assignment...
From Zero To Schematic
Schematics don't grow from thin air, so the first step was to create one. As this project will be a rather simplistic "some stuff around a microcontroller"-project I started off by collecting what stuff I wanted to have and where it should be connected:
- The programming / debugging port. It connects to pins RB6, RB7 and reset. Nothing fancy, just a five or six pin connector. If possible, I don't want to use those pins otherwise.
- The OLED Display. It is connected via I2C, and given that I have absolutely no interest in doing that by software, it should be connected to a hardware I2C port. The PIC has two of those, with connections to RB1 / RB2 and RC3 / RC4. I'll have to choose one pair later.
- A little piezo speaker. To make programming easy, it should be connected to a PWM output, and there is such a bunch of those that I won't list all of them here.
- A cable connection to play against other users. A UART might be a good start for that. There are two on this PIC, one of which is conveniently sharing its pins with the programming / debugging port which needs a connector anyway. I'll use that if I ever get around to programming any multiplayer.
- A few LEDs for creating an ambience and annoying the player. Having them on one or more PWM pins might be nice to create effects. There are a whole bunch of those, so we'll see later.
- A bunch of buttons. The original Gameboy has eight, six of which are used in most games. As we have just enough buttons left at the lab to do six... I will do six. They can be put on any I/O pin, so not much to think about here. Only Port B has internal pullups, though, and RB6 / RB7 are blocked by the debugging port, so...
The buttons were the first thing to be fixed in the end, as with six buttons and six pins-with-pullups left, they were an easy fit (and less layout work). With RB1 / RB2 used for buttons, the I2C for the display ends up on RC3 / RC4, and only a few PWM pins remain free. I used RC2, so the schematic is more or less sorted:
There's a power-LED already added, which might help when debugging this thing. And brings up the next problem: How do I power my toy? A battery might be cool, but adding a rechargeable one and not killing it adds to complexity and workload, I'll leave that out for now. I could plug a power cable into the debugging port, but that blocks out any other use of this port - like multiplayer. So, again, no. In the end, I added a micro USB port, not doing any USB, but just drawing the few milliamps of power I need. It's not OK with the standard, but it should work.
There is not much more to this schematic. The I2C needed its pullups, and I put some capacitors to the PIC's as well as the display's power supply. And that's it. With 5V from USB, our power supply is set and the PIC doesn't really need a crystal, so I'm leaving that out.
Drawing Up The Board
For a lot of simple games like Tetris, a landscape screen is a rather stupid idea, especially one as wide as the small OLEDs we have. So, I decided to put it in as a portrait display, which looks odd, but should work. Also, with a display that small the whole thing shouldn't really be big. At the same time, I really like the general layout of the original Game Boy Advance, so I shamelessly copied it (it wasn't new for Nintendo, either...). The "ambience" LEDs ended up around the display.
With the display dead center on the board and buttons on both sides of it there is little place left for the microcontroller - It could either go on the backside, or below the display. I put it on the backside, in the middle... so the I2C connections get really short. It's not really important, though.
Next, I moved around parts trying to get the connections as un-chaotic as possible. Since I don't care (yet) about which button ends up being which function, they are ordered (on the board) by their connections. It's six identical buttons, first time I start caring about which one is which is when writing the software for them.
Then, I drew an outline for the board - Just so it looks cool, there will be a lot of empty space on this one. With the board edges defined, I placed the USB and debug connectors, then sprinkled the board with the few capacitors and resistors it needs.
To be able to mill it, I had to adhere to some design rules, of course - Most of which are more or less taken from experience with the PCB mill. I set the values in KiCad to a minimal track width of 0.25mm, with a clearence of (also) 0.25mm. Both values are conservative to what the mill can do when taken to its limits, as I had no intention of driving stuff to its limits (and having to deal with failures). KiCad will automatically make you adhere to the rules you set during routing, so usually things will turn out OK. It's sensible to also run a complete DRC before finally milling the board, of course, to catch any stray problems:
The six unconnected nets it found are acceptable in this special case, as they are at the buttons, which don't really need the missing connections. So, while they can't be ignored by default, I ignored them in this case, and made the board.
The design files are available, of course. I made the board, and did a first bit of software for this board during Datasheet reading week.
If you want to build your own, you will need:
Reference | Amount | Type |
---|---|---|
IC1 | 1 | PIC18F26K22-I/SO |
DS1 | 1 | 0.96" OLED Display |
SP1 | 1 | Speaker PKM13EPYH4002-B0 |
P1 | 1 | SMD Pinheader 6-pin horizontal |
P2 | 1 | Micro-USB jack, ZX62D-B-5PA8 |
SW1, SW2, SW3, SW4, SW5, SW6 | 6 | Tactile Switch MC32882 |
D7, D8, D9 | 3 | Green 0603 LED |
D1, D2, D3, D4, D5, D6 | 6 | Red 0603 LED |
R1, R2, R3, R6 | 4 | Resistor 0603 680Ω |
R4 | 1 | Resistor 0603 18Ω |
R5 | 1 | Resistor 0603 2.2kΩ |
R7, R8 | 2 | Resistor 0603 4.7kΩ |
C1, C3, C5 | 3 | Ceramic Capacitor 0603 1µF |
C2 | 1 | Ceramic Capacitor 0603 10µF |
C4, C6 | 2 | Ceramic Capacitor 0603 100nF |
final project -- weekly assignments -- about me -- fab academy