Mining BitCoins with a Raspberry Pi

Ok, so Bitcoins have been around for a while now. It has crashed twice and maybe a little late in the day to ‘get rich’ from mining coins. Anyway! I wanted to learn about Bitcoins and the mining process. This project is purely for interest and I do not expect to profit from it at all. I had a Raspberry Pi sitting around gathering dust so I decided to try to use it to mine bitcoins. This is how I did it.


Getting Started

I looked at ways of mining online, and for a raspberry pi the only way was to use a USB ASIC device. I started by getting all devices I needed. Here is what I used:

Qty  Item  Price (GBP)
1 Raspberry Pi
1 D-Link 7-Port Powered USB Hub – Model DUB-H7 (eBay) £22.00
5 USB ASIC Bitcoin Miner Block Erupter (eBay) £20.00 (Each)
1 Arctic Cooling Breeze Mobile USB Fan (Amazon) £10.00
1 Adafruit 16×2 LCD + Keypad Kit (Pimoroni) £21.00
1 USB Wifi (Pimorono) £8.00

 

Wifi

To start I had to get my Raspberry Pi (RPi) to wireless connect to my router. This was because I cannot get a cable from my RPi to the router. I had a great deal of trouble trying to get the Wifi working! I was only using the command line over SSH. I found several websites telling me to do different things and none seemed to work. I finally got it working using a mixture of different websites, I’ve posted my solution here.

bitcoinpiminer

LCD Screen

Adafruit has a LCD kit which is fantasic. It sits perfectly on top of the Pi showing information. If you want to get one then head to the Adafruit website for full instructions.

Install the latest version of Raspbian

I had used my RPi for different things before, so I wanted to have a clean install of Raspbian. At the time of writing, Raspbian wheezy is the latest version.


Getting it working

bitcoinhub

Connecting it together

I have my five USB Block Erupters connected to the powered USB hub. The USB fan also connected to the hub to keep the Block Erupters cool. The hub is then connected to my Raspberry Pi. I did try to have the USB hub power the Raspberry Pi, however it didn’t work.

Installing the Software

I’m using cgminer, which is a program that can used to mine Bitcoins. To install it first we need to install the software that cgminer depends on. I used the following command to install it:

sudo apt-get update

sudo apt-get install libusb-1.0-0-dev libusb-1.0-0 libcurl4-openssl-dev libncurses5-dev libudev-dev

I spent many hours trying to get cgminer working, for some reason I could not get many versions to work on my RPi. Some would not make, open or would freeze after about 10 minutes. After hours of trying many different versions I got cgminer 3.8.5 working.

cd
wget http://ck.kolivas.org/apps/cgminer/3.8/cgminer-3.8.5.tar.bz2

Once downloaded, I uncompressed and opened the directory.

tar xvf cgminer-3.8.5.tar.bz2
cd cgminer-3.8.5

Next I needed to configure cgminer to work with my USB Block Erupters

./configure --enable-icarus

And make the program

sudo make

As long as no errors appeared then everything should be good!

Creating the config file

I created a new file called cgminer.conf. This is where I placed all my details for mining pool. I’m using Bitminter.com as I found it easy to use. You should do your own research and choose a pool that you trust.

cd
sudo nano cgminer.conf

I found this example config file from learn.adafruit.com.

{
"pools" : [
    {
        "url" : "PoolAddress:Port",
        "user" : "UserName.WorkerName",
        "pass" : "Password"
    }
]
,
    "api-listen" : true,
    "api-port" : "4028",
    "expiry" : "120",
    "failover-only" : true,
    "log" : "5",
    "no-pool-disable" : true,
    "queue" : "2",
    "scan-time" : "60",
    "worktime" : true,
    "shares" : "0",
    "kernel-path" : "/usr/local/bin",
    "api-allow" : "0/0",
    "icarus-options" : "115200:1:1",
    "icarus-timing" : "3.0=100"
}

Example my “url” is set to “http://mint.bitminter.com:8332”. Bitminter sets their usernames as your username, an underscore and then worker name. Other sites I’ve seen username, dot and then your worker name. Once you have completed your settings in Nano press CTRL-O to write the file, then Press CTRL-X to close nano.

Start Mining.

Everything should be ready! I started mining by typing the following command.

sudo ./cgminer-3.8.5/cgminer --config cgminer.conf

This command opens cgminer and start mining Bitcoins! To quit press q.

PiMiner

PiMiner is a piece of software written by Adafruit that displays information from cgminer on the LCD display. This makes it very handy to see stats without having to log into the RPi. To install it, ensure that your LCD screen works and run the following commands.

cd
git clone https://github.com/adafruit/PiMiner.git
sudo python PiMiner/PiMiner.py &

Your LCD screen should now show the details of cgminer (When cgminer is running)

Make it run automatically when you turn on your RPi

To make cgminer and PiMiner automatically run on boot, follow these instructions.
Open rc.local

sudo nano /etc/rc.local

Add the following code to rc.local above “exit 0”

cd /home/pi/PiMiner
python PiMiner.py &
cd /home/pi
nohup ./cgminer-3.8.5/cgminer --config cgminer.conf &

It should look something like this

bitcoinrclocal

Complete! You should now have a working RPi mining you Bitcoins.


 

And finally

I never started this project to make money. In fact I expected to lose money buying all the equipment etc. It was more to learn how to set up a Bitcoin miner. I have completed this project and gained a lot of knowledge from it. I will keep my Pi running for a few days and may decide to sell all the ASIC miners back on eBay.