Quick Start- LoPy


Top three reasons why we like the LoPy:

  1. Programmable with MicroPython
  2. Three different wireless options creates many possibilities- LoRa, BLE, wifi
  3. Dual processor- main processor is entirely free to run the user application
LoPy Module

LoPy Module

Requires some knowledge of Python or experience with programming using IDEs.


Get It Now





Quick Start

Before you start, contact KotahiNet for a free network connection. We will send ABP (Activation By Personalisation) details you need to enter into the code. Remember to check there is network coverage in your area.

Refer to Pycom’s Quickstart Guide for more details about the steps below.

The LoPy firmware is under active development. As a first step, place the LoPy on the expansion board and put in flashing mode by using a wire to connect the fourth pin on the left from the top to the second pin on the right from the top. Then connect the expansion board to your computer with a USB cable and run the firmware update tool.

Putting the LoPy in flash mode

Putting the LoPy in flash mode

IMPORTANT: On first running the firmware update tool, when asked for country, DO NOT select New Zealand as the frequency set will not allow for KotahiNet’s channels. Choose any EU country instead.

If you’re having problems with flashing the LoPy, this checklist might help. Tip: if you’re using Windows and can’t find the updater shortcut installed by the firmware updater tool, look for Pycom Firmware Update in the Start menu.

After flashing the latest firmware, download and install Pycom’s IDE, Pymakr, for your OS from the Resources page. While Pycom is retiring Pymakr in favour of other tools and plugins, it remains an easy way to get started.

Connect the LoPy placed on the Expansion Board to a USB port where it will set up as a COM device. On then running Pymakr for the first time, go to Settings > Preferences > Pycom Device and select the COM port from the dropdown box. The User and Password boxes are to be left empty. This step is only required once.

Other options to connect to the LoPy include wifi. Follow these instructions.


Click New to open a new file. Copy the code below and paste by right clicking in the file pane.

IMPORTANT: Change the dev_addr (Device Address), nwk_swkey (Network Session Key), and app_swkey (Application Session Key) in the code to that provided by KotahiNet. Follow the same formatting in terms of using pairs.

Click on the green arrow to run the code once.

Data sent will be visible on a web page. KotahiNet will provide the details about this when providing your ABP details.


from network import LoRa
import socket
import binascii
import struct

# Initialize LoRa in LORAWAN mode.
lora = LoRa(mode=LoRa.LORAWAN)

# Set up KotahiNet channels
lora.add_channel(0, frequency=864862500, dr_min=0, dr_max=5)
lora.add_channel(1, frequency=865062500, dr_min=0, dr_max=5)
lora.add_channel(2, frequency=865402500, dr_min=0, dr_max=5)
lora.add_channel(3, frequency=865602500, dr_min=0, dr_max=5)
lora.add_channel(4, frequency=865985000, dr_min=0, dr_max=5)
lora.add_channel(5, frequency=866200000, dr_min=0, dr_max=5)
lora.add_channel(6, frequency=866400000, dr_min=0, dr_max=5)
lora.add_channel(7, frequency=866600000, dr_min=0, dr_max=5)

# create ABP authentication params- REPLACE WITH THOSE PROVIDED BY KOTAHINET
dev_addr = struct.unpack(“>l”, binascii.unhexlify(’01 57 BB 85′.replace(‘ ‘,”)))[0]
nwk_swkey = binascii.unhexlify(’97 AB 74 B7 C8 22 FA E3 1E C3 DF AD 5F 84 27 17’.replace(‘ ‘,”))
app_swkey = binascii.unhexlify(’44 AB FE E3 35 3B BD 80 6D B1 05 E7 CD 59 6C 31’.replace(‘ ‘,”))

# join a network using ABP (Activation By Personalization)
lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))

# create a LoRa socket
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)

# set the LoRaWAN data rate
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 0)

# make the socket blocking

# send some data
s.send(bytes([0x01, 0x02, 0x03]))
print(‘data sent’)

# get any data received…
data = s.recv(64)


Tip: if you get the error below it is because New Zealand has been selected as the install country.

File “<stdin>”, line 10, in <module>
ValueError: invalid argument(s) value