Ejemplo n.º 1
0
def main():
    global i2c
    i2c = I2C()
    i2c.speed = '50kHz'
    i2c.configure(power=True, pullup=True, aux=False, cs=False)

    while True:
        UpdateGauges(cpu_usage(), memory_usage(), network_usage(), 0)
        time.sleep(SLEEP_SECONDS)
    exit();
Ejemplo n.º 2
0
    def __init__(self, bpInterface='', bpBaudRate=115200):

        if '' == bpInterface or 0 == bpBaudRate:
            raise UserWarning('Invalid Bus Pirate interface parameters!')

        self.i2c = I2C(connect=False)
        self.__bpInterface = bpInterface
        self.__bpBaudRate = bpBaudRate

        # should be updated after successful calling to enable()
        self.__shadowRegs = [0x00] * 16  # at index 0 is address 0x00
Ejemplo n.º 3
0
# HackRF wiki:
# https://github.com/mossmann/hackrf/wiki/Lemondrop-Bring-Up

import sys

from pyBusPirateLite.I2C import *
from math import log

if len(sys.argv) < 2:
    print('Usage: %s <path to serial device>' % (sys.argv[0], ))
    sys.exit()

serial_path = sys.argv[1]
print('Connecting to Bus Pirate on "%s"...' % (serial_path, ))

i2c = I2C(serial_path, 115200)
i2c.resetBP()

print('Entering I2C mode...')
if not i2c.BBmode():
    print('BBmode() failed')
    sys.exit()

if not i2c.enter_I2C():
    print('enter_I2C() failed')
    sys.exit()

if not i2c.set_speed(I2CSpeed._400KHZ):
    print('set_speed() failed')
    sys.exit()
Ejemplo n.º 4
0
        help="EEPROM memory size. See the EEPROM's data sheet.")
    parser.add_argument("-S",
                        "--i2c-speed",
                        dest="i2c_speed",
                        default=3,
                        type=int,
                        help="0=5KHZ, 1=50KHZ,2=100KHZ, 3=400KHZ")
    # Debug mode not implemented yet
    #parser.add_option("-D", "--debug",
    #dest="DEBUG", action="store_true", default=False,
    #help="Debug mode to print debug information about SPI transations.")

    args = parser.parse_args(sys.argv[1:])

    #NOTE: Leave USB speed at max because it never really changes when using the BusPirate.
    i2c = I2C(args.bp, 115200)

    print "Entering binmode: ",
    if i2c.BBmode():
        print "OK."
    else:
        print "failed."
        sys.exit()

    print "Entering raw I2C mode: ",
    if i2c.enter_I2C():
        print "OK."
    else:
        print "failed."
        sys.exit()
Ejemplo n.º 5
0
    i2c.send_stop_bit()
    if ret:
        return data_out

if __name__ == '__main__':
    parser = argparse.ArgumentParser(sys.argv[0])
    parser.add_argument("-o", "--output", dest="outfile", metavar="OUTFILE", type=argparse.FileType('wb'),
            required=True)
    parser.add_argument("-p", "--serial-port", dest="bp", default="/dev/ttyUSB0")
    parser.add_argument("-s", "--size", dest="size", type=int, required=True)
    parser.add_argument("-S", "--serial-speed", dest="speed", default=115200, type=int)
    parser.add_argument("-b", "--block-size", dest="bsize", default=256, type=int)

    args = parser.parse_args(sys.argv[1:])

    i2c = I2C(args.bp, args.speed)
    print "Entering binmode: ",
    if i2c.BBmode():
        print "OK."
    else:
        print "failed."
        sys.exit()

    print "Entering raw I2C mode: ",
    if i2c.enter_I2C():
        print "OK."
    else:
        print "failed."
        sys.exit()
        
    print "Configuring I2C."
Ejemplo n.º 6
0
class ssd1306(object):
  def __init__(self, isc):
    self.i2c=i2c
    assert i2c.BBmode()
    assert i2c.enter_I2C()
    assert i2c.cfg_pins(PinCfg.POWER)
    assert i2c.set_speed(I2CSpeed._100KHZ)

    self.reset()


  def reset(self):
asdf


  def write(data):
    i2c.send_start_bit()
    i2c.bulk_trans(len(data),data)
    i2c.send_stop_bit()



if __name__ == '__main__':
  i2c = I2C("/dev/ttyUSB0", 115200)
  oled = ssd1306(spi)

  i2c.resetBP()


Ejemplo n.º 7
0
    data_out = []
    i2c.send_start_bit()
    i2c.bulk_trans(len(data2), data2)
    while numbytes > 0:
        data_out.append(ord(i2c.read_byte()))
        if numbytes > 1:
            i2c.send_ack()
        numbytes -= 1
    i2c.send_nack()
    i2c.send_stop_bit()

    return data_out


if __name__ == '__main__':
    i2c = I2C("COM4", 115200)
    print "Entering binmode: ",
    if i2c.BBmode():
        print "OK."
    else:
        print "failed."
        sys.exit()

    print "Entering raw I2C mode: ",
    if i2c.enter_I2C():
        print "OK."
    else:
        print "failed."
        sys.exit()

    print "Configuring I2C."
Ejemplo n.º 8
0
    (10, 0x01),  # bypass ref divide by 2, disable doubler, divide by 1
    (9, 0x70),  # 2.5mA charge pump current
    (8, 0x00),
    (7, 0x00),  # muxout: tristate, N[11:8] = 0
    (6, 0x43),  # N[7:0] = 67
    (5, 0x00),  # R-divider disabled
    (4, 0x01),
    (3, 0x00),  # FRAC[24] = 0
    (2, 0x87),  # FRAC[23:16] = 0x87
    (1, 0x2b),  # FRAC[15:8] = 0x2b
    (0, 0x02),  # FRAC[7:0] = 0x02
)

enable_vga = ((30, 0x01), )

i2c = I2C('/dev/tty.usbserial-A5005CUQ', 115200)
i2c.resetBP()

if not i2c.BBmode():
    print('BBmode() failed')
    sys.exit()

#i2c.reset()

if not i2c.enter_I2C():
    print('enter_I2C() failed')
    sys.exit()

if not i2c.set_speed(I2CSpeed._400KHZ):
    print('set_speed() failed')
    sys.exit()
Ejemplo n.º 9
0
	new_values = []
	for x in values:
		if (abs(x-median) > median*ALLOWED_ERROR):
			print "Value %s too far from median - ignoring" % x
		else:
			new_values.append(x)
	for x in new_values:
		sum += x
	avg = sum/len(new_values)
	return avg

if __name__ == '__main__':
	i2c = None
	# Allow for old and new bus pirate libraries
	try:
		i2c = I2C()
		i2c.connect(DEVICE, 115200, 0.01)
	except TypeError, x:
		i2c = I2C(DEVICE, 115200)

	print "Entering binmode: ",
	sys.stdout.flush()
	if i2c.BBmode(): print "OK."
	else: raise Exception("failed.")

	print "Entering raw I2C mode: ",
	if i2c.enter_I2C(): print "OK."
	else: raise Exception("failed.")
		
	print "Configuring I2C:",
	if not i2c.cfg_pins(I2CPins.POWER | I2CPins.PULLUPS ):