Monday, 20 May 2013


Earth Rover 

Part III

Providing Power, Direction and Speed Control


 Wiring the Motors, DPDT Relays and PWM to the MOSFET


The diagram above shows how I wired four of the DPDT relays (on my eight relay board) to control the direction and speed of the motors for the Rover's wheels.

A logic level, power N-MOSFET switches up to 8A (10A absolute max) to provide motive power at 12vdc vdc. The gate is controlled by an Arduino PWM pin so speed can be adjusted accordingly. However each individual relay is only capable of switching 2A at 12vdc, but that can give me 24watts, per wheel in theory.

Saturday, 18 May 2013

Earth Rover 

Part II

Android-Arduino User-Interface

Tablet Screen Shot

This is my first stab at producing a user interface to communicate with my Arduino Earth Rover over blue-tooth. I given links to the code below, it's a bit raw but there lots of work to do. You can send commands from the Android, like setting the speed and direction. Also there is some test code to confirm the sending of data from the Arduino, eg a bump sensor. When the correct data  is sent from the Rover an alert toast appears and the text of a button will change to red, depending on which side of the Rover was bumped.

***Disclaimer***
 * Please note this code is provided for free and AS IS. There is no support and no guarantee
 * from the Author. As a non-expert I am happy to answer constructive comments and questions.
 *****************
 *Subject to GNU licence version 3 and copyright of Craig Turner May 2013:

 * please use it, modify it, and enjoy it.
 * If you find it useful please link to my website:
 * http://gampageek.blogspot.co.uk/2013/05/blog-post.html
 *
 * Bluetooth coding based on Matt Bell's Blog here:
 * http://bellcode.wordpress.com/2012/01/02/android-and-arduino-bluetooth-communication/
 */
Arduino code here
Android code here


Earth Rover 

Part I

Arduino Semi-Autonomous Robot 

With Android User-Interface

Ok, I'm not even attempting to build something like the Mars Rover :o - but my mini budget earth rover is a good starting point for me to learn some more robotics. I've built RC and sequence (dancing) robots before see here, but not an autonomous robot with sensors that can find it's own way around a space.

I've pulled together some resources to start with, some used in previous projects:

  • A 4WD robot car chassis here

     
  • An android tablet
  • A Japanese eight module DPDT relay board from Ebay £29 [to direct power to the motors]

  • Arduino Mega 2560 dev board  from here

  • An OWI-535 Robotic Arm from here



  • An SRF05 ultrasonic sensor from here
  • A selection of micro-switches to act as bump-sensors from here


  • Discrete components such as power MOSFETs, power fly-back diodes, resistors, capacitors, leds, terminals, headers etc... from a standard electronic supplier eg here
https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Componentes.JPG/400px-Componentes.JPG
[Image is not of actual components used]


That's a start.

Coming soon in Part II -  Arduino remote control from an Android tablet over blue-tooth.


Monday, 8 April 2013


Chillout with The Relaxino Heart App

Copyright Craig Turner (Gampa Geek) April 2013.

 A few weeks back I posted some Arduino code designed to work with the Grove Heart Rate monitor (arduino-meets-yogic-arts). Since then I have developed an Android Application that works with Arduino over Blue-tooth to display your heart rate in a tablet user interface. It also provides simple biofeedback via the screen which flashes at your heart rate. The user can choose a target rate from 30 to 100 bpm, using a sliding seek-bar. The screen changes from purple to green when the target is achieved, enabling the user to practice breathing techniques, reduce heart-rate and so achieve a better level of relaxation, through biofeedback training.

Why did I bother? Well I had a heart attack about 8 months ago so this type of thing came uppermost in my mind. I now use the prototype Relaxino hardware and app to chillout and relax the heart.


Explanation of how it works.
It works by measuring your heart rate and taking an average over 20 beats.  An LED on Arduino pin 13 flashes each time your heart beats, because each beat triggers an external interrupt.  The average heart rate is sent every 20 beats over Bluetooth to the Android device.

You set a target rate on the Android, so a purple screen flashes when you are above target and a green one when you are at, or below the target heart rate. This allows you to try to relax and get feedback on how you are doing. Lie or sit down and try to relax, taking long deep breaths in and out, empty your mind and gently focus on the screen light (being in the dark helps so you can see the pulses through semi-closed eyelids).

Geekery Recipe:
Arduino
  • The device uses a RISING interrupt on pin 2, so attach the output wire (yellow) of the heart monitor to pin 2 of the Arduino.

  •  Black wire goes to ground and red to +5v.

  • Connect the Rx and Tx, power and ground of the Bluetooth module (mine is a BlueSmirf Gold) to the Arduino pins 4 and 5 respectively.
  • Attach the ear clip to your left ear. Beware some peoples ear lobes are too thick (mine are) so play around with the position. I had to put it on a thin flattish part of my ear.
  • Upload the code to the board.

  • LED on pin 13 will pulse at same rate as your heart. You can check by feeling the pulse in your neck. Both should be approx in sync.

  •  Open the serial monitor (for debug if required)

Android
  • Install the App - you can do this directly using Relaxino.apk, or create a project in Eclipse Juno, and cutting and pasting the .java and .xml files. NB the manifest and layout files are in the same .xml file. You might need the app icon too so I included it on the Google drive.
  •  Check the Arduino BT module is paired with your Android device (in Android settings). It may require a PIN but they are usually trivial numbers such as 0000 or 1234.
  •  Start the app and enter the name of your BT device eg FireFly-008A and click Open Connection.
  •  A connection should happen and a success message “Connection Opened: device_name ” appears. The message in the purple bar will say “Waiting...” If it fails just keep trying.
  •  Press reset on the Arduino – and the message should change from “Waiting” to “Sensing Heart Rate”.
  •  After 20 beats the message should read  “Your Heart Rate is: something bpm”
  • This is your actual average heart rate sent every 20 beats from the Arduino.
  • Set the target heart rate for your relaxation. When you reach the target the screen will change from flashing-purple to flashing-green.
  •  Lie or sit down and try to relax, taking long deep breaths in and out, empty your mind and gently focus on the screen light (being in the dark helps so you can see the pulses through semi-closed eyelids).
  • Gradually increase the length of the breaths, counting if you need to: 6-8 seconds for in, 6-8 seconds for out (or do whatever you can manage). Build up to longer and longer ins and outs. Don't rush it and get out of breath - your heart will beat faster!
  • With practice it can help you relax by providing simple biofeedback.
Screen Shot

Video of Relaxino

Grove Heart Rate Monitor - Ear Clip

Arduino and Android Code and App here:  Google Drive
App only is now on Google Play Relaxino
 App Icon: blueglassheart.png


/**
 * Communicate with Arduino over Blue-tooth to display your
 * heart rate in a tablet user interface. It also provides simple biofeedback
 * via a flashing screen which flashes with your heart rate. The user can choose
 * a target rate from 30 to 100 bpm, using a sliding seek-bar. The screen changes
 * from purple to green when the target is achieved, enabling the user to use breathing
 * techniques to reduce heart-rate and so achieve a better level of relaxation,
 * through biofeedback training.
 *
 ***Disclaimer***
 * Please note this code is provided for free and AS IS. There is no support and no guarantee
 * from the Author.As a non-expert I happy to answer constructive comments and questions.
 *****************
 *Subject to GNU licence version 3 and copyright of Craig Turner April 2013:

 * please use it, modify it, and enjoy it.
 * If you find it useful please link to my website:
 * http://gampageek.blogspot.co.uk/2013/04/chillout-with-relaxino-heart-app-few.html
 *
 * Bluetooth coding based on Matt Bell's Blog here:
 * http://bellcode.wordpress.com/2012/01/02/android-and-arduino-bluetooth-communication/
 */


Friday, 29 March 2013

Storage Options day-night IP camera


Following on from this thread:- http://arduino.cc/forum/index.php/topic,53498.0.html I bought a storage options day-night IP camera. Excellent value. Lots of functionality see:- http://www.storageoptions.com/products/ip-cameras/indoor/ip-camera Including motion alarm and night vision!

My only criticism is that support a bit poor especially zero support for so called advanced use of the motion sensing alarm output, which I guess is the one some arduino users would want to use. I know I did. However they do say up-front they don't support advanced use. But I though at least they could tell us what each of those terminal on the back are for!

Anyway after contacting Storage Options and getting nothing. I went on and worked it out so I thought to post an example in case anyone else wants a go!.

Arduino sketch below.

See the above drawing of the green I/O screw terminals on the back of IP camera. Wire up according to that and just follow the camera's manual for setup of alarms in the camera software.

Code ----------------------------------------------------------------------------------------------
const int IPalarm = 6;      // the number of the IP camera INPUT pin
const int ledPin = 4;      // the number of the LED pin to attach led with 560 ohm resitor
char flag1 = ' '; // char to store alarm data

void setup () {
 
// setup the arduino pins
  pinMode(IPalarm, INPUT);
  digitalWrite(IPalarm, LOW);

  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);


}

void loop () {
 
  if (digitalRead (IPalarm) == HIGH) // if IP camera alarm activated set flag1 to 'i'
 
   {
   
     flag1 = 'i';
   }
 
    switch (flag1) { // action according to flag1 (using switch case because I am using lots of different values of flag1 in a bigger project)
// could just use if... else

    case 'i': //IP motion alarm was triggered
      digitalWrite(ledPin, HIGH);
      break;
 
    default:  // No alarm
      digitalWrite(ledPin, LOW);

    }// end of switch case

}

Wednesday, 13 March 2013

Free Android Java Code

It can be tricky finding good resources when you are starting out, so I want to recommend the above website  for people studying programming http://www.deitel.com/. Once you register you get access to gigabytes of information, tutorials, code etc.. without even having to buy their books. AWESOME! Thanks Deitel. I am currently studying the Android-Programmers-App-Driven-Developer-ebook. I use the Java forum at Stack Overflow for asking questions. Happy Troll-free surfing ;)

There are probably others out there so I'll post them when I find them. Please feel free to post links to useful sites in the comments. Nice for viewing code outside of IDE: Programmer's Notepad.

Java Thread Example for a Beginner in Android

 /*
 * Simple use of Android Thread
 * Flash the screen between an array of colours at an interval
 *
 */

At first finding out how to work with threads in Android Java was quite tricky, so I've posted this simple example I put together from various tutorials and expert input from Stack Overflow.



Code:------------------------------------------------------------------

package biz.consett.mydraw;

public class AColor // a list of colours you can use in hex format
{

    final static int RED = 0xFFFF0000; // hex alpha_R_G_B
    final static int GREEN = 0xFF00FF00;
    final static int BLUE = 0xFF0000FF;
    final static int PURPLE = 0xFFAA00AA;
}


package biz.consett.mydraw;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

/*
 * Simple use of Android Thread
 * Flash the screen between an array of colours at an interval
 *
 */

public class MainActivity extends Activity
{

    static final int[] COLORS =
    {AColor.RED,  AColor.BLUE, AColor.GREEN};// colour array
    // Colour Red Green Blue
    // Index [0] [1] [2]

    private int currentColor = 0;

    private View MYVIEW = null;
    //boolean whichColor = true;

    final int interval = 100; // 0.6 second

    @Override
    public void onCreate(Bundle savedInstanceState)
    {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MYVIEW = (View) findViewById(R.id.my_view);

        MYVIEW.setBackgroundColor(Color.RED);// set initial colour

        new Thread(new Runnable()
        {

            // @Override
            public void run()
            {

                while (true)
                {
                    try
                    {
                        Thread.sleep(interval); // sleep for interval
                      
                    }
                  
                    catch (InterruptedException e)
                    {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                        updateColor();
                  
                } // end of  while true loop
              
              
            }// end of run

        }).start(); // end of runnable

    } // end of onCreate bundle

    private void updateColor()
    {
      
        runOnUiThread(new Runnable()
        {

            @Override
            public void run()
            {

                if (currentColor > COLORS.length - 1)
                {
                    currentColor = 0;
                  
                }
                MYVIEW.setBackgroundColor(COLORS[currentColor]);
              
                currentColor++;
              
            }// end of run
        });
      
    }
}// -------------END OF MainActivity extends Activity-----------------------


MANIFEST:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="biz.consett.mydraw"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="biz.consett.mydraw.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


LAYOUT:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    
    <View
      
    android:id="@+id/my_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  
    </View>
  
</RelativeLayout>


END CODE:-----------------------------------------

Wednesday, 20 February 2013

Arduino for Android


Well what the heck have I been doing for the past three weeks? It seems like I've been going around and around in circles trying to research resources on the www to help me learn how to make apps for Android and so eventually develop accessory applications. Why so hard so far?

Strengths
  • Done some java before
  • 18 months of Arduino
  • Some electronics knowledge
Weaknesses
  • New to smart phones and tablet PCs
  • New to Android dev tools
  • New to Eclipse Juno 
  • New to USB protocol and Java supported classes
  • ......
So on balance it seems the weaknesses greatly outweigh the strengths, huh? Like for a lot of Silver Surfers, the mobile computing side has snook up on me. I have always had a mobile phone - I recall a huge one I had in 1990 (about the size of a briefcase and most of it was the battery).



I mostly use my now tiny featureless phone for texts and calls. I have a Dell mini with 3G that never got used over 3G, because I always used local WiFi  - a lot cheaper.

Moving on to Android


Apart from being new to all of this, the hardest part was finding out which tablets (or phones) supported Android Accessory and the ADK.

  • It isn’t just a case of getting a tablet with the correct operating system, because some hardware doesn’t support it even when the manufacturer claims it so! My cheap and cheerful tablet (<£100)  doesn’t, so beware of these.  You can build and run non-accessory apps on these of course.
  • Hardware claims by the manufacturer may be let down by the USB chip in the machine not having the correct drivers, also some of these tablets have little or no support. In fact that seems to be a symptom of the low-end Android industry
  • But they may not support future.usb and so the example code needs non-trivial modification, at least for a new starter. You need to use hardware.usb in that case.

Ok that’s the whinge over - to positive thought and actions!
I need to order a Google Nexus 7 (from Google Play) and an Arduinomega ADK By doing this I hope to reduce my unknowns. The Nexus also supports Blue Tooth, which will also come in handy when paired with a BlueSmirf module see link: Android-Arduino over BT.
So there should be cross-compatibility with most of the stuff I want to do with my Android tablet and Arduino to learn about making Android USB accessories.
Here are some websites and tutorials I used and found very helpful:
Making Android Apps in Eclipse Juno
I got the above tutorials working nicely on my low-end Tablet (ICS 4.0.3)

Very interesting post on Android and Arduino BT

Android Lectures 
This is a Chinese website but the lectures are in English. Lecture 16 and 17 are usb.hardware.
The ones below obviously didn’t work yet (need the new Tablet):
And the associated book website: http://www.duinodroid.com
I'll keep posting updates as I progress in the development of Arduino for Android.