In this article, we'll see how to program Particle Electron in Python using Zerynth to develop cellular-connected electronics projects and products in a few clicks.
Particle Electron PlatformParticle Electron is a GSM enabled development platform for creating cellular-connected electronics projects and products with M2M in mind. It comes with a Particle SIM card with service in more than 100 countries worldwide, and includes 3 months of Particle’s 1MB monthly data plan for IoT devices.
Particle Electron combines a powerful ARM Cortex M3 microcontroller (STM32F205RG Cortex M3) with a 3G/2G gsm module from UBlox (U260 or G350). In addition to having 1Mb of internal flash memory for storing the firmware, the Particle Electron also features 128k of RAM and 120 MHz of clock.
Particle Electron Board Summary- Microcontroller: ARM 32-bit Cortex™-M3 CPU Core
- Operating Voltage: 3.3V
- Input Voltage: 3.6-6V
- Digital I/O Pins (DIO): 28
- Analog Input Pins (ADC): 14
- Analog Outputs Pins (DAC): 1
- UARTs: 5
- SPIs: 2
- I2Cs: 1
- CANs: 1
- Flash Memory: 1Mb
- SRAM: 128 KB
- Clock Speed: 120Mhz
- Cellular modem: U-Blox SARA U-series (3G)
- Board dimensions: 2.0″ x 0.8″ x 0.3″ (0.5″ including headers)
From Particle Store:
- Particle’s data plan
- Particle Electron board
- Particle SIM Card
From Zerynth:
Miscellaneous:
- Li-Po battery (2000mAh)
- USB cable
The Electron is equipped with on-board power management circuit powered by BQ24195 pm unit and MAX17043 fuel gauge. The Electron can be powered via the VIN (3.9V-12VDC) pin, the USB Micro B connector or a LiPo battery. When powered from a LiPo battery alone, the power management IC switches off the internal regulator and supplies power to the system directly from the battery.
Connect and Virtualize a Particle ElectronIf you hadn’t done it yet, download and install Zerynth Studio.
Then connect the board to your PC. On Windows machines, the Particle Electron USB Drivers are required by the Zerynth Studio for accessing the serial port establishing a connection with the STM32 UART. More detailed info on the related Zerynth Doc section.
Follow these steps to register and virtualize a Particle Electron:
Put the Electron in DFU Mode (Device Firmware Upgrade):
- Hold down BOTH buttons (reset and setup)
- Release only the reset button, while holding down the setup button
- Wait for the LED to start flashing magenta, then yellow
- Release the setup button; the device is now in DFU Mode (yellow blinking LED)
- Select the Electron on the Device Management toolbar
- Register the device by clicking the “Z” button from the Zerynth Studio
- Create a Virtual Machine for the device by clicking the “Z” button for the second time
- Virtualize the device by clicking the “Z” button for the third time
After virtualization, the Particle Electron is ready to be programmed and the Zerynth scripts uploaded.
Let’s start with the “HTTP Time GSM Example” example to show the capabilities of the Particle Electron.
Just follow the steps below (for more detailed info read this getting started):
Access the Quick Search Bar (more info here) through the shortcut Ctrl+P and type “GSM HTTP”
- Select the example and clone it by clicking on the dedicated button;
- At this stage, Zerynth Studio converts the example in a new project giving you the possibility to edit the Title and the Description. Remember that Zerynth Studio doesn’t allow two projects to have the same name. If you are trying to clone an example that you already cloned in the past leaving the default Title, then you need to give a different title to this new project.
- click on “Create” and you are done!
Code
Zerynth - HTTP Time GSM Example:
################################################################################
#
# HTTP Time GSM Example
#
################################################################################
# the classic wifi requests example, very little changes accessing
# the net through a gsm connection!
# import our gsm chip specific driver
from ublox.g350 import g350
# and the generic gsm module
from wireless import gsm
import streams
import requests
streams.serial()
# init the gsm driver!
# The driver automatically registers itself to the gsm interface
# with the correct configuration for the selected board
g350.auto_init()
print("Connecting...")
try:
# connect to our APN
gsm.connect_net('spark.telefonica.com')
except Exception as e:
print("ooops, something wrong while connecting :(", e)
while True:
sleep(1000)
# from now on everything is exactly identical to wifi HTTP Time Example ;)
# let's try to connect to timeapi.org to get the current UTC time
for i in range(3):
try:
print("Trying to connect...")
# we need to impersonate a web browser: as easy as setting the http user-agent header
user_agent = {"user-agent":"Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405"}
# go get that time!
# url resolution and http protocol handling are hidden inside the requests module
response = requests.get("http://www.timeapi.org/utc/now",headers=user_agent)
# let's check the http response status: if different than 200, something went wrong
print("Http Status:",response.status)
# if we get here, there has been no exception, exit the loop
break
except Exception as e:
print(e)
try:
# check status and print the result
if response.status==200:
print("Success!!")
print("-------------")
print("And the result is:",response.content)
print("-------------")
except Exception as e:
print("ooops, something very wrong! :(",e)
Now you have to uplink the code.
Just Select the virtualized device from the “Device Management Toolbar, click the dedicated “uplink” button of Zerynth Studio and reset the device by pressing the Reset on-board button when asked.
Done! Now you can see the result printed on the serial monitor!
Power SavingPower saving is the key for cellular IoT success.
One of the most important challenges of the cellular IoT technology is how to maximize the battery life. To meet this specification, Zerynth has included the “Power Saving” feature within the Zerynth Studio PRO version (Available from June 28), that will also include features like:
- Selectable RTOS
- Over the Air update development
- Hardware-driven Secured Firmware burned on the device at industrial volumes
- and many more
You still have few days to pre-order Zerynth Studio PRO with up to 50% discount!
Via Zerynth Academy
Comments