Showing only posts from category: MicroPython

Teckin ESP32

Read more

#Zerynth: ESP32 & Google IoT Core - Part 2: Getting data from Smart Power Outlets


This part 2 of the tutorial will allow you to get data from the smart power outlets and send it to the Google Cloud Platform (GCP) throught the Google IoT Core and using an ESP32 programmed with Zerynth (Python). This data is not usually available to the user (directly, you need to use the power outlet application), and it is sent to the company servers.

If you want to check, if your power outlets are compatible for this tutorial, they should have the port 6668 opened. To check that:

>>> nmap <<ip-address>> -p 6668
[...]
Host is up (0.13s latency).

PORT     STATE SERVICE
6668/tcp open  irc

If the answer is as shown above, the port is opened. If you don't have the nmap application and you are on Windows, look at the Nmap Network Scanning tool. On Ubuntu type on a terminal sudo apt-get install nmap.

Teckin ESP32

Read more

#MicroPython: Controlling Smart Power Outlets using an ESP32


Today there is a wide range of offer for home automation devices. A lot of sensors, actors etc. can be connected to the cloud and be controlled using Google Home, Amazon Alexa, your smartphone, etc. There are a lot of companies offering low cost devices, e.g. Sonoff, Tuya, Teckin etc. Most of these solutions are based on ESP32 or ESP8266, and all of them send data to cloud solutions usually deployed on Amazon services, and the data is only accessible using the Android/iOS applications. They can be also controlled using voice commands over Google Home or Amazon Alexa devices.

Nice, but... my aim was to control these devices locally (using LAN and not Wi-Fi) and send the data to the Google Cloud Platform (GCP) to make some analytics later. To be clear, when you use the Android/iOS application (or Google Home/Amazon Alexa) and you switch on/off e.g. a smart power outlet, the application connects with the company server in which the smart power outlet is registered and it sends the command. Then, the server sends back the action to your smart outlet. An exception is Amazon Alexa that sometimes connects directly to the devices (e.g. Belkin switches / Philips Hue), when you are at home on the same network (Wi-Fi). That's why you can re-program the Sonoff devices using Sonoff-Tasmota and then, you don't need a cloud connection anymore. However, if you use Google Home, this is not possible.

To sum up the aim of this post: Using this tutorial, you'll be able to control locally (LAN) most of the low-cost smart power outlets using an ESP32 programmed in MicroPython. Additionally, you can use the available data to do some analytics.

Note: Application like home assistant allows you to make this too, but you need at least a Raspberry Pi to run it, and that means power consumption. That's why, I like to do this with an ESP32 and of course, using MicroPython!

ESP32 LoRa

Read more

#MicroPython: ESP32 sending data using LoRa


LoRa (Long Range) is a patented digital wireless data communication technology. It was developed by Cycleo of Grenoble in France and then acquired by Semtech in 2012. Semtech defines the Lora Technology "as the DNA of IoT, which connects sensors to the Cloud and enables real-time communication of data and analytics that can be utilized to enhance efficiency and productivity".

To sum up, LoRa is a wireless data communication technology that enables very-long-range transmissions (more than 10 km in rural areas) with low power consumption. It uses license-free sub-gigahertz radio frequency bands as the 169 MHz, 433 MHz, 868 MHz for Europe and 915 MHz for North America. The technology can be divided in two parts:

  • LoRa: the physical layer,
  • LoRaWAN (Long Range Wide Area Network): the upper layers.

Here the code:

Python Code: https://github.com/lemariva/uPyLora

Rpi zero rt performance min

Read more

#Zerynth: ESP32 & Google IoT Core - Part 1: Sending data to the Cloud


There are lot of tutorials about connecting the ESP32 to a cloud service, but I planned to connect these boards using MicroPython directly to the cloud. That means, I didn't want to use a hardware or software bridge. I wanted to use the Google IoT Core, but MicroPython doesn't support JSON Web Token (JWT), which is needed for the device authentication. I tried to write the library myself, but it didn't work, because of the needed dependencies and the small memory available on the ESP modules. But, I found Zerynth. Zerynth supports JWT and using it, it is possible to connect the ESP32 directly to the Google IoT Core. The company Zerynth defined its product as "the middleware for IoT and Industry 4.0" and the ecosystem was stable as far as I tested it. The IDE (Zerynth Studio) can be a little bit improved, but it works well enough.

Zerynth is neither free nor open-source but every new user gets a welcome pack with 10 Zerynth VM licenses with FreeRTOS (5 Starter and 5 Premium) for free (more info here). If you need to register more sensors, you can use the store to purchase the additional licenses.

Important NOTE: I didn't get any money to promote Zerynth, I just wanted to use Python to connect the ESP32 directly to the Google IoT Core and this was the only option that I've found. If you know another one, please comment this post or send me a message. Thanks!


MicroPython

Read more

#MicroPython: Camera stabilisation application


To continue the series of posts "connecting sensors to MicroPython", this article is about the MPU6055 (you can use also the MPU9255, I am still waiting for the Chinese sensor package) and the WiPy 3.0. Combining the IMU sensor with the WiPy and two micro servos 9g, it is possible to stabilize a camera (tilt/rotate).

To calculate the compensation needed for the stabilisation, I added the umatrix, quaternion and ulinalg libraries to the project to make matrix multiplication and quaternion to Euler conversion. The ahrs library from Madgwick fusions the data of the accelerometer, gyroscope (and magnetometer, only with MPU9255) and allows to calculate the rotation of the IMU in quaternion coordinates. I rewrote (most of) the libraries to be compatible with MicroPython.


Wemos micropython min

Read more

#Tutorial: Getting started with MicroPython: Sensors - Part 1


One of the most visited articles on my blog is the Getting started with MicroPython! tutorial. If you still don't know what is MicroPython and you want to start programming microcontroller boards (ESP32, ESP8266 etc.) using a small version of Python 3, you should look at that article. Don't expect to use machine learning or/and other big libraries (the available RAM and microcontroller performance is far away for that aim), but you can do some projects like these:

Wipy2.0 Xmas-lights

Read more

#Micropython: Merry Xmas & Happy New Year!


It has been a while since my last post! Sorry, I was a little bit busy and then I was on a business trip in Melbourne for the CDC2017 and then I had a week holiday in Bangkok. I will be posting some photos on the next days!

It's been a year now since I started this blog. It's a hard job to maintain it up-to-date but I still have fun writing and coding for this purpose! So let us start!


The first video that I published a year ago was using the Wipy2.0 and a WS2812b led strip for some Christmas lights (click here). Now, this time I bought a WS2812b panel (100 bits or 10x10 pixels -or leds- see fig. 1) and as we have/had christmas again, so I wrote some code for this panel to make again some Xmas lights! :).

WiPy & Geolocalization

Read more

#MicroPython & #WiPy 2.0/3.0: Geolocation using WLAN


I was surfing the services that Google offers, I found the Geolocation API. As Google describes the API: it returns a location and accuracy radius based on information about cell towers and WiFi nodes that the mobile client can detect. As I was writing the last post using MicroPython, I thought the WiPy 2.0 could be a nice "mobile client".

To use the API you need to get an API key from Google. As a standard user of the API, you get:

  • 2,500 free requests per day, and
  • 50 requests per second, per user.

I thought I could play with it to test the accuracy of the geolocation.

Python Code: https://github.com/lemariva/uPyGeo

If you’re not up to speed with MicroPython, Wipy see earlier articles in here.

Wemos & Amazon Echo

Read more

#MicroPython: WeMos (ESP32) and Amazon Echo (Alexa) - Switching LED Colors!


I don’t have any Belkin WeMo system or Philips Hue light bulbs. However, I have two ESP32 running MicroPython (see my last article), and a W2812b LED strip, and I thought I should be able to say, "Echo/Alexa, turn on the kitchen light" or "Echo/Alexa, turn on the blue light" and It should work with this setup.

And... it works as you can see in this video!

If you are interesting in only using the code, then click here. Otherwise, you can read the complete story... ;)

Python Code: https://github.com/lemariva/uPyEcho

If you’re not up to speed with MicroPython, Wipy see earlier articles in here.

Wemos MicroPython

Read more

#Tutorial: Getting started with MicroPython


Another quick tutorial, this time for MicroPython on ESP32/ESP8266. You can find all the information that I'm writing in this post in different articles on the Internet but I've not found anything that summarizes all the topics. That is why I am writting this post. I included some links at the end of each topic to extend the info. Feel free to visit them if you want more info, or write a comment I will try to respond it.

Python Code: https://github.com/lemariva/ESP32-MicroPython

MicroPython & Board

What's MicroPython?

Quoting the official micropython page results in the following

MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments.

As you see, in my last posts (sorry about the link, I need some pagekit taxonomy!), I have been programming the Wipy 2.0. This board is a tiny MicroPython enabled WiFi & Bluetooth IoT development platform.

Fortunately, there is a port of MicroPython for the ESP32, and this time I've installed the firmware on the Wemos board. The development tool includes a ESP-WROOM-32 microcontroller.

Wipy2.0 Vu-Meter

Read more

#MicroPython: Vu meter using WS2812B and SPW2430


Hi everyone,

As soon as I saw the WS2812B led strip, I thought: doing a vu-meter with these LEDs would be a nice thing!.

I was looking for economical MEMS microphones with board (I didn't want to solder a board). I found two options: SPH0645LM4H and SPW2430.

The SPH0645LM4H uses an I2S interface and the SPW2430 has an analog output. The second board (SPW2430) has two outputs: AC pin which has a capacitor in series to eliminate the DC output of the IC, and the output of the IC (DC pin).

Python Code: https://goo.gl/eWTCUl

Weather Wipy2.0

Read more

#MicroPython: Weather Report using NEO-M8N


Hi!

I had two busy months, I've been writting my PhD-Thesis, and another publication and yeap... sorry! I forgot to update the blog!

Python Code: https://goo.gl/v7NCkj

Three weeks ago, I received a Ublox NEO-M8N GPS and I tested it with the code that I had. I said it should work, but as you know it always needs some modifications! The NEO-M8N supports GLONASS and GPS, so the $GP changes to $GN, e.g. $GPGGA (GPS) > $GNGGA (GPS+GLONASS).

The following changes were added:

# lines 604-606:
if self.gps_segments[0][2:] in self.supported_sentences:
    # parse the Sentence Based on the message type, return True if parse is clean                        
    if self.supported_sentences[self.gps_segments[0][2:]](self): 

...

# line 798:
# All the currently supported NMEA sentences
supported_sentences = {'RMC': gprmc, 'GGA': gpgga, 'VTG': gpvtg, 'GSA': gpgsa, 'GSV': gpgsv, 'GLL': gpgll} # GPS + GLONASS

I bought it from ebay, here the link:

NEO-M8N Ublox NEO-M8N x 1
The cold start needs a bit more time (estimated), but the module has a battery, then the warm start is much more faster (under 10 second). Please note that the VCC and GND pins are switched w.r.t. the NEO-6M board!

Gearbest tv box promotion promotion

Wipy 2.0 ST7735S Ublox

Read more

#MicroPython: Weather Report Box


Hi again!... First of all:

Happy Chinese New Year!!!

I've just uploaded some code for the Wipy 2.0. I wanted to write some python. That was why I took the Wipy 2.0 and programmed something like a weather report box: In this project the Wipy 2.0 reads the GPS coordinates via UART, then makes a web get request using the API of openweathermap, and after that the results are displayed on a LCD.

If you like this, please leave a comment, share and/or like! It would be very much appreciated!

Python Code: https://goo.gl/v7NCkj