import board from digitalio import DigitalInOut from adafruit_bluefruitspi import BluefruitSPI import neopixel ADVERT_NAME = b'BlinkaNeoLamp' # 16 neopixels on a digital pin, adjust as necessary! pixels = neopixel.NeoPixel(board.D5, 16) pixels.fill(0) spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) cs = DigitalInOut(board.D8) irq = DigitalInOut(board.D7) rst = DigitalInOut(board.D4) bluefruit = BluefruitSPI(spi_bus, cs, irq, rst, debug=False) def init_bluefruit(): # Initialize the device and perform a factory reset print("Initializing the Bluefruit LE SPI Friend module") bluefruit.init() bluefruit.command_check_OK(b'AT+FACTORYRESET', delay=1) # Print the response to 'ATI' (info request) as a string print(str(bluefruit.command_check_OK(b'ATI'), 'utf-8')) # Change advertised name bluefruit.command_check_OK(b'AT+GAPDEVNAME=' + ADVERT_NAME) def wait_for_connection(): print("Waiting for a connection to Bluefruit LE Connect ...")
# we wrap the loop in a try/except block and have multiple loops # and functions to keep our connection up and running no matter what import time import busio import board from digitalio import DigitalInOut from adafruit_bluefruitspi import BluefruitSPI ADVERT_NAME = b'BlinkaBLE' spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) cs = DigitalInOut(board.D8) irq = DigitalInOut(board.D7) rst = DigitalInOut(board.D4) bluefruit = BluefruitSPI(spi_bus, cs, irq, rst, debug=False) def init_bluefruit(): # Initialize the device and perform a factory reset print("Initializing the Bluefruit LE SPI Friend module") bluefruit.init() bluefruit.command_check_OK(b'AT+FACTORYRESET', delay=1) # Print the response to 'ATI' (info request) as a string print(str(bluefruit.command_check_OK(b'ATI'), 'utf-8')) # Change advertised name bluefruit.command_check_OK(b'AT+GAPDEVNAME=' + ADVERT_NAME) def wait_for_connection(): print("Waiting for a connection to Bluefruit LE Connect ...")
# A simple echo test for the Feather M0 Bluefruit # Sets the name, then echo's all RX'd data with a reversed packet import time import busio import board from digitalio import DigitalInOut from adafruit_bluefruitspi import BluefruitSPI spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) cs = DigitalInOut(board.D8) irq = DigitalInOut(board.D7) rst = DigitalInOut(board.D4) bluefruit = BluefruitSPI(spi_bus, cs, irq, rst, debug=False) # Initialize the device and perform a factory reset print("Initializing the Bluefruit LE SPI Friend module") bluefruit.init() bluefruit.command_check_OK(b'AT+FACTORYRESET', delay=1) # Print the response to 'ATI' (info request) as a string print(str(bluefruit.command_check_OK(b'ATI'), 'utf-8')) # Change advertised name bluefruit.command_check_OK(b'AT+GAPDEVNAME=BlinkaBLE') while True: print("Waiting for a connection to Bluefruit LE Connect ...") # Wait for a connection ... dotcount = 0 while not bluefruit.connected:
# Initialize the onboard LED onBoardLED = DigitalInOut(PIN_ONBOARD_LED) onBoardLED.direction = Direction.OUTPUT # Initialize the I2C bus i2c = busio.I2C(board.SCL, board.SDA) # Initialize the SPI bus spi = busio.SPI(SPI_SCK, MOSI=SPI_MOSI, MISO=SPI_MISO) print() print("{0} v{1:1.1f}".format(BLUEFRUIT_DEV_NAME, SCRIPT_VERSION)) # Initialize the Bluefruit LE SPI Friend and perform a factory reset bluefruit = BluefruitSPI(spi, cs=BLUEFRUIT_CS, irq=BLUEFRUIT_IRQ, reset=BLUEFRUIT_RST) print() print("Initializing Bluetooth") bluefruit.init() bluefruit.command_check_OK(b'AT+FACTORYRESET', delay=1) # Print the response to 'ATI' (info request) as a string print(str(bluefruit.command_check_OK(b'ATI'), 'utf-8')) # Change advertised name bluefruit.command_check_OK(b'AT+GAPDEVNAME=' + BLUEFRUIT_DEV_NAME) # Set the name of the beacon ##BLUEFRUIT_BEACON_NAME = "FrankBLE" ##bluefruit.command_check_OK(b'AT+BLEURIBEACON=' BLUEFRUIT_BEACON_NAME)
import board from digitalio import DigitalInOut from adafruit_bluefruitspi import BluefruitSPI import neopixel ADVERT_NAME = b'BlinkaNeoLamp' # 16 neopixels on a digital pin, adjust as necessary! pixels = neopixel.NeoPixel(board.D5, 16) pixels.fill(0) spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) cs = DigitalInOut(board.D8) irq = DigitalInOut(board.D7) rst = DigitalInOut(board.D4) bluefruit = BluefruitSPI(spi_bus, cs, irq, rst, debug=False) def init_bluefruit(): # Initialize the device and perform a factory reset print("Initializing the Bluefruit LE SPI Friend module") bluefruit.init() bluefruit.command_check_OK(b'AT+FACTORYRESET', delay=1) # Print the response to 'ATI' (info request) as a string print(str(bluefruit.command_check_OK(b'ATI'), 'utf-8')) # Change advertised name bluefruit.command_check_OK(b'AT+GAPDEVNAME='+ADVERT_NAME) def wait_for_connection(): print("Waiting for a connection to Bluefruit LE Connect ...") # Wait for a connection ... dotcount = 0
# we wrap the loop in a try/except block and have multiple loops # and functions to keep our connection up and running no matter what import time import busio import board from digitalio import DigitalInOut from adafruit_bluefruitspi import BluefruitSPI ADVERT_NAME = b'BlinkaBLE' spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) cs = DigitalInOut(board.D8) irq = DigitalInOut(board.D7) rst = DigitalInOut(board.D4) bluefruit = BluefruitSPI(spi_bus, cs, irq, rst, debug=False) def init_bluefruit(): # Initialize the device and perform a factory reset print("Initializing the Bluefruit LE SPI Friend module") bluefruit.init() bluefruit.command_check_OK(b'AT+FACTORYRESET', delay=1) # Print the response to 'ATI' (info request) as a string print(str(bluefruit.command_check_OK(b'ATI'), 'utf-8')) # Change advertised name bluefruit.command_check_OK(b'AT+GAPDEVNAME='+ADVERT_NAME) def wait_for_connection(): print("Waiting for a connection to Bluefruit LE Connect ...") # Wait for a connection ... dotcount = 0