Tagged: python Toggle Comment Threads | Keyboard Shortcuts

  • julie 11:35 am on March 20, 2016 Permalink
    Tags: python, , sensor,   

    Light sensor Python script 

    “””script to read a Light Dependent Resistor on GPIO pin 11
    must be run in command line:
    –login as root
    >sudo su
    — run python command from directory
    >python lightsensor.py
    — ctrl-C to quit
    “””
    #!/usr/bin/python
    import time
    import os
    import RPi.GPIO as GPIO

    GPIO.setmode(GPIO.BOARD)

    def LDRtime(LDRpin):
    reading = 0
    GPIO.setup(LDRpin, GPIO.OUT)
    GPIO.output(LDRpin, GPIO.LOW)
    time.sleep(0.1)

    GPIO.setup(LDRpin, GPIO.IN)
    while (GPIO.input(LDRpin) == GPIO.LOW):
    reading += 1
    return reading

    while True:
    print LDRtime(11)

    “””
    put LDRtime into a variable
    see if LDRtime is higher than a certain value
    if it is send a 1 to the MySQL database with timestamp
    if it goes lower than a certain value then send a 0 to the MySQL database with timestamp

    “””

    NOTE: paste code from editable post to preserve indents.

     
  • julie 9:07 pm on November 17, 2015 Permalink
    Tags: , , python,   

    Local iMac db setup 

    status at 20151117:
    Python script ok. Failing at the MySQL commit as the primary key stuff is not letting the data into the table.
    To do: add data to the sensor table. check PKs and FKs. check them again. Look at using python to check for duplicates instead of doing it this way.

     
  • julie 3:23 pm on October 1, 2015 Permalink
    Tags: mariaDB, , python,   

    Setting up iMac (OSXYosemite 10.10.5) 

    $ sudo easy_install pip
    $ sudo pip install -U setuptools
    $ sudo pip install pyserial

    install MariaDB as that is what is installed on pew
    ==

    • make sure Xcode is uptodate or install it

    $ xcode-select –install

    • install homebrew

    $ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

    • Check Homebrew

    $ brew doctor

    • Update Homebrew

    $ brew update

    • Check MariaDB version in brew repo

    $ brew info mariadb

    • Install MariaDB

    $ brew install mariadb

    • Run the Database Installer (change the version number in the path to match where MariaDB was installed in previous step)

    $ unset TMPDIR
    $ cd /usr/local/Cellar/mariadb/10.0.21/
    $ mysql_install_db

    • Start MariaDB

    $ mysql.server start

    • Secure the Installation

    $ mysql_secure_installation

    • Connect to MariaDB

    $ mysql -u root -p

    • Verify MariaDB Version

    $ select @@version;

    Fabulous source of the above instructions – https://mariadb.com/blog/installing-mariadb-10010-mac-os-x-homebrew

    ===

    • $ sudo pip install MySQL-python

    $ sudo pip install PyMySQL

    ===

    • plug in USB to serial convertor and a sensor. You may have FTDI drivers installed – check using from root dir:

    $ ls /dev/cu.*

    You are looking for /dev/cu.usbserial or /dev/tty.usbserial (see http://pbxbook.com/other/mac-tty.html )

    If not showing up install driver at http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=229&pcid=41 and restart.

    ===

    • Change path in conn.py to be correct serial port path:

    ser0 = serial.Serial(‘/dev/tty.usbserial’, 9600, timeout=5)

    • and fuck me this all worked straight away. I am learning after all.

    Update 13th Nov 2015
    To get up and running on the command line:
    $ mysql.server start
    then
    $ mysql -u root -p
    created nmr db on iMac and created tables using latest schema hosted on github.

    TODO – export database from pew and install on imac so that nmr_index contains a tag ID that it can match.

     
  • julie 11:26 am on July 29, 2015 Permalink
    Tags: python,   

    Python tips 

    Creating the code on Mac OS, to switch to Pi later

    ensure pip install and upgraded
    $ sudo pip install -U setuptools
    $ sudo pip install pyserial
    $ brew install mysql-connector-c ( on Mac OSX you need the mysql connection lib, will be installed if XCode installed apparently, see http://stackoverflow.com/questions/16182294/installing-mysql-python-on-mac-os-x)
    $ sudo pip install MySQL-python

    $ sudo pip install PyMySQL [alternative called pymysql which is a Python client connection to MySQL , follows same API as MySQL-python and works with Python 3 – this works so far…]

    Can’t TCP into the server db so use SSH
    sudo pip install paramiko [which also installs pycrypto and ecdsa]

    >> import serial
    >> import MySQLdb

    For Pi:

    1. apt-get install python-mysqldb
     
  • julie 1:36 pm on June 11, 2015 Permalink
    Tags: python,   

    Choosing R or Python for data analysis? An infographic.

     
  • julie 8:57 am on May 27, 2015 Permalink
    Tags: python,   

    Tutorial – Learn Python in 10 minutes – Stavros’ Stuff.

    PySerial

    python tutorials and resources

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel