Skip to main content

How to Mine Cryptocurrency with Raspberry Pi

Raspberry Pi Bitcoin Mining
(Image credit: Tom's Hardware)

With Bitcoins trading at almost $14,000 per bitcoin, perhaps it is finally time for me to get into the cryptocurrency game? Instead of buying bitcoins, could I use my Raspberry Pi to mine for bitcoins instead? 

What is Cryptocurrency mining? 

Crypto mining is the digital version of mining for gold, combining performing complicated calculations and pure luck (being the first to complete the calculation) with your computer. Mining is essential to cryptocurrencies in order to maintain their distributed ledger, aka Blockchain. 

While Bitcoin is the most well-known form of cryptocurrency, it’s hardly the only game in town. All forms of cryptocurrency use blockchains to maintain the validity of each transaction and prevent someone from fraudulently spending their coins more than once.

Is Raspberry Pi Bitcoin mining profitable in 2020? 

My initial research showed that mining for bitcoins with any consumer grade computer is not profitable when factoring in the cost of electricity and hardware. Most bitcoin mining is now done on ASIC Bitcoin Miners; hobbyists and individuals can find limited success by joining a mining pool, harnessing the power of a group of distributed computers. What if we joined a mining pool, used solar panels to power our Pi, and ‘wrote-off’ the cost of our hardware? Bitcoin mining is an extremely competitive venture with too many other miners, increasing difficulty levels, and lower rewards for miners

Despite this gloom and doom news, I decided to forge ahead with this project and set my sights on alternative cryptocurrencies. As of the writing of this article, there are over six thousand alternative cryptocurrencies traded today.

Raspberry Pi Bitcoin Mining

(Image credit: Tom's Hardware)

Mining Pools

Individual cryptocurrency mining was out of the question since we are using a Raspberry Pi and not an ASIC Bitcoin Miner. I looked at several mining pool software groups I could join; most had options for Windows and MacOS; there were no mining pools with support for Raspberry Pi. Raspberry Pi is not supported by Linux miner software due to its ARM Architecture. Supported Linux mining software is based on x86 processors found in typical PCs.

Disclaimer: This article is presented as an educational opportunity to spark interest in learning more about blockchain and cryptocurrency, and not necessarily to generate cryptocurrency. The methods described in this article are hacks and not officially supported. The easier and faster method is to download and install the free software associated with the mining pool of your choice on your PC. 

What You’ll Need for this Project 

This tutorial is based on terminal commands. If you are not familiar with terminal commands on your Raspberry Pi, we highly recommend reviewing 25+ Linux Commands Raspberry Pi Users Need to Know first 

How to Mine for Cryptocurrency on Raspberry Pi

We will start by creating our account with Minergate, a cryptocurrency mining pool with 3.5 million users worldwide for Bitcoin Gold, Zcash, Ethereum, Ethereum Classic, and Monero. This tutorial is specific to mining Monero as it was the only cryptocurrency I had any level of success with.

Raspberry Pi Bitcoin Mining

(Image credit: Tom's Hardware)

2. Boot your Raspberry Pi. If you don’t already have a microSD card see our article on how to set up a Raspberry Pi for the first time or how to do a headless Raspberry Pi install.

3. If you are using Raspberry Pi OS with Desktop, open a Terminal, or press Ctrl-T. If you are using Raspberry Pi Lite, login as you would normally.

4. Once in your terminal, run the following updates and install the necessary dependencies: 

sudo apt-get update && sudo apt-get upgrade -y
sudo apt install git automake autoconf libcurl4-openssl-dev libjansson-dev libssl-dev libgmp-dev 
cd cpuminer-multi

Raspberry Pi Bitcoin Mining

(Image credit: Tom's Hardware)

5. Now, let’s compile the mining code with the following three commands. This step will take a couple of minutes on a Raspberry Pi 4.

sudo ./autogen.sh
sudo ./configure
sudo ./build.sh

Raspberry Pi Bitcoin Mining

(Image credit: Tom's Hardware)

6. After building and configuring our mining software on our Raspberry Pi, let’s start mining for Monero! Enter the following terminal command to start the miner, replacing YOUR_EMAIL with the email address you used to signup for your Minergate account.

./cpuminer -a cryptonight -o stratum+tcp://xmr.pool.minergate.com:45700 -u YOUR_EMAIL

You should see the mining software start and hopefully see a few shares ‘accepted’ with ‘yes!’

Raspberry Pi Bitcoin Mining

(Image credit: Tom's Hardware)

7. Let’s check your Minergate Dashboard by logging into https://minergate.com/internal. You can do this on a Chromium browser if using Raspberry Pi Desktop, or on your PC. Scroll down your dashboard until you see Monero. If everything is working, your Monero Status will indicate ONLINE. Congratulations! You’re now mining for Monero! 

Raspberry Pi Bitcoin Mining

(Image credit: Tom's Hardware)

How to Start Raspberry Pi Crypto Mining on Boot 

To automatically start our cryptocurrency miner on boot on our Raspberry Pi, we’ll use the Crontab method.

crontab -e

If you haven’t set the crontab previously, you’ll see the response “no crontab for pi, Select an editor.”

1. Type ‘1’ and hit Enter.

2. This will open a new crontab file, arrow down to the bottom of your crontab file and enter the command below, replacing YOUR_EMAIL, with the email address you used when creating your Minergate account

@reboot sudo /cpuminer-multi/cpuminer -a cryptonight -o stratum+tcp://xmr.pool.minergate.com:45700 -u YOUR_EMAIL

Raspberry Pi Bitcoin Mining

(Image credit: Tom's Hardware)

4. Press Ctrl-X, and y to save your crontab.

5. Now reboot your Pi by typing ‘sudo reboot’ in your Terminal.

How much Monero did I mine with Raspberry Pi? 

My Raspberry Pi 4 calculated 357 good shares in about 8 hours of run time. Miners are rewarded for good shares. Bad Shares are calculations where I came up with the right answer, but my Pi produced the results slower than another computer. Miners only get paid when they submit the correct answer first. Invalid shares are the worst as a miner is penalized for every invalid share due to possible fraudulent activity. I was a bit worried when my first 4 shares were marked as invalid shares. 

Raspberry Pi Bitcoin Mining

(Image credit: Tom's Hardware)

357 good shares = 0.000001410642 Monero = 0.00015569 USD

I made the equivalent of 1/100th of a penny in 8 hours.

In order to withdraw my Monero, I needed a minimum of 0.05 Monero, approximately equal to $5.811 USD. (Exchange rate at the time of the writing of this article.) At a pace of accumulating 0.000001410642 Monero per 8 hours, it would take me 3,762 years to reach the minimum withdrawal threshold of 0.05 Monero. 

Raspberry Pi Bitcoin Mining

(Image credit: Tom's Hardware)

Lessons Learned about Raspberry Pi Crypto mining

As stated at the beginning of this article, the purpose of this exercise was to learn about cryptocurrency and not to make a profit.

  • Cryptocurrency mining rewards are calculated by shares and hash rates. My hash rate varied from 1.6 H/s to 33.3 H/s. The average hash rate for the pool was 10.27 MH/s, approximately 3 million times my Pi’s hash rate. For reference, 1 MH/s is 1,000,000 hashes per second.
  • The mining pool company (in this case Minergate), also charges a small commission on your transactions. You have the choice of luck based commission (higher risk, higher reward), or Pay Per Share (higher commission for Minergate, but less risk).
  • At various points during the writing of this article, my Pi had numerous ‘time out’ errors and ‘send_line failed.’ Sometimes a reboot of the Pi would help, and sometimes, the miner would eventually start working again without human intervention.

Raspberry Pi Bitcoin Mining

(Image credit: Tom's Hardware)
  • Endymio
    it would take me 3,762 years to reach the minimum withdrawal threshold
    So in 38 centuries, you'll gross $5. The net's far worse, because I don't see anything on the description of that solar panel that indicates it will supply the Pi off solar power. In fact, given the manufacturer's refusal to place a wattage or time-to-charge under solar on the product description, I'd call the solar feature just a gimmick -- it's a plug in battery with a lamp on it.
    Reply
  • Findecanor
    Crypto-"mining" is a type of Ponzi scheme. Don't do it!
    Reply
  • damiebius
    Is it possible to enable GPU hardware accelaration on RPI ?
    Reply
  • SurJector2
    You don't need to become root to download and compile cpuminer so
    sudo git clone https://github.com/carolinedunn/cpuminer-multishould be
    sudo git clone https://github.com/carolinedunn/cpuminer-multiand
    sudo ./build.shshoud be
    ./build.sh
    Otherwise, nice post!
    Reply
  • Endymio
    Findecanor said:
    Crypto-"mining" is a type of Ponzi scheme. Don't do it!
    Leaving aside the issue of whether or not crypto currency is a Ponzi scheme, crypto mining certainly isn't. Let's use terms properly, shall we?
    Reply
  • jasonkaler
    Why not plug a usb crypto miner into your pi?
    They usually produce around 300MH/s at around 2.5-10W
    Reply
  • USAFRet
    jasonkaler said:
    Why not plug a usb crypto miner into your pi?
    They usually produce around 300MH/s at around 2.5-10W
    This was more a case of "Can it be done?"
    Rather than..."How to get the most Mh/s from a Pi."
    Reply
  • mogster
    A few questions:

    You mention the ARM CPU as a limiting factor. Would it work better with a cheap x86 unit like the Atomic Pi?

    The last time I checked, World Community Grid had a client for ARM but no actual jobs to process. Has that changed?

    Have you tried the xmrig miner?

    Is there any real use for Monero? No one seems to want it.
    Reply
  • surfacenoise
    Admin said:
    Is it possible to mine for cryptocurrency in 2020 with Raspberry Pi?

    How to Mine Cryptocurrency with Raspberry Pi : Read more

    If you want to go deeper down this rabbit hole I'd recommend investigating mining uPlexa instead of Monero on smaller devices like the Raspberry PI. More information here: https://www.uplexa.com/. While Monero has wider adoption, uPlexa is growing... you can exchange uPlexa for Ethereum on Stex and Bitcoin on Graviex.

    Because it's designed for IoT you won't run into issues with Bad or Invalid shares mining uPlexa on your Raspberry PI. There are pools like upxpool.com that offer ports with very low difficulty that are also perfect for older Android phones (you can mine using their dedicated Android app or run Ubuntu in Termux), Raspberry PI, etc.

    After overclocking my RPI4 and installing Raspberry OS 64 bit... I've been running xmrigCC for months and get a solid 1.1 kH/s hashrate. While that still will only net you about 19 cents a month at current values that's a significant improvement over Monero. And in 6 months uPlexa's exchange value has fluctuated significantly. That 19 cents was worth closer to 50 cents over the summer.

    More importantly... there's a ton of development happening with uPlexa. They will be launching a new update shortly called Steadfast Storm which includes a dVPN on the uPlexa network. Mining powers the network. And a few days worth of mining on your RPI should be more than enough to cover access.

    More on Steadfast Storm: https://medium.com/@uplexa/uplexa-steadfast-storm-masternodes-pos-pow-7e3db179438a
    xmrigCC mining uPlexa on my Raspberry PI 4:

    Reply
  • Redbot
    You don't need to choose between mining and helping cure COVID-19. You can do both with Gridcoin and World Community Grid.
    Reply