Introduction to the PiMagic
Around 18 months ago, not long after getting my hands on the Raspberry Pi, I concluded that whilst this is a great, low cost computer which is great for educational needs and has the right level of power for a lot of my projects it’s rather lacking in the I/O department. Fundamental issues are:
- 3.3V logic at the I/O pins rather than 5V
- No protection of the I/O pins – for educational use there will for sure be many dead-Pi’s
- No analogue inputs
- Generating PWM or using the one-wire protocol needs to be software driven (bit-banged)
Now this could be easily remedied with the addition of one of the commonplace add-on cards e.g. the Gertboard, but for me this has too much functionality, is too configurable (read complicated), is physically bulky and is expensive (relatively). An commonplace alternative solution is to connect an Arduino, but this is still a little bulky for some of my projects and uses up a valuable USB port (admittedly not such an issue on the new B+).
At the time therefore I set out to design what I now call the PiMagic.
I decided that an Arduino clone was the way to go. Not only would the hardware be cheap and the part-count would be low, but also the board would be compatible with the plethora of shields and existing projects out there. All these shields and existing projects can now be expanded with the power of Raspberry Pi!
Having ruled out the use of USB, I decided that using the onboard UART was easier than SPI or I2C giving most flexibility with software and operating systems. In addition, one GPIO line is used also to provide a reset pulse allowing reprogramming of the Arduino software in-situ (if needed).
The block diagram shows that a level-shifter circuit is needed to convert between the 3.3V logic of the Raspberry Pi and the 5V logic of the Arduino world. A standard ATMEGA 328P is used (with Arduino bootloader for reprogramming over the UART connection) and running Firmata application software by default. The board uses a 16MHz resonator (rather than a crystal to keep the price low) and the footprint will be that of standard Arduino headers to allow plugging in of additional, standard shields.
Finally, a 250mA polyfuse is added in the 5V line, since a known issue with early Raspberry Pi’s is burning of PCB tracks through pulling too much current on the 5V line.
Overall with the fuse, the 328P and the polyfuse it should be pretty difficult to accidentally damage the Raspberry Pi when experimenting via the PiMagic board.
First Prototype / Proof of Concept
The first prototype was build on a prototyping board using a AdaFruit level shifter which worked well. The design was then refined and transferred onto a shield as proof of concept… see below…
The full schematic for the PiMagic is shown below (click to zoom)…
I first presented the shield briefly at Wuthering Bytes 2013 – here’s the slides which give an overview…
First PCB (with error)
After laying out the PCB our good friends at Ragworm etched the prototype board…
It should be noted that there is an error on this board, which is reflected in the uploaded source files. The transistors Q1 and Q2 have the legends upside-down so please note this – if assembling a Rev01b board the flats of the transistors should go at the top and the centre leg needs to be re-formed with small pliers (fixing this is on the to-do list below).
You’ll notice that with a little careful placement I was able to free up enough board real estate to allow pass-through pads for all of the Raspberry Pi’s expansion connector and even a small prototyping area at the bottom.
Downloads: The full schematic and PCB layout can be downloaded from the GitHub repository right here.
R1………………….. 4K7 ,10%, 0.25W resistor
R2, R7, R8, R9…. 10K ,10%, 0.25W resistor (4 off)
R3………………….. 1K ,10%, 0.25W resistor
R6………………….. 22K ,10%, 0.25W resistor
R10………………… 12K ,10%, 0.25W resistor
R11, R12………….. 220R,10%, 0.25W resistor
(note that there are no R4, R5 !)
C1, C2…………….. 100nF, 63V polyester capacitor (2 off)
C3…………………. 100uF, 25V radial electrolytic capacitor
Q1, Q2 …………… 2N7000 N-channel MOSFET
Y1…………………. 16MHz ceramic resonator
F1…………………. 250mA polyfuse
LED1……………… 3mm orange LED
LED2……………… 3mm green LED
IC1………………… ATMEGA 328-PU microcontroller (with Arduino bootloader preloaded – “Standard Firmata” application is recommended)
28 pin DIL IC socket, 6 way header, 8 way header (2 off),10 way header, 13×2 way header (you may need to buy a 14×2 way header or two 14×1 trimming off one row)
and finally the PiMagic PCB
Whilst assembling the Rev01b prototype I generated a time-lapse video.
Solder assembly is actually quite straightforward – as usual starting with the low-profile parts first (resistors) I then move through the IC socket, the LEDs (flat to the board), the transistors (after forming the legs with pliers), polyester capacitors, resonator, polyfuse (after straightening the legs – I know some will say the kink is there for a reason), the headers bottomside, the headers topside and last the electrolytic cap (being the tallest part). Finally soldering done I insert the pre-programmed ATMEGA328P and we’re all set to go.
When it’s all done it should look something like this….
Here it is installed on a Rev B raspberry Pi, and on a Rev B+. It’s compatible with both but of course doesn’t feed through the extra I/O port pins (and the mounting hole doesn’t align). Actually it sits rather well on the PIMORONI case.
Project Status & License
The project is mostly complete and the examples page shows some applications of the PiMagic in use. There are a few issues right now that need some more attention:
- The hack to toggle port pin #4 during reprogramming with avrdude is troublesome and unreliable. This is maybe a timing issue with different revisions of Raspbian or could be to do with the requirements of the Arduino bootloader. This needs investigation but I’m not ruling out a customised version of avrdude rather than trapping for the DTR pin toggle in the OS and redirecting this to pin #4.
- A small change is needed to the Q1, Q2 PCB layout – last time I trust someone else’s library – the pins are mirrored hence these transistors should be inserted upside-down compared to the silkscreen on the current (Rev01b) layout.
PiMagic is released as open source hardware – modifications, improvements and reuse are encouraged. “Ohw-logo” by Brandon Stafford – http://oshwlogo.com/, http://www.oshwa.org/open-source-hardware-logo/. Licensed under CC BY-SA 3.0 via Wikimedia Commons.
PiMagic by @croz_tech is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.