July 15, 2013 14:07
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
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.
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.
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.
Open source (hardware and software!) advocate, Treasurer and Director of the Free and Open Source Silicon Foundation, organiser of Wuthering Bytes technology festival and founder of the Open Source Hardware User Group.
CommentsLogin to comment
June 13, 2017 10:46
Fellas i need to exchange btc to payeer, do you think this service https://www.youtube.com/watch?v=vvukywovqec is legit?
November 27, 2013 19:27
Great article, would it be possible to use multiple FPGAs, or would you need separate serial devices for each one on the Pi?
November 27, 2013 18:23
sorry - a mistake in step 5 --> ignore the brackets
November 27, 2013 18:20
After a couple of days trying and debugging the mining software on the RPi
i found the solution.
The mining pool changed the protocol from "http / getwork" to "stratum" and that
made the difference. The little correction for your guide is that you need a proxy
on your RPi which converts the getwork protocol to the stratum. Infos on this site:
--> few additional steps to your guide:
1. go to this site and download the proxy software: https://github.com/slush0/stratum-mining-proxy/
2. follow the installation there (for linux)
3. you may need to install python (how to is described in readme-file)
4. change in the file "mining_proxy.py" the default server in line 27 to default='stratum.btcguild.com'
5. start the proxy software (here the file config-live2.tcl)
6. change the server in your mining software (config-live2.tcl) to "http://localhost:3333/"
7. run your mining software on RPi
8. wait til the first hash accepted ;-)
Now it works for me finally - was a good fun to make it run...
Thx again, Andrew.
November 7, 2013 19:43
OK, so "startum.btcguild.com" definitely looks like an incorrect URL (typo!) Try changing this to "stratum.btcguild.com". I haven't had my setup running for quite a while now (DE0-Nano being used for other things), so my memory is a bit hazy, but I seem to recall trying a few different hosts before I got it to work (the software uses a deprecated pooling protocol, so this meant that not as many servers support it). If you're using BTC Guild, I'd also suggest trying the connection details I used, as can be seen in the screenshot (host: btcguild.com, port: 8332).
Hope that helps.
November 7, 2013 11:14
I checked what you mentioned, but without success. The RPi is set up like provided instructions on github. I tried an uart communication with another tool (e.g. file transmission via minicom) and could see the activity on oscilloscope. But there is no activity on Tx line while running miner-software (whithout FPGA). The internet connection is present (verified with ping to stratum.btcguild.com). I compiled the software (run make) like you described - additionally make send_json... I cannot look behind the running software and dont understand the code completely. My console output looks like that (numbers here random):
URL = startum.btcguild.com 3333 /
November 6, 2013 11:57
@sparkerdesign, the linked projects provide wiring details, and if I remember correctly you need to disable the login process from attaching to the serial port (otherwise the miner won't be able to communicate). If you've successfully disable the serial port console login, I'd try swapping the transmit and receive connections. Other than this, and assuming your DE0-Nano is programmed as it should be, I'm not sure what to suggest.
November 5, 2013 19:48
thx for your guide. I followed the description, but
unfortunately i cannot establich any connection between
de0 nano and RPi. After start it repeats the line "getwork tmpfile..."
with different numbers at the end. sometimes it reports "BAD HASH" or
something like that.
What im doing wrong with it? Any ideas?
October 24, 2013 20:15
Great post Andrew. I ran through your guide and got my DE0-Nano/Raspberry Pi to start hashing :) .
July 29, 2013 16:57
I'd seen ASICs but not that particular one — wow, impressive stuff!
July 19, 2013 15:28
hi, are you see this chip?
https://products.butterflylabs.com/home ... -chip.html
is very powerfull for mining bitcoins