Homepage Wiki Forum Buy
embedded Linux Gnublin

Command line / scripts

Easy scripts for beginners

consoleThe easiest way to start into the world of automation is to build small shell scripts. You can build small loops, where you can for example the temperature for an limit. It the limit is reached you can start an motor or an fan.

It must not be always a huge software. Oft simple solution are a smart and quick way for solving a problem.

Example temperature sensor:

You can start reading out the temperature with the following command:

gnublin-lm75

You get the actual temperature in ° Celsius as output:

21 °C

You can also get JSON compatible output:

gnublin-lm75 -j

Then the output looks like this

{"temperature":"21","result":"0"}

 

Example

An easy blinking LED you can create with this script:

#!/bin/sh
# Blink the onboard LED

GPIO=3

cleanup() { # Release the GPIO port
  echo $GPIO > /sys/class/gpio/unexport
  exit
}

# Open the GPIO port
echo $GPIO > /sys/class/gpio/export
echo "high" > /sys/class/gpio/gpio$GPIO/direction

trap cleanup 2 # call cleanup on Ctrl-C

# Blink forever
while [ "1" = "1" ]; do
  echo 1 > /sys/class/gpio/gpio$GPIO/value
  sleep 1
  echo 0 > /sys/class/gpio/gpio$GPIO/value
  sleep 1
done

cleanup # call the cleanup routine

 

 

On this way you can build easy programs, like to measure temperature and if a value is reached to move an motor, send a mail or start the webcam and so on.