Friday, September 19, 2014

Display CPU Frequency monitor on Raspberry Pi Task Bar

To enable CPUFreq frontend applet on your Raspberry Pi taskbar to monitor CPU frequency:




  • Right click Task Bar
  • Select Add/Remove Panel Items
  • Select CPU Usage Monitor, click Add.
  • CPUFreq frontend, click Add.

CPUFreq frontend applet will be added on your Task Bar. To monitor your CPU frequency, move mouse hover over the CPUFreq frontend applet.


Tuesday, September 16, 2014

Sunday, September 14, 2014

Python + bottle@Raspberry Pi: Web based GPIO control

This example show how to program in Python with bottle on Raspberry Pi, to implement web base GPIO control.

bottle is a Python web server library. To install bottle on Raspberry Pi, enter the command:
sudo apt-get install python-bottle


Create webled.py
from bottle import route, run
import RPi.GPIO as GPIO

host = '192.168.1.105'

pinButton = 17
pinLed = 18
GPIO.setmode(GPIO.BCM)
# pin 17 as input with pull-up resistor
GPIO.setup(pinButton, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# pin 18 as output
GPIO.setup(pinLed, GPIO.OUT)

LedState = False

def read_button():
    if GPIO.input(pinButton):
        return 'Released'
    else:
        return 'Pressed'

def update_led():
    GPIO.output(pinLed, LedState)
    
def toggleLed():
    global LedState
    LedState = not LedState
    
@route('/')
@route('/<arg>')
def index(arg=""):
    if arg == "toggle":
        toggleLed()
        
    update_led()
    
    response = "<html>\n"
    response += "<body>\n"
    response += "<script>\n"
    response += "function changed()\n"
    response += "{window.location.href='/toggle'}\n"
    response += "</script>\n"
    
    response += "Button: " + read_button() +"\n"
    response += "<br/><br/>\n"
    response += "<input type='button' onClick='changed()' value=' LED '/>\n"
    response += "</body></html>\n"
    return response
    
run(host=host, port=80)

Run it:
$ sudo python webled.py



Related:
- Web control to display on Pi connected LCD Module, with Python and bottle

Python RPi.GPIO: Read Button using GPIO.add_event_detect() with callback

The example show how to detect events of GPIO, to detect button pressed/released. It have the same operation in the post "Python RPi.GPIO: Button and LED".



import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
# pin 17 as input with pull-up resistor
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# pin 18 as output
GPIO.setup(18, GPIO.OUT)

def ButtonCallback(channel):
    if (GPIO.input(17)):
        GPIO.output(18, False)
    else:
        GPIO.output(18, True)
    
GPIO.add_event_detect(17, GPIO.BOTH, callback=ButtonCallback);

while(True):
    #do nothing
    time.sleep(1)

Friday, September 12, 2014

Learn about physical computing with Raspberry Pi

New Raspbian (and NOOBS) available

New release (2014-09-09) of Raspbian, and also New Out Of the Box Software (NOOBS), available.

  • New firmware with various fixes and improvements
  • Minecraft Pi pre-installed
  • Sonic Pi upgraded to 2.0
  • Include Epiphany browser work from Collabora
  • Switch to Java 8 from Java 7
  • Updated Mathematica
  • Misc minor configuration changes

Download: http://www.raspberrypi.org/downloads/


Python RPi.GPIO: Button and LED

This example read button input from pin 17 (set as input with pull-up resister) and set output to pin 18 to turn ON/OFF LED accordingly.



The code GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) set pin 17 as input with pull-up resistor. If you omit the option pull_up_down=GPIO.PUD_UP, the pin will have no pull-up resistor, and become un-stable.

led.py
import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)
# pin 17 as input with pull-up resistor
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# pin 18 as output
GPIO.setup(18, GPIO.OUT)

while(True):
 if (GPIO.input(17)):
  GPIO.output(18, False)
 else:
  GPIO.output(18, True)


Next:
Read Button using GPIO.add_event_detect() with callback

Wednesday, September 10, 2014

Raspberry Pi Python exercise: Change GPIO LED brightness with GPIO.PWM

Example of Python on Raspberry Pi, to change GPIO LED brightness with GPIO.PWM.



led.py
import RPi.GPIO as GPIO
import time

led_pin = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT)

#frequency 500 Hz
led_pwm = GPIO.PWM(led_pin, 500)
#duty cycle = 100
led_pwm.start(100)

while(True):
    led_pwm.ChangeDutyCycle(100)
    time.sleep(1)
    led_pwm.ChangeDutyCycle(80)
    time.sleep(1)
    led_pwm.ChangeDutyCycle(60)
    time.sleep(1)
    led_pwm.ChangeDutyCycle(40)
    time.sleep(1)
    led_pwm.ChangeDutyCycle(20)
    time.sleep(1)
    led_pwm.ChangeDutyCycle(0)
    time.sleep(1)


Connection, check lst post of "Toggle LED on GPIO".

Raspberry Pi Python exercise: Toggle LED on GPIO

Python example run on Raspberry Pi, to toggle GPIO pin for LED.

connection:

Example code, led.py:
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

while(True):
    GPIO.output(18, True)
    time.sleep(1.5)
    GPIO.output(18, False)
    time.sleep(0.5)


Run it with sudo:
$ sudo python led.py

Next:
Change GPIO LED brightness with GPIO.PWM

Saturday, September 6, 2014

java-google-translate-text-to-speech, unofficial API for Google Translate in Java.

java-google-translate-text-to-speech is API unofficial with the main features of Google Translate in Java. I will add text-to-speech (tts) function in my next Yahoo Weather exercise.

This video show how to download jars, and add library to Netbeans Java project.

Install espeak, Text to Speech (Speech Synthesis), on Raspberry Pi

eSpeak is a compact open source software speech synthesizer for English and other languages, for Linux and Windows.   http://espeak.sourceforge.net.

To install espeak on Raspberry Pi, enter the command:
sudo apt-get install espeak

To test:
$ espeak hello




Play mp3 on Raspberry Pi

To play mp3 on Raspberry Pi, using omxplayer command:

example:
$ omxplayer HelloWorld.mp3


scp, easiest way to copy file from Linux PC to Raspberry Pi

Example:

$ scp HelloWorld.mp3 pi@192.168.1.105:~/


Friday, September 5, 2014

Download and add Apache HttpComponents jar to Netbeans Project

In the coming post, I have to use Apache HttpComponents jar in my code. The Apache HttpComponents™ project is responsible for creating and maintaining a toolset of low level Java components focused on HTTP and associated protocols.

It can be download here: http://hc.apache.org/.

This video show how to download and add the Apache HttpComponents jar to your project in Netbeans.

Thursday, September 4, 2014

Epiphany browser for Raspberry Pi released

Epiphany released, it is a improved web browser for Raspberry Pi. To install on Raspberry Pi, enter the command in Terminal:

$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo apt-get install epiphany-browser



Source:
http://www.raspberrypi.org/web-browser-released/

Wednesday, September 3, 2014

Java serial communication with Arduino Uno with jSSC, on Raspberry Pi

jSSC (Java Simple Serial Connector) - library for working with serial ports from Java. jSSC support Win32(Win98-Win8), Win64, Linux(x86, x86-64, ARM), Solaris(x86, x86-64), Mac OS X 10.5 and higher(x86, x86-64, PPC, PPC64).

This post show a Java program run on Raspberry Pi, using jSSC library, to send message to USB connected Arduino Uno board.


The development platform is a PC running Ubuntu with Netbeans 8, and deploy the program to Raspberry Pi remotely.

- To add jSSC library to our Netbeans Java project, read the post "Install and test java-simple-serial-connector with Arduino".

- The program code is almost same as the code on the page. With 3 seconds delay after serialPort.openPort(), to wait Automatic (Software) Reset on Arduino Uno board.
package java_jssc_uno;

import java.util.logging.Level;
import java.util.logging.Logger;
import jssc.SerialPort;
import jssc.SerialPortException;

public class Java_jSSC_Uno {

    public static void main(String[] args) {
        SerialPort serialPort = new SerialPort("/dev/ttyACM0");
        try {
            System.out.println("Port opened: " + serialPort.openPort());

            try {
                Thread.sleep(3000);
            } catch (InterruptedException ex) {
                Logger.getLogger(Java_jSSC_Uno.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            System.out.println("Params setted: " + serialPort.setParams(9600, 8, 1, 0));
            System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("Java_jSSC_Uno".getBytes()));
            System.out.println("Port closed: " + serialPort.closePort());
        }
        catch (SerialPortException ex){
            System.out.println(ex);
        }
    }
    
}

- To deploy to Raspberry Pi remotely with Netbeans 8, refer to the post "Set up Java SE 8 Remote Platform on Netbeans 8 for Raspberry Pi".


For the sketch (and extra info) on Arduino Uno, read the post in my Arduino blog.


Node.js Chat Server on RPi, send msg to Arduino Uno, display on LCD Module

This example combine the last post of "Node.js Chat application using socket.io, run on Raspberry Pi", and "Node.js send string to Arduino Uno" in my another blog for Arduino. To create a Chat server, and send the received messages to USB connected Arduino Uno board, then display on the equipped 2x16 LCD Module on Arduino.


In order to use serialport in Node.js to send message to serial port, enter the command on Raspberry Pi command line to install serialport.
$ npm install serialport

Modify index.js in last post to add handles for serialport.
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort('/dev/ttyACM0', 
    {   baudrate: 9600
    });
    
serialPort.on("open", function () {
    console.log('open');
});

app.get('/', function(req, res){
  res.sendfile('index.html');
});

io.on('connection', function(socket){
  socket.on('chat message', function(msg){
    io.emit('chat message', msg);
    
    serialPort.write(msg, function(err, results) {
            console.log('err ' + err);
            console.log('results ' + results);
        });
    
  });
});

http.listen(3000, function(){
  console.log('listening on *:3000');
});

For the sketch on Arduino Uno, refer to the post "Read from Arduino Serial port, and write to 2x16 LCD".

Node.js Chat application using socket.io, run on Raspberry Pi

The tutorial Get Started: Chat application describe how to create a basic chat application on Node.js using socket.io.

This video show how I following the tutorial to do the job on Raspberry Pi:

The next post show how to send the received messages to USB connected Arduino Uno using serialport, and display on LCD Module.


Tuesday, September 2, 2014

Web base, remotely visual programming Raspberry Pi/Galileo with Wyliodrin

You can program your embedded devices using a browser on any computer.

Here is a short tutorial on how to program the Raspberry Pi with the new visual interface from Wyliodrin.


https://www.wyliodrin.com/