CyrusBuiltHTPC Update

I’ve finally released a new build of CyrusBuiltHTPC for Raspian Linux.  This new build will install the latest XBMC (12.2 “Frodo”) and configure your Raspberry Pi as a full-fledged HTPC with the following features:

1) AirPlay support
2) TVHeadEnd support
3) libCEC support, so you can control it using your TV’s remote.
4) Support for relocating rootfs to an EXT4-formatted USB HDD.
5) A ~60% reduction in overall CPU usage.
6) Support for the DS1307 Real-Time Clock.
7) XBMC can now be updated just like any other package in the system via “apt-get update” or using the “systemupdate” tool installed with CyrusBuiltHTPC.
8) Reduced memory usage footprint to ~40MB on average.

NOTE:  This has only been tested with the Raspberry Pi Revision 2 Model B.  IT HAS NOT BEEN TESTED ON PREVIOUS RASPBERRY PIs AND LIKELY WILL NOT FUNCTION CORRECTLY.

This build makes use of the pre-compiled DEB packages built and maintained by Michael Gorven (cocooncrash).

Usage instructions:

Once you’ve pulled down the source package, navigate to the CyrusBuiltHTPC/CyrusBuiltHTPC folder in the terminal and then type “chmod +rx remote_install.sh”.  If you have not already done so, enable the SSH daemon on your Pi.  Then run “./remote_install.sh” in the terminal and follow the prompts.  This will push the CyrusBuiltHTPC package to the home folder of the Pi user (or whichever user you specified).

On the Pi, navigate to ~/CyrusBuiltHTPC in the terminal and type “chmod +rx setup.sh” and then run it “./setup.sh”.  This will make all the necessary scripts executable and install some system tools.  You can now run commands like “systemreboot” to reboot the Pi immediately or “systemshutdown” to gracefully power off, or “systemupdate” to upgrade and update the system.  You can also backup and restore the system configuration files modified by CyrusBuiltHTPC setup.  To proceed with installing XBMC do “cd ~/CyrusBuiltHTPC/xbmc_install” and then “./get_and_install_xbmc.sh” from the terminal.  This will add Michael Gorven’s APT repo for XBMC and then pull down XBMC and any necessary dependencies and install it all.

Once finished, you will be prompted to run the platform configuration utility.  This will install RTC support, some additional tools, configure XBMC to auto-start on boot, grant the authority to XBMC to shutdown and reboot the system, and give you the option to relocate rootfs.  This will also overclock the system to 800MHz and set the memory slice to 128MB/384MB.  As prompted, you will need to reboot the system for the configuration changes to take effect.  If you chose not to run the platform configuration utility, make sure you are not booted into desktop mode (pure console, not running X11/Xorg), and run “xbmc-rpi” to launch XBMC.  The xbmc-rpi script will store the current terminal settings before launching XBMC and then restore the terminal when XBMC quits so you are left with a black screen afterward.

I plan to make this available as a custom distribution of Raspbian in the form a disk image that you can just plop onto an SD card and go with.  But this will be a little ways down the road.  Hop on over to my GitHub page to get the latest CyrusBuiltHTPC stuff.

Enjoy!

Tuesday, June 18th, 2013 Arduino, Hardware, Programming, Raspberry Pi No Comments

HTPC Pt 3

USB-to-SATA adapter and 250GB Hitachi HDD.  Relocated rootfs to the HDD to eliminate writes and reduce reads from the SD card. The SD card is only used for bootstrap, and then hands off to the HDD.

USB-to-SATA adapter and 250GB Hitachi HDD. Relocated rootfs to the HDD to eliminate writes and reduce reads from the SD card. The SD card is only used for bootstrap, and then hands off to the HDD.

 

Raspbian up and running on the HTPC.  Once I work out on the compilation issues with XBMC 12.1, I'll post pics of that too.

Raspbian up and running on the HTPC. Once I work out on the compilation issues with XBMC 12.1, I’ll post pics of that too.

 

And there you have it.  A fully-functional HTPC (connected via HDMI to a 1080P HDTV) that also works as a full-blown Linux desktop.  CEC is also working, so if the TV is off with the HTPC turns on, the TV will turn on and switch to that input.  Likewise, XBMC can be controlled using the TV remote because the TV essentially becomes a peripheral of the HTPC via libCEC.  Thanks to my PMU, it behaves much like a PC would in the sense of power on/off, reset, auto-off on shutdown, etc.  The only thing it does not do yet is power on via remote control (…. yet).

Sunday, May 5th, 2013 Arduino, Hardware, Raspberry Pi No Comments

HTPC Pt 2

The Raspberry Pi (Model B., revision 2). The brown & black wires go to the RPi reset, and the colored cable goes to the RTC. The purple wire is for shutdown detection.

The Raspberry Pi (Model B., revision 2). The brown & black wires go to the RPi reset, and the colored cable goes to the RTC. The purple wire is for shutdown detection.

 

Better shot of the Pi with the 2-pin header added to the board for reset.

Better shot of the Pi with the 2-pin header added to the board for reset.

The DS1307-based Real-Time Clock (RTC) from Adafruit (http://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/overview)

The DS1307-based Real-Time Clock (RTC) from Adafruit (http://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/overview)

 

The DC-to-DC ATX power supply. The connector was removed and the wires fed into a terminal block for easier wiring. The PMU is powered off the +5V standby lead from PSU (purple lead) and the green wire is the ATX trigger.

The DC-to-DC ATX power supply. The connector was removed and the wires fed into a terminal block for easier wiring. The PMU is powered off the +5V standby lead from PSU (purple lead) and the green wire is the ATX trigger.

Wireless keyboard/mouse combo.  TV remote shown for size comparison.

Wireless keyboard/mouse combo. TV remote shown for size comparison.

 

 

Sunday, May 5th, 2013 Arduino, Hardware, Raspberry Pi No Comments

HTPC

I finally got around to taking some photos of my HTPC.

Here it is fully assembled in its Mini-ITX chassis

Here it is fully assembled in its Mini-ITX chassis

 

And here is the front bezel of the chassis (Power button w/LED, HDD LED, reset button - the big red one)

And here is the front bezel of the chassis (Power button w/LED, HDD LED, reset button – the big red one)

With the top off. Top tray holds the HDD.

With the top off. Top tray holds the HDD.

 

And here's all the guts. The middle board is the PMU I designed. It is controlled by the blue Arduino Micro on board.

And here’s all the guts. The middle board is the PMU I designed. It is controlled by the blue Arduino Micro on board.

 

Close-up of the PMU. The green terminal block on the right is power input. The block up top is the switched power (to RPi and HDD).

Close-up of the PMU. The green terminal block on the right is power input. The block up top is the switched power (to RPi and HDD).

 

Sunday, May 5th, 2013 Arduino, Hardware, Raspberry Pi No Comments

Raspberry Pi ATX power management using an Arduino (Pt. 2)

Well, I finally posted all my source code and schematics on github at https://github.com/cyrusbuilt/CyrusBuiltHTPC.  Now some details on the Arduino code: To enable debug mode (if necessary…. it’s been thoroughly tested and I’m currently using it on my own box everyday), uncomment line 45 in Raspi_ATX_PMU.ino.  If you do, the firmware will not complete initialization until it connects to the host that will be monitoring the serial output.  It will attempt a serial connection at 9600 BAUD and will not do anything else until connected.  This is intentional so that you can see the boot screen which displays the pin definitions and their current state. Otherwise, you’d miss the boot screen by the time the connection is actually made.  Once connected, all actions and pin states are output to the serial port as the events are handled.  The 2 libraries in the “lib” folder will need to be copied to the “libraries” folder of your Arduino installation in order to compile.

And now some notes on the HTPC platform installation stuff:  Use the following procedure to set up the platform correctly: 1) Make sure SSH is enabled on the Raspberry Pi.  2) Navigate to the CyrusBuiltHTPC folder from a terminal and type “chmod +rx remote_install.sh”. This will make the remote installation script executable. 3) Type “./remote_install.sh”.  This will just push all the platform installation stuff to the Pi using SCP.  If you’ve already copied the platform installation stuff to the Pi by other means, then just skip steps 2 and 3. 4) Type “chmod +rx setup.sh” in the terminal on the Pi (or via SSH), and then type “./setup.sh”.  This will perform the initial setup by setting the appropriate permissions on the other scripts and installing the utility scripts (systemreboot, systemshutdown, systemupdate) in /usr/bin. 5) Navigate to /home/pi/xbmc_install in the terminal and type “./build-and-install-xbmc.sh”.  This will pull XBMC from its github repository and proceed to compile and install XBMC.  This may take up to 13 hours to complete. 6) After rebooting, navigate to “~/” and type “./configure-htpc-platform.sh”.  This will configure the platform appropriately and set up the Pi to boot into XBMC automatically (you can still exit XBMC to get to a command prompt).

The whole system performs well.  I’ve been streaming TV shows in HD from my TVersity server for months without any problem.  I think I can reduce boot time by relocating rootfs to the USB HDD, as described here.  I will post some pictures of the HTPC and some additional schematics laying out how the whole thing is supposed to be connected together.

Cheers!

Wednesday, April 3rd, 2013 Arduino, C/C++, Programming, Raspberry Pi No Comments

Raspberry Pi ATX power management using an Arduino (Pt. 1)

So I’ve been rather busy.  I completed my R-Pi HTPC.  I also completed my ATX power management board.  This is a subject that has been tackled in a number of ways.  I’ve seen various methods and implementations.  The problem with using an ATX power supply to power a Raspberry Pi is: You have to “trigger” it on yourself by tying the trigger (green) lead to ground, and when you shut down the Pi, it does not turn all the way off. This means you either need to disconnect the power to the Pi -or- disconnect the power to the ATX supply -or- disconnect the trigger.  I went with a multi-step approach using an Arduino Micro.

 

Theory of Operation

So the way this works is somewhat complex, but very effective and more-or-less mimics the basic ACPI function on a standard ATX-style motherboard.  The Arduino monitors 2 input pins, these pins have momentary (normally open) push buttons attached to them.  When the system is off, pushing the reset button is ignored, but pushing the power button triggers a relay that powers on the Pi.  Once its on, pushing the reset button triggers another relay that shorts the reset pins on the Pi (you will likely need to solder a 2-pin header onto the Pi).  This sounds simple, but to accomplish all this AND accommodate a 2.5″ SATA HDD, requires a little bit more complexity.

I used a total of (3) 5V relays and some transistor magic to make it all happen.  1 relay handles shorting the reset pins on the Pi, another handles switching the 5V rail on/off for powering the Pi and providing the 5V to the HDD, the 3rd relay handles switching the 12V rail on/off to the HDD.  Obviously, the relays for the 5V and 12V rails need to switch simultaneously.  Now, to truly behave like a normal ACPI-compliant board, we can’t leave the ATX supply on all the time.  So we’ll power the Arduino using the 5V Standby on the ATX supply (purple wire).  This lead is always “hot”.  On a normal motherboard, this standby voltage is used to back the NVRAM portion of the CMOS (used for storing user settings (time, date, etc)) and also to power the ACPI circuit.  When you push the power button on your computer, this circuit triggers the ATX supply on and powers up the rest of the system.  That is our goal with the Pi.

So, to do this we will need all 8 digital I/O pins on the Arduino.  One of the caveats is: The 5V standby does not provide enough juice to power all 3 relays and 2 LEDs.  So, we use it to power the Arduino only.  Then using an NPN transistor as a switch, we short the trigger to ground causing the ATX supply to “turn on”, giving us another dedicated 5V rail from the ATX supply to power the rest of the circuit.  Now that we can power the relays, turning the power on will activate both power control relays powering on the Pi and the HDD and allowing it to boot normally.  To turn it off, pushing the power button drive the output pins low, causing the relays to switch off.  Of course, we can’t just power these relays using the output from the I/O pins directly, so we use NPN transistors activated by the output pins to turn on the relays, and we clamp the relay coil using a rectifier diode.

But what about “soft off”?  Good point.  When you shutdown the Raspberry Pi, that doesn’t shut off the power.  So you would have to shutdown the Pi, then turn off the power, then turn it back on to get it boot up again.  That’s annoying.  As it turns out, the Raspberry Pi drives the UART TxD pin on the GPIO header high when it turns on.  It will go low again for ~200ms when the hand-off from the soft-firmware to the kernel bootstrapper occurs and will then stay high until CPU_HALT.  So we just connect to TxD pin to an input pin on the Arduino and watch its state.  When the system is powered on, we monitor that pin to see if it goes low.  Now since we know that it will briefly go low at some point during the boot cycle, we can’t just shutdown as soon as we see that .  So inside our loop() routine, the first time we notice this happen, we need to use a timer and a counter to keep track of *how long* the pin went low.  To be safe, my Arduino firmware waits 500ms for up to 4 cycles (a total of 2 seconds) after CPU_HALT to be certain that the Pi has shutdown completely.

As it turns out, this is just enough time for the TV/Monitor to notice that the HDMI signal is lost.  By then, the Arduino drops out both power control relays, then waits another 50ms and turns off the ATX supply.  That’s pretty much the jist of it.  I plan to post my schematics, firmware source code, and all the scripts and config files for the actual HTPC software to GitHub as soon as I get everything together.  Keep an eye out for my next post where all dig into system design, materials, etc and then later on the OS and software.  I’ll post a bunch of pics to.  In the meantime, you can take a look at the schematic for the power management board here.

Thursday, March 14th, 2013 Uncategorized No Comments

Arduinos!!

Ok, so I’ve been playing with a couple of Arduinos for a while now.  I love these things…. soooo many possibilities.  I used to use the Parallax BASIC Stamp 2P24 for similar purposes, but quite frankly, they are just too expensive to compete with the Arduino (or Raspberry PI for that matter).  Plus, I don’t really care for the PBasic programming language either. The Arduino essentially uses C/C++ and the libraries are extensive.

Anyway, I bought 2 of these guys.  I started with an Arduino Uno and did some experiments and prototyping with it.  After playing around I had a cool idea….. remember when I said I got a Raspberry PI a while back?  Well, I had decided to build an HTPC using the PI, a Mini-ITX chassis w/power supply, an RTC (real-time clock), and some other goodies.  I found that Raspberry Pi + Raspbian + XBMC (Xbox Media Center) = One badass HTPC.  I mostly stream video from my TVersity server, but I also added a 250GB 2.5″ SATA HDD using a USB-to-SATA adapter.  The power supply that came with Mini-ITX chassis is more than ample considering the Pi only uses 5V @ 0.5A DC.  The bulk of the power consumption is spent on the HDD.  I also got a SWEET mini wireless keyboard/mouse combo so I can work the whole thing while sittin across the room in bed.  I can even surf the web!

Caveats:
1) There is a lot of work to getting XBMC compiled and installed on Raspbian.  There are pre-built images that have a stripped-down OS based on Raspbian with XBMC already integrated as a self-contained HTPC OS.  They were great, but did not support I2C or the DS1307 (both needed for the RTC module), nor did it have adequate support for my USB-to-SATA controller.  I found it best to just build XMBC on top of Raspbian and then customize the whole thing as needed.

2) Power.  The Mini-ITX chassis uses an ATX-style power supply.  It also has power and reset buttons, as well as power indicator LED in the front bezel just as you’d expect from any other PC.  The problem is this:  The Pi does not behave like an ATX-class PC.  You can soft-off through the OS, but it does not power off the board.  You have to disconnect and then reconnect the power in order to get it to boot up again.  However, there are 2 solder pads on the Pi used for reset.  So then I got the idea:  I could build a PMU (power management unit) using an Arduino!!

As it turns out, the ATX specification has a 5V standby pin (purple wire) that is always on as long as it has power.  This is what keeps certain functions of your motherboard alive so it can monitor power button presses, which then tells the power supply to turn on by driving the trigger pin (green wire) low, or in other words, ties it to ground.  So my thought was to use the Arduino to sense power and reset buttons and then drive relays to to control them.

But that is where I ran into problems.  I started off trying to use an ATtiny85 and just program it using my Arduino Uno as an ISP, but that didn’t work out because I couldn’t get the damn thing programmed.  I eventually gave up and bought an Arduino Micro from AdaFruit.  Not as cheap as the ATtiny85, but far more versatile and a breeze to program.  Plus it supported a greater instruction set, which I ended up needing anyway.

Then I ran into another problem:  Power draw.  The Arduino Micro, plus LED and a couple of relays is just too much power draw from the 5V standby pin.  I did not have sufficient power to run the whole circuit.  So, plan B: tie the trigger pin low leaving the ATX supply on full-time (or while it to a switch for hard-disconnect).  Then I can use the full 12V and 5V rails from the ATX supply.  The only thing is, I had to add a third relay.  The relay assignments are as follows:

Relay 1 = Reset switch.
Relay 2 = 5V power switch for Raspberry Pi and HDD.
Relay 3 = 12V power switch for HDD.

So the basic operation is simple:

Power button press (momentary):
Power currently on? no-> turn on LED and Relays 2 and 3. Otherwise, turn them all off.

Reset button press (momentary):
Power currently on? yes->turn off LED and turn on Relay 1. Do not switch states back until button release. During this time, ignore power button presses; Otherwise, do nothing.

This was actually quite effective.  The prototyping phase is done.  I just need to start soldering this stuff to the PCB!!  I’ll be posting schematics, source code, etc to github as soon as I get everything put together and tested.

Tuesday, February 12th, 2013 Arduino, C/C++, Hardware, Programming, Raspberry Pi No Comments

MonoPluginFramework Released

I released my MonoPluginFramework.  You can get it over at https://github.com/cyrusbuilt/MonoPluginFramework.  Its a simple easy to use plugin framework for Mono/.NET supporting dynamically loading plugin assemblies, independant plugin configurations, plugin diagnostics, and plugin management. This is meant to be lighter and easier to implement than the Addins framework.

While this framework has not yet been throughly unit tested, it is based on a .NET/WinForms variation that used in another project that worked quite well.  If anyone gets a chance to look at this and test it, by all means, give’er a whirl.  I’ll be generating API documentation soon.  In the meantime, the code itself is well documented.

It works like almost any other plugin framework.  The plugin itself implements the IPlugin interface.  The host application then uses the PluginManager to load and manage the plugins.  You can also write your own plugin management class(es) by implementing the IPluginHost interface.  The CyrusBuilt.MonoPluginFramework.UI namespace includes a couple of GUI classes used for reading/writing  plugin configurations if the plugin has an associated config.

More updates will be coming soon, so keep an eye on the github page.

Tuesday, January 29th, 2013 Programming No Comments

I’m finally on GitHub!!

Well…. I finally made the leap.  I’ve joined GitHub and published a few of my projects already.  I can check out all my stuff over at: https://github.com/cyrusbuilt.  I’ve published my file utilities library (FileLib) for AutoItV3, my AutoItProjectCreator, and my work-in-progress Raspberry Pi library for Mono/.NET (MonoPi).  Feel free to check them out and provide feed back.

Thursday, December 13th, 2012 Uncategorized No Comments

I Finally Got A Raspberry Pi!!!

Yep… Got one. I got the new Revision 2.0 Model B board. This puppy has an ARMv6 processor, Broadcom VideoCore IV chipset and 512MB RAM. I am typing this in !NetSurf in RiscOS booted from the Pi. You can download a RiscOS image along with a few different Linux images here.  I’ve also been testing an OpenELEC image, which is basically an XBMC distribution made for the Raspberry Pi (among other devices).  This thing is SWEET!  I still need to test the Raspbian Linux image, but I intend to run FirefoxOS on top of it if I can get it to work.  I will be posting pics/videos as I continue testing so stay tuned!  Also worthy of note:  I’m already 40% finished with a Mono/.NET API framework for interfacing with the GPIO pins ‘n such on the Pi.  There is another library currently available called RaspberryPiDotNet which my library is partially derived from, but at my last check, it did not yet support the new Revision 2.0 board, as the GPIO pins changed on the Rev2 board.  My library has support for both Rev1 and Rev2 boards.  I will post in the Downloads page as soon as I have a stable release.  I also intend to publish it to GitHub.

More to follow!  If you are interested, I bought mine from MCM Electronics along with a 16GB SD card and an acrylic case.

Friday, December 7th, 2012 Uncategorized No Comments