- Octopus, a “tentacular” shield for Arduino and FishinoPosted 4 days ago
- Keychainino: a programmable, playful Key RingPosted 2 weeks ago
- Let’s Build an open source Quadcopter – Part2Posted 3 weeks ago
- Let’s Build an open source Quadcopter – Part1Posted 4 weeks ago
- An open source 3D Scanner made with Raspberry PiPosted 1 month ago
- Open Wheels 2: an all-in-one board to control any of your robotic ProjectsPosted 1 month ago
- GuppY: Fishino becomes NanoPosted 2 months ago
- FISHINO becomes MegaPosted 2 months ago
- Discovering OpenSCAD – part 2: advanced functionsPosted 2 months ago
- How to make an OpenSource Vertical PlotterPosted 2 months ago
The Zerynth Framework: programming IoT with Python
ZERYNTH, formerly known as VIPER, is a software suite used for the programming of interactive items, that are ready for the cloud and the Internet of Things. ZERYNTH enables the development in Python, on the most widespread prototyping platforms, and by using paradigms and features that are typical of a high level programming.
Nowadays, everyone is connected to the Internet. It’s not just persons, everything is connected or may be connected: that’s the IoT revolution. Televisions, lamps and “smart” thermostats are starting to appear peremptorily in our houses, and it is already possible today to have alarm clocks that are synchronized to the city traffic service, and washing machines that decide the best washing function in our place, depending on the atmospheric conditions.
If there are only a few million items of this kind, today, in a few years they will be billions. All the major manufacturers of consumer goods are thinking at how to acquire useful information and at how to analyze the great amounts of data that these items will exchange in order to offer new services. The greatest part of these devices have a microcontroller inside, which enables its functioning, and also its connection to the Internet. However, in order to have this “Internet of Things” to be able to achieve its potential, some practical projects are needed, so to make even the simplest items of everyday life “smart”.
For example, is it possible to connect the toaster to the Internet? And what about the dog bowl? And the baby cradle?
From a technical point of view, all of this can surely be done.
Surely, the prototyping platforms (such as Arduino, ST Nucleo, Core and Particle’s Photon) are not lacking. Moreover, in order to have each item of everyday life becoming smart, it is needed to supply it with both sensors and actuators, that are capable of making it interactive.
Thanks to the ZERYNTH Shield, each item of everyday usage will be able to exchange information with the environment and, obviously, with the people. We will see the ZERYNTH Shield in detail, in the following paragraphs.
Break down the barriers between Hardware and Software
A part of the difficulties hindering the development of the IoT lies in the “linguistic” barriers between man (who wants to prototype his ideas in a simple and flexible way) and hardware (that requires specific instructions). The real problem is that it would require “advanced” information technology competences, far too advanced for the market these electronic boards refer to. On the other hand, if we want interactive items, we have to try hard to create devices that are capable of executing many activities at the same time. This requires the learning of paradigms such as the real-time, the interrupts, the callbacks, that are not very simple to learn and manage. But if on one hand the prototyping boards are now available to everyone, on the other one many people encounter quite some difficulties when approaching such boards: first of all, they have to know how to program well in C, or in the other programming languages that each board requires. This would already exclude a good part of the people that could see a renewal and an evolution of their professionalisms in the IoT: artisans, web designers, and also artists and window dressers.
From the opposite side, the current situation often turns out to be a not very flexible one, even for the most expert programmers, since it suffices that the need to change the board for their project arises, that they have to restart writing code from the beginning, and in the programming language required by the new board.
To do so that each user may program his interactive items, the approach to their programming needs to be changed.
In the hope to simplify the way with which these “things” are programmed and connected to the Internet, ZERYNTH gathers a series of software components to better automatize the development process of interactive items.
ZERYNTH, available for the download as open source: is a multiplatform (Linux, Windows and Mac) work suite that enables the programming of the greatest part of the 32-bit boards actually available on the market: from the professional boards used in the industrial field to the most well-known prototyping boards for hobbyists, such as Arduino DUE, UDOO, Particle and ST Nucleo.
Moreover, ZERYNTH is programmed in Python, that is one of the easiest and most intuitive programming languages among the existing ones. Python is in fact used in both schools and universities, and in the professional world.
Thanks to its slender and powerful syntax and to the multiplatform support, it is used for many kinds of applications: from the networking, to the web, to the graphics.
ZERYNTH’s peculiarity lies in the fact that it manages to combine the ease of use with professional performances. That’s precisely what occurred with Photoshop, the most well-known photo editing software, now indiscriminately used by students, amateur and professional photographers alike.
ZERYNTH guarantees a rapid development and an effective integration with sensors, actuators and cloud services, thus reducing times and energies used for the development.
The code used in the prototyping phase, in fact, may be used again for both the electronics selected for the production in series, and for the future project updates, or even on another board among those that are supported.
ZERYNTH’s idea is born out of the need to optimize such processes, by means of a web interface used to manage and program the boards, of a virtual machine operating in “real time” and of an extended library of ready-to-use functions.
Moreover, the suite includes a mobile App that enables the control of the ZERYNTH items by means of smartphones, thus without having to develop specific Apps for each project. All of this is already “natively connected to the cloud”. Such a configuration allows to reduce times and the energies used for the development.
In detail, ZERYNTH is composed of:
• ZERYNTH STUDIO: a multiplatform and browser-based development environment, with cloud synchronization and storage of the projects;
• ZERYNTH VM: a Virtual Real-Time Machine for 32-bit microcontrollers, written in Python 3, with multi-threading support.
It is compatible with all the boards upon the 32-bit ARM chip, such as Arduino Due, UDOO, Particle, STNucleo.
• the ZERYNTH Library: a set of modules including the CC3000 of Spark Core’s Wi-Fi and Adafruit’s Wi-Fi shield, the Adafruit/Sparkfun thermal printer, the NeoPixel LED ring, the RTTL smart melody player, a signals library of the Streams kind, as well as the TCP and UDP protocols.
• the ZERYNTH APP: an app, available for both iOS and Android, that acts as an interface to drive the boards that have been programmed by means of ZERYNTH, without having to use switches or potentiometers. The command interface can be customized for each single project, since technically the app is a HTML client that displays the templates defined by the Python scripts inside the ZERYNTH Objects’ memory.
In respect to other solutions, ZERYNTH is natively cross-platform and compatible with all the 32-bit boards that are based on ARM32, and has a great number of sensors and kits for a rapid prototyping.
Moreover, it integrates a real-time operating system, and enables the data analytics concerning the board and the components.
Differently from those who carry out the product prototyping by means of Arduino or Raspberry Pi development suites, ZERYNTH makes it easier to use the industrial components, in order to create commercial products that are ready for the market. With a few lines of code, the users may develop a wide selection of IoT applications, ranging from home automation to fitness, from robotics to seamanship, from the industrial applications to the remote maintenance controls, and up to smart agriculture.
How ZERYNTH works
Very briefly, ZERYNTH works by deleting the standard firmware of the boards on which it is installed, and by substituting it with an embedded operating system (ChibiOS) that features multithreading, and on which a Python 3 virtual machine relies on.
The “flashing” operation for the board’s firmware, that thus becomes “Virtualized”, is directly executed from the interface of the ZERYNTH’s programming environment.
The development environment includes the libraries needed in order to natively manage the most useful hardware and software components: from the Wi-Fi shields to the network protocols, from the sensors in general to the cloud services for the Internet of Things (such as, for example, Cometa www.cometa.cc ). ZERYNTH is capable of connecting the items to the network, via TCP and UDP, thus enabling the usage of HTTP and – on the boards on which cryptography is allowed – even of HTTPS.
Thus the data passing between the items and the network is safe! To this day, ZERYNTH runs on Arduino Due, Spark Core, Spark Photon, UDOO, ST Nucleo, Mikroelektronica Flip & Click, but potentially on countless other boards: that is, all of those that are based on the ARM architecture. In fact, regardless of the board, you are going to write in Python, and then ZERYNTH will adapt your program to the board of your choice.
It is very easy to use ZERYNTH:
1. you will have to download the Windows, Linux or iOS installer, from ZERYNTH STUDIO download page;
2. you will have to install it and to launch the application, by means of the icon now appeared on the desktop;
3. you will have to create a ZERYNTH user account, by means of the dedicated button, found up and on the right. Please check your e-mail and verify your new account, by clicking on the appropriate link (registering allows to participate to ZERYNTH’s community, to save your own project online in ZERYNTH’s Cloud, and to automatically receive updates);
4. you will have to connect the board and, possibly it may be renamed at leisure, so to easily recognize it in the future;
5. in order to make the board an usable one, you will have to “virtualize” it, that is to say, to install the ZERYNTH VM (Virtual Machine) on it, by means of the dedicated button in ZERYNTH STUDIO’s topbar;
6. you will have to create a new project or to clone an example, then to compile the script and to load it into the board.
A very simple example, in which it is possible to glimpse ZERYNTH potentialities, is given by the “Multiple LED Blink” (Listing 1).
# Initialize the digital pins where the LEDs are connected as output pinMode(D2,OUTPUT) pinMode(D3,OUTPUT) pinMode(D4,OUTPUT) # Define the ‘blink’ function to be used by the threads # delayON and delayOFF are optional parameters, used as default if not specified when you call the function def blink(pin,timeON=100,timeOFF=100): while True: digitalWrite(pin,HIGH) # turn the LED ON by making the voltage HIGH sleep(timeON) # wait for timeON digitalWrite(pin,LOW) # turn the LED OFF by making the voltage LOW sleep(timeOFF) # wait for timeOFF # Create three threads that execute instances of the ‘blink’ function. thread(blink,D2) # D2 is ON for 100 ms and OFF for 100 ms, the default values of delayON an delayOFF thread(blink,D3,200) # D3 is ON for 200 ms and OFF for 100 ms, the default value of delayOFF thread(blink,D4,500,200) # D4 is ON for 500 ms and OFF for 200 ms
Among the experts, to make a LED flash corresponds to the “Hello world” of the embedded devices… But with ZERYNTH it is possible to make it in a much more complex and entertaining way, and with even less toil. We are in fact able to make many LEDs flash at different frequencies, by using different separated threads, in a few lines of code.
Yes, you read it right: we may use the threads on boards of the Arduino kind! We will no longer have to write all of our code in a single logic loop, as it is typical of the imperative programming. With ZERYNTH , it is possible to proceed with a real multithread implementation! This example shows how to use ZERYNTH ’s thread in order to guide three LEDs with asymmetric flashing frequencies, that differ from one another.
Once the script has been executed, three threads are created (in addition to the main thread, that is always available), each one of them executes a specific instance of the “blink” function, with different parameters.
Each thread in ZERYNTH is a sort of separated and parallel process that operates autonomously on your board. A thread requires to execute a function as an input for the definition. The same function may be instanced by the various threads, by giving the possibility to write some very brief and readable code. With the threads it is possible to design your algorithm’s architecture, by taking advantage of the parallelism that is typical of high level systems.
Moreover, thanks to the passing parameters in Python, the default values may be defined by the inputs for each function. In this way it is possible to start the threads, without having to specify all the inputs required by the function. In the absence of the explicit value, the default values will serve to “fill the spaces”. In this case, all the “blink” function’s parameters will be passed as arguments to the functions.
The ZERYNTH Shield is a shield that is compatible with Arduino and Particle’s pin-outs and natively supported by ZERYNTH’s development environment.
It shows a set of commonly used sensors and actuators, among them there are touch detection sensors, infrared LEDs, a microphone, a luminosity sensor and a temperature sensor.
Moreover, there are the “Aux” ports, that enable the usage of other sensors, such as those of Grove, ThinkerKit, Phidgets, and Adafruit’s Neopixel LED strips.
The fact of having a series of sensors aboard, and all the most used communication ports ready to be connected, allows makers, artisans and designers to easily develop their smart objects, thus without having to deal with the electric circuit, and with the welding or the loose cables in the breadboard. It is enough to connect an Arduino Due or a Photon or a ST Nucleo to the shield, and to start to work with one of the ZERYNTH examples found in its library. The routing guarantees the compatibility of the ZERYNTH Shield with the greatest part of Arduino shields, such as the Ethernet, Wi-Fi and BLE shields. This means that the ZERYNTH shield can be easily docked on the top of your “shields’ heap”, without having any pin compatibility problem. The board has temperature, sound, light sensors available, and also a capacitive touch sensor and an IR receiver. Aboard it also has a piezoelectric buzzer and an IR LED emitter (actuator). The communication ports aboard are SPI and I²C-Bus; the board is completed by an Analog and a Digital Aux line, in addition to a PWM output and a port for Adafruit’s Neopixel LED strips.
The IR receiver is based on the TSOP34838 component, that may be used in order to read signals from the common 38 kHz IR devices, such as air conditioning and home theatre ones, and televisions. The IR receiver requires a digital input pin and is connected to the D2 pin on Arduino and to the A4 pin on Particle’s layout.
The temperature sensor belongs to the MCP9700/9701 series and converts the temperature into analog voltage. A key advantage of this thermistors’ series is the resistance to parasitic capacitance, and the ability to activate great capacitive loads. The integrated circuit’s output pin is connected to Arduino’s A4 pin and to the A1 pin on Particle formats.
The ZERYNTH Shield integrates a photoresistor, also known as light-dependant resistor (LDR). LDRs are variable low cost resistances in which the resistance changes, depending on the quantity of light hitting its surface. In dark environments the resistance is high; in lighted environments the resistance is low.
They may be used in order to answer to events such as the transition from day to night (and vice versa), for home automation applications and gardening, and are often used in order to control the street lighting.
The circuit is a simple voltage divider, that allows a quite accurate reading of the photoresistor’s resistance. The resistance that is an opposite to the LDR has been set to 20k, since the chosen LDR has a resistance varying from 12k to 36 k ohm. The sensor is connected to Arduino’s A5 pin and to the A0 pin on Particle formats.
A small amplified electret microphone with a gain of about 200 times is used in order to enable the detection of voices, environmental sounds and similar noises. The implemented circuit is based on a simple amplification stage, followed by a buffer. The microphone’s amplifier output is connected to Arduino’s A3 pin and to Particle’s A2 pin.
Capacitive Touch sensor
The ZERYNTH Shield integrates a capacitive touch sensor, based on the AT42QT1010 chip, an integrated component that is used in order to convert any capacitive surface in a button. The chip manages the monitoring of a conductive zone and is activated when the zone is touched. As long as a touch is detected (for example, a finger) the AT42QT1010 keeps the output signal at a high level. When the touch is interrupted, the signal is brough to the low level.
The AT42QT1010 sensor’s output is connected to the D7 pin on both Arduino and Particle. The touch’s pin can be connected to a metal surface, to be supplied with sensors by means of the expansion connector (P1).
This transducer, built upon the ZERYNTH shield, is needed in order to generate acoustic signals, tones and alarms. The buzzer is powered by means of the 5V line, in order to avoid interferences with the sensors. The buzzer is guided via the pins connected to Arduino’s D8 pin and to Particle’s A6 pin.
IR LED emitter
An IR LED, guided by a BJT, is connected to the D6 pin on Arduino, and to the A5 pin on Particle. A PWM wave is used in order to create infrared pulses, that may be received and decoded by common IR receivers.
Adafruit Neopixel LED
In the ZERYNTH Shield, a dedicated port for the connection of Adafruit’s Neopixel LED strips has been included. The power supply pin is connected to Particle’s Vin and to Arduino’s 5V pin. The pins to be used are the GND, the Vin, and the LED control pin. The command pin for the LED’s digital control is connected to the D9 pin on Arduino, and to the D6 pin on Particle. If the configuration includes more than 24 LEDs, in order to avoid possible damages to your board, it is needed to use an external 5V power supply, in order to power the LEDs.
It is a 8X2 male connector on which all the Aux pins are availablein table, in a configuration that is a compatible one with Seedstudio Grove modules’ analog and digital outputs. The expansion connector also allows an easy usage of the Phidgets and Thinkerkit modules, and also makes the 3.3V, 5V and GND power supply lines available. The expansion connector also allows to expose the SPI pins, but unfortunately this function, available with Arduino and Nucleo, is not available on Particle’s Photon, due to hardware limitations.
The ZERYNTH shield also includes a port on which to use the I²C. The port has a pin order that is compatible with the I²C Grove sensors and actuators (3,3, SCL, SDA, GND), and that enables the plug and play usage of these modules. Other manufacturer’s I²C devices may be used, but please pay attention to execute appropriate connections.
ZERYNTH Shield’s Library
The ZERYNTH shield has been developed so to make the life easier for smart objects developers. For this reason, ZERYNTH’s team has developed a control library that is dedicated to the ZERYNTH shield.
ZERYNTH Shield’s control library is released along with ZERYNTH ’s suite and includes various high level functions, that are ready to be used.
Some examples come from the average of the sensors’ signals and the filtering systems of the data coming from it.
There is also a series of smart functions, such as the “smart motion detection” that allows the usage of the luminosity sensor as a presence sensor, or the “double click”, that allows the detection of two close touches on a button, by means of the capacitive sensor. Let’s see a simple usage example of ZERYNTH Shield’s library on ZERYNTH STUDIO, as shown in Listing 2.
############################################################################################################ # TOI Shield basics # # Created by VIPER Team 2015 CC # Authors: L. Rizzello, G. Baldi, D. Mazzei ############################################################################################################ import streams import adc from drivers.toishield import toishield streams.serial() # toishield defines pin names in a board indipendent manner # let’s use them to read raw sensors values while True: print(“ Microphone:”,adc.read(toishield.microphone_pin)) print(“ Light:”,adc.read(toishield.light_pin)) print(“Temperature:”,adc.read(toishield.temperature_pin)) print(“ Touch:”,digitalRead(toishield.touch_pin)) # aux pins are also accessible! print(“ AUX1:”,adc.read(toishield.aux1.ADC)) print(“-”*40) sleep(500) # this scripts runs on every supported board, without a single change...cool isn’t it? 🙂
Finally, let’s analyze some possible usage scenarios: the union between ZERYNTH software tools and the ZERYNTH Shield may help people to monitor their home, by means of the wireless communication and without having to create tracks in the walls. Thus it will allow them to know, as an example, if the children have returned from school, or to turn off the heating if it has been accidentally left on, or to check from their workplace if the gas has been turned off. All of this can be carried out by means of their PC or smartphone.
Soon we will propose some simple, practical projects, that have been developed by means of firmware that has been written in ZERYNTH.