Commits

Cmed Technology committed cc736d5

wip

Comments (0)

Files changed (3)

+LCD
+===
+
+
+Sonar
+=====
+
+
+Managing the code
+=================
+
+To deploy from a host linux box you need "fabric".
+
+    http://fabfile.org
+
+sudo apt-get install fabric
+
+Every function in fabfile.py is callable using:
+
+    fab <function name>
+
+So to provision the raspberry with deb packages and stop using the UART as a TTY
+etc:
+
+    fab provision
+
+The IP address of the pi is in a constant at the the top of fabfile.py.
 from fabric.api import run, local, sudo, env, put
 
 
-env.hosts = ['pi@192.168.200.139']
-env.passwords = {'pi@192.168.200.139': 'raspberry'}
+PI_ADDRESS = '192.168.200.139'
+IMG_FILE = '/localbackup/2013-07-26-wheezy-raspbian.img'
+SD_CARD_DEVICE = '/dev/mmcblk0'
+
+
+env.hosts = ['pi@{}'.format(PI_ADDRESS)]
+env.passwords = {env.hosts[0]: 'raspberry'}
 
 
 def flash():
-    block_device = '/dev/mmcblk0'
-    osfile = '/localbackup/2013-07-26-wheezy-raspbian.img'
     # local('sudo umount {}p1'.format(block_device))
     # local('sudo umount {}p2'.format(block_device))
-    local('sudo dcfldd bs=1M if={} of={}'.format(osfile, block_device))
+    local('sudo dcfldd bs=1M if={} of={}'.format(IMG_FILE, SD_CARD_DEVICE))
     local('sudo sync')
 
 
 
 def reboot():
     sudo('shutdown -r now')
-
         GPIO.output(channel, 0)
 
 
-def all_pins(v):
-    for channel in channels.values():
-        print '{}={}'.format(channel, v)
-        GPIO.output(channel, v)
-
-
 def wait():
     time.sleep(0.002)
 
 def send_nibble(d, rs=0):
     GPIO.output(channels['register_select'], rs)
     wait()
-    GPIO.output(channels['enable'], 1)
     GPIO.output(channels['bit0'], d & 0b0001)
     GPIO.output(channels['bit1'], d & 0b0010)
     GPIO.output(channels['bit2'], d & 0b0100)
     GPIO.output(channels['bit3'], d & 0b1000)
+    GPIO.output(channels['enable'], 1)
     wait()
     GPIO.output(channels['enable'], 0)
     wait()
 
     # Set 4 bit operation (again), 5x8 chars, and 1 line display.
     send_nibble(0b0010)
-    send_nibble(0b0000)
+    send_nibble(0b0000)  # NF00, where N=number of display lines, and F is font
 
     # Switch on display and cursor, and entire display is in space mode.
     send_nibble(0b0000)
     send_nibble(0b1110)
 
 
-    # for b in [0b0010, 0b0010, 0b0000, 0b0000, 0b1110]:
-    #     send_nibble(b)
-
 def append_char(c):
     if isinstance(c, str):
         c = ord(c)
 
-    # Function meaning: append character.
+    # Function meaning: "append character"
     send_nibble(0b0000)
     send_nibble(0b0110)
 
-    # Send the character
+    # Send the character (which we think is ASCII)
     send_nibble((c >> 4) & 0x0F, rs=1)
     send_nibble(c & 0x0F, rs=1)
 
-    # for i in range(31):
-    #     # Function meaning: append character.
-    #     send_nibble(0b0000)
-    #     send_nibble(0b0110)
 
-    #     # The letter H
-    #     send_nibble(0b0100, rs=1)
-    #     send_nibble(0b1000, rs=1)
+if __name__ == '__main__':
+    initialise()
+    init_lcd_4_bit()
 
-    # send_nibble(0b0011)
-    # send_nibble(0b0011)
-    # send_nibble(0b0011)
-    # send_nibble(0b0010)
+    for x in "Super!":
+        append_char(x)
 
-    # send_nibble(0b0010)
-    # send_nibble(0b0010)
-    # send_nibble(0b1110)
-
-
-def control_display(display=0, cursor=0, blink=0):
-    send_nibble(0b0000)
-    send_nibble(0b1000 + 0b0100 * display + 0b0010 * cursor + 0b0001 * blink)
-
-
-def send_byte(d):
-    if isinstance(d, str):
-        d = ord(d)
-    GPIO.output(channels['enable'], 1)
-    GPIO.output(channels['bit0'], d & 0x10)
-    GPIO.output(channels['bit1'], d & 0x20)
-    GPIO.output(channels['bit2'], d & 0x40)
-    GPIO.output(channels['bit3'], d & 0x80)
-    GPIO.output(channels['enable'], 0)
-    wait()
-    GPIO.output(channels['enable'], 1)
-    GPIO.output(channels['bit0'], d & 0x01)
-    GPIO.output(channels['bit1'], d & 0x02)
-    GPIO.output(channels['bit2'], d & 0x04)
-    GPIO.output(channels['bit3'], d & 0x08)
-    GPIO.output(channels['enable'], 0)
-    wait()
-
-
-def send_packet(command, data):
-    GPIO.output(channels['register_select'], 0)
-    wait()
-    send_byte(command)
-    GPIO.output(channels['register_select'], 1)
-    wait()
-    send_byte(data)
-
-
-def test1():
-    for i in range(2):
-        all_pins(1)
-        time.sleep(2)
-        all_pins(0)
-        time.sleep(2)
-
-
-def test2():
-    # on()
-    # time.sleep(1)
-    # off()
-    # time.sleep(1)
-    # on()
-    for c in 'Hello Alex':
-        send_byte(c)
-
-
-def test3():
-    send_byte(8)
-    time.sleep(1)
-    send_byte(12)
-    time.sleep(1)
-    on()
-    time.sleep(1)
-    off()
-    time.sleep(1)
-
-
-
-
-
-initialise()
-init_lcd_4_bit()
-for x in "Hello Alex":
-    append_char(x)
-
-# control_display()
-# control_display(display=1, cursor=1)
-
-GPIO.cleanup()
+    # Cleanup resource and return GPIO to input only.
+    GPIO.cleanup()