Arduino IsNumeric Function

I needed an “IsNumeric(string)” function for some Arduino code I’m writing and couldn’t find one in the libraries so I thought I’d share mine:

EDIT: updated version:

boolean isNumeric(String str) {
    unsigned int stringLength = str.length();
 
    if (stringLength == 0) {
        return false;
    }
 
    boolean seenDecimal = false;
 
    for(unsigned int i = 0; i < stringLength; ++i) {
        if (isDigit(str.charAt(i))) {
            continue;
        }
 
        if (str.charAt(i) == '.') {
            if (seenDecimal) {
                return false;
            }
            seenDecimal = true;
            continue;
        }
        return false;
    }
    return true;
}
boolean isNumeric(String str) {
    for(char i = 0; i < str.length(); i++) {
        if ( !(isDigit(str.charAt(i)) || str.charAt(i) == '.' )) {
            return false;
        }
    }
    return true;
}

There are a few tweaks that should be added (such as counting decimal points as this would currently except 12.34.56 which is clearly not a valid number), this is a good starting point however. Done.

Hope that’s useful for someone!

Installing mariadb for CentOS

Reference commands for install and setup of mysql / mariadb on red hat distros like CentOS.

The below commands install the server, enable the database service to start on boot, setup the database service and finally start the service.

yum install mariadb-server mariadb

systemctl enable mariadb.service

mysql_secure_installation

systemctl start mariadb.service

Install SVN from source

I’ve been having problems recently with SVN not being kept up to date on a company repo. So I installed SVN from source so that I could use a modern GUI.

(smartsvn has a free version which I opted to use but once it had upgraded my repos they no longer worked with the command line client – so that needed updating)

Installing from source

yum update
yum groupinstall "Development tools"
yum groupinstall "Additional Development"
wget https://archive.apache.org/dist/subversion/subversion-1.8.9.tar.gz
tar zxvf subversion-1.8.9.tar.gz
cd subversion-1.8.9
./get-deps.sh
./configure
make
make check
sudo make install

If APR and APRUTIL cannot be found

If you find that it complains about APR and APRUTIL missing during the configure command then run this line instead:

./configure --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr/

Rotate a point around another point code

If you need to rotate a point around another point in 2D then here is a nice function. The below is in C#.

/// <summary>
/// Rotates 'p1' about 'p2' by 'angle' degrees clockwise.
/// </summary>
/// <param name="p1">Point to be rotated</param>
/// <param name="p2">Point to rotate around</param>
/// <param name="angle">Angle in degrees to rotate clockwise</param>
/// <returns>The rotated point</returns>
public Point RotatePoint(Point p1, Point p2, double angle) {

    double radians = ConvertToRadians(angle);
    double sin = Math.Sin(radians);
    double cos = Math.Cos(radians);

    // Translate point back to origin
    p1.X -= p2.X;
    p1.Y -= p2.Y;

    // Rotate point
    double xnew = p1.X * cos - p1.Y * sin;
    double ynew = p1.X * sin + p1.Y * cos;
    
    // Translate point back
    Point newPoint = new Point((int)xnew + p2.X, (int)ynew + p2.Y);
    return newPoint;
 }

 public double ConvertToRadians(double angle) {
     return (Math.PI / 180) * angle;
 }

Enjoy 🙂

Robot Prototype 2 chassis

The previous robot prototype chassis did not work very well on high friction surfaces (carpets, grass etc.). Thus prototype 2 was born.

The problems were caused by 2 things as far as I can tell, trying to skid all 4 wheels and also having 4 motors that did not have enough torque. This lead to Prototype 1 stalling frequently when rotating.

Continue reading Robot Prototype 2 chassis

Using windscreen wiper motors for a robot

A DC motor is a DC motor…. right? No, it’s not always that simple.

windscreenwiper-motor

Windscreen wiper motors are fairly cheap when bought second hand from a scrap yard (where I got mine from) and give very good torque for larger robotics projects. You’ve just got to be aware of a couple of things before getting started.

Continue reading Using windscreen wiper motors for a robot

Test internet connectivity from bash script

Ensure you have curl installed and then you can use the following bash code in your scripts to test for internet connectivity.

 

#!/bin/bash

echo "Testing connection..."

curlOutput=$(curl -I http://google.com)

# Possible cases, there are more but here we cover:
# 407 which can mean bad proxy details,
# 200 which means everything is OK,
# 302 which is a redirection but for us that's OK too.

if [[ $curlOutput == *"407"* ]]
then
 echo "No internet connection, bad proxy username / password";
 return
fi

if [[ $curlOutput == *"200"* ]]
then
 echo "internet connection OK";
 return
fi

if [[ $curlOutput == *"302"* ]]
then
 echo "internet connection OK";
 return
fi

 

Enjoy 🙂

Google now allows up to 50,000 songs to be uploaded to your Google account

As you may be aware Google Music allows user to both buy music but also upload any music files they already have to their Google account. This means you can then listen to your music from any device or browser, with the added ability to cache or ‘pin’ content locally so you don’t rinse your mobile data limit.

Google has now increased the limit of uploadable songs from 10,000 to 50,000 so all of you with huge music collections can now really listen to all of your music anywhere you go on any device!