Exemplo n.º 1
0
            continue
    print("Connected to", str(esp.ssid, 'utf-8'), "\tRSSI:", esp.rssi)

    # Initialize a requests object with a socket and esp32spi interface
    requests.set_socket(socket, esp)


# setting up lora  ....

import adafruit_rfm9x

TIMEOUT = 5

cs = digitalio.DigitalInOut(board.A5)
reset = digitalio.DigitalInOut(board.A4)
rfm9x = adafruit_rfm9x.RFM9x(esp_spi, cs, reset, 915.0)

# setting up an indicator LED for the itsy on-board red LED on pin 13
led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
led.value = False

# main loop
attemptCount = 0

while True:

    gc.collect()

    try:
        else:
            return False
    else:
        if abs(prevOrigins[0][0] - currOrigin[0]) < pixels and abs(
                prevOrigins[0][1] - currOrigin[1]) < pixels:
            prevOrigins[0] = currOrigin
            return True
        else:
            return shouldntTransmit(prevOrigins[1:], currOrigin) or False


# Configure LoRa Radio
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0)
rfm9x.tx_power = 23
prev_packet = None

#ADDED FOR DUPLICATION CORRECTION
prevOrigins = []
currOrigin = tuple()
isDuplicate = False

#Instatiate a global variable 'persons_counter' to determine number of people detected
#Starting at 0 upon main call
persons_counter = 0


def classify_frame(net, inputQueue, outputQueue):
    # keep looping
import digitalio
import adafruit_rfm9x

# Define radio parameters.
RADIO_FREQ_MHZ = 915.0  # Frequency of the radio in Mhz. Must match your
# module! Can be a value like 915.0, 433.0, etc.

# Define pins connected to the chip.
# set GPIO pins as necessary - this example is for Raspberry Pi
CS = digitalio.DigitalInOut(board.CE1)
RESET = digitalio.DigitalInOut(board.D25)

# Initialize SPI bus.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
# Initialze RFM radio
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)

# enable CRC checking
rfm9x.enable_crc = True
# set delay before transmitting ACK (seconds)
rfm9x.ack_delay = 0.1
# set node addresses
rfm9x.node = 2
rfm9x.destination = 1
# initialize counter
counter = 0
ack_failed_counter = 0

# Wait to receive packets.
print("Waiting for packets...")
while True:
Exemplo n.º 4
0
    # Initialize a requests object with a socket and esp32spi interface
    requests.set_socket(socket, esp)


# lora

import adafruit_rfm9x

TIMEOUT = 5

lora_spi = busio.SPI(board.D13, MOSI=board.D11, MISO=board.D12)

cs = digitalio.DigitalInOut(board.D5)
reset = digitalio.DigitalInOut(board.D7)

rfm9x = adafruit_rfm9x.RFM9x(lora_spi, cs, reset, 915.0)

# bme280
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

# change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25

# main loop

index = 0

while True:

    print("radio waiting ...")
Exemplo n.º 5
0
import board
import time
import busio, digitalio
import adafruit_rfm9x
# Configure SD card (b/c it's on the the same SPI bus as radios)
sdcs = digitalio.DigitalInOut(board.CS_SD)
sdcs.switch_to_output(value=True)
# Define radios
rf_cs1 = digitalio.DigitalInOut(board.RF1_CS)
rf_rst1 = digitalio.DigitalInOut(board.RF1_RST)
rf_cs1.switch_to_output(value=True)
rf_rst1.switch_to_output(value=True)
rf_cs2 = digitalio.DigitalInOut(board.RF2_CS)
rf_rst2 = digitalio.DigitalInOut(board.RF2_RST)
rf_cs2.switch_to_output(value=True)
rf_rst2.switch_to_output(value=True)
# Setup SPI bus
spi  = busio.SPI(board.SCK,MOSI=board.MOSI,MISO=board.MISO)
# Initialize radio
try:
    radio1 = adafruit_rfm9x.RFM9x(spi, rf_cs2, rf_rst2, 433.0)
except Exception as e:
    print('[ERROR][RADIO 1]',e)
count = 0
radio1.tx_power = 23
while True:
    radio1.send('hello world {}'.format(count))
    count += 1
    print(count)
    time.sleep(1)
Exemplo n.º 6
0
        if speed > 0:
            speed += MIN_SPEED
        elif speed < 0:
            speed -= MIN_SPEED
        return speed * self.speed_multiplier
    def set_wheel_speed(self, signed_control_byte):
        self.motor.throttle = self.convert_byte_to_throttle(signed_control_byte)

i2c = board.I2C()
servokit = ServoKit(channels=16)

#initialize LoRa radio
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
radio_nss = DigitalInOut(board.A5)
radio_reset = DigitalInOut(board.A4)
radio = adafruit_rfm9x.RFM9x(spi, radio_nss, radio_reset, 915.0)

##initialize left gripper
left_gripper_sensor = DigitalInOut(board.D12)
left_gripper_sensor.direction = Direction.INPUT
left_gripper_sensor.pull = Pull.DOWN
left_gripper = Gripper(servokit.servo[LEFT_GRIPPER_SERVO],left_gripper_sensor)

##initialize right gripper
right_gripper_sensor = DigitalInOut(board.D13)
right_gripper_sensor.direction = Direction.INPUT
right_gripper_sensor.pull = Pull.DOWN
right_gripper = Gripper(servokit.servo[RIGHT_GRIPPER_SERVO],right_gripper_sensor)

##initialize wheel motors
ain1 = pulseio.PWMOut(board.D5)
Exemplo n.º 7
0
import random
import threading

RADIO_FREQ_MHZT = 868.0  # Frequency of the radio in Mhz. Must match your
RADIO_FREQ_MHZR = 869.0

CS = digitalio.DigitalInOut(board.CE1)
RESET = digitalio.DigitalInOut(board.D25)

CS2 = digitalio.DigitalInOut(board.D17)
RESET2 = digitalio.DigitalInOut(board.D5)

spiR = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
spiT = busio.SPI(board.D21, MOSI=board.D20, MISO=board.D19)

rfm9xR = adafruit_rfm9x.RFM9x(spiR, CS, RESET, RADIO_FREQ_MHZR)
rfm9xT = adafruit_rfm9x.RFM9x(spiT, CS2, RESET2, RADIO_FREQ_MHZT)

# Radio 1: Transmitter
# enable CRC checking
#rfm9xT.enable_crc = True
rfm9xT.node = 4
rfm9xT.destination = 3
rfm9xT.tx_power = 5
rfm9xT.spreading_factor = 10
rfm9xT.ack_retries = 1
#rfm9xT.signal_bandwidth = 125000
counterT = 0

# Radio 2: Receiver NOT WOKRING
# enable CRC checking
Exemplo n.º 8
0
    'passwd': config['APRS']['Passcode'],
    'host': config['APRS'].get('Host', fallback='rotate.aprs.net'),
    'port': config['APRS'].getint('Port', fallback=14580)
}

AIS = APRS_IS(config['APRS']['Callsign'], **connect_kwargs)
try:
    # Configure LoRA model pins
    CS = digitalio.DigitalInOut(
        getattr(board, config['LORA'].get("PinCS", "CE0")))
    RESET = digitalio.DigitalInOut(
        getattr(board, config['LORA'].get("PinReset", "D25")))
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

    # Create LoRa modem connection and configure it
    rfm9x = adafruit_rfm9x.RFM9x(
        spi, CS, RESET, config['LORA'].getfloat('Frequency', fallback=433.775))
    rfm9x.signal_bandwidth = config['LORA'].getfloat('Bandwidth',
                                                     fallback=125000)
    rfm9x.spreading_factor = config['LORA'].getint('SpreadingFactor',
                                                   fallback=12)
    rfm9x.coding_rate = config['LORA'].getint('CodingRate', fallback=5)
    rfm9x.enable_crc = True

    # connect to APRS iGate
    AIS.connect(blocking=True)

    time.sleep(1)

    gwpos = create_gateway_announcement()
    logger.info('Announce Gateway: "%s"', gwpos)
    AIS.sendall(gwpos)  # TODO: announce regularly
Exemplo n.º 9
0
#CS and reset are correct (we checked with meters)
cs = digitalio.DigitalInOut(board.P2_31)
reset = digitalio.DigitalInOut(board.P2_8)
mypin = digitalio.DigitalInOut(board.P2_25)
"""
mypin.direction = digitalio.Direction.OUTPUT
mypin.value = False
print("Should be low right now")
time.sleep(1)
mypin.value = True
"""
print(repr(board))
print(repr(adafruit_blinka.board.beagleboard.beaglebone_pocketbeagle))
sck = board.SCLK_1  #board.P2_29
mosi = board.MOSI_1  #board.P2_25
miso = board.MISO_1  #board.P2_27

spi = busio.SPI(sck, mosi, MISO=miso)
rfm9x = adafruit_rfm9x.RFM9x(spi, cs, reset, RADIO_FREQ_MHZ, baudrate=9600)
print(rfm9x)
rfm9x.node = ord("t")
while True:
    packet = rfm9x.receive(keep_listening=True, with_header=True)
    #receive(*, keep_listening=True, with_header=False, with_ack=False, timeout=None)
    if packet is not None:
        print("Received a pak")
    else:
        print("Packet was not recieved")
        print(packet)
    time.sleep(1)
# Define pins connected to the chip, use these if wiring up the breakout according to the guide:
CS = digitalio.DigitalInOut(board.D5)
RESET = digitalio.DigitalInOut(board.D6)
INT = digitalio.DigitalInOut(board.D24)
# Or uncomment and instead use these if using a Feather M0 RFM9x board and the appropriate
# CircuitPython build:
# CS = digitalio.DigitalInOut(board.RFM9X_CS)
# RESET = digitalio.DigitalInOut(board.RFM9X_RST)

# Define the onboard LED
LED = digitalio.DigitalInOut(board.D13)
LED.direction = digitalio.Direction.OUTPUT

# Initialze RFM radio
# Assume that CS is connected to channel 1, pin 7
rfm9x = adafruit_rfm9x.RFM9x(RESET, INT, RADIO_FREQ_MHZ)

# Note that the radio is configured in LoRa mode so you can't control sync
# word, encryption, frequency deviation, or other settings!

# You can however adjust the transmit power (in dB).  The default is 13 dB but
# high power radios like the RFM95 can go up to 23 dB:
rfm9x.tx_power = 23

# Send a packet.  Note you can only send a packet up to 252 bytes in length.
# This is a limitation of the radio packet size, so if you need to send larger
# amounts of data you will need to break it into smaller send calls.  Each send
# call will wait for the previous one to finish before continuing.
rfm9x.send(bytes("Hello world!\r\n", "utf-8"))
print('Sent Hello World message!')
Exemplo n.º 11
0
    def __init__(self):
        self.hardware = {
            'IMU': False,
            'Radio1': False,
            'Radio2': False,
            'SDcard': False,
            'GPS': False,
            'MRAM': False,
            'WDT': False,
            'USB': False,
            'PWR': False,
        }

        # Define burn wires:
        self._relayA = digitalio.DigitalInOut(board.RELAY_A)
        self._relayA.switch_to_output(
            drive_mode=digitalio.DriveMode.OPEN_DRAIN)
        self._deployA = False

        # Define battery voltage
        self._vbatt = analogio.AnalogIn(board.BATTERY)

        # Define MPPT charge current measurement
        self._ichrg = analogio.AnalogIn(board.L1PROG)

        # Define SPI,I2C,UART
        self.i2c = busio.I2C(board.SCL, board.SDA)
        self.spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
        self.uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=10)

        # Define GPS
        self.en_gps = digitalio.DigitalInOut(board.EN_GPS)
        self.en_gps.switch_to_output()

        # Define sdcard
        self._sdcs = digitalio.DigitalInOut(board.xSDCS)
        self._sdcs.switch_to_output(value=True)

        # Define radio
        self._rf_cs1 = digitalio.DigitalInOut(board.RF1_CS)
        self._rf_rst1 = digitalio.DigitalInOut(board.RF1_RST)
        self._rf_cs1.switch_to_output(value=True)
        self._rf_rst1.switch_to_output(value=True)
        self._rf_cs2 = digitalio.DigitalInOut(board.RF2_CS)
        self._rf_rst2 = digitalio.DigitalInOut(board.RF2_RST)
        self._rf_cs2.switch_to_output(value=True)
        self._rf_rst2.switch_to_output(value=True)

        # Define MRAM (manual-mode)
        # self._mram_cs = digitalio.DigitalInOut(microcontroller.pin.PB11)
        # self._mram_cs.switch_to_output(value=True)

        # Initialize Neopixel
        try:
            self.neopixel = neopixel.NeoPixel(board.NEOPIXEL,
                                              1,
                                              brightness=0.2,
                                              pixel_order=neopixel.GRBW)
            self.neopixel[0] = (0, 0, 0)
            self.hardware['Neopixel'] = True
        except Exception as e:
            print('[WARNING][Neopixel]', e)

        # Initialize USB charger
        try:
            self.usb = bq25883.BQ25883(self.i2c)
            self.usb.charging = False
            self.usb.wdt = False
            self.usb.led = False
            self.usb_charging = False
            self.hardware['USB'] = True
        except Exception as e:
            print('[ERROR][USB Charger]', e)

        # Initialize sdcard
        try:
            self._sd = adafruit_sdcard.SDCard(self.spi, self._sdcs)
            self._vfs = storage.VfsFat(self._sd)
            storage.mount(self._vfs, "/sd")
            sys.path.append("/sd")
            self.hardware['SDcard'] = True
        except Exception as e:
            print('[ERROR][SD Card]', e)

        # Initialize Power Monitor
        try:
            self.pwr = adm1176.ADM1176(self.i2c)
            self.pwr.sense_resistor = 1
            self.hardware['PWR'] = True
        except Exception as e:
            print('[ERROR][Power Monitor]', e)

        # Initialize IMU
        try:
            self.IMU = bmx160.BMX160_I2C(self.i2c)
            self.hardware['IMU'] = True
        except Exception as e:
            print('[ERROR]', e)

        # Initialize radio(s)
        try:
            self.radio1 = adafruit_rfm9x.RFM9x(self.spi, self._rf_cs1,
                                               self._rf_rst1, 433.0)
            self.hardware['Radio1'] = True
        except Exception as e:
            print('[ERROR][RADIO 1]', e)
        try:
            self.radio2 = adafruit_rfm9x.RFM9x(self.spi, self._rf_cs2,
                                               self._rf_rst2, 433.0)
            self.hardware['Radio2'] = True
        except Exception as e:
            print('[ERROR][RADIO 2]', e)
Exemplo n.º 12
0
import board
# Import the SSD1306 module.
#import adafruit_ssd1306
# Import the RFM9x radio module.
import adafruit_rfm9x
import serial, string

CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
# spi.max_speed_hz=5000000
# while not spi.try_lock():
#     pass
# spi.try_lock()
# spi.configure(baudrate=433000000, phase=0, polarity=0)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0, baudrate=1000000)
rfm9x.tx_power = 20
prev_packet = None

msg_count = 0;
output = " "
ser = serial.Serial('/dev/ttyACM0', 115200, 8, 'N', 1, timeout=1)

while True:
    # packet = rfm9x.receive()
    # ife_string = str(formula_electric)
    data = bytes("ife_string", "utf-8")
    output = ser.readline()
    if output != " ":
        print ("send " + str(msg_count))
        rfm9x.send(output)