def gpio_input(pinId, inputTime):
        """ Receive a logic value from a GPIO pin """
        """
        TODO: Don't change pin to input, but read file instead
        """
        #insertDebugLog(NOTICE, "GPIO input from: {}".format(pinId), CDH, int(time.time()))

        pinId = SensorEntropy.get_gpio_pin(pinId)
        pin = Pin(pinId,'INPUT')
        return pin.digitalRead() != 0
Exemple #2
0
    def __init__(self, port='/dev/ttyS1', power_key='J4.26', power_status='J4.28', network_status='J4.30', ring='J4.32', retries=20):

        self.ser = serial.Serial(port)
        self.ser.baudrate = 115200
        self.ser.bytesize = 8
        self.ser.parity = 'N'
        self.ser.stopbits = 1
        self.ser.timeout = 0
        self.ser.xonxoff = 0
        self.ser.rtscts = 0

        self.retries = retries

        # Configuration des pins de contrôle
        self.power_key = Pin(power_key, 'HIGH')
        self.power_status = Pin(power_status, 'INPUT')
        self.network_status = Pin(network_status, 'INPUT')
        self.ring = Pin(ring, 'INPUT')

        self.pwr = self.power_status.get()
        self.rng = self.ring.get()

        # Démarre le Fona s'il ne l'est pas déja
        if not self.pwr:
            logging.info('Demarrage du module Fona...')
            self.power_key.off()
            sleep(2)
            self.power_key.on()
            sleep(2)

        logging.debug('Power Status: ' + str(self.pwr))
        logging.debug('Ring Indicator: ' + str(self.rng))

        # Configuration générale
        self.set_echo(False)
        self.set_clock(when=datetime.now(), delta='-16')
        self.set_buzzer(True)

        # Configuration des SMS
        self.set_text_mode(True)
        self.set_encoding(encoding='8859-1')

        # Active le son sur le speaker (et non le casque d'écoute)
        self.set_audio_channel(1)
        self.set_volume(20)

        # Active le microphone
        self.set_mic(True)
        self.set_mic_gain(1,15)
        self.set_mic_bias(False)

        # Désactive les LED pour économiser de l'énergie
        self.set_netlight(False)
Exemple #3
0
    def __init__(self, rst, dc, cs, spi="/dev/spidev32766.0"):
        self._log = logging.getLogger('Adafruit_SSD1306.SSD1306Base')
        self.width = 128
        self.height = 64
        self._pages = self.height/8
        self._buffer = [0]*(self.width*self._pages)

        # Setup reset, DC and CS pins
        self._rst = Pin(rst, 'HIGH')
        self._dc = Pin(dc, 'HIGH')

        # Handle hardware SPI
        self._log.debug('Using hardware SPI')
        self._spi = spibus(spi, cs)
    def gpio_output(pinId, pinStatus):
        """ Outputs a logic value on a GPIO pin """
        #insertDebugLog(NOTICE, "GPIO output from: {}".format(pinId), CDH, int(time.time()))

        pinId = SensorEntropy.get_gpio_pin(pinId)
        led = Pin(pinId,'OUTPUT')
        if pinStatus == ON:
            led.on()
            return True
        elif pinStatus == OFF:
            led.off()
            return True
        else:
            raise Exception('Incorrect GPIO status')
            return False
Exemple #5
0
 def MFRC522_Init(self):
   RST = Pin(self.NRSTPD,'OUTPUT')
   RST.on()
 
   self.MFRC522_Reset();
   
   
   self.Write_MFRC522(self.TModeReg, 0x8D)
   self.Write_MFRC522(self.TPrescalerReg, 0x3E)
   self.Write_MFRC522(self.TReloadRegL, 30)
   self.Write_MFRC522(self.TReloadRegH, 0)
   
   self.Write_MFRC522(self.TxAutoReg, 0x40)
   self.Write_MFRC522(self.ModeReg, 0x3D)
   self.AntennaOn()
Exemple #6
0
class spibus():
    """Class provided in Acme Systems' playground examples spisend.py.
    """

    fd=None
    write_buffer = create_string_buffer(8192)
    read_buffer = create_string_buffer(8192)

    ioctl_arg = spi_ioc_transfer(tx_buf=addressof(write_buffer),
                                 rx_buf=addressof(read_buffer),
                                 len=1,
                                 delay_usecs=0,
                                 speed_hz=5000000,
                                 bits_per_word=8,
                                 cs_change = 0)

    def __init__(self, device, cs):
        self._cs = Pin(cs, 'HIGH')
        self.fd = posix.open(device, posix.O_RDWR)
        ioctl(self.fd, SPI_IOC_RD_MODE, " ")
        ioctl(self.fd, SPI_IOC_WR_MODE, struct.pack('I',0))

    def send(self, len):
        self._cs.low()
        self.ioctl_arg.len=len
        ioctl(self.fd, SPI_IOC_MESSAGE(1), addressof(self.ioctl_arg))
        self._cs.high()

    def write(self, s):
        i = 0
        for c in s:
            if c.__class__ is not str:
                c = chr(c)
            self.write_buffer[i] = c
            i += 1
        self.send(len(s))
Exemple #7
0
def read_adc():
    global s
    global BUFFER_SIZE
    global adc
    print(m.read_adc_data())
    adc[s] = m.read_adc_data()
    print(adc[s])
    if s == BUFFER_SIZE:
        fd.write("\n".join(adc))
        fd.close
        s = 0
    else:
        s = +1


DRDYOUT = Pin('PC0', 'INPUT')
#DRDYOUT.set_edge("both", read_adc)


def write_file(f, buff, t):
    print(t)
    print("Writing file")
    f.write("\n".join(str(x) for x in buff))
    t = 0
    buff = None
    return buff, t


t1 = 0
t2 = BUFFER_SIZE
buffer1 = []
Exemple #8
0
print "*"
print "*  Test ACS AriaG25 Board"
print "*"
print "*"
print "* Test Output"
print "* Test Input"
print "* Test Modem"
print "* Test Analog"
print "* Test USB"
print "*"
print "* Type ctrl-C to exit"
print "*"
print "**********************************"
 
 
OUTDIG0 = Pin('W10','OUTPUT') 
OUTDIG1 = Pin('W9','OUTPUT')
LED1 = Pin('N17','OUTPUT')
STATUS_GSM = Pin('N16','INPUT')

LDIGIN0 = Pin('W16','INPUT')
LDIGIN1 = Pin('W15','INPUT')
LDIGIN2 = Pin('W14','INPUT')
LDIGIN3 = Pin('W13','INPUT')
LDIGIN4 = Pin('W12','INPUT')
LDIGIN5 = Pin('W11','INPUT')

while True:

	print""		
	print "**********************************"
Exemple #9
0
	print "4 - Right ON"
	print "5 - ON-OFF"
	print "6 - OFF-ON"
	print "q - Quit"
	print "----------------------"

	print "Select: ",
	test_to_run=getch()
	if test_to_run=="q":
		print "Goodbye cruel world !"
		quit()
	print " "

	if test_to_run=="1":
		for ariapin in j1pinlist:
			a = Pin("J1." + str(ariapin),'OUTPUT')
			a.on()

		for ariapin in j2pinlist:
			a = Pin("J2." + str(ariapin),'OUTPUT')
			a.on()

		#J3
		for ariapin in j3pinlist:
			a = Pin("J3." + str(ariapin),'OUTPUT')
			a.on()

	if test_to_run=="2":
		for ariapin in j1pinlist:
			a = Pin("J1." + str(ariapin),'OUTPUT')
			a.off()
Exemple #10
0
from time import sleep
from ablib import Pin
 
Power_USB_A = Pin('N7','HIGH')
Power_USB_B = Pin('N8','HIGH')
Power_USB_C = Pin('N9','HIGH')

while True:
	print "USB A OFF"
	Power_USB_A.off()
	sleep(1) 

	print "USB B OFF"
	Power_USB_B.off()
	sleep(1) 

	print "USB C OFF"
	Power_USB_C.off()
	sleep(1) 

	print "USB A ON"
	Power_USB_A.on()
	sleep(1) 

	print "USB B ON"
	Power_USB_B.on()
	sleep(1) 

	print "USB C ON"
	Power_USB_C.on()
	sleep(1) 
Exemple #11
0
 def __init__(self, device, cs):
     self._cs = Pin(cs, 'HIGH')
     self.fd = posix.open(device, posix.O_RDWR)
     ioctl(self.fd, SPI_IOC_RD_MODE, " ")
     ioctl(self.fd, SPI_IOC_WR_MODE, struct.pack('I',0))
Exemple #12
0
from time import sleep
from ablib import Pin

power_overrun = Pin('W9', 'INPUT')

while True:
    if power_overrun.get_value() == False:
        print "Power overrun !"
        sleep(1)
'''
file: reedTest.py
description: Reads interrupts from reed switch for debug purposes
authors: alberto valente <*****@*****.**>, davide grobberio <*****@*****.**>
project: OpenPluvio an OpenSource tipping bucket rain gauge
version: 1.0
organization: Verona FabLab <www.veronafablab.it>
license: CC-BY-SA

'''
from ablib import Pin
from time import sleep

def pressed():
    print "Pressed"

PB=Pin('PC0','INPUT')
PB.set_edge("falling",pressed)

#Never ending loop
i=0
while True:
    print i
    i=i+1
    sleep(0.5)
    def SendByte(self, byte):

        SHT_DATA_OUT = Pin(self.PIN_DATA, 'OUTPUT')
        SHT_CLK = Pin(self.PIN_CLK, 'OUTPUT')

        tmp = 0x80
        for i in range(8):
            if byte & tmp:
                SHT_DATA_OUT.on()
            else:
                SHT_DATA_OUT.off()

            SHT_CLK.on()
            SHT_CLK.off()

            tmp = tmp / 2

        SHT_CLK.on()

        SHT_DATA_IN = Pin(self.PIN_DATA, 'INPUT')
        #ACK Check
        actualTime = time.time()
        ACK = SHT_DATA_IN.digitalRead()
        while ACK == 1 & ((actualTime + 0.1) > time.time()):
            ACK = SHT_DATA_IN.digitalRead()
        SHT_CLK.off()

        #Wait conversion Start
        actualTime = time.time()
        ACK = SHT_DATA_IN.digitalRead()
        while ACK == 0 & ((actualTime + 0.1) > time.time()):
            ACK = SHT_DATA_IN.digitalRead()

        #Wait conversion End
        actualTime = time.time()
        ACK = SHT_DATA_IN.digitalRead()
        while ACK == 1 & ((actualTime + 0.5) > time.time()):
            ACK = SHT_DATA_IN.digitalRead()
    def SendStart(self):

        SHT_DATA_OUT = Pin(self.PIN_DATA, 'OUTPUT')
        SHT_CLK = Pin(self.PIN_CLK, 'OUTPUT')

        SHT_DATA_OUT.on()
        SHT_CLK.on()
        usleep(1)

        SHT_DATA_OUT.off()
        SHT_CLK.off()
        usleep(1)

        SHT_CLK.on()
        SHT_DATA_OUT.on()
        usleep(1)

        SHT_CLK.off()
    def ReadData(self):

        SHT_CLK = Pin(self.PIN_CLK, 'OUTPUT')
        SHT_DATA_IN = Pin(self.PIN_DATA, 'INPUT')

        #Read 8 MSB
        byte = 0
        for i in range(8):
            SHT_CLK.on()
            byte = byte * 2 + SHT_DATA_IN.digitalRead()
            SHT_CLK.off()

        #ACK
        actualTime = time.time()
        ACK = SHT_DATA_IN.digitalRead()
        while ACK == 0 & ((actualTime + 0.1) > time.time()):
            ACK = SHT_DATA_IN.digitalRead()

        SHT_DATA_OUT = Pin(self.PIN_DATA, 'OUTPUT')
        SHT_DATA_OUT.off()
        usleep(1)
        SHT_CLK.on()
        usleep(400)
        SHT_CLK.off()
        SHT_DATA_IN = Pin(self.PIN_DATA, 'INPUT')

        #Read 8 LSB
        for i in range(8):
            SHT_CLK.on()
            byte = byte * 2 + SHT_DATA_IN.digitalRead()
            SHT_CLK.off()

        #CRC
        SHT_DATA_OUT = Pin(self.PIN_DATA, 'OUTPUT')
        SHT_DATA_OUT.on()
        SHT_CLK.on()
        usleep(400)
        SHT_CLK.off()
        SHT_DATA_OUT.off()

        return byte
Exemple #17
0
fd = open(file_data_name, "w")

def read_adc():
    global s
    global BUFFER_SIZE
    global adc
    print(m.read_adc_data())
    adc[s] = m.read_adc_data()
    print(adc[s])
    if s == BUFFER_SIZE:
        fd.write("\n".join(adc))
        fd.close
        s = 0
    else:
        s =+ 1
DRDYOUT = Pin('PC0', 'INPUT')
#DRDYOUT.set_edge("both", read_adc)


def write_file(f, buff, t):
    print(t)
    print("Writing file")
    f.write("\n".join(str(x) for x in buff))
    t = 0
    buff = None
    return buff, t


t1 = 0
t2 = BUFFER_SIZE
buffer1 = []
Exemple #18
0
#!/usr/bin/env python

import sys
import subprocess
import time
import threading
from ablib import Pin

#Pin 2 can't be used.
#Pin 3 is the potentiometer. It will be accessed by a different function for ADC
push_button = Pin("4", "INPUT")

LED = Pin("12", "OUTPUT")

########################################################################################################


class Volume_Control(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        previous_value = 0
        while True:
            current_value = self.get_pot_value()
            if (previous_value != current_value):
                previous_value = current_value
                self.set_volume(self.pot_convert(current_value))
            LED.digitalWrite("LOW")
            time.sleep(.5)
            LED.digitalWrite("HIGH")
Exemple #19
0
from ablib import Pin
from time import sleep

print "Blinking led"
print "Type ctrl-C to exit"

led = Pin('N20', 'OUTPUT')

while True:
    sleep(0.2)
    led.on()
    sleep(0.2)
    led.off()
Exemple #20
0
#!/usr/bin/env python

import time
from ablib import Pin
import sys
import threading
import uart

nfc_reset = Pin("1", "OUTPUT")  #LOW ASSERTED

UART = uart.UART_Control()


class NFC_Control(threading.Thread):

    NFC_RX_size = 30  # Both arrays below have length 24
    NFC_RX = [
        None
    ] * NFC_RX_size  # First 16-bytes are the PAN ID, and second 14 bytes are used in the Encryption key calculation

    #-----NFC COMMANDS-----
    REQB_SENSB = [None] * 3
    ATTRIB = [None] * 9
    NDEF_APP_SEL = [None] * 15
    CAP_CONT_SEL = [None] * 9
    CAP_CONT_READ = [None] * 7
    NDEF_SEL = [None] * 9
    NLEN_READ = [None] * 7
    NDEF_READ = [None] * 7
    NLEN_CLEAR = [None] * 8
    SEND_NDEF = [None] * (12 + NFC_RX_size)
Exemple #21
0
class SSD1306():

    def __init__(self, rst, dc, cs, spi="/dev/spidev32766.0"):
        self._log = logging.getLogger('Adafruit_SSD1306.SSD1306Base')
        self.width = 128
        self.height = 64
        self._pages = self.height/8
        self._buffer = [0]*(self.width*self._pages)

        # Setup reset, DC and CS pins
        self._rst = Pin(rst, 'HIGH')
        self._dc = Pin(dc, 'HIGH')

        # Handle hardware SPI
        self._log.debug('Using hardware SPI')
        self._spi = spibus(spi, cs)

    def _initialize(self):
        # 128x64 pixel specific initialization.
        self.command(SSD1306_DISPLAYOFF)                    # 0xAE
        self.command(SSD1306_SETDISPLAYCLOCKDIV)            # 0xD5
        self.command(0x80)                                  # the suggested ratio 0x80
        self.command(SSD1306_SETMULTIPLEX)                  # 0xA8
        self.command(0x3F)
        self.command(SSD1306_SETDISPLAYOFFSET)              # 0xD3
        self.command(0x0)                                   # no offset
        self.command(SSD1306_SETSTARTLINE | 0x0)            # line #0
        self.command(SSD1306_CHARGEPUMP)                    # 0x8D
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.command(0x10)
        else:
            self.command(0x14)
        self.command(SSD1306_MEMORYMODE)                    # 0x20
        self.command(0x00)                                  # 0x0 act like ks0108
        self.command(SSD1306_SEGREMAP | 0x1)
        self.command(SSD1306_COMSCANDEC)
        self.command(SSD1306_SETCOMPINS)                    # 0xDA
        self.command(0x12)
        self.command(SSD1306_SETCONTRAST)                   # 0x81
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.command(0x9F)
        else:
            self.command(0xCF)
        self.command(SSD1306_SETPRECHARGE)                  # 0xd9
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.command(0x22)
        else:
            self.command(0xF1)
        self.command(SSD1306_SETVCOMDETECT)                 # 0xDB
        self.command(0x40)
        self.command(SSD1306_DISPLAYALLON_RESUME)           # 0xA4
        self.command(SSD1306_NORMALDISPLAY)                 # 0xA6

    def command(self, c):
        """Send command byte to display. D/C low = Command."""
        # SPI write.
        self._dc.low()
        self._spi.write([c])

    def data(self, c):
        """Send byte of data to display. D/C high = Data."""
        self._dc.high()
        self._spi.write([c])

    def begin(self, vccstate=SSD1306_SWITCHCAPVCC):
        """Initialize display."""
        # Save vcc state.
        self._vccstate = vccstate
        # Reset and initialize display.
        self.reset()
        self._initialize()
        # Turn on the display.
        self.command(SSD1306_DISPLAYON)

    def reset(self):
        """Reset the display."""
        # Set reset high for a millisecond.
        self._rst.high()
        time.sleep(0.001)
        # Set reset low for 10 milliseconds.
        self._rst.low()
        time.sleep(0.010)
        # Set reset high again.
        self._rst.high()

    def display(self):
        """Write display buffer to physical display."""
        self.command(SSD1306_COLUMNADDR)
        self.command(0)              # Column start address. (0 = reset)
        self.command(self.width-1)   # Column end address.
        self.command(SSD1306_PAGEADDR)
        self.command(0)              # Page start address. (0 = reset)
        self.command(self._pages-1)  # Page end address.

        # Write buffer data.
        # Set DC high for data.
        self._dc.high()
        # Write buffer.
        self._spi.write(self._buffer)

    def image(self, image):
        """Set buffer to value of Python Imaging Library image.  The image should
        be in 1 bit mode and a size equal to the display size.
        """
        if image.mode != '1':
            raise ValueError('Image must be in mode 1.')
        imwidth, imheight = image.size
        if imwidth != self.width or imheight != self.height:
            raise ValueError('Image must be same dimensions as display ({0}x{1}).'.format(self.width, self.height))
        # Grab all the pixels from the image, faster than getpixel.
        pix = image.load()
        # Iterate through the memory pages
        index = 0
        for page in range(self._pages):
            # Iterate through all x axis columns.
            for x in range(self.width):
                # Set the bits for the column of pixels at the current position.
                bits = 0
                # Don't use range here as it's a bit slow
                for bit in [0, 1, 2, 3, 4, 5, 6, 7]:
                    bits = bits << 1
                    bits |= 0 if pix[(x, page*8+7-bit)] == 0 else 1
                # Update buffer byte and increment to next byte.
                self._buffer[index] = bits
                index += 1

    def clear(self):
        """Clear contents of image buffer."""
        self._buffer = [0]*(self.width*self._pages)

    def set_contrast(self, contrast):
        """Sets the contrast of the display.  Contrast should be a value between
        0 and 255."""
        if contrast < 0 or contrast > 255:
            raise ValueError('Contrast must be a value from 0 to 255 (inclusive).')
        self.command(SSD1306_SETCONTRAST)
        self.command(contrast)

    def dim(self, dim):
        """Adjusts contrast to dim the display if dim is True, otherwise sets the
        contrast to normal brightness if dim is False.
        """
        # Assume dim display.
        contrast = 0
        # Adjust contrast based on VCC if not dimming.
        if not dim:
            if self._vccstate == SSD1306_EXTERNALVCC:
                contrast = 0x9F
            else:
                contrast = 0xCF
Exemple #22
0
from time import sleep
from ablib import Pin

Power_USB_A = Pin('N7', 'HIGH')
Power_USB_B = Pin('N8', 'HIGH')
Power_USB_C = Pin('N9', 'HIGH')

while True:
    print "USB A OFF"
    Power_USB_A.off()
    sleep(1)

    print "USB B OFF"
    Power_USB_B.off()
    sleep(1)

    print "USB C OFF"
    Power_USB_C.off()
    sleep(1)

    print "USB A ON"
    Power_USB_A.on()
    sleep(1)

    print "USB B ON"
    Power_USB_B.on()
    sleep(1)

    print "USB C ON"
    Power_USB_C.on()
    sleep(1)
Exemple #23
0
from time import sleep
from ablib import Pin

print "Modem ON"

quectel_power = Pin('W10', 'HIGH')
quectel_power_key = Pin('E10', 'LOW')

quectel_power_key.on()
sleep(1)
quectel_power_key.off()
file: bascula2db.py
description: Reads interrupts from reed switch and saves timestamp on db
authors: alberto valente <*****@*****.**>, davide grobberio <*****@*****.**>
project: OpenPluvio an OpenSource tipping bucket rain gauge
version: 1.0
organization: Verona FabLab <www.veronafablab.it>
license: CC-BY-SA

'''

from ablib import Pin
from time import sleep
import sqlite3

DBNAME = '/var/www/OpenPluvio/db/openpluvio'

def basculata():
    connection = sqlite3.connect(DBNAME)
    cursor = connection.cursor()
    cursor.execute('insert into basculate default values')
    connection.commit()
    connection.close()

PB=Pin('PC0','INPUT')
PB.set_edge("falling",basculata)

#Never ending loop
while True:
    sleep
   
Exemple #25
0
from time import sleep
from ablib import Pin

print "Modem OFF"

quectel_power = Pin('W10', 'LOW')
quectel_power_key = Pin('E10', 'LOW')
Exemple #26
0
    print "4 - Right ON"
    print "5 - ON-OFF"
    print "6 - OFF-ON"
    print "q - Quit"
    print "----------------------"

    print "Select: ",
    test_to_run = getch()
    if test_to_run == "q":
        print "Goodbye cruel world !"
        quit()
    print " "

    if test_to_run == "1":
        for ariapin in j1pinlist:
            a = Pin("J1." + str(ariapin), 'OUTPUT')
            a.on()

        for ariapin in j2pinlist:
            a = Pin("J2." + str(ariapin), 'OUTPUT')
            a.on()

        #J3
        for ariapin in j3pinlist:
            a = Pin("J3." + str(ariapin), 'OUTPUT')
            a.on()

    if test_to_run == "2":
        for ariapin in j1pinlist:
            a = Pin("J1." + str(ariapin), 'OUTPUT')
            a.off()
Exemple #27
0
from ablib import Pin
from time import sleep
 
line = Pin('N20','OUTPUT')

while True:
	sleep(0.2)
	line.digitalWrite('HIGH')
	sleep(0.2)
	line.digitalWrite('LOW')
Exemple #28
0
from ablib import Pin
from time import sleep

led = Pin('W9', 'OUTPUT')
button = Pin('W15', 'INPUT')

while True:
    if button.digitalRead() == 0:
        led.on()
    else:
        led.off()