Example #1
0
def setup(keymap=FULL):
    global _is_setup, spi, callbacks, pins, leds, buf, states
    if _is_setup:
        return
    _is_setup = True

    callbacks = [None for key in keymap]
    pins = [key[0] for key in keymap]
    leds = [key[1] for key in keymap]
    buf = [[0, 0, 0, 1.0] for key in keymap]
    states = [True for key in keymap]

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(pins, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    for pin in pins:
        GPIO.add_event_detect(pin,
                              GPIO.BOTH,
                              callback=_handle_keypress,
                              bouncetime=1)

    spi = SpiDev()
    spi.open(0, 0)
    spi.max_speed_hz = 1000000

    atexit.register(_on_exit)
def setup_spi():
    logger.debug("SPI setup")
    spi = SpiDev()
    spi.open(bus=0, device=0)
    spi.max_speed_hz = 1000000
    spi.bits_per_word = 8
    spi.loop = False
    spi.mode = 3
    spi.no_cs = True
    return spi
Example #3
0
def read_touch_screen(channel):
    """Read the HackPack touchscreen coordinates."""
    spi = SpiDev()
    spi.open(1, 0)
    spi.no_cs = True
    spi.max_speed_hz = 2000000

    # Manual chip select
    GPIO.output(CS_TOUCH, 1)
    GPIO.output(CS_TOUCH, 0)
    responseData = spi.xfer([channel, 0, 0])
    GPIO.output(CS_TOUCH, 1)
    spi.close()
    return (responseData[1] << 5) | (responseData[2] >> 3)
def value_to_percent(channel=0):
    spi = SpiDev()
    spi.open(0, 0)
    spi.max_speed_hz = 20**5
    spi_data = spi.xfer2([1, (8 + channel) << 4, 0])
    spi.close()

    licht_waarde = int((spi_data[1] << 8) + spi_data[2])
    licht_percent = round((licht_waarde / 1023 * 100), 2)

    digitale_waarde = float((spi_data[1] << 8) + spi_data[2])
    # decibels = round((digitale_waarde+83.2073) /11.003 , 2)
    decibels = (20.0 * math.log10(digitale_waarde / 5.0))

    # return print("lichtsterkte: ", licht_percent)
    return print("decibels: ", decibels)
Example #5
0
 def __init__(self,
              port=0,
              dev=0,
              speed=1000000,
              interval=600,
              node="acc_sensor",
              save_path=None):
     self.interval = interval
     self.node = node
     self.save_path = save_path
     spi = SpiDev()
     spi.open(port, dev)
     #config SPI port
     spi.max_speed_hz = speed
     spi.mode = 0b11
     #set_pin()
     self.writebytes = spi.writebytes
     self.writebytes2 = spi.xfer3
     self.read = spi.xfer2
     self.start_up()
     self.file_time = datetime.now()
     self.fname = self.node + self.file_time.strftime("_%Y-%m-%d_%H-%M.csv")
     print("creating new log file")
     self.signals = ['time', 'x', 'y', 'z']
import Adafruit_BBIO.GPIO as GPIO
from spidev import SpiDev
import time
import datetime

spi = SpiDev(1, 0)
spi.mode = 3
spi.max_speed_hz = 200000
#spi.xfer2([0x0])

GPIO.setup("P9_11", GPIO.OUT) # A0 sipm select bit0
GPIO.setup("P9_12", GPIO.OUT) # A1 sipm select bit1
GPIO.setup("P9_13", GPIO.OUT) # A2 sipm select bit2
GPIO.setup("P9_14", GPIO.OUT) # A3 sipm select bit3


GPIO.setup("P9_15", GPIO.OUT) # A5 chip select bit0
GPIO.setup("P9_16", GPIO.OUT) # A6 chip select bit1

#chip select map
# 0: nc
# 1: pga
# 2: temp
# 3: mem


GPIO.output("P9_11", GPIO.LOW)
GPIO.output("P9_12", GPIO.LOW)
GPIO.output("P9_13", GPIO.LOW)
GPIO.output("P9_14", GPIO.LOW)
GPIO.output("P9_15", GPIO.LOW)
Example #7
0
from traceback import print_last

from spidev import SpiDev
import RPi.GPIO as GPIO

from rfid_rc522 import RC522Spi

try:
    spi = SpiDev()
    spi.open(0, 0)
    spi.max_speed_hz = 100000

    rfid = RC522Spi(spi, 22)

    assert rfid.calculate_crc(b'123456789') == b'\xbf\x05'

    if rfid.selftest():
        print("selftest passed!")
    else:
        print("selftest FAILED!")
except Exception as e:
    print_last()
finally:
    GPIO.cleanup()
Example #8
0
 def config_interface(spi_dev: SpiDev, clock: int) -> None:
     spi_dev.cshigh = True  # use inverted CS
     spi_dev.mode = 0b01
     spi_dev.max_speed_hz = clock  # set SPI clock
Example #9
0
	print "read eeprom"
	cmd = [0x03, 0] + [0 for i in range(8*16)]
	res = spi.xfer2(cmd)
	print res


if __name__ == "__main__":
	GPIO.setup("P9_11", GPIO.OUT)
	GPIO.setup("P9_12", GPIO.OUT)
	GPIO.setup("P9_13", GPIO.OUT)
	GPIO.setup("P9_14", GPIO.OUT)
	GPIO.setup("P9_15", GPIO.OUT)

	#spi = SPI()
	#spi.open(0, 0)
	#spi.msh = 0

	spi = SpiDev(1,0)
	spi.mode = 3
	spi.max_speed_hz = 100000


	check_eeprom_status()
	write_eeprom(3, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])

	GPIO.cleanup()
	spi.close()


 def _setup_spidev(self, bus, channel, mode=1):
     spi = SpiDev(bus, channel)
     spi.max_speed_hz = 1200000
     spi.mode = mode
     return spi
Example #11
0
from spidev import SpiDev

dev = SpiDev(0, 0)
dev.max_speed_hz = 7800000

resp = dev.xfer([0xA3])

time_sec = 0x74749054

while True:
    resp = dev.xfer([0xA3])
    if resp == [0xA0] or resp == [0xA5]:
        print "%s" % ''.join(["0x%02X " % x for x in resp]).strip()

        resp = dev.xfer([0xA2])
        print "%s" % ''.join(["0x%02X " % x for x in resp]).strip()

        # first_stage_hash - 256 bits
        resp = dev.xfer([
            0x09, 0xA0, 0xD1, 0x91, 0x92, 0xEF, 0x77, 0xC3, 0x04, 0xFE, 0x44,
            0x78, 0x88, 0xF9, 0xEF, 0x50, 0x69, 0xD6, 0x48, 0x46, 0x5A, 0x19,
            0x14, 0x6F, 0xB7, 0x70, 0x61, 0x97, 0x14, 0xD0, 0x89, 0x04
        ])
        print "%s" % ''.join(["0x%02X " % x for x in resp]).strip()

        # input_M - 96 bits
        #resp = dev.xfer([0x45, 0xF4, 0x99, 0x2E, 0x74, 0x74, 0x90, 0x54, 0x74, 0x7B, 0x1B, 0x18]);
        resp = dev.xfer([0x45, 0xF4, 0x99, 0x2E])
        print "%s" % ''.join(["0x%02X " % x for x in resp]).strip()

        # time
Example #12
0
#!/usr/bin/env python3
from flask import Flask, render_template, request
from spidev import SpiDev

app = Flask(__name__)

spi = SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 15200


LINEAR_MAX = 15   # mm/s
ANGULAR_MAX = 5   # rad/s


@app.route('/')
def index():
    return render_template('index.html',
                           title='Cybot control')


@app.route('/send', methods=['PUT'])
def send():
    if request.method == 'PUT':
        body = request.get_json()
        app.logger.debug(body)
        send_spi(encode(body))
        return "Done"


def encode(data):
Example #13
0
import time
import sys
from spidev import SpiDev

dev = SpiDev(0, 0)
dev.max_speed_hz = 10

try:
    while True:
        dev.writebytes([1, 2, 4, 8, 16, 32, 64, 128])
        time.sleep(0.001)
except KeyboardInterrupt:
    sys.exit(0)
Example #14
0
from spidev import SpiDev
import time
import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(6, GPIO.OUT)

spi = SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 390000

print("Flashlight to waitstate")
#string_to_send = "state;1\n"
string_to_send = "shot;1\n"
string_to_bytes = str.encode(string_to_send)
GPIO.output(6, 1)
time.sleep(0.01)
spi.xfer(string_to_bytes)
GPIO.output(6, 0)
time.sleep(1)
GPIO.cleanup()