Saturday, 17 December 2016

RC Control Rover with FPV

RC Control Rover with FPV

Super Simple Fritzing Layout
This is a super simple way to get my Taranis to control my rover, its as easy as plug each channel into an Arduino input and read the pulse, I also added a 3 way switch to control the speed as I only needed three speeds.

The arduino code speaks for itself

>> Arduino Code <<

You can see the FPV DRV footage here :

You can see the FPV DRV footage here 

Tuesday, 13 October 2015

AntMiner U3 & Raspberry Pi running CGMiner

AntMiner U3 with a Raspberry Pi 2

Back in the day I used to run GPU miners and some of those 444MH/s USB miners, I ended up selling the GPU's as they were using more in electricity and got bored of the USB miners as they were not fast enough to really justify running them.

While ordering some other bits and pieces of Ali Express I came accros the AntMiner U3 and had to buy one especially for the price. I knew I would never get my money back, especially at the current Bitcoin price, but as I enjoy playing and as it was so cheap I thought why not.

Here is the link to the cheapest U3 I could find with free postage


Included is everything you need to get started, the ASIC, power and USB cable

While waiting for the miner I have been reading up on the U3, it very much looks like a budget miner that is for fun rather than a serious piece of hardware.

I am trying to keep the power consumption down to as little as possible which is why I decided to run this on a Raspberry Pi. Raspberry Pi 2 Model B (Quad Core CPU 900 MHz, 1 GB RAM)

All in all at the current Bitcoin price of $235 I would just about break even each month, not including the purchase cost, I am writing this off :-)

Lets go ahead and get it running!

First is to flash Rasbian on an SD card, I wont go through this process as it is heavily documented already. Install Raspberry Pi Image

Next is to download and compile cgminer, the only option required is the --enable-icarus option.

# apt-get install build-essential autoconf automake libtool pkg-config libcurl3-dev libudev-dev libncurses5-dev screen

cd /bitcoin/


tar -xvjpf cgminer-4.9.2.tar.bz2

cd cgminer-4.9.2/

./configure --enable-icarus


Next was to create a simple script to run cgminer in screen so I can connect to it whenever I wanted




screen -S cgminer -d -m /bitcoin/cgminer-4.9.2/cgminer -o <mining-pool>:<port> -u user.worker -p x --api-listen --api-allow W:


chmod +x


Perfect! cgminer installed and running on my Rapsberry Pi

About 18 hours running the U3 and it whent 'Zombie' on me!

The solution, build a script that runs every 5 minutes to monitor the hashrate through cgminer API and if its drops to 0, trigger a relay to reset the power to the U3 and then restart cgminer.

First off was to read the hash rate from cgminer API.

pycgminer is perfect for this and makes it so easy!

There are a few ways to install pycgminer, the method I chose was:

apt-get install python3-setuptools



pip install pycgminer


I created a very simple Python script to do this:



# Check if AntMiner has gone 'Zombie'
# Checks cgminer API using pycgminer
# Run cgminer with the --api-listen --api-allow W: to allow 'Write' access
# Connect relay live to COM and NC (Normally Closed)

import time
import RPi.GPIO as GPIO

from pycgminer import CgminerAPI
cgminer = CgminerAPI()

relayPin = 18 # Connect to IN on relay along with 5V and GND

GPIO.setup(18, GPIO.OUT)

lcd = cgminer.lcd()
hash = lcd['LCD'][0]['GHS 5s']
print " "
print "Checking if U3 has 'Zombied'..."
print "Hash rate is: ", hash, " GHS 5s"
if int(hash) < 1:
        print "ARGH!!! Setting GPIO Pin to HIGH"
        GPIO.output(relayPin, GPIO.HIGH)
        print "Waiting 15 seconds..."
        GPIO.output(relayPin, GPIO.LOW)
        print "Restarting cgminer..."
        print "YEY! Miner is up, move on nothing to see"


I use GPIO Pin 18 as the control pin and use pycgminer to retrieve the hash value from the API

Sorry, not the best photo, Relay is connected to 5v, GND and Pin 18

Add this to crontab to run every 5 minutes

crontab -e
*/5 * * * * /bitcoin/

 That should do it :)


Turns out I over complicated things a little :) All that is required is a restart of the Pi to get everything back up and running and to add the startup script to cron to run on a reboot, I just removed all GPIO references in the python script above and replaced with 'os.system('shutdown -r now') to restart the Raspberry Pi if the hashrate hits 0.

I added the below entry to cron

@reboot /bitcoin/

This seems to be doing the job nicely, I only have a 5 minute downtime when the U3 Zombies so I am very happy with that.

Sunday, 11 October 2015

Bluetooth Control via Android App

Next on the list was to add a Bluetooth module and create an Android app to be able to manually control the robot if so desired.

I picked up a cheap JY-MCU HC-06 off Ebay.

I also decided to pick up a logic level converter while I was at it as the HC-06 module ran at 3.3v and the Uno runs at 5v, I didn't have to purchase one as the tutorial talked you through using resistors instead but I thought I might as well as they were so cheap on Ebay.

For the Arduino sketch and Android app I followed these excellent instructions, no need to replicate what I did on my blog as these were perfect.

Swapped around some microcontroller

I started to run out of space on the robot so decided to swap out the Arduino Uno with a Teensy 2.0 I had spare, I could fit this on the breadboard already on the robot so didnt use any more room.

I had to amend the code very slightly, changing a few pin assignments and using hardware serial instead of software serial, other than that it was a pretty painless exercise.

I was also running low on pins using the Arduino mini so while I was at it I decided to swap the mini out with a Teensy 2.0++ that I also had spare, this gave me another 28 pins give or take for future sensors.

Not very tidy....

First batch of hardware!


I have just cut out a piece of card to lay everything out on, you can see the Raspberry Pi under the red motor controller and then an Arduino Uno connected via i2c.

Starting my journey into robotics

So I have wanted to build a robot ... so here goes!

I decided on the Sparkfun Rover 5 kit with 4 motors and encoders as this will get me started and cover me when I want to get a bit more complicated.

As for the controller I opted for the Dagu - 4 Channel DC Motor Controller with Encoder Support as again this will get me started and also cover me for when I want to play with the encoders.

I decided to add a Raspberry Pi and a few arduinos, not 100% required but I love working with them and wanted to split 'motor control' and 'sensor control' up for ease of debugging and future redundancy.

Initial thoughts are to communicate with the Pi over i2c, the Pi being the 'master' running a python program to control all the bits of the robot and the arduinos being 'slaves' listening for commands from the Pi or Serial and pyserial.

Here is my first mock up before receiving the Rover 5 kit of the pi controlling 4 LED's (representing each motor).

Saturday, 16 February 2013

Minecraft Pi API

Well what can I say, my love for Minecraft, my love for the Raspberry Pi, and my love for Python and Java.

How could I miss the opportunity to use all of these all together?

I couldn't!!!

So first of all lets download and run Minecraft Pi on my RPi, looks good, we are limited to creative mode at the moment and also I have no sound, but I only want to play with the API so thats not a problem.

I had a quick play with both the Python and Java API's and chose Java as there didn't seem to be many blogs about it and also I have a little experience with Java and like it.

I didnt fancy running Minecraft and also playing with the API all on my Pi so as you can connect to a remote minecraft instance from the API this is what I did.

Lets just have a little play and see what we can do. I thought something easy to start, how about get my players location and then be able to choose a block type using the id then simply place it next to the player.

Here is my simple java code:

 import java.util.Scanner;  
 import pi.Block;  
 import pi.Item;  
 import pi.Minecraft;  
 import pi.Vec;  
 public class API {  
      public static int a = 0;  
        public static void main(String[] args) {  
             Minecraft mc = Minecraft.connect(args);  
                mc.postToChat("Hello Minecraft Pi!");  
                while (a !=999){  
                     Vec pos = mc.player.getPosition();  
                     mc.postToChat("Player position is: " + pos);  
                     Scanner reader = new Scanner(;  
                     print("Enter a Block id");  
                     print("999 to exit");  
                     print(": ");  
                     pos = mc.player.getPosition();
           public static void print(String arg){  

This is a very basic crude example but hopefully it will help you started 

You could of course edit this to instead drop an item at your location when the API is ready etc, I really do love this API the possibilities are endless!

Next steps, control something physical either through the RPi's GPIO's or maybe using an arduino, any excuse :) one of my other loves

Control hardware from within the game, have hardware trigger something in game......