Archive

Posts Tagged ‘thaieasyelec’
Orange Pi Development Boards

How to Use 3G and GPS on Raspberry Pi with ThaiEasyElec 3G HAT Expansion Board

February 11th, 2018 11 comments

Venus Supply is an embedded systems company based in Bangkok, Thailand that sells products through their ThaiEasyElec website/brand, as well as a act as a local distributor for popular DIY electronics items. I previously tested their ESPino32 ESP32 board, and the company has now send me another of their new product called “3G HAT Expansion for Raspberry Pi” and based on Quectel UC20-G that support 3G and GPS/GLONASS connectivity globally, meaning it should work in any country with 2G or 3G coverage.

After listing the specifications, going through unboxing and assembly with a Raspberry Pi 2/3 board, I’ll write some quick start guide to show what I had to do to use GPS and connect to 3G with a Hologram SIM card.

3G HAT Expansion for Raspberry Pi Specifications

  • Quectel UC20-G wireless module supporting
    • Cellular
      • 3G – UMTS @ 800/850/900/1900/2100 MHz
      • 2G – GSM @ 850/900/1800/1900 MHz
      • Data – HSPA+ up to 14.4 Mbps Downlink, 5.76 Mbps Uplink, EDGE, GPRS
      • Push-Pull SIM Card with ESD protection
      • Main + Diversity RP-SMA antenna connectors
    • GNSS
      • Qualcomm gpsOne Gen8 engine
      • GPS, GLONASS
      • RP-SMA antenna connector
  • Host interface – USB and UART
  • Audio – Audio codec, and 3.5 audio jack with microphone and mono audio
  • Misc
    • Auto start jumper (J3)
    • Software start/stop via GPIO17 or GPIO18 pin configurable via Jumper “P8”
    • Power switch
    • LED – Status LED, network, power
    • Back-up battery to reduce GPS fix time
  • Raspberry Pi Hat Compatible with 40-pin Raspberry Pi header

Unboxing

I received the kit in a carton box with three zipped packages: one for the board and accessories, and two for the GPS/GLONASS and 3G antennas which are not included by default.

Click to Enlarge

The GPS antenna comes with a 3-meter cable which should make it suitable to install in most cars or trucks, and the HAT package includes an extra zip bag with spacers, screws, nuts, and a 40-pin female header. I’ve also been told a 25cm micro USB cable should be included, but it seems they forgot it for my package…

Click to Enlarge

Looking closer at the board we can see Quectel UC20GB module in the center of the board, the three RP-SMA antenna connectors clearly marked with DIV, GNSS, and MAIN, the micro USB port for power and data, the 3.5mm audio jack, and in the top right connector J3 2-pin header to enable autostart, 3-pin P8 header to select GPIO 17 or GPIO 18 for software on/off, and the power key to manually start or stop the the module.

Click to Enlarge

They’ve also given access the the 40-pin RPi header using male pins, as a 4-pin UART connector.

The other side of the battery comes the audio codec board based on Nuvoton NAU8814Y mono audio codec, the SIM card slot fitted with a black dummy SIM card, a CR1220 coincell battery for GPS fix backup, and a 40-pin female header used for connection to the Raspberry Pi.

Click to Enlarge

I’ve been told the battery supploes power to the internal clock engine of the module, which can calculate the new position of satellites and get GPS fix faster  from data used up to 3 days ago.

3G HAT Assembly and Configuration with Raspberry Pi 2/3

Assembly is pretty straightforward,  first install the four spacers  on the Raspberry Pi board and fasten them with the nuts underneath the board, instead of the 40-pin female header on Raspberry Pi board, place the 3G HAT on top, and fasten the remaining four screws.
Connect the cellular antenna to the MAIN connector, and the GPS antenna to the GNSS connector. You’ll also need to flash Raspbian to a micro SD card. I’ll run the same Raspbian Stretch Lite image as I used with ANAVI Light pHAT starter kit.
If you want to follow the instructions provided by ThaiEasyElec (in Thai only for now, but easy enough to follow, and an English version is coming), you’ll need a GUI, so I’d recommend you install the full Raspbian Stretch image and connect an HDMI display, although you may run VNC client as well. I’ll do something a little different as I’ll do an headless setup instead, using Ethernet and SSH most of the time, but to test 3G, I’ll also disable Ethernet, so I also connected a USB to serial cable as shown below in order to access the serial console.

Click to Enlarge

Find a (short) micro USB to USB cable to connect the micro USB port of the HAT expansion board to the one of the USB ports of the Raspberry Pi to power on the board. I also had to remove the dummy SIM card, and insert my own SIM card with the contacts facing the board. After installation, we’ll see around 3mm of the SIM card, but that’s normal. Finally, you’ll need to decide how you want to manage the power: either with the power button, J3 jumper to autostart, or with pin 17 or 18 from the Raspberry Pi. I decided to move the jumper to J3 to always power on the module, but if you run on batteries, you’ll probably want to use the GPIO pin instead.

Verify the 3G HAT is Recognized in Linux

Now we are ready to start our Raspberry Pi board, and login to a terminal via SSH, serial, or in the desktop. We should find Quectel UC20 module with 05c6:9003 VID:PID with lsusb:

If you don’t see it, make sure the USB cable is connected, and you’ve powered the module up. I recommend you move the jumper to J3 at first like I did. Then you should see four ttyUSB devices:

Each are used by the module as follows:

  • /dev/ttyUSB0 – DM interface – Diagnose port (no used in this review)
  • /dev/ttyUSB1 –  NMEA interface – For GPS NMEA sentence output (read-only)
  • /dev/ttyUSB2 – AT interface (for GPS)
  • /dev/ttyUSB3 – Modem interface for PPP connections and AT command

Controlling GPS and Handling GPS Data

ThaiEasyElec uses Putty for Linux, but since I’m doing this headless I’ll install picocom intead:

Now we can connect to /dev/ttyUSB2 using 115200 8N1 to send some AT commands to the module:

The first command (AT+QGPS=1) turns the GNSS module on, and the second one (AT+QGPSEND) turns it off.

Let’s keep it on for now, and connect to /dev/ttyUSB1 @ 9600 baud to check NMEA output which should be updated every second when GPS is enabled:

That’s the meaning for each field:

  • GPGGA – Global Positioning System Fix Data, Time, Position and related fix data
  • GPRMC – Recommended minimum data
  • GPGSV – Detailed satellite data
  • GPGSA – Overall satellite data
  • GPVTG – Vector track and speed over the ground

GPGSA does not have data in the output above, simply because the GPS fix did not occur yet.

If you just want to enable GNSS each time the module is powered on, run the following command:

To disable this option, simply run the same command with 0 instead of 1. You can also query “autogps” status but running the command without the second parameter:

You’ll find more details about the GNSS AT command set for GPS and GLONASS in  Quectel UC20 GNSS AT Commands Manual (pdf).

Reading NMEA sentences is possible, but not really user friendly, and if we want to see a nice representation of the data we can run the GPS Daemon (gspd) and client (cgps) instad. Let’s exit both picocom sessions with GPS still running, and install the necessary packages:

The daemon will automatically run after installation, so let’s stop it…

… in order to run it with our own parameters, i.e. using /dev/ttyUSB1 NMEA interface:

Now we can run the client as follows:

After a few seconds should get a fix with details information (left) and data about the satellites (right).

I previously played with GPS using NavSpark mini GPS Module (Arduino compatible), and at the time  I could manage to get a GPS fix inside my room, but in this case I had to move the antenna outdoor to get signal. If you want to integrate such capability into your own app, you may want to study cgps source code.

It’s also possible to get the coordinate through /dev/ttyUSB2 terminal using QGPSLOC AT command with one of the following three modes:

  • Mode 0 – format = ddmm.mmmmN/S, dddmm.mmmmE/W
  • Mode 1 – format = ddmm.mmmmmmN/S, dddmm.mmmmmmE/W
  • Mode 2 – format = (-d)dd.ddddd,(-)ddd.ddddd

The fields from left to right: <UTC time>,<latitude>,<longitude>,<hdop>,<altitude>,<fix>,<cog>,<spkm>,<spkn>,<UTC date>,<nsat>

Short explanation for the not-so-obvious fields:

  • <hdop> – Horizontal precision, 0.5-99.9 (quoted from GPGGA sentence)
  • <fix> – GNSS positioning mode (quoted from GNGSA/GPGSA): 2 = 2D positioning; 3 = 3D positioning
  • <cog> – Ground heading based on true north. Format: ddd.mm (quoted from GPVTG sentence)
  • <spkm> – Speed over ground. Format: xxxx.x, unit: Km/h, accurate to one decimal place (quoted from GPVTG sentence)
  • <spkn> – Speed over ground. Format: xxxx.x, unit: knots, accurate to one decimal place (quoted from GPVTG sentence)
  • <nsat> –  Number of satellites, from 00 to 24 (the first 0 will also be transferred, quoted from GPGGA sentence)

3G HAT with Hologram SIM Card

Let’s now move to the cellular part of the module. I’ll use Hologram developer IoT SIM card, but any 3G SIM card should do.

Connection Method 1 – Sakis3G and UMTSkeeper

ThaiEasyElec documentation uses the two following programs to establish a 3G PPP connection:

  • Sakis3G is a parameter and hardware controller for connecting to the Internet.
  • UMTSkeeper is reconnecting with Sakis3G when the connection is down.

Booth can be found in umtskeeper package that we can install from a tarball:

We then need to install some extra packages:

We’re then told to launch Sakis3G in interactive mode to configure the connection. The look of it will depend whether you launch it from the dekstop, a SSH terminal, or a serial terminal. The interface looks really ugly (and messy) from the serial console, so instead I launched it from an SSH terminal:

We need to select 1. Connect with 3G, then 3. Custom tty…, and input /dev/ttyUSB3 for CUSTOM_TTY variable.

The next step auto-detected the correct APN (HOLOGRAM), so I just selected OK, and then was asked about APN_USER and APN_PASS.

Those parameters will also depend on your specific connection. Hologram does not use user and password, but simply pressing Enter will abort the configuration, so I entered 0 for both. After that, Sakig3G will try to connect and it worked!

Pressing Enter will bring us back to the main menu, where we can select Connection Information to find a few more details.

Let’s go back in the top menu, disconnect, and exit Sakis3G. Now we can run umtskeeper with the same parameters:

But the output does not look so good the very first time, since it complains about “no modem connected”:

But eventually we do get a connection. If you connect later, the Internet status message changes to:

Connection Method 2 – PPP Creator Script

While I was eventually successful, the first time I tried Method 1 I failed for some reasons, so at the time I looked for alternatives way to connect, and found Sixfab also used Hologram SIM card with their own RPi 3G/4G shield – also based a a Quectel module, and instead wrote ppp-creator.sh script.

So I downloaded it to my Raspberry Pi board, and executed it which created some other connection scripts.

Now we can run pppd call gprs command to establish a connection:

All good, and even simpler than the first method, although you may have to change the script in case you need APN username and password.

Testing the Connection

Whether we use method 1 or 2, we can now verify ppp0 is indeed up and connected.

I did that with Ethernet connected, so now I’ll disconnect Ethernet, turn it down, and start the script from the serial connection as a background process:

Again we can see on ppp0 is an active connection:

I can test outboud traffic with ping.

All good, but then I tried to connect via SSH using

But it failed to connection, maybe because 10.170.40.106 is a “local IP address”, and the “remote IP address” set to 10.64.64.64 is just a default address as shown in the log while running pppd call gprs.

SSH Tunelling with Hologram SIM card

I’m not familiar enough with 3G/4G connectivity to know if it’s a common issue but in the case of Hologram service we need to setup tunnelling to access via SSH (or another port/service). This can be done via SpaceBrige program or the command line, as you’ll find both methods on the relevant page on Hologram website.

I used SpaceBridge program in this case. You can download the client for Windows, Linux, or Mac OS. This is what I had to do in Ubuntu 16.04:

Now you’ll need to enable Tunneling for your device in Hologram dashboard, and get your Hologram API key, which you can generate and copy from your account.

Click OK, select your device(s), input your device port (e.g. 22 for SSH), and the local port on the computer to remotely access your Raspberry Pi over 3G.Click Done, and within a few seconds the tunnerl should be up and running.

I was finally able to connect the Raspberry Pi over SSH using the following command:

I could also get the GPS coordinate from there using cgps client.

If you want to stop the connection manually started with pppd call gprs, find the PID, and kill it:

In your actual project, you’ll want to control the connection using initd scripts or systemd.

I’d like to thanks Venus Supply / ThaiEasyElec for sending the product for review, it’s been fun to try out. If you’re interested you can purchase the board for 2350 THB (~$75) on their website, and may also consider adding the GSM/3G antenna for 120 THB (~$4) as well as the GNSS antenna for 350 THB (~$12).

A Day at Chiang Mai Maker Party 4.0

December 6th, 2017 6 comments

The Chiang Mai Maker Party 4.0 is now taking place until December 9, and I went there today, as I was especially interested in the scheduled NB-IoT talk and workshop to find out what was the status about LPWA in Thailand. But there are many other activities planned, and if you happen to be in Chiang Main in the next few days, you may want to check out the schedule on the event page or Facebook.

I’m going to go though what I’ve done today to give you a better idea about the event, or even the maker movement in Thailand.

Click to Enlarge

Booth and activity area should be the same over the 4 days, but the talks, open activity, and workshop will be different each day. Today, people could learn how to solder in the activity area.
The even was not really big with manufacturers/sellers like ThaiEasyElec, INEX, or Gravitech closer to the entrance…


… and slighter higher up in a different zone, companies and makers were showcasing their products or projects. I still managed to spent 5 interesting hours at the event attending to talks and checking out the various projects.

I started my day with a talk entitled “Maker Movement in South East Asia” presented by William Hooi, previously a teacher, who found One Maker Group and setup the first MakerSpace in Singapore, as well as helped introduce the Maker Faire in Singapore in 2012 onwards.


There was three parts to talk with an history of the Maker movement (worldwide), the maker movement in Singapore, and whether Making should be integrated into school curriculum.
He explained at first the government who not know about makers, so it was difficult to get funding, but eventually they jump on the bandwagon, and are now puring money on maker initiative. One thing that surprised me in the talk is that before makers were hidden their hobby, for fear of being mocked by other, for one for one person doing an LED jacket, and another working on an Iron Man suit. The people around them would not understand why they would waste their time on such endeavors, but the Maker Space and Faire helped finding like minded people. Some of the micro:bit boards apparently ended in Singapore, and when I say some, I mean 100,000 units. Another thing that I learned is the concept of “digital retreat for kids” where parents send kids to make things with their hands – for example soldering -, and not use smartphone or tablets at all, since they are already so accustomed to those devices.

One I was done with the talk, I walked around, so I’ll report about some of the interesting project I came across. I may write more detailed posts for some of the items lateron.

Click to Enlarge

Falling object detection demo using OpenCV on the software side, a webcam connected to…

Click to Enlarge

ASUS Tinker board to handle fall detection, and an NVIDIA Jetson board for artificial intelligence. If fall is detection an alert to send to the tablet, and the system also interfaces with Xiaomi Mi band 2.

Katunyou has also made a more compact product, still based on Tinker Board, for nursing home, or private home where an elderly may live alone. The person at the stand also organizes Raspberry Pi 3 workshops in Chiang Mai.

I found yet another product based on Raspberry Pi 3 board. SRAN is a network security device made by Global Tech that report threats from devices accessing your network using machine learning.

Click to Enlarge

Nordic Technology House showcased a magic mirror based on Raspberry Pi 3, and a webcam to detect your dance move, but their actual product shown above is a real-time indoor air monitoring system that report temperature, humidity, CO2 level, and PM 2.5 levels, and come sent alerts via LINE if thresholds are exceeded.

One booth had some drones including the larger one above spraying insecticides for the agriculture market.

Click to Enlarge

There was also a large about sewing machines, including some smarter one where you can design embroidery in a table before sewing.

There were also a few custom ESP8266 or ESP32 boards, but I forgot to take photos.

The Maker Party is also a good place to go with your want to buy some board or smart home devices.

Click to Enlarge

Beside Raspberry Pi Zero W / 3, ESP8266 boards and Asus Tinker board seem to be popular items in Thailand. I could also spot Sonoff wireless switch, and an Amazon Dot, although I could confirm only English is supported, no Thai language.

BBC Micro:bit board and accessories can also be bought at the event.


M5Stack modules, and Raspberry Pi 3 Voice Kit were also for sale.

Click to Enlarge

Books are also available for ESP32, Raspberry Pi 3, IoT, etc… in Thai language.

Click to Enlarge

But if you can’t read Thai there was also a choice of book in English about RPi, Arduino, Linux for Makers, IoT and so on. I then attended the second talk of the day: “NB-IoT” by AIS, one of the top telco company in Thailand. Speakers included Phuchong Charoensub, IoT Marketing Specialist, and Pornsak Hanvoravongchai, Device Innovation Manager, among others. They went through various part include a presentation of AIS current M2M business, what IoT will change (e.g. brings in statups and makers), some technical details about NB-IoT, and the company offering for makers.

I’ll go into more details in a separate post tomorrow, but if you want to get started the good news is that it’s now possible to pre-order a 1,990 THB Arduino Shield ($61) between December 6-9, and get it shipped on February 14, 2018. NB-IoT connectivity is free for one year, and will then cost 350 Baht (around $10) per year per device. However, there’s a cost to enable NB-IoT on LTE base stations, so AIS will only enable NB-IoT at some universities, and maker spaces, meaning for example, I would most certainly be able to use such kit from home. An AIS representative told me their no roadmap for deployment, it will depend on the business demand for such services.

If you are lucky you may even spot one or two dancing dinosaurs at the event.

Getting Started with Espruino & JavaScript on ESP32 with ESPino32 Board

September 11th, 2017 No comments

Venus Supply Co., Ltd, better known as ThaiEasyElec, is a company based in Thailand, selling embedded systems and development board, as well as providing development services based in Thailand. The company sent me their latest board called ESPino32 powered by Espressif ESP-WROOM-32 WiFi and Bluetooth module for evaluation. While the board is supported in Arduino-esp32, I’ve already tested Arduino with ESP32-Bit module & ESP32-T board, so after checking out the hardware, I’ll load it with something different: Espruino, a firmware allowing for JavaScript programming over the serial console, or a Web based IDE.

ESPino32 Unboxing and Soldering

The board shipped with four female headers, and I/O stickers.

Click to Enlarge

The board includes ESP-WROOM-32, exposes I/Os through four 10-pin headers, features CP2104 chip for serial to USB debugging via micro USB port, two buttons (reset and program), a user LED connected to IO16, and a jumper to select between regulated power supply (micro USB or Vin), or battery power (Vbat).

Click to Enlarge

If you’re going to integrate your board in a project, you may want to use it asif without header to save on space, but for prototyping and use with a breadboard, we should start by soldering the four female headers. It’s even a little easier than with other headers, since you can simply place the board on top of the headers to do the soldering.

Click to Enlarge

Once we’re done, we can apply the stickers on all four headers, which will make it easier to play with while connecting the jumper cables.

Now we can insert the board into a breadboard, connect an external 5V LED through pin 16, and connect a micro USB cable to a computer to get power and access the board.

Click to Enlarge

A board with female headers has the advantage of providing two usable rows on each side of the board. With male-only you’d lose that extra row, unless you use a narrower board such as  ESP32 Pico Core board.

That’s the output I get when connecting the board to my Linux computer:

Quick Start Guide for Espruino on ESP32

Espruino has a page about ESP32 support that explains what is working:

  • onewire
  • hardware SPI
  • hardware I2C
  • DAC
  • ADC
  • Serial
  • WIFI – as a client and access point

and what is not (yet):

  • Over-The-Air (OTA) firmware updates.
  • Bluetooth and BLE

So we can’t play with Bluetooth, but WiFi and GPIO should work. There are also some instructions in that page which I will follow and adapt (since some are not working/out of date) below.

First we need to download the latest version of Espruino, in my case Espruino 1.94.

Espruino Firmware for various board – Click to Enlarge

The zip file includes firmware for all supported platforms include the company’s own Espruino boards & Puck.js, Micro::bit, OlimeXino, Raspberry Pi, STM32 discovery boards, and more..

For our use, we need to get into espruino_1v94_espruino, where we’ll find 3 binary files (bootloader.bin, espruino_esp32.bin, and partitions_espruino.bin), as well as README_flash.txt that explains how to do the update in Windows with flash_download_tools_v3.4.4.zip, or in Linux with esptool.py from the ESP-IDF SDK. I’m running Ubuntu 16.04, so I’ll go with the later, but since most people won’t need to install the ESP-IDF SDK, you can instead get esptool from pip for Python 2.7 or 3.4 or newer:

if you’ve used esptool previously for other esp32/esp8266 board(s) before, you can upgrade esptool with:

In my case, I had installed an older version of esptool (v0.4.6) with apt when I played with NodeMCU board, so I removed it:

Now that we have the latest esptool utility installed, we can flash the image we’ve  just extracted:

It worked the first time. Log of successful installation:

At this point, in theory, you can install Espruino Web IDE chrome extension,  click on the connect icon on the left top corner, select /dev/ttyUSB0 port, and program away.

Click to Enlarge

Espruino Web IDE will also show in Ubuntu 16.04 dash. But in practise, there’s a known issue that the first time you won’t be able to connect through the Web IDE, and indeed I could not.. The work around is to first connect using screen or minicom in a terminal window:

We can then run an hello world sample:

That “=undefined” is a little confusing, but Espruino developers explain that is expected :

This is normal and it indicates the result of the last operation, which in this case is the return value of console.log, which is always undefined.

The next step is to configure a WiFi connection to your access point:

Replace “YOUR_SSID” and “YOUR_SSID_PASSWORD” with the value for your WiFi router. If this is successful, you should  see a message like shortly after:

The line wifi.save() will make sure the WiFi connection is permanent, so the board will reconnect to the router automatically after each reboot.

We can now go back to Espruino Web IDE, click on the Setup icon on the top right corner, go to Communications tab, and input the IP address (192.168.0.112 in my case) in the field “Connect over TCP Address“.

Click to Enlarge

You don’t even need to connect the board to your computer at this stage, if you be powered by a battery, or a USB power adapter. If we click on the Connect icon again, we’ll have the option to select TCP/IP: 192.168.0.112.

Click to Enlarge

I wrote a simply LED blink demo in the right part of the window, and clicked on he Upload button (third button in the middle) to upload and start the program:

Click to Enlarge

D16 is connected both the board’s IO16 LED and the LED on the board. IO16 will be turned on when D16 is low, and my LED when D16 is high every half second. I’ve shot a quick demo below.

However, if you reboot or power cycle the board, your program will not automatically start. So if you want the program to be “permanent”, add save command at the end of your code:

The output from the console should look like when you click on Upload button.

I could turn off and on the board, the LED demo resumed automatically without having to upload the code from the IDE.

Note that at this stage, I started to have some strange issues, like failure to connect to the board, and sometimes it would should “module http not found” or “module wiki not found”, as I wrote code for a web server.

It could be you need include the code for a permanent WiFi connection, before running the save command. It was still working sometimes, but I decided to connect through micro USB cable via Espruino Web IDE (it worked at this stage) to carry on with my tests more reliably.

In case you want to use ESPino32 board as small webserver, you can do so by creating a access point, and returning a simple “hello world” with the following code:

I click on Upload button, and I could access web server from Firefox.

The main advantage of Espruino over the Arduino IDE is that it’s much faster to try your code on the target, since there’s no need to compile a binary, upload to the board, and flash to storage during development. Another advantage depends on your skill set, as if you’re a seasoned web developer with a good knowledge of JavaScript, you won’t need to learn C programming used in Arduino IDE.

For other interface (SPI, I2C, ADC…) and more advanced tasks, you may check Espruino ESP32 page, but be forewarned, as the blink and web server samples did not work for me (unknown variable and missing semi-colon) by default. So you may want to read through the API reference in case the samples do not work. The company behind Espruino, Pur3 Ltd, is likely focusing most of the development efforts of their own hardware platforms like Puck.js and Espruino boards, and there’s more activity for those in the forums. So if you are interested in JavaScript on micro-controllers, but don’t want too many issues, ESP32 may not be best platform to learn, but if you like challenges, go ahead! 🙂

I’d like to thank ThaiEasyElec for sending an ESPino32 board sample. The company sells the board locally and globally for respectively 590 THB / ~$16 plus shipping on their website, where you’ll also find some documentation in English and Thai language. If you are based in Thailand, you can get further discount and free shipping if you purchase through LINE app.