Thursday, January 16, 2014

Raspberry Pi for Block Erupter Bitcoin Mining

Previously I have written about setting up Bitcoin mining with the Block Erupter in Ubuntu, however a more efficient way to mine can be to use of a Raspberry Pi to control the Block Erupter(s). The major benefit to this is the greatly reduced power consumption, provided by the Raspberry Pi compared to a desktop computer or a laptop.

Controlling the mining of a Block Erupter does not require huge amounts of system resources, so the Pi can also be used for other tasks at the same time (ssh tunnelling, small webserver and so on).

Initial Requirements and Expected Outcome

Hardware

  • Raspberry Pi (preferably model B)
  • Block Erupter (as used in this guide, but other miners should also work if connectable)
  • Powered USB hub
  • Small fan (cooling the miner, necessary for Block Erupter)

Software

  • Raspbian Wheezy (OS running on the Raspberry Pi)
  • screen
  • bfgminer 3.9 [1]

Expectation

  • Steady, reliable mining speed of 300-330 MH/s
  • Low HW errors, definitely under 1%, but better in the range of 0.4-0.6%
  • Continuous running without the need of reboot or maintenance of any sort
  • No "hungs" of the Raspberry Pi, mining and configuration to be done without physical access to the hardware after initial setu
  •  Remote access and configuration (reach the Raspberry Pi through ssh)

Installation

Installing bfgminer

I have installed the latest version (as of December 2013) of bfgminer 3.9.0. This will be the reference in this guide. If you choose to install another version, please change the commands accordingly.

  1.  ssh into the Raspberry Pi. You will need root privileges.

    ssh user@raspberrypi
  2. Installing dependencies

    sudo apt-get install build-essential autoconf automake libtool pkg-config libcurl4-gnutls-dev libjansson-dev uthash-dev libncursesw5-dev libudev-dev libusb-1.0-0-dev libevent-dev libmicrohttpd-dev hidapi libmicrohttpd-dev
  3.  Download bfgminer

    wget http://luke.dashjr.org/programs/bitcoin/files/bfgminer/3.9.0/bfgminer-3.9.0.zip
  4. Unzip

    unzip bfgminer-3.9.0.zip
  5. Cd to directory

    cd bfgminer-3.9.0
  6. Configure. Note that by default all miner configuaations are enabled, so no extra argumetns are required if building for Block Erupters. (If you would like to disable some miners because you will not be using them, check out the README file that comes with bfgminer)

    ./configure
  7. And finally make

    sudo make
Technically it is done and bfgminer can be run.Navigate to the directory and

sudo ./bfgminer -o pool:port -u usrname -p password -S erupter:all

Where "-S erupter:all"  is important as it tells bfgminer to search for all connected Block Erupters and use them for mining.

The problem of running bfgminer like this is that it is only running until you have the ssh tunnel open. Once you close it, bfgminer shuts down. Hence one would need to have a computer running 24/7 in order to keep the ssh tunnel open and contiue mining. To overcome this problem, screen will be used. [2]

Running bfgminer "as a service" with screen 

"Screen is a full-screen window manager that multiplexes a physical terminal between several processes." [3] Technically it allows to run a command in a virtual terminal window in the background, which allows running the miner in the background too without the need of a live ssh connection to the Raspberry pi.

Simply install screen with
sudo apt-get install screen

After that, running bfgminer with screen goes as the following.

Start Bfgminer
sudo screen -dmS miner ./bfgminer -o pool:port -u usrname -p password -S erupter:all

Note: that this assumes you are in the directory of bfgminer. If you want to make a general command append the route to before ./bfgminer.

This will start bfgminer in a new screen session, detached, so no output will be shown on the screen, you will be returned to the command line. Here is a short explanation what the parts of the above command do.

  • screen: start a new screen sessions
  • -dm : Start screen in "detached" mode. This creates a new session but doesn’t attach to it. This is useful for system startup scripts.
  • -S: Session name. When creating a new session, this option can be used to specify a meaningful name for the session. As above I named the session "miner", one may choose a more specific name as well.


Switch to the Screen Session 

sudo screen -dR miner

This will switch to the screen session where bfgminer is running. Here you can monitor the miner, accepted shares, stales and so on. Once you checked the miner is running OK, exit the screen session properly, without interrupting the miner!

Stop Screen Sessions

CTRL+A+D

This will properly detach the screen session, without interrupting the miner. Note if you exit the screen session with CTRL+C or exit the miner with "q", the mining will stop.

Observations

Choice of Miner

Originally I tried to make mining work with cgminer as that was more familiar to me and have been using it for quite a while. However, I have encountered several problems that I could not overcome.
I tried virtually every version of cgminer from 2.8 until the latest version to see which one works best, but none could perform reliably. Hardware errors (HW) were in the 10% range (!) which is far above the expected value. First I feared that I bought a somehow faulty chip and this was the reason for getting so many HW errors.
The miner was also somehow unstable and caused the Raspbery Pi to hung after about ~20h of running and required a maanual reboot. This was definitely not what I was looking for.

All this might not be caused by cgminer as I find it a great software for mining (works great on my computer), however I could not get it to work the way I wanted to with he raspberry Pi.

Bfgminer seems to have solved all these issues. The miner runs steady with a low ~0.50% HW error and it did not get hung so far after some extensive testing. Configuration is easy and it works pretty much "out of the box".

Pool

Some pools implement a high stratum difficulty which means that a 330MH/s miner will have a hard time submitting shares at all. I found this issue with quite a few pools. Triplemining on the other hand has a stratum difficulty of 1 and I am submitting a share about every 30-40 seconds.

Cooling and Hardware

As mentioned before in my setting up Bitcoin mining with the Block Erupter in Ubuntu article, the Block Erupter requires some cooling. Initially I wanted to add some small copper heat sinks, however this plan failed due to delayed delivery of the heat sinks. Hence I am only using a small fan directed over the Block Erupter and somewhat creating a slight air movement over the rasoberry Pi as well. See some pictures below. Not a masterpiece for sure, but runs fine and was a nice experiment!

Complete setup contained in a plastic basket

Block Erupter and the USB hub

Small USB fan (partially disassembled)
Bfgminer stats after running for 7 days


References


No comments:

Post a Comment