def __init__(self, ssid, password, adafruit_username, adafruit__aio_key, adafruit_feed_key): self.debug = True self.station = network.WLAN(network.STA_IF) self.ssid = ssid self.password = password self.adafruit_feed_key = adafruit_feed_key self.lastCallTime = 0 self.lastCheckIn = 0 self.minBetweenCalls = 0.5 self.minBetweenCheckIn = 60 myMqttClient = 'dog-sensor-mqtt-client' adafruit_io_url = 'io.adafruit.com' adafruit_username = adafruit_username adafruit__aio_key = adafruit__aio_key self.c = MQTTClient(myMqttClient, adafruit_io_url, 0, adafruit_username, adafruit__aio_key) self.c.connect() # Software I2C setup: self.i2c = bitbangio.I2C(board.SCL, board.SDA) self.lis3dh = adafruit_lis3dh.LIS3DH_I2C(self.i2c) # Set range of accelerometer (can be RANGE_2_G, RANGE_4_G, RANGE_8_G or RANGE_16_G). self.lis3dh.range = adafruit_lis3dh.RANGE_2_G # Set click detection to double and single clicks. The first parameter is a value: # - 0 = Disable click detection. # - 1 = Detect single clicks. # - 2 = Detect single and double clicks. # The second parameter is the threshold and a higher value means less sensitive # click detection. Note the threshold should be set based on the range above: # - 2G = 40-80 threshold # - 4G = 20-40 threshold # - 8G = 10-20 threshold # - 16G = 5-10 threshold self.lis3dh.set_click(2, 80)
def run(): """main""" do_connect() with bitbangio.I2C(SCL, SDA) as i2c, nativeio.DigitalInOut(GPIO15) as pin: pin.switch_to_output() start(i2c, pin)
import board import network import time import ntptime import bitbangio as io import adafruit_ht16k33.segments ssid = '' password = '' i2c = io.I2C(board.SCL, board.SDA) display = adafruit_ht16k33.segments.Seg14x4(i2c) display.fill(0) sta_if = network.WLAN(network.STA_IF) if not sta_if.isconnected(): sta_if.active(True) sta_if.connect(ssid, password) while not sta_if.isconnected(): pass #TZ = 14400 # UTC to EDT TZ = 18000 # UTC to EST t = None while not t: time.sleep(0.1) try: t = ntptime.ntptime() except Exception:
# ap.ifconfig() # Station Interface (connecting to wifi) import network wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect('thingnet', 'uPy12345678') wlan.ifconfig(('192.168.4.2', '255.255.255.0', '192.168.4.1', '8.8.8.8')) # wlan.scan() # scan for access points # wlan.isconnected() # check if the station is connected to an AP # wlan.config('mac') # get the interface's MAC adddress # wlan.ifconfig() # get the interface's IP/netmask/gw/DNS addresses # Haptic Feedback import board import bitbangio import adafruit_drv2605 i2c = bitbangio.I2C(board.SCL, board.SDA) drv = adafruit_drv2605.DRV2605(i2c) drv.use_ERM() drv.set_waveform(14) drv.play() # Button Interupt from machine import Pin def callback(p): print('%s changed to %d', (p, p.value())) p2 = Pin(2, Pin.IN) p2_irq = p2.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=callback)
## https://learn.adafruit.com/circuitpython-basics-i2c-and-spi/spi-devices ## https://circuitpython.readthedocs.io/projects/busdevice/en/latest/api.html import board #hardware details of the specific board that you are using import busio import digitalio from board import * #from adafruit_bus_device.spi_device import SPIDevice import bitbangio import time with busio.SPI(SCK, MOSI, MISO) as spi_bus: cs = digitalio.DigitalInOut( D5) # chip select == Latch_pin == 74hc595 pin 12 # device = SPIDevice(spi_bus, cs) device = bitbangio.I2C(board.D52, board.D51) # show which pins are these on print("sck ", SCK) # 74hc595 pin 11 print("mosi ", MOSI) # 74hc595 pin 14 print("miso ", MISO) # not used bytes_read = bytearray(4) # read buffer bytes_write = bytearray(1) # one byte buffer for write data # The object assigned to spi in the with statements below # is the original spi_bus object. We are using the busio.SPI # operations busio.SPI.readinto() and busio.SPI.write(). while True: for testData in range( 256 ): # for an example lets transmit all values 0 to 255 one at a time.
# Set default state to 'off' nrf.listen = False nrf.power = False print("Finished initializing nRF24 module") ### Initialize neopixel output ledPin = board.NEOPIXEL pixelMain = neopixel.NeoPixel(ledPin, 1, pixel_order=neopixel.GRB) pixelMain.fill((0, 0, 0)) # turn off on startup print("Finished initializing neopixel") ### Initialize MPU6050 sensor # Initialize soft I2C softScl = board.D2 # manual serial clock line softSdl = board.D3 # manual serial data line i2c = bitbangio.I2C(softScl, softSdl) # software i2c # Initialize MPU6050 object sensor = adafruit_mpu6050.MPU6050(i2c) sensor.cycle_rate = adafruit_mpu6050.Rate.CYCLE_40_HZ # update cycle rate sensor.cycle = True # only periodically update sensor (saves power!) print("Finished initializing mpu6050") # Setup calibrated accel values numAvgValues = 7 listAccelX = [None] * numAvgValues listAccelY = [None] * numAvgValues listAccelZ = [None] * numAvgValues listFaceIdx = [0] * numAvgValues ### Other things
# and let's make 0 = 50% = 1.65V # Dictionaries/structures containing data for each 'SENSOR' mouse = { 'Name': '1', 'File': open('/dev/input/mouse0'), 'dx': 0, 'dy': 0, 'xbusSDA': 2, 'xbusSCL': 3, 'ybusSDA': 17, 'ybusSCL': 27 } # initialize I2C buses (X: SDA 2 SC: 3; Y: SDA 17 SCL 27) i2cX = bitbangio.I2C(3, 2) i2cY = bitbangio.I2C(27, 17) # initialize MCP4725 dacX = adafruit_mcp4725(i2cX) dacY = adafruit_mcp4725(i2cY) # Declare variables transmit_timer = None data_lock = Lock() ppm = 3937 # num pixels per meter maxv = 1.5 # max velocity (m/s) transmit_delay = .01 #.01 read_delay = .001 #0.001 distCalib = 1 / ppm / transmit_delay / maxv / 2
# This file is executed on every boot (including wake-boot from deepsleep) import esp esp.osdebug(None) import gc gc.collect() import network wlan = network.WLAN(network.STA_IF) wlan.active(True) from board import * import bitbangio as io i2c = io.I2C(SCL, SDA) from adafruit_pca9685 import motor motors = motor.DCMotors(i2c) motors.brake(0) motors.brake(3) import Robot carro = Robot.Control(motors) # replserver boot code try: import usocket as socket except: import socket import os import webrepl webrepl.start(password='******') replpath = "webrepl-inlined.html.gz"