The Raspberry Pi Blog

Click the links to see the full blog posts.
  1. Get python program that reads serial port working, see attached program (SerialRead.py)

  2. Install MySQL server on Pi. You will be asked for a root password as part of the install, please user CoderDojo as password

    sudo apt-get install mysql-server

  3. Install MySQL library for Python

    sudo apt-get install python-mysqldb

  4. Log into MySQL and create table

    mysql -u root –p

    CREATE TABLE IF NOT EXISTS RndNums (Id INT PRIMARY KEY AUTO_IMCREMENT, RndNum VARCHAR(2)

  5. Create user (testuser) and set password (test623)

    CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'test623';

  6. Grant privileges to testuser on all tables in testdb database

    GRANT ALL ON testdb.* TO 'testuser'@'localhost';

  7. Query new table

    SELECT * FROM RndNums;

  8. Modify Python program to include the following functionality. See program SerialDB.py
    1. database functionality to write values from Serial port to database table.

    2. functionality to write to serial port to turn led on Arduino on/off. If value is greater than 50 and turn led off if value is less than 50.

  9. After the program has run, use a terminal window to start MySQL and query table to check that values have been inserted. See steps 4 & 7 above

Arduino + Pi + Python

  1. We will connect an Arduino to the Raspberry Pi. There will be a program running on the Arduino that generates random numbers and sends these to the serial port.
  2. Use the sample Python program below to read in values from the serial port and display these.
  3. We when then add some logic to compare the values and print different messages depending on values.
  4. We will also install MySQL database and create a table to store the values from serial port.
  5. Finally we will update the Python program to use MySql and write vales read from serial port to a database table.

Pi + Python

  1. Setup Raspberry Pi
  2. Installed an Geany IDE (Integrated Development Environment) on Pi (sudo apt-get – install Geany)
  3. Installed the Python serial library (sudo apt-get install python-serial)
  4. Ran some small Python programs, using For and While loops. The version of Python we are using is v2.7

The following link provides a good tutorial on Python, which you may wish to look at before next week's session.

http://www.learnpython.org/

Useful Linux commands

To use the following commands, open terminal window from desktop

whoshows who is logged onto the PI
ls –llists files in directory
sshOpen a secure connection with another computer / PI
ifconfigShows details of IP address
manShow help details on Linux command and options
sudoAllows a command to be executed as a superuser or other user
raspi-configNot a Linux command, but allow various confiruration parameters to be changed, including starting SSH server. Need to prefix with sudo (ie. sudo raspi-config)
startxStarts the desktop
apt-getUsed to install and remove applications
 apt-get install [package name]
 apt-get remove [package name]
apt-cache searchCan be used to search for applications
 apt-cache search [game]
exitCloses command window

What is the Raspberry PI?

Produced by Raspberry PI foundation

Released in Feb 2012

System on a Chip (SOC) – CPU & GPU + RAM on single chip – unlike PC architecture.

Model A – Single USB, No network port

Model B 2 USB port, network port

512MB RAM on newer models

Runs Linux Operating System

Operating System is stored on SD card

Raspberry PI does not come with monitor, keyboard, mouse, power supply, Operating System, hard disk

Subscribe to Blog