Pages:
Author

Topic: Walkthrough: Raspberry Pi/Block Erupter mining rig setup with autostart and vnc - page 3. (Read 30950 times)

newbie
Activity: 10
Merit: 0
You are using quite an old version of cgminer (3.1.1) here. As a heads up for any newbies reading this, this is the latest version that supports the -S parameter. More recent versions expect to communicate directly with the the USB driver, so the setup procedure is quite different. Perhaps you would like to update your tutorial with this information?
That's a good point. I did compile the latest version (3.3.1), but couldn't get it to run. But if I can get it to run, I'll post the instructions here.
full member
Activity: 196
Merit: 100
You are using quite an old version of cgminer (3.1.1) here. As a heads up for any newbies reading this, this is the latest version that supports the -S parameter. More recent versions expect to communicate directly with the the USB driver, so the setup procedure is quite different. Perhaps you would like to update your tutorial with this information?
newbie
Activity: 26
Merit: 0
      Walkthrough: Raspberry Pi/Block Erupter mining rig setup with autostart and vnc

      Objective

      The objective of this project was to put together a Raspberry Pi controlled Block Erupter USB mining rig using CGminer, that is contributing to a mining pool (in this case Slush's mining pool https://mining.bitcoin.cz/), with enhancements that make it headless, with automatic log on and start up, whilst being accessible via VNC.

      There are already some very good tutorials out there (used here), but I found that each of these had slighlty different enhancements of no interest to me, which meant that their specific commands were not ideal. So this is my attempt as muddling through things, interfacing different solutions together to get what I need, and troubleshooting problems as they arise using online sources. I hope others find this walkthough useful, I am sure that you'd be able to find these solutions for yourself, but I thought it might be useful for others who maybe are less confident or don't know the right search terms to put into Google. Plus it's a record in case I forget should I need to recreate it.

      If you do find this walkthrough a timesaver, and something that gets you up and running, you might like to buy me a shandy or two by tossing me a few milibits:
      bitcoin:1PhtdmAhwUB2ywGiYGEYHLY7ponXykKfBY

      http://s22.postimg.org/ou7ozavep/miner.jpg
      (updated image 1/8/13 - everything is fixed on a heavy stand that provides a nice volume of air underneath. There are two Arctic Breeze mobile fans in there too)


      As pointed out by J35st3r, the version of CGMiner that the tutorial below get's you to install is version 3.1.1. Apparently (according to the Adafruit tutorial) http://learn.adafruit.com/piminer-raspberry-pi-bitcoin-miner/install-cgminer the most recent version 3.3.1 has problems addressing the USB devices under Raspbian. But I'd be interested in trying it out sometime

      Sources


      Equipment

      • Raspberry Pi
      • SD Card (I use a 2gb one)
      • Powered USB hub/s, choose one that has an adapter that will allow for 0.5amps per block erupter. You may be able to power the raspberry pi from this also, plus an optional fan. (The Raspberry Pi has one microUSB connection for it's power but you must also use one of it's full sized USB sockets to carry data to the hub). I use Belkin USB2.0 4-port F5U23QEA, which has a 2.6A adapter which should allow for 4 block erupters ok, or if powering the RPi and a fan then 3.
      • Asicminer usb Block Erupter. I first heard about these through the Raspberry Pi blog (http://www.raspberrypi.org/archives/4243), having previously used ATi cards for mining. Adafruit talks about using Bitmit, and there are inticing prices if you can but some Bitcoin, but there are also some UK scammers on there (just make sure that you make use of it's Escrow service). Prices on eBay are coming down. All the calculators out there such as this one suggest that with ever increasing mining difficulty (as more bitcoins get released), it's pretty clear that this is a project just for kicks rather than income, and this diversion is going to be costing you money for the privillage of playing a miner. Still apparently the world is aching for a decentralised currency outside of local govt control, and if the oil producing countries get on board there is a potential to destablise the dollar, and things might get interesting (according to my economist friend over a pint that is!)
      • Monitor (hdmi, or hdmi to dvi cable), usb keyboard, mouse


      Prerequisites

      • You will have and account created at Slush's Mining Pool.
      • On the My account screen of Slush's, you will need to have registered a new worker as your RPi, giving it a descriptive name for yourself and password, leaving the difficulty as unset or auto.
      • You may wish to set up a Bitcoin wallet. There are many to choose from but I just use the main one 'Bitcoin-Qt. This is a piece of software that you have installed on a computer. When you first run it it takes ages to download all of the blocks of the blockchain (probably an overnight job). But afterwards on the Recieve tab you can create new addresses, and create one of these to enter into Slush's My account page for when it pay's out. Also in the My Accounts screen you might want to set a more manageable payout threshold from 1BTC to maybe 0.15BTC.

      Instructions
      Step 1 - Prepare the Raspberry Pi

      • 1. Download the most recent version of Wheezy from the RaspberryPi foundations website (http://www.raspberrypi.org/downloads). This is the operating system for the RPi, that sits on the SD card. I extract it onto the SD card on a PC with a card reader and Win 32 Disk Imager. When you turn on the Raspberry Pi the username is 'pi' and the password is 'raspberry', and after this you are taken to the bash prompt (which looks like Command Prompt in windoze).
      • 2. Now to install CGminer on the Raspberry Pi, follow the instructions from the Adafruit tutorial on installing software. You need to have an internet connection, via ideally an ethernet cable  which is the route covered here. You can control the Raspberry Pi over SSH as the tutorial suggests, but for simplicity for the initial setup use a local monitor via hdmi, or a hdmi to DVI adapter, keyboard and mouse. The tutorial will ask you to enter commands into the bash: you can either do this directly in the bash terminal (after you enter the username and passwd above), or you can launch LXDE which is a gui interface similar to windows, which means that you can enter the commands through a windowed application called LXterminal, but you can also have a website open in Midora so that you can copy an paste the tutorials commands from the interent instead fo having to type them in. Run LXDE in the first place by typing 'startx' when you reach the initial bash terminal, and both Lxterminal and Midora have icons on the desktop.

              Other things worth mentioning:
        • In LXDE you can logout which returns you to the bash terminal.
        • In either the LXterminal window or at the bash you can enter these two commands 'sudo reboot' and 'sudo halt' to restart or shut down the raspberry pi nicely.
        • A lot of commands start out with the word sudo, which is essentially gives your authorisation as a super user on the computer for commands considered risky for the system (think Windows 7 constantly firing up it's UAC each time you want to install something)
        • Another common thing and a feature in the instructions is to use the command nano, this fires up a basic text editor in which you can enter/edit text and then save it out to the same or a new file.
      • 3. So following Adafruit's instructions you install CGminer. Ignore the PiMiner step, but go to the next page Configure Settings where you set up a config file for CGminer to tell it about your setup and your username and password. Use your Slush miner login details as created in the prereqs section above. The PoolAddress as suggested in the tutorial is the one you need ("http://stratum.bitcoin.cz:3333").

      Now with Cgminer installed, and the config file setup, how do we actually run Cgminer for the first time just to check that everything works?

      Step 2 - Initial check of hardware
      Here we need to bifurcate slightly from the Adafruit tutorial, because they want us to use PiMiner using their LCD Raspberry Pi shield, which is nice but not what we are after.

      • 1. First we need to find out what hardware address the RPi has given our block erupter (plug it in now if it is not, via the powered USB hub). The Start Mining page of the Adafruit tutorial tells how to so this, essentially type this at either the Bash terminal or LXterminal from within LXDE:
              ls /dev/*USB*
        This should give you some addresses such as /dev/ttyUSB0 which you should make a note of.
      • 2. Next we need to return the rpi back to the root directory rather than any subfolders such as the one for cgminer. Enter:
             cd\
        (this returns the bash prompt back at the root directory, so afterwards you should see pi@raspberrypi ~ $ instead of pi@raspberrypi ~/cgminer-3.1.1 $.
      • 3. Now to launch cgminer, in a slightly different way from the Adafruit tutorial. Enter:
             sudo ./cgminer-3.1.1/cgminer --config /home/pi/cgminer.conf -S /dev/ttyUSB0
        (if you have more than one block erupter add extra of these -S /dev/ttyUSB1 and -S /dev/ttyUSB2 and so on. This command launches cgminer, tells about the config file and the hardware we want it to use.


      Now hopefully you should see CGminer starting up, then connecting to your pool, and then starting to receive and send work (Accepted blocks). If there are any problems then check things such as your cgminer config file, by retracing your steps.

      http://s17.postimg.org/k34h33c1r/cgminer.jpg

      Step 3 - Set up Auto-login and autostart of Rpi and CGminer
      Next up, to set it so that the Raspberry Pi automatically starts mining when the Raspberry Pi is turned on, without any intervention. This means that if there is a power cut it comes back online unaided, and also we can do away with the keyboard and mouse and screen. You can set it so that it mines without having to run through LXDE (loads CGminer directly at the bash), but you lose the ability to use VNC, and whilst you can use SSH to control the computer there are disadvantages to this which I will come on to in the next section. There did not seem to be any advantages in hashrate one way or the other, so do it like this.

      • 1. Follow the instructions in Issue 3, page 3 of the excellent Raspberry Pi fanzine The MagPi: http://issuu.com/themagpi/docs/the_magpi_issue_3_final?e=4599523/2586562

              Rebooting (sudo reboot in the bash/lxterminal) you should find that from power on, the Rpi automatically fires up LXDE. Ok, but what about firing up CGminer with our settings?
      • 2. To do this we follow part of Jafc76's super tutorial: https://forums.butterflylabs.com/bitcoin-discussion/3238-super-tutorial-raspberry-pi-raspbian-cgminer-tightvnc-wifi-boot.html.Look down his walkthrough until you see " - The last step is to autostart CGMiner every time...." in step 10. At the bash/lxterminal prompt enter:
              sudo nano /etc/xdg/lxsession/LXDE/autostart
      • 3. Then (slightly different from his instructions) type:
             @/usr/bin/lxterminal --geometry=90x35 -e sudo ./cgminer-3.1.1/cgminer --config /home/pi/cgminer.conf -S /dev/ttyUSB0 -S /dev/ttyUSB1 -S /dev/ttyUSB2 -S /dev/ttyUSB3 -S /dev/ttyUSB4 -S /dev/ttyUSB5
              (adding or taking extra block erupters if required). This tells cgminer about the config we want it to use.
      • 4. Now rebooting the machine (sudo reboot), you should find that Rpi fires up LXDE, and then launches cgminer in a window. If it does not check that you entered the above correctly.

      That means that we can now get rid of the screen and keyboard, and locate the machine somewhere remotely, but what about if we want to be able to remotely access the machine and update it's settings in some way?

      Step 4 - Setting up VNC access
      This is for controlling the Raspberry Pi remotely through another computer and the network rather than having to use a monitor, keyboard and mouse directly on the Raspberry Pi. There are two options put forward in the tutorials, neither work well enough for what we need:
      • Control the bash remotely using SSH, this is good if you run CGminer outside of LXDE, or for basic stuff like rebooting (sudo reboot) etc. Follow the Adafruit instructions here.
      • Alternatively run a VNC server, gives you the ability to control LXDE as if you were sat in front of it, giving you a moving image screenshot of what would be on the screen. Adafruit's instructions for this are here.

      The trouble with both of these is that when you login via these means it creates a second and new concurrent user session, so you can't see what the original one in terms of seeing what is the current session/desktop is doing. This is clever stuff and a fundamental basis of Linux, but no good when you want to dip in every now and again to see how CGminer and the block erupters are getting on.You need to have access to the actual session, not have create a new one.

      • 1. To solve this, I followed the instructions here http://www.raspberrypi.org/phpBB3/viewtopic.php?p=108862#p108862. This installs x11vnc instead of the tightvncserver Adafruit uses, which is still VNC protocol but lets you control the existing user session.
      • 2. Now after a restart (sudo reboot) you should find that you can log-in remotely to the existing session. On my Windows7 machine I use TightVNC viewer.
      • 3. You'll need the IP address of your Raspberry Pi to connect. To find this, type this into the bash on the Raspberry Pi (so don't disconnect the monitor, mouse and kb just yet!)
              sudo ifconfig

              It should be the first IP address (i.e. 192.168.1.7). This gives you the ip address of the rpi. If you connect to the internet through a router, this may be only a local network address; if you would like to access the RPi from outside your local network you'll need to set up port forwarding on your router.
      • 4. So this works great until you disconnect your monitor and then that VNC is now giving you a crappy 640x480 resolution when you next connect. This seems to be becuase the Raspberry Pi, detects no HDMI connection, and then gives you a composite video sized desktop. I tried various things that didn't work, but finally found this thread: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=19600

              The solution for me was identified by the poster Simon. In the bash/Lxterminal enter:
              sudo nano /boot/config.txt

              Then in the nano editor, scroll downwards a few pages until you see the line '#hdmi_force_hotplug=1' and delete the # (making the line of code visible to the machine). I didn't need to go any further, as I was quite happy with the widescreen HDMI dimensions over anything like VGA.
      • 5. Reboot the computer, and then give it 10-20 seconds to boot into LXDE by itself again, and then you should be able to access it from you favourite vnc client.

      http://s17.postimg.org/4wyfc5m0v/cgminer_vnc.jpg

      Using the system

      • For mining the system should 'just work', provided that it has an ethernet connection, block erupters, and sufficient usb power.
      • To check things quickly you can log into the My Accounts page of Slush's website, to check that last share is at 0minutes ago.
      • If you need to restart cgminer for whatever reason, I think it's preferable to quit CGminer via the Q key, and then do a sudo halt, or sudo reboot. Although pulling the plug I think is ok
      • If you need to change any settings, then VNC into into the RPi, after powering on and leaving it for 10-20 secs for LXDE to load
      • If you want to add further block erupters then you need to find their addresses (see Step 2 ls /dev/*USB*), then edit the /etc/xdg/lxsession/LXDE/autostart text file in Step 3 to include the new address/es
      • If you move your miner to a new location and new ethernet/IP address, you'd need to reconnect a monitor and keyboard/mouse to run the sudo ifconfig command again, although I think there is software to sniff out local IP addresses which you could use to identify the rpi.


      Power consumption
      According to my maplins energy meter, at 12p/kwh (EDF 2013), for 744 hrs/month.

      • Raspberry Pi alone - 5w - £0.48 p.m.
      • Raspberry Pi w. 1 block erupter - 8w - £0.77 p.m. (335mh/s)
      • Raspberry Pi w. 2 block erupter - 11w - £1.06 p.m. (670mh/s)
      • Raspberry Pi w. 6 block erupters - 28w - £2.50 p.m. (2004mh/s) (actual with seperate wallwart for RPi)


      Things I'd like to improve
      Any pointers or suggestions I'd welcome

      • It would be nice to find out how to tie the cgminer launch command to an LXDE desktop icon, so that I would not have to reboot the machine to relaunch cgminer or manually type it into lxterminal
      • A failover device that would monitor the hashrate of CGminer and restart either CGminer or the system if it detected a crash of some sort
      • In cases where the Rpi freezes completely, the ability to remotely or automatically restart the rpi
      • Add wifi capabaility instead of ethernet. This is really easy to do given the time, although certain Aruba wifi networks I use have complicated browser based logins that I'm not sure how it would work with RPi, and seondly at home I'd be worried about my wifi router freezing up every now and again.
      • Try out the MinePeon project to see how it compares
      • Try out with a more recent version of CGMiner - I'd have to move away from the Adafruit guide though so a big job I think
      • A way of bringing down the difficulty of bitcoin mining for a few months  Wink


      Updates to this post
      14/07/13 - Added info about the old CGminer version used[/list][/list]
      01/08/13 - Updated image to show setup with Arctic fans

      Updates to add when I get round to it
      01/08/13 - Add info about adding a backup pool to cgminer.conf
      Pages:
      Jump to: