Pycom GPy Getting Started

Chris just shared a new tutorial: "Pycom GPy Getting Started"

The main thing I want you to get out of this project is this: upon completion you will have cellular data connected to your Internet of Things device! LoRa, Sigfox, Bluetooth and WiFi can’t compete with cellular data for coverage, speed and…

Read more

Well, I know I’d love to see the GPy-LoJack in the Projects section.

Hi, I am developing some products using the Pycom GPY as a core element for comm’s - it’s a very useful device.

I found your “Pycom GPy Getting Started” document very helpful in checking my own version of the comms/RTC function, which is simiar to yours but with a few enhancements.

I have no problem running the code the first time snd then on a second run it correctly bypasses the LTE setup - as it should… all good to that point.

But if I want to run it a 3rd or more times the code fails at the lte = LTE() variable - if I has it out then it will run as many times as I like but of course won’t run the first time. Being able to run the RTC code is something I will be wanting to do to refresh the RTC to (i) keep it corrected and (ii) to refresh a date time stamp for writing and sending data .

Have you noticed this behaviour and is there a fix you are aware of?

Steve Williams


Hi Steve,

I find myself using LoPy4 though not a lot of time with the Gpy. Given it’s more of a code question, it would be best to engage Pycom directly on their forum. Please do share the outcome here afterwards though, I’m all ears!

Tip - just share the bare minimum code to replicate the issue on the Pycom forum.

Hi Graham…

I had tried the Pycom forum without much luck, along with web searches - not helped by time zone differences.

I’m a bit of an experimenter so after a bit of trial and error I used this code in the ‘try’ section…


if not rtc.synced():

global lte

lte = LTE()


for z in range (0,(trpt * 60) / td):

dcdts = getCDTS()


RTC is updated every 5 seconds


This sets a global LTE variable only when the code is first run, for subsequent runs the variable is ignored,

I will need add in some code to run the LTE set up variable on demand, but that won’t be hard - just another variable to be set as a flag… :slight_smile:

I have attached the whole code file for your information - but this little bit of code is a work in progress… the getCDTS function is still being tweaked - getting it to sync to a 0 or 5 least significant seconds value (for creating folder names) - but it isn’t working to my satisfaction yet.

I note that you supply a lot of the hardware I am using so when it comes to build up a first prototype run of 110 units, I will get a quote from you.

1 Like

A while ago I used your tutorial to help me get my GPY set up and working on the Telstra network, when I had just received it. I have been having trouble just recently with the LTE not attaching (it had been doing so just fine for months). In trying to resolve the problem, discussing the issue with Pycom, they have advise that the AT!= command should never be issued in a Pycom device? The tutorial includes lte.send_at_cmd(‘AT!=“RRC::addscanfreq band=28 dl-earfcn=9410”’) and others.

Pycom suggest instead to use lte=LTE(carrier=“telstra”) are you guys aware of this? I’ve tried to use the instruction but my LTE still won’t attach? I presume (information is sketchy from Pycom) that the band and other information is now built in to the Seqans firmware so all that has to be done is to select the required carrier.

Hi Steve,

At the time of writing this was a working way to connect your GPy to LTE. Firmware updates by Pycom might have changed this. There is an upcoming set of Tutorials that I am making on connecting Pycom devices to the various networks offered. Keep and eye out for those!

In regard to the AT!= commands, I was not aware of any problems with using that command, Pycom would know best though!

From the Pycom Forum…

If your APN has User and Password, Which is the AT command for setting up those parameters in the Cellular Modem?

Hi Juan,

Who is your APN that requires a User and Password? I don’t see any direction within the docs for how to do that.

Thanks for the Reply, The Carrier it’s T-Mobile Austria. However, I have found the code:

    print(".", end='')

But I still not capable to connect to the LTE-NB. I have tested in my phone, it connects to the network carrier (just for data). Any idea how to debug ?

Hi Juan,

This device requires LTE cat m1, which is only offered by Telstra. It is possible to connect to NB-IoT, but you need to re-flash the firmware. The only help I can give you with that path, and everything that lies beyond it, is direct you to the Pycom docs about it:

A fantastic tutorial, thanks everyone at CORE Electronics, it gave me a great start!

However Pycom have developed their firmware since this was written, so some of the complexity in now abstracted.

The LTE() object now identifies the carrier from the SIM card and all of the AT+ commands can be commented out, see below. I am not sure if the reset is still needed.
@Stephen do you have these tutorials on Github where I can push changes?
I confirmed this on a GPy running 1.18.2.r3 pycom firmware on a CatM1 Telstra in Australia.

    # While the configuration of the CGDCONT register survives resets,
    # the other configurations don't. So just set them all up every time.
    # print("Configuring LTE ", end='')
    # lte.send_at_cmd('AT+CGDCONT=1,"IP","telstra.internet"')
    # print(".", end='')
    # lte.send_at_cmd('AT!="RRC::addscanfreq band=28 dl-earfcn=9410"')
    # print(".", end='')
    # lte.send_at_cmd('AT+CFUN=1')
    # print(" OK")

Hi Phil,

I’ll look into it :slight_smile:

Hi Phil,

Could you share the whole code that you have confirmed is working? I’ll create a Git for it, but for now I’d like to get it up on this page so it can continue to be a resource.

I am following your tutorial and trying to import LTE ( from network import LTE) in my gpy. The problem I have is that I get an error like
Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name LTE
Why doesn’t my gpy recognize the LTE module?
Thank you.

Hi Jacob,

I’m not too sure! Perhaps thats a question for the Pycom forum. Have you updated the firmware on your Gpy lately?

I recently bought a GPy for a project that I’m working on, but for the last 3 weeks I had no luck. I’m using Atom with the Pymakr package, and did some test code like changing the LED color and that worked, but when I try a code that I found on a tutorial, I got no answer at all.
I am from Mexico and using an AT&T sim, have someone made that work?
Any help will be very appreciated

Hey @Alonso98639,

Could you give us some more information and post your code here? This will allow us to see whats going on .

import time
from machine import RTC
from network import LTE


# Need to use global variables.
# If in each function you delare a new reference, functionality is broken
lte = LTE()
rtc = RTC()

# Returns a network.LTE object with an active Internet connection.
def getLTE():

    # If already used, the lte device will have an active connection.
    # If not, need to set up a new connection.
    if lte.isconnected():
        return lte

    # If correctly configured for carrier network, attach() should succeed.
    if not lte.isattached():
        print("Attaching to LTE network ", end='')
            if lte.isattached():
                print(" OK")
            print('.', end='')

    # Once attached, connect() should succeed.
    if not lte.isconnected():
        print("Connecting on LTE network ", end='')
            if lte.isconnected():
                print(" OK")
            print('.', end='')

    # Once connect() succeeds, any call requiring Internet access will
    # use the active LTE connection.
    return lte

# Clean disconnection of the LTE network is required for future
# successful connections without a complete power cycle between.
def endLTE():

    print("Disonnecting LTE ... ", end='')
    print("Detaching LTE ... ", end='')

# Sets the internal real-time clock.
# Needs LTE for Internet access.
def setRTC():

    # Ensures LTE session is connected before attempting NTP sync.
    lte = getLTE()

    print("Updating RTC from {} ".format(NTP_SERVER), end='')
    while not rtc.synced():
        print('.', end='')
    print(' OK')

# Only returns an RTC object that has already been synchronised with an NTP server.
def getRTC():

    if not rtc.synced():

    return rtc

# Program starts here.
    print("Initially, the RTC is {}".format("set" if rtc.synced() else "unset"))
    rtc = getRTC()
        print("RTC is {}".format( if rtc.synced() else "unset"))
except Exception:
    pass # do nothing on error