Open source fpga bitcoin miner - congratulate, what
Bitcoin Mining with a Raspberry Pi and DE0-Nano
Using a Raspberry Pi with an FPGA development board for a first foray into Bitcoin mining.
With a performance of only 0.2 million hashes per second (MH/s) a Raspberry Pi alone is a non-starter for Bitcoin mining. However, the low cost and low energy consumption computer makes the perfect platform for coordinating mining across more capable hardware.
In the mining rig described here an FPGA does all the hard work (SHA-256 hashing) and communicates over a serial link with a Raspberry Pi. The latter requesting new work from, and submitting proof of work done to, a Bitcoin mining pool.
DE0-Nano Bitcoin Miner
The Open Source FPGA Bitcoin Miner port for DE0-Nano was created by GitHub user kramble, who has published a repository containing the HDL along with software for use with Raspberry Pi.
In order to compile the Verilog design it's necessary to install the Altera Quartus II software (the free-of-charge Web Edition version will suffice).
Building the miner design
The GitHub repo contains various different Bitcoin miner HDL designs and the one that was used here is located in the Hashers22_serial folder.
In order to compile this we start Quartus II, browse to the Hashers22_serial directory and open fpgaminer.qpf. Upon selecting compile you may want to go and make a cup of tea, as on my laptop this took around 20 minutes!
At this stage it would be possible to download the compiled design to the FPGA, but it would be lost as soon as power to the board is removed. To make it permanent we must convert the SOF file to a JIC file which can be used to program the configuration device, an EPCS16 flash memory IC.
From the File menu select Convert Programming Files and set the following parameters:
Programming file type: JTAG Indirect Configuration File
Configuration device: EPCS16
File name: fpgaminer.jic
Then highlight Flash Loader and select Add Device → Cyclone IV E → EP4CE22. Next highlight SOF Data and select Add File and browse to fpgaminer.sof.
Finally, select Generate to create the JIC file.
Next open up the programmer by selecting Tools → Programmer. If there is an entry for the .SOF file delete this, then add the JIC file, ensure Program/Configure is ticked, and then select Start.
Setting up the Raspberry Pi
By default the Raspberry Pi UART is set up as a hardware console and since here it will be used for communicating with the DE0-Nano, some configuration is required. This is straightforward enough and covered in the provided instructions.
The Raspberry Pi software lives in the serial_solo directory. Running make builds the mine application, but for some reason not the send_json binary which is also required. This can be compiled with:
$gcc -g -c -o send_json send_json.c
$gcc -o send_json send_json.o
Mining pool account details are then set in config-live2.tcl.
Connecting the two together
The DE0-Nano and Raspberry Pi both use 3v3 logic levels, however, the instructions still recommend using optoisolators between the two.
I went for a much more direct connection between the boards, placing 1K resistors in series with TX and RX just to give some measure of protection. Since this was my first attempt at Bitcoin mining I also added LEDs so that I could at least confirm when data was being exchanged.
Starting mining
The DE0-Nano miner powers up in a halted state and is started by pressing KEY0. Following which the minelive2.sh script is executed on the Raspberry Pi.
With any luck after a little while it should then be reported that a sha256 match was found and the “GOLD number” will be incremented by 1.
After a few successful matches we can then check the mining pool dashboard to see that these have been registered.
The estimated speed shown in the dashboard screenshot above should be disregarded as the miner hadn't been running for very long and this is based on insufficient data.
Final thoughts
I left the DE0-Nano clock speed set at the fpgaminer default of 40MHz, which supposedly gives a performance of 6.67 MH/s. The BTC Guild performance charts showed that in practice the miner varied between around 5 and 10 MH/s on average.
I find Bitcoin fascinating and although I have no intention of trying to make a fortune with the cryptocurrency, there is something strangely compelling about Bitcoin mining. When starting out I didn't give a second thought to increasing the FPGA clock speed, but now I find I'm tempted to put a heatsink on the FPGA, double the clock speed or more and try out higher performing designs.
If money is not the motivation, then what is? Well, simple geeky fun, the pursuit of amassing a volatile stash of what may amount to absolutely nothing, and playing a very small part in what is very likely to be a fun ride however it turns out.
— Andrew Back
-